I should have compiled with -pedantic, of course... I've included a few fixes in the attachment.
malloc() returns a char*, not a jbyte*.
[#1] byte addressable unit of data storage large enough to hold any member of the basic character set of the execution environment
[#2] NOTE 1 It is possible to express the address of each individual byte of an object uniquely.
[#3] NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit.
3.5 [#1] character bit representation that fits in a byte *
Do we actually have to deal with platforms that have non 8-bit chars? I guess quite a few other things/algorithms in the class library would break if it is so...
It's fine to be pedantic, but up to a point...
FYI: The JNI specification guarantees that jbyte is an 8-bit signed value.
Etienne
-- Etienne M. Gagnon, Ph.D. http://www.info.uqam.ca/~egagnon/ SableVM: http://www.sablevm.org/ SableCC: http://www.sablecc.org/
#include <jni.h> #include <stdio.h> #include <stdlib.h>
/* * Class: JNITest * Method: getPtr * Signature: ()[B */ JNIEXPORT jbyteArray JNICALL Java_JNITest_getPtr (JNIEnv * env, jclass class) { int *int_ptr; jbyteArray nativePtr; int_ptr = (int *) malloc (sizeof (int));; *int_ptr = 0x47; nativePtr = (*env)->NewByteArray (env, (jint) sizeof (int *)); if (nativePtr == NULL) return NULL; (*env)->SetByteArrayRegion (env, nativePtr, 0, (int) sizeof (int *), (jbyte *) &int_ptr); return nativePtr; } /* * Class: JNITest * Method: testPtr * Signature: ([B)V */ JNIEXPORT void JNICALL Java_JNITest_testPtr (JNIEnv * env, jclass class, jbyteArray nativePtr) { int *int_ptr; (*env)->GetByteArrayRegion (env, nativePtr, 0, (jint) sizeof (int *), (jbyte *) & int_ptr); printf ("value = %x\n", *int_ptr); }
_______________________________________________ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath