Skip to content

Commit

Permalink
Merge pull request #594 from java-native-access/471-native-bool
Browse files Browse the repository at this point in the history
Add support for determining 'bool' size
  • Loading branch information
twall committed Feb 19, 2016
2 parents 35cd6cf + 745d5ac commit 6d62b00
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions native/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ static int _protect;

#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif

#define MEMCPY(ENV,D,S,L) do { \
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ public void uncaughtException(Callback c, Throwable e) {
public static final int WCHAR_SIZE;
/** Size of a native <code>size_t</code> type, in bytes. */
public static final int SIZE_T_SIZE;
/** Size of a native <code>bool</code> 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;
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/com/sun/jna/NativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6d62b00

Please sign in to comment.