Browse files

fixes #129

  • Loading branch information...
1 parent da4d941 commit eaff9bd176d0c08789197ddbdbee81090ea9ecb4 @twall twall committed Oct 5, 2012
View
2 CHANGES.md
@@ -17,6 +17,8 @@ Bug Fixes
* Fix crash in direct mode callbacks with certain type conversions - [@twall](https://github.com/twall).
* More thoroughly propagate unexpected exceptions generated in jnidispatch - [@twall](https://github.com/twall).
* Cleanup maven poms and publishing to central repo - [@bhamail](https://github.com/bhamail).
+* [#129](https://github.com/twall/jna/issues/129): Allow `Memory` field in structure - [@twall](https://github.com/twall).
+* Preserve `PointerType` fields on `Structure.read()` if unchanged - [@twall](https://github.com/twall).
Release 3.4.2
=============
View
2 src/com/sun/jna/Native.java
@@ -1025,7 +1025,7 @@ public static int getNativeSize(Class cls) {
return POINTER_SIZE;
}
throw new IllegalArgumentException("Native size for type \"" + cls.getName()
- + "\" is unknown");
+ + "\" is unknown");
}
/** Indicate whether the given class is supported as a native argument
View
3 src/com/sun/jna/Pointer.java
@@ -452,6 +452,9 @@ else if (NativeMapped.class.isAssignableFrom(type)) {
if (nm != null) {
Object value = getValue(offset, nm.nativeType(), null);
result = nm.fromNative(value, new FromNativeContext(type));
+ if (nm.equals(result)) {
+ result = nm;
+ }
}
else {
NativeMappedConverter tc = NativeMappedConverter.getInstance(type);
View
2 src/com/sun/jna/PointerType.java
@@ -98,6 +98,6 @@ public boolean equals(Object o) {
}
public String toString() {
- return pointer == null ? "NULL" : pointer.toString();
+ return pointer == null ? "NULL" : pointer.toString() + " (" + super.toString() + ")";
}
}
View
5 src/com/sun/jna/Structure.java
@@ -626,6 +626,9 @@ Object readField(StructField structField) {
Object result = memory.getValue(offset, fieldType, currentValue);
if (readConverter != null) {
result = readConverter.fromNative(result, structField.context);
+ if (currentValue != null && currentValue.equals(result)) {
+ result = currentValue;
+ }
}
if (fieldType.equals(String.class)
@@ -1193,7 +1196,7 @@ protected int getNativeAlignment(Class type, Object value, boolean isFirstElemen
|| Float.class == type || Double.class == type) {
alignment = size;
}
- else if (Pointer.class == type
+ else if ((Pointer.class.isAssignableFrom(type) && !Function.class.isAssignableFrom(type))
|| (Platform.HAS_BUFFERS && Buffer.class.isAssignableFrom(type))
|| Callback.class.isAssignableFrom(type)
|| WString.class == type
View
12 test/com/sun/jna/StructureTest.java
@@ -553,6 +553,16 @@ protected List getFieldOrder() {
}
}
+ public void testMemoryField() {
+ class MemoryFieldStructure extends Structure {
+ public Memory m;
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "m" });
+ }
+ }
+ new MemoryFieldStructure().size();
+ }
+
public void testDisallowFunctionPointerAsField() {
class BadFieldStructure extends Structure {
public Function cb;
@@ -785,9 +795,11 @@ protected List getFieldOrder() {
}
TestStructure s = new TestStructure();
final Pointer p = s.p;
+ final TestPointer p2 = s.p2;
s.write();
s.read();
assertSame("Should preserve Pointer references if peer unchanged", p, s.p);
+ assertSame("Should preserve PointerType references if peer unchanged", p2, s.p2);
}
public void testPreserveStringFields() {

0 comments on commit eaff9bd

Please sign in to comment.