[Python-checkins] r82667 - python/branches/import_unicode/Python/import.c

victor.stinner python-checkins at python.org
Fri Jul 9 01:32:15 CEST 2010


Author: victor.stinner
Date: Fri Jul  9 01:32:15 2010
New Revision: 82667

Log:
update_compiled_module() pathname is an object

not a char*

Modified:
   python/branches/import_unicode/Python/import.c

Modified: python/branches/import_unicode/Python/import.c
==============================================================================
--- python/branches/import_unicode/Python/import.c	(original)
+++ python/branches/import_unicode/Python/import.c	Fri Jul  9 01:32:15 2010
@@ -1218,24 +1218,17 @@
 }
 
 static int
-update_compiled_module(PyCodeObject *co, char *pathname)
+update_compiled_module(PyCodeObject *co, PyObject *newname)
 {
-    PyObject *oldname, *newname;
+    PyObject *oldname;
 
-    newname = PyUnicode_DecodeFSDefault(pathname);
-    if (newname == NULL)
-        return -1;
-
-    if (!PyUnicode_Compare(co->co_filename, newname)) {
-        Py_DECREF(newname);
+    if (!PyUnicode_Compare(co->co_filename, newname))
         return 0;
-    }
 
     oldname = co->co_filename;
     Py_INCREF(oldname);
     update_code_filenames(co, oldname, newname);
     Py_DECREF(oldname);
-    Py_DECREF(newname);
     return 1;
 }
 
@@ -1252,6 +1245,7 @@
     char *cpathname;
     PyCodeObject *co;
     PyObject *m;
+    PyObject *pathobj;
 
     if (fstat(fileno(fp), &st) != 0) {
         PyErr_Format(PyExc_RuntimeError,
@@ -1278,8 +1272,12 @@
         fclose(fpc);
         if (co == NULL)
             return NULL;
-        if (update_compiled_module(co, pathname) < 0)
+        pathobj = PyUnicode_DecodeFSDefault(pathname);
+        if (pathobj == NULL)
+            return NULL;
+        if (update_compiled_module(co, pathobj) < 0)
             return NULL;
+        Py_DECREF(pathobj);
         if (Py_VerboseFlag)
             PySys_WriteStderr("import %s # precompiled from %s\n",
                 name, cpathname);


More information about the Python-checkins mailing list