diff --git a/CHANGES.md b/CHANGES.md index 5e28d10f60..6417de12b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,7 +22,8 @@ Features * [#547](https://github.com/java-native-access/jna/pull/547): Added `GetSystemTimes` to `com.sun.jna.platform.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis). * [#548](https://github.com/java-native-access/jna/pull/548): Return 64-bit unsigned integer from `com.sun.jna.platform.win32.WinBase.FILETIME` - [@dbwiddis](https://github.com/dbwiddis). * [#524](https://github.com/java-native-access/jna/pull/524): Added IShellFolder interface plus necessary utility functions to Windows platform, and a sample for enumerating objects in My Computer - [@lwahonen](https://github.com/lwahonen). -* [#484](https://github.com/twall/jna/pull/484): Added `XFetchName` to `X11` interface - [@pinaf](https://github.com/pinaf). +* [#471](https://github.com/java-native-access/jna/issues/471): Determine size of native `bool` - [@twall](https://github.com/twall). +* [#484](https://github.com/java-native-access/jna/pull/484): Added `XFetchName` to `X11` interface - [@pinaf](https://github.com/pinaf). * [#554](https://github.com/java-native-access/jna/pull/554): Initial code for a few Unix 'libc' API(s) [@lgoldstein](https://github.com/lgoldstein) * [#552](https://github.com/java-native-access/jna/pull/552): Added `Module32FirstW` and `Module32NextW` to `com.sun.jna.platform.win32.Kernel32` (and helper to `com.sun.jna.platform.win32.Kernel32Util`) and `MODULEENTRY32W` structure to `com.sun.jna.platform.win32.Tlhelp32` - [@mlfreeman2](https://github.com/mlfreeman2). * [#564](https://github.com/java-native-access/jna/pull/564): Use generic definition of Native#loadLibrary [@lgoldstein](https://github.com/lgoldstein) diff --git a/native/dispatch.c b/native/dispatch.c index ecefb146f3..0f64421a68 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -97,6 +97,8 @@ static int _protect; #ifdef __cplusplus extern "C" { +#else +#include #endif #define MEMCPY(ENV,D,S,L) do { \ @@ -2738,6 +2740,7 @@ Java_com_sun_jna_Native_sizeof(JNIEnv *env, jclass UNUSED(cls), jint type) case com_sun_jna_Native_TYPE_LONG: return sizeof(long); case com_sun_jna_Native_TYPE_WCHAR_T: return sizeof(wchar_t); case com_sun_jna_Native_TYPE_SIZE_T: return sizeof(size_t); + case com_sun_jna_Native_TYPE_BOOL: return sizeof(bool); default: { char msg[MSG_SIZE]; diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java index a6a9670efd..1b10bb35a8 100644 --- a/src/com/sun/jna/Native.java +++ b/src/com/sun/jna/Native.java @@ -124,11 +124,14 @@ public void uncaughtException(Callback c, Throwable e) { public static final int WCHAR_SIZE; /** Size of a native size_t type, in bytes. */ public static final int SIZE_T_SIZE; + /** Size of a native bool type (C99 and later), in bytes. */ + public static final int BOOL_SIZE; private static final int TYPE_VOIDP = 0; private static final int TYPE_LONG = 1; private static final int TYPE_WCHAR_T = 2; private static final int TYPE_SIZE_T = 3; + private static final int TYPE_BOOL = 4; static final int MAX_ALIGNMENT; static final int MAX_PADDING; @@ -143,6 +146,7 @@ public static float parseVersion(String v) { LONG_SIZE = sizeof(TYPE_LONG); WCHAR_SIZE = sizeof(TYPE_WCHAR_T); SIZE_T_SIZE = sizeof(TYPE_SIZE_T); + BOOL_SIZE = sizeof(TYPE_BOOL); // Perform initialization of other JNA classes until *after* // initializing the above final fields diff --git a/test/com/sun/jna/NativeTest.java b/test/com/sun/jna/NativeTest.java index 1602c5c764..164d03375e 100644 --- a/test/com/sun/jna/NativeTest.java +++ b/test/com/sun/jna/NativeTest.java @@ -157,6 +157,10 @@ public void testCustomizeDefaultStringEncoding() { } } + public void testSizeof() { + assertEquals("Wrong bool size", 1, Native.BOOL_SIZE); + } + public static interface TestLib extends Library { interface VoidCallback extends Callback { void callback();