Commit | Line | Data |
---|---|---|
12232b79 JH |
1 | |
2 | /* | |
cdad3b53 | 3 | * Copyright © 2001 Novell, Inc. All Rights Reserved. |
12232b79 JH |
4 | * |
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. | |
7 | * | |
8 | */ | |
9 | ||
10 | /* | |
11 | * FILENAME : interface.c | |
12 | * DESCRIPTION : Perl parsing and running functions. | |
13 | * Author : SGP | |
14 | * Date : January 2001. | |
15 | * | |
16 | */ | |
17 | ||
18 | ||
19 | ||
20 | #include "interface.h" | |
21 | ||
22 | #include "win32ish.h" // For "BOOL", "TRUE" and "FALSE" | |
23 | ||
24 | ||
25 | static void xs_init(pTHX); | |
26 | //static void xs_init(pTHXo); //(J) | |
27 | ||
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_ | |
31 | ||
32 | EXTERN_C BOOL Remove_Thread_Ctx(void); | |
33 | ||
34 | ||
35 | ClsPerlHost::ClsPerlHost() | |
36 | { | |
37 | ||
38 | } | |
39 | ||
40 | ClsPerlHost::~ClsPerlHost() | |
41 | { | |
42 | ||
43 | } | |
44 | ||
45 | ClsPerlHost::VersionNumber() | |
46 | { | |
47 | return 0; | |
48 | } | |
49 | ||
50 | int | |
51 | ClsPerlHost::PerlCreate(PerlInterpreter *my_perl) | |
52 | { | |
53 | /* if (!(my_perl = perl_alloc())) // Allocate memory for Perl. | |
54 | return (1);*/ | |
55 | perl_construct(my_perl); | |
56 | ||
57 | return 1; | |
58 | } | |
59 | ||
60 | int | |
61 | ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env) | |
62 | { | |
63 | return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line. | |
64 | } | |
65 | ||
66 | int | |
67 | ClsPerlHost::PerlRun(PerlInterpreter *my_perl) | |
68 | { | |
69 | return(perl_run(my_perl)); // Run Perl. | |
70 | } | |
71 | ||
fe2024f9 | 72 | int |
12232b79 JH |
73 | ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl) |
74 | { | |
fe2024f9 | 75 | int ret = perl_destruct(my_perl); // Destructor for Perl. |
12232b79 | 76 | //// perl_free(my_perl); // Free the memory allocated for Perl. |
fe2024f9 | 77 | return(ret); |
12232b79 JH |
78 | } |
79 | ||
80 | void | |
81 | ClsPerlHost::PerlFree(PerlInterpreter *my_perl) | |
82 | { | |
83 | perl_free(my_perl); // Free the memory allocated for Perl. | |
84 | ||
85 | // Remove the thread context set during Perl_set_context | |
86 | // This is added here since for web script there is no other place this gets executed | |
87 | // and it cannot be included into cgi2perl.xs unless this symbol is exported. | |
88 | Remove_Thread_Ctx(); | |
89 | } | |
90 | ||
91 | /*============================================================================================ | |
92 | ||
93 | Function : xs_init | |
94 | ||
95 | Description : | |
96 | ||
97 | Parameters : pTHX (IN) - | |
98 | ||
99 | Returns : Nothing. | |
100 | ||
101 | ==============================================================================================*/ | |
102 | ||
103 | static void xs_init(pTHX) | |
104 | //static void xs_init(pTHXo) //J | |
105 | { | |
106 | char *file = __FILE__; | |
107 | ||
108 | dXSUB_SYS; | |
109 | newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); | |
110 | } | |
111 | ||
112 | ||
113 | EXTERN_C | |
114 | int RunPerl(int argc, char **argv, char **env) | |
115 | { | |
116 | int exitstatus = 0; | |
117 | ClsPerlHost nlm; | |
118 | ||
119 | PerlInterpreter *my_perl = NULL; // defined in Perl.h | |
120 | PerlInterpreter *new_perl = NULL; // defined in Perl.h | |
121 | ||
122 | //__asm{int 3}; | |
12232b79 JH |
123 | |
124 | PERL_SYS_INIT(&argc, &argv); | |
125 | ||
126 | if (!(my_perl = perl_alloc())) // Allocate memory for Perl. | |
127 | return (1); | |
128 | ||
129 | if(nlm.PerlCreate(my_perl)) | |
130 | { | |
131 | PL_perl_destruct_level = 0; | |
132 | ||
fe2024f9 | 133 | if(!nlm.PerlParse(my_perl, argc, argv, env)) |
12232b79 JH |
134 | { |
135 | #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing | |
136 | # ifdef PERL_OBJECT | |
137 | CPerlHost *h = new CPerlHost(); | |
138 | new_perl = perl_clone_using(my_perl, 1, | |
139 | h->m_pHostperlMem, | |
140 | h->m_pHostperlMemShared, | |
141 | h->m_pHostperlMemParse, | |
142 | h->m_pHostperlEnv, | |
143 | h->m_pHostperlStdIO, | |
144 | h->m_pHostperlLIO, | |
145 | h->m_pHostperlDir, | |
146 | h->m_pHostperlSock, | |
147 | h->m_pHostperlProc | |
148 | ); | |
149 | CPerlObj *pPerl = (CPerlObj*)new_perl; | |
150 | # else | |
151 | new_perl = perl_clone(my_perl, 1); | |
152 | # endif | |
153 | ||
fe2024f9 | 154 | (void) perl_run(new_perl); // Run Perl. |
12232b79 JH |
155 | PERL_SET_THX(my_perl); |
156 | #else | |
fe2024f9 | 157 | (void) nlm.PerlRun(my_perl); |
12232b79 JH |
158 | #endif |
159 | } | |
fe2024f9 | 160 | exitstatus = nlm.PerlDestroy(my_perl); |
12232b79 JH |
161 | } |
162 | if(my_perl) | |
163 | nlm.PerlFree(my_perl); | |
164 | ||
165 | #ifdef USE_ITHREADS | |
166 | if (new_perl) | |
167 | { | |
168 | PERL_SET_THX(new_perl); | |
fe2024f9 | 169 | exitstatus = nlm.PerlDestroy(new_perl); |
12232b79 JH |
170 | nlm.PerlFree(my_perl); |
171 | } | |
172 | #endif | |
173 | ||
174 | PERL_SYS_TERM(); | |
175 | return exitstatus; | |
176 | } | |
177 | ||
178 | ||
179 | // FUNCTION: AllocStdPerl | |
180 | // | |
181 | // DESCRIPTION: | |
182 | // Allocates a standard perl handler that other perl handlers | |
183 | // may delegate to. You should call FreeStdPerl to free this | |
184 | // instance when you are done with it. | |
185 | // | |
186 | IPerlHost* AllocStdPerl() | |
187 | { | |
188 | return (IPerlHost*) new ClsPerlHost(); | |
189 | } | |
190 | ||
191 | ||
192 | // FUNCTION: FreeStdPerl | |
193 | // | |
194 | // DESCRIPTION: | |
195 | // Frees an instance of a standard perl handler allocated by | |
196 | // AllocStdPerl. | |
197 | // | |
198 | void FreeStdPerl(IPerlHost* pPerlHost) | |
199 | { | |
200 | if (pPerlHost) | |
201 | delete (ClsPerlHost*) pPerlHost; | |
202 | //// delete pPerlHost; | |
203 | } | |
204 |