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 : Perl parsing and running functions.
14 * Date : January 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 (pTHXo_ CV* cv);
30 ClsPerlHost::ClsPerlHost()
35 ClsPerlHost::~ClsPerlHost()
40 ClsPerlHost::VersionNumber()
46 ClsPerlHost::PerlCreate(PerlInterpreter *my_perl)
48 /* if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
50 perl_construct(my_perl);
56 ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
58 return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line.
62 ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
64 return(perl_run(my_perl)); // Run Perl.
68 ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
70 perl_destruct(my_perl); // Destructor for Perl.
71 perl_free(my_perl); // Free the memory allocated for Perl.
75 /*============================================================================================
81 Parameters : pTHX (IN) -
85 ==============================================================================================*/
87 static void xs_init(pTHX)
89 char *file = __FILE__;
92 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
97 int RunPerl(int argc, char **argv, char **env)
102 PerlInterpreter *my_perl = NULL; // defined in Perl.h
103 PerlInterpreter *new_perl = NULL; // defined in Perl.h
105 #ifdef PERL_GLOBAL_STRUCT
106 #define PERLVAR(var,type)
107 #define PERLVARA(var,type)
108 #define PERLVARI(var,type,init) PL_Vars.var = init;
109 #define PERLVARIC(var,type,init) PL_Vars.var = init;
111 #include "perlvars.h"
119 PERL_SYS_INIT(&argc, &argv);
121 if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
124 if(nlm.PerlCreate(my_perl))
126 PL_perl_destruct_level = 0;
128 exitstatus = nlm.PerlParse(my_perl, argc, argv, env);
131 #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing
133 CPerlHost *h = new CPerlHost();
134 new_perl = perl_clone_using(my_perl, 1,
136 h->m_pHostperlMemShared,
137 h->m_pHostperlMemParse,
145 CPerlObj *pPerl = (CPerlObj*)new_perl;
147 new_perl = perl_clone(my_perl, 1);
150 exitstatus = perl_run(new_perl); // Run Perl.
151 PERL_SET_THX(my_perl);
153 exitstatus = nlm.PerlRun(my_perl);
156 nlm.PerlDestroy(my_perl);
162 PERL_SET_THX(new_perl);
163 nlm.PerlDestroy(new_perl);
172 // FUNCTION: AllocStdPerl
175 // Allocates a standard perl handler that other perl handlers
176 // may delegate to. You should call FreeStdPerl to free this
177 // instance when you are done with it.
179 IPerlHost* AllocStdPerl()
181 return new ClsPerlHost();
185 // FUNCTION: FreeStdPerl
188 // Frees an instance of a standard perl handler allocated by
191 void FreeStdPerl(IPerlHost* pPerlHost)
193 delete (ClsPerlHost*) pPerlHost;