diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-20 21:37:17 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-20 21:37:17 (GMT) |
commit | 6ae1e7f04e9817dd4a92584c608469a47eea2f56 (patch) | |
tree | b979958421bc7065133c2b0fbe9539b8bfe2dae0 /Python | |
parent | 6a1454f3a441b6f84cabaff250b2744a5e4f4ec0 (diff) | |
download | cpython-6ae1e7f04e9817dd4a92584c608469a47eea2f56.zip cpython-6ae1e7f04e9817dd4a92584c608469a47eea2f56.tar.gz cpython-6ae1e7f04e9817dd4a92584c608469a47eea2f56.tar.bz2 |
Issue #3080: imp.load_module() accepts None for the module path
imp.find_module() returns None as module path for builtin and frozen builtins.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c index 38960b1..abc3906 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3744,17 +3744,22 @@ imp_load_source(PyObject *self, PyObject *args) static PyObject * imp_load_module(PyObject *self, PyObject *args) { - PyObject *name, *fob, *pathname, *ret; + PyObject *name, *fob, *pathname, *pathname_obj, *ret; char *suffix; /* Unused */ char *mode; int type; FILE *fp; - if (!PyArg_ParseTuple(args, "UOO&(ssi):load_module", - &name, &fob, - PyUnicode_FSDecoder, &pathname, - &suffix, &mode, &type)) + if (!PyArg_ParseTuple(args, "UOO(ssi):load_module", + &name, &fob, &pathname_obj, &suffix, &mode, &type)) return NULL; + if (pathname_obj != Py_None) { + if (!PyUnicode_FSDecoder(pathname_obj, &pathname)) + return NULL; + } + else + pathname = NULL; + if (*mode) { /* Mode must start with 'r' or 'U' and must not contain '+'. Implicit in this test is the assumption that the mode @@ -3763,7 +3768,7 @@ imp_load_module(PyObject *self, PyObject *args) if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) { PyErr_Format(PyExc_ValueError, "invalid file open mode %.200s", mode); - Py_DECREF(pathname); + Py_XDECREF(pathname); return NULL; } } @@ -3772,12 +3777,12 @@ imp_load_module(PyObject *self, PyObject *args) else { fp = get_file(NULL, fob, mode); if (fp == NULL) { - Py_DECREF(pathname); + Py_XDECREF(pathname); return NULL; } } ret = load_module(name, fp, pathname, type, NULL); - Py_DECREF(pathname); + Py_XDECREF(pathname); if (fp) fclose(fp); return ret; |