Skip to content

Commit 7897cc7

Browse files
authored
Merge pull request #1724 from dbwiddis/fix-variable-size-mappings
Fix variable-size type mappings in mac SystemB and XAttr
2 parents 1e2075a + 95d793e commit 7897cc7

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Bug Fixes
2020
* [#1721](https://github.com/java-native-access/jna/pull/1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@dbwiddis](https://github.com/dbwiddis).
2121
* [#1722](https://github.com/java-native-access/jna/pull/1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@dbwiddis](https://github.com/dbwiddis).
2222
* [#1636](https://github.com/java-native-access/jna/issues/1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@matthiasblaesing](https://github.com/matthiasblaesing).
23+
* [#1724](https://github.com/java-native-access/jna/pull/1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@dbwiddis](https://github.com/dbwiddis).
2324

2425
Release 5.18.1
2526
==============

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.sun.jna.platform.unix.LibCAPI;
3434
import com.sun.jna.ptr.IntByReference;
3535
import com.sun.jna.ptr.LongByReference;
36+
import com.sun.jna.ptr.NativeLongByReference;
3637
import com.sun.jna.ptr.PointerByReference;
3738

3839
public interface SystemB extends LibCAPI, Library {
@@ -580,6 +581,13 @@ class Timezone extends Structure {
580581
* The host's page size (in bytes), set on success.
581582
* @return 0 on success; sets errno on failure
582583
*/
584+
int host_page_size(int hostPort, NativeLongByReference pPageSize);
585+
586+
/**
587+
* @deprecated Use
588+
* {@link #host_page_size(int, NativeLongByReference)}
589+
*/
590+
@Deprecated
583591
int host_page_size(int hostPort, LongByReference pPageSize);
584592

585593
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.sun.jna.Library;
2727
import com.sun.jna.Native;
2828
import com.sun.jna.Pointer;
29+
import com.sun.jna.platform.unix.LibCAPI.size_t;
30+
import com.sun.jna.platform.unix.LibCAPI.ssize_t;
2931

3032
/**
3133
* JNA wrapper for <sys/xattr.h>
@@ -48,15 +50,33 @@ public interface XAttr extends Library {
4850
String XATTR_RESOURCEFORK_NAME = "com.apple.ResourceFork";
4951

5052
// see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/getxattr.2.html
53+
ssize_t getxattr(String path, String name, Pointer value, size_t size, int position, int options);
54+
55+
/**
56+
* @deprecated Use {@link #getxattr(String, String, Pointer, size_t, int, int)}
57+
*/
58+
@Deprecated
5159
long getxattr(String path, String name, Pointer value, long size, int position, int options);
5260

5361
// see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/setxattr.2.html
62+
int setxattr(String path, String name, Pointer value, size_t size, int position, int options);
63+
64+
/**
65+
* @deprecated Use {@link #setxattr(String, String, Pointer, size_t, int, int)}
66+
*/
67+
@Deprecated
5468
int setxattr(String path, String name, Pointer value, long size, int position, int options);
5569

5670
// see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/removexattr.2.html
5771
int removexattr(String path, String name, int options);
5872

5973
// see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/listxattr.2.html
74+
ssize_t listxattr(String path, Pointer namebuff, size_t size, int options);
75+
76+
/**
77+
* @deprecated Use {@link #listxattr(String, Pointer, size_t, int)}
78+
*/
79+
@Deprecated
6080
long listxattr(String path, Pointer namebuff, long size, int options);
6181

6282
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030

3131
import com.sun.jna.Memory;
3232
import com.sun.jna.Native;
33+
import com.sun.jna.platform.unix.LibCAPI.size_t;
3334

3435
public class XAttrUtil {
3536

3637
public static List<String> listXAttr(String path) {
3738
// get required buffer size
38-
long bufferLength = XAttr.INSTANCE.listxattr(path, null, 0, 0);
39+
long bufferLength = XAttr.INSTANCE.listxattr(path, null, size_t.ZERO, 0).longValue();
3940

4041
if (bufferLength < 0)
4142
return null;
@@ -44,7 +45,7 @@ public static List<String> listXAttr(String path) {
4445
return new ArrayList<>(0);
4546

4647
Memory valueBuffer = new Memory(bufferLength);
47-
long valueLength = XAttr.INSTANCE.listxattr(path, valueBuffer, bufferLength, 0);
48+
long valueLength = XAttr.INSTANCE.listxattr(path, valueBuffer, new size_t(bufferLength), 0).longValue();
4849

4950
if (valueLength < 0)
5051
return null;
@@ -54,7 +55,7 @@ public static List<String> listXAttr(String path) {
5455

5556
public static String getXAttr(String path, String name) {
5657
// get required buffer size
57-
long bufferLength = XAttr.INSTANCE.getxattr(path, name, null, 0, 0, 0);
58+
long bufferLength = XAttr.INSTANCE.getxattr(path, name, null, size_t.ZERO, 0, 0).longValue();
5859

5960
if (bufferLength < 0) {
6061
return null;
@@ -66,7 +67,8 @@ public static String getXAttr(String path, String name) {
6667

6768
Memory valueBuffer = new Memory(bufferLength);
6869
valueBuffer.clear();
69-
long valueLength = XAttr.INSTANCE.getxattr(path, name, valueBuffer, bufferLength, 0, 0);
70+
long valueLength = XAttr.INSTANCE.getxattr(path, name, valueBuffer, new size_t(bufferLength), 0, 0)
71+
.longValue();
7072

7173
if (valueLength < 0) {
7274
return null;
@@ -77,7 +79,7 @@ public static String getXAttr(String path, String name) {
7779

7880
public static int setXAttr(String path, String name, String value) {
7981
Memory valueBuffer = encodeString(value);
80-
return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size(), 0, 0);
82+
return XAttr.INSTANCE.setxattr(path, name, valueBuffer, new size_t(valueBuffer.size()), 0, 0);
8183
}
8284

8385
public static int removeXAttr(String path, String name) {

0 commit comments

Comments
 (0)