@@ -2131,13 +2131,15 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
21312131
21322132 if ((pkgname != NULL ) && (pkgname != Py_None )) {
21332133 /* __package__ is set, so use it */
2134+ char * pkgname_str ;
21342135 Py_ssize_t len ;
2136+
21352137 if (!PyUnicode_Check (pkgname )) {
21362138 PyErr_SetString (PyExc_ValueError ,
21372139 "__package__ set to non-string" );
21382140 return NULL ;
21392141 }
2140- len = PyUnicode_GET_SIZE (pkgname );
2142+ pkgname_str = PyUnicode_AsStringAndSize (pkgname , & len );
21412143 if (len == 0 ) {
21422144 if (level > 0 ) {
21432145 PyErr_SetString (PyExc_ValueError ,
@@ -2151,7 +2153,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
21512153 "Package name too long" );
21522154 return NULL ;
21532155 }
2154- strcpy (buf , PyUnicode_AsString ( pkgname ) );
2156+ strcpy (buf , pkgname_str );
21552157 } else {
21562158 /* __package__ not set, so figure it out and set it */
21572159 modname = PyDict_GetItem (globals , namestr );
@@ -2161,14 +2163,17 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
21612163 modpath = PyDict_GetItem (globals , pathstr );
21622164 if (modpath != NULL ) {
21632165 /* __path__ is set, so modname is already the package name */
2164- Py_ssize_t len = PyUnicode_GET_SIZE (modname );
2166+ char * modname_str ;
2167+ Py_ssize_t len ;
21652168 int error ;
2169+
2170+ modname_str = PyUnicode_AsStringAndSize (modname , & len );
21662171 if (len > MAXPATHLEN ) {
21672172 PyErr_SetString (PyExc_ValueError ,
21682173 "Module name too long" );
21692174 return NULL ;
21702175 }
2171- strcpy (buf , PyUnicode_AsString ( modname ) );
2176+ strcpy (buf , modname_str );
21722177 error = PyDict_SetItem (globals , pkgstr , modname );
21732178 if (error ) {
21742179 PyErr_SetString (PyExc_ValueError ,
0 commit comments