mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Patch by Just van Rossum that changes how we search for submodules of
frozen packages. (I *think* this means that we can now have a built-in module bar that's a submodule of a frozen package foo, by registering the built-in module with a name "foo.bar" in the table of builtin modules.)
This commit is contained in:
parent
bd3a527f93
commit
0506a431d5
1 changed files with 20 additions and 19 deletions
|
@ -819,8 +819,8 @@ static int check_case(char *, int, int, char *);
|
||||||
static int find_init_module Py_PROTO((char *)); /* Forward */
|
static int find_init_module Py_PROTO((char *)); /* Forward */
|
||||||
|
|
||||||
static struct filedescr *
|
static struct filedescr *
|
||||||
find_module(name, path, buf, buflen, p_fp)
|
find_module(realname, path, buf, buflen, p_fp)
|
||||||
char *name;
|
char *realname;
|
||||||
PyObject *path;
|
PyObject *path;
|
||||||
/* Output parameters: */
|
/* Output parameters: */
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -835,7 +835,25 @@ find_module(name, path, buf, buflen, p_fp)
|
||||||
static struct filedescr fd_frozen = {"", "", PY_FROZEN};
|
static struct filedescr fd_frozen = {"", "", PY_FROZEN};
|
||||||
static struct filedescr fd_builtin = {"", "", C_BUILTIN};
|
static struct filedescr fd_builtin = {"", "", C_BUILTIN};
|
||||||
static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
|
static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
|
||||||
|
char name[MAXPATHLEN+1];
|
||||||
|
|
||||||
|
strcpy(name, realname);
|
||||||
|
|
||||||
|
if (path != NULL && PyString_Check(path)) {
|
||||||
|
/* Submodule of "frozen" package:
|
||||||
|
Set name to the fullname, path to NULL
|
||||||
|
and continue as "usual" */
|
||||||
|
if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) {
|
||||||
|
PyErr_SetString(PyExc_ImportError,
|
||||||
|
"full frozen module name too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(buf, PyString_AsString(path));
|
||||||
|
strcat(buf, ".");
|
||||||
|
strcat(buf, name);
|
||||||
|
strcpy(name, buf);
|
||||||
|
path = NULL;
|
||||||
|
}
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
if (is_builtin(name)) {
|
if (is_builtin(name)) {
|
||||||
strcpy(buf, name);
|
strcpy(buf, name);
|
||||||
|
@ -855,23 +873,6 @@ find_module(name, path, buf, buflen, p_fp)
|
||||||
#endif
|
#endif
|
||||||
path = PySys_GetObject("path");
|
path = PySys_GetObject("path");
|
||||||
}
|
}
|
||||||
else if (PyString_Check(path)) {
|
|
||||||
/* Submodule of frozen package */
|
|
||||||
if (PyString_Size(path) + 1 + strlen(name) >= (unsigned int)buflen) {
|
|
||||||
PyErr_SetString(PyExc_ImportError,
|
|
||||||
"full frozen module name too long");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(buf, PyString_AsString(path));
|
|
||||||
strcat(buf, ".");
|
|
||||||
strcat(buf, name);
|
|
||||||
if (find_frozen(buf) != NULL)
|
|
||||||
return &fd_frozen;
|
|
||||||
PyErr_Format(PyExc_ImportError,
|
|
||||||
"frozen module %.200s not found", buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path == NULL || !PyList_Check(path)) {
|
if (path == NULL || !PyList_Check(path)) {
|
||||||
PyErr_SetString(PyExc_ImportError,
|
PyErr_SetString(PyExc_ImportError,
|
||||||
"sys.path must be a list of directory names");
|
"sys.path must be a list of directory names");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue