need to make pointer size adjustment from int to long at compile time only where needed.

This commit is contained in:
Doug MacEachern 2004-09-06 17:50:58 +00:00
parent 5f3deb8927
commit c4b58c19bc
2 changed files with 14 additions and 3 deletions

View File

@ -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)

View File

@ -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;