From 188beaf5b1986cdc0e1cfbd4c29cbdcb7cb0f46e Mon Sep 17 00:00:00 2001 From: Michael Zucchi Date: Tue, 14 May 2019 22:31:37 +0930 Subject: [PATCH] Revert previous changes. A rough solution to a rare problem. --- .../classes/au/notzed/nativez/NativeZ.java | 2 - .../classes/au/notzed/nativez/ReferenceZ.java | 53 ------------------- src/notzed.nativez/jni/nativez-jni.c | 38 ------------- src/notzed.nativez/jni/nativez-jni.def | 4 -- src/notzed.nativez/jni/nativez.h | 3 -- 5 files changed, 100 deletions(-) delete mode 100644 src/notzed.nativez/classes/au/notzed/nativez/ReferenceZ.java diff --git a/src/notzed.nativez/classes/au/notzed/nativez/NativeZ.java b/src/notzed.nativez/classes/au/notzed/nativez/NativeZ.java index 19d3ae1..f33ce74 100644 --- a/src/notzed.nativez/classes/au/notzed/nativez/NativeZ.java +++ b/src/notzed.nativez/classes/au/notzed/nativez/NativeZ.java @@ -72,8 +72,6 @@ public abstract class NativeZ { static private final ReferenceQueue references = new ReferenceQueue<>(); static { - System.loadLibrary("nativez"); - Thread cleanup = new Thread(NativeZ::cleaner, "NativeZ cleaner"); cleanup.setPriority(Thread.MAX_PRIORITY); cleanup.setDaemon(true); diff --git a/src/notzed.nativez/classes/au/notzed/nativez/ReferenceZ.java b/src/notzed.nativez/classes/au/notzed/nativez/ReferenceZ.java deleted file mode 100644 index c80bc29..0000000 --- a/src/notzed.nativez/classes/au/notzed/nativez/ReferenceZ.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2019 Michael Zucchi - * - * This file is part of nativez - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * (1) Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * (3)The name of the author may not be used to - * endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ -package au.notzed.nativez; - -/** - * This is a native object which keeps references to Java objects. - *

- * This is used when a native object requires some references but has - * nowhere in the native object being wrapped to store them. - *

- * This is only used by the native code side. - */ -public class ReferenceZ extends NativeZ { - - public ReferenceZ(long p) { - super(p); - } - - private static native void release(long p); - -} diff --git a/src/notzed.nativez/jni/nativez-jni.c b/src/notzed.nativez/jni/nativez-jni.c index a3dfaf4..77c553c 100644 --- a/src/notzed.nativez/jni/nativez-jni.c +++ b/src/notzed.nativez/jni/nativez-jni.c @@ -52,23 +52,7 @@ static int fail(const char *ctx, const char *what) { return -1; } -jint JNI_OnLoad(JavaVM *vmi, void *reserved) { - JNIEnv *env; - - if ((*vmi)->GetEnv(vmi, (void *)&env, JNI_VERSION_1_4) < 0) - return 0; - - if (nativez_OnLoad(vmi, env) != 0) - return 0; - - - return JNI_VERSION_1_4; -} - jint nativez_OnLoad(JavaVM *vmi, JNIEnv *env) { - /* Only init once */ - if (vm) - return 0; /* Save VM - required for callbacks from threads */ vm = vmi; @@ -382,25 +366,3 @@ void *NativeZ_getP(JNIEnv *env, jobject jo) { else return NULL; } - -#include "au_notzed_nativez_ReferenceZ.h" - -typedef struct NZReferenceZ { - size_t count; - jobject jreference[]; -} NZReferenceZ; - -jobject ReferenceZ_create(JNIEnv *env, jobject *reflist, size_t count) { - NZReferenceZ *ref = malloc(sizeof(*ref) + sizeof(jobject) * count); - - if (!ref) { - nativez_ThrowOutOfMemoryError(env, "Creating ReferenceZ"); - return NULL; - } - - ref->count = count; - for (int i=0;ijreference[i] = (*env)->NewGlobalRef(env, reflist[i]); - - return NativeZ_create(env, ReferenceZ_classid, ref); -} diff --git a/src/notzed.nativez/jni/nativez-jni.def b/src/notzed.nativez/jni/nativez-jni.def index f85b4a2..3fa29af 100644 --- a/src/notzed.nativez/jni/nativez-jni.def +++ b/src/notzed.nativez/jni/nativez-jni.def @@ -20,7 +20,3 @@ java NativeZ au/notzed/nativez/NativeZ { static refer, (Ljava/lang/Class;J)Lau/notzed/nativez/NativeZ; p, J } - -java ReferenceZ au/notzed/nativez/ReferenceZ { -} - diff --git a/src/notzed.nativez/jni/nativez.h b/src/notzed.nativez/jni/nativez.h index 2258408..51d862c 100644 --- a/src/notzed.nativez/jni/nativez.h +++ b/src/notzed.nativez/jni/nativez.h @@ -200,7 +200,4 @@ jobject NativeZ_refer(JNIEnv *env, jclass jc, void *p); /* Retreive the native pointer stored in NativeZ subclass instance jo */ void *NativeZ_getP(JNIEnv *env, jobject jo); -/* Create an object which maintains jni-side references to java objects */ -jobject ReferenceZ_create(JNIEnv *env, jobject *reflist, size_t count); - #endif -- 2.39.5