[libjna-java] 02/03: Added a default implementation of Structure.getFieldOrder() to preserve the compatibility with JNA < 3.5.0
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Wed Oct 15 23:27:53 BST 2014
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository libjna-java.
commit 2bed85a971af3832d923214e47892a1c48b3df3e
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Thu Oct 16 00:23:02 2014 +0200
Added a default implementation of Structure.getFieldOrder() to preserve the compatibility with JNA < 3.5.0
---
debian/changelog | 2 +
.../12-structure-backward-compatibility.patch | 76 ++++++++++++++++++++++
debian/patches/series | 1 +
3 files changed, 79 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index bf1198f..9f67fa7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,8 @@ libjna-java (4.1.0-1) UNRELEASED; urgency=low
* Removed 08-multiarch-support.patch (merged upstream since jna 3.5.0)
* Removed 02-builddir.patch (merged upstream since 4.0.0)
* Removed 05-support-gnu-kfreebsd.patch (merged upstream since 4.0.0)
+ * Added a default implementation of Structure.getFieldOrder() to preserve
+ the compatibility with JNA < 3.5.0
* Moved libjnidispatch.so into its own new arch any libjna-jni package
* Install libjnidispatch.so in a multiarch path
* Install the Maven artifacts for the platform jar (Closes: #743732)
diff --git a/debian/patches/12-structure-backward-compatibility.patch b/debian/patches/12-structure-backward-compatibility.patch
new file mode 100644
index 0000000..559e2f5
--- /dev/null
+++ b/debian/patches/12-structure-backward-compatibility.patch
@@ -0,0 +1,76 @@
+Description: Provide a default implementation of the abstract Structure.getFieldOrder()
+ method to preserve the compatibility with JNA < 3.5.0. The implementation is derived
+ from the JNA 3.4.2 code.
+Author: Emmanuel Bourg <ebourg at apache.org>
+Forwarded: not-needed
+--- a/src/com/sun/jna/Structure.java
++++ b/src/com/sun/jna/Structure.java
+@@ -106,6 +106,34 @@
+ */
+ public interface ByReference { }
+
++ private static class MemberOrder {
++ private static final String[] FIELDS = { "first", "second", "middle", "penultimate", "last" };
++ public int first;
++ public int second;
++ public int middle;
++ public int penultimate;
++ public int last;
++ }
++
++ private static final boolean REVERSE_FIELDS;
++ private static final boolean REQUIRES_FIELD_ORDER;
++
++ static {
++ // Check for predictable field order; IBM and JRockit store fields in
++ // reverse order; Excelsior JET requires explicit order
++ Field[] fields = MemberOrder.class.getFields();
++ List names = new ArrayList();
++ for (int i=0; i < fields.length; i++) {
++ names.add(fields[i].getName());
++ }
++ List expected = Arrays.asList(MemberOrder.FIELDS);
++ List reversed = new ArrayList(expected);
++ Collections.reverse(reversed);
++
++ REVERSE_FIELDS = names.equals(reversed);
++ REQUIRES_FIELD_ORDER = !(names.equals(expected) || REVERSE_FIELDS);
++ }
++
+ /** Use the platform default alignment. */
+ public static final int ALIGN_DEFAULT = 0;
+ /** No alignment, place all fields on nearest 1-byte boundary */
+@@ -831,7 +859,32 @@
+ * field order as returned by {@link Class#getFields()} is not
+ * guaranteed to be predictable.
+ */
+- protected abstract List getFieldOrder();
++ protected List getFieldOrder() {
++ if (REQUIRES_FIELD_ORDER) {
++ throw new Error("This VM does not store fields in a predictable order; you must implement Structure.getFieldOrder on " + getClass() + " to explicitly indicate the field order: " + System.getProperty("java.vendor") + ", " + System.getProperty("java.version"));
++ }
++
++ return getFieldNames();
++ }
++
++ private List<String> getFieldNames() {
++ List<String> names = new ArrayList<String>();
++ for (Class cls = getClass(); !cls.equals(Structure.class); cls = cls.getSuperclass()) {
++ List<String> fields = new ArrayList<String>();
++ for (Field field : cls.getDeclaredFields()) {
++ int modifiers = field.getModifiers();
++ if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
++ continue;
++ }
++ fields.add(field.getName());
++ }
++ if (REVERSE_FIELDS) {
++ Collections.reverse(fields);
++ }
++ names.addAll(0, fields);
++ }
++ return names;
++ }
+
+ /**
+ * Force a compile-time error on the old method of field definition
diff --git a/debian/patches/series b/debian/patches/series
index 3e21bda..705cad6 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -4,3 +4,4 @@
06-remove-gjdoc-inexistent-options.patch
09-javadoc.patch
10-disable-full-jar.patch
+12-structure-backward-compatibility.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libjna-java.git
More information about the pkg-java-commits
mailing list