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"
22 #include "win32ish.h" // For "BOOL", "TRUE" and "FALSE"
25 static void xs_init(pTHX);
26 //static void xs_init(pTHXo); //(J)
28 EXTERN_C int RunPerl(int argc, char **argv, char **env);
29 EXTERN_C void Perl_nw5_init(int *argcp, char ***argvp);
30 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); // (J) pTHXo_
32 EXTERN_C BOOL Remove_Thread_Ctx(void);
35 ClsPerlHost::ClsPerlHost()
40 ClsPerlHost::~ClsPerlHost()
45 ClsPerlHost::VersionNumber()
51 ClsPerlHost::PerlCreate(PerlInterpreter *my_perl)
53 /* if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
55 perl_construct(my_perl);
61 ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
63 return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line.
67 ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
69 return(perl_run(my_perl)); // Run Perl.
73 ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
75 perl_destruct(my_perl); // Destructor for Perl.
76 //// perl_free(my_perl); // Free the memory allocated for Perl.
80 ClsPerlHost::PerlFree(PerlInterpreter *my_perl)
82 perl_free(my_perl); // Free the memory allocated for Perl.
84 // Remove the thread context set during Perl_set_context
85 // This is added here since for web script there is no other place this gets executed
86 // and it cannot be included into cgi2perl.xs unless this symbol is exported.
90 /*============================================================================================
96 Parameters : pTHX (IN) -
100 ==============================================================================================*/
102 static void xs_init(pTHX)
103 //static void xs_init(pTHXo) //J
105 char *file = __FILE__;
108 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
113 int RunPerl(int argc, char **argv, char **env)
118 PerlInterpreter *my_perl = NULL; // defined in Perl.h
119 PerlInterpreter *new_perl = NULL; // defined in Perl.h
122 #ifdef PERL_GLOBAL_STRUCT
123 #define PERLVAR(var,type)
124 #define PERLVARA(var,type)
125 #define PERLVARI(var,type,init) PL_Vars.var = init;
126 #define PERLVARIC(var,type,init) PL_Vars.var = init;
128 #include "perlvars.h"
136 PERL_SYS_INIT(&argc, &argv);
138 if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
141 if(nlm.PerlCreate(my_perl))
143 PL_perl_destruct_level = 0;
145 exitstatus = nlm.PerlParse(my_perl, argc, argv, env);
148 #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing
150 CPerlHost *h = new CPerlHost();
151 new_perl = perl_clone_using(my_perl, 1,
153 h->m_pHostperlMemShared,
154 h->m_pHostperlMemParse,
162 CPerlObj *pPerl = (CPerlObj*)new_perl;
164 new_perl = perl_clone(my_perl, 1);
167 exitstatus = perl_run(new_perl); // Run Perl.
168 PERL_SET_THX(my_perl);
170 exitstatus = nlm.PerlRun(my_perl);
173 nlm.PerlDestroy(my_perl);
176 nlm.PerlFree(my_perl);
181 PERL_SET_THX(new_perl);
182 nlm.PerlDestroy(new_perl);
183 nlm.PerlFree(my_perl);
192 // FUNCTION: AllocStdPerl
195 // Allocates a standard perl handler that other perl handlers
196 // may delegate to. You should call FreeStdPerl to free this
197 // instance when you are done with it.
199 IPerlHost* AllocStdPerl()
201 return (IPerlHost*) new ClsPerlHost();
205 // FUNCTION: FreeStdPerl
208 // Frees an instance of a standard perl handler allocated by
211 void FreeStdPerl(IPerlHost* pPerlHost)
214 delete (ClsPerlHost*) pPerlHost;
215 //// delete pPerlHost;