Patch: FYI: core handler fix

Tom Tromey tromey@redhat.com
Mon Apr 22 15:30:00 GMT 2002


I'm checking this in on the trunk and the branch.

With my change to --resource I noticed that the core code wasn't
working any more.  If I use `--resource=foo', Core::create is called
with a name like "/foo".  I don't know why this started happening.

Other parts of this patch are definitely needed to fix real bugs in
the implementation.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* gnu/gcj/natCore.cc (create): Use __builtin_alloca, and compute
	correct length of UTF-8 encoded name.  Strip leading `/'.
	(_Jv_RegisterResource): Use _Jv_Malloc.

Index: gnu/gcj/natCore.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/natCore.cc,v
retrieving revision 1.1
diff -u -r1.1 natCore.cc
--- gnu/gcj/natCore.cc 6 Sep 2001 22:32:53 -0000 1.1
+++ gnu/gcj/natCore.cc 22 Apr 2002 22:23:31 -0000
@@ -1,6 +1,6 @@
 // natCore -- C++ side of Core
 
-/* Copyright (C) 2001  Free Software Foundation
+/* Copyright (C) 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -40,7 +40,7 @@
   // These are permanent data structures for now.  This routine is
   // called from a static constructor, so we shouldn't depend on too
   // much existing infrastructure.
-  core_chain *cc = (core_chain *) malloc (sizeof (core_chain));
+  core_chain *cc = (core_chain *) _Jv_Malloc (sizeof (core_chain));
 
   cc->name_length = ((int *)rptr)[0];
   cc->data_length = ((int *)rptr)[1];
@@ -56,9 +56,17 @@
 gnu::gcj::Core *
 gnu::gcj::Core::create (jstring name)
 {
-  char buf[name->length() + 1];
+  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;
+    }
 
   core_chain *node = root;
 



More information about the Java-patches mailing list