From 290bbcf333679ffa057d57d1b540608e3bec8ada Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Thu, 17 Jul 2025 11:32:16 -0700 Subject: Specify fixed underlying types for enums exposed by core This allows a few widely-used enums to be shrunk from 4 bytes to 1 byte, improving packing when they're used as struct members. To remain compatible with C, we follow CoreFoundation's approach and use a macro when defining the enum: ``` #if defined(__cplusplus) || __has_extension(c_fixed_enum) #define BN_ENUM(type, name) enum name : type #else #define BN_ENUM(type, name) typedef type name; enum #endif BN_ENUM(uint8_t, SomeEnum) { ... } ``` In C++ and C23 this will expand to an enum with a fixed underlying type. In older C language versions, this will result in the enum type being a typedef of the underlying type, with an unnamed enum providing the enum values. Minor changes were needed within the Python bindings to update places that made assumptions about the underlying type of the enums. --- python/binaryview.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python/binaryview.py') diff --git a/python/binaryview.py b/python/binaryview.py index f9afe2b8..47deb136 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -7161,7 +7161,7 @@ class BinaryView: :rtype: None """ value = ctypes.c_char_p() - string_type = ctypes.c_int() + string_type = core.StringTypeEnum() result = core.BNCheckForStringAnnotationType(self.handle, addr, value, string_type, allow_short_strings, allow_large_strings, child_width) if result: result = value.value.decode("utf-8") @@ -10591,7 +10591,7 @@ to a the type "tagRECT" found in the typelibrary "winX64common" if not isinstance(buffer, databuffer.DataBuffer): raise TypeError("buffer must be an instance of databuffer.DataBuffer") string = ctypes.c_char_p() - string_type = ctypes.c_int() + string_type = core.StringTypeEnum() if arch is not None: arch = arch.handle if not core.BNStringifyUnicodeData(self.handle, arch, buffer.handle, null_terminates, allow_short_strings, ctypes.byref(string), ctypes.byref(string_type)): -- cgit v1.3.1