{{ message }}
[2.7] bpo-10746: Fix ctypes PEP 3118 type codes for c_long, c_bool, c_int (GH-31)#3242
Merged
pitrou merged 2 commits intoSep 2, 2017
Merged
[2.7] bpo-10746: Fix ctypes PEP 3118 type codes for c_long, c_bool, c_int (GH-31)#3242pitrou merged 2 commits into
pitrou merged 2 commits into
Conversation
…_int (pythonGH-31) Ctypes currently produces wrong pep3118 type codes for several types. E.g. memoryview(ctypes.c_long()).format gives "<l" on 64-bit platforms, but it should be "<q" instead for sizeof(c_long) == 8 The problem is that the '<>' endian specification in the struct syntax also turns on the "standard size" mode, which makes type characters have a platform-independent meaning, which does not match with the codes used internally in ctypes. The struct module format syntax also does not allow specifying native-size non-native-endian items. This commit adds a converter function that maps the internal ctypes codes to appropriate struct module standard-size codes in the pep3118 format strings. The tests are modified to check for this.. (cherry picked from commit 07f1658)
Member
|
This PR failed building on AppVeyor, see: https://ci.appveyor.com/project/python/cpython/build/2.7.13+.5702#L306 |
Sorry, something went wrong.
eamanu
reviewed
Aug 30, 2017
Contributor
Author
|
Thanks for the comment. I will look at this again next week once I'm back
at a win32 machine.
30.8.2017 17.40 "Emmanuel Arias" <notifications@github.com> kirjoitti:
… ***@***.**** commented on this pull request.
------------------------------
In Modules/_ctypes/_ctypes.c
<#3242 (comment)>:
> +#elif SIZEOF_LONG == 8
+ case 'l': pep_code = 'q'; break;
+ case 'L': pep_code = 'Q'; break;
+#else
+# error SIZEOF_LONG has an unexpected value
+#endif /* SIZEOF_LONG */
+#if SIZEOF__BOOL == 1
+ case '?': pep_code = '?'; break;
+#elif SIZEOF__BOOL == 2
+ case '?': pep_code = 'H'; break;
+#elif SIZEOF__BOOL == 4
+ case '?': pep_code = 'L'; break;
+#elif SIZEOF__BOOL == 8
+ case '?': pep_code = 'Q'; break;
+#else
+# error SIZEOF__BOOL has an unexpected value
Hi @pv <https://github.com/pv>,
The problems is with the win compilation. SIZEOF__BOOL has an unexpected
value
I'm really new, but sound how if you don't define SIZEOF__BOOL variable.
Searching where is that defining, I found its defintion in PC/pyconfig.h,
but you never including that. I cannot test if that is the solution,
because I don`t have my tools here.
regard!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3242 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACI5gLOsgdiCoDOfqW9CuTamaz9aRl7ks5sdWZBgaJpZM4PHCsl>
.
|
Sorry, something went wrong.
Contributor
Author
|
Should be fixed now. In Python 2.7, SIZEOF__BOOL is defined to 1 if HAVE_C99_BOOL is undefined in cfield.c. I now duplicated that definition in ctypes.c. On Python 3.x, there are no such ifdefs for SIZEOF__BOOL in either file, as the variable seems to be always defined. |
Sorry, something went wrong.
Member
|
Thank you! Now merging. |
Sorry, something went 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
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.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.
Ctypes currently produces wrong pep3118 type codes for several types.
E.g. memoryview(ctypes.c_long()).format gives "<l" on 64-bit platforms,
but it should be "<q" instead for sizeof(c_long) == 8
The problem is that the '<>' endian specification in the struct syntax
also turns on the "standard size" mode, which makes type characters have
a platform-independent meaning, which does not match with the codes used
internally in ctypes. The struct module format syntax also does not
allow specifying native-size non-native-endian items.
This commit adds a converter function that maps the internal ctypes
codes to appropriate struct module standard-size codes in the pep3118
format strings. The tests are modified to check for this..
(cherry picked from commit 07f1658)
https://bugs.python.org/issue10746