Fix incorrect types passed to Py_BuildValue and PyArg_ParseTupleAndKeywords#193
Open
QuLogic wants to merge 2 commits into
Open
Fix incorrect types passed to Py_BuildValue and PyArg_ParseTupleAndKeywords#193QuLogic wants to merge 2 commits into
QuLogic wants to merge 2 commits into
Conversation
In all cases, these calls told Python it was getting ints (`i`), which are 4 bytes, but several cases passed either `Py_ssize_t` or `Py_uintptr_t`, which are 8 bytes. On little-endian machines, this will work, as the bytes align, but on big-endian machine, Python will most probably see 0, since the top bytes are more likely to be unfilled unless values are very large.
For a similar reason as `Py_BuildValue`, telling Python to use a smaller sized value than actually passed may cause strange values to end up in the result.
Author
|
Here's a downstream build with this PR applied that works on all (little- and big-endian) architectures: https://src.fedoraproject.org/rpms/python-pyahocorasick/pull-request/3 |
Author
|
There seems to be one more oddity at: pyahocorasick/src/AutomatonItemsIter.c Lines 254 to 262 in 88256f5 vs: Lines 49 to 66 in 88256f5 where if AHOCORASICK_UNICODE is not defined, it states that it is const char * to Python, but the TRIE_LETTER_TYPE is uint16_t. I'm not sure if it's the former or latter that is wrong.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Always using
iis broken, as that is 4 bytes, butPy_ssize_tandPy_uintptr_tare 8 bytes.On little endian machines, this is usually fine, since the first 4 bytes (of 4-byte or 8-byte integers) will be the same, but on big-endian machines, a 4-byte integer corresponds with the last 4 bytes of the 8-byte integer
For small numbers on big-endian machines, it is thus likely that the result will be 0. If the value is over 32 bits, then the result will be wrong on little-endian machines as well.
Fixes #142