diff options
| author | Mark Rowe <mark@vector35.com> | 2025-07-17 11:32:16 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2025-12-11 21:09:38 -0800 |
| commit | 290bbcf333679ffa057d57d1b540608e3bec8ada (patch) | |
| tree | f8c576eed0fdde52735e4555dfce3dbd7e692f1d /python/binaryview.py | |
| parent | e902d25c22f2bf1426d2619933587ace06a38921 (diff) | |
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.
Diffstat (limited to 'python/binaryview.py')
| -rw-r--r-- | python/binaryview.py | 4 |
1 files changed, 2 insertions, 2 deletions
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)): |
