Skip to content

Commit 8e6cbda

Browse files
author
Lyor Goldstein
committed
Use generic definition of Native#loadLibrary
1 parent a6a0c4e commit 8e6cbda

33 files changed

+686
-679
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Features
2525
* [#484](https://github.com/twall/jna/pull/484): Added `XFetchName` to `X11` interface - [@pinaf](https://github.com/pinaf).
2626
* [#554](https://github.com/java-native-access/jna/pull/554): Initial code for a few Unix 'libc' API(s) [@lgoldstein](https://github.com/lgoldstein)
2727
* [#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).
28+
* [#564](https://github.com/java-native-access/jna/pull/564): Use generic definition of Native#loadLibrary [@lgoldstein](https://github.com/lgoldstein)
2829

2930
Bug Fixes
3031
---------

build.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
<buildnumber/>
5757
<!-- JNA library release version -->
5858
<property name="jna.major" value="4"/>
59-
<property name="jna.minor" value="2"/>
60-
<property name="jna.revision" value="1"/>
59+
<property name="jna.minor" value="3"/>
60+
<property name="jna.revision" value="0"/>
6161
<property name="jna.build" value="0"/> <!--${build.number}-->
6262
<condition property="version.suffix" value="" else="-SNAPSHOT">
6363
<or>

contrib/ntservice/src/jnacontrib/jna/Advapi32.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
* @author TB
2626
*/
2727
public interface Advapi32 extends StdCallLibrary {
28-
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32",
29-
Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
28+
Advapi32 INSTANCE = Native.loadLibrary("Advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
3029

3130
/*
3231
* SC_HANDLE WINAPI OpenSCManager( LPCTSTR lpMachineName, LPCTSTR

contrib/platform/src/com/sun/jna/platform/mac/Carbon.java

+19-15
Original file line numberDiff line numberDiff line change
@@ -33,58 +33,62 @@
3333
* Date: 7/25/11
3434
*/
3535
public interface Carbon extends Library {
36-
public static Carbon INSTANCE = (Carbon) Native.loadLibrary("Carbon", Carbon.class);
36+
Carbon INSTANCE = Native.loadLibrary("Carbon", Carbon.class);
3737

38-
public static final int cmdKey = 0x0100;
39-
public static final int shiftKey = 0x0200;
40-
public static final int optionKey = 0x0800;
41-
public static final int controlKey = 0x1000;
38+
int cmdKey = 0x0100;
39+
int shiftKey = 0x0200;
40+
int optionKey = 0x0800;
41+
int controlKey = 0x1000;
4242

4343
/**
4444
* Obtains the event target reference for the standard toolbox dispatcher
4545
* @return event dispatcher reference
4646
*/
47-
public Pointer GetEventDispatcherTarget();
47+
Pointer GetEventDispatcherTarget();
4848

4949
/**
5050
* Installs an event handler on a specified event target.
5151
*/
52-
public int InstallEventHandler(Pointer inTarget, EventHandlerProcPtr inHandler, int inNumTypes, EventTypeSpec[] inList, Pointer inUserData, PointerByReference outRef);
52+
int InstallEventHandler(Pointer inTarget, EventHandlerProcPtr inHandler, int inNumTypes, EventTypeSpec[] inList, Pointer inUserData, PointerByReference outRef);
5353

5454
/**
5555
* Registers a global hot key.
5656
*/
57-
public int RegisterEventHotKey(int inHotKeyCode, int inHotKeyModifiers, EventHotKeyID.ByValue inHotKeyID, Pointer inTarget, int inOptions, PointerByReference outRef);
57+
int RegisterEventHotKey(int inHotKeyCode, int inHotKeyModifiers, EventHotKeyID.ByValue inHotKeyID, Pointer inTarget, int inOptions, PointerByReference outRef);
5858

5959
/**
6060
* Obtains a parameter from the specified event.
6161
*/
62-
public int GetEventParameter(Pointer inEvent, int inName, int inDesiredType, Pointer outActualType, int inBufferSize, IntBuffer outActualSize, EventHotKeyID outData);
62+
int GetEventParameter(Pointer inEvent, int inName, int inDesiredType, Pointer outActualType, int inBufferSize, IntBuffer outActualSize, EventHotKeyID outData);
6363

6464
/**
6565
* Removes the specified event handler
6666
*/
67-
public int RemoveEventHandler(Pointer inHandlerRef);
67+
int RemoveEventHandler(Pointer inHandlerRef);
6868

6969
/**
7070
* Unregisters a global hot key.
7171
*/
72-
public int UnregisterEventHotKey(Pointer inHotKey);
72+
int UnregisterEventHotKey(Pointer inHotKey);
7373

7474
public class EventTypeSpec extends Structure {
7575
public int eventClass;
7676
public int eventKind;
77-
protected List getFieldOrder() {
78-
return Arrays.asList(new String[] { "eventClass", "eventKind" }); }
77+
@Override
78+
protected List<String> getFieldOrder() {
79+
return Arrays.asList("eventClass", "eventKind");
80+
}
7981
}
8082

8183
public static class EventHotKeyID extends Structure {
8284
public int signature;
8385
public int id;
8486

8587
public static class ByValue extends EventHotKeyID implements Structure.ByValue { }
86-
protected List getFieldOrder() {
87-
return Arrays.asList(new String[] { "signature", "id" }); }
88+
@Override
89+
protected List<String> getFieldOrder() {
90+
return Arrays.asList("signature", "id");
91+
}
8892
}
8993

9094
public static interface EventHandlerProcPtr extends Callback {

contrib/platform/src/com/sun/jna/platform/mac/SystemB.java

+57-57
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 Daniel Widdis
2+
* Copyright (c) 2015 Daniel Widdis
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Lesser General Public License as published by
@@ -33,46 +33,47 @@
3333
*/
3434
public interface SystemB extends Library {
3535

36-
public static SystemB INSTANCE = (SystemB) Native.loadLibrary("System",
37-
SystemB.class);
36+
SystemB INSTANCE = Native.loadLibrary("System", SystemB.class);
3837

3938
// host_statistics()
40-
static int HOST_LOAD_INFO = 1;// System loading stats
41-
static int HOST_VM_INFO = 2; // Virtual memory stats
42-
static int HOST_CPU_LOAD_INFO = 3;// CPU load stats
39+
int HOST_LOAD_INFO = 1;// System loading stats
40+
int HOST_VM_INFO = 2; // Virtual memory stats
41+
int HOST_CPU_LOAD_INFO = 3;// CPU load stats
4342

4443
// host_statistics64()
45-
static int HOST_VM_INFO64 = 4; // 64-bit virtual memory stats
44+
int HOST_VM_INFO64 = 4; // 64-bit virtual memory stats
4645

4746
// host_cpu_load_info()
48-
static int CPU_STATE_MAX = 4;
49-
static int CPU_STATE_USER = 0;
50-
static int CPU_STATE_SYSTEM = 1;
51-
static int CPU_STATE_IDLE = 2;
52-
static int CPU_STATE_NICE = 3;
47+
int CPU_STATE_MAX = 4;
48+
int CPU_STATE_USER = 0;
49+
int CPU_STATE_SYSTEM = 1;
50+
int CPU_STATE_IDLE = 2;
51+
int CPU_STATE_NICE = 3;
5352

5453
// host_processor_info() flavor
55-
static int PROCESSOR_BASIC_INFO = 1;
56-
static int PROCESSOR_CPU_LOAD_INFO = 2;
54+
int PROCESSOR_BASIC_INFO = 1;
55+
int PROCESSOR_CPU_LOAD_INFO = 2;
5756

5857
// Data size
59-
static int UINT64_SIZE = Native.getNativeSize(long.class);
60-
static int INT_SIZE = Native.getNativeSize(int.class);
58+
int UINT64_SIZE = Native.getNativeSize(long.class);
59+
int INT_SIZE = Native.getNativeSize(int.class);
6160

6261
public static class HostCpuLoadInfo extends Structure {
6362
public int cpu_ticks[] = new int[CPU_STATE_MAX];
64-
63+
64+
@Override
6565
protected List<String> getFieldOrder() {
66-
return Arrays.asList(new String[] { "cpu_ticks" });
66+
return Arrays.asList("cpu_ticks");
6767
}
6868
}
6969

7070
public static class HostLoadInfo extends Structure {
7171
public int[] avenrun = new int[3]; // scaled by LOAD_SCALE
7272
public int[] mach_factor = new int[3]; // scaled by LOAD_SCALE
73-
73+
74+
@Override
7475
protected List<String> getFieldOrder() {
75-
return Arrays.asList(new String[] { "avenrun", "mach_factor" });
76+
return Arrays.asList("avenrun", "mach_factor");
7677
}
7778
}
7879

@@ -94,12 +95,13 @@ public static class VMStatistics extends Structure {
9495
// # of pages speculative (included in free_count)
9596
public int speculative_count;
9697

98+
@Override
9799
protected List<String> getFieldOrder() {
98-
return Arrays.asList(new String[] { "free_count", "active_count",
99-
"inactive_count", "wire_count", "zero_fill_count",
100-
"reactivations", "pageins", "pageouts", "faults",
101-
"cow_faults", "lookups", "hits", "purgeable_count",
102-
"purges", "speculative_count" });
100+
return Arrays.asList("free_count", "active_count",
101+
"inactive_count", "wire_count", "zero_fill_count",
102+
"reactivations", "pageins", "pageouts", "faults",
103+
"cow_faults", "lookups", "hits", "purgeable_count",
104+
"purges", "speculative_count");
103105
}
104106
}
105107

@@ -137,34 +139,34 @@ public static class VMStatistics64 extends Structure {
137139

138140
@Override
139141
protected List<String> getFieldOrder() {
140-
return Arrays.asList(new String[] { "free_count", "active_count",
141-
"inactive_count", "wire_count",
142-
"zero_fill_count", "reactivations",
143-
"pageins", "pageouts",
144-
"faults", "cow_faults",
145-
"lookups", "hits",
146-
"purges",
147-
"purgeable_count", "speculative_count",
148-
"decompressions", "compressions",
149-
"swapins", "swapouts",
150-
"compressor_page_count", "throttled_count",
151-
"external_page_count", "internal_page_count",
152-
"total_uncompressed_pages_in_compressor" });
142+
return Arrays.asList("free_count", "active_count",
143+
"inactive_count", "wire_count",
144+
"zero_fill_count", "reactivations",
145+
"pageins", "pageouts",
146+
"faults", "cow_faults",
147+
"lookups", "hits",
148+
"purges",
149+
"purgeable_count", "speculative_count",
150+
"decompressions", "compressions",
151+
"swapins", "swapouts",
152+
"compressor_page_count", "throttled_count",
153+
"external_page_count", "internal_page_count",
154+
"total_uncompressed_pages_in_compressor");
153155
}
154156
}
155157

156158
/**
157159
* The mach_host_self system call returns the calling thread's host name
158160
* port. It has an effect equivalent to receiving a send right for the host
159161
* port.
160-
*
162+
*
161163
* @return the host's name port
162164
*/
163165
int mach_host_self();
164166

165167
/**
166168
* The host_page_size function returns the page size for the given host.
167-
*
169+
*
168170
* @param machPort
169171
* The name (or control) port for the host for which the page
170172
* size is desired.
@@ -177,7 +179,7 @@ protected List<String> getFieldOrder() {
177179
/**
178180
* The host_statistics function returns scheduling and virtual memory
179181
* statistics concerning the host as specified by hostStat.
180-
*
182+
*
181183
* @param machPort
182184
* The control port for the host for which information is to be
183185
* obtained.
@@ -191,13 +193,12 @@ protected List<String> getFieldOrder() {
191193
* returned (in natural-sized units).
192194
* @return 0 on success; sets errno on failure
193195
*/
194-
int host_statistics(int machPort, int hostStat, Structure stats,
195-
IntByReference count);
196+
int host_statistics(int machPort, int hostStat, Structure stats, IntByReference count);
196197

197198
/**
198199
* The host_statistics64 function returns 64-bit virtual memory statistics
199200
* concerning the host as specified by hostStat.
200-
*
201+
*
201202
* @param machPort
202203
* The control port for the host for which information is to be
203204
* obtained.
@@ -210,17 +211,16 @@ int host_statistics(int machPort, int hostStat, Structure stats,
210211
* returned (in natural-sized units).
211212
* @return 0 on success; sets errno on failure
212213
*/
213-
int host_statistics64(int machPort, int hostStat, Structure stats,
214-
IntByReference count);
214+
int host_statistics64(int machPort, int hostStat, Structure stats, IntByReference count);
215215

216216
/**
217217
* The sysctl() function retrieves system information and allows processes
218218
* with appropriate privileges to set system information. The information
219219
* available from sysctl() consists of integers, strings, and tables.
220-
*
220+
*
221221
* The state is described using a "Management Information Base" (MIB) style
222222
* name, listed in name, which is a namelen length array of integers.
223-
*
223+
*
224224
* The information is copied into the buffer specified by oldp. The size of
225225
* the buffer is given by the location specified by oldlenp before the call,
226226
* and that location gives the amount of data copied after a successful call
@@ -229,18 +229,18 @@ int host_statistics64(int machPort, int hostStat, Structure stats,
229229
* call supplies as much data as fits in the buffer provided and returns
230230
* with the error code ENOMEM. If the old value is not desired, oldp and
231231
* oldlenp should be set to NULL.
232-
*
232+
*
233233
* The size of the available data can be determined by calling sysctl() with
234234
* the NULL argument for oldp. The size of the available data will be
235235
* returned in the location pointed to by oldlenp. For some operations, the
236236
* amount of space may change often. For these operations, the system
237237
* attempts to round up so that the returned size is large enough for a call
238238
* to return the data shortly thereafter.
239-
*
239+
*
240240
* To set a new value, newp is set to point to a buffer of length newlen
241241
* from which the requested value is to be taken. If a new value is not to
242242
* be set, newp should be set to NULL and newlen set to 0.
243-
*
243+
*
244244
* @param name
245245
* MIB array of integers
246246
* @param namelen
@@ -262,7 +262,7 @@ int sysctl(int[] name, int namelen, Pointer oldp, IntByReference oldlenp,
262262
* The sysctlbyname() function accepts an ASCII representation of the name
263263
* and internally looks up the integer name vector. Apart from that, it
264264
* behaves the same as the standard sysctl() function.
265-
*
265+
*
266266
* @param name
267267
* ASCII representation of the MIB name
268268
* @param oldp
@@ -290,15 +290,15 @@ int sysctlbyname(String name, Pointer oldp, IntByReference oldlenp,
290290
* to repeatedly request the same variable (the sysctl() function runs in
291291
* about a third the time as the same request made via the sysctlbyname()
292292
* function).
293-
*
293+
*
294294
* The number of elements in the mib array can be determined by calling
295295
* sysctlnametomib() with the NULL argument for mibp.
296-
*
296+
*
297297
* The sysctlnametomib() function is also useful for fetching mib prefixes.
298298
* If size on input is greater than the number of elements written, the
299299
* array still contains the additional elements which may be written
300300
* programmatically.
301-
*
301+
*
302302
* @param name
303303
* ASCII representation of the name
304304
* @param mibp
@@ -309,10 +309,10 @@ int sysctlbyname(String name, Pointer oldp, IntByReference oldlenp,
309309
* @return 0 on success; sets errno on failure
310310
*/
311311
int sysctlnametomib(String name, Pointer mibp, IntByReference size);
312-
312+
313313
/**
314314
* The host_processor_info function returns information about processors.
315-
*
315+
*
316316
* @param machPort
317317
* The control port for the host for which information is to be
318318
* obtained.

contrib/platform/src/com/sun/jna/platform/mac/XAttr.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
interface XAttr extends Library {
2424

2525
// load from current image
26-
XAttr INSTANCE = (XAttr) Native.loadLibrary(null, XAttr.class);
26+
XAttr INSTANCE = Native.loadLibrary(null, XAttr.class);
2727

2828
// see /usr/include/sys/xattr.h
2929
int XATTR_NOFOLLOW = 0x0001;

contrib/platform/src/com/sun/jna/platform/unix/LibC.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
*/
2222
public interface LibC extends LibCAPI, Library {
2323
String NAME = "c";
24-
LibC INSTANCE = (LibC) Native.loadLibrary(NAME, LibC.class);
24+
LibC INSTANCE = Native.loadLibrary(NAME, LibC.class);
2525
}

0 commit comments

Comments
 (0)