From b099b760d29aa32aa363827e4620d75b8b630f19 Mon Sep 17 00:00:00 2001 From: friedkeenan Date: Tue, 31 Dec 2024 05:31:16 -0600 Subject: [PATCH] Remove support for an alignment of zero, it's unnecessary and an alignment of 1 suffices. --- pak/test.py | 21 ++++++++------------- pak/types/misc.py | 2 +- pak/types/type.py | 3 --- tests/test_types/test_misc.py | 2 +- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/pak/test.py b/pak/test.py index cd14890..1bf506a 100644 --- a/pak/test.py +++ b/pak/test.py @@ -49,19 +49,14 @@ def _common_type_behavior(type_cls, *, static_size, alignment, default, ctx): # We must have a static size if we are aligned. assert static_size is not None - # The alignment cannot be negative. - assert alignment >= 0 - - if alignment == 0: - # We must be the equivalent of 'EmptyType' - # if we have an alignment of '0'. - assert static_size == 0 - else: - # Check that the alignment is a power of two. - assert (alignment & (alignment - 1)) == 0 - - # Check that the static size is a multiple of the alignment. - assert static_size % alignment == 0 + # The alignment must be positive. + assert alignment > 0 + + # The alignment must be a power of two. + assert (alignment & (alignment - 1)) == 0 + + # The static size must be a multiple of the alignment. + assert static_size % alignment == 0 if default is NO_DEFAULT: import pytest diff --git a/pak/types/misc.py b/pak/types/misc.py index 4e05eec..67bbad8 100644 --- a/pak/types/misc.py +++ b/pak/types/misc.py @@ -24,7 +24,7 @@ class EmptyType(Type): """ _size = 0 - _alignment = 0 + _alignment = 1 def __get__(self, instance, owner=None): if instance is None: diff --git a/pak/types/type.py b/pak/types/type.py index 853c675..d52bca9 100644 --- a/pak/types/type.py +++ b/pak/types/type.py @@ -530,9 +530,6 @@ def _alignment(cls, *, ctx): @staticmethod def _alignment_padding_at_offset(offset, alignment): - if alignment <= 0: - return 0 - return -offset & (alignment - 1) @staticmethod diff --git a/tests/test_types/test_misc.py b/tests/test_types/test_misc.py index bc54190..372a6b5 100644 --- a/tests/test_types/test_misc.py +++ b/tests/test_types/test_misc.py @@ -13,7 +13,7 @@ async def test_empty(): (None, b""), static_size = 0, - alignment = 0, + alignment = 1, default = None, )