[Python-checkins] r87160 - in python/branches/py3k: Modules/_lsprof.c Objects/moduleobject.c

alexander.belopolsky python-checkins at python.org
Fri Dec 10 19:14:16 CET 2010


Author: alexander.belopolsky
Date: Fri Dec 10 19:14:16 2010
New Revision: 87160

Log:
Reverted accidental commit (from r87159)

Modified:
   python/branches/py3k/Modules/_lsprof.c
   python/branches/py3k/Objects/moduleobject.c

Modified: python/branches/py3k/Modules/_lsprof.c
==============================================================================
--- python/branches/py3k/Modules/_lsprof.c	(original)
+++ python/branches/py3k/Modules/_lsprof.c	Fri Dec 10 19:14:16 2010
@@ -176,21 +176,31 @@
     if (fn->m_self == NULL) {
         /* built-in function: look up the module name */
         PyObject *mod = fn->m_module;
-        PyObject *modname;
-        if (mod != NULL) {
-            if (PyUnicode_Check(mod)) {
-                modname = mod;
-                Py_INCREF(modname);
+        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();
             }
-            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 && 
-            PyUnicode_CompareWithASCIIString(modname, "builtins") != 0)
-            return PyUnicode_FromFormat("<%U.%s>",
+        else {
+            modname = "builtins";
+        }
+        if (strcmp(modname, "builtins") != 0)
+            return PyUnicode_FromFormat("<%s.%s>",
                                         modname,
                                         fn->m_ml->ml_name);
         else

Modified: python/branches/py3k/Objects/moduleobject.c
==============================================================================
--- python/branches/py3k/Objects/moduleobject.c	(original)
+++ python/branches/py3k/Objects/moduleobject.c	Fri Dec 10 19:14:16 2010
@@ -168,8 +168,8 @@
     return d;
 }
 
-PyObject *
-PyModule_GetNameObject(PyObject *m)
+const char *
+PyModule_GetName(PyObject *m)
 {
     PyObject *d;
     PyObject *nameobj;
@@ -185,21 +185,7 @@
         PyErr_SetString(PyExc_SystemError, "nameless module");
         return NULL;
     }
-    Py_INCREF(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;
+    return _PyUnicode_AsString(nameobj);
 }
 
 PyObject*


More information about the Python-checkins mailing list