Title: CField.size from the ctypes module does not behave as documented on bitfields
Type: behavior Stage: patch review
Components: ctypes, Documentation Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Eric Wieser, amaury.forgeotdarc, belopolsky, docs@python, mangrisano, meador.inge, shihai1991
Priority: normal Keywords: patch

Created on 2019-06-07 03:46 by Eric Wieser, last changed 2019-07-08 17:32 by shihai1991.

Pull Requests
URL Status Linked Edit
PR 14647 open shihai1991, 2019-07-08 17:04
Messages (2)
msg344895 - (view) Author: Eric Wieser (Eric Wieser) Date: 2019-06-07 03:46
This behavior is pretty surprising:

import ctypes

class Simple(ctypes.Structure):
    _fields_ = [
        ('a', ctypes.c_uint8),
        ('b', ctypes.c_uint8),

class Bitfields(ctypes.Structure):
    _fields_ = [
        ('a', ctypes.c_uint8, 8),
        ('b', ctypes.c_uint8, 8),

print(Simple.b.size)     # 1
print(Bitfields.b.size)  # 262148

The docstring for this field, from `help(type(Bitfields.b).size)`, is:

> Help on getset descriptor _ctypes.CField.size:
> size
>    size in bytes of this field

So either the behavior or the docstring needs to change.
msg344921 - (view) Author: Michele Angrisano (mangrisano) * Date: 2019-06-07 10:56
Hi Eric,

Thank you for the report.
Would you interested to propose a Pull Request for this issue?
You can read the devguide for more info:
Date User Action Args
2019-07-08 17:32:40shihai1991setnosy: + shihai1991
2019-07-08 17:04:18shihai1991setkeywords: + patch
stage: patch review
pull_requests: + pull_request14458
2019-06-07 10:56:55mangrisanosetnosy: + belopolsky, amaury.forgeotdarc, meador.inge, mangrisano
messages: + msg344921
2019-06-07 06:51:30Eric Wiesersettype: behavior
components: + ctypes
2019-06-07 03:46:36Eric Wiesercreate