[Python-checkins] r82902 - in python/branches/import_unicode: Modules/zipimport.c Python/import.c
victor.stinner
python-checkins at python.org
Wed Jul 14 22:38:15 CEST 2010
Author: victor.stinner
Date: Wed Jul 14 22:38:15 2010
New Revision: 82902
Log:
get_data() takes a PyObject* for archive argument
* Rename fopen_unicode() to _Py_fopen(), it's now a private function
* Rename stat_unicode() to _Py_stat(), it's now a private function
Modified:
python/branches/import_unicode/Modules/zipimport.c
python/branches/import_unicode/Python/import.c
Modified: python/branches/import_unicode/Modules/zipimport.c
==============================================================================
--- python/branches/import_unicode/Modules/zipimport.c (original)
+++ python/branches/import_unicode/Modules/zipimport.c Wed Jul 14 22:38:15 2010
@@ -44,8 +44,9 @@
static PyObject *zip_directory_cache = NULL;
/* forward decls */
+extern FILE* _Py_fopen(PyObject *unicode, const char *mode);
static PyObject *read_directory(char *archive);
-static PyObject *get_data(char *archive, PyObject *toc_entry);
+static PyObject *get_data(PyObject *archive, PyObject *toc_entry);
static PyObject *get_module_code(ZipImporter *self, char *fullname,
int *p_ispackage, char **p_modpath);
@@ -441,7 +442,7 @@
PyErr_SetFromErrnoWithFilename(PyExc_IOError, path);
return NULL;
}
- return get_data(archive_str, toc_entry);
+ return get_data(self->archive, toc_entry);
}
static PyObject *
@@ -491,7 +492,7 @@
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) {
- PyObject *bytes = get_data(_PyUnicode_AsString(self->archive), toc_entry);
+ PyObject *bytes = get_data(self->archive, toc_entry);
PyObject *res = PyUnicode_FromString(PyBytes_AsString(bytes));
Py_XDECREF(bytes);
return res;
@@ -825,7 +826,7 @@
/* Given a path to a Zip file and a toc_entry, return the (uncompressed)
data as a new reference. */
static PyObject *
-get_data(char *archive, PyObject *toc_entry)
+get_data(PyObject *archive, PyObject *toc_entry)
{
PyObject *raw_data, *data = NULL, *decompress;
char *buf;
@@ -843,10 +844,10 @@
return NULL;
}
- fp = fopen(archive, "rb");
+ fp = _Py_fopen(archive, "rb");
if (!fp) {
PyErr_Format(PyExc_IOError,
- "zipimport: can not open file %s", archive);
+ "zipimport: can not open file %U", archive);
return NULL;
}
@@ -856,7 +857,7 @@
if (l != 0x04034B50) {
/* Bad: Local File Header */
PyErr_Format(ZipImportError,
- "bad local file header in %s",
+ "bad local file header in %U",
archive);
fclose(fp);
return NULL;
@@ -1086,12 +1087,8 @@
{
PyObject *data, *code;
char *modpath;
- char *archive = _PyUnicode_AsString(self->archive);
-
- if (archive == NULL)
- return NULL;
- data = get_data(archive, toc_entry);
+ data = get_data(self->archive, toc_entry);
if (data == NULL)
return NULL;
Modified: python/branches/import_unicode/Python/import.c
==============================================================================
--- python/branches/import_unicode/Python/import.c (original)
+++ python/branches/import_unicode/Python/import.c Wed Jul 14 22:38:15 2010
@@ -137,9 +137,9 @@
};
/* Forward */
-static FILE* fopen_unicode(PyObject *unicode, const char *mode);
+FILE* _Py_fopen(PyObject *unicode, const char *mode);
#ifdef HAVE_STAT
-static int stat_unicode(PyObject *unicode, struct stat *statbuf);
+int _Py_stat(PyObject *unicode, struct stat *statbuf);
static int find_init_module(PyObject *);
#endif
@@ -1084,7 +1084,7 @@
long magic;
long pyc_mtime;
- fp = fopen_unicode(cpathobj, "rb");
+ fp = _Py_fopen(cpathobj, "rb");
if (fp == NULL)
return NULL;
magic = PyMarshal_ReadLongFromFile(fp);
@@ -1471,7 +1471,7 @@
return NULL;
}
- if (stat_unicode(pyobj, &statbuf) == 0 &&
+ if (_Py_stat(pyobj, &statbuf) == 0 &&
S_ISREG(statbuf.st_mode)) {
return pyobj;
}
@@ -1828,7 +1828,7 @@
/* Check for package import (buf holds a directory name,
and there's an __init__ module in that directory */
#ifdef HAVE_STAT
- if (stat_unicode(unicode, &statbuf) == 0 && /* it exists */
+ if (_Py_stat(unicode, &statbuf) == 0 && /* it exists */
S_ISDIR(statbuf.st_mode) && /* it's a directory */
case_ok(unicode, 0, namelen, name)) { /* case matches */
if (find_init_module(unicode)) { /* and has __init__.py */
@@ -1894,7 +1894,7 @@
filemode = fdp->mode;
if (filemode[0] == 'U')
filemode = "r" PY_STDIOTEXTMODE;
- fp = fopen_unicode(unicode, filemode);
+ fp = _Py_fopen(unicode, filemode);
if (fp != NULL) {
if (case_ok(unicode, strlen(fdp->suffix), namelen, name)) {
break;
@@ -2024,7 +2024,7 @@
if (fullpath_bytes == NULL)
return 0;
- done = findfirst(PyBytes_AS_STRING(fullpath_bytes),
+ done = findfirst(PyBytes_AS_STRING(fullpath_bytes),
&ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC);
Py_DECREF(fullpath_bytes);
if (done) {
@@ -2119,9 +2119,10 @@
#endif
}
-static FILE*
-fopen_unicode(PyObject *unicode, const char *mode)
+FILE*
+_Py_fopen(PyObject *unicode, const char *mode)
{
+ /* FIXME: use _wfopen() on Windows */
FILE *f;
PyObject *bytes = PyUnicode_EncodeFSDefault(unicode);
if (bytes == NULL) {
@@ -2136,8 +2137,8 @@
#ifdef HAVE_STAT
-static int
-stat_unicode(PyObject *unicode, struct stat *statbuf)
+int
+_Py_stat(PyObject *unicode, struct stat *statbuf)
{
int ret;
PyObject *bytes = PyUnicode_EncodeFSDefault(unicode);
@@ -2159,7 +2160,7 @@
PyObject *unicode;
unicode = PyUnicode_FromFormat("%U%c__init__.py", bufobj, SEP);
- if (stat_unicode(unicode, &statbuf) == 0) {
+ if (_Py_stat(unicode, &statbuf) == 0) {
if (case_ok(unicode,
3, /* ignore ".py" suffix */
8, "__init__")) {
@@ -2170,7 +2171,7 @@
Py_DECREF(unicode);
unicode = PyUnicode_FromFormat("%U%c__init__.py%c", bufobj, SEP, Py_OptimizeFlag ? "o" : "c");
- if (stat_unicode(unicode, &statbuf) == 0) {
+ if (_Py_stat(unicode, &statbuf) == 0) {
if (case_ok(unicode,
4, /* ignore ".pyc" / ".pyo" suffix */
8, "__init__")) {
@@ -3467,7 +3468,7 @@
if (mode[0] == 'U')
mode = "r" PY_STDIOTEXTMODE;
if (fob == NULL) {
- fp = fopen_unicode(pathobj, mode);
+ fp = _Py_fopen(pathobj, mode);
}
else {
int fd = PyObject_AsFileDescriptor(fob);
@@ -3815,7 +3816,7 @@
struct stat statbuf;
int rv;
- rv = stat_unicode(pathobj, &statbuf);
+ rv = _Py_stat(pathobj, &statbuf);
if (rv == 0) {
/* it exists */
if (S_ISDIR(statbuf.st_mode)) {
More information about the Python-checkins
mailing list