Andrew Haley wrote:
malloc() returns a char*, not a jbyte*.

So, can you tell me the difference between a jbyte and a "signed char"?


Sigh. No it isn't, and this code will break with gcc.

OK, maybe I am tired and I don't see it. GCC -Wall does not complain about the attached example.

...  Also, "when a pointer to an object is converted
to a pointer to a character type, the result points to the lowest
addressed byte of the object.  Successive increments of the result, up
to the size of the object, yield pointers to the remaining bytes of
the object."


We agree on this.  Now: what's different between "signed char" and "jbyte"?
Can they actually be distinct on some platform?

Etienne

--
Etienne M. Gagnon, Ph.D.             http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITest */

#ifndef _Included_JNITest
#define _Included_JNITest
#ifdef __cplusplus
extern "C"
{
#endif
/*
 * Class:     JNITest
 * Method:    getPtr
 * Signature: ()[B
 */
  JNIEXPORT jbyteArray JNICALL Java_JNITest_getPtr (JNIEnv *, jclass);

/*
 * Class:     JNITest
 * Method:    testPtr
 * Signature: ([B)V
 */
  JNIEXPORT void JNICALL Java_JNITest_testPtr (JNIEnv *, jclass, jbyteArray);

#ifdef __cplusplus
}
#endif
#endif
public class JNITest
{
    static
    {
	System.loadLibrary("test");
    }

    public static void main(String[] args)
    {
	byte[] nativePtr = getPtr();
	testPtr(nativePtr);
    }

    private static native byte[] getPtr();
    private static native void testPtr(byte[] nativPtr);
}
#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 = (int *) malloc (sizeof (int));;
  *int_ptr = 0x47;
 
  jbyteArray nativePtr = (*env)->NewByteArray (env, (jint) sizeof (int *));

  if (nativePtr == NULL)
    return NULL;

  (*env)->SetByteArrayRegion (env, nativePtr, 0, (int) sizeof (int *),
			      (char *) &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

Reply via email to