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);
29 EXTERN_C BOOL Remove_Thread_Ctx(void);
32 ClsPerlHost::ClsPerlHost()
37 ClsPerlHost::~ClsPerlHost()
42 ClsPerlHost::VersionNumber()
48 ClsPerlHost::RegisterWithThreadTable()
50 return(fnRegisterWithThreadTable());
54 ClsPerlHost::UnregisterWithThreadTable()
56 return(fnUnregisterWithThreadTable());
60 ClsPerlHost::PerlCreate(PerlInterpreter *my_perl)
62 /* if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
64 perl_construct(my_perl);
65 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
71 ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
73 return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line.
77 ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
79 return(perl_run(my_perl)); // Run Perl.
83 ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
85 return(perl_destruct(my_perl)); // Destructor for Perl.
89 ClsPerlHost::PerlFree(PerlInterpreter *my_perl)
91 perl_free(my_perl); // Free the memory allocated for Perl.
93 // Remove the thread context set during Perl_set_context
94 // This is added here since for web script there is no other place this gets executed
95 // and it cannot be included into cgi2perl.xs unless this symbol is exported.
99 /*============================================================================================
105 Parameters : pTHX (IN) -
109 ==============================================================================================*/
111 static void xs_init(pTHX)
113 char *file = __FILE__;
116 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
121 int RunPerl(int argc, char **argv, char **env)
126 PerlInterpreter *my_perl = NULL; // defined in Perl.h
127 PerlInterpreter *new_perl = NULL; // defined in Perl.h
129 #ifdef PERL_GLOBAL_STRUCT
130 #define PERLVAR(prefix,var,type)
131 #define PERLVARA(prefix,var,type)
132 #define PERLVARI(prefix,var,type,init) PL_Vars.prefix##var = init;
133 #define PERLVARIC(prefix,var,type,init) PL_Vars.prefix##var = init;
135 #include "perlvars.h"
143 PERL_SYS_INIT(&argc, &argv);
145 if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
148 if(nlm.PerlCreate(my_perl))
150 PL_perl_destruct_level = 0;
152 if(!nlm.PerlParse(my_perl, argc, argv, env))
154 #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing
155 new_perl = perl_clone(my_perl, 1);
157 (void) perl_run(new_perl); // Run Perl.
158 PERL_SET_THX(my_perl);
160 (void) nlm.PerlRun(my_perl);
163 exitstatus = nlm.PerlDestroy(my_perl);
166 nlm.PerlFree(my_perl);
171 PERL_SET_THX(new_perl);
172 exitstatus = nlm.PerlDestroy(new_perl);
173 nlm.PerlFree(my_perl);
182 // FUNCTION: AllocStdPerl
185 // Allocates a standard perl handler that other perl handlers
186 // may delegate to. You should call FreeStdPerl to free this
187 // instance when you are done with it.
189 IPerlHost* AllocStdPerl()
191 return (IPerlHost*) new ClsPerlHost();
195 // FUNCTION: FreeStdPerl
198 // Frees an instance of a standard perl handler allocated by
201 void FreeStdPerl(IPerlHost* pPerlHost)
204 delete (ClsPerlHost*) pPerlHost;