From 599ed75a674f7ad2c983783ed6f3a75bd5ccae18 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Sat, 23 May 2015 22:24:10 +1000 Subject: PEP 489: Multi-phase extension module initialization Known limitations of the current implementation: - documentation changes are incomplete - there's a reference leak I haven't tracked down yet The leak is most visible by running: ./python -m test -R3:3 test_importlib However, you can also see it by running: ./python -X showrefcount Importing the array or _testmultiphase modules, and then deleting them from both sys.modules and the local namespace shows significant increases in the total number of active references each cycle. By contrast, with _testcapi (which continues to use single-phase initialisation) the global refcounts stabilise after a couple of cycles. --- Python/dynload_next.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Python/dynload_next.c') diff --git a/Python/dynload_next.c b/Python/dynload_next.c index 85c95b41bb..c555b3802f 100644 --- a/Python/dynload_next.c +++ b/Python/dynload_next.c @@ -27,8 +27,9 @@ const char *_PyImport_DynLoadFiletab[] = {".so", NULL}; #define LINKOPTIONS NSLINKMODULE_OPTION_BINDNOW| \ NSLINKMODULE_OPTION_RETURN_ON_ERROR|NSLINKMODULE_OPTION_PRIVATE #endif -dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname, - const char *pathname, FILE *fp) +dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix, + const char *shortname, + const char *pathname, FILE *fp) { dl_funcptr p = NULL; char funcname[258]; @@ -39,7 +40,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname, const char *errString; char errBuf[512]; - PyOS_snprintf(funcname, sizeof(funcname), "_PyInit_%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), "_%20s_%.200s", prefix, shortname); #ifdef USE_DYLD_GLOBAL_NAMESPACE if (NSIsSymbolNameDefined(funcname)) { -- cgit v1.2.1 From 4fb0cf62c7f9df26671a1e58646c8511e30048a1 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 23 May 2015 14:13:41 -0700 Subject: Issue #24268: Fix import naming when loading extension modules. Patch by Petr Viktorin. --- Python/dynload_next.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/dynload_next.c') diff --git a/Python/dynload_next.c b/Python/dynload_next.c index c555b3802f..83a8b2bb31 100644 --- a/Python/dynload_next.c +++ b/Python/dynload_next.c @@ -40,7 +40,7 @@ dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix, const char *errString; char errBuf[512]; - PyOS_snprintf(funcname, sizeof(funcname), "_%20s_%.200s", prefix, shortname); + PyOS_snprintf(funcname, sizeof(funcname), "_%.20s_%.200s", prefix, shortname); #ifdef USE_DYLD_GLOBAL_NAMESPACE if (NSIsSymbolNameDefined(funcname)) { -- cgit v1.2.1