Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ testexc: $(TESTSDIR)/testexc.c
testexcrun: $(TESTSDIR)/testexcrun.c
gcc -o $(TESTSDIR)/testexcrun $(TESTSDIR)/testexcrun.c -lscript $(LDFLAGS) $(CPPFLAGS)

tests: test1 testcall testexc testexcrun
testmul: $(TESTSDIR)/testmul.c
gcc -o $(TESTSDIR)/testmul $(TESTSDIR)/testmul.c -lscript $(LDFLAGS) $(CPPFLAGS)

tests: test1 testcall testexc testexcrun testmul
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/test1 $(TESTSDIR)/test1.lua
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/test1 $(TESTSDIR)/test1.py
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/test1 $(TESTSDIR)/test1.rb
Expand All @@ -75,6 +78,7 @@ tests: test1 testcall testexc testexcrun
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/testexc $(TESTSDIR)/testexc.lua
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/testexc $(TESTSDIR)/testexc.py
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/testexcrun $(TESTSDIR)/testexcrun.pl
LD_LIBRARY_PATH=$(BUILD_LIBDIR) $(TESTSDIR)/testmul $(TESTSDIR)/testmul.pl

clean:
rm -rf build
Expand Down
2 changes: 1 addition & 1 deletion libscript-lua/configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

AC_PREREQ(2.59)
AC_INIT([libscript-lua], [1.0], [hisham@inf.puc-rio.br])
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_SRCDIR([src/libscript-lua.c])
AC_CONFIG_HEADER([config.h])

Expand Down
4 changes: 2 additions & 2 deletions libscript-perl/configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

AC_PREREQ(2.59)
AC_INIT([libscript-perl], [1.0], [hisham@inf.puc-rio.br])
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_SRCDIR([src/libscript-perl.c])
AC_CONFIG_HEADER([config.h])

Expand All @@ -14,7 +14,7 @@ AC_PROG_CC

AC_PERL_DEVEL

AC_PERL_DEFINE_CHECK([usemultiplicity], , AC_MSG_ERROR([Perl was compiled without the -Dusemultiplicity flag.]))
AC_PERL_DEFINE_CHECK([usemultiplicity], ,AC_DEFINE([P_DONT_USE_MULTIPLICITY], [1], [Perl was compiled without the -Dusemultiplicity flag.]) )

#AC_CHECK_LIB([script], [script_init], , AC_MSG_ERROR([Could not find suitable LibScript library.]))

Expand Down
22 changes: 22 additions & 0 deletions libscript-perl/src/libscript-perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

#include <EXTERN.h>
#include <perl.h>


#include "libscript-perl.h"
#include "config.h"


EXTERN_C void xs_init(pTHX);

#define LEN_CODE 1024

#if P_DONT_USE_MULTIPLICITY
static char script_perl_state_exists = 0;
#endif

char* script_perl_make_package_name(const char* name) {
int name_size = strlen(name) + 1;
char* package_name = malloc(name_size);
Expand All @@ -19,6 +26,14 @@ char* script_perl_make_package_name(const char* name) {
}

script_plugin_state script_plugin_init_perl(script_env* env) {

#if P_DONT_USE_MULTIPLICITY
if(script_perl_state_exists) {
script_set_error_message(env, "System does not support multiple instances of Perl.");
return NULL;
}
#endif

/* Has to be called "my_perl" because the
PL_perl_destruct_level macro expects it... */
char* package_name;
Expand Down Expand Up @@ -49,16 +64,23 @@ script_plugin_state script_plugin_init_perl(script_env* env) {
free(package_name);
Perl_eval_pv(my_perl, code, TRUE);

#if P_DONT_USE_MULTIPLICITY
script_perl_state_exists = 1;
#endif
return (script_plugin_state) my_perl;
}

void script_plugin_done_perl(script_perl_state state) {

PerlInterpreter* my_perl = (PerlInterpreter*) state;
PERL_SET_CONTEXT(my_perl);

PL_perl_destruct_level = 1;
perl_destruct(my_perl);
perl_free(my_perl);
#if P_DONT_USE_MULTIPLICITY
script_perl_state_exists = 0;
#endif
}

script_err script_plugin_run_perl(script_perl_state state, char* programtext) {
Expand Down
2 changes: 1 addition & 1 deletion libscript-python/configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

AC_PREREQ(2.59)
AC_INIT([libscript-python], [1.0], [hisham@inf.puc-rio.br])
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_SRCDIR([src/libscript-python.c])
AC_CONFIG_HEADER([config.h])

Expand Down
2 changes: 1 addition & 1 deletion libscript-ruby/configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

AC_INIT([libscript-ruby], [1.0], [hisham@inf.puc-rio.br])
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_SRCDIR([src/libscript-ruby.c])
AC_CONFIG_HEADER([config.h])

Expand Down
2 changes: 1 addition & 1 deletion libscript/configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

AC_PREREQ(2.59)
AC_INIT([libscript], [1.0], [hisham@inf.puc-rio.br])
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_SRCDIR([src/libscript.c])
AC_CONFIG_HEADER([config.h])

Expand Down
2 changes: 1 addition & 1 deletion libscript/src/libscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const char* script_error_message(script_env* env) {
case SCRIPT_ERRAPI: return "API call error";
case SCRIPT_ERRFILE: return "File error";
case SCRIPT_ERRFILENOTFOUND: return "File not found";
case SCRIPT_ERRDL: return "Plugin error";
case SCRIPT_ERRDL: return (env->error_message[0] ? env->error_message : "Plugin error");
case SCRIPT_ERRDLOPEN: return "Could not open plugin";
case SCRIPT_ERRDLINVALID: return "Invalid plugin";
case SCRIPT_ERRDLCLOSE: return "Could not close plugin";
Expand Down
4 changes: 2 additions & 2 deletions libscript/src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static script_err free_plugin(script_env* env, script_plugin* plugin) {
/* FIXME: decouple finalization of states and unloading of plugins */
if (plugin->dlhandle) {
done_fn = (script_plugin_done_fn) get_symbol(plugin, "done");
if (done_fn)
if (done_fn && plugin->state)
done_fn(plugin->state);

err = lt_dlclose(plugin->dlhandle);
Expand Down Expand Up @@ -96,7 +96,7 @@ script_plugin* script_plugin_load(script_env* env, const char* id) {
init_fn = (script_plugin_init_fn) get_symbol(plugin, "init");
if (!init_fn) return fail_plugin(env, plugin, SCRIPT_ERRDLINVALID);
plugin->state = init_fn(env, env->namespace);
if (!plugin->state) return fail_plugin(env, plugin, SCRIPT_ERRLANG);
if (!plugin->state) return fail_plugin(env, plugin, SCRIPT_ERRDL);
plugin->run = (script_plugin_run_fn) get_symbol(plugin, "run");
if (!plugin->run) return fail_plugin(env, plugin, SCRIPT_ERRDLINVALID);
plugin->call = (script_plugin_call_fn) get_symbol(plugin, "call");
Expand Down
47 changes: 47 additions & 0 deletions tests/testmul.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#include <stdio.h>
#include <libscript.h>
#include <stdlib.h>


int main(int argc, char** argv) {
script_env* env1, *env2;
int err1, err2, status_code;

env1 = script_init("env1");
env2 = script_init("env2");

if (!env1 || !env2) {
printf("Could not init libscript.\n");
exit(1);
}
err1 = script_run_file(env1, argv[1]);
if (err1) {
printf("ERROR: Could not start first instance of Perl (error %d: %s).\n", err1, script_error_message(env1));
}
err2 = script_run_file(env2, argv[1]);
if (err2) {
printf("Could not start second instance of Perl (error %d: %s).\n", err2, script_error_message(env2));
printf("This is natural if your system doesn't support -Dusemultiplicity.\n");
}
script_done(env1);
script_done(env2);
printf("\n\nBoth instances of Perl have been terminated.\n\n");
env1 = script_init("env1");
env2 = script_init("env2");

if (!env1 || !env2) {
printf("Could not init libscript again.\n");
exit(1);
}
err1 = script_run_file(env1, argv[1]);
if (err1) {
printf("ERROR: Could not start first instance of Perl. (error %d: %s).\n", err1, script_error_message(env1));
}
err2 = script_run_file(env2, argv[1]);
if (err2) {
printf("Could not start second instance of Perl (error %d: %s).\n", err2, script_error_message(env2));
printf("This is natural if your system doesn't support -Dusemultiplicity.\n");
}
return err1;
}
2 changes: 2 additions & 0 deletions tests/testmul.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

print "Greetings from a new Perl instance!\n";