[Python-checkins] r82702 - in python/branches/import_unicode: PC/import_nt.c Python/import.c
victor.stinner
python-checkins at python.org
Fri Jul 9 01:33:07 CEST 2010
Author: victor.stinner
Date: Fri Jul 9 01:33:07 2010
New Revision: 82702
Log:
Move buffer into PyWin_FindRegisteredModule()
The function now returns the path as a PyUnicodeObject*
Modified:
python/branches/import_unicode/PC/import_nt.c
python/branches/import_unicode/Python/import.c
Modified: python/branches/import_unicode/PC/import_nt.c
==============================================================================
--- python/branches/import_unicode/PC/import_nt.c (original)
+++ python/branches/import_unicode/PC/import_nt.c Fri Jul 9 01:33:07 2010
@@ -17,9 +17,11 @@
FILE *PyWin_FindRegisteredModule(const char *moduleName,
struct filedescr **ppFileDesc,
- char *pathBuf,
- Py_ssize_t pathLen)
+ PyObject **pathobj)
{
+ /* FIXME: use wchar_t* type */
+ char pathBuf[MAXPATHLEN+1];
+ Py_ssize_t pathLen = sizeof(pathBuf);
char *moduleKey;
const char keyPrefix[] = "Software\\Python\\PythonCore\\";
const char keySuffix[] = "\\Modules\\";
@@ -45,6 +47,9 @@
sizeof(keySuffix) +
strlen(moduleName) +
sizeof(debugString) - 1;
+
+ *pathobj = NULL;
+
/* alloca == no free required, but memory only local to fn,
* also no heap fragmentation!
*/
@@ -80,7 +85,14 @@
if (fdp->suffix == NULL)
return NULL;
fp = fopen(pathBuf, fdp->mode);
- if (fp != NULL)
+ if (fp == NULL)
+ return NULL;
+ *pathobj = PyUnicode_DecodeFSDefault(pathBuf);
+ if (*pathobj != NULL)
*ppFileDesc = fdp;
+ else {
+ fclose(fp);
+ fp = NULL;
+ }
return fp;
}
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:33:07 2010
@@ -1623,7 +1623,7 @@
#ifdef MS_COREDLL
extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **,
- char *, Py_ssize_t);
+ PyObject **);
#endif
static int case_ok(PyObject *, Py_ssize_t, Py_ssize_t, char *);
@@ -1707,8 +1707,7 @@
if (search_path == NULL) {
#ifdef MS_COREDLL
- /* FIXME: use buf buffer */
- char bbuf[MAXPATHLEN+1];
+ PyObject *winpath;
#endif
if (is_builtin(name)) {
*path = PyUnicode_DecodeFSDefault(name);
@@ -1717,16 +1716,14 @@
return &fd_builtin;
}
#ifdef MS_COREDLL
- fp = PyWin_FindRegisteredModule(name, &fdp, bbuf, sizeof(bbuf));
+ fp = PyWin_FindRegisteredModule(name, &fdp, &winpath);
if (fp != NULL) {
- *path = PyUnicode_DecodeFSDefault(bbuf);
- if (*path == NULL) {
- fclose(fp);
- return NULL;
- }
*p_fp = fp;
+ *path = winpath;
return fdp;
}
+ else if (PyErr_Occurred())
+ return NULL;
#endif
search_path = PySys_GetObject("path");
}
More information about the Python-checkins
mailing list