summaryrefslogtreecommitdiff
path: root/universal.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2007-03-07 21:44:52 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-03-08 15:06:49 +0000
commit803059618a6e90fb614193e8cdf81c79f27d8764 (patch)
treedb5730c32d430d60f92969264750bf6e012b98b2 /universal.c
parent83a611dd5adb33872b776b40314625f3a354690b (diff)
downloadperl-803059618a6e90fb614193e8cdf81c79f27d8764.tar.gz
Re: [PATCH] Tweaks so that miniperl.exe doesnt croak while building perl.exe
Message-ID: <9b18b3110703071144t787e028s8a79fa1986624b54@mail.gmail.com> p4raw-id: //depot/perl@30517
Diffstat (limited to 'universal.c')
-rw-r--r--universal.c297
1 files changed, 297 insertions, 0 deletions
diff --git a/universal.c b/universal.c
index 4cbda94cf4..69c31f1590 100644
--- a/universal.c
+++ b/universal.c
@@ -220,6 +220,26 @@ Perl_sv_does(pTHX_ SV *sv, const char *name)
return does_it;
}
+regexp *
+Perl_get_re_arg( pTHX_ SV *sv, U32 flags, MAGIC **mgp) {
+ MAGIC *mg;
+ if (sv) {
+ if (SvMAGICAL(sv))
+ mg_get(sv);
+ if (SvROK(sv) &&
+ (sv = (SV*)SvRV(sv)) && /* assign deliberate */
+ SvTYPE(sv) == SVt_PVMG &&
+ (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
+ {
+ if (mgp) *mgp = mg;
+ return (regexp *)mg->mg_obj;
+ }
+ }
+ if (mgp) *mgp = NULL;
+ return ((flags && PL_curpm) ? PM_GETRE(PL_curpm) : NULL);
+}
+
+
PERL_XS_EXPORT_C void XS_UNIVERSAL_isa(pTHX_ CV *cv);
PERL_XS_EXPORT_C void XS_UNIVERSAL_can(pTHX_ CV *cv);
PERL_XS_EXPORT_C void XS_UNIVERSAL_DOES(pTHX_ CV *cv);
@@ -254,6 +274,12 @@ XS(XS_Internals_hash_seed);
XS(XS_Internals_rehash_seed);
XS(XS_Internals_HvREHASH);
XS(XS_Internals_inc_sub_generation);
+XS(XS_re_is_regexp);
+XS(XS_re_regname);
+XS(XS_re_regnames);
+XS(XS_re_regnames_iterinit);
+XS(XS_re_regnames_iternext);
+XS(XS_re_regnames_count);
void
Perl_boot_core_UNIVERSAL(pTHX)
@@ -306,6 +332,12 @@ Perl_boot_core_UNIVERSAL(pTHX)
newXSproto("Internals::HvREHASH", XS_Internals_HvREHASH, file, "\\%");
newXSproto("Internals::inc_sub_generation",XS_Internals_inc_sub_generation,
file, "");
+ newXSproto("re::is_regexp", XS_re_is_regexp, file, "$");
+ newXSproto("re::regname", XS_re_regname, file, ";$$$");
+ newXSproto("re::regnames", XS_re_regnames, file, ";$$");
+ newXSproto("re::regnames_iterinit", XS_re_regnames_iterinit, file, ";$");
+ newXSproto("re::regnames_iternext", XS_re_regnames_iternext, file, ";$$");
+ newXSproto("re::regnames_count", XS_re_regnames_count, file, ";$");
}
@@ -1098,6 +1130,271 @@ XS(XS_Internals_inc_sub_generation)
XSRETURN_EMPTY;
}
+XS(XS_re_is_regexp)
+{
+ dVAR;
+ dXSARGS;
+ if (items != 1)
+ Perl_croak(aTHX_ "Usage: %s(%s)", "re::is_regexp", "sv");
+ PERL_UNUSED_VAR(cv); /* -W */
+ PERL_UNUSED_VAR(ax); /* -Wall */
+ SP -= items;
+ {
+ SV * sv = ST(0);
+ if ( Perl_get_re_arg( aTHX_ sv, 0, NULL ) )
+ {
+ XSRETURN_YES;
+ } else {
+ XSRETURN_NO;
+ }
+ /* NOTREACHED */
+ PUTBACK;
+ return;
+ }
+}
+
+XS(XS_re_regname)
+{
+
+ dVAR;
+ dXSARGS;
+ if (items < 1 || items > 3)
+ Perl_croak(aTHX_ "Usage: %s(%s)", "re::regname", "sv, qr = NULL, all = NULL");
+ PERL_UNUSED_VAR(cv); /* -W */
+ PERL_UNUSED_VAR(ax); /* -Wall */
+ SP -= items;
+ {
+ SV * sv = ST(0);
+ SV * qr;
+ SV * all;
+ regexp *re = NULL;
+ SV *bufs = NULL;
+
+ if (items < 2)
+ qr = NULL;
+ else {
+ qr = ST(1);
+ }
+
+ if (items < 3)
+ all = NULL;
+ else {
+ all = ST(2);
+ }
+ {
+ re = Perl_get_re_arg( aTHX_ qr, 1, NULL);
+ if (SvPOK(sv) && re && re->paren_names) {
+ bufs = CALLREG_NAMEDBUF(re,sv,all && SvTRUE(all));
+ if (bufs) {
+ if (all && SvTRUE(all))
+ XPUSHs(newRV(bufs));
+ else
+ XPUSHs(SvREFCNT_inc(bufs));
+ XSRETURN(1);
+ }
+ }
+ XSRETURN_UNDEF;
+ }
+ PUTBACK;
+ return;
+ }
+}
+
+XS(XS_re_regnames)
+{
+ dVAR;
+ dXSARGS;
+ if (items < 0 || items > 2)
+ Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames", "sv = NULL, all = NULL");
+ PERL_UNUSED_VAR(cv); /* -W */
+ PERL_UNUSED_VAR(ax); /* -Wall */
+ SP -= items;
+ {
+ SV * sv;
+ SV * all;
+ regexp *re = NULL;
+ IV count = 0;
+
+ if (items < 1)
+ sv = NULL;
+ else {
+ sv = ST(0);
+ }
+
+ if (items < 2)
+ all = NULL;
+ else {
+ all = ST(1);
+ }
+ {
+ re = Perl_get_re_arg( aTHX_ sv, 1, NULL );
+ if (re && re->paren_names) {
+ HV *hv= re->paren_names;
+ (void)hv_iterinit(hv);
+ while (1) {
+ HE *temphe = hv_iternext_flags(hv,0);
+ if (temphe) {
+ IV i;
+ IV parno = 0;
+ SV* sv_dat = HeVAL(temphe);
+ I32 *nums = (I32*)SvPVX(sv_dat);
+ for ( i = 0; i < SvIVX(sv_dat); i++ ) {
+ if ((I32)(re->lastcloseparen) >= nums[i] &&
+ re->startp[nums[i]] != -1 &&
+ re->endp[nums[i]] != -1)
+ {
+ parno = nums[i];
+ break;
+ }
+ }
+ if (parno || (all && SvTRUE(all))) {
+ STRLEN len;
+ char *pv = HePV(temphe, len);
+ if ( GIMME_V == G_ARRAY )
+ XPUSHs(newSVpvn(pv,len));
+ count++;
+ }
+ } else {
+ break;
+ }
+ }
+ }
+ if ( GIMME_V == G_ARRAY )
+ XSRETURN(count);
+ else
+ XSRETURN_UNDEF;
+ }
+ PUTBACK;
+ return;
+ }
+}
+
+
+XS(XS_re_regnames_iterinit)
+{
+ dVAR;
+ dXSARGS;
+ if (items < 0 || items > 1)
+ Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames_iterinit", "sv = NULL");
+ PERL_UNUSED_VAR(cv); /* -W */
+ PERL_UNUSED_VAR(ax); /* -Wall */
+ SP -= items;
+ {
+ SV * sv;
+ regexp *re = NULL;
+
+ if (items < 1)
+ sv = NULL;
+ else {
+ sv = ST(0);
+ }
+ {
+ re = Perl_get_re_arg( aTHX_ sv, 1, NULL );
+ if (re && re->paren_names) {
+ (void)hv_iterinit(re->paren_names);
+ XPUSHs(newSViv(HvTOTALKEYS(re->paren_names)));
+ } else {
+ XSRETURN_UNDEF;
+ }
+ }
+ PUTBACK;
+ return;
+ }
+}
+
+
+XS(XS_re_regnames_iternext)
+{
+ dVAR;
+ dXSARGS;
+ if (items < 0 || items > 2)
+ Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames_iternext", "sv = NULL, all = NULL");
+ PERL_UNUSED_VAR(cv); /* -W */
+ PERL_UNUSED_VAR(ax); /* -Wall */
+ SP -= items;
+ {
+ SV * sv;
+ SV * all;
+ regexp *re;
+
+ if (items < 1)
+ sv = NULL;
+ else {
+ sv = ST(0);
+ }
+
+ if (items < 2)
+ all = NULL;
+ else {
+ all = ST(1);
+ }
+ {
+ re = Perl_get_re_arg( aTHX_ sv, 1, NULL );
+ if (re && re->paren_names) {
+ HV *hv= re->paren_names;
+ while (1) {
+ HE *temphe = hv_iternext_flags(hv,0);
+ if (temphe) {
+ IV i;
+ IV parno = 0;
+ SV* sv_dat = HeVAL(temphe);
+ I32 *nums = (I32*)SvPVX(sv_dat);
+ for ( i = 0; i < SvIVX(sv_dat); i++ ) {
+ if ((I32)(re->lastcloseparen) >= nums[i] &&
+ re->startp[nums[i]] != -1 &&
+ re->endp[nums[i]] != -1)
+ {
+ parno = nums[i];
+ break;
+ }
+ }
+ if (parno || (all && SvTRUE(all))) {
+ STRLEN len;
+ char *pv = HePV(temphe, len);
+ XPUSHs(newSVpvn(pv,len));
+ XSRETURN(1);
+ }
+ } else {
+ break;
+ }
+ }
+ }
+ XSRETURN_UNDEF;
+ }
+ PUTBACK;
+ return;
+ }
+}
+
+
+XS(XS_re_regnames_count)
+{
+ SV * sv;
+ regexp *re = NULL;
+ dVAR;
+ dXSARGS;
+
+ if (items < 0 || items > 1)
+ Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames_count", "sv = NULL");
+ PERL_UNUSED_VAR(cv); /* -W */
+ PERL_UNUSED_VAR(ax); /* -Wall */
+ SP -= items;
+ if (items < 1)
+ sv = NULL;
+ else {
+ sv = ST(0);
+ }
+ re = Perl_get_re_arg( aTHX_ sv, 1, NULL );
+ if (re && re->paren_names) {
+ XPUSHs(newSViv(HvTOTALKEYS(re->paren_names)));
+ } else {
+ XSRETURN_UNDEF;
+ }
+ PUTBACK;
+ return;
+}
+
+
/*
* Local variables:
* c-indentation-style: bsd