From 3b03560ee709e36fe20937008028b3591de34874 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 14 Jul 2006 16:14:52 +0000 Subject: [PATCH] Split the external LWJGL version from the internal version of the native JNI library. The internal JNI version is now an integer. This has multiple advantages over the old way: 1. The JNI_VERSION field is now included automatically in the generated JNI headers, relieving us of the burden of updating the version number in both java and native code. 2. We can update the JNI version with every non-compatible change of the JNI library API, not just once per release, giving us extra safety when users download and build LWJGL from SVN. 3. We can now avoid rebuilding natives if a particular release only contains java changes. Currently, This is mostly a problem when Brian bumps the external version prior a release and I forget to re-build the natives ;) --- src/java/org/lwjgl/DefaultSysImplementation.java | 5 ++++- src/java/org/lwjgl/Sys.java | 11 +++++++---- src/java/org/lwjgl/SysImplementation.java | 2 +- src/native/common/common_tools.c | 5 ++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/java/org/lwjgl/DefaultSysImplementation.java b/src/java/org/lwjgl/DefaultSysImplementation.java index dd8d200f..54223244 100644 --- a/src/java/org/lwjgl/DefaultSysImplementation.java +++ b/src/java/org/lwjgl/DefaultSysImplementation.java @@ -39,7 +39,10 @@ package org.lwjgl; * $Id$ */ abstract class DefaultSysImplementation implements SysImplementation { - public native String getNativeLibraryVersion(); + /** Included to let native have easy access to Sys.JNI_VERSION */ + private final static int JNI_VERSION = Sys.JNI_VERSION; + + public native int getJNIVersion(); public native void setDebug(boolean debug); public long getTimerResolution() { diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 03e50985..ab4e7084 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -56,6 +56,9 @@ public final class Sys { /** Current version of library */ private static final String VERSION = "1.0beta2"; + /** Current version of the JNI library */ + static final int JNI_VERSION = 1; + /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; @@ -97,10 +100,10 @@ public final class Sys { implementation = createImplementation(); loadLibrary(JNI_LIBRARY_NAME); - String native_version = implementation.getNativeLibraryVersion(); - if (!native_version.equals(getVersion())) - throw new LinkageError("Version mismatch: jar version is '" + getVersion() + - "', native libary version is '" + native_version + "'"); + int native_jni_version = implementation.getJNIVersion(); + if (native_jni_version != JNI_VERSION) + throw new LinkageError("Version mismatch: jar version is '" + JNI_VERSION + + "', native libary version is '" + native_jni_version + "'"); implementation.setDebug(LWJGLUtil.DEBUG); } diff --git a/src/java/org/lwjgl/SysImplementation.java b/src/java/org/lwjgl/SysImplementation.java index f7c9e7d3..e29946b0 100644 --- a/src/java/org/lwjgl/SysImplementation.java +++ b/src/java/org/lwjgl/SysImplementation.java @@ -44,7 +44,7 @@ interface SysImplementation { /** * Return the version of the native library */ - String getNativeLibraryVersion(); + int getJNIVersion(); void setDebug(boolean debug); diff --git a/src/native/common/common_tools.c b/src/native/common/common_tools.c index f424893b..cbda3691 100644 --- a/src/native/common/common_tools.c +++ b/src/native/common/common_tools.c @@ -48,7 +48,6 @@ #include "org_lwjgl_DefaultSysImplementation.h" static bool debug = false; -static const char* VERSION = "1.0beta2"; static JavaVM *jvm; void initAttribList(attrib_list_t *list) { @@ -64,9 +63,9 @@ void putAttrib(attrib_list_t *list, int attrib) { list->current_index++; } -JNIEXPORT jstring JNICALL Java_org_lwjgl_DefaultSysImplementation_getNativeLibraryVersion +JNIEXPORT jint JNICALL Java_org_lwjgl_DefaultSysImplementation_getJNIVersion (JNIEnv *env, jobject ignored) { - return NewStringNative(env, VERSION); + return org_lwjgl_DefaultSysImplementation_JNI_VERSION; } JNIEXPORT void JNICALL Java_org_lwjgl_DefaultSysImplementation_setDebug