mirror of
https://github.com/python/cpython.git
synced 2025-09-09 18:32:22 +00:00
Fix importing of shared libraries from inside packages.
This is a bit of a hack: when the shared library is loaded, the module name is "package.module", but the module calls Py_InitModule*() with just "module" for the name. The shared library loader squirrels away the true name of the module in _Py_PackageContext, and Py_InitModule*() will substitute this (if the name actually matches).
This commit is contained in:
parent
ee6fd1c392
commit
2e58ff3ef5
2 changed files with 26 additions and 3 deletions
|
@ -39,6 +39,9 @@ typedef extended va_double;
|
|||
typedef double va_double;
|
||||
#endif
|
||||
|
||||
/* Package context -- the full module name for package imports */
|
||||
char *_Py_PackageContext = NULL;
|
||||
|
||||
/* Py_InitModule4() parameters:
|
||||
- name is the module name
|
||||
- methods is the list of top-level functions
|
||||
|
@ -69,6 +72,13 @@ Py_InitModule4(name, methods, doc, passthrough, module_api_version)
|
|||
if (module_api_version != PYTHON_API_VERSION)
|
||||
fprintf(stderr, api_version_warning,
|
||||
name, PYTHON_API_VERSION, name, module_api_version);
|
||||
if (_Py_PackageContext != NULL) {
|
||||
char *p = strrchr(_Py_PackageContext, '.');
|
||||
if (p != NULL && strcmp(name, p+1) == 0) {
|
||||
name = _Py_PackageContext;
|
||||
_Py_PackageContext = NULL;
|
||||
}
|
||||
}
|
||||
if ((m = PyImport_AddModule(name)) == NULL)
|
||||
return NULL;
|
||||
d = PyModule_GetDict(m);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue