Skip to content

Commit

Permalink
Use __align__ instead of align in StructureMetaType.__init__ (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miauwkeru authored May 31, 2024
1 parent 8b14f78 commit a495db9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dissect/cstruct/types/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StructureMetaType(MetaType):

def __new__(metacls, name: str, bases: tuple[type, ...], classdict: dict[str, Any]) -> MetaType:
if (fields := classdict.pop("fields", None)) is not None:
metacls._update_fields(metacls, fields, align=classdict.get("align", False), classdict=classdict)
metacls._update_fields(metacls, fields, align=classdict.get("__align__", False), classdict=classdict)

return super().__new__(metacls, name, bases, classdict)

Expand Down
10 changes: 9 additions & 1 deletion tests/test_types_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dissect.cstruct.exceptions import ParserError
from dissect.cstruct.types.base import Array, BaseType
from dissect.cstruct.types.pointer import Pointer
from dissect.cstruct.types.structure import Field, Structure
from dissect.cstruct.types.structure import Field, Structure, StructureMetaType

from .utils import verify_compiled

Expand Down Expand Up @@ -529,3 +529,11 @@ def test_structure_definition_self(cs: cstruct) -> None:

assert issubclass(cs.test.fields["b"].type, Pointer)
assert cs.test.fields["b"].type.type is cs.test


def test_align_struct_in_struct(cs: cstruct) -> None:
with patch.object(StructureMetaType, "_update_fields") as update_fields:
cs._make_struct("test", [Field("a", cs.uint64)], align=True)

_, kwargs = update_fields.call_args
assert kwargs["align"]

0 comments on commit a495db9

Please sign in to comment.