summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2008-05-03 18:24:43 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2008-05-03 18:24:43 (GMT)
commita85998af7c44c047cb4e35cfa8373330e3f45088 (patch)
tree4f8af4d5cd63bb592f4504b729916a3cf8bb9285 /Python/import.c
parent999679a23ec5731d32dbdbf04b61d4ebb4bcd476 (diff)
downloadcpython-a85998af7c44c047cb4e35cfa8373330e3f45088.zip
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.gz
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.bz2
Issue #1950: Fixed misusage of PyUnicode_AsString().
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c
index 8b11aad..5dabd9f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2131,13 +2131,15 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
if ((pkgname != NULL) && (pkgname != Py_None)) {
/* __package__ is set, so use it */
+ char *pkgname_str;
Py_ssize_t len;
+
if (!PyUnicode_Check(pkgname)) {
PyErr_SetString(PyExc_ValueError,
"__package__ set to non-string");
return NULL;
}
- len = PyUnicode_GET_SIZE(pkgname);
+ pkgname_str = PyUnicode_AsStringAndSize(pkgname, &len);
if (len == 0) {
if (level > 0) {
PyErr_SetString(PyExc_ValueError,
@@ -2151,7 +2153,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
"Package name too long");
return NULL;
}
- strcpy(buf, PyUnicode_AsString(pkgname));
+ strcpy(buf, pkgname_str);
} else {
/* __package__ not set, so figure it out and set it */
modname = PyDict_GetItem(globals, namestr);
@@ -2161,14 +2163,17 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
modpath = PyDict_GetItem(globals, pathstr);
if (modpath != NULL) {
/* __path__ is set, so modname is already the package name */
- Py_ssize_t len = PyUnicode_GET_SIZE(modname);
+ char *modname_str;
+ Py_ssize_t len;
int error;
+
+ modname_str = PyUnicode_AsStringAndSize(modname, &len);
if (len > MAXPATHLEN) {
PyErr_SetString(PyExc_ValueError,
"Module name too long");
return NULL;
}
- strcpy(buf, PyUnicode_AsString(modname));
+ strcpy(buf, modname_str);
error = PyDict_SetItem(globals, pkgstr, modname);
if (error) {
PyErr_SetString(PyExc_ValueError,