diff options
author | 2022-01-18 11:38:39 -0800 | |
---|---|---|
committer | 2022-01-18 11:38:39 -0800 | |
commit | d3e17e7f7402ddc41272784cd5dd202eb6f7e4cd (patch) | |
tree | fc1c8bb83db842cbe7ad575a1b4c39dd4d163a5c /Source/Utils/WarpXUtil.cpp | |
parent | 988cb01e64eb5677e3ac1f4c0d70dcf3c4b2ea3b (diff) | |
download | WarpX-d3e17e7f7402ddc41272784cd5dd202eb6f7e4cd.tar.gz WarpX-d3e17e7f7402ddc41272784cd5dd202eb6f7e4cd.tar.zst WarpX-d3e17e7f7402ddc41272784cd5dd202eb6f7e4cd.zip |
Python: Fix UB in Inputs Passing (#2726)
Trying to fix the macOS PyPy 3.7 error seen in https://github.com/conda-forge/warpx-feedstock/issues/37
Testing in https://github.com/conda-forge/warpx-feedstock/pull/38
After googling for a while, the original implementation was likely based on https://code.activestate.com/lists/python-list/704158, which contains bugs.
1) Bug: `create_string_buffer`
Allocating new, null-terminated char arrays with `ctypes.create_string_buffer` does lead to scrambled arrays in pypy3.7.
As far as I can see, this [should have also worked](https://docs.python.org/3/library/ctypes.html), but maybe there is a bug in the upstream implementation or the original code created some kind of use-after-free on a temporary while the new implementation just shares the existing byte address.
This leads to errors such as the ones here:
https://github.com/conda-forge/warpx-feedstock/pull/38#issuecomment-1010160519
The call `argvC[i] = ctypes.c_char_p(enc_arg)` is equivalent in creating a `NULL`-terminated char array.
2) Bug: Last Argv Argument
The last argument in the array of char arrays `argv` in ANSII C needs to be a plain `NULL` ptr.
Before this PR, this has been allocated but never initialized, leading to undefined behavior (read as: crashes).
Reference: https://stackoverflow.com/a/39096006/2719194
3) Cleanup: there is a pre-defined `ctypes.c_char_p` we can use for pointer of char.
Diffstat (limited to 'Source/Utils/WarpXUtil.cpp')
0 files changed, 0 insertions, 0 deletions