Skip to content

Commit

Permalink
Prevent accidental setting of non-existent ctype fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
agoessling committed Aug 15, 2023
1 parent 27a73ea commit 2db94de
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/py_stuff_sack.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __eq__(self, other):


class _Message(ctypes.Structure):
__slots__ = []

@classmethod
def get_buffer(cls):
Expand Down Expand Up @@ -197,7 +198,7 @@ def get_globals(library, message_spec):

if isinstance(t, stuff_sack.Bitfield):
fields = [(f.name, BITFIELD_MAP[t.bytes], f.bits) for f in t.fields]
global_vars[t.name] = type(t.name, (ctypes.Structure,), {'_fields_': fields})
global_vars[t.name] = type(t.name, (ctypes.Structure,), {'__slots__': [], '_fields_': fields})
ctypes_map[t.name] = global_vars[t.name]

if isinstance(t, stuff_sack.Struct):
Expand All @@ -210,7 +211,7 @@ def get_globals(library, message_spec):

fields.append((field.name, field_type))

attrs = {'_fields_': fields}
attrs = {'__slots__': [], '_fields_': fields}

base = ctypes.Structure
if isinstance(t, stuff_sack.Message):
Expand Down

0 comments on commit 2db94de

Please sign in to comment.