[jffi-next] 19/24: Make Array, Struct, Union all inherit from Aggregate, to centralize the cleanup (cherry picked from commit 4f12f2165612c1031cea0d6da141c06792c5afd2)

Tim Potter tpot-guest at moszumanska.debian.org
Wed Mar 4 04:51:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

tpot-guest pushed a commit to tag 0.6.5
in repository jffi-next.

commit 2e3e30f7687de488607cbc47a3e03650409ce68c
Author: Wayne Meissner <wmeissner at gmail.com>
Date:   Mon Aug 24 08:12:16 2009 +1000

    Make Array, Struct, Union all inherit from Aggregate, to centralize the cleanup
    (cherry picked from commit 4f12f2165612c1031cea0d6da141c06792c5afd2)
---
 src/com/kenai/jffi/Aggregate.java | 18 ++++++++++++++++++
 src/com/kenai/jffi/Array.java     | 11 +----------
 src/com/kenai/jffi/Struct.java    | 11 +----------
 src/com/kenai/jffi/Union.java     | 11 +----------
 4 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/src/com/kenai/jffi/Aggregate.java b/src/com/kenai/jffi/Aggregate.java
new file mode 100644
index 0000000..3264453
--- /dev/null
+++ b/src/com/kenai/jffi/Aggregate.java
@@ -0,0 +1,18 @@
+
+package com.kenai.jffi;
+
+public abstract class Aggregate extends Type {
+
+    public Aggregate(long handle) {
+        super(handle);
+    }
+    
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            Foreign.getInstance().freeStruct(handle);
+        } finally {
+            super.finalize();
+        }
+    }
+}
diff --git a/src/com/kenai/jffi/Array.java b/src/com/kenai/jffi/Array.java
index de4280d..a638ae1 100644
--- a/src/com/kenai/jffi/Array.java
+++ b/src/com/kenai/jffi/Array.java
@@ -4,7 +4,7 @@ package com.kenai.jffi;
 /**
  * Describes the layout of a C array
  */
-public final class Array extends Type {
+public final class Array extends Aggregate {
     /* Keep a strong reference to the element types so it is not GCed */
     private final Type elementType;
 
@@ -53,13 +53,4 @@ public final class Array extends Type {
     public final int length() {
         return length;
     }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            Foreign.getInstance().freeStruct(handle);
-        } finally {
-            super.finalize();
-        }
-    }
 }
diff --git a/src/com/kenai/jffi/Struct.java b/src/com/kenai/jffi/Struct.java
index df10791..c693223 100644
--- a/src/com/kenai/jffi/Struct.java
+++ b/src/com/kenai/jffi/Struct.java
@@ -4,7 +4,7 @@ package com.kenai.jffi;
 /**
  * Describes the layout of a C struct
  */
-public final class Struct extends Type {
+public final class Struct extends Aggregate {
     /* Keep a strong reference to the field types so they do not GCed */
     private final Type[] fields;
 
@@ -17,13 +17,4 @@ public final class Struct extends Type {
         super(Foreign.getInstance().newStruct(Type.nativeHandles(fields), false));
         this.fields = (Type[]) fields.clone();
     }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            Foreign.getInstance().freeStruct(handle);
-        } finally {
-            super.finalize();
-        }
-    }
 }
diff --git a/src/com/kenai/jffi/Union.java b/src/com/kenai/jffi/Union.java
index 28d2ae9..1575d5e 100644
--- a/src/com/kenai/jffi/Union.java
+++ b/src/com/kenai/jffi/Union.java
@@ -4,7 +4,7 @@ package com.kenai.jffi;
 /**
  * Describes the layout of a C union
  */
-public final class Union extends Type {
+public final class Union extends Aggregate {
     /* Keep a strong reference to the field types so they do not GCed */
     private final Type[] fields;
 
@@ -17,13 +17,4 @@ public final class Union extends Type {
         super(Foreign.getInstance().newStruct(Type.nativeHandles(fields), true));
         this.fields = (Type[]) fields.clone();
     }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            Foreign.getInstance().freeStruct(handle);
-        } finally {
-            super.finalize();
-        }
-    }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jffi-next.git



More information about the pkg-java-commits mailing list