From 57dea26d80db9a1b455ef89cc843930fe18b0369 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Mon, 30 Nov 1998 01:24:53 +0000 Subject: [PATCH] JPL tweaks to build with 5.005 p4raw-id: //depot/perlext/jpl@2407 --- JNI/JNI.xs | 67 ++++++++++++++++++--------------------- JNI/typemap | 16 +++++----- JPL/Compile.pm | 31 ++++++++---------- PerlInterpreter/PerlInterpreter.c | 25 +++++++-------- README | 14 +++++--- 5 files changed, 73 insertions(+), 80 deletions(-) diff --git a/JNI/JNI.xs b/JNI/JNI.xs index d54a6cc..10eb2cf 100644 --- a/JNI/JNI.xs +++ b/JNI/JNI.xs @@ -4,15 +4,9 @@ * This package may be copied under the same terms as Perl itself. */ -#ifdef __cplusplus -extern "C" { -#endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" -#ifdef __cplusplus -} -#endif #include #include @@ -37,6 +31,7 @@ makeargs(char *sig, SV** svp, int items) char *s = sig; JNIEnv* env = jplcurenv; char *start; + STRLEN n_a; if (jpldebug) fprintf(stderr, "sig = %s, items = %d\n", sig, items); @@ -98,7 +93,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jboolean); jbooleanArray ja = (*env)->NewBooleanArray(env, len); - (*env)->SetBooleanArrayRegion(env, ja, 0, len, (jboolean*)SvPV(sv,na)); + (*env)->SetBooleanArrayRegion(env, ja, 0, len, (jboolean*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -129,7 +124,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jbyte); jbyteArray ja = (*env)->NewByteArray(env, len); - (*env)->SetByteArrayRegion(env, ja, 0, len, (jbyte*)SvPV(sv,na)); + (*env)->SetByteArrayRegion(env, ja, 0, len, (jbyte*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -160,7 +155,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jchar); jcharArray ja = (*env)->NewCharArray(env, len); - (*env)->SetCharArrayRegion(env, ja, 0, len, (jchar*)SvPV(sv,na)); + (*env)->SetCharArrayRegion(env, ja, 0, len, (jchar*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -191,7 +186,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jshort); jshortArray ja = (*env)->NewShortArray(env, len); - (*env)->SetShortArrayRegion(env, ja, 0, len, (jshort*)SvPV(sv,na)); + (*env)->SetShortArrayRegion(env, ja, 0, len, (jshort*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -222,7 +217,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jint); jintArray ja = (*env)->NewIntArray(env, len); - (*env)->SetIntArrayRegion(env, ja, 0, len, (jint*)SvPV(sv,na)); + (*env)->SetIntArrayRegion(env, ja, 0, len, (jint*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -253,7 +248,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jlong); jlongArray ja = (*env)->NewLongArray(env, len); - (*env)->SetLongArrayRegion(env, ja, 0, len, (jlong*)SvPV(sv,na)); + (*env)->SetLongArrayRegion(env, ja, 0, len, (jlong*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -284,7 +279,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jfloat); jfloatArray ja = (*env)->NewFloatArray(env, len); - (*env)->SetFloatArrayRegion(env, ja, 0, len, (jfloat*)SvPV(sv,na)); + (*env)->SetFloatArrayRegion(env, ja, 0, len, (jfloat*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -315,7 +310,7 @@ makeargs(char *sig, SV** svp, int items) jsize len = sv_len(sv) / sizeof(jdouble); jdoubleArray ja = (*env)->NewDoubleArray(env, len); - (*env)->SetDoubleArrayRegion(env, ja, 0, len, (jdouble*)SvPV(sv,na)); + (*env)->SetDoubleArrayRegion(env, ja, 0, len, (jdouble*)SvPV(sv,n_a)); jv[ix++].l = (jobject)ja; } else @@ -340,7 +335,7 @@ makeargs(char *sig, SV** svp, int items) jcl = (*env)->FindClass(env, "java/lang/String"); ja = (*env)->NewObjectArray(env, len, jcl, 0); for (esv = AvARRAY((AV*)rv), i = 0; i < len; esv++, i++) { - jobject str = (jobject)(*env)->NewStringUTF(env, SvPV(*esv,na)); + jobject str = (jobject)(*env)->NewStringUTF(env, SvPV(*esv,n_a)); (*env)->SetObjectArrayElement(env, ja, i, str); } jv[ix++].l = (jobject)ja; @@ -375,7 +370,7 @@ makeargs(char *sig, SV** svp, int items) } else { jobject str = (jobject)(*env)->NewStringUTF(env, - SvPV(*esv,na)); + SvPV(*esv,n_a)); (*env)->SetObjectArrayElement(env, ja, i, str); } } @@ -393,7 +388,7 @@ makeargs(char *sig, SV** svp, int items) if (!SvROK(sv) || strnEQ(s, "java/lang/String;", 17)) { s += 17; jv[ix++].l = (jobject)(*env)->NewStringUTF(env, - (char*) SvPV(sv,na)); + (char*) SvPV(sv,n_a)); break; } while (*s != ';') s++; @@ -2528,7 +2523,7 @@ GetBooleanArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jboolean)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseBooleanArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2558,7 +2553,7 @@ GetByteArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jbyte)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseByteArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2588,7 +2583,7 @@ GetCharArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jchar)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseCharArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2618,7 +2613,7 @@ GetShortArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jshort)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseShortArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2648,7 +2643,7 @@ GetIntArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jint)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseIntArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2678,7 +2673,7 @@ GetLongArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jlong)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseLongArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2708,7 +2703,7 @@ GetFloatArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jfloat)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseFloatArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2738,7 +2733,7 @@ GetDoubleArrayElements(array) (STRLEN)RETVAL_len_ * sizeof(jdouble)))); } else - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } (*env)->ReleaseDoubleArrayElements(env, array,RETVAL,JNI_ABORT); RESTOREENV; @@ -2893,7 +2888,7 @@ SetBooleanArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetBooleanArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -2912,7 +2907,7 @@ SetByteArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetByteArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -2931,7 +2926,7 @@ SetCharArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetCharArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -2950,7 +2945,7 @@ SetShortArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetShortArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -2969,7 +2964,7 @@ SetIntArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetIntArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -2988,7 +2983,7 @@ SetLongArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetLongArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -3007,7 +3002,7 @@ SetFloatArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetFloatArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -3026,7 +3021,7 @@ SetDoubleArrayRegion(array,start,len,buf) { if (buf_len_ < len) croak("string is too short"); - else if (buf_len_ > len && dowarn) + else if (buf_len_ > len && PL_dowarn) warn("string is too long"); (*env)->SetDoubleArrayRegion(env, array,start,len,buf); RESTOREENV; @@ -3093,7 +3088,7 @@ GetJavaVM(...) if (items--) { ++mark; - lib = SvPV(*mark, na); + lib = SvPV(*mark, PL_na); } else lib = 0; @@ -3106,7 +3101,7 @@ GetJavaVM(...) JNI_GetDefaultJavaVMInitArgs(&vm_args); vm_args.exit = &call_my_exit; while (items > 1) { - char *s = SvPV(*++mark,na); + char *s = SvPV(*++mark,PL_na); items -= 2; if (strEQ(s, "checkSource")) vm_args.checkSource = (jint)SvIV(*++mark); @@ -3121,7 +3116,7 @@ GetJavaVM(...) else if (strEQ(s, "verifyMode")) vm_args.verifyMode = (jint)SvIV(*++mark); else if (strEQ(s, "classpath")) - vm_args.classpath = savepv(SvPV(*++mark,na)); + vm_args.classpath = savepv(SvPV(*++mark,PL_na)); else if (strEQ(s, "enableClassGC")) vm_args.enableClassGC = (jint)SvIV(*++mark); else if (strEQ(s, "enableVerboseGC")) diff --git a/JNI/typemap b/JNI/typemap index c5b15f6..9bd0691 100644 --- a/JNI/typemap +++ b/JNI/typemap @@ -49,7 +49,7 @@ T_JSTRING $var = ($type)(void*)SvIV(SvRV($arg)); } else - $var = ($type)(*env)->NewStringUTF(env, (char *) SvPV($arg,na)) + $var = ($type)(*env)->NewStringUTF(env, (char *) SvPV($arg,PL_na)) T_JVALUELIST if (SvROK($arg)) { AV* av = (AV*)SvRV($arg); @@ -65,7 +65,7 @@ T_JVALUELIST T_JIDSIG { $var = ($type)SvIV($arg); - sig = (char*)SvPV($arg,na); + sig = (char*)SvPV($arg,PL_na); } T_JPTROBJ if (SvROK($arg) && SvOBJECT(SvRV($arg))) { @@ -189,7 +189,7 @@ T_JPTROBJ # T_U_LONG # $var = (unsigned long)SvIV($arg) # T_CHAR -# $var = (char)*SvPV($arg,na) +# $var = (char)*SvPV($arg,PL_na) # T_U_CHAR # $var = (unsigned char)SvIV($arg) # T_FLOAT @@ -199,7 +199,7 @@ T_JPTROBJ # T_DOUBLE # $var = (double)SvNV($arg) # T_PV -# $var = ($type)SvPV($arg,na) +# $var = ($type)SvPV($arg,PL_na) # T_PTR # $var = ($type)SvIV($arg) # T_PTRREF @@ -255,7 +255,7 @@ T_JPTROBJ # T_OPAQUE # $var NOT IMPLEMENTED # T_OPAQUEPTR -# $var = ($type)SvPV($arg,na) +# $var = ($type)SvPV($arg,PL_na) # T_PACKED # $var = XS_unpack_$ntype($arg) # T_PACKEDARRAY @@ -366,7 +366,7 @@ T_JPTROBJ # if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) ) # sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1))); # else -# $arg = &sv_undef; +# $arg = &PL_sv_undef; # } # T_INOUT # { @@ -374,7 +374,7 @@ T_JPTROBJ # if ( do_open(gv, "+<&", 3, FALSE, 0, 0, $var) ) # sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1))); # else -# $arg = &sv_undef; +# $arg = &PL_sv_undef; # } # T_OUT # { @@ -382,5 +382,5 @@ T_JPTROBJ # if ( do_open(gv, "+>&", 3, FALSE, 0, 0, $var) ) # sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1))); # else -# $arg = &sv_undef; +# $arg = &PL_sv_undef; # } diff --git a/JPL/Compile.pm b/JPL/Compile.pm index 39dd6b8..6d95112 100755 --- a/JPL/Compile.pm +++ b/JPL/Compile.pm @@ -371,15 +371,15 @@ $glue emit <<""; ! PUTBACK; ! if (perl_call_sv(methodsv, G_EVAL|G_KEEPERR)) -! retsv = *stack_sp--; +! retsv = *PL_stack_sp--; ! else -! retsv = &sv_undef; +! retsv = &PL_sv_undef; ! } emit <<""; -! if (SvTRUE(GvSV(errgv))) { +! if (SvTRUE(ERRSV)) { ! jthrowable newExcCls; ! ! (*env)->ExceptionDescribe(env); @@ -387,7 +387,7 @@ $glue ! ! newExcCls = (*env)->FindClass(env, "java/lang/RuntimeException"); ! if (newExcCls) -! (*env)->ThrowNew(env, newExcCls, SvPV(GvSV(errgv),na)); +! (*env)->ThrowNew(env, newExcCls, SvPV(ERRSV,PL_na)); ! } ! @@ -416,7 +416,7 @@ $glue } elsif ($sig =~ s#^Ljava/lang/String;##) { emit <<""; -! retval = (*env)->NewStringUTF(env, SvPV(retsv,na)); +! retval = (*env)->NewStringUTF(env, SvPV(retsv,PL_na)); ! FREETMPS; ! LEAVE; ! return retval; @@ -468,7 +468,7 @@ $glue ! jsize len = sv_len(retsv) / sizeof($ntype); ! ! ${ntype}Array ja = (*env)->New${ptype}Array(env, len); -! (*env)->Set${ptype}ArrayRegion(env, ja, 0, len, ($ntype*)SvPV(retsv,na)); +! (*env)->Set${ptype}ArrayRegion(env, ja, 0, len, ($ntype*)SvPV(retsv,PL_na)); ! retval = ($rettype)ja; ! } ! else @@ -495,7 +495,7 @@ $glue ! jcl = (*env)->FindClass(env, "java/lang/String"); ! ja = (*env)->NewObjectArray(env, len, jcl, 0); ! for (esv = AvARRAY((AV*)rv), i = 0; i < len; esv++, i++) { -! jobject str = (jobject)(*env)->NewStringUTF(env, SvPV(*esv,na)); +! jobject str = (jobject)(*env)->NewStringUTF(env, SvPV(*esv,PL_na)); ! (*env)->SetObjectArrayElement(env, ja, i, str); ! } ! retval = ($rettype)ja; @@ -535,7 +535,7 @@ $glue ! } ! else { ! jobject str = (jobject)(*env)->NewStringUTF(env, -! SvPV(*esv,na)); +! SvPV(*esv,PL_na)); ! (*env)->SetObjectArrayElement(env, ja, i, str); ! } ! } @@ -734,18 +734,15 @@ sub emit_c_header { ! !#include "$hfile" ! -!#ifdef __cplusplus -!extern "C" { -!#endif -! !#include "EXTERN.h" !#include "perl.h" ! -!#ifdef __cplusplus -!} -!# define EXTERN_C extern "C" -!#else -!# define EXTERN_C extern +!#ifndef EXTERN_C +!# ifdef __cplusplus +!# define EXTERN_C extern "C" +!# else +!# define EXTERN_C extern +!# endif !#endif ! !extern int jpldebug; diff --git a/PerlInterpreter/PerlInterpreter.c b/PerlInterpreter/PerlInterpreter.c index 29a275e..8bf3f5f 100644 --- a/PerlInterpreter/PerlInterpreter.c +++ b/PerlInterpreter/PerlInterpreter.c @@ -5,18 +5,15 @@ #include "PerlInterpreter.h" #include -#ifdef __cplusplus -extern "C" { -#endif - #include "EXTERN.h" #include "perl.h" -#ifdef __cplusplus -} -# define EXTERN_C extern "C" -#else -# define EXTERN_C extern +#ifndef EXTERN_C +# ifdef __cplusplus +# define EXTERN_C extern "C" +# else +# define EXTERN_C extern +# endif #endif static void xs_init _((void)); @@ -46,17 +43,17 @@ Java_PerlInterpreter_init(JNIEnv *env, jobject obj, jstring js) exit(1); } - if (curinterp) + if (PL_curinterp) return; perl_init_i18nl10n(1); - if (!do_undump) { + if (!PL_do_undump) { my_perl = perl_alloc(); if (!my_perl) exit(1); perl_construct( my_perl ); - perl_destruct_level = 0; + PL_perl_destruct_level = 0; } exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL ); @@ -90,7 +87,7 @@ Java_PerlInterpreter_eval(JNIEnv *env, jobject obj, jstring js) perl_eval_pv( (char*)jb, 0 ); - if (SvTRUE(GvSV(errgv))) { + if (SvTRUE(ERRSV)) { jthrowable newExcCls; (*env)->ExceptionDescribe(env); @@ -98,7 +95,7 @@ Java_PerlInterpreter_eval(JNIEnv *env, jobject obj, jstring js) newExcCls = (*env)->FindClass(env, "java/lang/RuntimeException"); if (newExcCls) - (*env)->ThrowNew(env, newExcCls, SvPV(GvSV(errgv),na)); + (*env)->ThrowNew(env, newExcCls, SvPV(ERRSV,PL_na)); } (*env)->ReleaseStringUTFChars(env,js,jb); diff --git a/README b/README index ae23b4b..1fe04b1 100644 --- a/README +++ b/README @@ -9,11 +9,11 @@ from the network. Don't expect not to be surprised occasionally. Requirements ------------ -Perl 5.004 (or later) must be compiled and installed as a shared library -(libperl.so). I had to use the system's malloc. We've tested -it most heavily with 5.004_04. +Perl 5.005_02 (or later) must be compiled and installed as a shared library +(libperl.so). I had to use the system's malloc. This version has not +been well tested under 5.005_02, so you can expect some rough edges. -You need JDK 1.1. On Solaris 1.1.1 works. On Linux you need 1.1.3 with +You need JDK 1.1. On Solaris 1.1.5 works. On Linux you need 1.1.3 with the patches from ftp://ftp.blackdown.org/pub/Linux/JDK/1.1.3/updates/libjava-1.1.3v2-1.tar.gz @@ -22,6 +22,10 @@ The get_jdk directory contains a script that will download JDK (but not the patch file above) off of the net for you. (This presumes you've already installed the modules mentioned in ../README.) +You may need to ensure that all files under the ../jpl directory are writable. +install-jpl expects to be run with super-user privileges so that it can +put things in the right places. + What the heck is JPL? --------------------- JPL is a hybrid (to use the polite term) language. It's basically Java @@ -55,7 +59,7 @@ Installation Run "install-jpl". You have to tell it whether you want to use the current directory for JPL_HOME or some other directory. Everything else should take care of itself, except that after install-jpl -write the setvars program, you are responsible to invoke it properly +writes the setvars program, you are responsible to invoke it properly before any JPL applications can be compiled under the current shell. sh: eval `setvars -sh` -- 2.7.4