[Python-checkins] cpython: Issue #19421: fix a check in warnings.warn() to be able to use it during Python

victor.stinner python-checkins at python.org
Mon Oct 28 18:47:46 CET 2013


http://hg.python.org/cpython/rev/1bbedfb20932
changeset:   86702:1bbedfb20932
parent:      86700:8962d1c442a6
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Oct 28 18:47:22 2013 +0100
summary:
  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().

files:
  Python/_warnings.c |  4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)


diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -534,7 +534,9 @@
                 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);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list