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

Skip to content

Commit b62a7b2

Browse files
author
Victor Stinner
committed
Fix _warnings.c: make the filename string ready
1 parent 1d4b35f commit b62a7b2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Python/_warnings.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,16 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
497497
/* Setup filename. */
498498
*filename = PyDict_GetItemString(globals, "__file__");
499499
if (*filename != NULL && PyUnicode_Check(*filename)) {
500-
Py_ssize_t len = PyUnicode_GetSize(*filename);
501-
int kind = PyUnicode_KIND(*filename);
502-
void *data = PyUnicode_DATA(*filename);
500+
Py_ssize_t len;
501+
int kind;
502+
void *data;
503+
504+
if (PyUnicode_READY(*filename))
505+
goto handle_error;
506+
507+
len = PyUnicode_GetSize(*filename);
508+
kind = PyUnicode_KIND(*filename);
509+
data = PyUnicode_DATA(*filename);
503510

504511
/* if filename.lower().endswith((".pyc", ".pyo")): */
505512
if (len >= 4 &&

0 commit comments

Comments
 (0)