/[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.3 by archie172, Wed Mar 16 15:14:29 2005 UTC revision 1.4 by glavaux, Fri Apr 8 13:01:42 2005 UTC
# Line 53  static void *NIOGetPointer (JNIEnv *, jo Line 53  static void *NIOGetPointer (JNIEnv *, jo
53  static jobject NIOGetRawData (JNIEnv *, void *pointer);  static jobject NIOGetRawData (JNIEnv *, void *pointer);
54    
55  static void *  static void *
56  NIOGetPointer (JNIEnv *env, jobject rawdata)  NIOGetPointer (JNIEnv * env, jobject rawdata)
57  {  {
58  #if SIZEOF_VOID_P == 4  #if SIZEOF_VOID_P == 4
59    return (void *) (*env)->GetIntField (env, rawdata, fieldNativePointer);    return (void *) (*env)->GetIntField (env, rawdata, fieldNativePointer);
# Line 65  NIOGetPointer (JNIEnv *env, jobject rawd Line 65  NIOGetPointer (JNIEnv *env, jobject rawd
65  }  }
66    
67  static jobject  static jobject
68  NIOGetRawData (JNIEnv *env, void *pointer)  NIOGetRawData (JNIEnv * env, void *pointer)
69  {  {
70  #if SIZEOF_VOID_P == 4  #if SIZEOF_VOID_P == 4
71    return (*env)->NewObject (env, classRawData, methodRawDataInit,    return (*env)->NewObject (env, classRawData, methodRawDataInit,
# Line 79  NIOGetRawData (JNIEnv *env, void *pointe Line 79  NIOGetRawData (JNIEnv *env, void *pointe
79  }  }
80    
81  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
82  Java_java_nio_VMDirectByteBuffer_init    Java_java_nio_VMDirectByteBuffer_init
83    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)))    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)))
84  {  {
85  #if SIZEOF_VOID_P == 4  #if SIZEOF_VOID_P == 4
86    classRawData = (*env)->FindClass (env, "gnu/classpath/RawData32");    classRawData = (*env)->FindClass (env, "gnu/classpath/RawData32");
87    if (classRawData == NULL)    if (classRawData == NULL)
88      {      {
89        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
90                                "unable to find internal class");                            "unable to find internal class");
91        return;        return;
92      }      }
93    
# Line 95  Java_java_nio_VMDirectByteBuffer_init Line 95  Java_java_nio_VMDirectByteBuffer_init
95                                             "<init>", "(I)V");                                             "<init>", "(I)V");
96    if (methodRawDataInit == NULL)    if (methodRawDataInit == NULL)
97      {      {
98        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
99                                "unable to find internal constructor");                            "unable to find internal constructor");
100        return;        return;
101      }      }
102      
103    fieldNativePointer = (*env)->GetFieldID (env, classRawData, "data", "I");    fieldNativePointer = (*env)->GetFieldID (env, classRawData, "data", "I");
104    if (fieldNativePointer == NULL)    if (fieldNativePointer == NULL)
105      {      {
106        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
107                                "unable to find internal field");                            "unable to find internal field");
108        return;        return;
109      }      }
110  #elif SIZEOF_VOID_P == 8  #elif SIZEOF_VOID_P == 8
111    classRawData = (*env)->FindClass (env, "gnu/classpath/RawData64");    classRawData = (*env)->FindClass (env, "gnu/classpath/RawData64");
112    if (classRawData == NULL)    if (classRawData == NULL)
113      {      {
114        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
115                                "unable to find internal class");                            "unable to find internal class");
116        return;        return;
117      }      }
118    
# Line 120  Java_java_nio_VMDirectByteBuffer_init Line 120  Java_java_nio_VMDirectByteBuffer_init
120                                             "<init>", "(J)V");                                             "<init>", "(J)V");
121    if (methodRawDataInit == NULL)    if (methodRawDataInit == NULL)
122      {      {
123        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
124                                "unable to find internal constructor");                            "unable to find internal constructor");
125        return;        return;
126      }      }
127      
128    fieldNativePointer = (*env)->GetFieldID (env, classRawData, "data", "J");    fieldNativePointer = (*env)->GetFieldID (env, classRawData, "data", "J");
129    if (fieldNativePointer == NULL)    if (fieldNativePointer == NULL)
130      {      {
131        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
132                                "unable to find internal field");                            "unable to find internal field");
133        return;        return;
134      }      }
135  #else  #else
# Line 137  Java_java_nio_VMDirectByteBuffer_init Line 137  Java_java_nio_VMDirectByteBuffer_init
137  #endif  #endif
138    
139    /* We need to wrap the jclass in global reference to make it persistent */    /* We need to wrap the jclass in global reference to make it persistent */
140    if ((classRawData = (*env)->NewGlobalRef(env, classRawData)) == NULL)    if ((classRawData = (*env)->NewGlobalRef (env, classRawData)) == NULL)
141      {      {
142        JCL_ThrowException(env, "java/lang/InternalError",        JCL_ThrowException (env, "java/lang/InternalError",
143                                "failed to create global reference");                            "failed to create global reference");
144        return;        return;
145      }      }
146  }  }
147    
148  JNIEXPORT jobject JNICALL  JNIEXPORT jobject JNICALL
149  Java_java_nio_VMDirectByteBuffer_allocate    Java_java_nio_VMDirectByteBuffer_allocate
150    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)), jint capacity)    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jint capacity)
151  {  {
152    void *buffer;    void *buffer;
153      
154    buffer = malloc (capacity);    buffer = malloc (capacity);
155    
156    if (buffer == NULL)    if (buffer == NULL)
# Line 159  Java_java_nio_VMDirectByteBuffer_allocat Line 159  Java_java_nio_VMDirectByteBuffer_allocat
159                            "unable to allocate memory for direct byte buffer");                            "unable to allocate memory for direct byte buffer");
160        return 0;        return 0;
161      }      }
162      
163    return NIOGetRawData (env, buffer);    return NIOGetRawData (env, buffer);
164  }  }
165    
166  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
167  Java_java_nio_VMDirectByteBuffer_free    Java_java_nio_VMDirectByteBuffer_free
168    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)), jobject address)    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jobject address)
169  {  {
170    free (NIOGetPointer (env, address));    free (NIOGetPointer (env, address));
171  }  }
172    
173  JNIEXPORT jbyte JNICALL  JNIEXPORT jbyte JNICALL
174  Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_RawData_2I    Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_RawData_2I
175    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
176     jobject address, jint index)     jobject address, jint index)
177  {  {
178    return ((jbyte *) NIOGetPointer (env, address))[index];    return ((jbyte *) NIOGetPointer (env, address))[index];
179  }  }
180    
181  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
182  Java_java_nio_VMDirectByteBuffer_put    Java_java_nio_VMDirectByteBuffer_put
183    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
184     jobject address, jint index, jbyte value)     jobject address, jint index, jbyte value)
185  {  {
186    jbyte *pointer = (jbyte *) NIOGetPointer (env, address) + index;    jbyte *pointer = (jbyte *) NIOGetPointer (env, address) + index;
# Line 188  Java_java_nio_VMDirectByteBuffer_put Line 188  Java_java_nio_VMDirectByteBuffer_put
188  }  }
189    
190  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
191  Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_RawData_2I_3BII    Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_RawData_2I_3BII
192    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
193     jobject address, jint index, jbyteArray dst, jint dst_offset, jint dst_len)     jobject address, jint index, jbyteArray dst, jint dst_offset, jint dst_len)
194  {  {
195    jbyte *src = (jbyte *) NIOGetPointer (env, address) + index;    jbyte *src = (jbyte *) NIOGetPointer (env, address) + index;
196    memcpy ((*env)->GetByteArrayElements (env, dst, NULL) + dst_offset, src, dst_len);    memcpy ((*env)->GetByteArrayElements (env, dst, NULL) + dst_offset, src,
197              dst_len);
198  }  }
199    
200  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
201  Java_java_nio_VMDirectByteBuffer_shiftDown    Java_java_nio_VMDirectByteBuffer_shiftDown
202    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
203     jobject address, jint dst_offset, jint src_offset, jint count)     jobject address, jint dst_offset, jint src_offset, jint count)
204  {  {
205    jbyte *dst = (jbyte *) NIOGetPointer (env, address) + dst_offset;    jbyte *dst = (jbyte *) NIOGetPointer (env, address) + dst_offset;
# Line 207  Java_java_nio_VMDirectByteBuffer_shiftDo Line 208  Java_java_nio_VMDirectByteBuffer_shiftDo
208  }  }
209    
210  JNIEXPORT jobject JNICALL  JNIEXPORT jobject JNICALL
211  Java_java_nio_VMDirectByteBuffer_adjustAddress    Java_java_nio_VMDirectByteBuffer_adjustAddress
212    (JNIEnv *env, jclass clazz __attribute__ ((__unused__)),    (JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
213     jobject address, jint offset)     jobject address, jint offset)
214  {  {
215    return NIOGetRawData (env, (jbyte *) NIOGetPointer (env, address) + offset);    return NIOGetRawData (env, (jbyte *) NIOGetPointer (env, address) + offset);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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