annotate Python/importdl.c @ 44156:fb84bd9500a4

Remove special-casing of integer operations, to stop using PyInt_CheckExact.
author Martin v. Löwis <martin@v.loewis.de>
date Tue, 04 Dec 2007 20:34:12 +0000
parents 50599bbb0c67
children 94f64f11fdd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* 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
3
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5314
diff changeset
4 #include "Python.h"
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
5
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
6 /* ./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
7 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
8 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
9 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
10 */
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
11 #ifdef HAVE_DYNAMIC_LOADING
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
12
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 #include "importdl.h"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
11600
14561e8395bb Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents: 11469
diff changeset
15 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
16 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
17 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
18
3898
94c6bf6fd7f4 If NO_DYNAMIC_LINK is defined, load_dynamic_module() will always fail.
Guido van Rossum <guido@python.org>
parents: 3732
diff changeset
19
11600
14561e8395bb Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents: 11469
diff changeset
20
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5314
diff changeset
21 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
22 _PyImport_LoadDynamicModule(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:
diff changeset
23 {
25040
db49ee76b7d0 Simplify, and avoid PyModule_GetDict() while we're at it.
Fred Drake <fdrake@acm.org>
parents: 20462
diff changeset
24 PyObject *m;
43573
50599bbb0c67 Move decl so it compiles with C89.
Neal Norwitz <nnorwitz@gmail.com>
parents: 43569
diff changeset
25 PyObject *path;
20462
2f0c5af4d5ea SF patch #471839: Bug when extensions import extensions (Shane Hathaway)
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
26 char *lastdot, *shortname, *packagecontext, *oldcontext;
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
27 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
28
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5894
diff changeset
29 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
30 Py_INCREF(m);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5894
diff changeset
31 return m;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5894
diff changeset
32 }
6602
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
33 lastdot = strrchr(name, '.');
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
34 if (lastdot == NULL) {
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
35 packagecontext = NULL;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
36 shortname = name;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
37 }
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
38 else {
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
39 packagecontext = name;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
40 shortname = lastdot+1;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
41 }
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
42
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
43 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
44 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
45 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 if (p == NULL) {
6602
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
47 PyErr_Format(PyExc_ImportError,
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
48 "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
49 shortname);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 }
20462
2f0c5af4d5ea SF patch #471839: Bug when extensions import extensions (Shane Hathaway)
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
52 oldcontext = _Py_PackageContext;
6602
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 6479
diff changeset
53 _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
54 (*p)();
20462
2f0c5af4d5ea SF patch #471839: Bug when extensions import extensions (Shane Hathaway)
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
55 _Py_PackageContext = oldcontext;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5894
diff changeset
56 if (PyErr_Occurred())
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5894
diff changeset
57 return NULL;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
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
59 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
60 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
61 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
62 "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
63 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
4042
6b4d0f1a0ae9 Many little fixes:
Guido van Rossum <guido@python.org>
parents: 3988
diff changeset
65 /* Remember the filename as the __file__ attribute */
43569
19319e70fc3e Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents: 30316
diff changeset
66 path = PyUnicode_DecodeFSDefault(pathname);
19319e70fc3e Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents: 30316
diff changeset
67 if (PyModule_AddObject(m, "__file__", path) < 0)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5314
diff changeset
68 PyErr_Clear(); /* Not important enough to report */
30316
19611d101d23 Patch #794826: Add __file__ in dynamically loaded modules for multiple
Martin v. Löwis <martin@v.loewis.de>
parents: 25040
diff changeset
69
19611d101d23 Patch #794826: Add __file__ in dynamically loaded modules for multiple
Martin v. Löwis <martin@v.loewis.de>
parents: 25040
diff changeset
70 if (_PyImport_FixupExtension(name, pathname) == NULL)
19611d101d23 Patch #794826: Add __file__ in dynamically loaded modules for multiple
Martin v. Löwis <martin@v.loewis.de>
parents: 25040
diff changeset
71 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5314
diff changeset
72 if (Py_VerboseFlag)
9329
7f242f29a45f Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents: 9299
diff changeset
73 PySys_WriteStderr(
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 "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
75 name, pathname);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5314
diff changeset
76 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
77 return m;
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
78 }
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11600
diff changeset
79
11600
14561e8395bb Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents: 11469
diff changeset
80 #endif /* HAVE_DYNAMIC_LOADING */