You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In unicode path Python 3.0.1 crashes when importing compiled module.
This does not happen on Python 3.0, new in 3.0.1.
Detailed Situation:
OS: win2000
current pathname contains Japanese characters.
./a.py contains only a statement "import b".
./b.py is empty.
> python a.py
(nothing is happen but b.pyc is created)
> python a.py
Traceback (most recent call last):
File "a.py", line 1, in <module>import b
UnicodeDecodeError: 'utf8' codec can't decode byte 0x82 in position 3:
unexpected code byte
Gasp. Sorry for the bug.
Should PyUnicode_CompareWithASCIIString() be replaced with something
else as well?
ocean-city commented on Feb 15, 2009
ocean-citymannequin
Mannequin
More actions
I'm not sure. Even my patch might not be correct anyway.
On my VC6 Debugger,
update_compiled_module(PyCodeObject *co, char *pathname)
pathname is surely mbcs.
But its caller load_source_module is calling
if (fstat(fileno(fp), &st) !=0) {
PyErr_Format(PyExc_RuntimeError,
"unable to get file status from '%s'",
pathname);
returnNULL;
}
I've looked into PyErr_Format code, it seems %s assumes utf-8. Anway,
it's difficult to know char* is utf-8 or filesystem encoding. :-(
ocean-city commented on Feb 15, 2009
ocean-citymannequin
Mannequin
More actions
I tracked down, and I found this mbcs path is set in Python/import.c(1394)
find_module.
if (PyUnicode_Check(v)) {
v=PyUnicode_AsEncodedString(v,
Py_FileSystemDefaultEncoding, NULL);
if (v==NULL)
returnNULL;
}
And this was introduced in r64126 to fix segfault mentioned in bpo-1342. I'm not understanding why segfault happened but, I feel this
issue is the part of big problem. (bpo-3080)
ocean-city commented on Feb 15, 2009
ocean-citymannequin
Mannequin
More actions
Should PyUnicode_CompareWithASCIIString() be replaced with something
else as well?
I hope revised patch will fix this too. There seems to be no function to
compare unicode object and file system encoded string, so I moved
unicode creation before comparation. This might increase overhead a bit.
bpo-3080 is big issue, so this is minimal solution for this issue. I
confirmed test_import.py passed.
Activity
miwa commentedon Feb 15, 2009
In unicode path Python 3.0.1 crashes when importing compiled module.
This does not happen on Python 3.0, new in 3.0.1.
ocean-city commentedon Feb 15, 2009
Quick observation. This bug was introduces in r68363.
pathname is mbcs on windows, but PyUnicode_FromString assumes it as UTF8.
ocean-city commentedon Feb 15, 2009
Here is a patch.
pitrou commentedon Feb 15, 2009
Gasp. Sorry for the bug.
Should PyUnicode_CompareWithASCIIString() be replaced with something
else as well?
ocean-city commentedon Feb 15, 2009
I'm not sure. Even my patch might not be correct anyway.
On my VC6 Debugger,
update_compiled_module(PyCodeObject *co, char *pathname)
pathname is surely mbcs.
But its caller load_source_module is calling
I've looked into PyErr_Format code, it seems %s assumes utf-8. Anway,
it's difficult to know char* is utf-8 or filesystem encoding. :-(
ocean-city commentedon Feb 15, 2009
I tracked down, and I found this mbcs path is set in Python/import.c(1394)
find_module.
And this was introduced in r64126 to fix segfault mentioned in
bpo-1342. I'm not understanding why segfault happened but, I feel this
issue is the part of big problem. (bpo-3080)
ocean-city commentedon Feb 15, 2009
I hope revised patch will fix this too. There seems to be no function to
compare unicode object and file system encoded string, so I moved
unicode creation before comparation. This might increase overhead a bit.
bpo-3080 is big issue, so this is minimal solution for this issue. I
confirmed test_import.py passed.
pitrou commentedon Mar 3, 2009
I cannot say anything except that the patch looks ok. If it doesn't make
anything worse and solves the present problem, I guess you can commit it.
ocean-city commentedon Mar 4, 2009
Thanks, fixed in r70157(py3k) and r70158(release30-maint)