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);
56 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
62 ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
64 return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line.
68 ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
70 return(perl_run(my_perl)); // Run Perl.
74 ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
76 int ret = perl_destruct(my_perl); // Destructor for Perl.
77 //// perl_free(my_perl); // Free the memory allocated for Perl.
82 ClsPerlHost::PerlFree(PerlInterpreter *my_perl)
84 perl_free(my_perl); // Free the memory allocated for Perl.
86 // Remove the thread context set during Perl_set_context
87 // This is added here since for web script there is no other place this gets executed
88 // and it cannot be included into cgi2perl.xs unless this symbol is exported.
92 /*============================================================================================
98 Parameters : pTHX (IN) -
102 ==============================================================================================*/
104 static void xs_init(pTHX)
105 //static void xs_init(pTHXo) //J
107 char *file = __FILE__;
110 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
115 int RunPerl(int argc, char **argv, char **env)
120 PerlInterpreter *my_perl = NULL; // defined in Perl.h
121 PerlInterpreter *new_perl = NULL; // defined in Perl.h
124 #ifdef PERL_GLOBAL_STRUCT
125 #define PERLVAR(prefix,var,type)
126 #define PERLVARA(prefix,var,type)
127 #define PERLVARI(prefix,var,type,init) PL_Vars.prefix##var = init;
128 #define PERLVARIC(prefix,var,type,init) PL_Vars.prefix##var = init;
130 #include "perlvars.h"
138 PERL_SYS_INIT(&argc, &argv);
140 if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
143 if(nlm.PerlCreate(my_perl))
145 PL_perl_destruct_level = 0;
147 if(!nlm.PerlParse(my_perl, argc, argv, env))
149 #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing
151 CPerlHost *h = new CPerlHost();
152 new_perl = perl_clone_using(my_perl, 1,
154 h->m_pHostperlMemShared,
155 h->m_pHostperlMemParse,
163 CPerlObj *pPerl = (CPerlObj*)new_perl;
165 new_perl = perl_clone(my_perl, 1);
168 (void) perl_run(new_perl); // Run Perl.
169 PERL_SET_THX(my_perl);
171 (void) nlm.PerlRun(my_perl);
174 exitstatus = nlm.PerlDestroy(my_perl);
177 nlm.PerlFree(my_perl);
182 PERL_SET_THX(new_perl);
183 exitstatus = nlm.PerlDestroy(new_perl);
184 nlm.PerlFree(my_perl);
193 // FUNCTION: AllocStdPerl
196 // Allocates a standard perl handler that other perl handlers
197 // may delegate to. You should call FreeStdPerl to free this
198 // instance when you are done with it.
200 IPerlHost* AllocStdPerl()
202 return (IPerlHost*) new ClsPerlHost();
206 // FUNCTION: FreeStdPerl
209 // Frees an instance of a standard perl handler allocated by
212 void FreeStdPerl(IPerlHost* pPerlHost)
215 delete (ClsPerlHost*) pPerlHost;
216 //// delete pPerlHost;