3 * Copyright © 2001 Novell, Inc. All Rights Reserved.
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * FILENAME : interface.c
12 * DESCRIPTION : Calling Perl APIs.
14 * Date Created : January 2001.
15 * Date Modified: July 2nd 2001.
20 #include "interface.h"
23 static void xs_init(pTHX);
25 EXTERN_C int RunPerl(int argc, char **argv, char **env);
26 EXTERN_C void Perl_nw5_init(int *argcp, char ***argvp);
27 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
30 ClsPerlHost::ClsPerlHost()
35 ClsPerlHost::~ClsPerlHost()
40 ClsPerlHost::VersionNumber()
46 ClsPerlHost::RegisterWithThreadTable()
48 return(fnRegisterWithThreadTable());
52 ClsPerlHost::UnregisterWithThreadTable()
54 return(fnUnregisterWithThreadTable());
58 ClsPerlHost::PerlCreate(PerlInterpreter *my_perl)
60 /* if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
62 perl_construct(my_perl);
68 ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
70 return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line.
74 ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
76 return(perl_run(my_perl)); // Run Perl.
80 ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
82 perl_destruct(my_perl); // Destructor for Perl.
83 perl_free(my_perl); // Free the memory allocated for Perl.
87 /*============================================================================================
93 Parameters : pTHX (IN) -
97 ==============================================================================================*/
99 static void xs_init(pTHX)
101 char *file = __FILE__;
104 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
109 int RunPerl(int argc, char **argv, char **env)
114 PerlInterpreter *my_perl = NULL; // defined in Perl.h
115 PerlInterpreter *new_perl = NULL; // defined in Perl.h
117 #ifdef PERL_GLOBAL_STRUCT
118 #define PERLVAR(var,type)
119 #define PERLVARA(var,type)
120 #define PERLVARI(var,type,init) PL_Vars.var = init;
121 #define PERLVARIC(var,type,init) PL_Vars.var = init;
123 #include "perlvars.h"
131 PERL_SYS_INIT(&argc, &argv);
133 if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
136 if(nlm.PerlCreate(my_perl))
138 PL_perl_destruct_level = 0;
140 exitstatus = nlm.PerlParse(my_perl, argc, argv, env);
143 #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing
144 new_perl = perl_clone(my_perl, 1);
146 exitstatus = perl_run(new_perl); // Run Perl.
147 PERL_SET_THX(my_perl);
149 exitstatus = nlm.PerlRun(my_perl);
152 nlm.PerlDestroy(my_perl);
158 PERL_SET_THX(new_perl);
159 nlm.PerlDestroy(new_perl);
168 // FUNCTION: AllocStdPerl
171 // Allocates a standard perl handler that other perl handlers
172 // may delegate to. You should call FreeStdPerl to free this
173 // instance when you are done with it.
175 IPerlHost* AllocStdPerl()
177 return new ClsPerlHost();
181 // FUNCTION: FreeStdPerl
184 // Frees an instance of a standard perl handler allocated by
187 void FreeStdPerl(IPerlHost* pPerlHost)
189 delete (ClsPerlHost*) pPerlHost;