From c4b58c19bc09af189c0e1c0e2003b3b1ed3e781f Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 6 Sep 2004 17:50:58 +0000 Subject: [PATCH] need to make pointer size adjustment from int to long at compile time only where needed. --- bindings/java/src/jni/javasigar.c | 14 ++++++++++++-- bindings/java/src/net/hyperic/sigar/Sigar.java | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bindings/java/src/jni/javasigar.c b/bindings/java/src/jni/javasigar.c index 7e16c866..020d6e6f 100644 --- a/bindings/java/src/jni/javasigar.c +++ b/bindings/java/src/jni/javasigar.c @@ -130,8 +130,13 @@ static jni_sigar_t *sigar_get_pointer(JNIEnv *env, jobject obj) { cls = JENV->GetObjectClass(env, obj); - pointer_field = JENV->GetFieldID(env, cls, "sigarWrapper", "J"); +#ifdef SIGAR_POINTER_LONG + pointer_field = JENV->GetFieldID(env, cls, "longSigarWrapper", "J"); jsigar = (jni_sigar_t *) JENV->GetLongField(env, obj, pointer_field); +#else + pointer_field = JENV->GetFieldID(env, cls, "sigarWrapper", "I"); + jsigar = (jni_sigar_t *) JENV->GetIntField(env, obj, pointer_field); +#endif if (!jsigar) { sigar_throw_exception(env, "sigar has been closed"); @@ -151,8 +156,13 @@ static void sigar_set_pointer(JNIEnv *env, jobject obj, const void *ptr) { jfieldID pointer_field; jclass cls = JENV->GetObjectClass(env, obj); - pointer_field = JENV->GetFieldID(env, cls, "sigarWrapper", "J"); +#ifdef SIGAR_POINTER_LONG + pointer_field = JENV->GetFieldID(env, cls, "longSigarWrapper", "J"); JENV->SetLongField(env, obj, pointer_field, (jlong)ptr); +#else + pointer_field = JENV->GetFieldID(env, cls, "sigarWrapper", "I"); + JENV->SetIntField(env, obj, pointer_field, (int)ptr); +#endif } JNIEXPORT jstring SIGAR_JNI(Sigar_formatSize) diff --git a/bindings/java/src/net/hyperic/sigar/Sigar.java b/bindings/java/src/net/hyperic/sigar/Sigar.java index c259c17b..811e211c 100644 --- a/bindings/java/src/net/hyperic/sigar/Sigar.java +++ b/bindings/java/src/net/hyperic/sigar/Sigar.java @@ -33,7 +33,8 @@ public class Sigar implements SigarProxy { private static SigarLoader loader = new SigarLoader(Sigar.class); private FileSystemMap mounts = null; - long sigarWrapper = 0; //holds the sigar_t * + int sigarWrapper = 0; //holds the sigar_t * + long longSigarWrapper = 0; //same, but where sizeof(void*) > sizeof(int) // lastCpu is used to calculate the cpuPerc; private Cpu lastCpu;