comparison Python/_warnings.c @ 86702:1bbedfb20932

Issue #19421: fix a check in warnings.warn() to be able to use it during Python finalization. sys.argv is set to None during Python finalization: add PyList_Check() to avoid a crash in PyList_Size().
author Victor Stinner <victor.stinner@gmail.com>
date Mon, 28 Oct 2013 18:47:22 +0100
parents df2fdd42b375
children c7326aa0b69c
comparison
equal deleted inserted replaced
86700:8962d1c442a6 86702:1bbedfb20932
532 *filename = NULL; 532 *filename = NULL;
533 if (module_str == NULL) 533 if (module_str == NULL)
534 goto handle_error; 534 goto handle_error;
535 if (strcmp(module_str, "__main__") == 0) { 535 if (strcmp(module_str, "__main__") == 0) {
536 PyObject *argv = PySys_GetObject("argv"); 536 PyObject *argv = PySys_GetObject("argv");
537 if (argv != NULL && PyList_Size(argv) > 0) { 537 /* PyList_Check() is needed because sys.argv is set to None during
538 Python finalization */
539 if (argv != NULL && PyList_Check(argv) && PyList_Size(argv) > 0) {
538 int is_true; 540 int is_true;
539 *filename = PyList_GetItem(argv, 0); 541 *filename = PyList_GetItem(argv, 0);
540 Py_INCREF(*filename); 542 Py_INCREF(*filename);
541 /* If sys.argv[0] is false, then use '__main__'. */ 543 /* If sys.argv[0] is false, then use '__main__'. */
542 is_true = PyObject_IsTrue(*filename); 544 is_true = PyObject_IsTrue(*filename);