From 3046647478f584b665a33c3a1c3d1d6117979d64 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Feb 2011 23:16:19 +0000 Subject: Issue #3080: Remove unused argument of _PyImport_GetDynLoadFunc() The first argument, fqname, was not used. --- Python/importdl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Python/importdl.c') diff --git a/Python/importdl.c b/Python/importdl.c index 9caed453aa..74ca8a7cca 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -12,8 +12,7 @@ #include "importdl.h" -extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name, - const char *shortname, +extern dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname, const char *pathname, FILE *fp); @@ -48,7 +47,7 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) shortname = lastdot+1; } - p0 = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp); + p0 = _PyImport_GetDynLoadFunc(shortname, pathname, fp); p = (PyObject*(*)(void))p0; if (PyErr_Occurred()) goto error; -- cgit v1.2.1 From 17a3c1b5c7bb9b20e89c29ee9fcf6ee78a6cce82 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 7 Mar 2011 18:20:56 +0100 Subject: Issue #3080: Import builtins using Unicode strings - is_builtin(), init_builtin(), load_builtin() and other builtin related functions use Unicode strings, instead of byte strings - Rename _PyImport_FixupExtensionUnicode() to _PyImport_FixupExtensionObject() - Rename _PyImport_FindExtensionUnicode() to _PyImport_FindExtensionObject() --- Python/importdl.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'Python/importdl.c') diff --git a/Python/importdl.c b/Python/importdl.c index 74ca8a7cca..f0e1f55d27 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -26,17 +26,23 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) dl_funcptr p0; PyObject* (*p)(void); struct PyModuleDef *def; - PyObject *result; + PyObject *nameobj, *result; path = PyUnicode_DecodeFSDefault(pathname); if (path == NULL) return NULL; - if ((m = _PyImport_FindExtensionUnicode(name, path)) != NULL) { + nameobj = PyUnicode_FromString(name); + if (nameobj == NULL) + return NULL; + m = _PyImport_FindExtensionObject(nameobj, path); + if (m != NULL) { + Py_DECREF(nameobj); Py_INCREF(m); result = m; goto finally; } + Py_DECREF(nameobj); lastdot = strrchr(name, '.'); if (lastdot == NULL) { packagecontext = NULL; @@ -82,12 +88,18 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) else Py_INCREF(path); - if (_PyImport_FixupExtensionUnicode(m, name, path) < 0) + nameobj = PyUnicode_FromString(name); + if (nameobj == NULL) + return NULL; + if (_PyImport_FixupExtensionObject(m, nameobj, path) < 0) { + Py_DECREF(nameobj); goto error; + } if (Py_VerboseFlag) - PySys_WriteStderr( - "import %s # dynamically loaded from %s\n", - name, pathname); + PySys_FormatStderr( + "import %U # dynamically loaded from %s\n", + nameobj, pathname); + Py_DECREF(nameobj); result = m; goto finally; -- cgit v1.2.1 From 7c1cd6d18d5ac37ec86183e7fabcf35ff11e3d21 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 14 Mar 2011 15:54:07 -0400 Subject: Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path Document also that dynamic module names are ASCII only --- Python/importdl.c | 70 +++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 41 deletions(-) (limited to 'Python/importdl.c') diff --git a/Python/importdl.c b/Python/importdl.c index f0e1f55d27..629f3e294e 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -15,67 +15,68 @@ extern dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname, const char *pathname, FILE *fp); - +/* name should be ASCII only because the C language doesn't accept non-ASCII + identifiers, and dynamic modules are written in C. */ PyObject * -_PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) +_PyImport_LoadDynamicModule(PyObject *name, PyObject *path, FILE *fp) { PyObject *m; - PyObject *path; - char *lastdot, *shortname, *packagecontext, *oldcontext; + PyObject *pathbytes; + char *namestr, *lastdot, *shortname, *packagecontext, *oldcontext; dl_funcptr p0; PyObject* (*p)(void); struct PyModuleDef *def; - PyObject *nameobj, *result; - path = PyUnicode_DecodeFSDefault(pathname); - if (path == NULL) + namestr = _PyUnicode_AsString(name); + if (namestr == NULL) return NULL; - nameobj = PyUnicode_FromString(name); - if (nameobj == NULL) - return NULL; - m = _PyImport_FindExtensionObject(nameobj, path); + m = _PyImport_FindExtensionObject(name, path); if (m != NULL) { - Py_DECREF(nameobj); Py_INCREF(m); - result = m; - goto finally; + return m; } - Py_DECREF(nameobj); - lastdot = strrchr(name, '.'); + + lastdot = strrchr(namestr, '.'); if (lastdot == NULL) { packagecontext = NULL; - shortname = name; + shortname = namestr; } else { - packagecontext = name; + packagecontext = namestr; shortname = lastdot+1; } - p0 = _PyImport_GetDynLoadFunc(shortname, pathname, fp); + pathbytes = PyUnicode_EncodeFSDefault(path); + if (pathbytes == NULL) + return NULL; + p0 = _PyImport_GetDynLoadFunc(shortname, + PyBytes_AS_STRING(pathbytes), fp); + Py_DECREF(pathbytes); p = (PyObject*(*)(void))p0; if (PyErr_Occurred()) - goto error; + return NULL; if (p == NULL) { PyErr_Format(PyExc_ImportError, - "dynamic module does not define init function (PyInit_%.200s)", + "dynamic module does not define init function" + " (PyInit_%s)", shortname); - goto error; + return NULL; } oldcontext = _Py_PackageContext; _Py_PackageContext = packagecontext; m = (*p)(); _Py_PackageContext = oldcontext; if (m == NULL) - goto error; + return NULL; if (PyErr_Occurred()) { Py_DECREF(m); PyErr_Format(PyExc_SystemError, "initialization of %s raised unreported exception", shortname); - goto error; + return NULL; } /* Remember pointer to module init function. */ @@ -88,26 +89,13 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) else Py_INCREF(path); - nameobj = PyUnicode_FromString(name); - if (nameobj == NULL) + if (_PyImport_FixupExtensionObject(m, name, path) < 0) return NULL; - if (_PyImport_FixupExtensionObject(m, nameobj, path) < 0) { - Py_DECREF(nameobj); - goto error; - } if (Py_VerboseFlag) PySys_FormatStderr( - "import %U # dynamically loaded from %s\n", - nameobj, pathname); - Py_DECREF(nameobj); - result = m; - goto finally; - -error: - result = NULL; -finally: - Py_DECREF(path); - return result; + "import %U # dynamically loaded from %R\n", + name, path); + return m; } #endif /* HAVE_DYNAMIC_LOADING */ -- cgit v1.2.1 From d206f91d5300b6ee4d99d9d45f9a4160fa384366 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 4 Apr 2011 23:05:53 +0200 Subject: Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes on Windows. --- Python/importdl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Python/importdl.c') diff --git a/Python/importdl.c b/Python/importdl.c index 629f3e294e..69bb7117ad 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -12,8 +12,13 @@ #include "importdl.h" +#ifdef MS_WINDOWS +extern dl_funcptr _PyImport_GetDynLoadWindows(const char *shortname, + PyObject *pathname, FILE *fp); +#else extern dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname, const char *pathname, FILE *fp); +#endif /* name should be ASCII only because the C language doesn't accept non-ASCII identifiers, and dynamic modules are written in C. */ @@ -22,7 +27,9 @@ PyObject * _PyImport_LoadDynamicModule(PyObject *name, PyObject *path, FILE *fp) { PyObject *m; +#ifndef MS_WINDOWS PyObject *pathbytes; +#endif char *namestr, *lastdot, *shortname, *packagecontext, *oldcontext; dl_funcptr p0; PyObject* (*p)(void); @@ -48,12 +55,16 @@ _PyImport_LoadDynamicModule(PyObject *name, PyObject *path, FILE *fp) shortname = lastdot+1; } +#ifdef MS_WINDOWS + p0 = _PyImport_GetDynLoadWindows(shortname, path, fp); +#else pathbytes = PyUnicode_EncodeFSDefault(path); if (pathbytes == NULL) return NULL; p0 = _PyImport_GetDynLoadFunc(shortname, PyBytes_AS_STRING(pathbytes), fp); Py_DECREF(pathbytes); +#endif p = (PyObject*(*)(void))p0; if (PyErr_Occurred()) return NULL; -- cgit v1.2.1