Skip to content

Commit 7cc7575

Browse files
committed
Reverted accidental commit (from r87159)
1 parent 69b826e commit 7cc7575

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

Modules/_lsprof.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,31 @@ normalizeUserObj(PyObject *obj)
176176
if (fn->m_self == NULL) {
177177
/* built-in function: look up the module name */
178178
PyObject *mod = fn->m_module;
179-
PyObject *modname;
180-
if (mod != NULL) {
181-
if (PyUnicode_Check(mod)) {
182-
modname = mod;
183-
Py_INCREF(modname);
179+
const char *modname;
180+
if (mod && PyUnicode_Check(mod)) {
181+
/* XXX: The following will truncate module names with embedded
182+
* null-characters. It is unlikely that this can happen in
183+
* practice and the concequences are not serious enough to
184+
* introduce extra checks here.
185+
*/
186+
modname = _PyUnicode_AsString(mod);
187+
if (modname == NULL) {
188+
modname = "<encoding error>";
189+
PyErr_Clear();
184190
}
185-
else if (PyModule_Check(mod)) {
186-
modname = PyModule_GetNameObject(mod);
187-
if (modname == NULL)
188-
PyErr_Clear();
191+
}
192+
else if (mod && PyModule_Check(mod)) {
193+
modname = PyModule_GetName(mod);
194+
if (modname == NULL) {
195+
PyErr_Clear();
196+
modname = "builtins";
189197
}
190198
}
191-
if (modname != NULL &&
192-
PyUnicode_CompareWithASCIIString(modname, "builtins") != 0)
193-
return PyUnicode_FromFormat("<%U.%s>",
199+
else {
200+
modname = "builtins";
201+
}
202+
if (strcmp(modname, "builtins") != 0)
203+
return PyUnicode_FromFormat("<%s.%s>",
194204
modname,
195205
fn->m_ml->ml_name);
196206
else

Objects/moduleobject.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ PyModule_GetDict(PyObject *m)
168168
return d;
169169
}
170170

171-
PyObject *
172-
PyModule_GetNameObject(PyObject *m)
171+
const char *
172+
PyModule_GetName(PyObject *m)
173173
{
174174
PyObject *d;
175175
PyObject *nameobj;
@@ -185,21 +185,7 @@ PyModule_GetNameObject(PyObject *m)
185185
PyErr_SetString(PyExc_SystemError, "nameless module");
186186
return NULL;
187187
}
188-
Py_INCREF(nameobj);
189-
return nameobj;
190-
}
191-
192-
const char *
193-
PyModule_GetName(PyObject *m)
194-
{
195-
PyObject *nameobj;
196-
char *utf8;
197-
nameobj = PyModule_GetNameObject(m);
198-
if (nameobj == NULL)
199-
return NULL;
200-
utf8 = _PyUnicode_AsString(nameobj);
201-
Py_DECREF(nameobj);
202-
return utf8;
188+
return _PyUnicode_AsString(nameobj);
203189
}
204190

205191
PyObject*

0 commit comments

Comments
 (0)