[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] Patch JCL_realloc()
From: |
Dr. Torsten Rupp |
Subject: |
[cp-patches] Patch JCL_realloc() |
Date: |
Wed, 03 Nov 2004 13:53:00 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 |
2004-11-03 Torsten Rupp address@hidden
* native/jni/classpath/jcl.h, native/jni/classpath/jcl.c,
native/jni/java-io/java_io_VMFile.c:
Inserted native layer macros for OS functions, added parameter for old
memory size to JCL_realloc() to be able to make an malloc() on system
where no realloc() is available.
--- native/jni/classpath/jcl.h.old Wed Nov 3 13:25:44 2004
+++ native/jni/classpath/jcl.h Wed Oct 27 15:28:19 2004
@@ -47,7 +47,7 @@
const char *className,
const char *errMsg);
JNIEXPORT void *JNICALL JCL_malloc (JNIEnv * env, size_t size);
-JNIEXPORT void *JNICALL JCL_realloc (JNIEnv * env, void *ptr, size_t size);
+JNIEXPORT void *JNICALL JCL_realloc (JNIEnv * env, void *ptr, size_t oldSize,
size_t size);
JNIEXPORT void JNICALL JCL_free (JNIEnv * env, void *p);
JNIEXPORT const char *JNICALL JCL_jstring_to_cstring (JNIEnv * env,
jstring s);
--- native/jni/java-io/java_io_VMFile.c.old Wed Nov 3 13:24:41 2004
+++ native/jni/java-io/java_io_VMFile.c Wed Nov 3 13:23:38 2004
@@ -640,6 +640,7 @@
{
tmp_filelist = (char**)JCL_realloc(env,
filelist,
+ max_filelist_count *
sizeof(char*),
(max_filelist_count +
REALLOC_SIZE) * sizeof(char*));
if (tmp_filelist==NULL)
{
--- native/jni/classpath/jcl.c.old Wed Nov 3 13:31:20 2004
+++ native/jni/classpath/jcl.c Wed Nov 3 13:46:58 2004
@@ -40,141 +40,143 @@
#include <stdlib.h>
#include <stdio.h>
-#include <jcl.h>
+
+#include "target_native.h"
+#include "target_native_io.h"
+#include "target_native_memory.h"
+
+#include "jcl.h"
#ifndef __GNUC__
#define __attribute__(x) /* nothing */
#endif
JNIEXPORT void JNICALL
-JCL_ThrowException (JNIEnv * env, const char *className, const char *errMsg)
+JCL_ThrowException(JNIEnv * env, const char * className, const char * errMsg)
{
jclass excClass;
- if ((*env)->ExceptionOccurred (env))
+ if((*env)->ExceptionOccurred(env))
{
- (*env)->ExceptionClear (env);
+ (*env)->ExceptionClear(env);
}
- excClass = (*env)->FindClass (env, className);
- if (excClass == NULL)
+ excClass = (*env)->FindClass(env, className);
+ if(excClass == NULL)
{
jclass errExcClass;
errExcClass =
- (*env)->FindClass (env, "java/lang/ClassNotFoundException");
- if (errExcClass == NULL)
- {
- errExcClass = (*env)->FindClass (env, "java/lang/InternalError");
- if (errExcClass == NULL)
- {
- fprintf (stderr, "JCL: Utterly failed to throw exeption ");
- fprintf (stderr, className);
- fprintf (stderr, " with message ");
- fprintf (stderr, errMsg);
+ (*env)->FindClass(env, "java/lang/ClassNotFoundException");
+ if(errExcClass == NULL)
+ {
+ errExcClass = (*env)->FindClass(env, "java/lang/InternalError");
+ if(errExcClass == NULL)
+ {
+ TARGET_NATIVE_IO_PRINT_ERROR("JCL: Utterly failed to throw
exeption %s with message %s\n",className,errMsg);
return;
- }
- }
- /* Removed this (more comprehensive) error string to avoid the need for
- * a static variable or allocation of a buffer for this message in this
- * (unlikely) error case. --Fridi.
+ }
+ }
+ /* Removed this (more comprehensive) error string to avoid the need for
a
+ * static variable or allocation of a buffer for this message in this
(unlikely)
+ * error case. --Fridi.
*
* sprintf(errstr,"JCL: Failed to throw exception %s with message %s:
could not find exception class.", className, errMsg);
*/
- (*env)->ThrowNew (env, errExcClass, className);
+ (*env)->ThrowNew(env, errExcClass, className);
}
- (*env)->ThrowNew (env, excClass, errMsg);
+ (*env)->ThrowNew(env, excClass, errMsg);
}
JNIEXPORT void *JNICALL
-JCL_malloc (JNIEnv * env, size_t size)
+JCL_malloc(JNIEnv * env, size_t size)
{
- void *mem = malloc (size);
- if (mem == NULL)
- {
- JCL_ThrowException (env, "java/lang/OutOfMemoryError",
- "malloc() failed.");
- return NULL;
- }
+ void *mem;
+ TARGET_NATIVE_MEMORY_ALLOC(mem,void*,size);
+ if(mem == NULL) {
+ JCL_ThrowException(env, "java/lang/OutOfMemoryError",
+ "malloc() failed.");
+ return NULL;
+ }
return mem;
}
JNIEXPORT void *JNICALL
-JCL_realloc (JNIEnv * env, void *ptr, size_t size)
+JCL_realloc(JNIEnv *env, void *ptr, size_t oldSize, size_t newSize)
{
- ptr = realloc (ptr, size);
- if (ptr == 0)
+ TARGET_NATIVE_MEMORY_REALLOC(ptr,void*,oldSize,newSize);
+ if (ptr == NULL)
{
- JCL_ThrowException (env, "java/lang/OutOfMemoryError",
- "malloc() failed.");
+ JCL_ThrowException(env,"java/lang/OutOfMemoryError",
+ "malloc() failed.");
return NULL;
}
- return (ptr);
+ return(ptr);
}
JNIEXPORT void JNICALL
-JCL_free (JNIEnv * env __attribute__ ((unused)), void *p)
+JCL_free(JNIEnv * env __attribute__ ((unused)), void * p)
{
- if (p != NULL)
+ if(p != NULL)
{
- free (p);
+ TARGET_NATIVE_MEMORY_FREE(p);
}
}
JNIEXPORT const char *JNICALL
-JCL_jstring_to_cstring (JNIEnv * env, jstring s)
+JCL_jstring_to_cstring(JNIEnv * env, jstring s)
{
- const char *cstr;
- if (s == NULL)
+ const char* cstr;
+ if(s == NULL)
{
JCL_ThrowException (env, "java/lang/NullPointerException",
- "Null string");
+ "Null string");
return NULL;
}
- cstr = (const char *) (*env)->GetStringUTFChars (env, s, NULL);
- if (cstr == NULL)
+ cstr = (const char*)(*env)->GetStringUTFChars(env, s, NULL);
+ if(cstr == NULL)
{
JCL_ThrowException (env, "java/lang/InternalError",
- "GetStringUTFChars() failed.");
+ "GetStringUTFChars() failed.");
return NULL;
}
return cstr;
}
JNIEXPORT void JNICALL
-JCL_free_cstring (JNIEnv * env, jstring s, const char *cstr)
+JCL_free_cstring(JNIEnv * env, jstring s, const char * cstr)
{
- (*env)->ReleaseStringUTFChars (env, s, cstr);
+ (*env)->ReleaseStringUTFChars(env, s, cstr);
}
JNIEXPORT jint JNICALL
-JCL_MonitorEnter (JNIEnv * env, jobject o)
+JCL_MonitorEnter(JNIEnv * env, jobject o)
{
- jint retval = (*env)->MonitorEnter (env, o);
- if (retval != 0)
+ jint retval = (*env)->MonitorEnter(env,o);
+ if(retval != 0)
{
JCL_ThrowException (env, "java/lang/InternalError",
- "MonitorEnter() failed.");
+ "MonitorEnter() failed.");
}
return retval;
}
JNIEXPORT jint JNICALL
-JCL_MonitorExit (JNIEnv * env, jobject o)
+JCL_MonitorExit(JNIEnv * env, jobject o)
{
- jint retval = (*env)->MonitorExit (env, o);
- if (retval != 0)
+ jint retval = (*env)->MonitorExit(env,o);
+ if(retval != 0)
{
JCL_ThrowException (env, "java/lang/InternalError",
- "MonitorExit() failed.");
+ "MonitorExit() failed.");
}
return retval;
}
JNIEXPORT jclass JNICALL
-JCL_FindClass (JNIEnv * env, const char *className)
+JCL_FindClass(JNIEnv * env, const char * className)
{
- jclass retval = (*env)->FindClass (env, className);
- if (retval == NULL)
+ jclass retval = (*env)->FindClass(env,className);
+ if(retval == NULL)
{
- JCL_ThrowException (env, "java/lang/ClassNotFoundException", className);
+ JCL_ThrowException(env, "java/lang/ClassNotFoundException", className);
}
return retval;
}
- [cp-patches] Patch JCL_realloc(),
Dr. Torsten Rupp <=