summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-06-20 12:59:53 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-06-20 12:59:53 (GMT)
commit7edb5dfcbc815e2479e4c68051bf1805d1c9348d (patch)
tree6cb46ecc2e28393bfb5db9a4b194d8fb3609d53a /Modules
parent99563b1df835218fd61fe1c86930b49dd55044be (diff)
downloadcpython-7edb5dfcbc815e2479e4c68051bf1805d1c9348d.zip
cpython-7edb5dfcbc815e2479e4c68051bf1805d1c9348d.tar.gz
cpython-7edb5dfcbc815e2479e4c68051bf1805d1c9348d.tar.bz2
Issue #6697: _lsprof: normalizeUserObj() doesn't encode/decode (UTF-8) the
module name anymore, only work on unicode strings. Therefore it doesn't truncate module names with embedded NUL characters, or fail if the module name contains surrogate characters (UTF-8 encoder fails on a surrogate character). Patch written by Alexander Belopolsky.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_lsprof.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index cc412bf..b0a226b 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -176,36 +176,29 @@ normalizeUserObj(PyObject *obj)
if (fn->m_self == NULL) {
/* built-in function: look up the module name */
PyObject *mod = fn->m_module;
- const char *modname;
- if (mod && PyUnicode_Check(mod)) {
- /* XXX: The following will truncate module names with embedded
- * null-characters. It is unlikely that this can happen in
- * practice and the concequences are not serious enough to
- * introduce extra checks here.
- */
- modname = _PyUnicode_AsString(mod);
- if (modname == NULL) {
- modname = "<encoding error>";
- PyErr_Clear();
+ PyObject *modname = NULL;
+ if (mod != NULL) {
+ if (PyUnicode_Check(mod)) {
+ modname = mod;
+ Py_INCREF(modname);
}
- }
- else if (mod && PyModule_Check(mod)) {
- modname = PyModule_GetName(mod);
- if (modname == NULL) {
- PyErr_Clear();
- modname = "builtins";
+ else if (PyModule_Check(mod)) {
+ modname = PyModule_GetNameObject(mod);
+ if (modname == NULL)
+ PyErr_Clear();
}
}
- else {
- modname = "builtins";
+ if (modname != NULL) {
+ if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) {
+ PyObject *result;
+ result = PyUnicode_FromFormat("<%U.%s>", modname,
+ fn->m_ml->ml_name);
+ Py_DECREF(modname);
+ return result;
+ }
+ Py_DECREF(modname);
}
- if (strcmp(modname, "builtins") != 0)
- return PyUnicode_FromFormat("<%s.%s>",
- modname,
- fn->m_ml->ml_name);
- else
- return PyUnicode_FromFormat("<%s>",
- fn->m_ml->ml_name);
+ return PyUnicode_FromFormat("<%s>", fn->m_ml->ml_name);
}
else {
/* built-in method: try to return