changeset: 70899:b87eac0369b5 user: Victor Stinner date: Mon Jun 20 14:59:53 2011 +0200 files: Modules/_lsprof.c description: 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. diff -r f571ed28a9ba -r b87eac0369b5 Modules/_lsprof.c --- a/Modules/_lsprof.c Mon Jun 20 14:45:54 2011 +0200 +++ b/Modules/_lsprof.c Mon Jun 20 14:59:53 2011 +0200 @@ -176,36 +176,29 @@ 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 = ""; - PyErr_Clear(); + PyObject *modname = NULL; + if (mod != NULL) { + if (PyUnicode_Check(mod)) { + modname = mod; + Py_INCREF(modname); + } + else if (PyModule_Check(mod)) { + modname = PyModule_GetNameObject(mod); + if (modname == NULL) + PyErr_Clear(); } } - else if (mod && PyModule_Check(mod)) { - modname = PyModule_GetName(mod); - if (modname == NULL) { - PyErr_Clear(); - 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); } - else { - 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); + return PyUnicode_FromFormat("<%s>", fn->m_ml->ml_name); } else { /* built-in method: try to return

AltStyle によって変換されたページ (->オリジナル) /