Kaydet (Commit) 7edb5dfc authored tarafından Victor Stinner's avatar Victor Stinner

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.
üst 99563b1d
...@@ -176,36 +176,29 @@ normalizeUserObj(PyObject *obj) ...@@ -176,36 +176,29 @@ normalizeUserObj(PyObject *obj)
if (fn->m_self == NULL) { if (fn->m_self == NULL) {
/* built-in function: look up the module name */ /* built-in function: look up the module name */
PyObject *mod = fn->m_module; PyObject *mod = fn->m_module;
const char *modname; PyObject *modname = NULL;
if (mod && PyUnicode_Check(mod)) { if (mod != NULL) {
/* XXX: The following will truncate module names with embedded if (PyUnicode_Check(mod)) {
* null-characters. It is unlikely that this can happen in modname = mod;
* practice and the concequences are not serious enough to Py_INCREF(modname);
* introduce extra checks here. }
*/ else if (PyModule_Check(mod)) {
modname = _PyUnicode_AsString(mod); modname = PyModule_GetNameObject(mod);
if (modname == NULL) { if (modname == NULL)
modname = "<encoding error>";
PyErr_Clear(); PyErr_Clear();
} }
} }
else if (mod && PyModule_Check(mod)) { if (modname != NULL) {
modname = PyModule_GetName(mod); if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) {
if (modname == NULL) { PyObject *result;
PyErr_Clear(); result = PyUnicode_FromFormat("<%U.%s>", modname,
modname = "builtins"; fn->m_ml->ml_name);
Py_DECREF(modname);
return result;
} }
Py_DECREF(modname);
} }
else { return PyUnicode_FromFormat("<%s>", fn->m_ml->ml_name);
modname = "builtins";
}
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);
} }
else { else {
/* built-in method: try to return /* built-in method: try to return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment