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

Skip to content

Commit 2a94f4c

Browse files
author
Victor Stinner
committed
get_code_from_data() uses the filesystem encoding to encode the module path,
instead of utf-8.
1 parent d36c821 commit 2a94f4c

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

Modules/zipimport.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,24 +1137,23 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
11371137
time_t mtime, PyObject *toc_entry)
11381138
{
11391139
PyObject *data, *code;
1140-
char *modpath;
1140+
PyObject *modpath;
11411141

11421142
data = get_data(self->archive, toc_entry);
11431143
if (data == NULL)
11441144
return NULL;
11451145

1146-
modpath = _PyUnicode_AsString(PyTuple_GetItem(toc_entry, 0));
1146+
modpath = PyUnicode_EncodeFSDefault(PyTuple_GetItem(toc_entry, 0));
11471147
if (modpath == NULL) {
11481148
Py_DECREF(data);
11491149
return NULL;
11501150
}
11511151

1152-
if (isbytecode) {
1153-
code = unmarshal_code(modpath, data, mtime);
1154-
}
1155-
else {
1156-
code = compile_source(modpath, data);
1157-
}
1152+
if (isbytecode)
1153+
code = unmarshal_code(PyBytes_AS_STRING(modpath), data, mtime);
1154+
else
1155+
code = compile_source(PyBytes_AS_STRING(modpath), data);
1156+
Py_DECREF(modpath);
11581157
Py_DECREF(data);
11591158
return code;
11601159
}

0 commit comments

Comments
 (0)