changeset: 96359:d89bab1f160e parent: 96357:1acb6c88b901 parent: 96358:784f372d701a user: Benjamin Peterson date: Fri May 29 17:11:36 2015 -0500 files: Misc/NEWS description: merge 3.5 (#24328) diff -r 1acb6c88b901 -r d89bab1f160e Lib/test/test_importlib/extension/test_loader.py --- a/Lib/test/test_importlib/extension/test_loader.py Sat May 30 00:58:09 2015 +0300 +++ b/Lib/test/test_importlib/extension/test_loader.py Fri May 29 17:11:36 2015 -0500 @@ -177,6 +177,14 @@ self.assertEqual(module.__name__, 'pkg.' + self.name) self.assertEqual(module.str_const, 'something different') + def test_load_short_name(self): + '''Test loading module with a one-character name''' + module = self.load_module_by_name('x') + self.assertIsInstance(module, types.ModuleType) + self.assertEqual(module.__name__, 'x') + self.assertEqual(module.str_const, 'something different') + assert 'x' not in sys.modules + def test_load_twice(self): '''Test that 2 loads result in 2 module objects''' module1 = self.load_module_by_name(self.name) diff -r 1acb6c88b901 -r d89bab1f160e Misc/NEWS --- a/Misc/NEWS Sat May 30 00:58:09 2015 +0300 +++ b/Misc/NEWS Fri May 29 17:11:36 2015 -0500 @@ -22,6 +22,8 @@ Core and Builtins ----------------- +- Issue #24328: Fix importing one character extension modules. + - Issue #11205: In dictionary displays, evaluate the key before the value. - Issue #24285: Fixed regression that prevented importing extension modules diff -r 1acb6c88b901 -r d89bab1f160e Modules/_testmultiphase.c --- a/Modules/_testmultiphase.c Sat May 30 00:58:09 2015 +0300 +++ b/Modules/_testmultiphase.c Fri May 29 17:11:36 2015 -0500 @@ -321,6 +321,14 @@ return PyModuleDef_Init(&def_nonascii_kana); } +/*** Module with a single-character name ***/ + +PyMODINIT_FUNC +PyInit_x(PyObject *spec) +{ + return PyModuleDef_Init(&main_def); +} + /**** Testing NULL slots ****/ static PyModuleDef null_slots_def = TEST_MODULE_DEF( diff -r 1acb6c88b901 -r d89bab1f160e Python/importdl.c --- a/Python/importdl.c Sat May 30 00:58:09 2015 +0300 +++ b/Python/importdl.c Fri May 29 17:11:36 2015 -0500 @@ -34,10 +34,11 @@ */ static PyObject * get_encoded_name(PyObject *name, const char **hook_prefix) { - char *buf; PyObject *tmp; PyObject *encoded = NULL; - Py_ssize_t name_len, lastdot, i; + PyObject *modname = NULL; + Py_ssize_t name_len, lastdot; + _Py_IDENTIFIER(replace); /* Get the short name (substring after last dot) */ name_len = PyUnicode_GetLength(name); @@ -71,16 +72,14 @@ } } - buf = PyBytes_AS_STRING(encoded); - assert(Py_REFCNT(encoded) == 1); - for (i = 0; i < PyBytes_GET_SIZE(encoded) + 1; i++) { - if (buf[i] == '-') { - buf[i] = '_'; - } - } + /* Replace '-' by '_' */ + modname = _PyObject_CallMethodId(encoded, &PyId_replace, "cc", '-', '_'); + if (modname == NULL) + goto error; Py_DECREF(name); - return encoded; + Py_DECREF(encoded); + return modname; error: Py_DECREF(name); Py_XDECREF(encoded);