[Python-checkins] r85549 - python/branches/py3k/Python/import.c

victor.stinner python-checkins at python.org
Fri Oct 15 22:34:32 CEST 2010


Author: victor.stinner
Date: Fri Oct 15 22:34:32 2010
New Revision: 85549

Log:
imp.cache_from_source() uses PyUnicode_FSConverter() to support surrogates in
module path


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

Modified: python/branches/py3k/Python/import.c
==============================================================================
--- python/branches/py3k/Python/import.c	(original)
+++ python/branches/py3k/Python/import.c	Fri Oct 15 22:34:32 2010
@@ -3460,21 +3460,24 @@
     static char *kwlist[] = {"path", "debug_override", NULL};
 
     char buf[MAXPATHLEN+1];
-    char *pathname, *cpathname;
+    PyObject *pathbytes;
+    char *cpathname;
     PyObject *debug_override = Py_None;
     int debug = !Py_OptimizeFlag;
 
     if (!PyArg_ParseTupleAndKeywords(
-                args, kws, "es|O", kwlist,
-                Py_FileSystemDefaultEncoding, &pathname, &debug_override))
+                args, kws, "O&|O", kwlist,
+                PyUnicode_FSConverter, &pathbytes, &debug_override))
         return NULL;
 
     if (debug_override != Py_None)
         if ((debug = PyObject_IsTrue(debug_override)) < 0)
             return NULL;
 
-    cpathname = make_compiled_pathname(pathname, buf, MAXPATHLEN+1, debug);
-    PyMem_Free(pathname);
+    cpathname = make_compiled_pathname(
+        PyBytes_AS_STRING(pathbytes),
+        buf, MAXPATHLEN+1, debug);
+    Py_DECREF(pathbytes);
 
     if (cpathname == NULL) {
         PyErr_Format(PyExc_SystemError, "path buffer too short");


More information about the Python-checkins mailing list