Skip to content

Commit e19760e

Browse files
Fix to use SIZE_T for GType rather than expecting it to be native long size (errors with Windows and Java 9) (#100)
1 parent 8a3012a commit e19760e

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/org/freedesktop/gstreamer/GObject.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ public static GType getType(Pointer ptr) {
144144
// Quick getter for GType without allocation
145145
// same as : new GObjectStruct(ptr).g_type_instance.g_class.g_type
146146
Pointer g_class = ptr.getPointer(0);
147-
return GType.valueOf(g_class.getNativeLong(0).longValue());
147+
if(Native.SIZE_T_SIZE == 8) {
148+
return GType.valueOf(g_class.getLong(0));
149+
} else if (Native.SIZE_T_SIZE == 4) {
150+
return GType.valueOf( ((long) g_class.getInt(0)) & 0xffffffffL );
151+
} else {
152+
throw new IllegalStateException("SIZE_T size not supported: " + Native.SIZE_T_SIZE);
153+
}
148154
}
149155

150156
/**

src/org/freedesktop/gstreamer/MiniObject.java

+22-15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package org.freedesktop.gstreamer;
2323

24+
import com.sun.jna.Native;
2425
import com.sun.jna.Pointer;
2526

2627
import org.freedesktop.gstreamer.lowlevel.GType;
@@ -49,9 +50,15 @@ public MiniObject(Initializer init) {
4950
* Gives the type value.
5051
*/
5152
public static GType getType(Pointer ptr) {
52-
// Quick getter for GType without allocation
53-
// same as : new MiniObjectStruct(ptr).type
54-
return GType.valueOf(ptr.getNativeLong(0).longValue());
53+
// Quick getter for GType without allocation
54+
// same as : new MiniObjectStruct(ptr).type
55+
if (Native.SIZE_T_SIZE == 8) {
56+
return GType.valueOf(ptr.getLong(0));
57+
} else if (Native.SIZE_T_SIZE == 4) {
58+
return GType.valueOf( ((long) ptr.getInt(0)) & 0xffffffffL );
59+
} else {
60+
throw new IllegalStateException("SIZE_T size not supported: " + Native.SIZE_T_SIZE);
61+
}
5562
}
5663

5764
/**
@@ -87,32 +94,32 @@ protected <T extends MiniObject> T makeWritable() {
8794
* @return the new MiniObject.
8895
*/
8996
public <T extends MiniObject> T copy() {
90-
MiniObject result = GSTMINIOBJECT_API.gst_mini_object_copy(this);
97+
MiniObject result = GSTMINIOBJECT_API.gst_mini_object_copy(this);
9198
if (result == null) {
9299
throw new NullPointerException("Could not make a copy of " + this.getClass().getSimpleName());
93100
}
94101
return (T)result;
95102
}
96103

97104
@Override
98-
protected void ref() {
105+
protected void ref() {
99106
GSTMINIOBJECT_API.gst_mini_object_ref(this);
100107
}
101-
108+
102109
@Override
103-
protected void unref() {
104-
GSTMINIOBJECT_API.gst_mini_object_unref(this);
110+
protected void unref() {
111+
GSTMINIOBJECT_API.gst_mini_object_unref(this);
105112
}
106113

107114
public int getRefCount() {
108-
final MiniObjectStruct struct = new MiniObjectStruct(handle());
109-
return (Integer) struct.readField("refcount");
115+
final MiniObjectStruct struct = new MiniObjectStruct(handle());
116+
return (Integer) struct.readField("refcount");
110117
}
111118

112119
@Override
113-
protected void disposeNativeHandle(Pointer ptr) {
114-
if (ownsHandle.get()) {
115-
GSTMINIOBJECT_API.gst_mini_object_unref(ptr);
116-
}
117-
}
120+
protected void disposeNativeHandle(Pointer ptr) {
121+
if (ownsHandle.get()) {
122+
GSTMINIOBJECT_API.gst_mini_object_unref(ptr);
123+
}
124+
}
118125
}

0 commit comments

Comments
 (0)