GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Add ability to force alignment of ctypes.Structure · Issue #112433 · python/cpython Closed Labels DescriptionFeature or enhancementProposal:When creating a I propose we add an An example of such a struct and it's use is as follows: import ctypes class IDString(ctypes.Structure): _align_ = 0x10 _fields_ = [ ("string", ctypes.c_char * 0x10), ] class main(ctypes.Structure): _fields_ = [ ("first", ctypes.c_uint32), ("second", ctypes.c_ubyte), ("string", IDString), ] data = bytearray( b"\x07\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" b"\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x21\x00\x00\x00\x00" ) m = main.from_buffer(data) print(f"first: {m.first}") # first: 7 print(f"second: {m.second}") # second: 1 print(f"string: {m.string.string}") # string: b'hello world!' Without the I have already made a (preliminary) implementation of this here. Because the attribute is optional, I believe there are no potential backward compatibility issues as the default alignment will simply be what it was before (ie. 1). Has this already been discussed elsewhere?I have already discussed this feature proposal on Discourse Links to previous discussion of this feature:https://discuss.python.org/t/add-ability-to-force-alignment-of-ctypes-structure/39109 Linked PRsActivity
MetadataMetadataAssigneesLabelsProjects
MilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |