summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-11-05 22:48:33 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-11-05 22:48:33 (GMT)
commitd968e27581e42874427979c87885997c59af5ba5 (patch)
treed6c2030a8e16c15bfd399c9a2a175070a38f47cd /Python
parent65676e407cd4beecf9ea482ae68926bff8329049 (diff)
downloadcpython-d968e27581e42874427979c87885997c59af5ba5.zip
cpython-d968e27581e42874427979c87885997c59af5ba5.tar.gz
cpython-d968e27581e42874427979c87885997c59af5ba5.tar.bz2
fix #4211: the __path__ of a frozen package should be a list.
Patch by Brett Cannon, review by Christian Heimes.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/Python/import.c b/Python/import.c
index 9c077fe..564ace88 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1293,37 +1293,16 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
Py_DECREF(meta_path);
}
- if (path != NULL && PyUnicode_Check(path)) {
- /* The only type of submodule allowed inside a "frozen"
- package are other frozen modules or packages. */
- char *p = _PyUnicode_AsString(path);
- if (strlen(p) + 1 + strlen(name) >= (size_t)buflen) {
- PyErr_SetString(PyExc_ImportError,
- "full frozen module name too long");
- return NULL;
- }
- strcpy(buf, p);
- strcat(buf, ".");
- strcat(buf, name);
- strcpy(name, buf);
- if (find_frozen(name) != NULL) {
- strcpy(buf, name);
- return &fd_frozen;
- }
- PyErr_Format(PyExc_ImportError,
- "No frozen submodule named %.200s", name);
- return NULL;
+ if (find_frozen(fullname) != NULL) {
+ strcpy(buf, fullname);
+ return &fd_frozen;
}
+
if (path == NULL) {
if (is_builtin(name)) {
strcpy(buf, name);
return &fd_builtin;
}
- if ((find_frozen(name)) != NULL) {
- strcpy(buf, name);
- return &fd_frozen;
- }
-
#ifdef MS_COREDLL
fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen);
if (fp != NULL) {
@@ -1333,6 +1312,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
#endif
path = PySys_GetObject("path");
}
+
if (path == NULL || !PyList_Check(path)) {
PyErr_SetString(PyExc_ImportError,
"sys.path must be a list of directory names");
@@ -1886,6 +1866,9 @@ find_frozen(char *name)
{
struct _frozen *p;
+ if (!name)
+ return NULL;
+
for (p = PyImport_FrozenModules; ; p++) {
if (p->name == NULL)
return NULL;
@@ -1959,7 +1942,7 @@ PyImport_ImportFrozenModule(char *name)
}
if (ispackage) {
/* Set __path__ to the package name */
- PyObject *d, *s;
+ PyObject *d, *s, *l;
int err;
m = PyImport_AddModule(name);
if (m == NULL)
@@ -1968,8 +1951,14 @@ PyImport_ImportFrozenModule(char *name)
s = PyUnicode_InternFromString(name);
if (s == NULL)
goto err_return;
- err = PyDict_SetItemString(d, "__path__", s);
- Py_DECREF(s);
+ l = PyList_New(1);
+ if (l == NULL) {
+ Py_DECREF(s);
+ goto err_return;
+ }
+ PyList_SET_ITEM(l, 0, s);
+ err = PyDict_SetItemString(d, "__path__", l);
+ Py_DECREF(l);
if (err != 0)
goto err_return;
}