245c3c04af
libjava: 2004-04-15 Bryce McKinlay <mckinlay@redhat.com> * prims.cc (_Jv_AllocObject): Remove `size' argument. (_Jv_AllocObjectNoFinalizer): Likewise. (_Jv_AllocObjectNoInitNoFinalizer): Likewise. (_Jv_AllocPtrFreeObject): Likewise. (_Jv_AllocString): Moved from natString.cc. Call collector interface directly even in the JVMPI case. * gcj/cni.h (JvAllocObject): Remove `size' argument from _Jv_AllocObject calls. * gcj/javaprims.h: Update prototypes. * gnu/gcj/natCore.cc (_Jv_create_core): Use `new', not _Jv_AllocObject. * java/lang/Class.h: Update _Jv_AllocObject friend prototype. * java/lang/natString.cc (_Jv_AllocString): Move to prims.cc. gcc/cp: 2004-04-15 Bryce McKinlay <mckinlay@redhat.com> * init.c (build_new_1): Don't use type size argument for Java _Jv_AllocObject call. gcc/java: 2004-04-15 Bryce McKinlay <mckinlay@redhat.com> * expr.c (expand_java_NEW): Don't use size argument for _Jv_AllocObject calls. * parse.y (patch_invoke): Likewise. From-SVN: r80754
114 lines
2.4 KiB
C++
114 lines
2.4 KiB
C++
// natCore -- C++ side of Core
|
|
|
|
/* Copyright (C) 2001, 2002, 2003 Free Software Foundation
|
|
|
|
This file is part of libgcj.
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
details. */
|
|
|
|
/* Author: Anthony Green <green@redhat.com>. */
|
|
|
|
#include <config.h>
|
|
|
|
#include <gcj/cni.h>
|
|
#include <jvm.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <java/lang/NullPointerException.h>
|
|
#include <java/io/IOException.h>
|
|
#include <gnu/gcj/Core.h>
|
|
|
|
// List of global core values.
|
|
static _Jv_core_chain *root;
|
|
|
|
static void
|
|
default_register_resource (_Jv_core_chain *node)
|
|
{
|
|
node->next = root;
|
|
root = node;
|
|
}
|
|
|
|
// This is set only when a lock is held on java.lang.Class.
|
|
// This function is called to handle a new core node.
|
|
void (*_Jv_RegisterCoreHook) (_Jv_core_chain *) = default_register_resource;
|
|
|
|
void
|
|
_Jv_RegisterResource (void *vptr)
|
|
{
|
|
char *rptr = (char *) vptr;
|
|
|
|
_Jv_core_chain *cc = (_Jv_core_chain *) _Jv_Malloc (sizeof (_Jv_core_chain));
|
|
|
|
cc->name_length = ((int *)rptr)[0];
|
|
cc->data_length = ((int *)rptr)[1];
|
|
cc->name = rptr + 2 * sizeof (int);
|
|
cc->data = cc->name + cc->name_length;
|
|
cc->next = NULL;
|
|
|
|
(*_Jv_RegisterCoreHook) (cc);
|
|
}
|
|
|
|
void
|
|
_Jv_FreeCoreChain (_Jv_core_chain *chain)
|
|
{
|
|
while (chain != NULL)
|
|
{
|
|
_Jv_core_chain *next = chain->next;
|
|
_Jv_Free (chain);
|
|
chain = next;
|
|
}
|
|
}
|
|
|
|
_Jv_core_chain *
|
|
_Jv_FindCore (_Jv_core_chain *node, jstring name)
|
|
{
|
|
char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (name) + 1);
|
|
jsize total = JvGetStringUTFRegion (name, 0, name->length(), buf);
|
|
buf[total] = '\0';
|
|
|
|
// Usually requests here end up as an absolute URL. We strip the
|
|
// initial `/'.
|
|
if (buf[0] == '/')
|
|
{
|
|
++buf;
|
|
--total;
|
|
}
|
|
|
|
while (node)
|
|
{
|
|
if (total == node->name_length
|
|
&& strncmp (buf, node->name, total) == 0)
|
|
return node;
|
|
node = node->next;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
gnu::gcj::Core *
|
|
_Jv_create_core (_Jv_core_chain *node, jstring name)
|
|
{
|
|
node = _Jv_FindCore (node, name);
|
|
|
|
gnu::gcj::Core *core = NULL;
|
|
if (node)
|
|
{
|
|
core = new gnu::gcj::Core ();
|
|
core->ptr = (gnu::gcj::RawData *) node->data;
|
|
core->length = node->data_length;
|
|
}
|
|
return core;
|
|
}
|
|
|
|
gnu::gcj::Core *
|
|
gnu::gcj::Core::create (jstring name)
|
|
{
|
|
gnu::gcj::Core *core = _Jv_create_core (root, name);
|
|
if (core == NULL)
|
|
throw new java::io::IOException (JvNewStringLatin1 ("can't open core"));
|
|
return core;
|
|
}
|