-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
[2.7] bpo-10746: Fix ctypes PEP 3118 type codes for c_long, c_bool, c_int (GH-31) #3242
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)
This PR failed building on AppVeyor, see: https://ci.appveyor.com/project/python/cpython/build/2.7.13+.5702#L306 |
#elif SIZEOF__BOOL == 8 | ||
case '?': pep_code = 'Q'; break; | ||
#else | ||
# error SIZEOF__BOOL has an unexpected value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pv,
The problems is with the win compilation. SIZEOF__BOOL has an unexpected value
I'm really new, but that 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!
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>
.
|
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. |
Thank you! Now merging. |
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