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

victor.stinner python-checkins at python.org
Fri Dec 3 18:06:43 CET 2010


Author: victor.stinner
Date: Fri Dec 3 18:06:43 2010
New Revision: 86979
Log:
import: use PyUnicode_FSConverter to support bytes path and PEP 383
(instead of PyArg_Parse*() with "es" format and Py_FileSystemDefaultEncoding)
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 Dec 3 18:06:43 2010
@@ -3206,14 +3206,14 @@
 static PyObject *
 imp_find_module(PyObject *self, PyObject *args)
 {
- char *name;
+ PyObject *name;
 PyObject *ret, *path = NULL;
- if (!PyArg_ParseTuple(args, "es|O:find_module",
- Py_FileSystemDefaultEncoding, &name,
+ if (!PyArg_ParseTuple(args, "O&|O:find_module",
+ PyUnicode_FSConverter, &name,
 &path))
 return NULL;
- ret = call_find_module(name, path);
- PyMem_Free(name);
+ ret = call_find_module(PyBytes_AS_STRING(name), path);
+ Py_DECREF(name);
 return ret;
 }
 
@@ -3331,23 +3331,23 @@
 imp_load_compiled(PyObject *self, PyObject *args)
 {
 char *name;
- char *pathname;
+ PyObject *pathname;
 PyObject *fob = NULL;
 PyObject *m;
 FILE *fp;
- if (!PyArg_ParseTuple(args, "ses|O:load_compiled",
+ if (!PyArg_ParseTuple(args, "sO&|O:load_compiled",
 &name,
- Py_FileSystemDefaultEncoding, &pathname,
+ PyUnicode_FSConverter, &pathname,
 &fob))
 return NULL;
- fp = get_file(pathname, fob, "rb");
+ fp = get_file(PyBytes_AS_STRING(pathname), fob, "rb");
 if (fp == NULL) {
- PyMem_Free(pathname);
+ Py_DECREF(pathname);
 return NULL;
 }
- m = load_compiled_module(name, pathname, fp);
+ m = load_compiled_module(name, PyBytes_AS_STRING(pathname), fp);
 fclose(fp);
- PyMem_Free(pathname);
+ Py_DECREF(pathname);
 return m;
 }
 
@@ -3386,22 +3386,22 @@
 imp_load_source(PyObject *self, PyObject *args)
 {
 char *name;
- char *pathname;
+ PyObject *pathname;
 PyObject *fob = NULL;
 PyObject *m;
 FILE *fp;
- if (!PyArg_ParseTuple(args, "ses|O:load_source",
+ if (!PyArg_ParseTuple(args, "sO&|O:load_source",
 &name,
- Py_FileSystemDefaultEncoding, &pathname,
+ PyUnicode_FSConverter, &pathname,
 &fob))
 return NULL;
- fp = get_file(pathname, fob, "r");
+ fp = get_file(PyBytes_AS_STRING(pathname), fob, "r");
 if (fp == NULL) {
- PyMem_Free(pathname);
+ Py_DECREF(pathname);
 return NULL;
 }
- m = load_source_module(name, pathname, fp);
- PyMem_Free(pathname);
+ m = load_source_module(name, PyBytes_AS_STRING(pathname), fp);
+ Py_DECREF(pathname);
 fclose(fp);
 return m;
 }
@@ -3455,13 +3455,13 @@
 imp_load_package(PyObject *self, PyObject *args)
 {
 char *name;
- char *pathname;
+ PyObject *pathname;
 PyObject * ret;
- if (!PyArg_ParseTuple(args, "ses:load_package",
- &name, Py_FileSystemDefaultEncoding, &pathname))
+ if (!PyArg_ParseTuple(args, "sO&:load_package",
+ &name, PyUnicode_FSConverter, &pathname))
 return NULL;
- ret = load_package(name, pathname);
- PyMem_Free(pathname);
+ ret = load_package(name, PyBytes_AS_STRING(pathname));
+ Py_DECREF(pathname);
 return ret;
 }
 
@@ -3534,21 +3534,23 @@
 {
 static char *kwlist[] = {"path", NULL};
 
+ PyObject *pathname_obj;
 char *pathname;
 char buf[MAXPATHLEN+1];
 
 if (!PyArg_ParseTupleAndKeywords(
- args, kws, "es", kwlist,
- Py_FileSystemDefaultEncoding, &pathname))
+ args, kws, "O&", kwlist,
+ PyUnicode_FSConverter, &pathname_obj))
 return NULL;
 
+ pathname = PyBytes_AS_STRING(pathname_obj);
 if (make_source_pathname(pathname, buf) == NULL) {
 PyErr_Format(PyExc_ValueError, "Not a PEP 3147 pyc path: %s",
 pathname);
- PyMem_Free(pathname);
+ Py_DECREF(pathname_obj);
 return NULL;
 }
- PyMem_Free(pathname);
+ Py_DECREF(pathname_obj);
 return PyUnicode_FromString(buf);
 }
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /