epeval.c

filter: Statementstmt 0.0% 0 / 299 Branchbran 0.0% 0 / 238 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 537 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« epdom.c ↑ Summary epinit.c »
1 /*###################################################################################
2 #
3 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
4 # Embperl - Copyright (c) 2008-2015 Gerald Richter
5 # Embperl - Copyright (c) 2015-2023 actevy.io
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 # For use with Apache httpd and mod_perl, see also Apache copyright.
10 #
11 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
12 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 ###################################################################################*/
16  
17  
18 #include "ep.h"
19 #include "epmacro.h"
20  
21  
22 /*---------------------------------------------------------------------------
23 * EvalDirect
24 */
25 /*!
26 *
27 * \_en
28 * Compile and execute Perl code
29 *
30 * @param pArg Perl code to eval as SV. Can be either
31 * a string (PV) or code (CV)
32 * @param numArgs Number of arguments
33 * @param pArgs Arguments
34 * \endif
35 *
36 * \_de
37 * Compiliert Perlcode und f?hrt ihn dann direkt aus.
38 *
39 * @param pArg Perlcode der compiliert werden soll als SV.
40 * Kann entweder eine Zeichenkette (SV) oder
41 * Code (CV) sein
42 * @param numArgs Anzahl der Argumente
43 * @param pArgs Argumente
44 * \endif
45 *
46 * ------------------------------------------------------------------------ */
47  
48 0 int EvalDirect (/*i/o*/ register req * r,
49 /*in*/ SV * pArg,
50 /*in*/ int numArgs,
51 /*in*/ SV ** pArgs)
52 {
53 epTHX_ /* dTHXsem */
54 0 dSP;
55 SV * pSVErr ;
56 int num ;
57 int n ;
58  
59 0 tainted = 0 ;
60  
61 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
62 0 ▶ for (num = 0; num < numArgs; num++)
Branch: 1 branch
BranchTrueFalseTotal
for (num = 0; num < numArgs; num++) 0 0 0
63 0 ▶ XPUSHs(pArgs [num]) ; /* push pointer to argument */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pArgs [num]) ; /* push pointer to argument */ 0 0 0
64 0 PUTBACK;
65  
66 #if PERL_VERSION >= 14
67 0 n = perl_eval_sv(pArg, G_SCALAR);
68 #else
69 n = perl_eval_sv(pArg, G_SCALAR | G_KEEPERR);
70 #endif
71  
72 0 SPAGAIN;
73 0 ▶ if (n > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) 0 0 0
74 0 pSVErr = POPs;
75 0 PUTBACK;
76  
77 //delap_log_error (APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, APLOG_STATUSCODE NULL, "eval direct %s serial=%d", SvPVX(pArg), pSVErr->sv_debug_serial) ;
78  
79 0 tainted = 0 ;
80 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
81 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
82 {
83 STRLEN l ;
84 0 char * p = SvPV (pSVErr, l) ;
85 0 ▶ if (l > sizeof (r -> errdat1) - 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > sizeof (r -> errdat1) - 1) 0 0 0
86 0 l = sizeof (r -> errdat1) - 1 ;
87 0 strncpy (r -> errdat1, p, l) ;
88 0 ▶ if (l > 0 && r -> errdat1[l-1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
89 0 l-- ;
90 0 r -> errdat1[l] = '\0' ;
91
92 /* LogError (r, rcEvalErr) ; */
93  
94 0 ▶ if (SvROK (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK (pSVErr)) 0 0 0
95 {
96 0 ▶ if (r -> pErrSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> pErrSV) 0 0 0
97 0 SvREFCNT_dec(r -> pErrSV) ;
98 0 r -> pErrSV = newRV (SvRV(pSVErr)) ;
99 }
100
101 0 sv_setpv(pSVErr,"");
102 0 return rcEvalErr ;
103 }
104  
105 0 return ok ;
106 }
107  
108  
109 /*---------------------------------------------------------------------------
110 * EvalConfig
111 */
112 /*!
113 *
114 * \_en
115 * Returns a CV for the given config expresseion. Can be either
116 * a CV, a name of a Perl sub or a string which starts with "sub "
117 * in which case it is compiled.
118 *
119 * @param pSV Config code
120 * @param numArgs Number of arguments
121 * @param pArgs Arguments
122 * @param sContext give some context information for the error message
123 * @param ppCV Returns the CV
124 * \endif
125 *
126 * \_de
127 * Liefert f?r einen gegeben Konfigurationsausdruck ein CV zur?ck.
128 * Der Ausdruck kann entweder schon ein CV sein, der Name einer
129 * Perlfunktion oder eine Zeichenkette die mit "sub " anf?ngt sein,
130 * in welchem Fall der Code kompiliert wird.
131 *
132 * @param pSV Konfigurationsausdruck
133 * @param numArgs Anzahl der Argumente
134 * @param pArgs Argumente
135 * @param sContext Gibt Information ?ber das Umfeld f?r die Fehlermeldung
136 * @param ppCV Liefert die CV zur?ck
137 * \endif
138 *
139 * ------------------------------------------------------------------------ */
140  
141 0 int EvalConfig (/*i/o*/ tApp * a,
142 /*in*/ SV * pSV,
143 /*in*/ int numArgs,
144 /*in*/ SV ** pArgs,
145 /*in*/ const char * sContext,
146 /*out*/ CV ** pCV)
147 {
148 0 char * s = "Needs CodeRef" ;
149 #ifdef PERL_IMPLICIT_CONTEXT
150 pTHX = a?a -> pPerlTHX:PERL_GET_THX;
151 #endif
152 0 dSP;
153  
154 EPENTRY (EvalConfig) ;
155  
156 0 tainted = 0 ;
157  
158 0 *pCV = NULL ;
159 0 ▶ if (SvPOK (pSV))
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK (pSV)) 0 0 0
160 {
161 STRLEN l ;
162 0 s = SvPV (pSV, l) ;
163 0 ▶ if (strncmp (s, "sub ", 4) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strncmp (s, "sub ", 4) == 0) 0 0 0
164 {
165 SV * pSVErr ;
166 0 SV * pRV = NULL ;
167 int n ;
168  
169 0 n = perl_eval_sv (pSV, G_EVAL | G_SCALAR) ;
170 0 tainted = 0 ;
171  
172 0 SPAGAIN;
173 0 ▶ if (n > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) 0 0 0
174 0 pRV = POPs;
175 0 PUTBACK;
176
177 0 tainted = 0 ;
178 0 ▶ if (n > 0 && SvROK (pRV))
Branch: 2 branches
BranchTrueFalseTotal
if (n > 0 && SvROK (pRV)) 0 0 0
if (n > 0 && SvROK (pRV)) 0 0 0
179 {
180 0 *pCV = (CV *)SvRV (pRV) ;
181 0 SvREFCNT_inc (*pCV) ;
182 }
183  
184 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
185 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
186 {
187 STRLEN l ;
188 0 char * p = SvPV (pSVErr, l) ;
189
190 0 LogErrorParam (a, rcEvalErr, p, sContext) ;
191  
192 0 sv_setpv(pSVErr,"");
193 0 *pCV = NULL ;
194 0 return rcEvalErr ;
195 }
196 }
197 else
198 {
199 0 *pCV = perl_get_cv (s, 0) ;
200 0 SvREFCNT_inc (*pCV) ;
201 }
202 }
203 else
204 {
205 0 ▶ if (SvROK (pSV))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK (pSV)) 0 0 0
206 {
207 0 *pCV = (CV *)SvRV (pSV) ;
208 }
209 }
210 //del ap_log_error (APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, APLOG_STATUSCODE NULL, "eval config %s serial=%d", s, ((SV *)(*pCV))->sv_debug_serial) ;
211  
212 0 ▶ if (!*pCV || SvTYPE (*pCV) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!*pCV || SvTYPE (*pCV) != SVt_PVCV) 0 0 0
if (!*pCV || SvTYPE (*pCV) != SVt_PVCV) 0 0 0
213 {
214 0 *pCV = NULL ;
215 0 LogErrorParam (a, rcEvalErr, s, sContext) ;
216 0 return rcEvalErr ;
217 }
218 #ifdef DMALLOC
219 AddDMallocMagic (*pCV, s?s:"EvalConfig", __FILE__, __LINE__) ;
220 #endif
221  
222 0 return ok ;
223 }
224  
225  
226 /*---------------------------------------------------------------------------
227 * EvalRegEx
228 */
229 /*!
230 *
231 * \_en
232 * Returns a CV for the given regular expression.
233 *
234 * @param sRegex regular expression as string
235 * @param sContext give some context information for the error message
236 * @param ppCV Returns the CV
237 * \endif
238 *
239 * \_de
240 * Liefert f?r eine gegebenen Regul?ren Ausdruck ein CV zur?ck.
241 *
242 * @param sRegex Regul?rer Ausdruck als Zeichenkette
243 * @param sContext Gibt Information ?ber das Umfeld f?r die Fehlermeldung
244 * @param ppCV Liefert die CV zur?ck
245 * \endif
246 *
247 * ------------------------------------------------------------------------ */
248  
249 0 int EvalRegEx (/*i/o*/ tApp * a,
250 /*in*/ char * sRegex,
251 /*in*/ const char * sContext,
252 /*out*/ CV ** ppCV)
253 {
254 epaTHX_
255 SV * pSV ;
256 char * p ;
257 STRLEN l ;
258 0 SV * pRV = NULL ;
259 SV * pSVErr ;
260 char c ;
261 int n ;
262 0 dSP ;
263  
264 0 ▶ if (sRegex[0] == '!')
Branch: 1 branch
BranchTrueFalseTotal
if (sRegex[0] == '!') 0 0 0
265 {
266 0 c = '!' ;
267 0 ▶ while (isspace(*sRegex))
Branch: 1 branch
BranchTrueFalseTotal
while (isspace(*sRegex)) 0 0 0
268 0 sRegex++ ;
269 }
270 else
271 0 c = '=' ;
272
273 0 tainted = 0 ;
274 0 pSV = newSVpvf ("package Embperl::Regex ; sub { $_[0] %c~ m{%s} }", c, sRegex) ;
275 newSVpvf2(pSV) ;
276  
277 /* perl_eval_pv seems to be broken in 5.005_03!! */
278 /* p = SvPV(pSV, l) ; */
279 /* pRV = perl_eval_pv (p, 0) ; */
280  
281 0 n = perl_eval_sv (pSV, G_EVAL | G_SCALAR) ;
282 0 SvREFCNT_dec(pSV);
283 0 tainted = 0 ;
284  
285 0 SPAGAIN;
286 0 ▶ if (n > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) 0 0 0
287 0 pRV = POPs;
288 0 PUTBACK;
289
290 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
291 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
292 {
293 0 p = SvPV (pSVErr, l) ;
294  
295 0 LogErrorParam (a, rcEvalErr, p, sContext) ;
296  
297 0 sv_setpv(pSVErr,"");
298 0 *ppCV = NULL ;
299 0 return rcEvalErr ;
300 }
301  
302 0 ▶ if (n > 0 && SvROK (pRV))
Branch: 2 branches
BranchTrueFalseTotal
if (n > 0 && SvROK (pRV)) 0 0 0
if (n > 0 && SvROK (pRV)) 0 0 0
303 {
304 0 *ppCV = (CV *)SvRV (pRV) ;
305 0 SvREFCNT_inc (*ppCV) ;
306 #ifdef DMALLOC
307 AddDMallocMagic (*ppCV, sRegex?sRegex:"EvalRegEx", __FILE__, __LINE__) ;
308 #endif
309 //del ap_log_error (APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, APLOG_STATUSCODE NULL, "eval regex %s serial=%d", sRegex, ((SV *)(*ppCV))->sv_debug_serial) ;
310 }
311 else
312 0 *ppCV = NULL ;
313  
314
315  
316 0 return ok ;
317 }
318  
319  
320
321
322  
323 /* -------------------------------------------------------------------------------
324 *
325 * Eval PERL Statements into a sub
326 *
327 * in sArg Statement to eval
328 * out pRet pointer to SV contains an CV to the evaled code
329 *
330 ------------------------------------------------------------------------------- */
331  
332 0 static int EvalAll (/*i/o*/ register req * r,
333 /*in*/ const char * sArg,
334 /*in*/ int flags,
335 /*in*/ const char * sName,
336 /*out*/ SV ** pRet)
337 {
338 epTHX_ /* dTHXsem */
339 static char sFormat [] = "package %s ; %s sub %s { \n#line %d \"%s\"\n%s\n} %s%s" ;
340 static char sFormatStrict [] = "package %s ; %s use strict ; sub %s {\n#line %d \"%s\"\n%s\n} %s%s" ;
341 static char sFormatArray [] = "package %s ; %s sub %s { \n#line %d \"%s\"\n[%s]\n} %s%s" ;
342 static char sFormatStrictArray [] = "package %s ; %s use strict ; sub %s {\n#line %d \"%s\"\n[%s]\n} %s%s" ;
343 SV * pSVCmd ;
344 SV * pSVErr ;
345 int n ;
346 0 char * sRef = "" ;
347 0 char * use_utf8 = "" ;
348  
349 0 dSP;
350
351 EPENTRY (EvalAll) ;
352  
353 0 GetLineNo (r) ;
354  
355 0 ▶ if (r -> Component.Config.bDebug & dbgDefEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgDefEval) 0 0 0
356 0 ▶ lprintf (r -> pApp, "[%d]DEF: Line %d: %s\n", r -> pThread -> nPid, r -> Component.nSourceline, sArg?sArg:"<unknown>") ;
Branch: 1 branch
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]DEF: Line %d: %s\n", r -> pThread -> nPid, r -> Component.nSourceline, sArg?sArg:"<unknown>") ; 0 0 0
357  
358 0 tainted = 0 ;
359  
360 0 ▶ if (!sName)
Branch: 1 branch
BranchTrueFalseTotal
if (!sName) 0 0 0
361 0 sName = "" ;
362
363 0 ▶ if (*sName)
Branch: 1 branch
BranchTrueFalseTotal
if (*sName) 0 0 0
364 0 sRef = "; \\&" ;
365
366 0 ▶ if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0) 0 0 0
367 0 use_utf8 = "use utf8;" ;
368
369 0 ▶ if (r -> Component.bStrict)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.bStrict) 0 0 0
370 0 ▶ if ((flags & G_ARRAY) != G_SCALAR)
Branch: 1 branch
BranchTrueFalseTotal
if ((flags & G_ARRAY) != G_SCALAR) 0 0 0
371 0 pSVCmd = newSVpvf(sFormatStrictArray, r -> Component.sEvalPackage, use_utf8, sName, r -> Component.nSourceline, r -> Component.sSourcefile, sArg, sRef, sName) ;
372 else
373 0 pSVCmd = newSVpvf(sFormatStrict, r -> Component.sEvalPackage, use_utf8, sName, r -> Component.nSourceline, r -> Component.sSourcefile, sArg, sRef, sName) ;
374 else
375 0 ▶ if ((flags & G_ARRAY) != G_SCALAR)
Branch: 1 branch
BranchTrueFalseTotal
if ((flags & G_ARRAY) != G_SCALAR) 0 0 0
376 0 pSVCmd = newSVpvf(sFormatArray, r -> Component.sEvalPackage, use_utf8, sName, r -> Component.nSourceline, r -> Component.sSourcefile, sArg, sRef, sName) ;
377 else
378 0 pSVCmd = newSVpvf(sFormat, r -> Component.sEvalPackage, use_utf8, sName, r -> Component.nSourceline, r -> Component.sSourcefile, sArg, sRef, sName) ;
379 newSVpvf2(pSVCmd) ;
380  
381 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
382 #if PERL_VERSION >= 14
383 0 n = perl_eval_sv(pSVCmd, G_SCALAR);
384 #else
385 n = perl_eval_sv(pSVCmd, G_SCALAR | G_KEEPERR);
386 #endif
387 0 SvREFCNT_dec(pSVCmd);
388 0 tainted = 0 ;
389  
390 0 SPAGAIN;
391 0 ▶ if (n > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) 0 0 0
392 0 *pRet = POPs;
393 else
394 0 *pRet = NULL ;
395 0 PUTBACK;
396  
397 0 ▶ if (r -> Component.Config.bDebug & dbgMem)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgMem) 0 0 0
398 0 lprintf (r -> pApp, "[%d]SVs: %d\n", r -> pThread -> nPid, sv_count) ;
399
400 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
401 0 ▶ if (SvTRUE (pSVErr) || (n == 0 && (flags & G_DISCARD) == 0))
Branch: 3 branches
BranchTrueFalseTotal
if (SvTRUE (pSVErr) || (n == 0 && (flags & G_DISCARD) == 0)) 0 0 0
if (SvTRUE (pSVErr) || (n == 0 && (flags & G_DISCARD) == 0)) 0 0 0
if (SvTRUE (pSVErr) || (n == 0 && (flags & G_DISCARD) == 0)) 0 0 0
402 {
403 STRLEN l ;
404 0 char * p = SvPV (pSVErr, l) ;
405 0 ▶ if (l > sizeof (r -> errdat1) - 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > sizeof (r -> errdat1) - 1) 0 0 0
406 0 l = sizeof (r -> errdat1) - 1 ;
407 0 strncpy (r -> errdat1, p, l) ;
408 0 ▶ if (l > 0 && r -> errdat1[l-1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
409 0 l-- ;
410 0 r -> errdat1[l] = '\0' ;
411
412 /*if (pRet && *pRet)
413 SvREFCNT_dec (*pRet) ;
414 */
415 0 *pRet = newSVpv (r -> errdat1, 0) ;
416
417 /* LogError (r, rcEvalErr) ; */
418 0 sv_setpv(pSVErr, "");
419  
420 0 return rcEvalErr ;
421 }
422  
423 0 return ok ;
424 }
425  
426  
427  
428 /* -------------------------------------------------------------------------------
429 *
430 * Call an already evaled PERL Statement
431 *
432 * in sArg Statement to eval (only used for logging)
433 * in pSub CV which should be called
434 * out pRet pointer to SV contains the eval return
435 *
436 ------------------------------------------------------------------------------- */
437  
438  
439 0 int CallCV (/*i/o*/ register req * r,
440 /*in*/ const char * sArg,
441 /*in*/ CV * pSub,
442 /*in*/ int flags,
443 /*out*/ SV ** pRet)
444 {
445 epTHX_ /* dTHXsem */
446 int num ;
447 #ifdef TABUSED
448 int nCountUsed = r -> TableStack.State.nCountUsed ;
449 int nRowUsed = r -> TableStack.State.nRowUsed ;
450 int nColUsed = r -> TableStack.State.nColUsed ;
451 #endif
452 SV * pSVErr ;
453 0 dSP; /* initialize stack pointer */
454  
455  
456 0 ▶ if (r -> Component.pImportStash)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pImportStash) 0 0 0
457 { /* do not execute any code on import */
458 0 *pRet = NULL ;
459 0 return ok ;
460 }
461
462  
463 EPENTRY (CallCV) ;
464  
465 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
466 0 ▶ lprintf (r -> pApp, "[%d]EVAL< %s\n", r -> pThread -> nPid, sArg?sArg:"<unknown>") ;
Branch: 1 branch
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]EVAL< %s\n", r -> pThread -> nPid, sArg?sArg:"<unknown>") ; 0 0 0
467  
468 0 tainted = 0 ;
469  
470 0 ENTER ;
471 0 SAVETMPS ;
472 0 ▶ PUSHMARK(sp); /* remember the stack pointer */
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); /* remember the stack pointer */ 0 0 0
473  
474 0 num = perl_call_sv ((SV *)pSub, flags | G_EVAL | G_NOARGS) ; /* call the function */
475 0 tainted = 0 ;
476  
477 0 SPAGAIN; /* refresh stack pointer */
478
479 0 ▶ if (r -> Component.Config.bDebug & dbgMem)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgMem) 0 0 0
480 0 lprintf (r -> pApp, "[%d]SVs: %d\n", r -> pThread -> nPid, sv_count) ;
481 /* pop the return value from stack */
482 0 ▶ if (num == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (num == 1) 0 0 0
483 {
484 0 *pRet = POPs ;
485 0 ▶ if (SvTYPE (*pRet) == SVt_PVMG)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE (*pRet) == SVt_PVMG) 0 0 0
486 { /* variable is magicaly -> fetch value now */
487 0 SV * pSV = newSVsv (*pRet) ;
488 0 *pRet = pSV ;
489 }
490 else
491 0 SvREFCNT_inc (*pRet) ;
492  
493 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
494 {
495 0 ▶ if (SvOK (*pRet))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (*pRet)) 0 0 0
496 0 lprintf (r -> pApp, "[%d]EVAL> %s\n", r -> pThread -> nPid, SvPV (*pRet, na)) ;
497 else
498 0 lprintf (r -> pApp, "[%d]EVAL> <undefined>\n", r -> pThread -> nPid) ;
499 }
500
501 #ifdef TABUSED
502 if ((nCountUsed != r -> TableStack.State.nCountUsed ||
503 nColUsed != r -> TableStack.State.nColUsed ||
504 nRowUsed != r -> TableStack.State.nRowUsed) &&
505 !SvOK (*pRet))
506 {
507 r -> TableStack.State.nResult = 0 ;
508 SvREFCNT_dec (*pRet) ;
509 *pRet = newSVpv("", 0) ;
510 }
511  
512 if ((r -> Component.Config.bDebug & dbgTab) &&
513 (r -> TableStack.State.nCountUsed ||
514 r -> TableStack.State.nColUsed ||
515 r -> TableStack.State.nRowUsed))
516 lprintf (r -> pApp, "[%d]TAB: nResult = %d\n", r -> pThread -> nPid, r -> TableStack.State.nResult) ;
517 #ifdef DMALLOC
518 AddDMallocMagic (*pRet, sArg?sArg:"CallCV", __FILE__, __LINE__) ;
519 #endif
520 #endif
521 }
522 0 ▶ else if (num == 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (num == 0) 0 0 0
523 {
524 0 *pRet = NULL ;
525 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
526 0 lprintf (r -> pApp, "[%d]EVAL> <NULL>\n", r -> pThread -> nPid) ;
527 }
528 else
529 {
530 0 *pRet = &sv_undef ;
531 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
532 0 lprintf (r -> pApp, "[%d]EVAL> returns %d args instead of one\n", r -> pThread -> nPid, num) ;
533 }
534  
535 /*if (SvREFCNT(*pRet) != 2)
536 lprintf (r -> pApp, "[%d]EVAL refcnt != 2 !!= %d !!!!!\n", r -> pThread -> nPid, SvREFCNT(*pRet)) ;*/
537  
538 0 PUTBACK;
539 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
540 0 LEAVE ;
541  
542 0 ▶ if (r -> bExit || r -> Component.bExit)
Branch: 2 branches
BranchTrueFalseTotal
if (r -> bExit || r -> Component.bExit) 0 0 0
if (r -> bExit || r -> Component.bExit) 0 0 0
543 {
544 0 ▶ if (*pRet)
Branch: 1 branch
BranchTrueFalseTotal
if (*pRet) 0 0 0
545 0 SvREFCNT_dec (*pRet) ;
546 0 *pRet = NULL ;
547 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
548 0 lprintf (r -> pApp, "[%d]EVAL> exit passed through\n", r -> pThread -> nPid) ;
549 0 return rcExit ;
550 }
551
552 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
553 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
554 {
555 STRLEN l ;
556 char * p ;
557  
558 0 p = SvPV (pSVErr, l) ;
559 0 ▶ if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0)
Branch: 3 branches
BranchTrueFalseTotal
if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0) 0 0 0
if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0) 0 0 0
if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0) 0 0 0
560 {
561 /* On an Apache::exit call, the function croaks with error having 'U' magic.
562 * When we get this return, we'll just give up and quit this file completely,
563 * without error. */
564
565 /*struct magic * m = SvMAGIC (pSVErr) ;*/
566  
567 0 tDomTree * pDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
568 0 tIndex n = ArrayGetSize (r -> pApp, pDomTree -> pCheckpoints) ;
569 0 ▶ if (n > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 2) 0 0 0
570 0 DomTree_checkpoint (r, n-1) ;
571  
572 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
573 0 lprintf (r -> pApp, "[%d]EVAL> exit called\n", r -> pThread -> nPid) ;
574
575 0 sv_setpv(pSVErr,"");
576  
577 0 r -> Component.Config.bOptions |= optNoUncloseWarn ;
578 0 r -> bExit = 1 ;
579  
580 0 return rcExit ;
581 }
582  
583 0 ▶ if (l > sizeof (r -> errdat1) - 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > sizeof (r -> errdat1) - 1) 0 0 0
584 0 l = sizeof (r -> errdat1) - 1 ;
585 0 strncpy (r -> errdat1, p, l) ;
586 0 ▶ if (l > 0 && r -> errdat1[l-1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
587 0 l-- ;
588 0 r -> errdat1[l] = '\0' ;
589  
590 0 ▶ if (SvROK (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK (pSVErr)) 0 0 0
591 {
592 0 ▶ if (r -> pErrSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> pErrSV) 0 0 0
593 0 SvREFCNT_dec(r -> pErrSV) ;
594 0 r -> pErrSV = newRV (SvRV(pSVErr)) ;
595 }
596
597
598 0 LogError (r, rcEvalErr) ;
599  
600 0 sv_setpv(pSVErr,"");
601  
602 0 return rcEvalErr ;
603 }
604  
605
606 0 return ok ;
607 }
608  
609 /* -------------------------------------------------------------------------------
610 *
611 * Eval PERL Statements and setup the correct return value/error message
612 *
613 * in sArg Statement to eval
614 * out ppSV pointer to an SV with should be set to CV of the evaled code
615 *
616 ------------------------------------------------------------------------------- */
617  
618  
619 0 int EvalOnly (/*i/o*/ register req * r,
620 /*in*/ const char * sArg,
621 /*in*/ SV ** ppSV,
622 /*in*/ int flags,
623 /*in*/ const char * sName)
624  
625  
626  
627 {
628 int rc ;
629 SV * pSub ;
630 epTHX_
631
632 EPENTRY (EvalOnly) ;
633  
634 0 r -> lastwarn[0] = '\0' ;
635
636 0 rc = EvalAll (r, sArg, flags, sName, &pSub) ;
637  
638 0 ▶ if (rc == ok && (flags & G_DISCARD))
Branch: 2 branches
BranchTrueFalseTotal
if (rc == ok && (flags & G_DISCARD)) 0 0 0
if (rc == ok && (flags & G_DISCARD)) 0 0 0
639 {
640 0 ▶ if (pSub)
Branch: 1 branch
BranchTrueFalseTotal
if (pSub) 0 0 0
641 0 SvREFCNT_dec (pSub) ;
642 0 return ok ;
643 }
644  
645 0 ▶ if (ppSV && *ppSV)
Branch: 2 branches
BranchTrueFalseTotal
if (ppSV && *ppSV) 0 0 0
if (ppSV && *ppSV) 0 0 0
646 0 SvREFCNT_dec (*ppSV) ;
647  
648 0 ▶ if (rc == ok && pSub != NULL && SvROK (pSub))
Branch: 3 branches
BranchTrueFalseTotal
if (rc == ok && pSub != NULL && SvROK (pSub)) 0 0 0
if (rc == ok && pSub != NULL && SvROK (pSub)) 0 0 0
if (rc == ok && pSub != NULL && SvROK (pSub)) 0 0 0
649 {
650 /*sv_setsv (*ppSV, pSub) ;*/
651 0 *ppSV = SvRV(pSub) ;
652 0 SvREFCNT_inc (*ppSV) ;
653 }
654 else
655 {
656 0 ▶ if (pSub != NULL && SvTYPE (pSub) == SVt_PV)
Branch: 2 branches
BranchTrueFalseTotal
if (pSub != NULL && SvTYPE (pSub) == SVt_PV) 0 0 0
if (pSub != NULL && SvTYPE (pSub) == SVt_PV) 0 0 0
657 {
658 0 *ppSV = pSub ; /* save error message */
659 0 pSub = NULL ;
660 }
661 0 ▶ else if (r -> lastwarn[0] != '\0')
Branch: 1 branch
BranchTrueFalseTotal
else if (r -> lastwarn[0] != '\0') 0 0 0
662 {
663 0 *ppSV = newSVpv (r -> lastwarn, 0) ;
664 }
665 else
666 {
667 0 *ppSV = newSVpv ("Compile Error", 0) ;
668 }
669
670 0 ▶ if (pSub)
Branch: 1 branch
BranchTrueFalseTotal
if (pSub) 0 0 0
671 0 SvREFCNT_dec (pSub) ;
672  
673 0 r -> bError = 1 ;
674 0 return rc ;
675 }
676  
677 0 return ok ;
678 }
679  
680 #if 0
681 /* -------------------------------------------------------------------------------
682 *
683 * Eval PERL Statements and execute the evaled code
684 *
685 * in sArg Statement to eval
686 * out ppSV pointer to an SV with should be set to CV of the evaled code
687 * out pRet pointer to SV contains the eval return
688 *
689 ------------------------------------------------------------------------------- */
690  
691  
692 static int EvalAndCall (/*i/o*/ register req * r,
693 /*in*/ const char * sArg,
694 /*in*/ SV ** ppSV,
695 /*in*/ int flags,
696 /*out*/ SV ** pRet)
697  
698  
699 {
700 int rc ;
701 epTHX_
702
703
704 EPENTRY (EvalAndCall) ;
705  
706 if ((rc = EvalOnly (r, sArg, ppSV, flags, "")) != ok)
707 {
708 *pRet = NULL ;
709 return rc ;
710 }
711  
712  
713 if (*ppSV && SvTYPE (*ppSV) == SVt_PVCV)
714 { /* Call the compiled eval */
715 return CallCV (r, sArg, (CV *)*ppSV, flags, pRet) ;
716 }
717
718 *pRet = NULL ;
719 r -> bError = 1 ;
720
721 if (ppSV && *ppSV)
722 SvREFCNT_dec (*ppSV) ;
723  
724 if (r -> lastwarn[0] != '\0')
725 {
726 *ppSV = newSVpv (r -> lastwarn, 0) ;
727 }
728 else
729 {
730 *ppSV = newSVpv ("Compile Error", 0) ;
731 }
732  
733 return rcEvalErr ;
734 }
735  
736 #endif
737  
738  
739 /* -------------------------------------------------------------------------------
740 *
741 * Call an already evaled PERL Statement
742 *
743 * in sArg Statement to eval (only used for logging)
744 * in pSub CV which should be called
745 * in numArgs number of arguments
746 * in pArgs args for subroutine
747 * out pRet pointer to SV contains the eval return
748 *
749 ------------------------------------------------------------------------------- */
750  
751  
752 0 int CallStoredCV (/*i/o*/ register req * r,
753 /*in*/ const char * sArg,
754 /*in*/ CV * pSub,
755 /*in*/ int numArgs,
756 /*in*/ SV ** pArgs,
757 /*in*/ int flags,
758 /*out*/ SV ** pRet)
759 {
760 epTHX_ /* dTHXsem */
761 int num ;
762 SV * pSVErr ;
763  
764 0 dSP; /* initialize stack pointer */
765  
766 EPENTRY (CallCV) ;
767  
768 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
769 0 ▶ lprintf (r -> pApp, "[%d]EVAL< %s\n", r -> pThread -> nPid, sArg?sArg:"<unknown>") ;
Branch: 1 branch
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]EVAL< %s\n", r -> pThread -> nPid, sArg?sArg:"<unknown>") ; 0 0 0
770  
771 0 tainted = 0 ;
772  
773 0 ENTER ;
774 0 SAVETMPS ;
775 0 ▶ PUSHMARK(sp); /* remember the stack pointer */
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); /* remember the stack pointer */ 0 0 0
776 0 ▶ for (num = 0; num < numArgs; num++)
Branch: 1 branch
BranchTrueFalseTotal
for (num = 0; num < numArgs; num++) 0 0 0
777 0 ▶ XPUSHs(pArgs [num]) ; /* push pointer to argument */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pArgs [num]) ; /* push pointer to argument */ 0 0 0
778 0 PUTBACK;
779  
780 0 ▶ num = perl_call_sv ((SV *)pSub, flags | G_EVAL | (numArgs?0:G_NOARGS)) ; /* call the function */
Branch: 1 branch
BranchTrueFalseTotal
num = perl_call_sv ((SV *)pSub, flags | G_EVAL | (numArgs?0:G_NOARGS)) ; /* call the function */ 0 0 0
781 0 tainted = 0 ;
782
783 0 SPAGAIN; /* refresh stack pointer */
784
785 0 ▶ if (r -> Component.Config.bDebug & dbgMem)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgMem) 0 0 0
786 0 lprintf (r -> pApp, "[%d]SVs: %d\n", r -> pThread -> nPid, sv_count) ;
787 /* pop the return value from stack */
788 0 ▶ if (num == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (num == 1) 0 0 0
789 {
790 0 *pRet = POPs ;
791 0 ▶ if (SvTYPE (*pRet) == SVt_PVMG)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE (*pRet) == SVt_PVMG) 0 0 0
792 { /* variable is magicaly -> fetch value now */
793 0 SV * pSV = newSVsv (*pRet) ;
794 0 *pRet = pSV ;
795 }
796 else
797 0 SvREFCNT_inc (*pRet) ;
798  
799 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
800 {
801 0 ▶ if (SvOK (*pRet))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (*pRet)) 0 0 0
802 0 lprintf (r -> pApp, "[%d]EVAL> %s\n", r -> pThread -> nPid, SvPV (*pRet, na)) ;
803 else
804 0 lprintf (r -> pApp, "[%d]EVAL> <undefined>\n", r -> pThread -> nPid) ;
805 }
806 #ifdef DMALLOC
807 AddDMallocMagic (*pRet, sArg?sArg:"CallStoredCV", __FILE__, __LINE__) ;
808 #endif
809 }
810 0 ▶ else if (num == 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (num == 0) 0 0 0
811 {
812 0 *pRet = NULL ;
813 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
814 0 lprintf (r -> pApp, "[%d]EVAL> <NULL>\n", r -> pThread -> nPid) ;
815 }
816 else
817 {
818 0 *pRet = &sv_undef ;
819 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
820 0 lprintf (r -> pApp, "[%d]EVAL> returns %d args instead of one\n", r -> pThread -> nPid, num) ;
821 }
822  
823 0 PUTBACK;
824 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
825 0 LEAVE ;
826  
827 /*
828 if (r -> bExit || r -> Component.bExit)
829 {
830 if (*pRet)
831 SvREFCNT_dec (*pRet) ;
832 *pRet = NULL ;
833 if (r -> Component.Config.bDebug & dbgEval)
834 lprintf (r -> pApp, "[%d]EVAL> exit passed through\n", r -> pThread -> nPid) ;
835 return rcExit ;
836 }
837 */
838  
839 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
840 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
841 {
842 STRLEN l ;
843 char * p ;
844  
845 0 p = SvPV (pSVErr, l) ;
846 0 ▶ if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0)
Branch: 3 branches
BranchTrueFalseTotal
if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0) 0 0 0
if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0) 0 0 0
if (p && l > 14 && strncmp(p, ">embperl_exit<", 14) == 0) 0 0 0
847 {
848 /* On an Apache::exit call, the function croaks with error having 'U' magic.
849 * When we get this return, we'll just give up and quit this file completely,
850 * without error. */
851
852 /*struct magic * m = SvMAGIC (pSVErr) ;*/
853 0 tDomTree * pDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
854 0 tIndex n = ArrayGetSize (r -> pApp, pDomTree -> pCheckpoints) ;
855 0 ▶ if (n > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 2) 0 0 0
856 0 DomTree_checkpoint (r, n-1) ;
857  
858 0 ▶ p = SvPV(ERRSV, l) ;
Branch: 1 branch
BranchTrueFalseTotal
p = SvPV(ERRSV, l) ; 0 0 0
859 0 ▶ if (l > 0 && strncmp (p, ">embperl_exit< request ", 23) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && strncmp (p, ">embperl_exit< request ", 23) == 0) 0 0 0
if (l > 0 && strncmp (p, ">embperl_exit< request ", 23) == 0) 0 0 0
860 0 r -> bExit = 1 ;
861
862 0 ▶ if (r -> Component.Config.bDebug & dbgEval)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgEval) 0 0 0
863 0 ▶ lprintf (r -> pApp, "[%d]EVAL> %s exit called (%s)\n", r -> pThread -> nPid, r -> bExit?"request":"component", p?p:"") ;
Branch: 2 branches
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]EVAL> %s exit called (%s)\n", r -> pThread -> nPid, r -> bExit?"request":"component", p?p:"") ; 0 0 0
lprintf (r -> pApp, "[%d]EVAL> %s exit called (%s)\n", r -> pThread -> nPid, r -> bExit?"request":"component", p?p:"") ; 0 0 0
864
865 0 sv_setpv(pSVErr,"");
866  
867 0 r -> Component.Config.bOptions |= optNoUncloseWarn ;
868 0 r -> Component.bExit = 1 ;
869  
870 0 return rcExit ;
871 }
872  
873 0 ▶ if (l > sizeof (r -> errdat1) - 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > sizeof (r -> errdat1) - 1) 0 0 0
874 0 l = sizeof (r -> errdat1) - 1 ;
875 0 strncpy (r -> errdat1, p, l) ;
876 0 ▶ if (l > 0 && r -> errdat1[l-1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
877 0 l-- ;
878 0 r -> errdat1[l] = '\0' ;
879  
880 0 ▶ if (SvROK (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK (pSVErr)) 0 0 0
881 {
882 0 ▶ if (r -> pErrSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> pErrSV) 0 0 0
883 0 SvREFCNT_dec(r -> pErrSV) ;
884 0 r -> pErrSV = newRV (SvRV(pSVErr)) ;
885 }
886
887
888 0 LogError (r, rcEvalErr) ;
889  
890 0 sv_setpv(pSVErr,"");
891  
892 0 return rcEvalErr ;
893 }
894  
895
896 0 return ok ;
897 }
898  
899 #if 0
900 #ifdef EP2
901  
902 /* -------------------------------------------------------------------------------
903 *
904 * Eval PERL Statements check if it's already compiled
905 *
906 * in sArg Statement to eval
907 * in nFilepos position von eval in file (is used to build an unique key)
908 * out pRet pointer to SV contains the eval return
909 *
910 ------------------------------------------------------------------------------- */
911  
912 int EvalStore (/*i/o*/ register req * r,
913 /*in*/ const char * sArg,
914 /*in*/ int nFilepos,
915 /*out*/ SV ** pRet)
916  
917  
918 {
919 int rc ;
920 SV ** ppSV ;
921 epTHX_
922
923
924 EPENTRY (Eval) ;
925  
926 *pRet = NULL ;
927  
928 /*if (r -> Component.Config.bDebug & dbgCacheDisable)
929 return EvalAllNoCache (r, sArg, pRet) ;
930 */
931 /* Already compiled ? */
932  
933 ppSV = hv_fetch(r -> Buf.pFile -> pCacheHash, (char *)&nFilepos, sizeof (nFilepos), 1) ;
934 if (ppSV == NULL)
935 {
936 strcpy (r -> errdat1, "CacheHash in EvalStore") ;
937 return rcHashError ;
938 }
939  
940 if (*ppSV != NULL && SvTYPE (*ppSV) == SVt_PV)
941 {
942 strncpy (r -> errdat1, SvPV(*ppSV, na), sizeof (r -> errdat1) - 1) ;
943 LogError (r, rcEvalErr) ;
944 return rcEvalErr ;
945 }
946  
947 lprintf (r -> pApp, "CV ppSV=%s type=%d\n", *ppSV?"ok":"NULL", *ppSV?SvTYPE (*ppSV):0) ;
948 if (*ppSV == NULL || SvTYPE (*ppSV) != SVt_PVCV)
949 {
950 if ((rc = EvalOnly (r, sArg, ppSV, G_SCALAR, "")) != ok)
951 {
952 *pRet = NULL ;
953 return rc ;
954 }
955 *pRet = *ppSV ;
956 return ok ;
957 }
958  
959 *pRet = *ppSV ;
960 r -> numCacheHits++ ;
961 return ok ;
962 }
963  
964  
965  
966 #endif /* EP2 */
967  
968 /* -------------------------------------------------------------------------------
969 *
970 * Eval PERL Statements and execute the evaled code, check if it's already compiled
971 *
972 * in sArg Statement to eval
973 * in nFilepos position von eval in file (is used to build an unique key)
974 * out pRet pointer to SV contains the eval return
975 *
976 ------------------------------------------------------------------------------- */
977  
978 int Eval (/*i/o*/ register req * r,
979 /*in*/ const char * sArg,
980 /*in*/ int nFilepos,
981 /*out*/ SV ** pRet)
982  
983  
984 {
985 SV ** ppSV ;
986 epTHX_
987
988
989 EPENTRY (Eval) ;
990  
991 *pRet = NULL ;
992  
993 /*if (r -> Component.Config.bDebug & dbgCacheDisable)
994 return EvalAllNoCache (r, sArg, pRet) ;
995 */
996 /* Already compiled ? */
997  
998 ppSV = hv_fetch(r -> Buf.pFile -> pCacheHash, (char *)&nFilepos, sizeof (nFilepos), 1) ;
999 if (ppSV == NULL)
1000 {
1001 strcpy (r -> errdat1, "CacheHash in Eval") ;
1002 return rcHashError ;
1003 }
1004  
1005 if (*ppSV != NULL && SvTYPE (*ppSV) == SVt_PV)
1006 {
1007 strncpy (r -> errdat1, SvPV(*ppSV, na), sizeof (r -> errdat1) - 1) ;
1008 LogError (r, rcEvalErr) ;
1009 return rcEvalErr ;
1010 }
1011  
1012 if (*ppSV == NULL || SvTYPE (*ppSV) != SVt_PVCV)
1013 return EvalAndCall (r, sArg, ppSV, G_SCALAR, pRet) ;
1014  
1015 r -> numCacheHits++ ;
1016 return CallCV (r, sArg, (CV *)*ppSV, G_SCALAR, pRet) ;
1017 }
1018  
1019  
1020 /* -------------------------------------------------------------------------------
1021 *
1022 * Eval PERL Statements and execute the evaled code, check if it's already compiled
1023 * strip off all <HTML> Tags before
1024 *
1025 * in sArg Statement to eval
1026 * in nFilepos position von eval in file (is used to build an unique key)
1027 * out pRet pointer to SV contains the eval return value
1028 *
1029 ------------------------------------------------------------------------------- */
1030  
1031  
1032 int EvalTransFlags (/*i/o*/ register req * r,
1033 /*in*/ char * sArg,
1034 /*in*/ int nFilepos,
1035 /*in*/ int flags,
1036 /*out*/ SV ** pRet)
1037  
1038  
1039 {
1040 SV ** ppSV ;
1041 epTHX_
1042
1043 EPENTRY (EvalTrans) ;
1044  
1045  
1046 *pRet = NULL ;
1047  
1048 /*
1049 if (r -> Component.Config.bDebug & dbgCacheDisable)
1050 {
1051 / * strip off all <HTML> Tags * /
1052 TransHtml (r, sArg, 0) ;
1053
1054 return EvalAllNoCache (r, sArg, pRet) ;
1055 }
1056 */
1057 /* Already compiled ? */
1058  
1059 ppSV = hv_fetch(r -> Buf.pFile -> pCacheHash, (char *)&nFilepos, sizeof (nFilepos), 1) ;
1060 if (ppSV == NULL)
1061 {
1062 strcpy (r -> errdat1, "CacheHash in EvalTransFlags") ;
1063 return rcHashError ;
1064 }
1065  
1066 if (*ppSV != NULL && SvTYPE (*ppSV) == SVt_PV)
1067 {
1068 strncpy (r -> errdat1, SvPV(*ppSV, na), sizeof (r -> errdat1) - 1) ;
1069 LogError (r, rcEvalErr) ;
1070 return rcEvalErr ;
1071 }
1072  
1073 if (*ppSV == NULL || SvTYPE (*ppSV) != SVt_PVCV)
1074 {
1075 /* strip off all <HTML> Tags */
1076 TransHtml (r, sArg, 0) ;
1077  
1078 return EvalAndCall (r, sArg, ppSV, flags, pRet) ;
1079 }
1080  
1081 r -> numCacheHits++ ;
1082
1083 return CallCV (r, sArg, (CV *)*ppSV, flags, pRet) ;
1084 }
1085  
1086  
1087 int EvalTrans (/*i/o*/ register req * r,
1088 /*in*/ char * sArg,
1089 /*in*/ int nFilepos,
1090 /*out*/ SV ** pRet)
1091
1092 {
1093 return EvalTransFlags (r, sArg, nFilepos, G_SCALAR, pRet) ;
1094 }
1095
1096
1097 /* -------------------------------------------------------------------------------
1098 *
1099 * Eval PERL Statements and execute the evaled code, check if it's already compiled
1100 * if yes do not call the code a second time
1101 * strip off all <HTML> Tags before
1102 *
1103 * in sArg Statement to eval
1104 * in nFilepos position von eval in file (is used to build an unique key)
1105 * out pRet pointer to SV contains the eval return value
1106 *
1107 ------------------------------------------------------------------------------- */
1108  
1109  
1110 int EvalTransOnFirstCall (/*i/o*/ register req * r,
1111 /*in*/ char * sArg,
1112 /*in*/ int nFilepos,
1113 /*out*/ SV ** pRet)
1114  
1115  
1116 {
1117 SV ** ppSV ;
1118 epTHX_
1119
1120 EPENTRY (EvalTrans) ;
1121  
1122  
1123 *pRet = NULL ;
1124  
1125 /* Already compiled ? */
1126  
1127 ppSV = hv_fetch(r -> Buf.pFile -> pCacheHash, (char *)&nFilepos, sizeof (nFilepos), 1) ;
1128 if (ppSV == NULL)
1129 {
1130 strcpy (r -> errdat1, "CacheHash in EvalTransOnFirstCall") ;
1131 return rcHashError ;
1132 }
1133  
1134 if (*ppSV != NULL && SvTYPE (*ppSV) == SVt_PV)
1135 {
1136 strncpy (r -> errdat1, SvPV(*ppSV, na), sizeof (r -> errdat1) - 1) ;
1137 LogError (r, rcEvalErr) ;
1138 return rcEvalErr ;
1139 }
1140  
1141 if (*ppSV == NULL || SvTYPE (*ppSV) != SVt_PVCV)
1142 {
1143 int rc ;
1144 HV * pImportStash = r -> Component.pImportStash ;
1145 r -> Component.pImportStash = NULL ; /* temporarely disable import */
1146  
1147 /* strip off all <HTML> Tags */
1148 TransHtml (r, sArg, 0) ;
1149  
1150 rc = EvalAndCall (r, sArg, ppSV, G_SCALAR, pRet) ;
1151  
1152 r -> Component.pImportStash = pImportStash ;
1153  
1154 return rc ;
1155 }
1156  
1157 r -> numCacheHits++ ;
1158
1159 return ok ; /* Do not call this a second time */
1160 }
1161  
1162  
1163 /* -------------------------------------------------------------------------------
1164 *
1165 * Eval PERL Statements into a sub, check if it's already compiled
1166 *
1167 * in sArg Statement to eval wrap into a sub
1168 * in nFilepos position von eval in file (is used to build an unique key)
1169 * in sName sub name
1170 *
1171 ------------------------------------------------------------------------------- */
1172  
1173 int EvalSub (/*i/o*/ register req * r,
1174 /*in*/ const char * sArg,
1175 /*in*/ int nFilepos,
1176 /*in*/ const char * sName)
1177  
1178  
1179 {
1180 int rc ;
1181 SV ** ppSV ;
1182 epTHX_
1183
1184
1185 EPENTRY (EvalSub) ;
1186  
1187  
1188  
1189 /* Already compiled ? */
1190  
1191 ppSV = hv_fetch(r -> Buf.pFile -> pCacheHash, (char *)&nFilepos, sizeof (nFilepos), 1) ;
1192 if (ppSV == NULL)
1193 {
1194 strcpy (r -> errdat1, "CacheHash in EvalSub") ;
1195 return rcHashError ;
1196 }
1197  
1198 if (*ppSV != NULL && SvTYPE (*ppSV) == SVt_PV)
1199 {
1200 strncpy (r -> errdat1, SvPV(*ppSV, na), sizeof (r -> errdat1) - 1) ;
1201 LogError (r, rcEvalErr) ;
1202 return rcEvalErr ;
1203 }
1204  
1205 if (*ppSV == NULL || SvTYPE (*ppSV) != SVt_PVCV)
1206 {
1207 char endc ;
1208 int len = strlen (sName) ;
1209
1210 while (len > 0 && isspace(sName[len-1]))
1211 len-- ;
1212 endc = sName[len] ;
1213 ((char *)sName)[len] = '\0' ;
1214
1215 if ((rc = EvalOnly (r, sArg, ppSV, 0, sName)) != ok)
1216 {
1217 ((char *)sName)[len] = endc ;
1218 return rc ;
1219 }
1220  
1221 if (r -> Component.pImportStash && *ppSV && SvTYPE (*ppSV) == SVt_PVCV)
1222 {
1223 hv_store (r -> Component.pExportHash, (char *)sName, len, newRV_inc(*ppSV), 0) ;
1224
1225 if (r -> Component.Config.bDebug & dbgImport)
1226 lprintf (r -> pApp, "[%d]IMP: %s -> %s (%x)\n", r -> pThread -> nPid, sName, HvNAME (r -> Component.pImportStash), *ppSV) ;
1227  
1228 /*
1229 gvp = (GV**)hv_fetch(r -> Component.pImportStash, (char *)sName, len, 1);
1230
1231 if (!gvp || *gvp == (GV*)&PL_sv_undef)
1232 {
1233 ((char *)sName)[len] = endc ;
1234 return rcHashError ;
1235 }
1236  
1237 gv = *gvp;
1238 if (SvTYPE(gv) != SVt_PVGV)
1239 gv_init(gv, r -> Component.pImportStash, (char *)sName, len, 0);
1240
1241 lprintf (r -> pApp, "sv_any=%x\n", gv -> sv_any) ;
1242
1243 SvREFCNT_dec (GvCV (gv)) ;
1244 GvCV_set (gv,(CV *)*ppSV) ;
1245 SvREFCNT_inc (*ppSV) ;
1246 */
1247 }
1248  
1249 ((char *)sName)[len] = endc ;
1250 return ok ;
1251 }
1252  
1253 r -> numCacheHits++ ;
1254 return ok ;
1255 }
1256  
1257  
1258 /* -------------------------------------------------------------------------------
1259 *
1260 * Eval PERL Statements and execute the evaled code, check if it's already compiled
1261 *
1262 * in sArg Statement to eval
1263 * in nFilepos position von eval in file (is used to build an unique key)
1264 * out pNum pointer to int, contains the eval return value
1265 *
1266 ------------------------------------------------------------------------------- */
1267  
1268  
1269  
1270 int EvalNum (/*i/o*/ register req * r,
1271 /*in*/ char * sArg,
1272 /*in*/ int nFilepos,
1273 /*out*/ int * pNum)
1274 {
1275 SV * pRet ;
1276 int n ;
1277 epTHX_
1278  
1279 EPENTRY (EvalNum) ;
1280  
1281  
1282 n = Eval (r, sArg, nFilepos, &pRet) ;
1283
1284 if (pRet)
1285 {
1286 *pNum = SvIV (pRet) ;
1287 SvREFCNT_dec (pRet) ;
1288 }
1289 else
1290 *pNum = 0 ;
1291  
1292 return ok ;
1293 }
1294
1295  
1296 /* -------------------------------------------------------------------------------
1297 *
1298 * EvalBool PERL Statements and execute the evaled code, check if it's already compiled
1299 *
1300 * in sArg Statement to eval
1301 * in nFilepos position von eval in file (is used to build an unique key)
1302 * out pTrue return 1 if evaled expression is true
1303 *
1304 ------------------------------------------------------------------------------- */
1305  
1306  
1307  
1308 int EvalBool (/*i/o*/ register req * r,
1309 /*in*/ char * sArg,
1310 /*in*/ int nFilepos,
1311 /*out*/ int * pTrue)
1312 {
1313 SV * pRet ;
1314 int rc ;
1315 epTHX_
1316  
1317 EPENTRY (EvalNum) ;
1318  
1319  
1320 rc = Eval (r, sArg, nFilepos, &pRet) ;
1321
1322 if (pRet)
1323 {
1324 *pTrue = SvTRUE (pRet) ;
1325 SvREFCNT_dec (pRet) ;
1326 }
1327 else
1328 *pTrue = 0 ;
1329  
1330 return rc ;
1331 }
1332
1333  
1334 /* -------------------------------------------------------------------------------
1335 *
1336 * EvalMain Scan file for [* ... *] and convert it to a perl program
1337 *
1338 *
1339 ------------------------------------------------------------------------------- */
1340  
1341  
1342 int EvalMain (/*i/o*/ register req * r)
1343  
1344 {
1345 int rc ;
1346 long nFilepos = -1 ;
1347 char * sProg = "" ;
1348 SV ** ppSV ;
1349 SV * pRet ;
1350 int flags = G_SCALAR ;
1351 epTHX_
1352  
1353 /* Already compiled ? */
1354  
1355 ppSV = hv_fetch(r -> Buf.pFile -> pCacheHash, (char *)&nFilepos, sizeof (nFilepos), 1) ;
1356 if (ppSV == NULL)
1357 {
1358 strcpy (r -> errdat1, "CacheHash in EvalMain") ;
1359 return rcHashError ;
1360 }
1361  
1362 if (*ppSV != NULL && SvTYPE (*ppSV) == SVt_PV)
1363 {
1364 strncpy (r -> errdat1, SvPV(*ppSV, na), sizeof (r -> errdat1) - 1) ;
1365 LogError (r, rcEvalErr) ;
1366 return rcEvalErr ;
1367 }
1368  
1369 if (*ppSV == NULL || SvTYPE (*ppSV) != SVt_PVCV)
1370 { /* Not already compiled -> build a perl frame program */
1371 char * pStart = r -> Component.pBuf ;
1372 char * pEnd = r -> Component.pEndPos ;
1373 char * pOpenBracket = r -> pConf -> pOpenBracket ;
1374 char * pCloseBracket = r -> pConf -> pCloseBracket ;
1375 int lenOpenBracket = strlen (pOpenBracket) ;
1376 int lenCloseBracket = strlen (pCloseBracket) ;
1377 char * pOpen ;
1378 char * pClose ;
1379 char buf [256] ;
1380 int nBlockNo = 1 ;
1381  
1382
1383 if (r -> sSubName && *(r -> sSubName))
1384 {
1385 int nPos = GetSubTextPos (r, r -> sSubName) ;
1386
1387 if (!nPos || pStart + nPos > pEnd || nPos < 0)
1388 {
1389 strncpy (r -> errdat1, r -> sSubName, sizeof (r -> errdat1) - 1) ;
1390 return rcSubNotFound ;
1391 }
1392 pStart += nPos ;
1393 }
1394 pOpen = pStart - 1 ;
1395
1396 do
1397 pOpen = strstr (pOpen + 1, pOpenBracket) ;
1398 while (pOpen && pOpen > pStart && pOpen[-1] == '[') ;
1399
1400
1401 if (!pOpen)
1402 { /* no top level perl blocks -> call ProcessBlock directly */
1403 ProcessBlock (r, pStart - r -> Component.pBuf, r -> Component.pEndPos - r -> Component.pBuf, 1) ;
1404 return ok ;
1405 }
1406  
1407  
1408 OutputToMemBuf (r, NULL, r -> Component.pEndPos - r -> Component.pBuf) ;
1409  
1410 while (pStart)
1411 {
1412 pClose = NULL ;
1413 if (pOpen)
1414 {
1415 if ((pClose = strstr (pOpen + lenOpenBracket, pCloseBracket)) == NULL)
1416 {
1417 strncpy (r -> errdat1, pCloseBracket, sizeof (r -> errdat1) - 1) ;
1418 return rcMissingRight ;
1419 }
1420 *pOpen = '\0' ;
1421 }
1422 else
1423 pOpen = pEnd ;
1424  
1425  
1426 sprintf (buf, "\n$___b=$_[0] -> ProcessBlock (%d,%d,%d);\ngoto \"b$___b\";\nb%d:;\n", pStart - r -> Component.pBuf, pOpen - pStart, nBlockNo, nBlockNo) ;
1427 oputs (r, buf) ;
1428 nBlockNo++ ;
1429 if (pClose)
1430 {
1431 owrite (r, pOpen + lenOpenBracket, pClose - (pOpen + lenOpenBracket)) ;
1432 pStart = pClose + lenCloseBracket ;
1433 /* skip trailing whitespaces */
1434 while (isspace(*pStart))
1435 pStart++ ;
1436 pOpen = pStart - 1 ;
1437 do
1438 pOpen = strstr (pOpen + 1, pOpenBracket) ;
1439 while (pOpen && pOpen > pStart && pOpen[-1] == '[') ;
1440 }
1441 else
1442 {
1443 pStart = NULL ;
1444 }
1445 }
1446  
1447 oputs (r, "\nb0:\n\0") ;
1448  
1449 sProg = OutputToStd (r) ;
1450 if (sProg == NULL)
1451 return rcOutOfMemory ;
1452  
1453 /* strip off all <HTML> Tags */
1454 TransHtml (r, sProg, 0) ;
1455  
1456 if ((rc = EvalAndCall (r, sProg, ppSV, flags, &pRet)) != ok)
1457 return rc ;
1458 return ok ; /* SvIV (pRet) ;*/
1459 }
1460  
1461 r -> numCacheHits++ ;
1462
1463 if ((rc = CallCV (r, sProg, (CV *)*ppSV, flags, &pRet)) != ok)
1464 return rc ;
1465 return ok ; /* SvIV (pRet) ;*/
1466 }
1467 #endif
1468  
« epdom.c ↑ Summary epinit.c »