classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Classpath build process and VM-specific issues


From: Etienne Gagnon
Subject: Re: Classpath build process and VM-specific issues
Date: Mon, 05 Apr 2004 19:20:26 -0400
User-agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.6) Gecko/20040402 Debian/1.6-4

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);
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]