-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
PyUnicode_EncodeFSDefault win32 inconsistancy. #60063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There is an inconsistency in PyUnicode_EncodeFSDefault(), on Linux its argument is checked to be unicode, and NULL is returned when its not. On windows however, this throws an assertion. The problem with this is, in some CAPI code you may pass an argument and check for NULL as an error case, and allow the python API's exception to be exposed to the script author. The problem here is a linux developer can use PyUnicode_EncodeFSDefault() this way, but not a windows developer. A simplified use case below of a case where PyUnicode_EncodeFSDefault would fail. Attached a fix so windows and posix systems behave the same. --- const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
{
if (PyBytes_Check(py_str)) {
return PyBytes_AS_STRING(py_str);
}
else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
return PyBytes_AS_STRING(*coerce);
} Also: heres a list to the bug report in blenders tracker, where the bug was found. https://projects.blender.org/tracker/index.php?func=detail&aid=31856&group_id=9&atid=498 |
Sounds reasonable to me. |
The code has changed considerable since you have created the patch. Is this still an issue for Python 3.3? |
Yes. |
msg192795 says this is still an issue so I'm not sure why it's been set to languishing as it's only 18 months old. |
It's not really a bug, Python behaves badly when you pass invalid parameters. Campbell was asked to update his patch but he didn't 2 years later. So I just close the issue. Reopen a new issue with an updated patch if you want a nice exception message instead of a patch. Or just fix your application to use Python C API correctly. |
Updated the patch for '93049:d9a3d23cf8f0' Note, the link for the original bug report has changed: See https://developer.blender.org/T31856 |
New changeset e124aab5d9a0 by Victor Stinner in branch 'default': |
I applied fix_unicode_v2.diff to Python 3.5. For older Python versions, it's easy to workaround this issue: ensure explicitly that your object is a Unicode object using PyUnicode_Check(). You may write your function to call PyUnicode_EncodeFSDefault() with a PyUnicode_Check() check. I prefer to not touch the stable 3.4 branch. |
this issue occureed when i run gns3-1.4.5 in python3.5.1 |
shanzhengcheng: Please don't update closed issues. gns3-1.4.5 is not part of the Python standard library. You'll get better support by using the gns3 support channels. If you still think that this is a bug in Python, please file a new issue by using the form at http://bugs.python.org/issue?@template=item (it would be great if you provide a reproducer without using gns3) Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: