natObjectInputStream.cc 2.09 KB
Newer Older
Tom Tromey committed
1 2
// natObjectInputStream.cc - Native part of ObjectInputStream class.

Tom Tromey committed
3
/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
Tom Tromey committed
4 5 6 7 8 9 10 11 12 13 14

   This ObjectInputStream is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the ObjectInputStream "LIBGCJ_LICENSE" for
details.  */

#include <config.h>

#include <gcj/cni.h>
#include <jvm.h>
Bryce McKinlay committed
15
#include <gcj/method.h>
Tom Tromey committed
16 17 18 19 20 21 22

#include <java/io/ObjectInputStream$GetField.h>
#include <java/io/ObjectInputStream.h>
#include <java/io/IOException.h>
#include <java/lang/Class.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/reflect/Method.h>
23 24
#include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/SecurityManager.h>
Bryce McKinlay committed
25 26
#include <java/lang/reflect/Constructor.h>
#include <java/lang/reflect/Method.h>
Tom Tromey committed
27

28 29 30 31 32
#ifdef DEBUG
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#endif

Tom Tromey committed
33
jobject
Bryce McKinlay committed
34 35
java::io::ObjectInputStream::allocateObject (jclass klass, jclass,
  ::java::lang::reflect::Constructor *ctr)
Tom Tromey committed
36 37 38 39 40 41 42 43 44 45 46
{
  jobject obj = NULL;
  using namespace java::lang::reflect;

  try
    {
      JvAssert (klass && ! klass->isArray ());
      if (klass->isInterface() || Modifier::isAbstract(klass->getModifiers()))
	obj = NULL;	
      else
	{
47
	  obj = _Jv_AllocObject (klass);
Bryce McKinlay committed
48
	}	
Tom Tromey committed
49 50 51 52 53 54
    }
  catch (jthrowable t)
    {
      return NULL;
    }

Bryce McKinlay committed
55
  jmethodID meth = _Jv_FromReflectedConstructor (ctr);
Tom Tromey committed
56

Tom Tromey committed
57 58 59 60
  // This is a bit inefficient, and a bit of a hack, since we don't
  // actually use the Method and since what is returned isn't
  // technically a Method.  We can't use Method.invoke as it looks up
  // the declared method.
Tom Tromey committed
61
  JArray<jclass> *arg_types
Tom Tromey committed
62 63
    = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
					   NULL);
Bryce McKinlay committed
64

Tom Tromey committed
65 66 67
  // We lie about this being a constructor.  If we put `true' here
  // then _Jv_CallAnyMethodA would try to allocate the object for us.
  _Jv_CallAnyMethodA (obj, JvPrimClass (void), meth, false, arg_types, NULL);
68

Bryce McKinlay committed
69
  return obj;
70 71 72 73 74 75 76 77
}

java::lang::ClassLoader*
java::io::ObjectInputStream::currentClassLoader (::java::lang::SecurityManager *sm)
{
  return sm->currentClassLoader ();
}