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

Skip to content

Commit ce5f4fb

Browse files
committed
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().
1 parent 1df788a commit ce5f4fb

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Python/_warnings.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,9 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
534534
goto handle_error;
535535
if (strcmp(module_str, "__main__") == 0) {
536536
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) {
538540
int is_true;
539541
*filename = PyList_GetItem(argv, 0);
540542
Py_INCREF(*filename);

0 commit comments

Comments
 (0)