| 1 | // natObjectInputStream.cc - Native part of ObjectInputStream class.
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
|
|---|
| 4 |
|
|---|
| 5 | This ObjectInputStream is part of libgcj.
|
|---|
| 6 |
|
|---|
| 7 | This software is copyrighted work licensed under the terms of the
|
|---|
| 8 | Libgcj License. Please consult the ObjectInputStream "LIBGCJ_LICENSE" for
|
|---|
| 9 | details. */
|
|---|
| 10 |
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 |
|
|---|
| 13 | #include <gcj/cni.h>
|
|---|
| 14 | #include <jvm.h>
|
|---|
| 15 |
|
|---|
| 16 | #include <java/io/ObjectInputStream$GetField.h>
|
|---|
| 17 | #include <java/io/ObjectInputStream.h>
|
|---|
| 18 | #include <java/io/IOException.h>
|
|---|
| 19 | #include <java/lang/Class.h>
|
|---|
| 20 | #include <java/lang/reflect/Modifier.h>
|
|---|
| 21 | #include <java/lang/reflect/Method.h>
|
|---|
| 22 |
|
|---|
| 23 | #ifdef DEBUG
|
|---|
| 24 | #include <java/lang/System.h>
|
|---|
| 25 | #include <java/io/PrintStream.h>
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | jobject
|
|---|
| 29 | java::io::ObjectInputStream::allocateObject (jclass klass)
|
|---|
| 30 | {
|
|---|
| 31 | jobject obj = NULL;
|
|---|
| 32 | using namespace java::lang::reflect;
|
|---|
| 33 |
|
|---|
| 34 | try
|
|---|
| 35 | {
|
|---|
| 36 | JvAssert (klass && ! klass->isArray ());
|
|---|
| 37 | if (klass->isInterface() || Modifier::isAbstract(klass->getModifiers()))
|
|---|
| 38 | obj = NULL;
|
|---|
| 39 | else
|
|---|
| 40 | {
|
|---|
| 41 | obj = JvAllocObject (klass);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | catch (jthrowable t)
|
|---|
| 45 | {
|
|---|
| 46 | return NULL;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | return obj;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | void
|
|---|
| 54 | java::io::ObjectInputStream::callConstructor (jclass klass, jobject obj)
|
|---|
| 55 | {
|
|---|
| 56 | jstring init_name = JvNewStringLatin1 ("<init>");
|
|---|
| 57 | // This is a bit inefficient, and a bit of a hack, since we don't
|
|---|
| 58 | // actually use the Method and since what is returned isn't
|
|---|
| 59 | // technically a Method. We can't use Method.invoke as it looks up
|
|---|
| 60 | // the declared method.
|
|---|
| 61 | JArray<jclass> *arg_types
|
|---|
| 62 | = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
|
|---|
| 63 | NULL);
|
|---|
| 64 | java::lang::reflect::Method *m = klass->getPrivateMethod (init_name,
|
|---|
| 65 | arg_types);
|
|---|
| 66 | // We lie about this being a constructor. If we put `true' here
|
|---|
| 67 | // then _Jv_CallAnyMethodA would try to allocate the object for us.
|
|---|
| 68 | jmethodID meth = (jmethodID) ((char *) (klass->methods)
|
|---|
| 69 | + m->offset);
|
|---|
| 70 | _Jv_CallAnyMethodA (obj, JvPrimClass (void), meth, false, arg_types, NULL);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | java::lang::reflect::Field *
|
|---|
| 74 | java::io::ObjectInputStream::getField (jclass klass, jstring name)
|
|---|
| 75 | {
|
|---|
| 76 | return klass->getPrivateField (name);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | java::lang::reflect::Method *
|
|---|
| 80 | java::io::ObjectInputStream::getMethod (jclass klass, jstring name,
|
|---|
| 81 | JArray<jclass> *arg_types)
|
|---|
| 82 | {
|
|---|
| 83 | return klass->getPrivateMethod (name, arg_types);
|
|---|
| 84 | }
|
|---|