diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-08 23:49:04 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-08 23:49:04 +0100 |
commit | 4d6c1c476aee975867c5375f9fc175f69d4b6266 (patch) | |
tree | 9cc8d4268113b7062f8c5390d9bff9f54e16ffd9 /Python/import.c | |
parent | db536afee14ebd2b74488313e1b1db5cd17fefdc (diff) | |
download | cpython-git-4d6c1c476aee975867c5375f9fc175f69d4b6266.tar.gz |
Issue #3080: _PyWin_FindRegisteredModule() returns the path as Unicode
* Document the function
* Use RegQueryValueW() instead of RegQueryValueA()
* Use _Py_fopen() instead of fopen()
* Allocate registry key on the heap, not on the stack, and handle memory
allocation failure
* Handle Python exception in find_module()
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c index d43b881c2f..8fab810eec 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1591,8 +1591,8 @@ PyImport_GetImporter(PyObject *path) { pathname and an open file. Return NULL if the module is not found. */ #ifdef MS_COREDLL -extern FILE *_PyWin_FindRegisteredModule(const char *, struct filedescr **, - char *, Py_ssize_t); +extern FILE *_PyWin_FindRegisteredModule(PyObject *, struct filedescr **, + PyObject **p_path); #endif static int case_ok(char *, Py_ssize_t, Py_ssize_t, char *); @@ -1679,6 +1679,9 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, } if (path == NULL) { +#ifdef MS_COREDLL + PyObject *filename, *filename_bytes; +#endif nameobj = PyUnicode_FromString(name); if (nameobj == NULL) return NULL; @@ -1687,14 +1690,24 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, strcpy(buf, name); return &fd_builtin; } - Py_DECREF(nameobj); #ifdef MS_COREDLL - fp = _PyWin_FindRegisteredModule(name, &fdp, buf, buflen); + fp = _PyWin_FindRegisteredModule(nameobj, &fdp, &filename); if (fp != NULL) { + Py_DECREF(nameobj); + filename_bytes = PyUnicode_EncodeFSDefault(filename); + Py_DECREF(filename); + if (filename_bytes == NULL) + return NULL; + strncpy(buf, PyBytes_AS_STRING(filename_bytes), buflen); + buf[buflen-1] = '\0'; + Py_DECREF(filename_bytes); *p_fp = fp; return fdp; } + else if (PyErr_Occurred()) + return NULL; #endif + Py_DECREF(nameobj); path = PySys_GetObject("path"); } |