Skip to content

Commit

Permalink
Remove support for an alignment of zero, it's unnecessary and an alig…
Browse files Browse the repository at this point in the history
…nment of 1 suffices.
  • Loading branch information
friedkeenan committed Dec 31, 2024
1 parent 67f32f0 commit b099b76
Showing 4 changed files with 10 additions and 18 deletions.
21 changes: 8 additions & 13 deletions pak/test.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pak/types/misc.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ class EmptyType(Type):
"""

_size = 0
_alignment = 0
_alignment = 1

def __get__(self, instance, owner=None):
if instance is None:
3 changes: 0 additions & 3 deletions pak/types/type.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/test_types/test_misc.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ async def test_empty():
(None, b""),

static_size = 0,
alignment = 0,
alignment = 1,
default = None,
)

0 comments on commit b099b76

Please sign in to comment.