GeezerVison is showing github.com — Wrong size of c_ulong/c_ulonglong in Linux · Issue #108907 · python/cpython
Wrong size of c_ulong/c_ulonglong in Linux #108907DescriptionBug report
Bug description:
Attribute _type_ of c_ulong returns L, which is correct following the format characters documentation; however, the documentation says it has 4 bytes size, but sizeof(c_ulong) returns 8 bytes.
>>> sizeof(c_ulong)
8
>>> c_ulong._type_
'L'
Also c_ulonglong is automatically casted to c_ulong:
t5=c_ulonglong(200000000000000000000000000000000000)
>>> type(t5)
<class 'ctypes.c_ulong'>
, thus if c_ulong will have 4 bytes, will be there available a type of 8 bytes size?
CPython versions tested on:
3.8
Operating systems tested on:
Linux
Linked PRs
Activityserhiy-storchaka commented on Sep 5, 2023
The ‘Standard size’ column refers to the size of the packed value in bytes when using standard size; that is, when the format string starts with one of '<', '>', '!' or '='. When using native size, the size of the packed value is platform-dependent.
terryjreedy commented on Sep 5, 2023 _type_ is apparently an attribute of each fundamental data type but unlike value, not of the base class _SimpleCData. Hence it is undocumented in this section. I think it should be, with a mention that the 'types' are 1 char strings from struct Format Characters(I am assuming this) -- with 'native' rather than 'standard' size implied. (I have no idea whether the above has always been true or if type is an addition.)
_type_ is only mentioned in Arrays and Pointers as "Specifies the type ..." with no indication as to what such specification consists of.
Reacted by Ronald Oussoren ronaldoussoren commented on Sep 6, 2023 IMHO there is no bug here, other than the documentation issue mentioned by @terryjreedy.
c_ulong and c_ulonglong are documented as being representations of the C types unsigned long and unsigned long long. As such they'll have the size of associated with those types. 64-bit Linux systems generally use a LP64 model where unsigned long and unsigned long long are both 64-bit bit integers, and hence c_ulong and c_ulonglong are the same type. On 32-bit systems unsigned long is generally a 32-bit quantity, and hence c_ulong and c_ulonglong won't. be the same type there.
encukou commented on Mar 23, 2026 Docs are updated.
the 'types' are 1 char strings from struct Format Characters(I am assuming this) -- with 'native' rather than 'standard' size implied. (I have no idea whether the above has always been true or if type is an addition.)
I've kept these -- and array -- separate. There are some differences, but if you're reading about one individual module it's better to get the full table than “X but with Y rather than Z”.
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|