Mercurial > cpython-lru_cache-weakref
annotate Python/import.c @ 24042:63fbbed10714 legacy-trunk
Simplify HTTPSConnection constructor.
See discussion in SF bug 458463.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Fri, 28 Jun 2002 23:38:14 +0000 |
| parents | 08475c87d24f |
| children | 8142f8d668a0 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
141
diff
changeset
|
1 |
| 6 | 2 /* Module definition and import implementation */ |
| 3 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
4 #include "Python.h" |
| 6 | 5 |
| 6 #include "node.h" | |
| 7 #include "token.h" | |
| 8 #include "errcode.h" | |
|
263
28f0ffd9facf
Support ".pyc" files: cached compilation results.
Guido van Rossum <guido@python.org>
parents:
228
diff
changeset
|
9 #include "marshal.h" |
|
28f0ffd9facf
Support ".pyc" files: cached compilation results.
Guido van Rossum <guido@python.org>
parents:
228
diff
changeset
|
10 #include "compile.h" |
| 926 | 11 #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
|
12 #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
|
13 #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
|
14 #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
|
15 #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
|
16 #endif |
|
263
28f0ffd9facf
Support ".pyc" files: cached compilation results.
Guido van Rossum <guido@python.org>
parents:
228
diff
changeset
|
17 |
|
14708
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
18 #ifdef HAVE_FCNTL_H |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
19 #include <fcntl.h> |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
20 #endif |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
21 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
22 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
|
23 /* 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
|
24 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
25 /* 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
|
26 /* 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
|
27 /* 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
|
28 a .pyc file in text mode the magic number will be wrong; also, the |
|
21010
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
29 Apple MPW compiler swaps their values, botching string constants. |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
30 XXX That probably isn't important anymore. |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
31 */ |
|
2812
fb3daf9b2456
new MAGIC; some changes to default files for imp.load_... functions
Guido van Rossum <guido@python.org>
parents:
2749
diff
changeset
|
32 /* 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
|
33 added to the .pyc file header? */ |
|
21010
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
34 /* New way to come up with the low 16 bits of the magic number: |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
35 (YEAR-1995) * 10000 + MONTH * 100 + DAY |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
36 where MONTH and DAY are 1-based. |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
37 XXX Whatever the "old way" may have been isn't documented. |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
38 XXX This scheme breaks in 2002, as (2002-1995)*10000 = 70000 doesn't |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
39 fit in 16 bits. |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
40 XXX Later, sometimes 1 gets added to MAGIC in order to record that |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
41 the Unicode -U option is in use. IMO (Tim's), that's a Bad Idea |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
42 (quite apart from that the -U option doesn't work so isn't used |
|
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
43 anyway). |
|
21886
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
44 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
45 XXX MAL, 2002-02-07: I had to modify the MAGIC due to a fix of the |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
46 UTF-8 encoder (it previously produced invalid UTF-8 for unpaired |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
47 high surrogates), so I simply bumped the month value to 20 (invalid |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
48 month) and set the day to 1. This should be recognizable by any |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
49 algorithm relying on the above scheme. Perhaps we should simply |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
50 start counting in increments of 10 from now on ?! |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
51 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
52 Known values: |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
53 Python 1.5: 20121 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
54 Python 1.5.1: 20121 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
55 Python 1.5.2: 20121 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
56 Python 2.0: 50823 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
57 Python 2.0.1: 50823 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
58 Python 2.1: 60202 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
59 Python 2.1.1: 60202 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
60 Python 2.1.2: 60202 |
|
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21712
diff
changeset
|
61 Python 2.2: 60717 |
|
23851
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
23832
diff
changeset
|
62 Python 2.3a0: 62011 |
|
21010
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
63 */ |
|
23851
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
23832
diff
changeset
|
64 #define MAGIC (62011 | ((long)'\r'<<16) | ((long)'\n'<<24)) |
|
487
77b80a91d357
New magic word; and check it.
Guido van Rossum <guido@python.org>
parents:
340
diff
changeset
|
65 |
| 12543 | 66 /* 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
|
67 value of this global to accommodate for alterations of how the |
| 12543 | 68 compiler works which are enabled by command line switches. */ |
| 69 static long pyc_magic = MAGIC; | |
| 70 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
71 /* 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
|
72 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
|
73 |
|
6541
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
74 /* 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
|
75 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
|
76 |
|
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
77 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
|
78 |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
79 /* 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
|
80 struct filedescr * _PyImport_Filetab = NULL; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
81 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
82 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
83 static const struct filedescr _PyImport_StandardFiletab[] = { |
|
23554
e5242f58a5b6
File modes in filedescr entries are also passed to Python, so we now put "U"
Jack Jansen <jack.jansen@cwi.nl>
parents:
23029
diff
changeset
|
84 {"/py", "U", PY_SOURCE}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
85 {"/pyc", "rb", PY_COMPILED}, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
86 {0, 0} |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
87 }; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
88 #else |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
89 static const struct filedescr _PyImport_StandardFiletab[] = { |
|
23554
e5242f58a5b6
File modes in filedescr entries are also passed to Python, so we now put "U"
Jack Jansen <jack.jansen@cwi.nl>
parents:
23029
diff
changeset
|
90 {".py", "U", PY_SOURCE}, |
|
18992
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
91 #ifdef MS_WIN32 |
|
23554
e5242f58a5b6
File modes in filedescr entries are also passed to Python, so we now put "U"
Jack Jansen <jack.jansen@cwi.nl>
parents:
23029
diff
changeset
|
92 {".pyw", "U", PY_SOURCE}, |
|
21010
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
93 #endif |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
94 {".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
|
95 {0, 0} |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
96 }; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
97 #endif |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
98 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
99 /* Initialize things */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
100 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
101 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
102 _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
|
103 { |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
104 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
|
105 struct filedescr *filetab; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
106 int countD = 0; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
107 int countS = 0; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
108 |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
109 /* 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
|
110 _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
|
111 */ |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
112 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
|
113 ++countD; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
114 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
|
115 ++countS; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
123 _PyImport_Filetab = filetab; |
|
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
124 |
|
5180
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
125 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
|
126 /* 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
|
127 for (; filetab->suffix != NULL; filetab++) { |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
128 #ifndef RISCOS |
|
11602
5738ad737114
In _PyImport_Init(), dynamically construct the table of legal suffixes
Guido van Rossum <guido@python.org>
parents:
10530
diff
changeset
|
129 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
|
130 filetab->suffix = ".pyo"; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
131 #else |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
132 if (strcmp(filetab->suffix, "/pyc") == 0) |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
133 filetab->suffix = "/pyo"; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
134 #endif |
|
5180
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
135 } |
|
6bc56259cc4c
When -O is given, use ".pyo" instead of ".pyc".
Guido van Rossum <guido@python.org>
parents:
5043
diff
changeset
|
136 } |
| 12543 | 137 |
| 138 if (Py_UnicodeFlag) { | |
| 139 /* Fix the pyc_magic so that byte compiled code created | |
| 140 using the all-Unicode method doesn't interfere with | |
| 141 code created in normal operation mode. */ | |
| 142 pyc_magic = MAGIC + 1; | |
| 143 } | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
144 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
145 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
146 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
147 _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
|
148 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
149 Py_XDECREF(extensions); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
150 extensions = NULL; |
|
14991
5d41ca49a10a
_PyImport_Fini(): Closed small memory leak when an embedded app calls
Barry Warsaw <barry@python.org>
parents:
14921
diff
changeset
|
151 PyMem_DEL(_PyImport_Filetab); |
|
5d41ca49a10a
_PyImport_Fini(): Closed small memory leak when an embedded app calls
Barry Warsaw <barry@python.org>
parents:
14921
diff
changeset
|
152 _PyImport_Filetab = NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
153 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
154 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
155 |
|
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 /* 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
|
157 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
|
158 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
|
159 |
|
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 #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
|
161 |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9187
diff
changeset
|
162 #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
|
163 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
168 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
169 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
|
170 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 } |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 } |
|
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 = 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
|
186 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
|
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 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
190 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
|
191 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9431
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
202 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
203 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
204 #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
|
205 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
206 #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
|
207 #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
|
208 |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
209 #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
|
210 |
|
19596
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
211 static PyObject * |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
212 imp_lock_held(PyObject *self, PyObject *args) |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
213 { |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
214 if (!PyArg_ParseTuple(args, ":lock_held")) |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
215 return NULL; |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
216 #ifdef WITH_THREAD |
|
22866
a561ff1b4ffa
Return bools from functions named is_<whatever>().
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
217 return PyBool_FromLong(import_lock_thread != -1); |
|
19596
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
218 #else |
|
22866
a561ff1b4ffa
Return bools from functions named is_<whatever>().
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
219 return PyBool_FromLong(0); |
|
19596
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
220 #endif |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
221 } |
|
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
222 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
223 /* Helper for sys */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
224 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
225 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
226 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
|
227 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 return interp->modules; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
232 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
233 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
234 |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
235 /* 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
|
236 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
|
237 "path", "argv", "ps1", "ps2", "exitfunc", |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
238 "exc_type", "exc_value", "exc_traceback", |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
239 "last_type", "last_value", "last_traceback", |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
240 NULL |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
241 }; |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
242 |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
243 static char* sys_files[] = { |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
244 "stdin", "__stdin__", |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
245 "stdout", "__stdout__", |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
246 "stderr", "__stderr__", |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
247 NULL |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
248 }; |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
249 |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
250 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
251 /* Un-initialize things, as good as we can */ |
| 86 | 252 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
253 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
254 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
|
255 { |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
256 int pos, ndone; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
257 char *name; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
258 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
|
259 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
|
260 PyObject *modules = interp->modules; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
261 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
262 if (modules == NULL) |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
263 return; /* Already done */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
264 |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
265 /* 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
|
266 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
|
267 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
|
268 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
|
269 destruction order. Sigh. */ |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
270 |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
271 value = PyDict_GetItemString(modules, "__builtin__"); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
272 if (value != NULL && PyModule_Check(value)) { |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
273 dict = PyModule_GetDict(value); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
274 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
275 PySys_WriteStderr("# clear __builtin__._\n"); |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
276 PyDict_SetItemString(dict, "_", Py_None); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
277 } |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
278 value = PyDict_GetItemString(modules, "sys"); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
279 if (value != NULL && PyModule_Check(value)) { |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
280 char **p; |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
281 PyObject *v; |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
282 dict = PyModule_GetDict(value); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
283 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
|
284 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
285 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
|
286 PyDict_SetItemString(dict, *p, Py_None); |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
287 } |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
288 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
|
289 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
290 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
|
291 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
|
292 if (v == NULL) |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
293 v = Py_None; |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
294 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
|
295 } |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
296 } |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
297 |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
298 /* First, delete __main__ */ |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
299 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
|
300 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
|
301 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
302 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
|
303 _PyModule_Clear(value); |
|
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
304 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
|
305 } |
|
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
306 |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
307 /* 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 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
|
319 re-imported. */ |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
320 |
|
7403
185c1d47ce7a
Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
Guido van Rossum <guido@python.org>
parents:
7367
diff
changeset
|
321 /* 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
|
322 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
|
323 do { |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
324 ndone = 0; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
325 pos = 0; |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 continue; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
333 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
|
334 continue; |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
335 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
336 PySys_WriteStderr( |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
337 "# 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
|
338 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
339 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
|
340 ndone++; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
341 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
342 } |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
343 } while (ndone > 0); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
344 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
345 /* 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
|
346 pos = 0; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 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
|
351 continue; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
352 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
|
353 continue; |
|
7202
fed3d200fb56
Two more refinements of the cleanup process.
Guido van Rossum <guido@python.org>
parents:
7111
diff
changeset
|
354 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
355 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
|
356 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
357 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
|
358 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
359 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
360 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
361 /* 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
|
362 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
|
363 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
|
364 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
365 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
|
366 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
367 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
|
368 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
369 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
|
370 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
|
371 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
372 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
|
373 _PyModule_Clear(value); |
|
7111
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
374 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
|
375 } |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
376 |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
377 /* 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
|
378 PyDict_Clear(modules); |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
379 interp->modules = NULL; |
|
f063f1eb2964
Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
Guido van Rossum <guido@python.org>
parents:
6907
diff
changeset
|
380 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
|
381 } |
|
166
28923e44254c
Added forward declaration (to satisfy Standard C).
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
382 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
383 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
384 /* 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
|
385 |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
386 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
387 PyImport_GetMagicNumber(void) |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
388 { |
| 12543 | 389 return pyc_magic; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
390 } |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1877
diff
changeset
|
391 |
| 6 | 392 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
393 /* 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
|
394 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
|
395 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
|
396 (for built-in modules) or by filename (for dynamically loaded |
|
19238
5b87ee44000b
Fixed typo in comment leading up to _PyImport_FixupExtension().
Barry Warsaw <barry@python.org>
parents:
19063
diff
changeset
|
397 modules), containing these modules. A copy of the module's |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
398 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
|
399 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
|
400 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
|
401 _PyImport_FindExtension(). */ |
| 6 | 402 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
403 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
404 _PyImport_FixupExtension(char *name, char *filename) |
| 6 | 405 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
406 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
|
407 if (extensions == NULL) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
408 extensions = PyDict_New(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
409 if (extensions == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
410 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
411 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
412 modules = PyImport_GetModuleDict(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
413 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
|
414 if (mod == NULL || !PyModule_Check(mod)) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
415 PyErr_Format(PyExc_SystemError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
416 "_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
|
417 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
418 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
419 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
|
420 if (dict == 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; |
|
20671
3fb403eaede1
Use PyDict_Copy() and PyDict_Update() instead of using PyObject_CallMethod()
Fred Drake <fdrake@acm.org>
parents:
20654
diff
changeset
|
422 copy = PyDict_Copy(dict); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
423 if (copy == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
424 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
425 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
|
426 Py_DECREF(copy); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
427 return copy; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
428 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
429 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
430 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
431 _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
|
432 { |
|
20671
3fb403eaede1
Use PyDict_Copy() and PyDict_Update() instead of using PyObject_CallMethod()
Fred Drake <fdrake@acm.org>
parents:
20654
diff
changeset
|
433 PyObject *dict, *mod, *mdict; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
434 if (extensions == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
435 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
436 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
|
437 if (dict == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
438 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
439 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
|
440 if (mod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
441 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
442 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
|
443 if (mdict == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
444 return NULL; |
|
20671
3fb403eaede1
Use PyDict_Copy() and PyDict_Update() instead of using PyObject_CallMethod()
Fred Drake <fdrake@acm.org>
parents:
20654
diff
changeset
|
445 if (PyDict_Update(mdict, dict)) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
446 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
447 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
448 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
|
449 name, filename); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
450 return mod; |
| 6 | 451 } |
| 452 | |
|
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 /* 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
|
455 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
|
456 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
|
457 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
|
458 '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
|
459 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
460 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
461 PyImport_AddModule(char *name) |
|
40
f28ac7f621c7
Added reload() functionality.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
462 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
463 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
|
464 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
|
465 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
466 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
|
467 PyModule_Check(m)) |
| 86 | 468 return m; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
469 m = PyModule_New(name); |
| 86 | 470 if (m == NULL) |
| 6 | 471 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
472 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
|
473 Py_DECREF(m); |
| 86 | 474 return NULL; |
| 6 | 475 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
476 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
|
477 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
478 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
479 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
480 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
481 |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
482 /* 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
|
483 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
|
484 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
485 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
486 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
|
487 { |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
488 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
|
489 } |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
490 |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
491 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
492 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
|
493 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
494 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
|
495 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
|
496 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
497 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
|
498 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
|
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 d = PyModule_GetDict(m); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
501 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
|
502 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
|
503 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
504 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
505 } |
|
3557
cee4a6d8415e
Remember source filename as <module>.__file__.
Guido van Rossum <guido@python.org>
parents:
3492
diff
changeset
|
506 /* 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
|
507 v = NULL; |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
508 if (pathname != NULL) { |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
509 v = PyString_FromString(pathname); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
510 if (v == NULL) |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
511 PyErr_Clear(); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
512 } |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
513 if (v == NULL) { |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
514 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
|
515 Py_INCREF(v); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
516 } |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
517 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
|
518 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
|
519 Py_DECREF(v); |
|
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
520 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
521 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
|
522 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
|
523 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
524 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
|
525 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
526 if ((m = PyDict_GetItemString(modules, name)) == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
527 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
528 "Loaded module %.200s not found in sys.modules", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
529 name); |
|
5758
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
530 return NULL; |
|
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
531 } |
|
bfe9ba74c19e
Fix problem discovered by Greg McFarlane: when an imported module
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
532 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
533 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
|
534 |
| 86 | 535 return m; |
| 6 | 536 } |
| 537 | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
538 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
539 /* 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
|
540 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
|
541 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
|
542 Doesn't set an exception. */ |
|
609
0ad5b35e3ad8
Support for dynamic loading added.
Guido van Rossum <guido@python.org>
parents:
510
diff
changeset
|
543 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
544 static char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
545 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
|
546 { |
|
18992
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
547 size_t len = strlen(pathname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
548 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
|
549 return NULL; |
|
18992
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
550 |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
551 #ifdef MS_WIN32 |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
552 /* Treat .pyw as if it were .py. The case of ".pyw" must match |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
553 that used in _PyImport_StandardFiletab. */ |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
554 if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0) |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
555 --len; /* pretend 'w' isn't there */ |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
556 #endif |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
557 memcpy(buf, pathname, len); |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
558 buf[len] = Py_OptimizeFlag ? 'o' : 'c'; |
|
7fa1f87ca6b2
Derived from SF patch #446899 Permit import of .pyw under Windows, from
Tim Peters <tim.peters@gmail.com>
parents:
18933
diff
changeset
|
559 buf[len+1] = '\0'; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
560 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
561 return buf; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
562 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
563 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
564 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
565 /* 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
|
566 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
|
567 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
|
568 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
|
569 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
|
570 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
|
571 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
572 static FILE * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
573 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
|
574 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
575 FILE *fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
576 long magic; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
577 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
|
578 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
579 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
|
580 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
|
581 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
582 magic = PyMarshal_ReadLongFromFile(fp); |
| 12543 | 583 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
|
584 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
585 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
|
586 fclose(fp); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
587 return NULL; |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
588 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
589 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
|
590 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
|
591 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
592 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
|
593 fclose(fp); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
594 return NULL; |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
595 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
596 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
597 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
|
598 return fp; |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
599 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
600 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
601 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
602 /* 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
|
603 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
604 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
605 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
|
606 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
607 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
|
608 |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
609 co = PyMarshal_ReadLastObjectFromFile(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 /* 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
|
611 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
|
612 if (!PyErr_Occurred()) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
613 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
614 "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
|
615 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
|
616 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
617 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
618 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
|
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 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
622 /* 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
|
623 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
|
624 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
625 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
626 load_compiled_module(char *name, char *cpathname, FILE *fp) |
| 6 | 627 { |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
628 long magic; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
629 PyCodeObject *co; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
630 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
|
631 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
632 magic = PyMarshal_ReadLongFromFile(fp); |
| 12543 | 633 if (magic != pyc_magic) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
634 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
635 "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
|
636 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
637 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
638 (void) PyMarshal_ReadLongFromFile(fp); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
639 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
|
640 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
|
641 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
642 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
643 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
|
644 name, cpathname); |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
645 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
|
646 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
|
647 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
648 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
649 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
650 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
651 /* 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
|
652 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
653 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
654 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
|
655 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
656 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
|
657 node *n; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
658 |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5375
diff
changeset
|
659 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
|
660 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
|
661 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
662 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
|
663 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
|
664 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
665 return co; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
666 } |
|
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 |
|
14708
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
669 /* Helper to open a bytecode file for writing in exclusive mode */ |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
670 |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
671 static FILE * |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
672 open_exclusive(char *filename) |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
673 { |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
674 #if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC) |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
675 /* Use O_EXCL to avoid a race condition when another process tries to |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
676 write the same file. When that happens, our open() call fails, |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
677 which is just fine (since it's only a cache). |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
678 XXX If the file exists and is writable but the directory is not |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
679 writable, the file will never be written. Oh well. |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
680 */ |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
681 int fd; |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
682 (void) unlink(filename); |
|
14921
3db8b8031a6a
The 2.0b2 change to write .pyc files in exclusive mode (if possible)
Tim Peters <tim.peters@gmail.com>
parents:
14708
diff
changeset
|
683 fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC |
|
3db8b8031a6a
The 2.0b2 change to write .pyc files in exclusive mode (if possible)
Tim Peters <tim.peters@gmail.com>
parents:
14708
diff
changeset
|
684 #ifdef O_BINARY |
|
3db8b8031a6a
The 2.0b2 change to write .pyc files in exclusive mode (if possible)
Tim Peters <tim.peters@gmail.com>
parents:
14708
diff
changeset
|
685 |O_BINARY /* necessary for Windows */ |
|
3db8b8031a6a
The 2.0b2 change to write .pyc files in exclusive mode (if possible)
Tim Peters <tim.peters@gmail.com>
parents:
14708
diff
changeset
|
686 #endif |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
687 |
|
14921
3db8b8031a6a
The 2.0b2 change to write .pyc files in exclusive mode (if possible)
Tim Peters <tim.peters@gmail.com>
parents:
14708
diff
changeset
|
688 , 0666); |
|
14708
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
689 if (fd < 0) |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
690 return NULL; |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
691 return fdopen(fd, "wb"); |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
692 #else |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
693 /* Best we can do -- on Windows this can't happen anyway */ |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
694 return fopen(filename, "wb"); |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
695 #endif |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
696 } |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
697 |
|
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
698 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
699 /* 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
|
700 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
|
701 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
|
702 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
|
703 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
704 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
705 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
|
706 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
707 FILE *fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
708 |
|
14708
89b2aee43e0b
On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
709 fp = open_exclusive(cpathname); |
|
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 (fp == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
711 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
712 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
|
713 "# 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
|
714 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
715 } |
| 12543 | 716 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
|
717 /* 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
|
718 PyMarshal_WriteLongToFile(0L, fp); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
719 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
|
720 if (ferror(fp)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
721 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
722 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
|
723 /* 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
|
724 fclose(fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
725 (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
|
726 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
727 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
728 /* 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
|
729 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
|
730 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
|
731 fflush(fp); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
732 fclose(fp); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
733 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
734 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
|
735 #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
|
736 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
|
737 #endif |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
738 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
739 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
740 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
741 /* 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
|
742 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
|
743 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
|
744 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
745 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
746 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
|
747 { |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
748 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
|
749 FILE *fpc; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
750 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
|
751 char *cpathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
752 PyCodeObject *co; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
753 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
|
754 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
755 mtime = PyOS_GetLastModificationTime(pathname, fp); |
|
16893
f1c8ea92ee85
Suppress a compiler warning under OpenVMS; time_t is unsigned on (at least)
Fred Drake <fdrake@acm.org>
parents:
16881
diff
changeset
|
756 if (mtime == (time_t)(-1)) |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
757 return NULL; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
758 #if SIZEOF_TIME_T > 4 |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
759 /* 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
|
760 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
|
761 when a 4-byte signed time_t will overflow. |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
762 */ |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
763 if (mtime >> 32) { |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
764 PyErr_SetString(PyExc_OverflowError, |
|
16893
f1c8ea92ee85
Suppress a compiler warning under OpenVMS; time_t is unsigned on (at least)
Fred Drake <fdrake@acm.org>
parents:
16881
diff
changeset
|
765 "modification time overflows a 4 byte field"); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
766 return NULL; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
767 } |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
768 #endif |
|
21010
4a9a9cc041de
Since the MAGIC number scheme is going to break on January 1st, document
Tim Peters <tim.peters@gmail.com>
parents:
20768
diff
changeset
|
769 cpathname = make_compiled_pathname(pathname, buf, |
| 17502 | 770 (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
|
771 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
|
772 (fpc = check_compiled_module(pathname, mtime, cpathname))) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
773 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
|
774 fclose(fpc); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
775 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
|
776 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
777 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
778 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
|
779 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
|
780 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
|
781 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
782 else { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
783 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
|
784 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
|
785 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
786 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
787 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
|
788 name, pathname); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
789 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
|
790 } |
|
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
|
791 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
|
792 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
|
793 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
794 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
795 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
796 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
797 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
798 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 static struct _frozen *find_frozen(char *name); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
803 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
804 /* 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
|
805 REFERENCE COUNT */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
806 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
807 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
808 load_package(char *name, char *pathname) |
|
6243
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 PyObject *m, *d, *file, *path; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
811 int err; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
812 char buf[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
813 FILE *fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
814 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
815 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
816 m = PyImport_AddModule(name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
817 if (m == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
818 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
|
819 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
820 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
|
821 name, pathname); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
822 d = PyModule_GetDict(m); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
823 file = PyString_FromString(pathname); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
824 if (file == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
825 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
826 path = Py_BuildValue("[O]", file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
827 if (path == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
828 Py_DECREF(file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
829 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
830 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
831 err = PyDict_SetItemString(d, "__file__", file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
832 if (err == 0) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
833 err = PyDict_SetItemString(d, "__path__", path); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
834 if (err != 0) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
835 m = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
836 goto cleanup; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
837 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
838 buf[0] = '\0'; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
839 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
|
840 if (fdp == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
841 if (PyErr_ExceptionMatches(PyExc_ImportError)) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
842 PyErr_Clear(); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
843 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
844 else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
845 m = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
846 goto cleanup; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
847 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
848 m = load_module(name, fp, buf, fdp->type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
849 if (fp != NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
850 fclose(fp); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
851 cleanup: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
852 Py_XDECREF(path); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
853 Py_XDECREF(file); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
854 return m; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
855 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
856 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
857 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
858 /* Helper to test for built-in module */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
859 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
860 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
861 is_builtin(char *name) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
862 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
863 int i; |
|
6541
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
864 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
|
865 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
|
866 if (PyImport_Inittab[i].initfunc == NULL) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
867 return -1; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
868 else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
869 return 1; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
870 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
871 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
872 return 0; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
873 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
874 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
875 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
876 /* 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
|
877 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
|
878 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
|
879 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
880 #ifdef MS_COREDLL |
|
13663
29da35543833
ANSIfy as many declarations as possible.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
881 extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **, |
|
29da35543833
ANSIfy as many declarations as possible.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
882 char *, int); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
883 #endif |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
884 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
885 static int case_ok(char *, int, int, char *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
886 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
|
887 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
888 static struct filedescr * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
889 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
|
890 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
|
891 { |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
892 int i, npath; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
893 size_t len, namelen; |
| 4596 | 894 struct filedescr *fdp = NULL; |
|
23554
e5242f58a5b6
File modes in filedescr entries are also passed to Python, so we now put "U"
Jack Jansen <jack.jansen@cwi.nl>
parents:
23029
diff
changeset
|
895 char *filemode; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
896 FILE *fp = NULL; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
897 #ifndef RISCOS |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
898 struct stat statbuf; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
899 #endif |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
900 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
|
901 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
|
902 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
|
903 char name[MAXPATHLEN+1]; |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
904 #if defined(PYOS_OS2) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
905 size_t saved_len; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
906 size_t saved_namelen; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
907 char *saved_buf = NULL; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
908 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
909 |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
910 if (strlen(realname) > MAXPATHLEN) { |
|
20527
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
911 PyErr_SetString(PyExc_OverflowError, |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
912 "module name is too long"); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
913 return NULL; |
|
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
914 } |
|
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
|
915 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
|
916 |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
917 if (path != NULL && PyString_Check(path)) { |
|
20527
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
918 /* The only type of submodule allowed inside a "frozen" |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
919 package are other frozen modules or packages. */ |
|
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
|
920 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
|
921 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
|
922 "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
|
923 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
|
924 } |
|
20b83ca06ce8
Patch by Just van Rossum that changes how we search for submodules of
Guido van Rossum <guido@python.org>
parents:
8845
diff
changeset
|
925 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
|
926 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
|
927 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
|
928 strcpy(name, buf); |
|
20768
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
929 #ifdef macintosh |
|
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
930 /* Freezing on the mac works different, and the modules are |
|
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
931 ** actually on sys.path. So we don't take the quick exit but |
|
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
932 ** continue with the normal flow. |
|
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
933 */ |
|
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
934 path = NULL; |
|
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
935 #else |
|
20527
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
936 if (find_frozen(name) != NULL) { |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
937 strcpy(buf, name); |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
938 return &fd_frozen; |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
939 } |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
940 PyErr_Format(PyExc_ImportError, |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
941 "No frozen submodule named %.200s", name); |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
942 return NULL; |
|
20768
7b0546ee4789
On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20671
diff
changeset
|
943 #endif |
|
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
|
944 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
945 if (path == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
946 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
|
947 strcpy(buf, name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
948 return &fd_builtin; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
949 } |
|
20249
1acecc908ee8
Remove a couple of unused local variables (bug #445960, compiler warnings
Greg Ward <gward@python.net>
parents:
19596
diff
changeset
|
950 if ((find_frozen(name)) != NULL) { |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
951 strcpy(buf, name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
952 return &fd_frozen; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
953 } |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
954 |
|
4111
90216e907345
PYTHONWIN -> MS_COREDLL
Guido van Rossum <guido@python.org>
parents:
3964
diff
changeset
|
955 #ifdef MS_COREDLL |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
956 fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
957 if (fp != NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
958 *p_fp = fp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
959 return fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
960 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
961 #endif |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
962 path = PySys_GetObject("path"); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
963 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
964 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
|
965 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
|
966 "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
|
967 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
|
968 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
969 npath = PyList_Size(path); |
|
1905
61c3c1a2fdb4
Fix various potential buffer overrun problems.
Guido van Rossum <guido@python.org>
parents:
1886
diff
changeset
|
970 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
|
971 for (i = 0; i < npath; i++) { |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
972 PyObject *copy = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
973 PyObject *v = PyList_GetItem(path, i); |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
974 #ifdef Py_USING_UNICODE |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
975 if (PyUnicode_Check(v)) { |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
976 copy = PyUnicode_Encode(PyUnicode_AS_UNICODE(v), |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
977 PyUnicode_GET_SIZE(v), Py_FileSystemDefaultEncoding, NULL); |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
978 if (copy == NULL) |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
979 return NULL; |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
980 v = copy; |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
981 } |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
982 else |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
983 #endif |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
984 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
|
985 continue; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
986 len = PyString_Size(v); |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
987 if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) { |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
988 Py_XDECREF(copy); |
|
1905
61c3c1a2fdb4
Fix various potential buffer overrun problems.
Guido van Rossum <guido@python.org>
parents:
1886
diff
changeset
|
989 continue; /* Too long */ |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
990 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
991 strcpy(buf, PyString_AsString(v)); |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
992 if (strlen(buf) != len) { |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
993 Py_XDECREF(copy); |
|
1905
61c3c1a2fdb4
Fix various potential buffer overrun problems.
Guido van Rossum <guido@python.org>
parents:
1886
diff
changeset
|
994 continue; /* v contains '\0' */ |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
995 } |
|
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
|
996 #ifdef macintosh |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
997 /* |
|
5980
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
998 ** 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
|
999 ** 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
|
1000 ** folders (so we don't have to bother trying to look |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1001 ** into them for resources). |
|
5980
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
1002 */ |
|
2894bb49e2ee
Use string interning and caching to get speedups on the mac (Jack).
Guido van Rossum <guido@python.org>
parents:
5938
diff
changeset
|
1003 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
|
1004 v = PyList_GET_ITEM(path, i); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1005 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
|
1006 static struct filedescr resfiledescr = |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1007 {"", "", PY_RESOURCE}; |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1008 |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1009 Py_XDECREF(copy); |
|
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
|
1010 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
|
1011 } |
|
8845
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1012 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
|
1013 static struct filedescr resfiledescr = |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1014 {"", "", PY_CODERESOURCE}; |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1015 |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1016 Py_XDECREF(copy); |
|
8845
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1017 return &resfiledescr; |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1018 } |
|
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
|
1019 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1020 if (len > 0 && buf[len-1] != SEP |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1021 #ifdef ALTSEP |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1022 && buf[len-1] != ALTSEP |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1023 #endif |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1024 ) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1025 buf[len++] = SEP; |
|
15401
c45c5080c844
Rip out DOS-8x3 support.
Guido van Rossum <guido@python.org>
parents:
14991
diff
changeset
|
1026 strcpy(buf+len, name); |
|
c45c5080c844
Rip out DOS-8x3 support.
Guido van Rossum <guido@python.org>
parents:
14991
diff
changeset
|
1027 len += namelen; |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1028 |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1029 /* Check for package import (buf holds a directory name, |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1030 and there's an __init__ module in that directory */ |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1031 #ifdef HAVE_STAT |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1032 if (stat(buf, &statbuf) == 0 && /* it exists */ |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1033 S_ISDIR(statbuf.st_mode) && /* it's a directory */ |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1034 find_init_module(buf) && /* it has __init__.py */ |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1035 case_ok(buf, len, namelen, name)) { /* and case matches */ |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1036 Py_XDECREF(copy); |
|
17642
e06c36c13f12
SF bug #417093: Case sensitive import: dir and .py file w/ same name
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1037 return &fd_package; |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1038 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1039 #else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1040 /* XXX How are you going to test for directories? */ |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1041 #ifdef RISCOS |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1042 if (isdir(buf) && |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1043 find_init_module(buf) && |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1044 case_ok(buf, len, namelen, name)) { |
|
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1045 Py_XDECREF(copy); |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1046 return &fd_package; |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1047 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1048 #endif |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1049 #endif |
|
6454
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
1050 #ifdef macintosh |
|
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
1051 fdp = PyMac_FindModuleExtension(buf, &len, name); |
|
17090
7e938f0e9a49
Case-checking was broken on the Macintosh. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16986
diff
changeset
|
1052 if (fdp) { |
|
6454
b5b35a0cf1aa
Moved mac-specific speedup to a different place (Jack)
Guido van Rossum <guido@python.org>
parents:
6375
diff
changeset
|
1053 #else |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1054 #if defined(PYOS_OS2) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1055 /* take a snapshot of the module spec for restoration |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1056 * after the 8 character DLL hackery |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1057 */ |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1058 saved_buf = strdup(buf); |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1059 saved_len = len; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1060 saved_namelen = namelen; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1061 #endif /* PYOS_OS2 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1062 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1063 #if defined(PYOS_OS2) |
|
23585
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1064 /* OS/2 limits DLLs to 8 character names (w/o |
|
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1065 extension) |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1066 * so if the name is longer than that and its a |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1067 * dynamically loaded module we're going to try, |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1068 * truncate the name before trying |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1069 */ |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1070 if (strlen(realname) > 8) { |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1071 /* is this an attempt to load a C extension? */ |
|
23585
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1072 const struct filedescr *scan; |
|
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1073 scan = _PyImport_DynLoadFiletab; |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1074 while (scan->suffix != NULL) { |
|
23585
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1075 if (!strcmp(scan->suffix, fdp->suffix)) |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1076 break; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1077 else |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1078 scan++; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1079 } |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1080 if (scan->suffix != NULL) { |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1081 /* yes, so truncate the name */ |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1082 namelen = 8; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1083 len -= strlen(realname) - namelen; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1084 buf[len] = '\0'; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1085 } |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1086 } |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1087 #endif /* PYOS_OS2 */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1088 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
|
1089 if (Py_VerboseFlag > 1) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
1090 PySys_WriteStderr("# trying %s\n", buf); |
|
17090
7e938f0e9a49
Case-checking was broken on the Macintosh. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16986
diff
changeset
|
1091 #endif /* !macintosh */ |
|
23554
e5242f58a5b6
File modes in filedescr entries are also passed to Python, so we now put "U"
Jack Jansen <jack.jansen@cwi.nl>
parents:
23029
diff
changeset
|
1092 filemode = fdp->mode; |
|
23585
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1093 if (filemode[0] == 'U') |
|
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
1094 filemode = "r" PY_STDIOTEXTMODE; |
|
23554
e5242f58a5b6
File modes in filedescr entries are also passed to Python, so we now put "U"
Jack Jansen <jack.jansen@cwi.nl>
parents:
23029
diff
changeset
|
1095 fp = fopen(buf, filemode); |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1096 if (fp != NULL) { |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1097 if (case_ok(buf, len, namelen, name)) |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1098 break; |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1099 else { /* continue search */ |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1100 fclose(fp); |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1101 fp = NULL; |
|
16423
5c40113409c3
Steve Majewski's patch #103495, MatchFilename() and find_module()
Barry Warsaw <barry@python.org>
parents:
16311
diff
changeset
|
1102 } |
|
5c40113409c3
Steve Majewski's patch #103495, MatchFilename() and find_module()
Barry Warsaw <barry@python.org>
parents:
16311
diff
changeset
|
1103 } |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1104 #if defined(PYOS_OS2) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1105 /* restore the saved snapshot */ |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1106 strcpy(buf, saved_buf); |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1107 len = saved_len; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1108 namelen = saved_namelen; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1109 #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
|
1110 } |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1111 #if defined(PYOS_OS2) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1112 /* don't need/want the module name snapshot anymore */ |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1113 if (saved_buf) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1114 { |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1115 free(saved_buf); |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1116 saved_buf = NULL; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1117 } |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1118 #endif |
|
23879
08475c87d24f
Apply diff2.txt from SF patch http://www.python.org/sf/566999
Walter Dörwald <walter@livinglogic.de>
parents:
23851
diff
changeset
|
1119 Py_XDECREF(copy); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
1120 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
|
1121 break; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
1122 } |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
1123 if (fp == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1124 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1125 "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
|
1126 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
|
1127 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1128 *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
|
1129 return fdp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1130 } |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
1131 |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1132 /* case_ok(char* buf, int len, int namelen, char* name) |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1133 * The arguments here are tricky, best shown by example: |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1134 * /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0 |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1135 * ^ ^ ^ ^ |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1136 * |--------------------- buf ---------------------| |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1137 * |------------------- len ------------------| |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1138 * |------ name -------| |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1139 * |----- namelen -----| |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1140 * buf is the full path, but len only counts up to (& exclusive of) the |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1141 * extension. name is the module name, also exclusive of extension. |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1142 * |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1143 * We've already done a successful stat() or fopen() on buf, so know that |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1144 * there's some match, possibly case-insensitive. |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1145 * |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1146 * case_ok() is to return 1 if there's a case-sensitive match for |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1147 * name, else 0. case_ok() is also to return 1 if envar PYTHONCASEOK |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1148 * exists. |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1149 * |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1150 * case_ok() is used to implement case-sensitive import semantics even |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1151 * on platforms with case-insensitive filesystems. It's trivial to implement |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1152 * for case-sensitive filesystems. It's pretty much a cross-platform |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1153 * nightmare for systems with case-insensitive filesystems. |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1154 */ |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1155 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1156 /* First we may need a pile of platform-specific header files; the sequence |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1157 * of #if's here should match the sequence in the body of case_ok(). |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1158 */ |
|
15802
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1159 #if defined(MS_WIN32) || defined(__CYGWIN__) |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1160 #include <windows.h> |
|
15802
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1161 #ifdef __CYGWIN__ |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1162 #include <sys/cygwin.h> |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1163 #endif |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1164 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1165 #elif defined(DJGPP) |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1166 #include <dir.h> |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1167 |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1168 #elif defined(macintosh) |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1169 #include <TextUtils.h> |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1170 |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1171 #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1172 #include <sys/types.h> |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1173 #include <dirent.h> |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1174 |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1175 #elif defined(PYOS_OS2) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1176 #define INCL_DOS |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1177 #define INCL_DOSERRORS |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1178 #define INCL_NOPMAPI |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1179 #include <os2.h> |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1180 |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1181 #elif defined(RISCOS) |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1182 #include "oslib/osfscontrol.h" |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1183 #endif |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1184 |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1185 static int |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1186 case_ok(char *buf, int len, int namelen, char *name) |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1187 { |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1188 /* Pick a platform-specific implementation; the sequence of #if's here should |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1189 * match the sequence just above. |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1190 */ |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1191 |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1192 /* MS_WIN32 || __CYGWIN__ */ |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1193 #if defined(MS_WIN32) || defined(__CYGWIN__) |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1194 WIN32_FIND_DATA data; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1195 HANDLE h; |
|
15802
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1196 #ifdef __CYGWIN__ |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1197 char tempbuf[MAX_PATH]; |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1198 #endif |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1199 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18803
diff
changeset
|
1200 if (Py_GETENV("PYTHONCASEOK") != NULL) |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1201 return 1; |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1202 |
|
15802
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1203 #ifdef __CYGWIN__ |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1204 cygwin32_conv_to_win32_path(buf, tempbuf); |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1205 h = FindFirstFile(tempbuf, &data); |
|
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1206 #else |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1207 h = FindFirstFile(buf, &data); |
|
15802
eb1767b068fe
SF Patch #103154 by jlt63: Cygwin Check Import Case Patch.
Guido van Rossum <guido@python.org>
parents:
15401
diff
changeset
|
1208 #endif |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1209 if (h == INVALID_HANDLE_VALUE) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1210 PyErr_Format(PyExc_NameError, |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1211 "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
|
1212 name, buf); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1213 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1214 } |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1215 FindClose(h); |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1216 return strncmp(data.cFileName, name, namelen) == 0; |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1217 |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1218 /* DJGPP */ |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1219 #elif defined(DJGPP) |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1220 struct ffblk ffblk; |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1221 int done; |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1222 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18803
diff
changeset
|
1223 if (Py_GETENV("PYTHONCASEOK") != NULL) |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
1224 return 1; |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1225 |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1226 done = findfirst(buf, &ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC); |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1227 if (done) { |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1228 PyErr_Format(PyExc_NameError, |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1229 "Can't find file for module %.100s\n(filename %.300s)", |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1230 name, buf); |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1231 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1232 } |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1233 return strncmp(ffblk.ff_name, name, namelen) == 0; |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1234 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1235 /* macintosh */ |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1236 #elif defined(macintosh) |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1237 FSSpec fss; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1238 OSErr err; |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1239 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18803
diff
changeset
|
1240 if (Py_GETENV("PYTHONCASEOK") != NULL) |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1241 return 1; |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1242 |
|
9096
2088f80253db
Mac-specific mod to enable aliases on import paths.
Guido van Rossum <guido@python.org>
parents:
9050
diff
changeset
|
1243 err = FSMakeFSSpec(0, 0, Pstring(buf), &fss); |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1244 if (err) { |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1245 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
|
1246 "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
|
1247 name, buf); |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1248 return 0; |
|
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1249 } |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1250 return fss.name[0] >= namelen && |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1251 strncmp(name, (char *)fss.name+1, namelen) == 0; |
|
7305
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1252 |
|
16932
abc8c6c025ce
Thanks to Steven Majewski, finally putting MacOS X imports to bed for 2.1b1.
Tim Peters <tim.peters@gmail.com>
parents:
16902
diff
changeset
|
1253 /* new-fangled macintosh (macosx) */ |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1254 #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1255 DIR *dirp; |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1256 struct dirent *dp; |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1257 char dirname[MAXPATHLEN + 1]; |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1258 const int dirlen = len - namelen - 1; /* don't want trailing SEP */ |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1259 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18803
diff
changeset
|
1260 if (Py_GETENV("PYTHONCASEOK") != NULL) |
|
16896
fa84f9f41092
More fiddling w/ the new-fangled Mac import code.
Tim Peters <tim.peters@gmail.com>
parents:
16893
diff
changeset
|
1261 return 1; |
|
fa84f9f41092
More fiddling w/ the new-fangled Mac import code.
Tim Peters <tim.peters@gmail.com>
parents:
16893
diff
changeset
|
1262 |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1263 /* Copy the dir component into dirname; substitute "." if empty */ |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1264 if (dirlen <= 0) { |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1265 dirname[0] = '.'; |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1266 dirname[1] = '\0'; |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1267 } |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1268 else { |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1269 assert(dirlen <= MAXPATHLEN); |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1270 memcpy(dirname, buf, dirlen); |
|
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1271 dirname[dirlen] = '\0'; |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1272 } |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1273 /* Open the directory and search the entries for an exact match. */ |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1274 dirp = opendir(dirname); |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1275 if (dirp) { |
|
16932
abc8c6c025ce
Thanks to Steven Majewski, finally putting MacOS X imports to bed for 2.1b1.
Tim Peters <tim.peters@gmail.com>
parents:
16902
diff
changeset
|
1276 char *nameWithExt = buf + len - namelen; |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1277 while ((dp = readdir(dirp)) != NULL) { |
|
16896
fa84f9f41092
More fiddling w/ the new-fangled Mac import code.
Tim Peters <tim.peters@gmail.com>
parents:
16893
diff
changeset
|
1278 const int thislen = |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1279 #ifdef _DIRENT_HAVE_D_NAMELEN |
|
16896
fa84f9f41092
More fiddling w/ the new-fangled Mac import code.
Tim Peters <tim.peters@gmail.com>
parents:
16893
diff
changeset
|
1280 dp->d_namlen; |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1281 #else |
|
16896
fa84f9f41092
More fiddling w/ the new-fangled Mac import code.
Tim Peters <tim.peters@gmail.com>
parents:
16893
diff
changeset
|
1282 strlen(dp->d_name); |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1283 #endif |
|
16902
f55f35dc5320
More MacOSX fiddling. As noted in a comment, I believe all variations
Tim Peters <tim.peters@gmail.com>
parents:
16896
diff
changeset
|
1284 if (thislen >= namelen && |
|
16932
abc8c6c025ce
Thanks to Steven Majewski, finally putting MacOS X imports to bed for 2.1b1.
Tim Peters <tim.peters@gmail.com>
parents:
16902
diff
changeset
|
1285 strcmp(dp->d_name, nameWithExt) == 0) { |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1286 (void)closedir(dirp); |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1287 return 1; /* Found */ |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1288 } |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1289 } |
|
16896
fa84f9f41092
More fiddling w/ the new-fangled Mac import code.
Tim Peters <tim.peters@gmail.com>
parents:
16893
diff
changeset
|
1290 (void)closedir(dirp); |
|
16880
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1291 } |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1292 return 0 ; /* Not found */ |
|
bdcd79873924
In Steven's apparent absence, check in *something* with a non-zero chance
Tim Peters <tim.peters@gmail.com>
parents:
16830
diff
changeset
|
1293 |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1294 /* RISC OS */ |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1295 #elif defined(RISCOS) |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1296 char canon[MAXPATHLEN+1]; /* buffer for the canonical form of the path */ |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1297 char buf2[MAXPATHLEN+2]; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1298 char *nameWithExt = buf+len-namelen; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1299 int canonlen; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1300 os_error *e; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1301 |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1302 if (Py_GETENV("PYTHONCASEOK") != NULL) |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1303 return 1; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1304 |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1305 /* workaround: |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1306 append wildcard, otherwise case of filename wouldn't be touched */ |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1307 strcpy(buf2, buf); |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1308 strcat(buf2, "*"); |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1309 |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1310 e = xosfscontrol_canonicalise_path(buf2,canon,0,0,MAXPATHLEN+1,&canonlen); |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1311 canonlen = MAXPATHLEN+1-canonlen; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1312 if (e || canonlen<=0 || canonlen>(MAXPATHLEN+1) ) |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1313 return 0; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1314 if (strcmp(nameWithExt, canon+canonlen-strlen(nameWithExt))==0) |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1315 return 1; /* match */ |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1316 |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1317 return 0; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20527
diff
changeset
|
1318 |
|
22054
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1319 /* OS/2 */ |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1320 #elif defined(PYOS_OS2) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1321 HDIR hdir = 1; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1322 ULONG srchcnt = 1; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1323 FILEFINDBUF3 ffbuf; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1324 APIRET rc; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1325 |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1326 if (getenv("PYTHONCASEOK") != NULL) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1327 return 1; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1328 |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1329 rc = DosFindFirst(buf, |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1330 &hdir, |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1331 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY, |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1332 &ffbuf, sizeof(ffbuf), |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1333 &srchcnt, |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1334 FIL_STANDARD); |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1335 if (rc != NO_ERROR) |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1336 return 0; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1337 return strncmp(ffbuf.achName, name, namelen) == 0; |
|
5cbcfde3ad55
OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21886
diff
changeset
|
1338 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1339 /* assuming it's a case-sensitive filesystem, so there's nothing to do! */ |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1340 #else |
|
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1341 return 1; |
|
7305
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1342 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1343 #endif |
|
7305
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1344 } |
|
067e4813c6d6
Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
Guido van Rossum <guido@python.org>
parents:
7290
diff
changeset
|
1345 |
|
7290
72d531d54572
Add case checking feature on import.
Guido van Rossum <guido@python.org>
parents:
7232
diff
changeset
|
1346 |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1347 #ifdef HAVE_STAT |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1348 /* 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
|
1349 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1350 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
|
1351 { |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1352 const size_t save_len = strlen(buf); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1353 size_t i = save_len; |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1354 char *pname; /* pointer to start of __init__ */ |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1355 struct stat statbuf; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1356 |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1357 /* For calling case_ok(buf, len, namelen, name): |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1358 * /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0 |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1359 * ^ ^ ^ ^ |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1360 * |--------------------- buf ---------------------| |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1361 * |------------------- len ------------------| |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1362 * |------ name -------| |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1363 * |----- namelen -----| |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1364 */ |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1365 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
|
1366 return 0; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1367 buf[i++] = SEP; |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1368 pname = buf + i; |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1369 strcpy(pname, "__init__.py"); |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1370 if (stat(buf, &statbuf) == 0) { |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1371 if (case_ok(buf, |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1372 save_len + 9, /* len("/__init__") */ |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1373 8, /* len("__init__") */ |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1374 pname)) { |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1375 buf[save_len] = '\0'; |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1376 return 1; |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1377 } |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1378 } |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1379 i += strlen(pname); |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1380 strcpy(buf+i, Py_OptimizeFlag ? "o" : "c"); |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1381 if (stat(buf, &statbuf) == 0) { |
|
18388
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1382 if (case_ok(buf, |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1383 save_len + 9, /* len("/__init__") */ |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1384 8, /* len("__init__") */ |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1385 pname)) { |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1386 buf[save_len] = '\0'; |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1387 return 1; |
|
06332b3c4335
SF bug #438295: [Windows] __init__.py cause strange behavior
Tim Peters <tim.peters@gmail.com>
parents:
17642
diff
changeset
|
1388 } |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1389 } |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1390 buf[save_len] = '\0'; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1391 return 0; |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1392 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1393 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1394 #else |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1395 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1396 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1397 static int |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1398 find_init_module(buf) |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1399 char *buf; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1400 { |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1401 int save_len = strlen(buf); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1402 int i = save_len; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1403 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1404 if (save_len + 13 >= MAXPATHLEN) |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1405 return 0; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1406 buf[i++] = SEP; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1407 strcpy(buf+i, "__init__/py"); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1408 if (isfile(buf)) { |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1409 buf[save_len] = '\0'; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1410 return 1; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1411 } |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1412 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1413 if (Py_OptimizeFlag) |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1414 strcpy(buf+i, "o"); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1415 else |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1416 strcpy(buf+i, "c"); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1417 if (isfile(buf)) { |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1418 buf[save_len] = '\0'; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1419 return 1; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1420 } |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1421 buf[save_len] = '\0'; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1422 return 0; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1423 } |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1424 #endif /*RISCOS*/ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16932
diff
changeset
|
1425 |
|
6542
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1426 #endif /* HAVE_STAT */ |
|
62bdb1cbe0f5
New policy for package imports: only a directory containing
Guido van Rossum <guido@python.org>
parents:
6541
diff
changeset
|
1427 |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
1428 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
1429 static int init_builtin(char *); /* Forward */ |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1430 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1431 /* 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
|
1432 its module object WITH INCREMENTED REFERENCE COUNT */ |
| 86 | 1433 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1434 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1435 load_module(char *name, FILE *fp, char *buf, int type) |
| 86 | 1436 { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1437 PyObject *modules; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1438 PyObject *m; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1439 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
|
1440 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1441 /* 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
|
1442 switch (type) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1443 case PY_SOURCE: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1444 case PY_COMPILED: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1445 if (fp == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1446 PyErr_Format(PyExc_ValueError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1447 "file object required for import (type code %d)", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1448 type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1449 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1450 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1451 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1452 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1453 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
|
1454 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1455 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
|
1456 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
|
1457 break; |
| 6 | 1458 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1459 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
|
1460 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
|
1461 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1462 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
1463 #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
|
1464 case C_EXTENSION: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1465 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
|
1466 break; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
1467 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1468 |
|
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
|
1469 #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
|
1470 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
|
1471 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
|
1472 break; |
|
8845
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1473 case PY_CODERESOURCE: |
|
b933f584a26d
Added handling for Mac code resource modules (Jack Jansen).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1474 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
|
1475 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
|
1476 #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
|
1477 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1478 case PKG_DIRECTORY: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1479 m = load_package(name, buf); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1480 break; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1481 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1482 case C_BUILTIN: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1483 case PY_FROZEN: |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1484 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
|
1485 name = buf; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1486 if (type == C_BUILTIN) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1487 err = init_builtin(name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1488 else |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1489 err = PyImport_ImportFrozenModule(name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1490 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
|
1491 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1492 if (err == 0) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1493 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1494 "Purported %s module %.200s not found", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1495 type == C_BUILTIN ? |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1496 "builtin" : "frozen", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1497 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
|
1498 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1499 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1500 modules = PyImport_GetModuleDict(); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1501 m = PyDict_GetItemString(modules, name); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1502 if (m == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1503 PyErr_Format( |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1504 PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1505 "%s module %.200s not properly initialized", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1506 type == C_BUILTIN ? |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1507 "builtin" : "frozen", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1508 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
|
1509 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1510 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1511 Py_INCREF(m); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1512 break; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1513 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1514 default: |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1515 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1516 "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
|
1517 name, type); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1518 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
|
1519 |
|
141
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1520 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1521 |
| 6 | 1522 return m; |
| 1523 } | |
|
40
f28ac7f621c7
Added reload() functionality.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
1524 |
| 86 | 1525 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1526 /* 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
|
1527 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
|
1528 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
|
1529 |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1530 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1531 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
|
1532 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1533 struct _inittab *p; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1534 |
|
20249
1acecc908ee8
Remove a couple of unused local variables (bug #445960, compiler warnings
Greg Ward <gward@python.net>
parents:
19596
diff
changeset
|
1535 if (_PyImport_FindExtension(name, name) != NULL) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1536 return 1; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1537 |
|
6541
b2dfff06789c
Instead of using _PyImport_Inittab[] directly, use the new "official"
Guido van Rossum <guido@python.org>
parents:
6454
diff
changeset
|
1538 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
|
1539 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
|
1540 if (p->initfunc == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1541 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1542 "Cannot re-init internal module %.200s", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1543 name); |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1544 return -1; |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1545 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1546 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
1547 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
|
1548 (*p->initfunc)(); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1549 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
|
1550 return -1; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1551 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
|
1552 return -1; |
|
141
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1553 return 1; |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1554 } |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1555 } |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1556 return 0; |
|
bf5a8539d8ba
Call the init function of a built-in module here.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
1557 } |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1558 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1559 |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1560 /* 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
|
1561 |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1562 static struct _frozen * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1563 find_frozen(char *name) |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1564 { |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1565 struct _frozen *p; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1566 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1567 for (p = PyImport_FrozenModules; ; p++) { |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1568 if (p->name == NULL) |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1569 return NULL; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1570 if (strcmp(p->name, name) == 0) |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1571 break; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1572 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1573 return p; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1574 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1575 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1576 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1577 get_frozen_object(char *name) |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1578 { |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1579 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
|
1580 int size; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1581 |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1582 if (p == NULL) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1583 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1584 "No such frozen object named %.200s", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1585 name); |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1586 return NULL; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1587 } |
|
20527
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1588 if (p->code == NULL) { |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1589 PyErr_Format(PyExc_ImportError, |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1590 "Excluded frozen object named %.200s", |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1591 name); |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1592 return NULL; |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1593 } |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1594 size = p->size; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1595 if (size < 0) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1596 size = -size; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1597 return PyMarshal_ReadObjectFromString((char *)p->code, size); |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1598 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1599 |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1600 /* Initialize a frozen module. |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1601 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
|
1602 an exception set if the initialization failed. |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1603 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
|
1604 |
|
6263e2fd9398
init_frozen non-static, frozenmain.c not in Makefile any more
Guido van Rossum <guido@python.org>
parents:
2270
diff
changeset
|
1605 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1606 PyImport_ImportFrozenModule(char *name) |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1607 { |
|
3683
ec39264311ff
struct frozen is now struct _frozen and comes from import.h.
Guido van Rossum <guido@python.org>
parents:
3590
diff
changeset
|
1608 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
|
1609 PyObject *co; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1610 PyObject *m; |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1611 int ispackage; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1612 int size; |
|
2891
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1613 |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1614 if (p == NULL) |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
1615 return 0; |
|
20527
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1616 if (p->code == NULL) { |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1617 PyErr_Format(PyExc_ImportError, |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1618 "Excluded frozen object named %.200s", |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1619 name); |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1620 return -1; |
|
3d3b6b4cb79f
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
20249
diff
changeset
|
1621 } |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1622 size = p->size; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1623 ispackage = (size < 0); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1624 if (ispackage) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1625 size = -size; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1626 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
1627 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
|
1628 name, ispackage ? " package" : ""); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1629 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
|
1630 if (co == NULL) |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1631 return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1632 if (!PyCode_Check(co)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1633 Py_DECREF(co); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1634 PyErr_Format(PyExc_TypeError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1635 "frozen object %.200s is not a code object", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1636 name); |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1637 return -1; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1638 } |
|
7552
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1639 if (ispackage) { |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1640 /* 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
|
1641 PyObject *d, *s; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1642 int err; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1643 m = PyImport_AddModule(name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1644 if (m == NULL) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1645 return -1; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1646 d = PyModule_GetDict(m); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1647 s = PyString_InternFromString(name); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1648 if (s == NULL) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1649 return -1; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1650 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
|
1651 Py_DECREF(s); |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1652 if (err != 0) |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1653 return err; |
|
c8e5f704623d
Support for frozen packages, matching the revamped Tools/freeze.
Guido van Rossum <guido@python.org>
parents:
7535
diff
changeset
|
1654 } |
|
7232
74c57288a02b
Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
Guido van Rossum <guido@python.org>
parents:
7202
diff
changeset
|
1655 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
|
1656 Py_DECREF(co); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1657 if (m == NULL) |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1658 return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1659 Py_DECREF(m); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1660 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
|
1661 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1662 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1663 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1664 /* 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
|
1665 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
|
1666 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1667 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1668 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
|
1669 { |
|
16534
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1670 PyObject *pname; |
|
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1671 PyObject *result; |
|
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1672 |
|
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1673 pname = PyString_FromString(name); |
|
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1674 result = PyImport_Import(pname); |
|
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1675 Py_DECREF(pname); |
|
b59f3a1eb123
This modified version of a patch by Thomas Heller allows __import__
Marc-André Lemburg <mal@egenix.com>
parents:
16433
diff
changeset
|
1676 return result; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1677 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1678 |
|
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
|
1679 /* 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
|
1680 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
|
1681 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
|
1682 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
|
1683 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
|
1684 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
|
1685 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
|
1686 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
|
1687 |
|
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 /* 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
|
1689 |
|
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
|
1690 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1691 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
|
1692 PyObject *fromlist) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1693 { |
|
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
|
1694 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
|
1695 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
|
1696 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
|
1697 |
|
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
|
1698 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
|
1699 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
|
1700 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
|
1701 |
|
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
|
1702 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
|
1703 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
|
1704 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
|
1705 |
|
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
|
1706 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
|
1707 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
|
1708 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
|
1709 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
|
1710 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
|
1711 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
|
1712 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
|
1713 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
|
1714 } |
|
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
|
1715 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
|
1716 } |
|
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
|
1717 |
|
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
|
1718 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
|
1719 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
|
1720 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
|
1721 } |
|
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 |
|
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 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
|
1724 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
|
1725 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
|
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 |
|
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
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 } |
|
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 |
|
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 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
|
1735 } |
|
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
|
1736 |
|
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
|
1737 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1738 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
|
1739 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
|
1740 { |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1741 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
|
1742 lock_import(); |
|
7535
13b60abdb70d
Oops -- overuse of dabbrev-expand introduced a strange bug, where
Guido van Rossum <guido@python.org>
parents:
7533
diff
changeset
|
1743 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
|
1744 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
|
1745 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
|
1746 } |
|
ea8184bff12d
Add a single Python-wide (!) lock on import. Only one thread at a
Guido van Rossum <guido@python.org>
parents:
7403
diff
changeset
|
1747 |
|
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
|
1748 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1749 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
|
1750 { |
|
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
|
1751 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
|
1752 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
|
1753 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
|
1754 |
|
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
|
1755 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
|
1756 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
|
1757 |
|
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
|
1758 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
|
1759 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
|
1760 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
|
1761 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
|
1762 } |
|
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
|
1763 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
|
1764 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
|
1765 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
|
1766 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
|
1767 } |
|
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
|
1768 |
|
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
|
1769 *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
|
1770 *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
|
1771 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
|
1772 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
|
1773 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
|
1774 |
|
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
|
1775 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
|
1776 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
|
1777 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
|
1778 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
|
1779 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
|
1780 "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
|
1781 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
|
1782 } |
|
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
|
1783 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
|
1784 *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
|
1785 } |
|
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
|
1786 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
|
1787 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
|
1788 char *lastdot = strrchr(start, '.'); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1789 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
|
1790 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
|
1791 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
|
1792 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
|
1793 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
|
1794 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
|
1795 "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
|
1796 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
|
1797 } |
|
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
|
1798 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
|
1799 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
|
1800 *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
|
1801 } |
|
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
|
1802 |
|
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
|
1803 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
|
1804 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
|
1805 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
|
1806 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
|
1807 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
|
1808 /* 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
|
1809 - 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
|
1810 - 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
|
1811 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
|
1812 } |
|
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
|
1813 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1814 /* 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
|
1815 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1816 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
|
1817 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
|
1818 { |
|
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
|
1819 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
|
1820 char *dot = strchr(name, '.'); |
|
13226
12437deb0680
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13181
diff
changeset
|
1821 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
|
1822 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
|
1823 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
|
1824 |
|
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
|
1825 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
|
1826 *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
|
1827 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
|
1828 } |
|
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
|
1829 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
|
1830 *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
|
1831 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
|
1832 } |
|
8012
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1833 if (len == 0) { |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1834 PyErr_SetString(PyExc_ValueError, |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1835 "Empty module name"); |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1836 return NULL; |
|
2b09a5d26368
Reject empty module names -- otherwise __import__("") does something
Guido van Rossum <guido@python.org>
parents:
7987
diff
changeset
|
1837 } |
|
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
|
1838 |
|
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
|
1839 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
|
1840 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
|
1841 *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
|
1842 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
|
1843 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
|
1844 "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
|
1845 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
|
1846 } |
|
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
|
1847 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
|
1848 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
|
1849 *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
|
1850 |
|
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
|
1851 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
|
1852 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
|
1853 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
|
1854 /* 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
|
1855 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
|
1856 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
|
1857 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
|
1858 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
|
1859 return NULL; |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1860 } |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1861 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
|
1862 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
|
1863 *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
|
1864 } |
|
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
|
1865 } |
|
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
|
1866 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
|
1867 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
|
1868 |
|
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
|
1869 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
|
1870 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
|
1871 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
|
1872 "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
|
1873 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
|
1874 } |
|
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
|
1875 |
|
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
|
1876 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
|
1877 } |
|
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
|
1878 |
|
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
|
1879 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1880 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
|
1881 { |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1882 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
|
1883 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
|
1884 } |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1885 |
|
6429db5d0af7
Significant speedup -- when a submodule imports a global module, add a
Guido van Rossum <guido@python.org>
parents:
6250
diff
changeset
|
1886 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1887 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
|
1888 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
|
1889 { |
|
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
|
1890 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
|
1891 |
|
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
|
1892 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
|
1893 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
|
1894 |
|
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
|
1895 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
|
1896 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
|
1897 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
|
1898 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
|
1899 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
|
1900 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
|
1901 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
|
1902 } |
|
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
|
1903 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
|
1904 } |
|
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
|
1905 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
|
1906 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
|
1907 "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
|
1908 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
|
1909 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
|
1910 } |
|
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
|
1911 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
|
1912 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
|
1913 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
|
1914 /* 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
|
1915 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
|
1916 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
|
1917 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
|
1918 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
|
1919 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
|
1920 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
|
1921 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
|
1922 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
|
1923 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
|
1924 } |
|
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
|
1925 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
|
1926 } |
|
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
|
1927 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
|
1928 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
|
1929 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
|
1930 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
|
1931 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
|
1932 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
|
1933 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
|
1934 "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
|
1935 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
|
1936 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
|
1937 } |
|
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
|
1938 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
|
1939 *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
|
1940 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
|
1941 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
|
1942 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
|
1943 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
|
1944 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
|
1945 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
|
1946 } |
|
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
|
1947 } |
|
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
|
1948 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
|
1949 } |
|
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
|
1950 |
|
6375
b68185d94777
Remove unreachable "return 1" at end of ensure_fromlist().
Guido van Rossum <guido@python.org>
parents:
6305
diff
changeset
|
1951 /* 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
|
1952 } |
|
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
|
1953 |
|
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
|
1954 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
1955 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
|
1956 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
1957 PyObject *modules = PyImport_GetModuleDict(); |
|
18803
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
1958 PyObject *m, *res = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
1959 |
|
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
|
1960 /* 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
|
1961 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
|
1962 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
|
1963 */ |
|
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
|
1964 |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
1965 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
|
1966 Py_INCREF(m); |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1967 } |
|
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2128
diff
changeset
|
1968 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
|
1969 PyObject *path; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1970 char buf[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1971 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1972 FILE *fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1973 |
|
8374
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1974 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
|
1975 path = NULL; |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1976 else { |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1977 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
|
1978 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
|
1979 PyErr_Clear(); |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1980 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
|
1981 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
|
1982 } |
|
a1bfe5bc6d8e
Fix a curious bug: statements like "import sys.time" would succeed,
Guido van Rossum <guido@python.org>
parents:
8330
diff
changeset
|
1983 } |
|
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
|
1984 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1985 buf[0] = '\0'; |
|
8613
e3d3bbbd93f3
Fix two smal memory leaks discovered by Vadim Chugunov.
Guido van Rossum <guido@python.org>
parents:
8544
diff
changeset
|
1986 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
|
1987 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
|
1988 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
|
1989 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
|
1990 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
|
1991 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
|
1992 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
|
1993 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
|
1994 } |
|
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
|
1995 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
|
1996 if (fp) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
1997 fclose(fp); |
|
18803
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
1998 if (mod != Py_None) { |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
1999 /* Irrespective of the success of this load, make a |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2000 reference to it in the parent package module. |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2001 A copy gets saved in the modules dictionary |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2002 under the full name, so get a reference from |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2003 there, if need be. (The exception is when |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2004 the load failed with a SyntaxError -- then |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2005 there's no trace in sys.modules. In that case, |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2006 of course, do nothing extra.) */ |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2007 res = m; |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2008 if (res == NULL) |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2009 res = PyDict_GetItemString(modules, fullname); |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2010 if (res != NULL && |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2011 PyObject_SetAttrString(mod, subname, res) < 0) { |
|
763bb6fae280
SF Patch #441791, with changes: when "import foo.bar" fails with an
Guido van Rossum <guido@python.org>
parents:
18388
diff
changeset
|
2012 Py_XDECREF(m); |
|
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
|
2013 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
|
2014 } |
|
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
|
2015 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2016 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2017 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2018 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2019 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2020 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2021 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2022 /* 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
|
2023 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
|
2024 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2025 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2026 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
|
2027 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
2028 PyObject *modules = PyImport_GetModuleDict(); |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2029 PyObject *path = NULL; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2030 char *name, *subname; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2031 char buf[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2032 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2033 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
|
2034 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2035 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
|
2036 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2037 "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
|
2038 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2039 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2040 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
|
2041 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
|
2042 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
2043 if (m != PyDict_GetItemString(modules, name)) { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2044 PyErr_Format(PyExc_ImportError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2045 "reload(): module %.200s not in sys.modules", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2046 name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2047 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2048 } |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2049 subname = strrchr(name, '.'); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2050 if (subname == NULL) |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2051 subname = name; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2052 else { |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2053 PyObject *parentname, *parent; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2054 parentname = PyString_FromStringAndSize(name, (subname-name)); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2055 if (parentname == NULL) |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2056 return NULL; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2057 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
|
2058 Py_DECREF(parentname); |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2059 if (parent == NULL) { |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2060 PyErr_Format(PyExc_ImportError, |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2061 "reload(): parent %.200s not in sys.modules", |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2062 name); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2063 return NULL; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2064 } |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2065 subname++; |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2066 path = PyObject_GetAttrString(parent, "__path__"); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2067 if (path == NULL) |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2068 PyErr_Clear(); |
|
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2069 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2070 buf[0] = '\0'; |
|
6250
3fa4b7ae0e6b
Fix reload() for package submodules.
Guido van Rossum <guido@python.org>
parents:
6249
diff
changeset
|
2071 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
|
2072 Py_XDECREF(path); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2073 if (fdp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2074 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2075 m = load_module(name, fp, buf, fdp->type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2076 if (fp) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2077 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
|
2078 return m; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2079 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2080 |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2081 |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2082 /* 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
|
2083 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
|
2084 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
|
2085 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
|
2086 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
|
2087 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
|
2088 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
|
2089 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
|
2090 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2091 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2092 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
|
2093 { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2094 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
|
2095 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
|
2096 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
|
2097 PyObject *globals = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2098 PyObject *import = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2099 PyObject *builtins = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2100 PyObject *r = NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2101 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2102 /* Initialize constant string objects */ |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2103 if (silly_list == NULL) { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2104 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
|
2105 if (import_str == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2106 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2107 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
|
2108 if (builtins_str == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2109 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2110 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
|
2111 if (silly_list == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2112 return NULL; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2113 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2114 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2115 /* 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
|
2116 globals = PyEval_GetGlobals(); |
|
16712
6341f8d909ac
The code in PyImport_Import() tried to save itself a bit of work and
Guido van Rossum <guido@python.org>
parents:
16534
diff
changeset
|
2117 if (globals != NULL) { |
| 9431 | 2118 Py_INCREF(globals); |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2119 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
|
2120 if (builtins == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2121 goto err; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2122 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2123 else { |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2124 /* 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
|
2125 PyErr_Clear(); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2126 |
|
16712
6341f8d909ac
The code in PyImport_Import() tried to save itself a bit of work and
Guido van Rossum <guido@python.org>
parents:
16534
diff
changeset
|
2127 builtins = PyImport_ImportModuleEx("__builtin__", |
|
6341f8d909ac
The code in PyImport_Import() tried to save itself a bit of work and
Guido van Rossum <guido@python.org>
parents:
16534
diff
changeset
|
2128 NULL, NULL, NULL); |
|
6341f8d909ac
The code in PyImport_Import() tried to save itself a bit of work and
Guido van Rossum <guido@python.org>
parents:
16534
diff
changeset
|
2129 if (builtins == NULL) |
|
6341f8d909ac
The code in PyImport_Import() tried to save itself a bit of work and
Guido van Rossum <guido@python.org>
parents:
16534
diff
changeset
|
2130 return NULL; |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2131 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
|
2132 if (globals == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2133 goto err; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2134 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2135 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2136 /* Get the __import__ function from the builtins */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18808
diff
changeset
|
2137 if (PyDict_Check(builtins)) { |
|
16986
c5a417e8d84c
Add some spaces around the "=" in assignments.
Fred Drake <fdrake@acm.org>
parents:
16947
diff
changeset
|
2138 import = PyObject_GetItem(builtins, import_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18808
diff
changeset
|
2139 if (import == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18808
diff
changeset
|
2140 PyErr_SetObject(PyExc_KeyError, import_str); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18808
diff
changeset
|
2141 } |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2142 else |
|
16986
c5a417e8d84c
Add some spaces around the "=" in assignments.
Fred Drake <fdrake@acm.org>
parents:
16947
diff
changeset
|
2143 import = PyObject_GetAttr(builtins, import_str); |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2144 if (import == NULL) |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2145 goto err; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2146 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2147 /* 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
|
2148 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
|
2149 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
|
2150 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2151 err: |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2152 Py_XDECREF(globals); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2153 Py_XDECREF(builtins); |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2154 Py_XDECREF(import); |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
2155 |
|
6028
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2156 return r; |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2157 } |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2158 |
|
292193170da1
Added Jim Fulton's PyImport_Import(), which calls whatever
Guido van Rossum <guido@python.org>
parents:
5980
diff
changeset
|
2159 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2160 /* 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
|
2161 importing modules. |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2162 */ |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2163 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2164 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2165 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
|
2166 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2167 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
|
2168 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2169 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
|
2170 return NULL; |
| 12543 | 2171 buf[0] = (char) ((pyc_magic >> 0) & 0xff); |
| 2172 buf[1] = (char) ((pyc_magic >> 8) & 0xff); | |
| 2173 buf[2] = (char) ((pyc_magic >> 16) & 0xff); | |
| 2174 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
|
2175 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2176 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
|
2177 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2178 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2179 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2180 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
|
2181 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2182 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
|
2183 struct filedescr *fdp; |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2184 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2185 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
|
2186 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2187 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
|
2188 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
|
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 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
|
2191 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
|
2192 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
|
2193 if (item == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2194 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
|
2195 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2196 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2197 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
|
2198 Py_DECREF(list); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2199 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
|
2200 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2201 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2202 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
|
2203 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2204 return list; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2205 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2206 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2207 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2208 call_find_module(char *name, PyObject *path) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2209 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13266
diff
changeset
|
2210 extern int fclose(FILE *); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2211 PyObject *fob, *ret; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2212 struct filedescr *fdp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2213 char pathname[MAXPATHLEN+1]; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2214 FILE *fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2215 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2216 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
|
2217 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
|
2218 path = NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2219 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
|
2220 if (fdp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2221 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2222 if (fp != NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2223 fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2224 if (fob == NULL) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2225 fclose(fp); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2226 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2227 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2228 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2229 else { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2230 fob = Py_None; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2231 Py_INCREF(fob); |
|
16828
3b05212c1616
Implement PEP 235: Import on Case-Insensitive Platforms.
Tim Peters <tim.peters@gmail.com>
parents:
16712
diff
changeset
|
2232 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2233 ret = Py_BuildValue("Os(ssi)", |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2234 fob, pathname, fdp->suffix, fdp->mode, fdp->type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2235 Py_DECREF(fob); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2236 return ret; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2237 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2238 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2239 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2240 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
|
2241 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2242 char *name; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2243 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
|
2244 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
|
2245 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2246 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
|
2247 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2248 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2249 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2250 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
|
2251 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2252 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2253 int ret; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2254 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
|
2255 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
|
2256 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2257 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
|
2258 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
|
2259 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2260 if (ret == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2261 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2262 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
|
2263 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2264 m = PyImport_AddModule(name); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2265 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
|
2266 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2267 } |
|
1844
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2268 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2269 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2270 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
|
2271 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2272 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2273 int ret; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2274 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
|
2275 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
|
2276 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2277 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
|
2278 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
|
2279 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2280 if (ret == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2281 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2282 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
|
2283 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2284 m = PyImport_AddModule(name); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2285 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
|
2286 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2287 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2288 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2289 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2290 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
|
2291 { |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2292 char *name; |
| 3139 | 2293 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2294 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
|
2295 return NULL; |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2296 return get_frozen_object(name); |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2297 } |
|
964d76f49a5e
add imp.get_frozen_object()
Guido van Rossum <guido@python.org>
parents:
2868
diff
changeset
|
2298 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2299 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2300 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
|
2301 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2302 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
|
2303 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
|
2304 return NULL; |
|
22918
15c18bc9d715
is_builtin() is not a Boolean -- it can return -1, 0, 1. [SF #541652]
Guido van Rossum <guido@python.org>
parents:
22866
diff
changeset
|
2305 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
|
2306 } |
|
d1e6c9a64a56
* Python/import.c: support *.o/*.so as alternative for
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2307 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2308 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2309 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
|
2310 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2311 char *name; |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
2312 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
|
2313 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
|
2314 return NULL; |
|
8544
35a2151fb1c3
Ignore Windows case check for ALL CAPS 8.3 files
Guido van Rossum <guido@python.org>
parents:
8374
diff
changeset
|
2315 p = find_frozen(name); |
|
22866
a561ff1b4ffa
Return bools from functions named is_<whatever>().
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
2316 return PyBool_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
|
2317 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2318 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2319 static FILE * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2320 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
|
2321 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2322 FILE *fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2323 if (fob == NULL) { |
|
23585
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
2324 if (mode[0] == 'U') |
|
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
2325 mode = "r" PY_STDIOTEXTMODE; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2326 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
|
2327 if (fp == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2328 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
|
2329 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2330 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2331 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
|
2332 if (fp == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2333 PyErr_SetString(PyExc_ValueError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2334 "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
|
2335 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2336 return fp; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2337 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2338 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2339 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2340 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
|
2341 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2342 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2343 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2344 PyObject *fob = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2345 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
|
2346 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
|
2347 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
|
2348 &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
|
2349 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2350 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
|
2351 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
|
2352 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2353 m = load_compiled_module(name, pathname, fp); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2354 if (fob == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2355 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
|
2356 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2357 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2358 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2359 #ifdef HAVE_DYNAMIC_LOADING |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2360 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2361 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2362 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
|
2363 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2364 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2365 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2366 PyObject *fob = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2367 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
|
2368 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
|
2369 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
|
2370 &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
|
2371 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2372 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
|
2373 fp = get_file(pathname, fob, "r"); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2374 if (fp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2375 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2376 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2377 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
|
2378 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
|
2379 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2380 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2381 #endif /* HAVE_DYNAMIC_LOADING */ |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2382 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2383 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2384 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
|
2385 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2386 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2387 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2388 PyObject *fob = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2389 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
|
2390 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
|
2391 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
|
2392 &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
|
2393 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2394 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
|
2395 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
|
2396 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2397 m = load_source_module(name, pathname, fp); |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2398 if (fob == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2399 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
|
2400 return m; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2401 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2402 |
|
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
|
2403 #ifdef macintosh |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2404 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2405 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
|
2406 { |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2407 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
|
2408 char *pathname; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2409 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
|
2410 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2411 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
|
2412 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
|
2413 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
|
2414 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
|
2415 } |
|
d65c485e0ad8
Added hooks to support importing pyc code from a resource on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2294
diff
changeset
|
2416 #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
|
2417 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2418 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2419 imp_load_module(PyObject *self, PyObject *args) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2420 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2421 char *name; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2422 PyObject *fob; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2423 char *pathname; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2424 char *suffix; /* Unused */ |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2425 char *mode; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2426 int type; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2427 FILE *fp; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2428 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2429 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
|
2430 &name, &fob, &pathname, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2431 &suffix, &mode, &type)) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2432 return NULL; |
|
23586
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2433 if (*mode) { |
|
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2434 /* Mode must start with 'r' or 'U' and must not contain '+'. |
|
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2435 Implicit in this test is the assumption that the mode |
|
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2436 may contain other modifiers like 'b' or 't'. */ |
|
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2437 |
|
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2438 if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) { |
|
23585
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
2439 PyErr_Format(PyExc_ValueError, |
|
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
2440 "invalid file open mode %.200s", mode); |
|
0e8370e70888
Cover a few corners in the 'U' mode integration to make imp work.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23554
diff
changeset
|
2441 return NULL; |
|
23586
fba57e40f547
imp_load_module(): correct and comment the sense of the test for '+'
Guido van Rossum <guido@python.org>
parents:
23585
diff
changeset
|
2442 } |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2443 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2444 if (fob == Py_None) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2445 fp = NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2446 else { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2447 if (!PyFile_Check(fob)) { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2448 PyErr_SetString(PyExc_ValueError, |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2449 "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
|
2450 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2451 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2452 fp = get_file(pathname, fob, mode); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2453 if (fp == NULL) |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2454 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2455 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2456 return load_module(name, fp, pathname, type); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2457 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2458 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2459 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2460 imp_load_package(PyObject *self, PyObject *args) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2461 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2462 char *name; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2463 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
|
2464 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
|
2465 return NULL; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2466 return load_package(name, pathname); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2467 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2468 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2469 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2470 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
|
2471 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2472 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
|
2473 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
|
2474 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2475 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
|
2476 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2477 |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2478 /* Doc strings */ |
|
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2479 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2480 PyDoc_STRVAR(doc_imp, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2481 "This module provides the components needed to build your own\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2482 __import__ function. Undocumented functions are obsolete."); |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2483 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2484 PyDoc_STRVAR(doc_find_module, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2485 "find_module(name, [path]) -> (file, filename, (suffix, mode, type))\n\ |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2486 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
|
2487 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
|
2488 The module name cannot contain '.'; to search for a submodule of a\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2489 package, pass the submodule name and the package's __path__."); |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2490 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2491 PyDoc_STRVAR(doc_load_module, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2492 "load_module(name, file, filename, (suffix, mode, type)) -> module\n\ |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2493 Load a module, given information returned by find_module().\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2494 The module name must include the full package name, if any."); |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2495 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2496 PyDoc_STRVAR(doc_get_magic, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2497 "get_magic() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2498 Return the magic number for .pyc or .pyo files."); |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2499 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2500 PyDoc_STRVAR(doc_get_suffixes, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2501 "get_suffixes() -> [(suffix, mode, type), ...]\n\ |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2502 Return a list of (suffix, mode, type) tuples describing the files\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2503 that find_module() looks for."); |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2504 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2505 PyDoc_STRVAR(doc_new_module, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2506 "new_module(name) -> module\n\ |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2507 Create a new module. Do not enter it in sys.modules.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2508 The module name must include the full package name, if any."); |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2509 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2510 PyDoc_STRVAR(doc_lock_held, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2511 "lock_held() -> 0 or 1\n\ |
|
19596
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
2512 Return 1 if the import lock is currently held.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23586
diff
changeset
|
2513 On platforms without threads, return 0."); |
|
19596
1be18ef869a4
Add a new function imp.lock_held(), and use it to skip test_threaded_import
Tim Peters <tim.peters@gmail.com>
parents:
19238
diff
changeset
|
2514 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2515 static PyMethodDef imp_methods[] = { |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2516 {"find_module", imp_find_module, METH_VARARGS, doc_find_module}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2517 {"get_magic", imp_get_magic, METH_VARARGS, doc_get_magic}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2518 {"get_suffixes", imp_get_suffixes, METH_VARARGS, doc_get_suffixes}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2519 {"load_module", imp_load_module, METH_VARARGS, doc_load_module}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2520 {"new_module", imp_new_module, METH_VARARGS, doc_new_module}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2521 {"lock_held", imp_lock_held, METH_VARARGS, doc_lock_held}, |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2522 /* The rest are obsolete */ |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2523 {"get_frozen_object", imp_get_frozen_object, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2524 {"init_builtin", imp_init_builtin, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2525 {"init_frozen", imp_init_frozen, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2526 {"is_builtin", imp_is_builtin, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2527 {"is_frozen", imp_is_frozen, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2528 {"load_compiled", imp_load_compiled, METH_VARARGS}, |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2529 #ifdef HAVE_DYNAMIC_LOADING |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2530 {"load_dynamic", imp_load_dynamic, METH_VARARGS}, |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11602
diff
changeset
|
2531 #endif |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2532 {"load_package", imp_load_package, METH_VARARGS}, |
|
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
|
2533 #ifdef macintosh |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2534 {"load_resource", imp_load_resource, METH_VARARGS}, |
|
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
|
2535 #endif |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22651
diff
changeset
|
2536 {"load_source", imp_load_source, METH_VARARGS}, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2537 {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
|
2538 }; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2539 |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8613
diff
changeset
|
2540 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2541 setint(PyObject *d, char *name, int value) |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2542 { |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2543 PyObject *v; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2544 int err; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2545 |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2546 v = PyInt_FromLong((long)value); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2547 err = PyDict_SetItemString(d, name, v); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2548 Py_XDECREF(v); |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2549 return err; |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2550 } |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2551 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2552 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2553 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
|
2554 { |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2555 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
|
2556 |
|
6305
6e1fa76e7940
Added docstrings. Not for the obsolete functions though.
Guido van Rossum <guido@python.org>
parents:
6304
diff
changeset
|
2557 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
|
2558 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
|
2559 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
|
2560 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2561 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
|
2562 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
|
2563 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
|
2564 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
|
2565 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
|
2566 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
|
2567 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
|
2568 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
|
2569 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
|
2570 |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2571 failure: |
|
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6055
diff
changeset
|
2572 ; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2040
diff
changeset
|
2573 } |
|
8330
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2574 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2575 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2576 /* 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
|
2577 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
|
2578 *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
|
2579 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
|
2580 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2581 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
|
2582 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2583 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2584 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
|
2585 { |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2586 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
|
2587 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
|
2588 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
|
2589 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2590 /* 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
|
2591 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
|
2592 ; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2593 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
|
2594 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
|
2595 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
|
2596 ; |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2597 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2598 /* 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
|
2599 p = our_copy; |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12543
diff
changeset
|
2600 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
|
2601 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
|
2602 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
|
2603 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2604 /* 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
|
2605 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
|
2606 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
|
2607 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
|
2608 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
|
2609 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2610 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
|
2611 } |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2612 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2613 /* 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
|
2614 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2615 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
2616 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
|
2617 { |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2618 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
|
2619 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2620 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
|
2621 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2622 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
|
2623 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
|
2624 |
|
7a1e7da922f8
New APIs for embedding applications that want to add their own entries
Guido van Rossum <guido@python.org>
parents:
8012
diff
changeset
|
2625 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
|
2626 } |
