]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19421: fix a check in warnings.warn() to be able to use it during Python
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 28 Oct 2013 17:47:22 +0000 (18:47 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 28 Oct 2013 17:47:22 +0000 (18:47 +0100)
finalization.

sys.argv is set to None during Python finalization: add PyList_Check() to avoid
a crash in PyList_Size().

Python/_warnings.c

index b8d4bb61def4dc0db2463ef568ead0e29ab259a4..23b3f5c02d3f0dbed319850b1796a7a3adb6bda5 100644 (file)
@@ -534,7 +534,9 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
                 goto handle_error;
         if (strcmp(module_str, "__main__") == 0) {
             PyObject *argv = PySys_GetObject("argv");
-            if (argv != NULL && PyList_Size(argv) > 0) {
+            /* PyList_Check() is needed because sys.argv is set to None during
+               Python finalization */
+            if (argv != NULL && PyList_Check(argv) && PyList_Size(argv) > 0) {
                 int is_true;
                 *filename = PyList_GetItem(argv, 0);
                 Py_INCREF(*filename);