I've created a small patch to japhar with which I've tried to make
Japhar support printStackTrace (PrintStream) and printStackTrace
(PrintWriter) correctly. Currently it always prints to stderr.
I've run into a problem however in that when I get *println in the
included patch, it is null. I'm not sure what I'm doing wrong within
the Hungry api... anyone care to take a look?
Brian
--
Brian Jones <[EMAIL PROTECTED]>
? hungry/java/japhar/include/.runtime.h.swp
? hungry/java/japhar/lib/zlib/Makefile
? hungry/java/japhar/lib/zlib/Makefile.in
Index: hungry/java/japhar/include/runtime.h
===================================================================
RCS file: /cvsroot/hungry/java/japhar/include/runtime.h,v
retrieving revision 1.11
diff -r1.11 runtime.h
430a431,434
> HVM_ExceptionPrintBacktraceToStream(HungryEnv *henv, japhar_object* throwable_ref,
> japhar_object* stream);
>
> PR_EXTERN( void )
Index: hungry/java/japhar/lib/libffi/fficonfig.h.in
===================================================================
RCS file: /cvsroot/hungry/java/japhar/lib/libffi/fficonfig.h.in,v
retrieving revision 1.5
diff -r1.5 fficonfig.h.in
60a61,67
>
> /* Name of package */
> #undef PACKAGE
>
> /* Version number of package */
> #undef VERSION
>
Index: hungry/java/japhar/lib/libnative/java.lang/throwable.c
===================================================================
RCS file: /cvsroot/hungry/java/japhar/lib/libnative/java.lang/throwable.c,v
retrieving revision 1.19
diff -r1.19 throwable.c
38c38
< HVM_ExceptionPrintBacktrace(henv, throwable);
---
> HVM_ExceptionPrintBacktraceToStream(henv, throwable, printwriter_stream);
Index: hungry/java/japhar/lib/libruntime/exceptions.c
===================================================================
RCS file: /cvsroot/hungry/java/japhar/lib/libruntime/exceptions.c,v
retrieving revision 1.57
diff -r1.57 exceptions.c
66,67c66,73
< ClazzFile *throwable_class;
< MethodStruct *getMessage;
---
> HVM_ExceptionPrintBacktraceToStream(henv, throwable_ref, (japhar_object*)NULL);
> }
>
> PR_IMPLEMENT(void)
> HVM_ExceptionPrintBacktraceToStream(HungryEnv *henv, japhar_object* throwable_ref,
>japhar_object* stream_ref)
> {
> ClazzFile *throwable_class, *stream_class;
> MethodStruct *getMessage, *println = NULL;
74a81,82
> char *msg_to_print;
> japhar_object *msg_obj;
76c84,94
< throwable_class = HVM_ClassFind(henv, java_lang_Throwable);
---
> if (stream_ref != NULL)
> {
> ClazzFile *stream_clazz = HVM_ClassFind(henv, "java/io/PrintWriter");
> PRBool pwriter = HVM_ObjectIsInstanceOf(henv, stream_ref, stream_clazz);
> if (pwriter)
> stream_class = HVM_ClassFind(henv, "java/io/PrintWriter");
> else
> stream_class = HVM_ClassFind(henv, "java/io/PrintStream");
> println = HVM_MethodFind(henv, stream_class, "println",
> "()Ljava/lang/String;");
> }
77a96
> throwable_class = HVM_ClassFind(henv, java_lang_Throwable);
98a118,128
> msg_to_print = PR_smprintf("%s (%s)", exceptionname, msg_bytes);
> msg_obj = HVM_StringFromCString(henv, msg_to_print);
> if (msg_obj == NULL)
> abort_with_message("ExceptionPrintBacktraceToStream unable to allocate
>message");
>
> if (println != NULL)
> {
> HVM_MethodCall(henv, println, stream_ref, msg_obj);
> }
> else
> fprintf (stderr, "%s\n", msg_to_print);
100c130
< fprintf (stderr, "%s (%s)\n", exceptionname, msg_bytes);
---
> PR_smprintf_free(msg_to_print);
103c133,147
< fprintf (stderr, "%s\n", exceptionname);
---
> {
> msg_to_print = PR_smprintf("%s", exceptionname);
> msg_obj = HVM_StringFromCString(henv, msg_to_print);
> if (msg_obj == NULL)
> abort_with_message("ExceptionPrintBacktraceToStream unable to allocate
>message");
>
> if (println != NULL)
> {
> HVM_MethodCall(henv, println, stream_ref, msg_obj);
> }
> else
> fprintf (stderr, "%s\n", msg_to_print);
>
> PR_smprintf_free(msg_to_print);
> }
112,116c156,174
< fprintf (stderr, " in %s.%s(%s%snative method)\n",
< level->classname,
< level->method->name,
< level->filename ? level->filename : "",
< level->filename ? ", " : "");
---
> {
> msg_to_print = PR_smprintf(" in %s.%s(%s%snative method)",
> level->classname,
> level->method->name,
> level->filename ? level->filename : "",
> level->filename ? ", " : "");
> msg_obj = HVM_StringFromCString(henv, msg_to_print);
> if (msg_obj == NULL)
> abort_with_message("ExceptionPrintBacktraceToStream unable to allocate
>message");
>
> if (println != NULL)
> {
> HVM_MethodCall(henv, println, stream_ref, msg_obj);
> }
> else
> fprintf (stderr, "%s\n", msg_to_print);
>
> PR_smprintf_free(msg_to_print);
> }
118,123c176,193
< fprintf (stderr, " in %s.%s(%s%spc = %d)\n",
< level->classname,
< level->method->name,
< level->filename ? level->filename : "",
< level->filename ? ", " : "",
< level->pc);
---
> {
> msg_to_print = PR_smprintf(" in %s.%s(%s%spc = %d)",
> level->classname,
> level->method->name,
> level->filename ? level->filename : "",
> level->filename ? ", " : "",
> level->pc);
> msg_obj = HVM_StringFromCString(henv, msg_to_print);
> if (msg_obj == NULL)
> abort_with_message("ExceptionPrintBacktraceToStream unable to allocate
>message");
>
> if (println != NULL)
> {
> HVM_MethodCall(henv, println, stream_ref, msg_obj);
> }
> else
> fprintf (stderr, "%s\n", msg_to_print);
> }
125,131c195,213
< fprintf (stderr, " at %s.%s(%s%s%d, pc = %d)\n",
< level->classname,
< level->method->name,
< level->filename ? level->filename : "",
< level->filename ? ":" : "line ",
< line_number,
< level->pc);
---
> {
> msg_to_print = PR_smprintf(" at %s.%s(%s%s%d, pc = %d)",
> level->classname,
> level->method->name,
> level->filename ? level->filename : "",
> level->filename ? ":" : "line ",
> line_number,
> level->pc);
> msg_obj = HVM_StringFromCString(henv, msg_to_print);
> if (msg_obj == NULL)
> abort_with_message("ExceptionPrintBacktraceToStream unable to allocate
>message");
>
> if (println != NULL)
> {
> HVM_MethodCall(henv, println, stream_ref, msg_obj);
> }
> else
> fprintf (stderr, "%s\n", msg_to_print);
> }