Reverted accidental commit (from r87159)

This commit is contained in:
Alexander Belopolsky 2010-12-10 18:14:16 +00:00
parent fc55789cae
commit 532d091d05
2 changed files with 26 additions and 30 deletions

View File

@ -176,21 +176,31 @@ 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;
PyObject *modname; const char *modname;
if (mod != NULL) { if (mod && PyUnicode_Check(mod)) {
if (PyUnicode_Check(mod)) { /* XXX: The following will truncate module names with embedded
modname = mod; * null-characters. It is unlikely that this can happen in
Py_INCREF(modname); * practice and the concequences are not serious enough to
} * introduce extra checks here.
else if (PyModule_Check(mod)) { */
modname = PyModule_GetNameObject(mod); modname = _PyUnicode_AsString(mod);
if (modname == NULL) if (modname == NULL) {
PyErr_Clear(); modname = "<encoding error>";
PyErr_Clear();
} }
} }
if (modname != NULL && else if (mod && PyModule_Check(mod)) {
PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) modname = PyModule_GetName(mod);
return PyUnicode_FromFormat("<%U.%s>", if (modname == NULL) {
PyErr_Clear();
modname = "builtins";
}
}
else {
modname = "builtins";
}
if (strcmp(modname, "builtins") != 0)
return PyUnicode_FromFormat("<%s.%s>",
modname, modname,
fn->m_ml->ml_name); fn->m_ml->ml_name);
else else

View File

@ -168,8 +168,8 @@ PyModule_GetDict(PyObject *m)
return d; return d;
} }
PyObject * const char *
PyModule_GetNameObject(PyObject *m) PyModule_GetName(PyObject *m)
{ {
PyObject *d; PyObject *d;
PyObject *nameobj; PyObject *nameobj;
@ -185,21 +185,7 @@ PyModule_GetNameObject(PyObject *m)
PyErr_SetString(PyExc_SystemError, "nameless module"); PyErr_SetString(PyExc_SystemError, "nameless module");
return NULL; return NULL;
} }
Py_INCREF(nameobj); return _PyUnicode_AsString(nameobj);
return nameobj;
}
const char *
PyModule_GetName(PyObject *m)
{
PyObject *nameobj;
char *utf8;
nameobj = PyModule_GetNameObject(m);
if (nameobj == NULL)
return NULL;
utf8 = _PyUnicode_AsString(nameobj);
Py_DECREF(nameobj);
return utf8;
} }
PyObject* PyObject*