[kaffe] CVS kaffe (guilhem): Imported GNU Classpath version of the JNI implementation of serialization.

Kaffe CVS cvs-commits at kaffe.org
Fri Dec 3 13:59:04 PST 2004


PatchSet 5528 
Date: 2004/12/03 21:54:02
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Imported GNU Classpath version of the JNI implementation of serialization.

        * libraries/javalib/java/io/ObjectInputStream.java
        (newObject): Check for the existence of the constructor and whether
        it is private explicitly.

        * libraries/clib/io/ObjectInputStream.c: Removed.

        * libraries/clib/io/java_io_ObjectInputStream.c,
        libraries/clib/io/java_io_VMObjectStreamClass.c:
        Imported from GNU Classpath.

        * libraries/clib/io/Makefile.am: Removed ObjectInputStream.c
        and added java_io_ObjectInputStream.c and
        java_io_VMObjectStreamClass.c.

        * libraries/clib/io/Makefile.in: Regenerated.

Members: 
	ChangeLog:1.3074->1.3075 
	libraries/clib/io/Makefile.am:1.15->1.16 
	libraries/clib/io/Makefile.in:1.125->1.126 
	libraries/clib/io/ObjectInputStream.c:1.6->1.7(DEAD) 
	libraries/clib/io/java_io_ObjectInputStream.c:INITIAL->1.1 
	libraries/clib/io/java_io_VMObjectStreamClass.c:INITIAL->1.1 
	libraries/javalib/java/io/ObjectInputStream.java:1.43->1.44 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3074 kaffe/ChangeLog:1.3075
--- kaffe/ChangeLog:1.3074	Fri Dec  3 21:28:37 2004
+++ kaffe/ChangeLog	Fri Dec  3 21:54:02 2004
@@ -1,3 +1,21 @@
+2004-12-03  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* libraries/javalib/java/io/ObjectInputStream.java
+	(newObject): Check for the existence of the constructor and whether
+	it is private explicitly.
+
+	* libraries/clib/io/ObjectInputStream.c: Removed.
+
+	* libraries/clib/io/java_io_ObjectInputStream.c, 
+	libraries/clib/io/java_io_VMObjectStreamClass.c: 
+	Imported from GNU Classpath.
+
+	* libraries/clib/io/Makefile.am: Removed ObjectInputStream.c
+	and added java_io_ObjectInputStream.c and
+	java_io_VMObjectStreamClass.c.
+
+	* libraries/clib/io/Makefile.in: Regenerated.
+
 2004-12-03  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/javax/swing/JLayeredPane.java:
Index: kaffe/libraries/clib/io/Makefile.am
diff -u kaffe/libraries/clib/io/Makefile.am:1.15 kaffe/libraries/clib/io/Makefile.am:1.16
--- kaffe/libraries/clib/io/Makefile.am:1.15	Fri Jul 30 11:06:42 2004
+++ kaffe/libraries/clib/io/Makefile.am	Fri Dec  3 21:54:04 2004
@@ -8,7 +8,8 @@
 
 AM_CPPFLAGS = \
 	-I$(top_builddir)/include \
-	-I$(top_srcdir)/kaffe/kaffevm/jni
+	-I$(top_srcdir)/kaffe/kaffevm/jni \
+	-I$(top_srcdir)/libraries/clib/classpath
 
 native_LTLIBRARIES = libio.la
 
@@ -23,6 +24,7 @@
 
 libio_la_SOURCES = \
 	File.c \
-	ObjectInputStream.c
+	java_io_ObjectInputStream.c \
+	java_io_VMObjectStreamClass.c
 
 CLEANFILES = so_locations
Index: kaffe/libraries/clib/io/Makefile.in
diff -u kaffe/libraries/clib/io/Makefile.in:1.125 kaffe/libraries/clib/io/Makefile.in:1.126
--- kaffe/libraries/clib/io/Makefile.in:1.125	Mon Nov 22 17:23:58 2004
+++ kaffe/libraries/clib/io/Makefile.in	Fri Dec  3 21:54:04 2004
@@ -83,7 +83,9 @@
 nativeLTLIBRARIES_INSTALL = $(INSTALL)
 LTLIBRARIES = $(native_LTLIBRARIES)
 libio_la_LIBADD =
-am_libio_la_OBJECTS = libio_la-File.lo libio_la-ObjectInputStream.lo
+am_libio_la_OBJECTS = libio_la-File.lo \
+	libio_la-java_io_ObjectInputStream.lo \
+	libio_la-java_io_VMObjectStreamClass.lo
 libio_la_OBJECTS = $(am_libio_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config -I$(top_builddir)/include/kaffe
 depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp
@@ -368,7 +370,8 @@
 with_engine = @with_engine@
 AM_CPPFLAGS = \
 	-I$(top_builddir)/include \
-	-I$(top_srcdir)/kaffe/kaffevm/jni
+	-I$(top_srcdir)/kaffe/kaffevm/jni \
+	-I$(top_srcdir)/libraries/clib/classpath
 
 native_LTLIBRARIES = libio.la
 libio_la_CFLAGS = \
@@ -382,7 +385,8 @@
 
 libio_la_SOURCES = \
 	File.c \
-	ObjectInputStream.c
+	java_io_ObjectInputStream.c \
+	java_io_VMObjectStreamClass.c
 
 CLEANFILES = so_locations
 all: all-am
@@ -455,7 +459,8 @@
 	-rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libio_la-File.Plo at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libio_la-ObjectInputStream.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libio_la-java_io_ObjectInputStream.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libio_la-java_io_VMObjectStreamClass.Plo at am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@@ -485,12 +490,19 @@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -c -o libio_la-File.lo `test -f 'File.c' || echo '$(srcdir)/'`File.c
 
-libio_la-ObjectInputStream.lo: ObjectInputStream.c
- at am__fastdepCC_TRUE@	if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -MT libio_la-ObjectInputStream.lo -MD -MP -MF "$(DEPDIR)/libio_la-ObjectInputStream.Tpo" -c -o libio_la-ObjectInputStream.lo `test -f 'ObjectInputStream.c' || echo '$(srcdir)/'`ObjectInputStream.c; \
- at am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libio_la-ObjectInputStream.Tpo" "$(DEPDIR)/libio_la-ObjectInputStream.Plo"; else rm -f "$(DEPDIR)/libio_la-ObjectInputStream.Tpo"; exit 1; fi
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='ObjectInputStream.c' object='libio_la-ObjectInputStream.lo' libtool=yes @AMDEPBACKSLASH@
+libio_la-java_io_ObjectInputStream.lo: java_io_ObjectInputStream.c
+ at am__fastdepCC_TRUE@	if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -MT libio_la-java_io_ObjectInputStream.lo -MD -MP -MF "$(DEPDIR)/libio_la-java_io_ObjectInputStream.Tpo" -c -o libio_la-java_io_ObjectInputStream.lo `test -f 'java_io_ObjectInputStream.c' || echo '$(srcdir)/'`java_io_ObjectInputStream.c; \
+ at am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libio_la-java_io_ObjectInputStream.Tpo" "$(DEPDIR)/libio_la-java_io_ObjectInputStream.Plo"; else rm -f "$(DEPDIR)/libio_la-java_io_ObjectInputStream.Tpo"; exit 1; fi
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='java_io_ObjectInputStream.c' object='libio_la-java_io_ObjectInputStream.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -c -o libio_la-ObjectInputStream.lo `test -f 'ObjectInputStream.c' || echo '$(srcdir)/'`ObjectInputStream.c
+ at am__fastdepCC_FALSE@	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -c -o libio_la-java_io_ObjectInputStream.lo `test -f 'java_io_ObjectInputStream.c' || echo '$(srcdir)/'`java_io_ObjectInputStream.c
+
+libio_la-java_io_VMObjectStreamClass.lo: java_io_VMObjectStreamClass.c
+ at am__fastdepCC_TRUE@	if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -MT libio_la-java_io_VMObjectStreamClass.lo -MD -MP -MF "$(DEPDIR)/libio_la-java_io_VMObjectStreamClass.Tpo" -c -o libio_la-java_io_VMObjectStreamClass.lo `test -f 'java_io_VMObjectStreamClass.c' || echo '$(srcdir)/'`java_io_VMObjectStreamClass.c; \
+ at am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libio_la-java_io_VMObjectStreamClass.Tpo" "$(DEPDIR)/libio_la-java_io_VMObjectStreamClass.Plo"; else rm -f "$(DEPDIR)/libio_la-java_io_VMObjectStreamClass.Tpo"; exit 1; fi
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='java_io_VMObjectStreamClass.c' object='libio_la-java_io_VMObjectStreamClass.lo' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libio_la_CFLAGS) $(CFLAGS) -c -o libio_la-java_io_VMObjectStreamClass.lo `test -f 'java_io_VMObjectStreamClass.c' || echo '$(srcdir)/'`java_io_VMObjectStreamClass.c
 
 mostlyclean-libtool:
 	-rm -f *.lo
===================================================================
Checking out kaffe/libraries/clib/io/ObjectInputStream.c
RCS:  /home/cvs/kaffe/kaffe/libraries/clib/io/Attic/ObjectInputStream.c,v
VERS: 1.6
***************
--- kaffe/libraries/clib/io/ObjectInputStream.c	Fri Dec  3 21:59:04 2004
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,166 +0,0 @@
-/*
- * ObjectInputStream.c
- * 
- * Copyright (C) 2003, 2004 Kaffe.org's team. 
- *
- * See "licence.terms" for information on usage and redistribution 
- * of this file.
- */
-#include "config.h"
-#include "config-std.h"
-#include <kaffe/jni_md.h>
-#include <native.h>
-#include "object.h"
-#include "classMethod.h"
-#include "exception.h"
-#include "lookup.h"
-#include "soft.h"
-#include "support.h"
-#include "java_lang_SecurityManager.h"
-#include "java_io_ObjectInputStream.h"
-#include "java_lang_reflect_Field.h"
-#include "java_io_VMObjectStreamClass.h"
-
-
-struct Hjava_lang_ClassLoader*
-java_io_ObjectInputStream_currentClassLoader(
-		struct Hjava_lang_SecurityManager* mgr)
-{
-	return (struct Hjava_lang_ClassLoader *)
-		do_execute_java_method(mgr, "currentClassLoader",
-				"()Ljava/lang/ClassLoader;", 0, 0).l;
-}
-
-struct Hjava_lang_Object*
-java_io_ObjectInputStream_allocateObject(
-		struct Hjava_io_ObjectInputStream* this UNUSED,
-		struct Hjava_lang_Class* clazz)
-{
-	if (CLASS_IS_INTERFACE(clazz) || CLASS_IS_ABSTRACT(clazz))
-		throwException(InstantiationException(clazz->name->data));
-
-	return newObject(clazz);
-}
-
-void
-java_io_ObjectInputStream_callConstructor(
-		struct Hjava_io_ObjectInputStream* this UNUSED,
-		struct Hjava_lang_Class* clazz,
-		struct Hjava_lang_Object* object)
-{
-	Method* meth;
-
-	/* Taken from the ObjectStreamClassImpl.c */
-	meth = findMethodLocal(clazz, constructor_name, void_signature);
-	if (meth == 0) {
-		SignalErrorf("java.io.InvalidClassException",
-			     "%s; Missing no-arg constructor for class",
-			     CLASS_CNAME(clazz));
-	}
-	else if ((meth->accflags & (ACC_CONSTRUCTOR|ACC_PRIVATE)) != ACC_CONSTRUCTOR) {
-		SignalErrorf("java.io.InvalidClassException",
-			     "%s; IllegalAccessException",
-			     CLASS_CNAME(clazz));
-	}
-	else {
-		do_execute_java_method(object, 0, 0, meth, 0);
-	}
-}
-
-
-jboolean
-java_io_VMObjectStreamClass_hasClassInitializer(struct Hjava_lang_Class* clazz)
-{
-	Method* meth;
-
-	/* I prefer to remain prudent */
-	if (clazz == NULL)
-	{
-		soft_nullpointer();
-	}
-
-	meth = findMethodLocal(clazz, init_name, void_signature);
-	return (meth != NULL);		
-}
-
-static void*
-getFieldAddress (struct Hjava_lang_reflect_Field* sfield, struct Hjava_lang_Object *obj)
-{
-	if (unhand(sfield)->slot < CLASS_NSFIELDS(OBJECT_CLASS(sfield->clazz))) {
-		SignalError ("java.lang.IllegalArgumentException", "");
-	}
-
-	return (void *)((uintp)obj + FIELD_BOFFSET(CLASS_FIELDS(sfield->clazz) + unhand(sfield)->slot));
-}
-
-void java_io_VMObjectStreamClass_setBooleanNative
-                (struct Hjava_lang_reflect_Field* sfield,
-		 struct Hjava_lang_Object* obj,
-		 jboolean value)
-{
-	*(jboolean *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setByteNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jbyte value)
-{
-	*(jbyte *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setCharNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jchar value)
-{
-	*(jchar *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setShortNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jshort value)
-{
-	*(jshort *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setIntNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jint value)
-{
-	*(jint *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setLongNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jlong value)
-{
-	*(jlong *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setFloatNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jfloat value)
-{
-	*(jfloat *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setDoubleNative
-                (struct Hjava_lang_reflect_Field* sfield, 
-		 struct Hjava_lang_Object* obj,
-		 jdouble value)
-{
-	*(jdouble *)getFieldAddress (sfield, obj) = value;
-}
-
-void java_io_VMObjectStreamClass_setObjectNative
-                (struct Hjava_lang_reflect_Field* sfield,
-		 struct Hjava_lang_Object* obj, 
-		 struct Hjava_lang_Object* value)
-{
-	*(struct Hjava_lang_Object **)getFieldAddress (sfield, obj) = value;
-}
===================================================================
Checking out kaffe/libraries/clib/io/java_io_ObjectInputStream.c
RCS:  /home/cvs/kaffe/kaffe/libraries/clib/io/java_io_ObjectInputStream.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/clib/io/java_io_ObjectInputStream.c	Fri Dec  3 21:59:04 2004
@@ -0,0 +1,105 @@
+/* java_io_ObjectInputStream.c -- Native methods for ObjectInputStream class
+   Copyright (C) 1998, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+/*  TODO: check exceptions */
+/*        comments */
+
+/* do not move; needed here because of some macro definitions */
+#include <config.h>
+
+#include <jni.h>
+#include <jcl.h>
+
+#include "java_io_ObjectInputStream.h"
+
+/*
+ * Class:     java_io_ObjectInputStream
+ * Method:    currentClassLoader
+ * Signature: (Ljava/lang/SecurityManager;)Ljava/lang/ClassLoader;
+ */
+JNIEXPORT jobject JNICALL
+Java_java_io_ObjectInputStream_currentClassLoader( JNIEnv * env,
+						   jclass clazz,
+						   jobject loader )
+{
+  jmethodID id = (*env)->GetMethodID( env,
+				      (*env)->GetObjectClass( env, loader ),
+				      "currentClassLoader",
+				      "()Ljava/lang/ClassLoader;" );
+  
+  if( id == NULL )
+    return NULL;
+  
+  return (*env)->CallObjectMethod( env, loader, id, clazz );
+}
+
+
+/*
+ * Class:     java_io_ObjectInputStream
+ * Method:    allocateObject
+ * Signature: (Ljava/lang/Class;)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL
+Java_java_io_ObjectInputStream_allocateObject( JNIEnv * env,
+					       jobject self
+					       __attribute__ ((__unused__)),
+					       jclass clazz )
+{
+  return (*env)->AllocObject( env, clazz );
+}
+
+
+/*
+ * Class:     java_io_ObjectInputStream
+ * Method:    callConstructor
+ * Signature: (Ljava/lang/Class;Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL 
+Java_java_io_ObjectInputStream_callConstructor( JNIEnv * env,
+						jclass clazz
+						__attribute__ ((__unused__)),
+						jclass constr_class,
+						jobject obj )
+{
+  jmethodID id = (*env)->GetMethodID( env, constr_class,
+				      "<init>", "()V" );
+  if( id == NULL )
+    return;
+  
+  (*env)->CallNonvirtualVoidMethod( env, obj, constr_class, id);
+}
===================================================================
Checking out kaffe/libraries/clib/io/java_io_VMObjectStreamClass.c
RCS:  /home/cvs/kaffe/kaffe/libraries/clib/io/java_io_VMObjectStreamClass.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/clib/io/java_io_VMObjectStreamClass.c	Fri Dec  3 21:59:04 2004
@@ -0,0 +1,399 @@
+/* java_io_VMObjectStreamClass.c -- Native methods for VMObjectStreamClass.java
+   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+#include <jni.h>
+#include <jcl.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "java_io_VMObjectStreamClass.h"
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    hasClassInitializer
+ * Signature: (Ljava/lang/Class;)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMObjectStreamClass_hasClassInitializer(JNIEnv * env,
+						 jclass vmosklass
+						 __attribute__ ((__unused__)),
+						 jclass klass )
+{
+  jmethodID mid = (*env)->GetStaticMethodID(env, klass, "<clinit>", "()V");
+  if (mid == NULL)
+    {
+      (*env)->ExceptionClear(env);
+      return JNI_FALSE;
+    }
+  return JNI_TRUE;
+}
+
+static void throwInternalError(JNIEnv *env)
+{
+  jclass internalErrorClass;
+  jthrowable previousException, newException;
+  jmethodID initException, getMessageID, initCauseID;
+  jstring message;
+
+  internalErrorClass = (*env)->FindClass(env, "java/lang/InternalError");
+  /** Just give up if this also fails. */
+  if (internalErrorClass == NULL)
+    return;
+
+  previousException = (*env)->ExceptionOccurred(env);
+
+  if (previousException == NULL)
+    {
+      (*env)->ThrowNew(env, internalErrorClass, "Unknown error raised by the VM");
+      return;
+    }
+  
+  initException = (*env)->GetMethodID
+    (env, internalErrorClass, "<init>", "(Ljava/lang/String;)V");
+  getMessageID = (*env)->GetMethodID
+    (env, (*env)->GetObjectClass(env, previousException),
+     "getMessage", "()Ljava/lang/String;");
+  initCauseID = (*env)->GetMethodID
+    (env, internalErrorClass, "initCause", "(Ljava/lang/Throwable;)V");
+
+  message = (*env)->CallObjectMethod(env, previousException,
+				     getMessageID);
+
+  newException = (*env)->NewObject(env, internalErrorClass, initException,
+				   message);
+  (*env)->CallVoidMethod(env, newException, initCauseID,
+			 previousException);
+
+  (*env)->ExceptionClear(env);
+  (*env)->Throw(env, newException);
+}
+
+static jfieldID getFieldReference(JNIEnv *env, jobject field, 
+				  const char *type)
+{
+  jclass classClass;
+  jclass fieldClass;
+  jclass declaringClass;
+  jclass typeClass;
+  jfieldID fid;
+  const char *field_name;
+  const char *type_name;
+  int type_len;
+  jmethodID mid;
+  jstring name;
+  jstring tname;
+  int i;
+
+  fieldClass = (*env)->GetObjectClass(env, field);
+
+  mid = (*env)->GetMethodID(env, fieldClass, "getName", "()Ljava/lang/String;");
+  if (mid == NULL || (*env)->ExceptionOccurred(env) != NULL)
+    {
+      throwInternalError(env);
+      return NULL;
+    }
+
+  name = (*env)->CallObjectMethod(env, field, mid);
+  field_name = (*env)->GetStringUTFChars(env, name, NULL);
+ 
+  mid = (*env)->GetMethodID(env, fieldClass,
+			    "getDeclaringClass",
+			    "()Ljava/lang/Class;");
+  if (mid == NULL || (*env)->ExceptionOccurred(env) != NULL)
+    {
+      throwInternalError(env);
+      return NULL;
+    }
+
+  declaringClass = (*env)->CallObjectMethod(env, field, mid);
+
+  /* Do we need to find out the exact type descriptor of the field? */
+  if (type == NULL)
+    {
+      char *the_type;
+
+      mid = (*env)->GetMethodID(env, fieldClass,
+				"getType",
+				"()Ljava/lang/Class;");
+
+      if (mid == NULL || (*env)->ExceptionOccurred(env) != NULL)
+	{
+	  throwInternalError(env);
+	  return NULL;
+	}
+
+      typeClass = (*env)->CallObjectMethod(env, field, mid);
+      classClass = (*env)->FindClass(env, "java/lang/Class");
+
+      mid = (*env)->GetMethodID(env, classClass,
+				"getName",
+				"()Ljava/lang/String;");
+
+      if (mid == NULL || (*env)->ExceptionOccurred(env) != NULL)
+	{
+	  throwInternalError(env);
+	  return NULL;
+	}
+
+      tname = (*env)->CallObjectMethod(env, typeClass, mid);
+      type_name = (*env)->GetStringUTFChars(env, tname, NULL);
+
+      /*
+       * If it isn't an array class then the actual field type descriptor
+       * starts with 'L', ends with ';' and has '/' instead of '.'.
+       */
+      type_len = strlen((char *) type_name);
+      if (type_name[0] != '[')
+        {
+	  /* XXX - FIXME - should not use dynamic allocation in core lib. */
+	  the_type = (char *) malloc(type_len + 3);
+	  the_type[0] = 'L';
+	  the_type[type_len + 1] = ';';
+	  the_type[type_len + 2] = '\0';
+	  the_type++;
+	}
+      else
+	{
+	  /* XXX - FIXME - should not use dynamic allocation in core lib. */
+	  the_type = (char *) malloc(type_len + 1);
+	  the_type[type_len] = '\0';
+	}
+
+      for (i = 0; i < type_len; i++)
+	if (type_name[i] == '.')
+	  the_type[i] = '/';
+        else
+	  the_type[i] = type_name[i];
+
+      if (type_name[0] != '[')
+	the_type--;
+
+      (*env)->ReleaseStringUTFChars(env, tname, type_name);
+      fid = (*env)->GetFieldID(env, declaringClass, field_name, the_type);
+      free(the_type);
+    }
+  else
+    {
+      type_len = -1;
+      fid = (*env)->GetFieldID(env, declaringClass, field_name, type);
+    }
+
+  if (fid == NULL)
+    {
+      throwInternalError(env);
+      return NULL;
+    }
+  (*env)->ReleaseStringUTFChars(env, name, field_name);
+
+  return fid;
+}
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setBooleanNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setBooleanNative(JNIEnv * env,
+						  jclass vmosklass
+						  __attribute__ ((__unused__)),
+						  jobject field,
+						  jobject object,
+						  jboolean value )
+{
+  jfieldID fid = getFieldReference (env, field, "Z");
+
+  if (fid != NULL)
+    (*env)->SetBooleanField(env, object, fid, value);
+}
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setCharNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;C)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setCharNative(JNIEnv * env,
+					       jclass vmosklass
+					       __attribute__ ((__unused__)),
+					       jobject field,
+					       jobject object,
+					       jchar value )
+{
+  jfieldID fid = getFieldReference (env, field, "C");
+
+  if (fid != NULL)
+    (*env)->SetCharField(env, object, fid, value);
+}
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setByteNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;B)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setByteNative(JNIEnv * env,
+					       jclass vmosklass
+					       __attribute__ ((__unused__)),
+					       jobject field,
+					       jobject object,
+					       jbyte value )
+{
+  jfieldID fid = getFieldReference (env, field, "B");
+
+  if (fid != NULL)
+    (*env)->SetByteField(env, object, fid, value);
+}
+
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setShortNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;S)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setShortNative(JNIEnv * env,
+						jclass vmosklass
+						__attribute__ ((__unused__)),
+						jobject field,
+						jobject object,
+						jshort value )
+{
+  jfieldID fid = getFieldReference (env, field, "S");
+
+  if (fid != NULL)
+    (*env)->SetShortField(env, object, fid, value);
+}
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setIntNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;I)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setIntNative(JNIEnv * env,
+					      jclass vmosklass
+					      __attribute__ ((__unused__)),
+					      jobject field,
+					      jobject object,
+					      jint value )
+{
+  jfieldID fid = getFieldReference (env, field, "I");
+
+  if (fid != NULL)
+    (*env)->SetIntField(env, object, fid, value);
+}
+
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setLongNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;J)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setLongNative(JNIEnv * env,
+					       jclass vmosklass
+					       __attribute__ ((__unused__)),
+					       jobject field,
+					       jobject object,
+					       jlong value )
+{
+  jfieldID fid = getFieldReference (env, field, "J");
+
+  if (fid != NULL)
+    (*env)->SetLongField(env, object, fid, value);
+}
+
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setFloatNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;F)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setFloatNative(JNIEnv * env,
+						jclass vmosklass
+						__attribute__ ((__unused__)),
+						jobject field,
+						jobject object,
+						jfloat value )
+{
+  jfieldID fid = getFieldReference (env, field, "F");
+
+  if (fid != NULL)
+    (*env)->SetFloatField(env, object, fid, value);
+}
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setDoubleNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;D)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setDoubleNative(JNIEnv * env,
+						 jclass vmosklass
+						 __attribute__ ((__unused__)),
+						 jobject field,
+						 jobject object,
+						 jdouble value )
+{
+  jfieldID fid = getFieldReference (env, field, "D");
+
+  if (fid != NULL)
+    (*env)->SetDoubleField(env, object, fid, value);
+}
+
+/*
+ * Class:     java_io_VMObjectOutputStream
+ * Method:    setObjectNative
+ * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_io_VMObjectStreamClass_setObjectNative(JNIEnv * env,
+						 jclass vmosklass
+						 __attribute__ ((__unused__)),
+						 jobject field,
+						 jobject object,
+						 jobject value )
+{
+  jfieldID fid = getFieldReference (env, field, NULL);
+
+  if (fid != NULL)
+    (*env)->SetObjectField(env, object, fid, value);
+}
Index: kaffe/libraries/javalib/java/io/ObjectInputStream.java
diff -u kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.43 kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.44
--- kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.43	Sun Nov  7 20:24:34 2004
+++ kaffe/libraries/javalib/java/io/ObjectInputStream.java	Fri Dec  3 21:54:04 2004
@@ -41,12 +41,15 @@
 import gnu.classpath.Configuration;
 import gnu.java.io.ObjectIdentityWrapper;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.Hashtable;
 import java.util.Vector;
@@ -1754,11 +1757,35 @@
   // returns a new instance of REAL_CLASS that has been constructed
   // only to the level of CONSTRUCTOR_CLASS (a super class of REAL_CLASS)
   private Object newObject (Class real_class, Class constructor_class)
-    throws ClassNotFoundException
+    throws ClassNotFoundException, IOException
   {
     try
       {
 	Object obj = allocateObject (real_class);
+	final Class local_constructor_class = constructor_class;
+	Constructor void_constructor = (Constructor)
+	  AccessController.doPrivileged(new PrivilegedAction()
+	    {
+	      public Object run()
+	      {
+		try
+		  {
+		    return local_constructor_class.getDeclaredConstructor(new Class[0]);
+	          }
+	        catch (NoSuchMethodException e)
+	          {
+	            return null;
+		  }
+	      }
+            });
+
+	if (void_constructor == null)
+          throw new InvalidClassException(constructor_class.getName() + "; Missing no-arg constructor for class"); 
+	  
+	if (Modifier.isPrivate(void_constructor.getModifiers()))
+	  throw new InvalidClassException(constructor_class.getName() + 
+	  			          "; IllegalAccessException");
+	  
 	callConstructor (constructor_class, obj);
 	return obj;
       }




More information about the kaffe mailing list