Hello  PERL-Guts-Gurus,

     I built a Windows DLL with functions wrapping the primitive PERL XS
functions, such as perl_create, perl_parse, etc.( Actually I am using the
"jp" module developed by S Balamurugan http://search.cpan.org/search?dist=jp
).  All the functions in this DLL work fine when they are called by a C
program. But when I tried calling these functions from a Java program
through JNI, the perl_parse() function (wrapped by the PLInit() DLL function
) does not recognize ( doesn't import the names? )  the subroutines. 


Please use this code snippet for reference:

Windows DLL ( jperl.dll )
=========================
static PerlInterpreter *my_perl = NULL;

JPERL_API int PLInit( char *perlfile )
{
    char *args[] = { "jperl", perlfile };
    int argcount = 2;

    my_perl = perl_alloc();
    perl_construct(my_perl);
 
 
    perl_parse( my_perl, NULL, argcount, args, NULL );
 
    
    // For debugging purposes, right after perl_parse(),  
    //   print all the symbols of package 'main'. We should
    //   see all the functions defined in the input perl script.
    char **EvalRet; 
    PLEval( EvalRet, "foreach ( sort keys %{main::} ) { print \" $_ \n \";
}" );

    return 0;
}

// This function calls a PERL subroutine defined in the 
//   'perlfile' supplied to the PLInit() function.
PLCall( char **&AS, char *perl_function_name, ... );

// Other functions such as PLEval(), etc. go here....


C program testing PLInit() ( test.cpp )
=====================================
PLInit( "t.pl" );
char **AS
PLCall( AS, "TestFunc", .... );

This and all other functions work fine and I am able to see all the 
functions from t.pl recognized and listed by PLInit().

Java program testing PLInit() ( test.java )
=====================================
jp perlobj = new jp( "t.pl" );  // Implicit call to PLInit()
perlobj.PLCallScalar( "TestFunc", .... );  // Implicit call to PLCall()

This DOES NOT WORK!!!. I do not see any functions listed by PLInit() ( I 
get a success(0) return-value from perl_parse() though ). Obviously, 
since there are no functions recognized ( or imported ) I get a PERL
error message:
"Undefined subroutine &main::TestFunc called."


I guess there must be something with the JVM ( or JNI ) that affects the
behaviour of perl_parse(). 
I couldn't find a proper documentaion for perl_parse() except a few mutual
reference links.

Any help is highly appreciated.


Thanks,
Sathish Duraisamy
    

Reply via email to