1 #if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
5 #define PERL_NO_GET_CONTEXT
14 extern regexp* my_re_compile (pTHX_ char* exp, char* xend, PMOP* pm);
15 extern I32 my_regexec (pTHX_ regexp* prog, char* stringarg, char* strend,
16 char* strbeg, I32 minend, SV* screamer,
17 void* data, U32 flags);
19 extern char* my_re_intuit_start (pTHX_ regexp *prog, SV *sv, char *strpos,
20 char *strend, U32 flags,
21 struct re_scream_pos_data_s *data);
22 extern SV* my_re_intuit_string (pTHX_ regexp *prog);
24 extern void my_regfree (pTHX_ struct regexp* r);
25 extern SV* my_reg_numbered_buff_get(pTHX_ const REGEXP * const rx, I32 paren, SV* usesv);
26 extern SV* my_reg_named_buff_get(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags);
27 #if defined(USE_ITHREADS)
28 extern void* my_regdupe (pTHX_ const regexp *r, CLONE_PARAMS *param);
31 EXTERN_C const struct regexp_engine my_reg_engine;
35 const struct regexp_engine my_reg_engine = {
41 my_reg_numbered_buff_get,
42 my_reg_named_buff_get,
43 #if defined(USE_ITHREADS)
49 get_re_arg( pTHX_ SV *sv, U32 flags, MAGIC **mgp) {
55 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
56 SvTYPE(sv) == SVt_PVMG &&
57 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
60 return (regexp *)mg->mg_obj;
64 return ((flags && PL_curpm) ? PM_GETRE(PL_curpm) : NULL);
67 MODULE = re PACKAGE = re
72 PL_colorset = 0; /* Allow reinspection of ENV. */
73 /* PL_debug |= DEBUG_r_FLAG; */
74 XPUSHs(sv_2mortal(newSViv(PTR2IV(&my_reg_engine))));
83 if ( get_re_arg( aTHX_ sv, 0, NULL ) )
102 Checks if a reference is a regex or not. If the parameter is
103 not a ref, or is not the result of a qr// then returns false
104 in scalar context and an empty list in list context.
105 Otherwise in list context it returns the pattern and the
106 modifiers, in scalar context it returns the pattern just as it
107 would if the qr// was stringified normally, regardless as
108 to the class of the variable and any strigification overloads
112 if ( re = get_re_arg( aTHX_ sv, 0, &mg) ) /* assign deliberate */
114 /* Housten, we have a regex! */
120 if ( GIMME_V == G_ARRAY ) {
122 we are in list context so stringify
123 the modifiers that apply. We ignore "negative
124 modifiers" in this scenario.
127 char *fptr = INT_PAT_MODS;
129 U16 match_flags = (U16)((re->extflags & PMf_COMPILETIME) >> 12);
131 while((ch = *fptr++)) {
132 if(match_flags & 1) {
133 reflags[left++] = ch;
138 pattern = sv_2mortal(newSVpvn(re->precomp,re->prelen));
139 if (re->extflags & RXf_UTF8) SvUTF8_on(pattern);
141 /* return the pattern and the modifiers */
143 XPUSHs(sv_2mortal(newSVpvn(reflags,left)));
146 /* Scalar, so use the string that Perl would return */
147 /* return the pattern in (?msix:..) format */
148 pattern = sv_2mortal(newSVpvn(re->wrapped,re->wraplen));
149 if (re->extflags & RXf_UTF8)
155 /* It ain't a regexp folks */
156 if ( GIMME_V == G_ARRAY ) {
157 /* return the empty list */
160 /* Because of the (?:..) wrapping involved in a
161 stringified pattern it is impossible to get a
162 result for a real regexp that would evaluate to
163 false. Therefore we can return PL_sv_no to signify
164 that the object is not a regex, this means that one
167 if (regex($might_be_a_regex) eq '(?:foo)') { }
169 and not worry about undefined values.
186 if ( re = get_re_arg( aTHX_ sv, 0, 0) ) /* assign deliberate */
190 if (re->anchored_substr) {
191 an = newSVsv(re->anchored_substr);
192 } else if (re->anchored_utf8) {
193 an = newSVsv(re->anchored_utf8);
195 if (re->float_substr) {
196 fl = newSVsv(re->float_substr);
197 } else if (re->float_utf8) {
198 fl = newSVsv(re->float_utf8);
208 regname(sv, qr = NULL, all = NULL)
218 re = get_re_arg( aTHX_ qr, 1, NULL);
219 if (SvPOK(sv) && re && re->paren_names) {
220 bufs = CALLREG_NAMEDBUF(re,sv,all && SvTRUE(all));
222 if (all && SvTRUE(all))
225 XPUSHs(SvREFCNT_inc(bufs));
233 regnames(sv = NULL, all = NULL)
242 re = get_re_arg( aTHX_ sv, 1, NULL );
243 if (re && re->paren_names) {
244 HV *hv= re->paren_names;
245 (void)hv_iterinit(hv);
247 HE *temphe = hv_iternext_flags(hv,0);
251 SV* sv_dat = HeVAL(temphe);
252 I32 *nums = (I32*)SvPVX(sv_dat);
253 for ( i = 0; i < SvIVX(sv_dat); i++ ) {
254 if ((I32)(re->lastcloseparen) >= nums[i] &&
255 re->startp[nums[i]] != -1 &&
256 re->endp[nums[i]] != -1)
262 if (parno || (all && SvTRUE(all))) {
264 char *pv = HePV(temphe, len);
265 if ( GIMME_V == G_ARRAY )
266 XPUSHs(newSVpvn(pv,len));
274 if ( GIMME_V == G_ARRAY )
281 regnames_iterinit(sv = NULL)
288 re = get_re_arg( aTHX_ sv, 1, NULL );
289 if (re && re->paren_names) {
290 (void)hv_iterinit(re->paren_names);
291 XPUSHs(newSViv(HvTOTALKEYS(re->paren_names)));
298 regnames_iternext(sv = NULL, all = NULL)
306 re = get_re_arg( aTHX_ sv, 1, NULL );
307 if (re && re->paren_names) {
308 HV *hv= re->paren_names;
310 HE *temphe = hv_iternext_flags(hv,0);
314 SV* sv_dat = HeVAL(temphe);
315 I32 *nums = (I32*)SvPVX(sv_dat);
316 for ( i = 0; i < SvIVX(sv_dat); i++ ) {
317 if ((I32)(re->lastcloseparen) >= nums[i] &&
318 re->startp[nums[i]] != -1 &&
319 re->endp[nums[i]] != -1)
325 if (parno || (all && SvTRUE(all))) {
327 char *pv = HePV(temphe, len);
328 XPUSHs(newSVpvn(pv,len));
340 regnames_count(sv = NULL)
347 re = get_re_arg( aTHX_ sv, 1, NULL );
348 if (re && re->paren_names) {
349 XPUSHs(newSViv(HvTOTALKEYS(re->paren_names)));