Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Untangle ctypes bitfield size and expose field information #128715

Open
Labels
extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytopic-ctypestype-featureA feature request or enhancement
@encukou

Description

@encukou

Feature or enhancement

Currently, the internal representation of bitfields inctypes is a bit-packed number containing the size and offset. This is rather cumbersome to deal with. (As far as I can tell, the reason is that getters/setters take a single argument. But, these are internal so the signature can be changed.)

My plan is to break the CField size/offset information out into more wordy but explicit fields:

  • byte_size &byte_offset, which describe the byte-aligned field within a struct. (This has the same size as the underlying type, and must be fully contained in the struct & readable/writable.)
  • bit_size &bit_offset, which identify the bits within that chunk

Also, I intend to add corresponding attributes an the Python level, and expose_CField publicly asctypes.CField, mainly for typing purposes. At this point I don't plan to make the type instantiable.

Something like:

>>>classColor(Structure):...     _fields_= (...         ('red', c_uint8),...         ('green', c_uint8),...         ('blue', c_uint8),...         ('intense', c_bool,1),...         ('blinking', c_bool,1),...    )...>>> Color.red<ctypes.CField 'red' type=c_ubyte, ofs=0, size=1>>>> Color.green.type<class 'ctypes.c_ubyte'>>>> Color.blue.byte_offset2>>> Color.intense<ctypes.CField 'intense' type=c_bool, ofs=3, bit_size=1, bit_offset=0>>>> Color.blinking.bit_offset1

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytopic-ctypestype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp