35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
/* do not move; needed here because of some macro definitions */ |
39 |
|
#include "jamaica_config.h" |
40 |
|
|
41 |
|
#include <stdlib.h> |
42 |
#include <stdio.h> |
#include <stdio.h> |
43 |
#include <jcl.h> |
#include <jcl.h> |
|
#include <malloc.h> |
|
44 |
|
|
45 |
static char errstr[4098]; // this way the memory is pre-allocated, so that we do not have to worry if we are out of memory. |
static char errstr[4098]; // this way the memory is pre-allocated, so that we do not have to worry if we are out of memory. |
46 |
|
|
94 |
} |
} |
95 |
} |
} |
96 |
|
|
97 |
JNIEXPORT char * JNICALL JCL_jstring_to_cstring(JNIEnv * env, jstring s) { |
JNIEXPORT const char * JNICALL JCL_jstring_to_cstring(JNIEnv * env, jstring s) { |
98 |
char* cstr; |
const char* cstr; |
99 |
if(s == NULL) { |
if(s == NULL) { |
100 |
JCL_ThrowException(env, "java/lang/NullPointerException","Null string"); |
JCL_ThrowException(env, "java/lang/NullPointerException","Null string"); |
101 |
return NULL; |
return NULL; |
102 |
} |
} |
103 |
cstr = (char*)(*env)->GetStringUTFChars(env, s, NULL); |
cstr = (const char*)(*env)->GetStringUTFChars(env, s, NULL); |
104 |
if(cstr == NULL) { |
if(cstr == NULL) { |
105 |
JCL_ThrowException(env, "java/lang/InternalError", "GetStringUTFChars() failed."); |
JCL_ThrowException(env, "java/lang/InternalError", "GetStringUTFChars() failed."); |
106 |
return NULL; |
return NULL; |
108 |
return cstr; |
return cstr; |
109 |
} |
} |
110 |
|
|
111 |
JNIEXPORT void JNICALL JCL_free_cstring(JNIEnv * env, jstring s, char * cstr) { |
JNIEXPORT void JNICALL JCL_free_cstring(JNIEnv * env, jstring s, const char * cstr) { |
112 |
(*env)->ReleaseStringUTFChars(env, s, cstr); |
(*env)->ReleaseStringUTFChars(env, s, cstr); |
113 |
} |
} |
114 |
|
|