dslinux/user/perl/jpl/PerlInterpreter Makefile.PL PerlInterpreter.c PerlInterpreter.h PerlInterpreter.java

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 18:00:01 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/jpl/PerlInterpreter
In directory antilope:/tmp/cvs-serv17422/jpl/PerlInterpreter

Added Files:
	Makefile.PL PerlInterpreter.c PerlInterpreter.h 
	PerlInterpreter.java 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: PerlInterpreter.java ---
class PerlInterpreter {
    static boolean initted = false;

    public native void init(String s);
    public native void eval(String s);

//    public native long op(long i);

    public PerlInterpreter fetch () {
	if (!initted) {
	    init("$JPL::DEBUG = $ENV{JPLDEBUG}");
	    initted = true;
	}
	return this;
    }

    static {
	System.loadLibrary("PerlInterpreter");
    }
}


--- NEW FILE: PerlInterpreter.h ---
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class PerlInterpreter */

#ifndef _Included_PerlInterpreter
#define _Included_PerlInterpreter
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: initted */
/*
 * Class:     PerlInterpreter
 * Method:    init
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_PerlInterpreter_init
  (JNIEnv *, jobject, jstring);

/*
 * Class:     PerlInterpreter
 * Method:    eval
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_PerlInterpreter_eval
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif

--- NEW FILE: Makefile.PL ---
#!/usr/bin/perl

$JPL_SRC = "..";

use Config;

eval `$JPL_SRC/setvars -perl`;

if ($^O eq 'linux') {
    $flags = "-Dbool=char";	# avoid builtin bool altogether
    $libs = "-lc -lm -ldl";
} else {
    $flags = "";
    $libs = "-lc -lm -ldl";
}

# Needed for JNI.
if ($^O eq 'solaris') {
    $libs .= " -lthread";
}

open(MAKEFILE, ">Makefile");

print MAKEFILE <<"SUBS";
WHAT = PerlInterpreter
JAVA_HOME = $ENV{JAVA_HOME}
JPL_HOME = $ENV{JPL_HOME}
ARCHNAME = $Config{archname}
PERLARCHDIR = $Config{archlib}
CC = $Config{cc}
FLAGS = $Config{cccdlflags} $Config{ccdlflags} $Config{lddlflags} $flags
INCL  = -I\$(PERLARCHDIR)/CORE \\
	-I\$(JAVA_HOME)/include \\
	-I\$(JAVA_HOME)/include/$^O \\
	-I\$(JAVA_HOME)/include/genunix
LIBS = $libs

SUBS


print MAKEFILE <<'NOSUBS';
.SUFFIXES: .java .class

.java.class:
	javac $*.java

.class.h:
	javah -jni $*

all: PerlInterpreter.class libPerlInterpreter.so

PerlInterpreter.class: PerlInterpreter.java

PerlInterpreter.h: PerlInterpreter.class

libPerlInterpreter.so: PerlInterpreter.c PerlInterpreter.h
	$(CC) $(FLAGS) $(INCL) PerlInterpreter.c \
	$(PERLARCHDIR)/auto/DynaLoader/DynaLoader.a \
	$(LIBS) \
	-o libPerlInterpreter.so

test:

install: all
	mkdir -p $(JPL_HOME)/lib/$(ARCHNAME)
	cp libPerlInterpreter.so $(JPL_HOME)/lib/$(ARCHNAME)
	cp $(WHAT).class $(JPL_HOME)/lib

clean:
	rm -f libPerlInterpreter.so
	rm -f PerlInterpreter.class
NOSUBS

close MAKEFILE;

--- NEW FILE: PerlInterpreter.c ---
/*
 * "The Road goes ever on and on, down from the door where it began."
 */

#include "PerlInterpreter.h"
#include <dlfcn.h>

#include "EXTERN.h"
#include "perl.h"

#ifndef PERL_VERSION
#  include <patchlevel.h>
#  define PERL_REVISION		5
#  define PERL_VERSION		PATCHLEVEL
#  define PERL_SUBVERSION	SUBVERSION
#endif

#if PERL_REVISION == 5 && (PERL_VERSION < 4 || \
			   (PERL_VERSION == 4 && PERL_SUBVERSION <= 75))
#  define PL_na				na
#  define PL_sv_no			sv_no
#  define PL_sv_undef			sv_undef
#  define PL_dowarn			dowarn
#  define PL_curinterp			curinterp
#  define PL_do_undump			do_undump
#  define PL_perl_destruct_level	perl_destruct_level
#  define ERRSV				GvSV(errgv)
#endif

#ifndef newSVpvn
#  define newSVpvn(a,b)	newSVpv(a,b)
#endif

#ifndef pTHX
#  define pTHX		void
#  define pTHX_
#  define aTHX
#  define aTHX_
#  define dTHX		extern int JNI___notused
#endif

#ifndef EXTERN_C
#  ifdef __cplusplus
#    define EXTERN_C extern "C"
#  else
#    define EXTERN_C extern
#  endif
#endif

static void xs_init (pTHX);
static PerlInterpreter *my_perl;

int jpldebug = 0;
JNIEnv *jplcurenv;

JNIEXPORT void JNICALL
Java_PerlInterpreter_init(JNIEnv *env, jobject obj, jstring js)
{
    int exitstatus;
    int argc = 3;
    SV* envsv;
    SV* objsv;
 
    static char *argv[] = {"perl", "-e", "1", 0};

    if (getenv("JPLDEBUG"))
	jpldebug = atoi(getenv("JPLDEBUG"));

    if (jpldebug)
	fprintf(stderr, "init\n");

    if (!dlopen("libperl.so", RTLD_LAZY|RTLD_GLOBAL)) {
	fprintf(stderr, "%s\n", dlerror());
	exit(1);
    }

    if (PL_curinterp)
	return;

    perl_init_i18nl10n(1);

    if (!PL_do_undump) {
	my_perl = perl_alloc();
	if (!my_perl)
	    exit(1);
	perl_construct( my_perl );
	PL_perl_destruct_level = 0;
    }

    exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL );
    
    if (!exitstatus)
	Java_PerlInterpreter_eval(env, obj, js);

}

JNIEXPORT void JNICALL
Java_PerlInterpreter_eval(JNIEnv *env, jobject obj, jstring js)
{
    SV* envsv;
    SV* objsv;
    dSP;
    jbyte* jb;

    ENTER;
    SAVETMPS;

    jplcurenv = env;
    envsv = perl_get_sv("JPL::_env_", 1);
    sv_setiv(envsv, (IV)(void*)env);
    objsv = perl_get_sv("JPL::_obj_", 1);
    sv_setiv(objsv, (IV)(void*)obj);

    jb = (jbyte*)(*env)->GetStringUTFChars(env,js,0);

    if (jpldebug)
	fprintf(stderr, "eval %s\n", (char*)jb);

    perl_eval_pv( (char*)jb, 0 );

    if (SvTRUE(ERRSV)) {
	jthrowable newExcCls;

	(*env)->ExceptionDescribe(env);
	(*env)->ExceptionClear(env);

	newExcCls = (*env)->FindClass(env, "java/lang/RuntimeException");
	if (newExcCls)
	    (*env)->ThrowNew(env, newExcCls, SvPV(ERRSV,PL_na));
    }

    (*env)->ReleaseStringUTFChars(env,js,jb);
    FREETMPS;
    LEAVE;

}

/*
JNIEXPORT jint JNICALL
Java_PerlInterpreter_eval(JNIEnv *env, jobject obj, jint ji)
{
    op = (OP*)(void*)ji;
    op = (*op->op_ppaddr)(pTHX);
    return (jint)(void*)op;
}
*/

/* Register any extra external extensions */

/* Do not delete this line--writemain depends on it */
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_JNI (pTHX_ CV* cv);

static void
xs_init(pTHX)
{
    char *file = __FILE__;
    dXSUB_SYS;
        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}




More information about the dslinux-commit mailing list