diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-08-17 23:37:11 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-08-17 23:37:11 (GMT) |
commit | 6c00c1464f03deaafbbd5fdd212514cbf36b9bd4 (patch) | |
tree | 6928203bf836291bb890f9ebdfb7d71ac670ca98 /Objects/moduleobject.c | |
parent | 6951157475dd22893a2c5813cbbdac63de5c043f (diff) | |
download | cpython-6c00c1464f03deaafbbd5fdd212514cbf36b9bd4.zip cpython-6c00c1464f03deaafbbd5fdd212514cbf36b9bd4.tar.gz cpython-6c00c1464f03deaafbbd5fdd212514cbf36b9bd4.tar.bz2 |
Issue #9425: Create PyModule_GetFilenameObject() function
... to get the filename as a unicode object, instead of a byte string. Function
needed to support unencodable filenames. Deprecate PyModule_GetFilename() in
favor on the new function.
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 7b8e1b6..3a95261 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -188,8 +188,8 @@ PyModule_GetName(PyObject *m) return _PyUnicode_AsString(nameobj); } -static PyObject* -module_getfilename(PyObject *m) +PyObject* +PyModule_GetFilenameObject(PyObject *m) { PyObject *d; PyObject *fileobj; @@ -205,6 +205,7 @@ module_getfilename(PyObject *m) PyErr_SetString(PyExc_SystemError, "module filename missing"); return NULL; } + Py_INCREF(fileobj); return fileobj; } @@ -212,10 +213,13 @@ const char * PyModule_GetFilename(PyObject *m) { PyObject *fileobj; - fileobj = module_getfilename(m); + char *utf8; + fileobj = PyModule_GetFilenameObject(m); if (fileobj == NULL) return NULL; - return _PyUnicode_AsString(fileobj); + utf8 = _PyUnicode_AsString(fileobj); + Py_DECREF(fileobj); + return utf8; } PyModuleDef* @@ -346,19 +350,21 @@ static PyObject * module_repr(PyModuleObject *m) { const char *name; - PyObject *filename; + PyObject *filename, *repr; name = PyModule_GetName((PyObject *)m); if (name == NULL) { PyErr_Clear(); name = "?"; } - filename = module_getfilename((PyObject *)m); + filename = PyModule_GetFilenameObject((PyObject *)m); if (filename == NULL) { PyErr_Clear(); return PyUnicode_FromFormat("<module '%s' (built-in)>", name); } - return PyUnicode_FromFormat("<module '%s' from '%U'>", name, filename); + repr = PyUnicode_FromFormat("<module '%s' from '%U'>", name, filename); + Py_DECREF(filename); + return repr; } static int |