Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 37879:f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described
here (it's not a Py3K issue, just something Py3K discovers):
http://mail.python.org/pipermail/python-dev/2006-April/064051.html
Hye-Shik Chang promised to look for a fix, so no need to fix it here. The
tests that are expected to break are:
test_codecencodings_cn
test_codecencodings_hk
test_codecencodings_jp
test_codecencodings_kr
test_codecencodings_tw
test_codecs
test_multibytecodec
This merge fixes an actual test failure (test_weakref) in this branch,
though, so I believe merging is the right thing to do anyway.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Fri, 21 Apr 2006 10:40:58 +0000 |
| parents | 49c6eb688906 |
| children | 29ae5e0fc348 |
line wrap: on
line diff
--- a/Python/import.c Fri Apr 21 09:47:09 2006 +0000 +++ b/Python/import.c Fri Apr 21 10:40:58 2006 +0000 @@ -17,6 +17,9 @@ #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif +#ifdef __cplusplus +extern "C" { +#endif extern time_t PyOS_GetLastModificationTime(char *, FILE *); /* In getmtime.c */ @@ -40,6 +43,7 @@ Python 1.5: 20121 Python 1.5.1: 20121 Python 1.5.2: 20121 + Python 1.6: 50428 Python 2.0: 50823 Python 2.0.1: 50823 Python 2.1: 60202 @@ -1217,12 +1221,12 @@ #endif if (!PyString_Check(v)) continue; - len = PyString_Size(v); + len = PyString_GET_SIZE(v); if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) { Py_XDECREF(copy); continue; /* Too long */ } - strcpy(buf, PyString_AsString(v)); + strcpy(buf, PyString_AS_STRING(v)); if (strlen(buf) != len) { Py_XDECREF(copy); continue; /* v contains '\0' */ @@ -1934,6 +1938,16 @@ } tail = next; } + if (tail == Py_None) { + /* If tail is Py_None, both get_parent and load_next found + an empty module name: someone called __import__("") or + doctored faulty bytecode */ + Py_DECREF(tail); + Py_DECREF(head); + PyErr_SetString(PyExc_ValueError, + "Empty module name"); + return NULL; + } if (fromlist != NULL) { if (fromlist == Py_None || !PyObject_IsTrue(fromlist)) @@ -2094,7 +2108,8 @@ PyObject *result; if (strlen(name) == 0) { - /* empty module name only happens in 'from . import' */ + /* completely empty module name should only happen in + 'from . import' (or '__import__("")')*/ Py_INCREF(mod); *p_name = NULL; return mod; @@ -2936,3 +2951,7 @@ return PyImport_ExtendInittab(newtab); } + +#ifdef __cplusplus +} +#endif
