Mercurial > cpython-lru_cache-weakref
annotate Python/import.c @ 14278:fb8fb53a2eff legacy-trunk
Add a comment explaining the return value of PyOS_CheckStack().
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Thu, 31 Aug 2000 05:38:39 +0000 |
| parents | 1f1a156ed5af |
| children | 6f6f965c5e2d |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
141
diff
changeset
|
1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13226
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13226
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13226
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13226
diff
changeset
|
5 All rights reserved. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
141
diff
changeset
|
6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13226
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13226
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
141
diff
changeset
|
9 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
141
diff
changeset
|
10 |
| 6 | 11 /* Module definition and import implementation */ |
| 12 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
13 #include "Python.h" |
| 6 | 14 |
| 15 #include "node.h" | |
| 16 #include "token.h" | |
| 17 #include "errcode.h" | |
|
263
28f0ffd9facf
Support ".pyc" files: cached compilation results.
Guido van Rossum <guido@python.org>
parents:
228
diff
changeset
|
18 #include "marshal.h" |
|
28f0ffd9facf
Support ".pyc" files: cached compilation results.
Guido van Rossum <guido@python.org>
parents:
228
diff
changeset
|
19 #include "compile.h" |
| 926 | 20 #include "eval.h" |
|
675
5aff9f8fd299
Move SEP to osdefs.h. Use MAXPATHLEN from osdefs.h.
Guido van Rossum <guido@python.org>
parents:
630
diff
changeset
|
21 #include "osdefs.h" |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
22 #include "importdl.h" |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
23 #ifdef macintosh |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
24 #include "macglue.h" |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
25 #endif |
|
263
28f0ffd9facf
Support ".pyc" files: cached compilation results.
Guido van Rossum <guido@python.org>
parents:
228
diff
changeset
|
26 |
| 4596 | 27 #ifdef HAVE_UNISTD_H |
| 28 #include <unistd.h> | |
| 29 #endif | |
| 30 | |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
31 /* We expect that stat exists on most systems. |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
32 It's confirmed on Unix, Mac and Windows. |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
33 If you don't have it, add #define DONT_HAVE_STAT to your config.h. */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
34 #ifndef DONT_HAVE_STAT |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
35 #define HAVE_STAT |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
36 |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9971
diff
changeset
|
37 #ifndef DONT_HAVE_SYS_TYPES_H |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
38 #include <sys/types.h> |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9971
diff
changeset
|
39 #endif |
|
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9971
diff
changeset
|
40 #ifndef DONT_HAVE_SYS_STAT_H |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
41 #include <sys/stat.h> |
|
13266
4c4e95147258
Jack Jansen, Mac patch:
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
42 #elif defined(HAVE_STAT_H) |
|
4c4e95147258
Jack Jansen, Mac patch:
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
43 #include <stat.h> |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9971
diff
changeset
|
44 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
45 |
|
6762
0a3c7402d395
Jeff Rush: add definition for S_IFMT for VisualAge C/C++ under OS2.
Guido van Rossum <guido@python.org>
parents:
6542
diff
changeset
|
46 #if defined(PYCC_VACPP) |
|
0a3c7402d395
Jeff Rush: add definition for S_IFMT for VisualAge C/C++ under OS2.
Guido van Rossum <guido@python.org>
parents:
6542
diff
changeset
|
47 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */ |
|
0a3c7402d395
Jeff Rush: add definition for S_IFMT for VisualAge C/C++ under OS2.
Guido van Rossum <guido@python.org>
parents:
6542
diff
changeset
|
48 #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG) |
|
0a3c7402d395
Jeff Rush: add definition for S_IFMT for VisualAge C/C++ under OS2.
Guido van Rossum <guido@python.org>
parents:
6542
diff
changeset
|
49 #endif |
|
0a3c7402d395
Jeff Rush: add definition for S_IFMT for VisualAge C/C++ under OS2.
Guido van Rossum <guido@python.org>
parents:
6542
diff
changeset
|
50 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
51 #ifndef S_ISDIR |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
52 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
53 #endif |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
54 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
55 #endif |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
56 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
57 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
58 extern time_t PyOS_GetLastModificationTime(char *, FILE *); |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
59 /* In getmtime.c */ |
|
1351
e149c77d173c
Makefile, import.c: Lance's alternative module search (allow .pyc file
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
60 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
61 /* Magic word to reject .pyc files generated by other Python versions */ |
|
2812
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
62 /* Change for each incompatible change */ |
|
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
63 /* The value of CR and LF is incorporated so if you ever read or write |
|
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
64 a .pyc file in text mode the magic number will be wrong; also, the |
|
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
65 Apple MPW compiler swaps their values, botching string constants */ |
|
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
66 /* XXX Perhaps the magic number should be frozen and a version field |
|
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
67 added to the .pyc file header? */ |
|
4993
b82d847b3dcb
New MAGIC number (code objects have one more item when marshalled).
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
68 /* New way to come up with the magic number: (YEAR-1995), MONTH, DAY */ |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14163
diff
changeset
|
69 #define MAGIC (50823 | ((long)'\r'<<16) | ((long)'\n'<<24)) |
|
487
77b80a91d357
New magic word; and check it.
Guido van Rossum <guido@python.org>
parents:
340
diff
changeset
|
70 |
| 12543 | 71 /* Magic word as global; note that _PyImport_Init() can change the |
|
13181
6f4669814884
another typo caught by Rob Hooft
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
72 value of this global to accommodate for alterations of how the |
| 12543 | 73 compiler works which are enabled by command line switches. */ |
| 74 static long pyc_magic = MAGIC; | |
| 75 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
76 /* See _PyImport_FixupExtension() below */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
77 static PyObject *extensions = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
78 |
|
6541
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
79 /* This table is defined in config.c: */ |
|
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
80 extern struct _inittab _PyImport_Inittab[]; |
|
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
81 |
|
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
82 struct _inittab *PyImport_Inittab = _PyImport_Inittab; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
83 |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
84 /* these tables define the module suffixes that Python recognizes */ |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
85 struct filedescr * _PyImport_Filetab = NULL; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
86 static const struct filedescr _PyImport_StandardFiletab[] = { |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
87 {".py", "r", PY_SOURCE}, |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
88 {".pyc", "rb", PY_COMPILED}, |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
89 {0, 0} |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
90 }; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
91 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
92 /* Initialize things */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
93 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
94 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
95 _PyImport_Init(void) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
96 { |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
97 const struct filedescr *scan; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
98 struct filedescr *filetab; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
99 int countD = 0; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
100 int countS = 0; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
101 |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
102 /* prepare _PyImport_Filetab: copy entries from |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
103 _PyImport_DynLoadFiletab and _PyImport_StandardFiletab. |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
104 */ |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
105 for (scan = _PyImport_DynLoadFiletab; scan->suffix != NULL; ++scan) |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
106 ++countD; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
107 for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan) |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
108 ++countS; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
109 filetab = PyMem_NEW(struct filedescr, countD + countS + 1); |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
110 memcpy(filetab, _PyImport_DynLoadFiletab, |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
111 countD * sizeof(struct filedescr)); |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
112 memcpy(filetab + countD, _PyImport_StandardFiletab, |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
113 countS * sizeof(struct filedescr)); |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
114 filetab[countD + countS].suffix = NULL; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
115 |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
116 _PyImport_Filetab = filetab; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
117 |
|
5180
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
118 if (Py_OptimizeFlag) { |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
119 /* Replace ".pyc" with ".pyo" in _PyImport_Filetab */ |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
120 for (; filetab->suffix != NULL; filetab++) { |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
121 if (strcmp(filetab->suffix, ".pyc") == 0) |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
122 filetab->suffix = ".pyo"; |
|
5180
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
123 } |
|
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
124 } |
| 12543 | 125 |
| 126 if (Py_UnicodeFlag) { | |
| 127 /* Fix the pyc_magic so that byte compiled code created | |
| 128 using the all-Unicode method doesn't interfere with | |
| 129 code created in normal operation mode. */ | |
| 130 pyc_magic = MAGIC + 1; | |
| 131 } | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
132 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
133 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
134 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
135 _PyImport_Fini(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
136 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
137 Py_XDECREF(extensions); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
138 extensions = NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
139 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
140 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
141 |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
142 /* Locking primitives to prevent parallel imports of the same module |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
143 in different threads to return with a partially loaded module. |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
144 These calls are serialized by the global interpreter lock. */ |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
145 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
146 #ifdef WITH_THREAD |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
147 |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9187
diff
changeset
|
148 #include "pythread.h" |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
149 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
150 static PyThread_type_lock import_lock = 0; |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
151 static long import_lock_thread = -1; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
152 static int import_lock_level = 0; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
153 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
154 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
155 lock_import(void) |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
156 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
157 long me = PyThread_get_thread_ident(); |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
158 if (me == -1) |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
159 return; /* Too bad */ |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
160 if (import_lock == NULL) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
161 import_lock = PyThread_allocate_lock(); |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
162 if (import_lock_thread == me) { |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
163 import_lock_level++; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
164 return; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
165 } |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
166 if (import_lock_thread != -1 || !PyThread_acquire_lock(import_lock, 0)) { |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
167 PyThreadState *tstate = PyEval_SaveThread(); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
168 PyThread_acquire_lock(import_lock, 1); |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
169 PyEval_RestoreThread(tstate); |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
170 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
171 import_lock_thread = me; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
172 import_lock_level = 1; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
173 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
174 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
175 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
176 unlock_import(void) |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
177 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
178 long me = PyThread_get_thread_ident(); |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
179 if (me == -1) |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
180 return; /* Too bad */ |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
181 if (import_lock_thread != me) |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
182 Py_FatalError("unlock_import: not holding the import lock"); |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
183 import_lock_level--; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
184 if (import_lock_level == 0) { |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
185 import_lock_thread = -1; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
186 PyThread_release_lock(import_lock); |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
187 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
188 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
189 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
190 #else |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
191 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
192 #define lock_import() |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
193 #define unlock_import() |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
194 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
195 #endif |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
196 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
197 /* Helper for sys */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
198 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
199 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
200 PyImport_GetModuleDict(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
201 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
202 PyInterpreterState *interp = PyThreadState_Get()->interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
203 if (interp->modules == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
204 Py_FatalError("PyImport_GetModuleDict: no module dictionary!"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
205 return interp->modules; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
206 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
207 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
208 |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
209 /* List of names to clear in sys */ |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
210 static char* sys_deletes[] = { |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
211 "path", "argv", "ps1", "ps2", "exitfunc", |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
212 "exc_type", "exc_value", "exc_traceback", |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
213 "last_type", "last_value", "last_traceback", |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
214 NULL |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
215 }; |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
216 |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
217 static char* sys_files[] = { |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
218 "stdin", "__stdin__", |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
219 "stdout", "__stdout__", |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
220 "stderr", "__stderr__", |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
221 NULL |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
222 }; |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
223 |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
224 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
225 /* Un-initialize things, as good as we can */ |
| 86 | 226 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
227 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
228 PyImport_Cleanup(void) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
229 { |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
230 int pos, ndone; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
231 char *name; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
232 PyObject *key, *value, *dict; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
233 PyInterpreterState *interp = PyThreadState_Get()->interp; |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
234 PyObject *modules = interp->modules; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
235 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
236 if (modules == NULL) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
237 return; /* Already done */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
238 |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
239 /* Delete some special variables first. These are common |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
240 places where user values hide and people complain when their |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
241 destructors fail. Since the modules containing them are |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
242 deleted *last* of all, they would come too late in the normal |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
243 destruction order. Sigh. */ |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
244 |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
245 value = PyDict_GetItemString(modules, "__builtin__"); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
246 if (value != NULL && PyModule_Check(value)) { |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
247 dict = PyModule_GetDict(value); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
248 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
249 PySys_WriteStderr("# clear __builtin__._\n"); |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
250 PyDict_SetItemString(dict, "_", Py_None); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
251 } |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
252 value = PyDict_GetItemString(modules, "sys"); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
253 if (value != NULL && PyModule_Check(value)) { |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
254 char **p; |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
255 PyObject *v; |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
256 dict = PyModule_GetDict(value); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
257 for (p = sys_deletes; *p != NULL; p++) { |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
258 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
259 PySys_WriteStderr("# clear sys.%s\n", *p); |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
260 PyDict_SetItemString(dict, *p, Py_None); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
261 } |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
262 for (p = sys_files; *p != NULL; p+=2) { |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
263 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
264 PySys_WriteStderr("# restore sys.%s\n", *p); |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
265 v = PyDict_GetItemString(dict, *(p+1)); |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
266 if (v == NULL) |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
267 v = Py_None; |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
268 PyDict_SetItemString(dict, *p, v); |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
269 } |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
270 } |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
271 |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
272 /* First, delete __main__ */ |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
273 value = PyDict_GetItemString(modules, "__main__"); |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
274 if (value != NULL && PyModule_Check(value)) { |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
275 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
276 PySys_WriteStderr("# cleanup __main__\n"); |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
277 _PyModule_Clear(value); |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
278 PyDict_SetItemString(modules, "__main__", Py_None); |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
279 } |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
280 |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
281 /* The special treatment of __builtin__ here is because even |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
282 when it's not referenced as a module, its dictionary is |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
283 referenced by almost every module's __builtins__. Since |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
284 deleting a module clears its dictionary (even if there are |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
285 references left to it), we need to delete the __builtin__ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
286 module last. Likewise, we don't delete sys until the very |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
287 end because it is implicitly referenced (e.g. by print). |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
288 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
289 Also note that we 'delete' modules by replacing their entry |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
290 in the modules dict with None, rather than really deleting |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
291 them; this avoids a rehash of the modules dictionary and |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
292 also marks them as "non existent" so they won't be |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
293 re-imported. */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
294 |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
295 /* Next, repeatedly delete modules with a reference count of |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
296 one (skipping __builtin__ and sys) and delete them */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
297 do { |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
298 ndone = 0; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
299 pos = 0; |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
300 while (PyDict_Next(modules, &pos, &key, &value)) { |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
301 if (value->ob_refcnt != 1) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
302 continue; |
|
9187
e21d0798c02a
While scalling sys.modules, skip entries that don't have string keys,
Guido van Rossum <guido@python.org>
parents:
9096
diff
changeset
|
303 if (PyString_Check(key) && PyModule_Check(value)) { |
|
e21d0798c02a
While scalling sys.modules, skip entries that don't have string keys,
Guido van Rossum <guido@python.org>
parents:
9096
diff
changeset
|
304 name = PyString_AS_STRING(key); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
305 if (strcmp(name, "__builtin__") == 0) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
306 continue; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
307 if (strcmp(name, "sys") == 0) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
308 continue; |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
309 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
310 PySys_WriteStderr( |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
311 "# cleanup[1] %s\n", name); |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
312 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
313 PyDict_SetItem(modules, key, Py_None); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
314 ndone++; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
315 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
316 } |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
317 } while (ndone > 0); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
318 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
319 /* Next, delete all modules (still skipping __builtin__ and sys) */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
320 pos = 0; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
321 while (PyDict_Next(modules, &pos, &key, &value)) { |
|
9187
e21d0798c02a
While scalling sys.modules, skip entries that don't have string keys,
Guido van Rossum <guido@python.org>
parents:
9096
diff
changeset
|
322 if (PyString_Check(key) && PyModule_Check(value)) { |
|
e21d0798c02a
While scalling sys.modules, skip entries that don't have string keys,
Guido van Rossum <guido@python.org>
parents:
9096
diff
changeset
|
323 name = PyString_AS_STRING(key); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
324 if (strcmp(name, "__builtin__") == 0) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
325 continue; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
326 if (strcmp(name, "sys") == 0) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
327 continue; |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
328 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
329 PySys_WriteStderr("# cleanup[2] %s\n", name); |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
330 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
331 PyDict_SetItem(modules, key, Py_None); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
332 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
333 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
334 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
335 /* Next, delete sys and __builtin__ (in that order) */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
336 value = PyDict_GetItemString(modules, "sys"); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
337 if (value != NULL && PyModule_Check(value)) { |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
338 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
339 PySys_WriteStderr("# cleanup sys\n"); |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
340 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
341 PyDict_SetItemString(modules, "sys", Py_None); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
342 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
343 value = PyDict_GetItemString(modules, "__builtin__"); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
344 if (value != NULL && PyModule_Check(value)) { |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
345 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
346 PySys_WriteStderr("# cleanup __builtin__\n"); |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
347 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
348 PyDict_SetItemString(modules, "__builtin__", Py_None); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
349 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
350 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
351 /* Finally, clear and delete the modules directory */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
352 PyDict_Clear(modules); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
353 interp->modules = NULL; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
354 Py_DECREF(modules); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
355 } |
|
166
28923e44254c
Added forward declaration (to satisfy Standard C).
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
356 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
357 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
358 /* Helper for pythonrun.c -- return magic number */ |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
359 |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
360 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
361 PyImport_GetMagicNumber(void) |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
362 { |
| 12543 | 363 return pyc_magic; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
364 } |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
365 |
| 6 | 366 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
367 /* Magic for extension modules (built-in as well as dynamically |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
368 loaded). To prevent initializing an extension module more than |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
369 once, we keep a static dictionary 'extensions' keyed by module name |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
370 (for built-in modules) or by filename (for dynamically loaded |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
371 modules), containing these modules. A copy od the module's |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
372 dictionary is stored by calling _PyImport_FixupExtension() |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
373 immediately after the module initialization function succeeds. A |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
374 copy can be retrieved from there by calling |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
375 _PyImport_FindExtension(). */ |
| 6 | 376 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
377 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
378 _PyImport_FixupExtension(char *name, char *filename) |
| 6 | 379 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
380 PyObject *modules, *mod, *dict, *copy; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
381 if (extensions == NULL) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
382 extensions = PyDict_New(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
383 if (extensions == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
384 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
385 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
386 modules = PyImport_GetModuleDict(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
387 mod = PyDict_GetItemString(modules, name); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
388 if (mod == NULL || !PyModule_Check(mod)) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
389 PyErr_Format(PyExc_SystemError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
390 "_PyImport_FixupExtension: module %.200s not loaded", name); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
391 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
392 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
393 dict = PyModule_GetDict(mod); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
394 if (dict == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
395 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
396 copy = PyObject_CallMethod(dict, "copy", ""); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
397 if (copy == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
398 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
399 PyDict_SetItemString(extensions, filename, copy); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
400 Py_DECREF(copy); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
401 return copy; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
402 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
403 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
404 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
405 _PyImport_FindExtension(char *name, char *filename) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
406 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
407 PyObject *dict, *mod, *mdict, *result; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
408 if (extensions == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
409 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
410 dict = PyDict_GetItemString(extensions, filename); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
411 if (dict == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
412 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
413 mod = PyImport_AddModule(name); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
414 if (mod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
415 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
416 mdict = PyModule_GetDict(mod); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
417 if (mdict == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
418 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
419 result = PyObject_CallMethod(mdict, "update", "O", dict); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
420 if (result == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
421 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
422 Py_DECREF(result); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
423 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
424 PySys_WriteStderr("import %s # previously loaded (%s)\n", |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
425 name, filename); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
426 return mod; |
| 6 | 427 } |
| 428 | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
429 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
430 /* Get the module object corresponding to a module name. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
431 First check the modules dictionary if there's one there, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
432 if not, create a new one and insert in in the modules dictionary. |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
433 Because the former action is most common, THIS DOES NOT RETURN A |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
434 'NEW' REFERENCE! */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
435 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
436 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
437 PyImport_AddModule(char *name) |
|
40
f28ac7f621c7
Added reload() functionality.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
438 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
439 PyObject *modules = PyImport_GetModuleDict(); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
440 PyObject *m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
441 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
442 if ((m = PyDict_GetItemString(modules, name)) != NULL && |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
443 PyModule_Check(m)) |
| 86 | 444 return m; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
445 m = PyModule_New(name); |
| 86 | 446 if (m == NULL) |
| 6 | 447 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
448 if (PyDict_SetItemString(modules, name, m) != 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
449 Py_DECREF(m); |
| 86 | 450 return NULL; |
| 6 | 451 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
452 Py_DECREF(m); /* Yes, it still exists, in modules! */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
453 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
454 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
455 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
456 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
457 |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
458 /* Execute a code object in a module and return the module object |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
459 WITH INCREMENTED REFERENCE COUNT */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
460 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
461 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
462 PyImport_ExecCodeModule(char *name, PyObject *co) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
463 { |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
464 return PyImport_ExecCodeModuleEx(name, co, (char *)NULL); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
465 } |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
466 |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
467 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
468 PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
469 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
470 PyObject *modules = PyImport_GetModuleDict(); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
471 PyObject *m, *d, *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
472 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
473 m = PyImport_AddModule(name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
474 if (m == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
475 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
476 d = PyModule_GetDict(m); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
477 if (PyDict_GetItemString(d, "__builtins__") == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
478 if (PyDict_SetItemString(d, "__builtins__", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
479 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
480 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
481 } |
|
3557
cee4a6d8415e
Remember source filename as <module>.__file__.
Guido van Rossum <guido@python.org>
parents:
3492
diff
changeset
|
482 /* Remember the filename as the __file__ attribute */ |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
483 v = NULL; |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
484 if (pathname != NULL) { |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
485 v = PyString_FromString(pathname); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
486 if (v == NULL) |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
487 PyErr_Clear(); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
488 } |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
489 if (v == NULL) { |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
490 v = ((PyCodeObject *)co)->co_filename; |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
491 Py_INCREF(v); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
492 } |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
493 if (PyDict_SetItemString(d, "__file__", v) != 0) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
494 PyErr_Clear(); /* Not important enough to report */ |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
495 Py_DECREF(v); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
496 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
497 v = PyEval_EvalCode((PyCodeObject *)co, d, d); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
498 if (v == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
499 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
500 Py_DECREF(v); |
|
5758
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
501 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
502 if ((m = PyDict_GetItemString(modules, name)) == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
503 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
504 "Loaded module %.200s not found in sys.modules", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
505 name); |
|
5758
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
506 return NULL; |
|
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
507 } |
|
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
508 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
509 Py_INCREF(m); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
510 |
| 86 | 511 return m; |
| 6 | 512 } |
| 513 | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
514 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
515 /* Given a pathname for a Python source file, fill a buffer with the |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
516 pathname for the corresponding compiled file. Return the pathname |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
517 for the compiled file, or NULL if there's no space in the buffer. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
518 Doesn't set an exception. */ |
|
609
0ad5b35e3ad8
Support for dynamic loading added.
Guido van Rossum <guido@python.org>
parents:
510
diff
changeset
|
519 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
520 static char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
521 make_compiled_pathname(char *pathname, char *buf, size_t buflen) |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
522 { |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
523 size_t len; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
524 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
525 len = strlen(pathname); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
526 if (len+2 > buflen) |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
527 return NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
528 strcpy(buf, pathname); |
|
5180
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
529 strcpy(buf+len, Py_OptimizeFlag ? "o" : "c"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
530 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
531 return buf; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
532 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
533 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
534 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
535 /* Given a pathname for a Python source file, its time of last |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
536 modification, and a pathname for a compiled file, check whether the |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
537 compiled file represents the same version of the source. If so, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
538 return a FILE pointer for the compiled file, positioned just after |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
539 the header; if not, return NULL. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
540 Doesn't set an exception. */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
541 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
542 static FILE * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
543 check_compiled_module(char *pathname, long mtime, char *cpathname) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
544 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
545 FILE *fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
546 long magic; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
547 long pyc_mtime; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
548 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
549 fp = fopen(cpathname, "rb"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
550 if (fp == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
551 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
552 magic = PyMarshal_ReadLongFromFile(fp); |
| 12543 | 553 if (magic != pyc_magic) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
554 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
555 PySys_WriteStderr("# %s has bad magic\n", cpathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
556 fclose(fp); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
557 return NULL; |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
558 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
559 pyc_mtime = PyMarshal_ReadLongFromFile(fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
560 if (pyc_mtime != mtime) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
561 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
562 PySys_WriteStderr("# %s has bad mtime\n", cpathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
563 fclose(fp); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
564 return NULL; |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
565 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
566 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
567 PySys_WriteStderr("# %s matches %s\n", cpathname, pathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
568 return fp; |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
569 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
570 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
571 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
572 /* Read a code object from a file and check it for validity */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
573 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
574 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
575 read_compiled_module(char *cpathname, FILE *fp) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
576 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
577 PyObject *co; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
578 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
579 co = PyMarshal_ReadObjectFromFile(fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
580 /* Ugly: rd_object() may return NULL with or without error */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
581 if (co == NULL || !PyCode_Check(co)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
582 if (!PyErr_Occurred()) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
583 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
584 "Non-code object in %.200s", cpathname); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
585 Py_XDECREF(co); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
586 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
587 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
588 return (PyCodeObject *)co; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
589 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
590 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
591 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
592 /* Load a module from a compiled file, execute it, and return its |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
593 module object WITH INCREMENTED REFERENCE COUNT */ |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
594 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
595 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
596 load_compiled_module(char *name, char *cpathname, FILE *fp) |
| 6 | 597 { |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
598 long magic; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
599 PyCodeObject *co; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
600 PyObject *m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
601 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
602 magic = PyMarshal_ReadLongFromFile(fp); |
| 12543 | 603 if (magic != pyc_magic) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
604 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
605 "Bad magic number in %.200s", cpathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
606 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
607 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
608 (void) PyMarshal_ReadLongFromFile(fp); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
609 co = read_compiled_module(cpathname, fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
610 if (co == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
611 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
612 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
613 PySys_WriteStderr("import %s # precompiled from %s\n", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
614 name, cpathname); |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
615 m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
616 Py_DECREF(co); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
617 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
618 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
619 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
620 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
621 /* Parse a source file and return the corresponding code object */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
622 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
623 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
624 parse_source_module(char *pathname, FILE *fp) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
625 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
626 PyCodeObject *co; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
627 node *n; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
628 |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5375
diff
changeset
|
629 n = PyParser_SimpleParseFile(fp, pathname, Py_file_input); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
630 if (n == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
631 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
632 co = PyNode_Compile(n, pathname); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
633 PyNode_Free(n); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
634 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
635 return co; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
636 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
637 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
638 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
639 /* Write a compiled module to a file, placing the time of last |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
640 modification of its source into the header. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
641 Errors are ignored, if a write error occurs an attempt is made to |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
642 remove the file. */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
643 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
644 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
645 write_compiled_module(PyCodeObject *co, char *cpathname, long mtime) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
646 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
647 FILE *fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
648 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
649 fp = fopen(cpathname, "wb"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
650 if (fp == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
651 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
652 PySys_WriteStderr( |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
653 "# can't create %s\n", cpathname); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
654 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
655 } |
| 12543 | 656 PyMarshal_WriteLongToFile(pyc_magic, fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
657 /* First write a 0 for mtime */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
658 PyMarshal_WriteLongToFile(0L, fp); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
659 PyMarshal_WriteObjectToFile((PyObject *)co, fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
660 if (ferror(fp)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
661 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
662 PySys_WriteStderr("# can't write %s\n", cpathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
663 /* Don't keep partial file */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
664 fclose(fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
665 (void) unlink(cpathname); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
666 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
667 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
668 /* Now write the true mtime */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
669 fseek(fp, 4L, 0); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
670 PyMarshal_WriteLongToFile(mtime, fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
671 fflush(fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
672 fclose(fp); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
673 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
674 PySys_WriteStderr("# wrote %s\n", cpathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
675 #ifdef macintosh |
|
13552
dd2b5218e069
Include macglue.h for some function prototypes, and renamed a few
Jack Jansen <jack.jansen@cwi.nl>
parents:
13447
diff
changeset
|
676 PyMac_setfiletype(cpathname, 'Pyth', 'PYC '); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
677 #endif |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
678 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
679 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
680 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
681 /* Load a source module from a given file and return its module |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
682 object WITH INCREMENTED REFERENCE COUNT. If there's a matching |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
683 byte-compiled file, use that instead. */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
684 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
685 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
686 load_source_module(char *name, char *pathname, FILE *fp) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
687 { |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
688 time_t mtime; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
689 FILE *fpc; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
690 char buf[MAXPATHLEN+1]; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
691 char *cpathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
692 PyCodeObject *co; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
693 PyObject *m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
694 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
695 mtime = PyOS_GetLastModificationTime(pathname, fp); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
696 if (mtime == -1) |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
697 return NULL; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
698 #if SIZEOF_TIME_T > 4 |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
699 /* Python's .pyc timestamp handling presumes that the timestamp fits |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
700 in 4 bytes. This will be fine until sometime in the year 2038, |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
701 when a 4-byte signed time_t will overflow. |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
702 */ |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
703 if (mtime >> 32) { |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
704 PyErr_SetString(PyExc_OverflowError, |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
705 "modification time overflows a 4 bytes"); |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
706 return NULL; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
707 } |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
708 #endif |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
709 cpathname = make_compiled_pathname(pathname, buf, (size_t)MAXPATHLEN+1); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
710 if (cpathname != NULL && |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
711 (fpc = check_compiled_module(pathname, mtime, cpathname))) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
712 co = read_compiled_module(cpathname, fpc); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
713 fclose(fpc); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
714 if (co == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
715 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
716 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
717 PySys_WriteStderr("import %s # precompiled from %s\n", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
718 name, cpathname); |
|
9050
f3ebdb2274e4
__file__ used to be always set to the .pyc (or .pyo) file, even if
Guido van Rossum <guido@python.org>
parents:
8934
diff
changeset
|
719 pathname = cpathname; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
720 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
721 else { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
722 co = parse_source_module(pathname, fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
723 if (co == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
724 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
725 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
726 PySys_WriteStderr("import %s # from %s\n", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
727 name, pathname); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
728 write_compiled_module(co, cpathname, mtime); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
729 } |
|
9050
f3ebdb2274e4
__file__ used to be always set to the .pyc (or .pyo) file, even if
Guido van Rossum <guido@python.org>
parents:
8934
diff
changeset
|
730 m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
731 Py_DECREF(co); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
732 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
733 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
734 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
735 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
736 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
737 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
738 static PyObject *load_module(char *, FILE *, char *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
739 static struct filedescr *find_module(char *, PyObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
740 char *, size_t, FILE **); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
741 static struct _frozen *find_frozen(char *name); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
742 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
743 /* Load a package and return its module object WITH INCREMENTED |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
744 REFERENCE COUNT */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
745 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
746 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
747 load_package(char *name, char *pathname) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
748 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
749 PyObject *m, *d, *file, *path; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
750 int err; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
751 char buf[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
752 FILE *fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
753 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
754 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
755 m = PyImport_AddModule(name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
756 if (m == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
757 return NULL; |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
758 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
759 PySys_WriteStderr("import %s # directory %s\n", |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
760 name, pathname); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
761 d = PyModule_GetDict(m); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
762 file = PyString_FromString(pathname); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
763 if (file == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
764 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
765 path = Py_BuildValue("[O]", file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
766 if (path == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
767 Py_DECREF(file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
768 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
769 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
770 err = PyDict_SetItemString(d, "__file__", file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
771 if (err == 0) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
772 err = PyDict_SetItemString(d, "__path__", path); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
773 if (err != 0) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
774 m = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
775 goto cleanup; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
776 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
777 buf[0] = '\0'; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
778 fdp = find_module("__init__", path, buf, sizeof(buf), &fp); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
779 if (fdp == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
780 if (PyErr_ExceptionMatches(PyExc_ImportError)) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
781 PyErr_Clear(); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
782 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
783 else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
784 m = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
785 goto cleanup; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
786 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
787 m = load_module(name, fp, buf, fdp->type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
788 if (fp != NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
789 fclose(fp); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
790 cleanup: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
791 Py_XDECREF(path); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
792 Py_XDECREF(file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
793 return m; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
794 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
795 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
796 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
797 /* Helper to test for built-in module */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
798 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
799 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
800 is_builtin(char *name) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
801 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
802 int i; |
|
6541
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
803 for (i = 0; PyImport_Inittab[i].name != NULL; i++) { |
|
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
804 if (strcmp(name, PyImport_Inittab[i].name) == 0) { |
|
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
805 if (PyImport_Inittab[i].initfunc == NULL) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
806 return -1; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
807 else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
808 return 1; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
809 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
810 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
811 return 0; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
812 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
813 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
814 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
815 /* Search the path (default sys.path) for a module. Return the |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
816 corresponding filedescr struct, and (via return arguments) the |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
817 pathname and an open file. Return NULL if the module is not found. */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
818 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
819 #ifdef MS_COREDLL |
|
13663
29da35543833
ANSIfy as many declarations as possible.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
820 extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **, |
|
29da35543833
ANSIfy as many declarations as possible.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
821 char *, int); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
822 #endif |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
823 |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
824 #ifdef CHECK_IMPORT_CASE |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
825 static int check_case(char *, int, int, char *); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
826 #endif |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
827 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
828 static int find_init_module(char *); /* Forward */ |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
829 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
830 static struct filedescr * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
831 find_module(char *realname, PyObject *path, char *buf, size_t buflen, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
832 FILE **p_fp) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
833 { |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
834 int i, npath; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
835 size_t len, namelen; |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
836 struct _frozen *f; |
| 4596 | 837 struct filedescr *fdp = NULL; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
838 FILE *fp = NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
839 struct stat statbuf; |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
840 static struct filedescr fd_frozen = {"", "", PY_FROZEN}; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
841 static struct filedescr fd_builtin = {"", "", C_BUILTIN}; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
842 static struct filedescr fd_package = {"", "", PKG_DIRECTORY}; |
|
8934
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
843 char name[MAXPATHLEN+1]; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
844 |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
845 if (strlen(realname) > MAXPATHLEN) { |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
846 PyErr_SetString(PyExc_OverflowError, "module name is too long"); |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
847 return NULL; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
848 } |
|
8934
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
849 strcpy(name, realname); |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
850 |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
851 if (path != NULL && PyString_Check(path)) { |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
852 /* Submodule of "frozen" package: |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
853 Set name to the fullname, path to NULL |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
854 and continue as "usual" */ |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
855 if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) { |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
856 PyErr_SetString(PyExc_ImportError, |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
857 "full frozen module name too long"); |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
858 return NULL; |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
859 } |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
860 strcpy(buf, PyString_AsString(path)); |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
861 strcat(buf, "."); |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
862 strcat(buf, name); |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
863 strcpy(name, buf); |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
864 path = NULL; |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
865 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
866 if (path == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
867 if (is_builtin(name)) { |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
868 strcpy(buf, name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
869 return &fd_builtin; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
870 } |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
871 if ((f = find_frozen(name)) != NULL) { |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
872 strcpy(buf, name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
873 return &fd_frozen; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
874 } |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
875 |
|
4111
90216e907345
PYTHONWIN -> MS_COREDLL
Guido van Rossum <guido@python.org>
parents:
3964
diff
changeset
|
876 #ifdef MS_COREDLL |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
877 fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
878 if (fp != NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
879 *p_fp = fp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
880 return fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
881 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
882 #endif |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
883 path = PySys_GetObject("path"); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
884 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
885 if (path == NULL || !PyList_Check(path)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
886 PyErr_SetString(PyExc_ImportError, |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
887 "sys.path must be a list of directory names"); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
888 return NULL; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
889 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
890 npath = PyList_Size(path); |
|
1905
61c3c1a2fdb4
Fix various potential buffer overrun problems.
Guido van Rossum <guido@python.org>
parents:
1886
diff
changeset
|
891 namelen = strlen(name); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
892 for (i = 0; i < npath; i++) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
893 PyObject *v = PyList_GetItem(path, i); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
894 if (!PyString_Check(v)) |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
895 continue; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
896 len = PyString_Size(v); |
|
5894
e2df95b7be78
Removed some variables that are used to exchange data between import.c and
Guido van Rossum <guido@python.org>
parents:
5758
diff
changeset
|
897 if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) |
|
1905
61c3c1a2fdb4
Fix various potential buffer overrun problems.
Guido van Rossum <guido@python.org>
parents:
1886
diff
changeset
|
898 continue; /* Too long */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
899 strcpy(buf, PyString_AsString(v)); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
900 if (strlen(buf) != len) |
|
1905
61c3c1a2fdb4
Fix various potential buffer overrun problems.
Guido van Rossum <guido@python.org>
parents:
1886
diff
changeset
|
901 continue; /* v contains '\0' */ |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
902 #ifdef macintosh |
|
5980
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
903 #ifdef INTERN_STRINGS |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
904 /* |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
905 ** Speedup: each sys.path item is interned, and |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
906 ** FindResourceModule remembers which items refer to |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
907 ** folders (so we don't have to bother trying to look |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
908 ** into them for resources). |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
909 */ |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
910 PyString_InternInPlace(&PyList_GET_ITEM(path, i)); |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
911 v = PyList_GET_ITEM(path, i); |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
912 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
913 if (PyMac_FindResourceModule((PyStringObject *)v, name, buf)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
914 static struct filedescr resfiledescr = |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
915 {"", "", PY_RESOURCE}; |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
916 |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
917 return &resfiledescr; |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
918 } |
|
8845
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
919 if (PyMac_FindCodeResourceModule((PyStringObject *)v, name, buf)) { |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
920 static struct filedescr resfiledescr = |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
921 {"", "", PY_CODERESOURCE}; |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
922 |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
923 return &resfiledescr; |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
924 } |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
925 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
926 if (len > 0 && buf[len-1] != SEP |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
927 #ifdef ALTSEP |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
928 && buf[len-1] != ALTSEP |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
929 #endif |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
930 ) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
931 buf[len++] = SEP; |
|
3590
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
932 #ifdef IMPORT_8x3_NAMES |
|
6907
9ec6e0a8f353
Oops! Should've renamed dos_8x3 to dos-8x3 here, too.
Guido van Rossum <guido@python.org>
parents:
6762
diff
changeset
|
933 /* see if we are searching in directory dos-8x3 */ |
|
9ec6e0a8f353
Oops! Should've renamed dos_8x3 to dos-8x3 here, too.
Guido van Rossum <guido@python.org>
parents:
6762
diff
changeset
|
934 if (len > 7 && !strncmp(buf + len - 8, "dos-8x3", 7)){ |
|
3590
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
935 int j; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
936 char ch; /* limit name to 8 lower-case characters */ |
|
3590
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
937 for (j = 0; (ch = name[j]) && j < 8; j++) |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
938 if (isupper(ch)) |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
939 buf[len++] = tolower(ch); |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
940 else |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
941 buf[len++] = ch; |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
942 } |
|
6907
9ec6e0a8f353
Oops! Should've renamed dos_8x3 to dos-8x3 here, too.
Guido van Rossum <guido@python.org>
parents:
6762
diff
changeset
|
943 else /* Not in dos-8x3, use the full name */ |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3696
diff
changeset
|
944 #endif |
|
3696
67390c1daebe
Cosmetic change to the dox_8x3 hack.
Guido van Rossum <guido@python.org>
parents:
3683
diff
changeset
|
945 { |
|
3590
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
946 strcpy(buf+len, name); |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
947 len += namelen; |
|
73664ea2030e
moved verbose decl to pydebug.h; added dos_8x3 feature
Guido van Rossum <guido@python.org>
parents:
3557
diff
changeset
|
948 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
949 #ifdef HAVE_STAT |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
950 if (stat(buf, &statbuf) == 0) { |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
951 if (S_ISDIR(statbuf.st_mode)) { |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
952 if (find_init_module(buf)) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
953 #ifdef CHECK_IMPORT_CASE |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
954 if (!check_case(buf, len, namelen, |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
955 name)) |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
956 return NULL; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
957 #endif |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
958 return &fd_package; |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
959 } |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
960 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
961 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
962 #else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
963 /* XXX How are you going to test for directories? */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
964 #endif |
|
6454
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
965 #ifdef macintosh |
|
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
966 fdp = PyMac_FindModuleExtension(buf, &len, name); |
|
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
967 if (fdp) |
|
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
968 fp = fopen(buf, fdp->mode); |
|
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
969 #else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
970 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
971 strcpy(buf+len, fdp->suffix); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
972 if (Py_VerboseFlag > 1) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
973 PySys_WriteStderr("# trying %s\n", buf); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
974 fp = fopen(buf, fdp->mode); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
975 if (fp != NULL) |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
976 break; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
977 } |
|
5980
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
978 #endif /* !macintosh */ |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
979 if (fp != NULL) |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
980 break; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
981 } |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
982 if (fp == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
983 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
984 "No module named %.200s", name); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
985 return NULL; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
986 } |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
987 #ifdef CHECK_IMPORT_CASE |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
988 if (!check_case(buf, len, namelen, name)) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
989 fclose(fp); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
990 return NULL; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
991 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
992 #endif |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
993 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
994 *p_fp = fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
995 return fdp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
996 } |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
997 |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
998 #ifdef CHECK_IMPORT_CASE |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
999 |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1000 #ifdef MS_WIN32 |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1001 #include <windows.h> |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1002 #include <ctype.h> |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1003 |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1004 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1005 allcaps8x3(char *s) |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1006 { |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1007 /* Return 1 if s is an 8.3 filename in ALLCAPS */ |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1008 char c; |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1009 char *dot = strchr(s, '.'); |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1010 char *end = strchr(s, '\0'); |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1011 if (dot != NULL) { |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1012 if (dot-s > 8) |
|
12536
cc05edcccf52
Robin Becker: The following patch seems to fix a module case bug in
Guido van Rossum <guido@python.org>
parents:
12531
diff
changeset
|
1013 return 0; /* More than 8 before '.' */ |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1014 if (end-dot > 4) |
|
12536
cc05edcccf52
Robin Becker: The following patch seems to fix a module case bug in
Guido van Rossum <guido@python.org>
parents:
12531
diff
changeset
|
1015 return 0; /* More than 3 after '.' */ |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1016 end = strchr(dot+1, '.'); |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1017 if (end != NULL) |
|
12536
cc05edcccf52
Robin Becker: The following patch seems to fix a module case bug in
Guido van Rossum <guido@python.org>
parents:
12531
diff
changeset
|
1018 return 0; /* More than one dot */ |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1019 } |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1020 else if (end-s > 8) |
|
12536
cc05edcccf52
Robin Becker: The following patch seems to fix a module case bug in
Guido van Rossum <guido@python.org>
parents:
12531
diff
changeset
|
1021 return 0; /* More than 8 and no dot */ |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1022 while ((c = *s++)) { |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1023 if (islower(c)) |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1024 return 0; |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1025 } |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1026 return 1; |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1027 } |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1028 |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1029 static int |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1030 check_case(char *buf, int len, int namelen, char *name) |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1031 { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1032 WIN32_FIND_DATA data; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1033 HANDLE h; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1034 if (getenv("PYTHONCASEOK") != NULL) |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1035 return 1; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1036 h = FindFirstFile(buf, &data); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1037 if (h == INVALID_HANDLE_VALUE) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1038 PyErr_Format(PyExc_NameError, |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1039 "Can't find file for module %.100s\n(filename %.300s)", |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1040 name, buf); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1041 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1042 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1043 FindClose(h); |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1044 if (allcaps8x3(data.cFileName)) { |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1045 /* Skip the test if the filename is ALL.CAPS. This can |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1046 happen in certain circumstances beyond our control, |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1047 e.g. when software is installed under NT on a FAT |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1048 filesystem and then the same FAT filesystem is used |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1049 under Windows 95. */ |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1050 return 1; |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1051 } |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1052 if (strncmp(data.cFileName, name, namelen) != 0) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1053 strcpy(buf+len-namelen, data.cFileName); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1054 PyErr_Format(PyExc_NameError, |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1055 "Case mismatch for module name %.100s\n(filename %.300s)", |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1056 name, buf); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1057 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1058 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1059 return 1; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1060 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1061 #endif /* MS_WIN32 */ |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1062 |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1063 #ifdef macintosh |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1064 #include <TextUtils.h> |
|
12476
3500c4350f62
Jack Jansen: The new version of the GUSI i/o library on the Macintosh
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1065 #ifdef USE_GUSI1 |
|
9096
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1066 #include "TFileSpec.h" /* for Path2FSSpec() */ |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1067 #endif |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1068 static int |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1069 check_case(char *buf, int len, int namelen, char *name) |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1070 { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1071 FSSpec fss; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1072 OSErr err; |
|
12476
3500c4350f62
Jack Jansen: The new version of the GUSI i/o library on the Macintosh
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1073 #ifndef USE_GUSI1 |
|
9096
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1074 err = FSMakeFSSpec(0, 0, Pstring(buf), &fss); |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1075 #else |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1076 /* GUSI's Path2FSSpec() resolves all possible aliases nicely on |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1077 the way, which is fine for all directories, but here we need |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1078 the original name of the alias file (say, Dlg.ppc.slb, not |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1079 toolboxmodules.ppc.slb). */ |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1080 char *colon; |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1081 err = Path2FSSpec(buf, &fss); |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1082 if (err == noErr) { |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1083 colon = strrchr(buf, ':'); /* find filename */ |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1084 if (colon != NULL) |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1085 err = FSMakeFSSpec(fss.vRefNum, fss.parID, |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1086 Pstring(colon+1), &fss); |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1087 else |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1088 err = FSMakeFSSpec(fss.vRefNum, fss.parID, |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1089 fss.name, &fss); |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1090 } |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1091 #endif |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1092 if (err) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1093 PyErr_Format(PyExc_NameError, |
|
9096
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1094 "Can't find file for module %.100s\n(filename %.300s)", |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1095 name, buf); |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1096 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1097 } |
|
13266
4c4e95147258
Jack Jansen, Mac patch:
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
1098 if ( namelen > fss.name[0] || strncmp(name, (char *)fss.name+1, namelen) != 0 ) { |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1099 PyErr_Format(PyExc_NameError, |
|
9096
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1100 "Case mismatch for module name %.100s\n(filename %.300s)", |
|
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1101 name, fss.name); |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1102 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1103 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1104 return 1; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1105 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1106 #endif /* macintosh */ |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1107 |
|
7305
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1108 #ifdef DJGPP |
|
7367
0c79cafec4bc
Small patches to the DJGPP version of check_case().
Guido van Rossum <guido@python.org>
parents:
7305
diff
changeset
|
1109 #include <dir.h> |
|
0c79cafec4bc
Small patches to the DJGPP version of check_case().
Guido van Rossum <guido@python.org>
parents:
7305
diff
changeset
|
1110 |
|
7305
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1111 static int |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1112 check_case(char *buf, int len, int namelen, char *name) |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1113 { |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1114 struct ffblk ffblk; |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1115 int done; |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1116 |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1117 if (getenv("PYTHONCASEOK") != NULL) |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1118 return 1; |
|
7367
0c79cafec4bc
Small patches to the DJGPP version of check_case().
Guido van Rossum <guido@python.org>
parents:
7305
diff
changeset
|
1119 done = findfirst(buf, &ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC); |
|
7305
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1120 if (done) { |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1121 PyErr_Format(PyExc_NameError, |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1122 "Can't find file for module %.100s\n(filename %.300s)", |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1123 name, buf); |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1124 return 0; |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1125 } |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1126 |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1127 if (strncmp(ffblk.ff_name, name, namelen) != 0) { |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1128 strcpy(buf+len-namelen, ffblk.ff_name); |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1129 PyErr_Format(PyExc_NameError, |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1130 "Case mismatch for module name %.100s\n(filename %.300s)", |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1131 name, buf); |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1132 return 0; |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1133 } |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1134 return 1; |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1135 } |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1136 #endif |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1137 |
|
7987
697df93e5ddb
Comment out a label on an #endif.
Guido van Rossum <guido@python.org>
parents:
7979
diff
changeset
|
1138 #endif /* CHECK_IMPORT_CASE */ |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1139 |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1140 #ifdef HAVE_STAT |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1141 /* Helper to look for __init__.py or __init__.py[co] in potential package */ |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1142 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1143 find_init_module(char *buf) |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1144 { |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1145 size_t save_len = strlen(buf); |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1146 size_t i = save_len; |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1147 struct stat statbuf; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1148 |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1149 if (save_len + 13 >= MAXPATHLEN) |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1150 return 0; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1151 buf[i++] = SEP; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1152 strcpy(buf+i, "__init__.py"); |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1153 if (stat(buf, &statbuf) == 0) { |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1154 buf[save_len] = '\0'; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1155 return 1; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1156 } |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1157 i += strlen(buf+i); |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1158 if (Py_OptimizeFlag) |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1159 strcpy(buf+i, "o"); |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1160 else |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1161 strcpy(buf+i, "c"); |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1162 if (stat(buf, &statbuf) == 0) { |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1163 buf[save_len] = '\0'; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1164 return 1; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1165 } |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1166 buf[save_len] = '\0'; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1167 return 0; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1168 } |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1169 #endif /* HAVE_STAT */ |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1170 |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
1171 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1172 static int init_builtin(char *); /* Forward */ |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1173 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1174 /* Load an external module using the default search path and return |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1175 its module object WITH INCREMENTED REFERENCE COUNT */ |
| 86 | 1176 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1177 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1178 load_module(char *name, FILE *fp, char *buf, int type) |
| 86 | 1179 { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1180 PyObject *modules; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1181 PyObject *m; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1182 int err; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1183 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1184 /* First check that there's an open file (if we need one) */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1185 switch (type) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1186 case PY_SOURCE: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1187 case PY_COMPILED: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1188 if (fp == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1189 PyErr_Format(PyExc_ValueError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1190 "file object required for import (type code %d)", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1191 type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1192 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1193 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1194 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1195 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1196 switch (type) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1197 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1198 case PY_SOURCE: |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1199 m = load_source_module(name, buf, fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1200 break; |
| 6 | 1201 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1202 case PY_COMPILED: |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1203 m = load_compiled_module(name, buf, fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1204 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1205 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
1206 #ifdef HAVE_DYNAMIC_LOADING |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1207 case C_EXTENSION: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1208 m = _PyImport_LoadDynamicModule(name, buf, fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1209 break; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
1210 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1211 |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
1212 #ifdef macintosh |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
1213 case PY_RESOURCE: |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
1214 m = PyMac_LoadResourceModule(name, buf); |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
1215 break; |
|
8845
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1216 case PY_CODERESOURCE: |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1217 m = PyMac_LoadCodeResourceModule(name, buf); |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1218 break; |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
1219 #endif |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
1220 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1221 case PKG_DIRECTORY: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1222 m = load_package(name, buf); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1223 break; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1224 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1225 case C_BUILTIN: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1226 case PY_FROZEN: |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1227 if (buf != NULL && buf[0] != '\0') |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1228 name = buf; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1229 if (type == C_BUILTIN) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1230 err = init_builtin(name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1231 else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1232 err = PyImport_ImportFrozenModule(name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1233 if (err < 0) |
|
6299
0054a3840a75
Crrected a flow control error that caused the wrong error message when
Guido van Rossum <guido@python.org>
parents:
6285
diff
changeset
|
1234 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1235 if (err == 0) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1236 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1237 "Purported %s module %.200s not found", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1238 type == C_BUILTIN ? |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1239 "builtin" : "frozen", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1240 name); |
|
6299
0054a3840a75
Crrected a flow control error that caused the wrong error message when
Guido van Rossum <guido@python.org>
parents:
6285
diff
changeset
|
1241 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1242 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1243 modules = PyImport_GetModuleDict(); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1244 m = PyDict_GetItemString(modules, name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1245 if (m == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1246 PyErr_Format( |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1247 PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1248 "%s module %.200s not properly initialized", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1249 type == C_BUILTIN ? |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1250 "builtin" : "frozen", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1251 name); |
|
6299
0054a3840a75
Crrected a flow control error that caused the wrong error message when
Guido van Rossum <guido@python.org>
parents:
6285
diff
changeset
|
1252 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1253 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1254 Py_INCREF(m); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1255 break; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1256 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1257 default: |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1258 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1259 "Don't know how to import %.200s (type code %d)", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1260 name, type); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1261 m = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1262 |
|
141
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1263 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1264 |
| 6 | 1265 return m; |
| 1266 } | |
|
40
f28ac7f621c7
Added reload() functionality.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
1267 |
| 86 | 1268 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1269 /* Initialize a built-in module. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1270 Return 1 for succes, 0 if the module is not found, and -1 with |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1271 an exception set if the initialization failed. */ |
|
141
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1272 |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1273 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1274 init_builtin(char *name) |
|
141
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1275 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1276 struct _inittab *p; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1277 PyObject *mod; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1278 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1279 if ((mod = _PyImport_FindExtension(name, name)) != NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1280 return 1; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1281 |
|
6541
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
1282 for (p = PyImport_Inittab; p->name != NULL; p++) { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1283 if (strcmp(name, p->name) == 0) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1284 if (p->initfunc == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1285 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1286 "Cannot re-init internal module %.200s", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1287 name); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1288 return -1; |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1289 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1290 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
1291 PySys_WriteStderr("import %s # builtin\n", name); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1292 (*p->initfunc)(); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1293 if (PyErr_Occurred()) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1294 return -1; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1295 if (_PyImport_FixupExtension(name, name) == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1296 return -1; |
|
141
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1297 return 1; |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1298 } |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1299 } |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1300 return 0; |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1301 } |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1302 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1303 |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1304 /* Frozen modules */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1305 |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1306 static struct _frozen * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1307 find_frozen(char *name) |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1308 { |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1309 struct _frozen *p; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1310 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1311 for (p = PyImport_FrozenModules; ; p++) { |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1312 if (p->name == NULL) |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1313 return NULL; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1314 if (strcmp(p->name, name) == 0) |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1315 break; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1316 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1317 return p; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1318 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1319 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1320 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1321 get_frozen_object(char *name) |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1322 { |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1323 struct _frozen *p = find_frozen(name); |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1324 int size; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1325 |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1326 if (p == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1327 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1328 "No such frozen object named %.200s", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1329 name); |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1330 return NULL; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1331 } |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1332 size = p->size; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1333 if (size < 0) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1334 size = -size; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1335 return PyMarshal_ReadObjectFromString((char *)p->code, size); |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1336 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1337 |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1338 /* Initialize a frozen module. |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1339 Return 1 for succes, 0 if the module is not found, and -1 with |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1340 an exception set if the initialization failed. |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1341 This function is also used from frozenmain.c */ |
|
2294
6263e2fd9398
init_frozen non-static, frozenmain.c not in Makefile any more
Guido van Rossum <guido@python.org>
parents:
2270
diff
changeset
|
1342 |
|
6263e2fd9398
init_frozen non-static, frozenmain.c not in Makefile any more
Guido van Rossum <guido@python.org>
parents:
2270
diff
changeset
|
1343 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1344 PyImport_ImportFrozenModule(char *name) |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1345 { |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1346 struct _frozen *p = find_frozen(name); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1347 PyObject *co; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1348 PyObject *m; |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1349 int ispackage; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1350 int size; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1351 |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1352 if (p == NULL) |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1353 return 0; |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1354 size = p->size; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1355 ispackage = (size < 0); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1356 if (ispackage) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1357 size = -size; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1358 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
1359 PySys_WriteStderr("import %s # frozen%s\n", |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1360 name, ispackage ? " package" : ""); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1361 co = PyMarshal_ReadObjectFromString((char *)p->code, size); |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1362 if (co == NULL) |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1363 return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1364 if (!PyCode_Check(co)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1365 Py_DECREF(co); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1366 PyErr_Format(PyExc_TypeError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1367 "frozen object %.200s is not a code object", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1368 name); |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1369 return -1; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1370 } |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1371 if (ispackage) { |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1372 /* Set __path__ to the package name */ |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1373 PyObject *d, *s; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1374 int err; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1375 m = PyImport_AddModule(name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1376 if (m == NULL) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1377 return -1; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1378 d = PyModule_GetDict(m); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1379 s = PyString_InternFromString(name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1380 if (s == NULL) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1381 return -1; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1382 err = PyDict_SetItemString(d, "__path__", s); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1383 Py_DECREF(s); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1384 if (err != 0) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1385 return err; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1386 } |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
1387 m = PyImport_ExecCodeModuleEx(name, co, "<frozen>"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1388 Py_DECREF(co); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1389 if (m == NULL) |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1390 return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1391 Py_DECREF(m); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1392 return 1; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1393 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1394 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1395 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1396 /* Import a module, either built-in, frozen, or external, and return |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1397 its module object WITH INCREMENTED REFERENCE COUNT */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1398 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1399 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1400 PyImport_ImportModule(char *name) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1401 { |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1402 static PyObject *fromlist = NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1403 if (fromlist == NULL && strchr(name, '.') != NULL) { |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14163
diff
changeset
|
1404 fromlist = Py_BuildValue("(s)", "*"); |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1405 if (fromlist == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1406 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1407 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1408 return PyImport_ImportModuleEx(name, NULL, NULL, fromlist); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1409 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1410 |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1411 /* Forward declarations for helper routines */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1412 static PyObject *get_parent(PyObject *globals, char *buf, int *p_buflen); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1413 static PyObject *load_next(PyObject *mod, PyObject *altmod, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1414 char **p_name, char *buf, int *p_buflen); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1415 static int mark_miss(char *name); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1416 static int ensure_fromlist(PyObject *mod, PyObject *fromlist, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1417 char *buf, int buflen, int recursive); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1418 static PyObject * import_submodule(PyObject *mod, char *name, char *fullname); |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1419 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1420 /* The Magnum Opus of dotted-name import :-) */ |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1421 |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1422 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1423 import_module_ex(char *name, PyObject *globals, PyObject *locals, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1424 PyObject *fromlist) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1425 { |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1426 char buf[MAXPATHLEN+1]; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1427 int buflen = 0; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1428 PyObject *parent, *head, *next, *tail; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1429 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1430 parent = get_parent(globals, buf, &buflen); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1431 if (parent == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1432 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1433 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1434 head = load_next(parent, Py_None, &name, buf, &buflen); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1435 if (head == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1436 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1437 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1438 tail = head; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1439 Py_INCREF(tail); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1440 while (name) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1441 next = load_next(tail, tail, &name, buf, &buflen); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1442 Py_DECREF(tail); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1443 if (next == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1444 Py_DECREF(head); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1445 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1446 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1447 tail = next; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1448 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1449 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1450 if (fromlist != NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1451 if (fromlist == Py_None || !PyObject_IsTrue(fromlist)) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1452 fromlist = NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1453 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1454 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1455 if (fromlist == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1456 Py_DECREF(tail); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1457 return head; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1458 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1459 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1460 Py_DECREF(head); |
|
6285
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1461 if (!ensure_fromlist(tail, fromlist, buf, buflen, 0)) { |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1462 Py_DECREF(tail); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1463 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1464 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1465 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1466 return tail; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1467 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1468 |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1469 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1470 PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1471 PyObject *fromlist) |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1472 { |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1473 PyObject *result; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1474 lock_import(); |
|
7535
13b60abdb70d
Oops -- overuse of dabbrev-expand introduced a strange bug, where
Guido van Rossum <guido@python.org>
parents:
7533
diff
changeset
|
1475 result = import_module_ex(name, globals, locals, fromlist); |
|
7533
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1476 unlock_import(); |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1477 return result; |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1478 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1479 |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1480 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1481 get_parent(PyObject *globals, char *buf, int *p_buflen) |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1482 { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1483 static PyObject *namestr = NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1484 static PyObject *pathstr = NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1485 PyObject *modname, *modpath, *modules, *parent; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1486 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1487 if (globals == NULL || !PyDict_Check(globals)) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1488 return Py_None; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1489 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1490 if (namestr == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1491 namestr = PyString_InternFromString("__name__"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1492 if (namestr == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1493 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1494 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1495 if (pathstr == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1496 pathstr = PyString_InternFromString("__path__"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1497 if (pathstr == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1498 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1499 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1500 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1501 *buf = '\0'; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1502 *p_buflen = 0; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1503 modname = PyDict_GetItem(globals, namestr); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1504 if (modname == NULL || !PyString_Check(modname)) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1505 return Py_None; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1506 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1507 modpath = PyDict_GetItem(globals, pathstr); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1508 if (modpath != NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1509 int len = PyString_GET_SIZE(modname); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1510 if (len > MAXPATHLEN) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1511 PyErr_SetString(PyExc_ValueError, |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1512 "Module name too long"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1513 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1514 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1515 strcpy(buf, PyString_AS_STRING(modname)); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1516 *p_buflen = len; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1517 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1518 else { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1519 char *start = PyString_AS_STRING(modname); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1520 char *lastdot = strrchr(start, '.'); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1521 size_t len; |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1522 if (lastdot == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1523 return Py_None; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1524 len = lastdot - start; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1525 if (len >= MAXPATHLEN) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1526 PyErr_SetString(PyExc_ValueError, |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1527 "Module name too long"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1528 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1529 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1530 strncpy(buf, start, len); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1531 buf[len] = '\0'; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1532 *p_buflen = len; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1533 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1534 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1535 modules = PyImport_GetModuleDict(); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1536 parent = PyDict_GetItemString(modules, buf); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1537 if (parent == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1538 parent = Py_None; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1539 return parent; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1540 /* We expect, but can't guarantee, if parent != None, that: |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1541 - parent.__name__ == buf |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1542 - parent.__dict__ is globals |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1543 If this is violated... Who cares? */ |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1544 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1545 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1546 /* altmod is either None or same as mod */ |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1547 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1548 load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1549 int *p_buflen) |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1550 { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1551 char *name = *p_name; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1552 char *dot = strchr(name, '.'); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1553 size_t len; |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1554 char *p; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1555 PyObject *result; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1556 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1557 if (dot == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1558 *p_name = NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1559 len = strlen(name); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1560 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1561 else { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1562 *p_name = dot+1; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1563 len = dot-name; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1564 } |
|
8012
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1565 if (len == 0) { |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1566 PyErr_SetString(PyExc_ValueError, |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1567 "Empty module name"); |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1568 return NULL; |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1569 } |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1570 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1571 p = buf + *p_buflen; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1572 if (p != buf) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1573 *p++ = '.'; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1574 if (p+len-buf >= MAXPATHLEN) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1575 PyErr_SetString(PyExc_ValueError, |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1576 "Module name too long"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1577 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1578 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1579 strncpy(p, name, len); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1580 p[len] = '\0'; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1581 *p_buflen = p+len-buf; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1582 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1583 result = import_submodule(mod, p, buf); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1584 if (result == Py_None && altmod != mod) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1585 Py_DECREF(result); |
|
6252
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1586 /* Here, altmod must be None and mod must not be None */ |
|
6256
ce2092714484
Bugfix: import A.B from inside package was busted by mark_miss optimization.
Guido van Rossum <guido@python.org>
parents:
6252
diff
changeset
|
1587 result = import_submodule(altmod, p, p); |
|
6252
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1588 if (result != NULL && result != Py_None) { |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1589 if (mark_miss(buf) != 0) { |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1590 Py_DECREF(result); |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1591 return NULL; |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1592 } |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1593 strncpy(buf, name, len); |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1594 buf[len] = '\0'; |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1595 *p_buflen = len; |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1596 } |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1597 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1598 if (result == NULL) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1599 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1600 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1601 if (result == Py_None) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1602 Py_DECREF(result); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1603 PyErr_Format(PyExc_ImportError, |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1604 "No module named %.200s", name); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1605 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1606 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1607 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1608 return result; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1609 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1610 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1611 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1612 mark_miss(char *name) |
|
6252
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1613 { |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1614 PyObject *modules = PyImport_GetModuleDict(); |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1615 return PyDict_SetItemString(modules, name, Py_None); |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1616 } |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1617 |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1618 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1619 ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, int buflen, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1620 int recursive) |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1621 { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1622 int i; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1623 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1624 if (!PyObject_HasAttrString(mod, "__path__")) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1625 return 1; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1626 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1627 for (i = 0; ; i++) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1628 PyObject *item = PySequence_GetItem(fromlist, i); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1629 int hasit; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1630 if (item == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1631 if (PyErr_ExceptionMatches(PyExc_IndexError)) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1632 PyErr_Clear(); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1633 return 1; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1634 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1635 return 0; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1636 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1637 if (!PyString_Check(item)) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1638 PyErr_SetString(PyExc_TypeError, |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1639 "Item in ``from list'' not a string"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1640 Py_DECREF(item); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1641 return 0; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1642 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1643 if (PyString_AS_STRING(item)[0] == '*') { |
|
6285
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1644 PyObject *all; |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1645 Py_DECREF(item); |
|
6285
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1646 /* See if the package defines __all__ */ |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1647 if (recursive) |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1648 continue; /* Avoid endless recursion */ |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1649 all = PyObject_GetAttrString(mod, "__all__"); |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1650 if (all == NULL) |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1651 PyErr_Clear(); |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1652 else { |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1653 if (!ensure_fromlist(mod, all, buf, buflen, 1)) |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1654 return 0; |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1655 Py_DECREF(all); |
|
337054e9d4fa
Added support for __all__, which should be a list of modules to be
Guido van Rossum <guido@python.org>
parents:
6256
diff
changeset
|
1656 } |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1657 continue; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1658 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1659 hasit = PyObject_HasAttr(mod, item); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1660 if (!hasit) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1661 char *subname = PyString_AS_STRING(item); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1662 PyObject *submod; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1663 char *p; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1664 if (buflen + strlen(subname) >= MAXPATHLEN) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1665 PyErr_SetString(PyExc_ValueError, |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1666 "Module name too long"); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1667 Py_DECREF(item); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1668 return 0; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1669 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1670 p = buf + buflen; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1671 *p++ = '.'; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1672 strcpy(p, subname); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1673 submod = import_submodule(mod, subname, buf); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1674 Py_XDECREF(submod); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1675 if (submod == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1676 Py_DECREF(item); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1677 return 0; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1678 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1679 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1680 Py_DECREF(item); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1681 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1682 |
|
6375
b68185d94777
Remove unreachable "return 1" at end of ensure_fromlist().
Guido van Rossum <guido@python.org>
parents:
6305
diff
changeset
|
1683 /* NOTREACHED */ |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1684 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1685 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1686 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1687 import_submodule(PyObject *mod, char *subname, char *fullname) |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1688 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1689 PyObject *modules = PyImport_GetModuleDict(); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1690 PyObject *m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1691 |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1692 /* Require: |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1693 if mod == None: subname == fullname |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1694 else: mod.__name__ + "." + subname == fullname |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1695 */ |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1696 |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1697 if ((m = PyDict_GetItemString(modules, fullname)) != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1698 Py_INCREF(m); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1699 } |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1700 else { |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1701 PyObject *path; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1702 char buf[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1703 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1704 FILE *fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1705 |
|
8374
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1706 if (mod == Py_None) |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1707 path = NULL; |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1708 else { |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1709 path = PyObject_GetAttrString(mod, "__path__"); |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1710 if (path == NULL) { |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1711 PyErr_Clear(); |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1712 Py_INCREF(Py_None); |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1713 return Py_None; |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1714 } |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1715 } |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1716 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1717 buf[0] = '\0'; |
|
8613
e3d3bbbd93f3
Fix two smal memory leaks discovered by Vadim Chugunov.
Guido van Rossum <guido@python.org>
parents:
8544
diff
changeset
|
1718 fdp = find_module(subname, path, buf, MAXPATHLEN+1, &fp); |
|
e3d3bbbd93f3
Fix two smal memory leaks discovered by Vadim Chugunov.
Guido van Rossum <guido@python.org>
parents:
8544
diff
changeset
|
1719 Py_XDECREF(path); |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1720 if (fdp == NULL) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1721 if (!PyErr_ExceptionMatches(PyExc_ImportError)) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1722 return NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1723 PyErr_Clear(); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1724 Py_INCREF(Py_None); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1725 return Py_None; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1726 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1727 m = load_module(fullname, fp, buf, fdp->type); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1728 if (fp) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1729 fclose(fp); |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1730 if (m != NULL && mod != Py_None) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1731 if (PyObject_SetAttrString(mod, subname, m) < 0) { |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1732 Py_DECREF(m); |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1733 m = NULL; |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1734 } |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1735 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1736 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1737 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1738 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1739 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1740 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1741 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1742 /* Re-import a module of any kind and return its module object, WITH |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1743 INCREMENTED REFERENCE COUNT */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1744 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1745 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1746 PyImport_ReloadModule(PyObject *m) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1747 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1748 PyObject *modules = PyImport_GetModuleDict(); |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1749 PyObject *path = NULL; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1750 char *name, *subname; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1751 char buf[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1752 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1753 FILE *fp = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1754 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1755 if (m == NULL || !PyModule_Check(m)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1756 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1757 "reload() argument must be module"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1758 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1759 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1760 name = PyModule_GetName(m); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1761 if (name == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1762 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1763 if (m != PyDict_GetItemString(modules, name)) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1764 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1765 "reload(): module %.200s not in sys.modules", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1766 name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1767 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1768 } |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1769 subname = strrchr(name, '.'); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1770 if (subname == NULL) |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1771 subname = name; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1772 else { |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1773 PyObject *parentname, *parent; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1774 parentname = PyString_FromStringAndSize(name, (subname-name)); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1775 if (parentname == NULL) |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1776 return NULL; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1777 parent = PyDict_GetItem(modules, parentname); |
|
9971
0390af6acf7f
PyImport_ReloadModule(): Nailed a small memory leak. In the
Barry Warsaw <barry@python.org>
parents:
9680
diff
changeset
|
1778 Py_DECREF(parentname); |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1779 if (parent == NULL) { |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1780 PyErr_Format(PyExc_ImportError, |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1781 "reload(): parent %.200s not in sys.modules", |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1782 name); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1783 return NULL; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1784 } |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1785 subname++; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1786 path = PyObject_GetAttrString(parent, "__path__"); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1787 if (path == NULL) |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1788 PyErr_Clear(); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1789 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1790 buf[0] = '\0'; |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1791 fdp = find_module(subname, path, buf, MAXPATHLEN+1, &fp); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
1792 Py_XDECREF(path); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1793 if (fdp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1794 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1795 m = load_module(name, fp, buf, fdp->type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1796 if (fp) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1797 fclose(fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1798 return m; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1799 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1800 |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1801 |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1802 /* Higher-level import emulator which emulates the "import" statement |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1803 more accurately -- it invokes the __import__() function from the |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1804 builtins of the current globals. This means that the import is |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1805 done using whatever import hooks are installed in the current |
|
9680
8b61e1273b4b
Improve comment for PyImport_Import() as suggested by Bill Tutt.
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1806 environment, e.g. by "rexec". |
|
8b61e1273b4b
Improve comment for PyImport_Import() as suggested by Bill Tutt.
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1807 A dummy list ["__doc__"] is passed as the 4th argument so that |
|
8b61e1273b4b
Improve comment for PyImport_Import() as suggested by Bill Tutt.
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1808 e.g. PyImport_Import(PyString_FromString("win32com.client.gencache")) |
|
8b61e1273b4b
Improve comment for PyImport_Import() as suggested by Bill Tutt.
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1809 will return <module "gencache"> instead of <module "win32com">. */ |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1810 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1811 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1812 PyImport_Import(PyObject *module_name) |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1813 { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1814 static PyObject *silly_list = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1815 static PyObject *builtins_str = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1816 static PyObject *import_str = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1817 static PyObject *standard_builtins = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1818 PyObject *globals = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1819 PyObject *import = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1820 PyObject *builtins = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1821 PyObject *r = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1822 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1823 /* Initialize constant string objects */ |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1824 if (silly_list == NULL) { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1825 import_str = PyString_InternFromString("__import__"); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1826 if (import_str == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1827 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1828 builtins_str = PyString_InternFromString("__builtins__"); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1829 if (builtins_str == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1830 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1831 silly_list = Py_BuildValue("[s]", "__doc__"); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1832 if (silly_list == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1833 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1834 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1835 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1836 /* Get the builtins from current globals */ |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1837 globals = PyEval_GetGlobals(); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1838 if(globals != NULL) { |
| 9431 | 1839 Py_INCREF(globals); |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1840 builtins = PyObject_GetItem(globals, builtins_str); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1841 if (builtins == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1842 goto err; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1843 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1844 else { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1845 /* No globals -- use standard builtins, and fake globals */ |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1846 PyErr_Clear(); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1847 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1848 if (standard_builtins == NULL) { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1849 standard_builtins = |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1850 PyImport_ImportModule("__builtin__"); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1851 if (standard_builtins == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1852 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1853 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1854 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1855 builtins = standard_builtins; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1856 Py_INCREF(builtins); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1857 globals = Py_BuildValue("{OO}", builtins_str, builtins); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1858 if (globals == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1859 goto err; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1860 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1861 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1862 /* Get the __import__ function from the builtins */ |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1863 if (PyDict_Check(builtins)) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1864 import=PyObject_GetItem(builtins, import_str); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1865 else |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1866 import=PyObject_GetAttr(builtins, import_str); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1867 if (import == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1868 goto err; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1869 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1870 /* Call the _import__ function with the proper argument list */ |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1871 r = PyObject_CallFunction(import, "OOOO", |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1872 module_name, globals, globals, silly_list); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1873 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1874 err: |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1875 Py_XDECREF(globals); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1876 Py_XDECREF(builtins); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1877 Py_XDECREF(import); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1878 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1879 return r; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1880 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1881 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
1882 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1883 /* Module 'imp' provides Python access to the primitives used for |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1884 importing modules. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1885 */ |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1886 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1887 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1888 imp_get_magic(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1889 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1890 char buf[4]; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1891 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
1892 if (!PyArg_ParseTuple(args, ":get_magic")) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1893 return NULL; |
| 12543 | 1894 buf[0] = (char) ((pyc_magic >> 0) & 0xff); |
| 1895 buf[1] = (char) ((pyc_magic >> 8) & 0xff); | |
| 1896 buf[2] = (char) ((pyc_magic >> 16) & 0xff); | |
| 1897 buf[3] = (char) ((pyc_magic >> 24) & 0xff); | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1898 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1899 return PyString_FromStringAndSize(buf, 4); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1900 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1901 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1902 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1903 imp_get_suffixes(PyObject *self, PyObject *args) |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1904 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1905 PyObject *list; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1906 struct filedescr *fdp; |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1907 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
1908 if (!PyArg_ParseTuple(args, ":get_suffixes")) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1909 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1910 list = PyList_New(0); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1911 if (list == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1912 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1913 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1914 PyObject *item = Py_BuildValue("ssi", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1915 fdp->suffix, fdp->mode, fdp->type); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1916 if (item == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1917 Py_DECREF(list); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1918 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1919 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1920 if (PyList_Append(list, item) < 0) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1921 Py_DECREF(list); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1922 Py_DECREF(item); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1923 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1924 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1925 Py_DECREF(item); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1926 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1927 return list; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1928 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1929 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1930 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1931 call_find_module(char *name, PyObject *path) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1932 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1933 extern int fclose(FILE *); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1934 PyObject *fob, *ret; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1935 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1936 char pathname[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1937 FILE *fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1938 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1939 pathname[0] = '\0'; |
|
6249
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1940 if (path == Py_None) |
|
f10aad73e029
Phase two of package import. "import a.b.c" and all variants now do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1941 path = NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1942 fdp = find_module(name, path, pathname, MAXPATHLEN+1, &fp); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1943 if (fdp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1944 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1945 if (fp != NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1946 fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1947 if (fob == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1948 fclose(fp); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1949 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1950 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1951 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1952 else { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1953 fob = Py_None; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1954 Py_INCREF(fob); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1955 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1956 ret = Py_BuildValue("Os(ssi)", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1957 fob, pathname, fdp->suffix, fdp->mode, fdp->type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1958 Py_DECREF(fob); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1959 return ret; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1960 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1961 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1962 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1963 imp_find_module(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1964 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1965 char *name; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1966 PyObject *path = NULL; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
1967 if (!PyArg_ParseTuple(args, "s|O:find_module", &name, &path)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1968 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1969 return call_find_module(name, path); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1970 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1971 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1972 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1973 imp_init_builtin(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1974 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1975 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1976 int ret; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1977 PyObject *m; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
1978 if (!PyArg_ParseTuple(args, "s:init_builtin", &name)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1979 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1980 ret = init_builtin(name); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1981 if (ret < 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1982 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1983 if (ret == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1984 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1985 return Py_None; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1986 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1987 m = PyImport_AddModule(name); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1988 Py_XINCREF(m); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1989 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1990 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1991 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1992 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1993 imp_init_frozen(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1994 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1995 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1996 int ret; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1997 PyObject *m; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
1998 if (!PyArg_ParseTuple(args, "s:init_frozen", &name)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1999 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2000 ret = PyImport_ImportFrozenModule(name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2001 if (ret < 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2002 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2003 if (ret == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2004 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2005 return Py_None; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2006 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2007 m = PyImport_AddModule(name); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2008 Py_XINCREF(m); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2009 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2010 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2011 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2012 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2013 imp_get_frozen_object(PyObject *self, PyObject *args) |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2014 { |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2015 char *name; |
| 3139 | 2016 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2017 if (!PyArg_ParseTuple(args, "s:get_frozen_object", &name)) |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2018 return NULL; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2019 return get_frozen_object(name); |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2020 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2021 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2022 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2023 imp_is_builtin(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2024 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2025 char *name; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2026 if (!PyArg_ParseTuple(args, "s:is_builtin", &name)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2027 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2028 return PyInt_FromLong(is_builtin(name)); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2029 } |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2030 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2031 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2032 imp_is_frozen(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2033 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2034 char *name; |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
2035 struct _frozen *p; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2036 if (!PyArg_ParseTuple(args, "s:is_frozen", &name)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2037 return NULL; |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
2038 p = find_frozen(name); |
|
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
2039 return PyInt_FromLong((long) (p == NULL ? 0 : p->size)); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2040 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2041 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2042 static FILE * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2043 get_file(char *pathname, PyObject *fob, char *mode) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2044 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2045 FILE *fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2046 if (fob == NULL) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2047 fp = fopen(pathname, mode); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2048 if (fp == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2049 PyErr_SetFromErrno(PyExc_IOError); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2050 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2051 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2052 fp = PyFile_AsFile(fob); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2053 if (fp == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2054 PyErr_SetString(PyExc_ValueError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2055 "bad/closed file object"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2056 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2057 return fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2058 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2059 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2060 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2061 imp_load_compiled(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2062 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2063 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2064 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2065 PyObject *fob = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2066 PyObject *m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2067 FILE *fp; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2068 if (!PyArg_ParseTuple(args, "ss|O!:load_compiled", &name, &pathname, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2069 &PyFile_Type, &fob)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2070 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2071 fp = get_file(pathname, fob, "rb"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2072 if (fp == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2073 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2074 m = load_compiled_module(name, pathname, fp); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2075 if (fob == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2076 fclose(fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2077 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2078 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2079 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2080 #ifdef HAVE_DYNAMIC_LOADING |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2081 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2082 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2083 imp_load_dynamic(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2084 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2085 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2086 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2087 PyObject *fob = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2088 PyObject *m; |
|
2812
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
2089 FILE *fp = NULL; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2090 if (!PyArg_ParseTuple(args, "ss|O!:load_dynamic", &name, &pathname, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2091 &PyFile_Type, &fob)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2092 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2093 if (fob) { |
|
2812
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
2094 fp = get_file(pathname, fob, "r"); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2095 if (fp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2096 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2097 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2098 m = _PyImport_LoadDynamicModule(name, pathname, fp); |
|
2812
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
2099 return m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2100 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2101 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2102 #endif /* HAVE_DYNAMIC_LOADING */ |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2103 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2104 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2105 imp_load_source(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2106 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2107 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2108 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2109 PyObject *fob = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2110 PyObject *m; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2111 FILE *fp; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2112 if (!PyArg_ParseTuple(args, "ss|O!:load_source", &name, &pathname, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2113 &PyFile_Type, &fob)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2114 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2115 fp = get_file(pathname, fob, "r"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2116 if (fp == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2117 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2118 m = load_source_module(name, pathname, fp); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2119 if (fob == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2120 fclose(fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2121 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2122 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2123 |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2124 #ifdef macintosh |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2125 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2126 imp_load_resource(PyObject *self, PyObject *args) |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2127 { |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2128 char *name; |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2129 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2130 PyObject *m; |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2131 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2132 if (!PyArg_ParseTuple(args, "ss:load_resource", &name, &pathname)) |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2133 return NULL; |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2134 m = PyMac_LoadResourceModule(name, pathname); |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2135 return m; |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2136 } |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2137 #endif /* macintosh */ |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2138 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2139 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2140 imp_load_module(PyObject *self, PyObject *args) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2141 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2142 char *name; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2143 PyObject *fob; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2144 char *pathname; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2145 char *suffix; /* Unused */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2146 char *mode; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2147 int type; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2148 FILE *fp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2149 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2150 if (!PyArg_ParseTuple(args, "sOs(ssi):load_module", |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2151 &name, &fob, &pathname, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2152 &suffix, &mode, &type)) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2153 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2154 if (*mode && (*mode != 'r' || strchr(mode, '+') != NULL)) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2155 PyErr_Format(PyExc_ValueError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2156 "invalid file open mode %.200s", mode); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2157 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2158 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2159 if (fob == Py_None) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2160 fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2161 else { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2162 if (!PyFile_Check(fob)) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2163 PyErr_SetString(PyExc_ValueError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2164 "load_module arg#2 should be a file or None"); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2165 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2166 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2167 fp = get_file(pathname, fob, mode); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2168 if (fp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2169 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2170 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2171 return load_module(name, fp, pathname, type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2172 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2173 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2174 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2175 imp_load_package(PyObject *self, PyObject *args) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2176 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2177 char *name; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2178 char *pathname; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2179 if (!PyArg_ParseTuple(args, "ss:load_package", &name, &pathname)) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2180 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2181 return load_package(name, pathname); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2182 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2183 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2184 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2185 imp_new_module(PyObject *self, PyObject *args) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2186 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2187 char *name; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2188 if (!PyArg_ParseTuple(args, "s:new_module", &name)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2189 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2190 return PyModule_New(name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2191 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2192 |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2193 /* Doc strings */ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2194 |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2195 static char doc_imp[] = "\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2196 This module provides the components needed to build your own\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2197 __import__ function. Undocumented functions are obsolete.\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2198 "; |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2199 |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2200 static char doc_find_module[] = "\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2201 find_module(name, [path]) -> (file, filename, (suffix, mode, type))\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2202 Search for a module. If path is omitted or None, search for a\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2203 built-in, frozen or special module and continue search in sys.path.\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2204 The module name cannot contain '.'; to search for a submodule of a\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2205 package, pass the submodule name and the package's __path__.\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2206 "; |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2207 |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2208 static char doc_load_module[] = "\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2209 load_module(name, file, filename, (suffix, mode, type)) -> module\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2210 Load a module, given information returned by find_module().\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2211 The module name must include the full package name, if any.\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2212 "; |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2213 |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2214 static char doc_get_magic[] = "\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2215 get_magic() -> string\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2216 Return the magic number for .pyc or .pyo files.\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2217 "; |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2218 |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2219 static char doc_get_suffixes[] = "\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2220 get_suffixes() -> [(suffix, mode, type), ...]\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2221 Return a list of (suffix, mode, type) tuples describing the files\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2222 that find_module() looks for.\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2223 "; |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2224 |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2225 static char doc_new_module[] = "\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2226 new_module(name) -> module\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2227 Create a new module. Do not enter it in sys.modules.\n\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2228 The module name must include the full package name, if any.\ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2229 "; |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2230 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2231 static PyMethodDef imp_methods[] = { |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2232 {"find_module", imp_find_module, 1, doc_find_module}, |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2233 {"get_magic", imp_get_magic, 1, doc_get_magic}, |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2234 {"get_suffixes", imp_get_suffixes, 1, doc_get_suffixes}, |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2235 {"load_module", imp_load_module, 1, doc_load_module}, |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2236 {"new_module", imp_new_module, 1, doc_new_module}, |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2237 /* The rest are obsolete */ |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2238 {"get_frozen_object", imp_get_frozen_object, 1}, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2239 {"init_builtin", imp_init_builtin, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2240 {"init_frozen", imp_init_frozen, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2241 {"is_builtin", imp_is_builtin, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2242 {"is_frozen", imp_is_frozen, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2243 {"load_compiled", imp_load_compiled, 1}, |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2244 #ifdef HAVE_DYNAMIC_LOADING |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2245 {"load_dynamic", imp_load_dynamic, 1}, |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2246 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2247 {"load_package", imp_load_package, 1}, |
|
2349
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2248 #ifdef macintosh |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2249 {"load_resource", imp_load_resource, 1}, |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2250 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2251 {"load_source", imp_load_source, 1}, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2252 {NULL, NULL} /* sentinel */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2253 }; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2254 |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8613
diff
changeset
|
2255 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2256 setint(PyObject *d, char *name, int value) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2257 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2258 PyObject *v; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2259 int err; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2260 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2261 v = PyInt_FromLong((long)value); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2262 err = PyDict_SetItemString(d, name, v); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2263 Py_XDECREF(v); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2264 return err; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2265 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2266 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2267 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2268 initimp(void) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2269 { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2270 PyObject *m, *d; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2271 |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2272 m = Py_InitModule4("imp", imp_methods, doc_imp, |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2273 NULL, PYTHON_API_VERSION); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2274 d = PyModule_GetDict(m); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2275 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2276 if (setint(d, "SEARCH_ERROR", SEARCH_ERROR) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2277 if (setint(d, "PY_SOURCE", PY_SOURCE) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2278 if (setint(d, "PY_COMPILED", PY_COMPILED) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2279 if (setint(d, "C_EXTENSION", C_EXTENSION) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2280 if (setint(d, "PY_RESOURCE", PY_RESOURCE) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2281 if (setint(d, "PKG_DIRECTORY", PKG_DIRECTORY) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2282 if (setint(d, "C_BUILTIN", C_BUILTIN) < 0) goto failure; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2283 if (setint(d, "PY_FROZEN", PY_FROZEN) < 0) goto failure; |
|
8845
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
2284 if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2285 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2286 failure: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2287 ; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2288 } |
|
8330
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2289 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2290 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2291 /* API for embedding applications that want to add their own entries |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2292 to the table of built-in modules. This should normally be called |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2293 *before* Py_Initialize(). When the table resize fails, -1 is |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2294 returned and the existing table is unchanged. |
|
8330
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2295 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2296 After a similar function by Just van Rossum. */ |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2297 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2298 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2299 PyImport_ExtendInittab(struct _inittab *newtab) |
|
8330
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2300 { |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2301 static struct _inittab *our_copy = NULL; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2302 struct _inittab *p; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2303 int i, n; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2304 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2305 /* Count the number of entries in both tables */ |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2306 for (n = 0; newtab[n].name != NULL; n++) |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2307 ; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2308 if (n == 0) |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2309 return 0; /* Nothing to do */ |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2310 for (i = 0; PyImport_Inittab[i].name != NULL; i++) |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2311 ; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2312 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2313 /* Allocate new memory for the combined table */ |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2314 p = our_copy; |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2315 PyMem_RESIZE(p, struct _inittab, i+n+1); |
|
8330
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2316 if (p == NULL) |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2317 return -1; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2318 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2319 /* Copy the tables into the new memory */ |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2320 if (our_copy != PyImport_Inittab) |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2321 memcpy(p, PyImport_Inittab, (i+1) * sizeof(struct _inittab)); |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2322 PyImport_Inittab = our_copy = p; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2323 memcpy(p+i, newtab, (n+1) * sizeof(struct _inittab)); |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2324 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2325 return 0; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2326 } |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2327 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2328 /* Shorthand to add a single entry given a name and a function */ |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2329 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2330 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2331 PyImport_AppendInittab(char *name, void (*initfunc)(void)) |
|
8330
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2332 { |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2333 struct _inittab newtab[2]; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2334 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2335 memset(newtab, '\0', sizeof newtab); |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2336 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2337 newtab[0].name = name; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2338 newtab[0].initfunc = initfunc; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2339 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2340 return PyImport_ExtendInittab(newtab); |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2341 } |
