/[classpath]/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
ViewVC logotype

Diff of /classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by rsdio, Sat Jul 30 20:40:30 2005 UTC revision 1.9 by glavaux, Wed Aug 3 09:05:51 2005 UTC
# Line 45  exception statement from your version. * Line 45  exception statement from your version. *
45    
46  #include "java_nio_VMDirectByteBuffer.h"  #include "java_nio_VMDirectByteBuffer.h"
47    
 static jclass classRawData;  
 static jmethodID methodRawDataInit;  
 static jfieldID fieldNativePointer;  
   
 static void *NIOGetPointer (JNIEnv *, jobject);  
 static jobject NIOGetRawData (JNIEnv *, void *pointer);  
   
 static void *  
 NIOGetPointer (JNIEnv * env, jobject rawdata)  
 {  
 #if SIZEOF_VOID_P == 4  
   return (void *) (*env)->GetIntField (env, rawdata, fieldNativePointer);  
 #elif SIZEOF_VOID_P == 8  
   return (void *) (*env)->GetLongField (env, rawdata, fieldNativePointer);  
 #else  
 #error unsupported pointer size  
 #endif  
 }  
   
 static jobject  
 NIOGetRawData (JNIEnv * env, void *pointer)  
 {  
 #if SIZEOF_VOID_P == 4  
   return (*env)->NewObject (env, classRawData, methodRawDataInit,  
                             (jint) pointer);  
 #elif SIZEOF_VOID_P == 8  
   return (*env)->NewObject (env, classRawData, methodRawDataInit,  
                             (jlong) pointer);  
 #else  
 #error unsupported pointer size  
 #endif  
 }  
   
48  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
49  Java_java_nio_VMDirectByteBuffer_init  Java_java_nio_VMDirectByteBuffer_init
50    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)))    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)))
51  {  {
 #if SIZEOF_VOID_P == 4  
   classRawData = (*env)->FindClass (env, "gnu/classpath/RawData32");  
   if (classRawData == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "unable to find internal class");  
       return;  
     }  
   
   methodRawDataInit = (*env)->GetMethodID (env, classRawData,  
                                            "<init>", "(I)V");  
   if (methodRawDataInit == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "unable to find internal constructor");  
       return;  
     }  
   
   fieldNativePointer = (*env)->GetFieldID (env, classRawData, "data", "I");  
   if (fieldNativePointer == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "unable to find internal field");  
       return;  
     }  
 #elif SIZEOF_VOID_P == 8  
   classRawData = (*env)->FindClass (env, "gnu/classpath/RawData64");  
   if (classRawData == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "unable to find internal class");  
       return;  
     }  
   
   methodRawDataInit = (*env)->GetMethodID (env, classRawData,  
                                            "<init>", "(J)V");  
   if (methodRawDataInit == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "unable to find internal constructor");  
       return;  
     }  
   
   fieldNativePointer = (*env)->GetFieldID (env, classRawData, "data", "J");  
   if (fieldNativePointer == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "unable to find internal field");  
       return;  
     }  
 #else  
 #error unsupported pointer size  
 #endif  
   
   /* We need to wrap the jclass in global reference to make it persistent */  
   if ((classRawData = (*env)->NewGlobalRef (env, classRawData)) == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "failed to create global reference");  
       return;  
     }  
52  }  }
53    
54  JNIEXPORT jobject JNICALL  JNIEXPORT jobject JNICALL
# Line 160  Java_java_nio_VMDirectByteBuffer_allocat Line 66  Java_java_nio_VMDirectByteBuffer_allocat
66        return 0;        return 0;
67      }      }
68    
69    return NIOGetRawData (env, buffer);    return JCL_NewRawDataObject (env, buffer);
70  }  }
71    
72  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
73  Java_java_nio_VMDirectByteBuffer_free  Java_java_nio_VMDirectByteBuffer_free
74    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jobject address)    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jobject address)
75  {  {
76    free (NIOGetPointer (env, address));    free (JCL_GetRawData (env, address));
77  }  }
78    
79  JNIEXPORT jbyte JNICALL  JNIEXPORT jbyte JNICALL
# Line 175  Java_java_nio_VMDirectByteBuffer_get__Lg Line 81  Java_java_nio_VMDirectByteBuffer_get__Lg
81    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
82     jobject address, jint index)     jobject address, jint index)
83  {  {
84    return ((jbyte *) NIOGetPointer (env, address))[index];    return ((jbyte *) JCL_GetRawData (env, address))[index];
85  }  }
86    
87  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
# Line 183  Java_java_nio_VMDirectByteBuffer_put__Lg Line 89  Java_java_nio_VMDirectByteBuffer_put__Lg
89    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
90     jobject address, jint index, jbyte value)     jobject address, jint index, jbyte value)
91  {  {
92    jbyte *pointer = (jbyte *) NIOGetPointer (env, address) + index;    jbyte *pointer = (jbyte *) JCL_GetRawData (env, address) + index;
93    *pointer = value;    *pointer = value;
94  }  }
95    
# Line 192  Java_java_nio_VMDirectByteBuffer_get__Lg Line 98  Java_java_nio_VMDirectByteBuffer_get__Lg
98    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
99     jobject address, jint index, jbyteArray dst, jint dst_offset, jint dst_len)     jobject address, jint index, jbyteArray dst, jint dst_offset, jint dst_len)
100  {  {
101    jbyte *src = (jbyte *) NIOGetPointer (env, address) + index;    jbyte *src = (jbyte *) JCL_GetRawData (env, address) + index;
102    jbyte *_dst = (*env)->GetByteArrayElements (env, dst, NULL) + dst_offset;    jbyte *_dst = (*env)->GetByteArrayElements (env, dst, NULL) + dst_offset;
103    memcpy (_dst, src, dst_len);    memcpy (_dst, src, dst_len);
104    (*env)->ReleaseByteArrayElements (env, dst, _dst, 0);    (*env)->ReleaseByteArrayElements (env, dst, _dst, 0);
# Line 204  Java_java_nio_VMDirectByteBuffer_put__Lg Line 110  Java_java_nio_VMDirectByteBuffer_put__Lg
110     jobject address, jint index, jbyteArray src, jint src_offset, jint src_len)     jobject address, jint index, jbyteArray src, jint src_offset, jint src_len)
111  {  {
112    jbyte *_src = (*env)->GetByteArrayElements (env, src, NULL) + src_offset;    jbyte *_src = (*env)->GetByteArrayElements (env, src, NULL) + src_offset;
113    jbyte *dst = (jbyte *) NIOGetPointer (env, address) + index;    jbyte *dst = (jbyte *)JCL_GetRawData (env, address) + index;
114    (*env)->ReleaseByteArrayElements (env, src, _src, 0);    (*env)->ReleaseByteArrayElements (env, src, _src, 0);
115    memcpy (dst, _src, src_len);    memcpy (dst, _src, src_len);
116  }  }
# Line 214  Java_java_nio_VMDirectByteBuffer_shiftDo Line 120  Java_java_nio_VMDirectByteBuffer_shiftDo
120    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
121     jobject address, jint dst_offset, jint src_offset, jint count)     jobject address, jint dst_offset, jint src_offset, jint count)
122  {  {
123    jbyte *dst = (jbyte *) NIOGetPointer (env, address) + dst_offset;    jbyte *dst = (jbyte *) JCL_GetRawData (env, address) + dst_offset;
124    jbyte *src = (jbyte *) NIOGetPointer (env, address) + src_offset;    jbyte *src = (jbyte *) JCL_GetRawData (env, address) + src_offset;
125    memmove (dst, src, count);    memmove (dst, src, count);
126  }  }
127    
# Line 224  Java_java_nio_VMDirectByteBuffer_adjustA Line 130  Java_java_nio_VMDirectByteBuffer_adjustA
130    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
131     jobject address, jint offset)     jobject address, jint offset)
132  {  {
133    return NIOGetRawData (env, (jbyte *) NIOGetPointer (env, address) + offset);    return JCL_NewRawDataObject (env, (jbyte *) JCL_GetRawData (env, address) + offset);
134  }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26