Mercurial > cpython-lru_cache-weakref
annotate Python/importdl.c @ 13267:4ce255495da3 legacy-trunk
Jack Jansen, Mac patch:
If we have stat.h include it if we don't have sys/stat.h
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 01 Jul 2000 01:08:11 +0000 |
| parents | 87ee82e5c56d |
| children | f79434ee41fa |
| rev | line source |
|---|---|
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
5 All rights reserved. |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 ******************************************************************/ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 /* Support for dynamic loading of extension modules */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
13 #include "Python.h" |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
14 |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
15 /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
16 supported on this platform. configure will then compile and link in one |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
17 of the dynload_*.c files, as appropriate. We will call a function in |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
18 those modules to get a function pointer to the module's init function. |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
19 */ |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
20 #ifdef HAVE_DYNAMIC_LOADING |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
21 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 #include "importdl.h" |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
24 extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name, |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
25 const char *shortname, |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
26 const char *pathname, FILE *fp); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 |
|
3898
94c6bf6fd7f4
If NO_DYNAMIC_LINK is defined, load_dynamic_module() will always fail.
Guido van Rossum <guido@python.org>
parents:
3732
diff
changeset
|
28 |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
29 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
30 PyObject * |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
31 _PyImport_LoadDynamicModule(name, pathname, fp) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 char *name; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 char *pathname; |
|
2724
6a9ecb05c679
Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2435
diff
changeset
|
34 FILE *fp; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
36 PyObject *m, *d, *s; |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
37 char *lastdot, *shortname, *packagecontext; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
38 dl_funcptr p; |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
39 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
40 if ((m = _PyImport_FindExtension(name, pathname)) != NULL) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
41 Py_INCREF(m); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
42 return m; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
43 } |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
44 lastdot = strrchr(name, '.'); |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
45 if (lastdot == NULL) { |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
46 packagecontext = NULL; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
47 shortname = name; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
48 } |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
49 else { |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
50 packagecontext = name; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
51 shortname = lastdot+1; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
52 } |
|
3907
ac1d5abfd78e
Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents:
3898
diff
changeset
|
53 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
54 p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp); |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
55 if (PyErr_Occurred()) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 if (p == NULL) { |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
58 PyErr_Format(PyExc_ImportError, |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
59 "dynamic module does not define init function (init%.200s)", |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
60 shortname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 } |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
63 _Py_PackageContext = packagecontext; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 (*p)(); |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
6479
diff
changeset
|
65 _Py_PackageContext = NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
66 if (PyErr_Occurred()) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
67 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
68 if (_PyImport_FixupExtension(name, pathname) == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
69 return NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 |
|
5894
e2df95b7be78
Removed some variables that are used to exchange data between import.c and
Guido van Rossum <guido@python.org>
parents:
5511
diff
changeset
|
71 m = PyDict_GetItemString(PyImport_GetModuleDict(), name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 if (m == NULL) { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
73 PyErr_SetString(PyExc_SystemError, |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5894
diff
changeset
|
74 "dynamic module not initialized properly"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 } |
| 4042 | 77 /* Remember the filename as the __file__ attribute */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
78 d = PyModule_GetDict(m); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
79 s = PyString_FromString(pathname); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
80 if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
81 PyErr_Clear(); /* Not important enough to report */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
82 Py_XDECREF(s); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
83 if (Py_VerboseFlag) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
9299
diff
changeset
|
84 PySys_WriteStderr( |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 "import %s # dynamically loaded from %s\n", |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 name, pathname); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
87 Py_INCREF(m); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 return m; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
89 } |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
90 |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
91 #endif /* HAVE_DYNAMIC_LOADING */ |
