Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9464d61

Browse files
author
Victor Stinner
committed
Issue #3080: PyImport_Cleanup() uses Unicode
Replace strcmp() by PyUnicode_CompareWithASCIIString()
1 parent f6b563a commit 9464d61

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

Python/import.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ void
418418
PyImport_Cleanup(void)
419419
{
420420
Py_ssize_t pos, ndone;
421-
char *name;
422421
PyObject *key, *value, *dict;
423422
PyInterpreterState *interp = PyThreadState_GET()->interp;
424423
PyObject *modules = interp->modules;
@@ -491,14 +490,13 @@ PyImport_Cleanup(void)
491490
if (value->ob_refcnt != 1)
492491
continue;
493492
if (PyUnicode_Check(key) && PyModule_Check(value)) {
494-
name = _PyUnicode_AsString(key);
495-
if (strcmp(name, "builtins") == 0)
493+
if (PyUnicode_CompareWithASCIIString(key, "builtins") == 0)
496494
continue;
497-
if (strcmp(name, "sys") == 0)
495+
if (PyUnicode_CompareWithASCIIString(key, "sys") == 0)
498496
continue;
499497
if (Py_VerboseFlag)
500-
PySys_WriteStderr(
501-
"# cleanup[1] %s\n", name);
498+
PySys_FormatStderr(
499+
"# cleanup[1] %U\n", key);
502500
_PyModule_Clear(value);
503501
PyDict_SetItem(modules, key, Py_None);
504502
ndone++;
@@ -510,13 +508,12 @@ PyImport_Cleanup(void)
510508
pos = 0;
511509
while (PyDict_Next(modules, &pos, &key, &value)) {
512510
if (PyUnicode_Check(key) && PyModule_Check(value)) {
513-
name = _PyUnicode_AsString(key);
514-
if (strcmp(name, "builtins") == 0)
511+
if (PyUnicode_CompareWithASCIIString(key, "builtins") == 0)
515512
continue;
516-
if (strcmp(name, "sys") == 0)
513+
if (PyUnicode_CompareWithASCIIString(key, "sys") == 0)
517514
continue;
518515
if (Py_VerboseFlag)
519-
PySys_WriteStderr("# cleanup[2] %s\n", name);
516+
PySys_FormatStderr("# cleanup[2] %U\n", key);
520517
_PyModule_Clear(value);
521518
PyDict_SetItem(modules, key, Py_None);
522519
}

0 commit comments

Comments
 (0)