@@ -255,13 +255,13 @@ enum zi_module_info {
255255
256256/* Return some information about a module. */
257257static enum zi_module_info
258- get_module_info (ZipImporter * self , char * fullname )
258+ get_module_info (ZipImporter * self , PyObject * fullname )
259259{
260260 char * subname , path [MAXPATHLEN + 1 ];
261261 int len ;
262262 struct st_zip_searchorder * zso ;
263263
264- subname = get_subname (fullname );
264+ subname = get_subname (PyBytes_AS_STRING ( fullname ) );
265265
266266 len = make_filename (self -> prefix , subname , path , sizeof (path ));
267267 if (len < 0 )
@@ -286,14 +286,15 @@ zipimporter_find_module(PyObject *obj, PyObject *args)
286286{
287287 ZipImporter * self = (ZipImporter * )obj ;
288288 PyObject * path = NULL ;
289- char * fullname ;
289+ PyObject * fullname ;
290290 enum zi_module_info mi ;
291291
292- if (!PyArg_ParseTuple (args , "s |O:zipimporter.find_module" ,
293- & fullname , & path ))
292+ if (!PyArg_ParseTuple (args , "O& |O:zipimporter.find_module" ,
293+ PyUnicode_FSConverter , & fullname , & path ))
294294 return NULL ;
295295
296296 mi = get_module_info (self , fullname );
297+ Py_DECREF (fullname );
297298 if (mi == MI_ERROR )
298299 return NULL ;
299300 if (mi == MI_NOT_FOUND ) {
@@ -403,22 +404,27 @@ static PyObject *
403404zipimporter_is_package (PyObject * obj , PyObject * args )
404405{
405406 ZipImporter * self = (ZipImporter * )obj ;
406- char * fullname ;
407+ PyObject * fullname ;
407408 enum zi_module_info mi ;
408409
409- if (!PyArg_ParseTuple (args , "s :zipimporter.is_package" ,
410- & fullname ))
410+ if (!PyArg_ParseTuple (args , "O& :zipimporter.is_package" ,
411+ PyUnicode_FSConverter , & fullname ))
411412 return NULL ;
412413
413414 mi = get_module_info (self , fullname );
414415 if (mi == MI_ERROR )
415- return NULL ;
416+ goto error ;
416417 if (mi == MI_NOT_FOUND ) {
417- PyErr_Format (ZipImportError , "can't find module '%.200s '" ,
418+ PyErr_Format (ZipImportError , "can't find module '%.200U '" ,
418419 fullname );
419- return NULL ;
420+ goto error ;
420421 }
422+ Py_DECREF (fullname );
421423 return PyBool_FromLong (mi == MI_PACKAGE );
424+
425+ error :
426+ Py_DECREF (fullname );
427+ return NULL ;
422428}
423429
424430static PyObject *
@@ -490,24 +496,30 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
490496{
491497 ZipImporter * self = (ZipImporter * )obj ;
492498 PyObject * toc_entry ;
493- char * fullname , * subname , path [MAXPATHLEN + 1 ];
499+ PyObject * fullname ;
500+ char * subname , path [MAXPATHLEN + 1 ];
494501 int len ;
495502 enum zi_module_info mi ;
496503
497- if (!PyArg_ParseTuple (args , "s:zipimporter.get_source" , & fullname ))
504+ if (!PyArg_ParseTuple (args , "O&:zipimporter.get_source" ,
505+ PyUnicode_FSConverter , & fullname ))
498506 return NULL ;
499507
500508 mi = get_module_info (self , fullname );
501- if (mi == MI_ERROR )
509+ if (mi == MI_ERROR ) {
510+ Py_DECREF (fullname );
502511 return NULL ;
512+ }
503513 if (mi == MI_NOT_FOUND ) {
504- PyErr_Format (ZipImportError , "can't find module '%.200s '" ,
514+ PyErr_Format (ZipImportError , "can't find module '%.200U '" ,
505515 fullname );
516+ Py_DECREF (fullname );
506517 return NULL ;
507518 }
508- subname = get_subname (fullname );
519+ subname = get_subname (PyBytes_AS_STRING ( fullname ) );
509520
510521 len = make_filename (self -> prefix , subname , path , sizeof (path ));
522+ Py_DECREF (fullname );
511523 if (len < 0 )
512524 return NULL ;
513525
0 commit comments