From 9583a1f9a8cdd210daef7aa101cf344d246b6d72 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sun, 4 Oct 2026 17:32:52 +0000 Subject: [PATCH] Fix cdef size_t size on Win64 (LLP64), require 64-bit builds The generated cdef typedef'd size_t as unsigned long: 8 bytes on LP64 but only 4 on 64-bit Windows, where C's size_t is 8. cffi's import-time struct layout verification then failed (aegis_raf_scratch.len: cdef says 4, C compiler says 8). cffi pre-defines size_t/uint8_t with the correct platform sizes, so don't typedef them. Also hard-fail 32-bit build attempts in setup.py; 32-bit platforms are no longer supported. --- setup.py | 5 +++++ src/aeg/aegis_cdef.h | 3 --- tools/generate.py | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 214efd8..bfa78ae 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,11 @@ from setuptools import setup ROOT = Path(__file__).parent.resolve() +if sys.maxsize <= 2**32: + raise RuntimeError( + "aeg does not support 32-bit platforms; build with a 64-bit Python" + ) + libaegis_static = ROOT / "libaegis/zig-out/lib" / ( "aegis.lib" if sys.platform == "win32" else "libaegis.a" ) diff --git a/src/aeg/aegis_cdef.h b/src/aeg/aegis_cdef.h index 6c4a394..e120a03 100644 --- a/src/aeg/aegis_cdef.h +++ b/src/aeg/aegis_cdef.h @@ -1,8 +1,5 @@ /* This file is generated with tools/generate.py. Do not edit. */ -typedef unsigned char uint8_t; -typedef unsigned long size_t; - /* aegis.h */ int aegis_init(void); int aegis_verify_16(const uint8_t *x, const uint8_t *y); diff --git a/tools/generate.py b/tools/generate.py index fff240a..3b27bc7 100755 --- a/tools/generate.py +++ b/tools/generate.py @@ -74,12 +74,12 @@ def format_declaration(decl: str, max_width: int = 100) -> str: def generate_cdef(include_dir: pathlib.Path) -> str: + # cffi pre-defines uint8_t, size_t, etc. with the correct platform sizes. + # Do not typedef them here: "unsigned long" matches size_t on LP64 but is + # 4 bytes vs 8 on Win64 (LLP64), breaking struct layout verification. lines = [ "/* This file is generated with tools/generate.py. Do not edit. */", "", - "typedef unsigned char uint8_t;", - "typedef unsigned long size_t;", - "", ] headers = [