summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-05-29 22:10:30 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-05-29 22:10:30 (GMT)
commite20056c8f71a8e289016c0cbd5adb5826cd91f64 (patch)
tree3bdccf6b3978fc4c989e136093e6cff999d01785 /Python
parenta663121e10265bb4d05b715a262cb4c1d79da082 (diff)
downloadcpython-e20056c8f71a8e289016c0cbd5adb5826cd91f64.zip
cpython-e20056c8f71a8e289016c0cbd5adb5826cd91f64.tar.gz
cpython-e20056c8f71a8e289016c0cbd5adb5826cd91f64.tar.bz2
fix importing one char extension modules (closes #24328)
Diffstat (limited to 'Python')
-rw-r--r--Python/importdl.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/Python/importdl.c b/Python/importdl.c
index 579d2c5..1aa585d 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -34,10 +34,11 @@ static const char *nonascii_prefix = "PyInitU";
*/
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 @@ get_encoded_name(PyObject *name, const char **hook_prefix) {
}
}
- 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);