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
Fix wide character conversion bugs #75
Conversation
Do you have an example to trigger the bug that you are claiming you correct? |
As I noted, the pyml test "run file with filename" segfaults with the current code. This can be replicated by creating a file named test.py with these contents:
Then build pymltop and do this:
|
In utop, this works fine:
|
I can't explain why it works for you in utop, but the code is incorrect. The specification for Also, to verify that |
Thank you very much for the fix, and all your explanations. I am very sorry for the delay: this was a very busy month! Merged. |
This pull-request publishes a new release for pyml (2022-03-22): - New function `Py.Import.exec_code_module_from_string` (suggested by Francois Berenger, thierry-martinez/pyml#78) - New function `Py.Module.compile` provides a better API than `Py.compile`. - `Py.Object.t` can now be serialized (with Marshal or output_value), using Python pickle module - Cross-compiling friendly architecture detection (suggested by @EduardoRFS, https://discuss.ocaml.org/t/a-zoo-of-values-for-system/8525/20) - Detect macro `unix` instead of `__linux__`, to handle *BSD OSes (reported by Chris Pinnock, thierry-martinez/pyml#74) - Fix bug in Windows - Null checks for many functions raising OCaml exceptions, instead of segmentation fault (initial implementation by Laurent Mazare, thierry-martinez/pyml#72) - Fix wide character conversion bugs leading to segmentation fault in Py_wfopen (fixed by Jerry James, thierry-martinez/pyml#75) - `Gc.full_major ()` before unloading `libpython` in `Py.finalize`, to prevent segfaulting on finalizing dangling references to Python values after the library had been unloaded (reported by Denis Efremov on coccinelle mailing list) - Fix segmentation fault when `~debug_build:true` was passed to `Py.initialize` (reported by Stéphane Glondu, thierry-martinez/pyml#79)
I tried to run the tests on an x86_64 Fedora 35 box. The "run file with filename" test segfaulted, because the attempt to open the test file for reading failed, returning a NULL, and the NULL was then passed into the python library as a FILE *. The attempt to open for reading failed because of 2 bugs. This commit fixes both.
First, the last argument to mbstowcs is not big enough. It has to cover the null terminator. Failure to make it big enough led to garbage bytes in the last position, instead of the null terminator. As the mbstowcs man page says:
Second,
_Py_wfopen
wants the mode to be a wide string as well as the filename. I checked old Python versions, and this is the case as far back as Python 3.2, when_Py_wfopen
was introduced.