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.
Based on patch by Victor Stinner.
Add private C API function _PyUnicode_AsUnicode() which is similar to
PyUnicode_AsUnicode(), but checks for null characters.
There was few cases of using literal 0 instead of NULL in the context of
pointers. While this was a legitimate C code, using NULL rather than 0 makes
the code clearer.
* init commit, with initial tests for from_param and fields __set__ and __get__, and some additions to from_buffer and from_buffer_copy
* added the rest of tests and patches. probably only a first draft.
* removed trailing spaces
* replace ctype with ctypes in error messages
* change back from ctypes instance to ctype instance
* Fixed bpo-29565: Corrected ctypes passing of large structs by value.
Added code and test to check that when a structure passed by value
is large enough to need to be passed by reference, a copy of the
original structure is passed. The callee updates the passed-in value,
and the test verifies that the caller's copy is unchanged. A similar
change was also added to the test added for bpo-20160 (that test was
passing, but the changes should guard against regressions).
* Reverted unintended whitespace changes.
Issue #28915: Replace _PyObject_CallMethodId() with
_PyObject_CallMethodIdObjArgs() in unpickle(). _PyObject_CallMethodIdObjArgs()
avoids the creation of a temporary tuple and doesn't have to parse a format
string.
Replace _PyObject_CallMethodId() with _PyObject_GetAttrId()+PyObject_Call() for
the second call since it requires to "unpack" a tuple.
Add also a check in the type of the second parameter (state): it must be a
tuple.