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

Skip to content

Commit 2f3667a

Browse files
committed
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
1 parent 8442af3 commit 2f3667a

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

Objects/moduleobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ _PyModule_Clear(m)
117117
char *s = PyString_AsString(key);
118118
if (s[0] == '_' && s[1] != '_') {
119119
if (Py_VerboseFlag > 1)
120-
fprintf(stderr, "# clear[1] %s\n", s);
120+
PySys_WriteStderr("# clear[1] %s\n", s);
121121
PyDict_SetItem(d, key, Py_None);
122122
}
123123
}
@@ -130,7 +130,7 @@ _PyModule_Clear(m)
130130
char *s = PyString_AsString(key);
131131
if (s[0] != '_' || strcmp(s, "__builtins__") != 0) {
132132
if (Py_VerboseFlag > 1)
133-
fprintf(stderr, "# clear[2] %s\n", s);
133+
PySys_WriteStderr("# clear[2] %s\n", s);
134134
PyDict_SetItem(d, key, Py_None);
135135
}
136136
}

Python/import.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ PyImport_Cleanup()
220220
if (value != NULL && PyModule_Check(value)) {
221221
dict = PyModule_GetDict(value);
222222
if (Py_VerboseFlag)
223-
fprintf(stderr, "# clear __builtin__._\n");
223+
PySys_WriteStderr("# clear __builtin__._\n");
224224
PyDict_SetItemString(dict, "_", Py_None);
225225
}
226226
value = PyDict_GetItemString(modules, "sys");
@@ -230,12 +230,12 @@ PyImport_Cleanup()
230230
dict = PyModule_GetDict(value);
231231
for (p = sys_deletes; *p != NULL; p++) {
232232
if (Py_VerboseFlag)
233-
fprintf(stderr, "# clear sys.%s\n", *p);
233+
PySys_WriteStderr("# clear sys.%s\n", *p);
234234
PyDict_SetItemString(dict, *p, Py_None);
235235
}
236236
for (p = sys_files; *p != NULL; p+=2) {
237237
if (Py_VerboseFlag)
238-
fprintf(stderr, "# restore sys.%s\n", *p);
238+
PySys_WriteStderr("# restore sys.%s\n", *p);
239239
v = PyDict_GetItemString(dict, *(p+1));
240240
if (v == NULL)
241241
v = Py_None;
@@ -247,7 +247,7 @@ PyImport_Cleanup()
247247
value = PyDict_GetItemString(modules, "__main__");
248248
if (value != NULL && PyModule_Check(value)) {
249249
if (Py_VerboseFlag)
250-
fprintf(stderr, "# cleanup __main__\n");
250+
PySys_WriteStderr("# cleanup __main__\n");
251251
_PyModule_Clear(value);
252252
PyDict_SetItemString(modules, "__main__", Py_None);
253253
}
@@ -281,7 +281,7 @@ PyImport_Cleanup()
281281
if (strcmp(name, "sys") == 0)
282282
continue;
283283
if (Py_VerboseFlag)
284-
fprintf(stderr,
284+
PySys_WriteStderr(
285285
"# cleanup[1] %s\n", name);
286286
_PyModule_Clear(value);
287287
PyDict_SetItem(modules, key, Py_None);
@@ -300,7 +300,7 @@ PyImport_Cleanup()
300300
if (strcmp(name, "sys") == 0)
301301
continue;
302302
if (Py_VerboseFlag)
303-
fprintf(stderr, "# cleanup[2] %s\n", name);
303+
PySys_WriteStderr("# cleanup[2] %s\n", name);
304304
_PyModule_Clear(value);
305305
PyDict_SetItem(modules, key, Py_None);
306306
}
@@ -310,14 +310,14 @@ PyImport_Cleanup()
310310
value = PyDict_GetItemString(modules, "sys");
311311
if (value != NULL && PyModule_Check(value)) {
312312
if (Py_VerboseFlag)
313-
fprintf(stderr, "# cleanup sys\n");
313+
PySys_WriteStderr("# cleanup sys\n");
314314
_PyModule_Clear(value);
315315
PyDict_SetItemString(modules, "sys", Py_None);
316316
}
317317
value = PyDict_GetItemString(modules, "__builtin__");
318318
if (value != NULL && PyModule_Check(value)) {
319319
if (Py_VerboseFlag)
320-
fprintf(stderr, "# cleanup __builtin__\n");
320+
PySys_WriteStderr("# cleanup __builtin__\n");
321321
_PyModule_Clear(value);
322322
PyDict_SetItemString(modules, "__builtin__", Py_None);
323323
}
@@ -399,7 +399,7 @@ _PyImport_FindExtension(name, filename)
399399
return NULL;
400400
Py_DECREF(result);
401401
if (Py_VerboseFlag)
402-
fprintf(stderr, "import %s # previously loaded (%s)\n",
402+
PySys_WriteStderr("import %s # previously loaded (%s)\n",
403403
name, filename);
404404
return mod;
405405
}
@@ -542,19 +542,19 @@ check_compiled_module(pathname, mtime, cpathname)
542542
magic = PyMarshal_ReadLongFromFile(fp);
543543
if (magic != MAGIC) {
544544
if (Py_VerboseFlag)
545-
fprintf(stderr, "# %s has bad magic\n", cpathname);
545+
PySys_WriteStderr("# %s has bad magic\n", cpathname);
546546
fclose(fp);
547547
return NULL;
548548
}
549549
pyc_mtime = PyMarshal_ReadLongFromFile(fp);
550550
if (pyc_mtime != mtime) {
551551
if (Py_VerboseFlag)
552-
fprintf(stderr, "# %s has bad mtime\n", cpathname);
552+
PySys_WriteStderr("# %s has bad mtime\n", cpathname);
553553
fclose(fp);
554554
return NULL;
555555
}
556556
if (Py_VerboseFlag)
557-
fprintf(stderr, "# %s matches %s\n", cpathname, pathname);
557+
PySys_WriteStderr("# %s matches %s\n", cpathname, pathname);
558558
return fp;
559559
}
560560

@@ -605,7 +605,7 @@ load_compiled_module(name, cpathname, fp)
605605
if (co == NULL)
606606
return NULL;
607607
if (Py_VerboseFlag)
608-
fprintf(stderr, "import %s # precompiled from %s\n",
608+
PySys_WriteStderr("import %s # precompiled from %s\n",
609609
name, cpathname);
610610
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname);
611611
Py_DECREF(co);
@@ -649,7 +649,7 @@ write_compiled_module(co, cpathname, mtime)
649649
fp = fopen(cpathname, "wb");
650650
if (fp == NULL) {
651651
if (Py_VerboseFlag)
652-
fprintf(stderr,
652+
PySys_WriteStderr(
653653
"# can't create %s\n", cpathname);
654654
return;
655655
}
@@ -659,7 +659,7 @@ write_compiled_module(co, cpathname, mtime)
659659
PyMarshal_WriteObjectToFile((PyObject *)co, fp);
660660
if (ferror(fp)) {
661661
if (Py_VerboseFlag)
662-
fprintf(stderr, "# can't write %s\n", cpathname);
662+
PySys_WriteStderr("# can't write %s\n", cpathname);
663663
/* Don't keep partial file */
664664
fclose(fp);
665665
(void) unlink(cpathname);
@@ -671,7 +671,7 @@ write_compiled_module(co, cpathname, mtime)
671671
fflush(fp);
672672
fclose(fp);
673673
if (Py_VerboseFlag)
674-
fprintf(stderr, "# wrote %s\n", cpathname);
674+
PySys_WriteStderr("# wrote %s\n", cpathname);
675675
#ifdef macintosh
676676
setfiletype(cpathname, 'Pyth', 'PYC ');
677677
#endif
@@ -704,7 +704,7 @@ load_source_module(name, pathname, fp)
704704
if (co == NULL)
705705
return NULL;
706706
if (Py_VerboseFlag)
707-
fprintf(stderr, "import %s # precompiled from %s\n",
707+
PySys_WriteStderr("import %s # precompiled from %s\n",
708708
name, cpathname);
709709
pathname = cpathname;
710710
}
@@ -713,7 +713,7 @@ load_source_module(name, pathname, fp)
713713
if (co == NULL)
714714
return NULL;
715715
if (Py_VerboseFlag)
716-
fprintf(stderr, "import %s # from %s\n",
716+
PySys_WriteStderr("import %s # from %s\n",
717717
name, pathname);
718718
write_compiled_module(co, cpathname, mtime);
719719
}
@@ -748,7 +748,7 @@ load_package(name, pathname)
748748
if (m == NULL)
749749
return NULL;
750750
if (Py_VerboseFlag)
751-
fprintf(stderr, "import %s # directory %s\n",
751+
PySys_WriteStderr("import %s # directory %s\n",
752752
name, pathname);
753753
d = PyModule_GetDict(m);
754754
file = PyString_FromString(pathname);
@@ -962,7 +962,7 @@ find_module(realname, path, buf, buflen, p_fp)
962962
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
963963
strcpy(buf+len, fdp->suffix);
964964
if (Py_VerboseFlag > 1)
965-
fprintf(stderr, "# trying %s\n", buf);
965+
PySys_WriteStderr("# trying %s\n", buf);
966966
fp = fopen(buf, fdp->mode);
967967
if (fp != NULL)
968968
break;
@@ -1286,7 +1286,7 @@ init_builtin(name)
12861286
return -1;
12871287
}
12881288
if (Py_VerboseFlag)
1289-
fprintf(stderr, "import %s # builtin\n", name);
1289+
PySys_WriteStderr("import %s # builtin\n", name);
12901290
(*p->initfunc)();
12911291
if (PyErr_Occurred())
12921292
return -1;
@@ -1357,7 +1357,7 @@ PyImport_ImportFrozenModule(name)
13571357
if (ispackage)
13581358
size = -size;
13591359
if (Py_VerboseFlag)
1360-
fprintf(stderr, "import %s # frozen%s\n",
1360+
PySys_WriteStderr("import %s # frozen%s\n",
13611361
name, ispackage ? " package" : "");
13621362
co = PyMarshal_ReadObjectFromString((char *)p->code, size);
13631363
if (co == NULL)

Python/importdl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
809809
PyErr_Clear(); /* Not important enough to report */
810810
Py_XDECREF(s);
811811
if (Py_VerboseFlag)
812-
fprintf(stderr,
812+
PySys_WriteStderr(
813813
"import %s # dynamically loaded from %s\n",
814814
name, pathname);
815815
Py_INCREF(m);

0 commit comments

Comments
 (0)