summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-10-28 17:47:22 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-10-28 17:47:22 (GMT)
commitce5f4fba11262453f06ad431803a672be8a950dd (patch)
tree15734e899ef54c8c455c751769c28ce91f2cd154 /Python/_warnings.c
parent1df788acd40675836a0f4c1fc127007c87f7bb6c (diff)
downloadcpython-ce5f4fba11262453f06ad431803a672be8a950dd.zip
cpython-ce5f4fba11262453f06ad431803a672be8a950dd.tar.gz
cpython-ce5f4fba11262453f06ad431803a672be8a950dd.tar.bz2
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().
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index b8d4bb6..23b3f5c 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -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);