3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 * 2005, 2006, 2007 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "The roots of those mountains must be roots indeed; there must be
13 * great secrets buried there which have not been discovered since the
14 * beginning." --Gandalf, relating Gollum's story
17 /* This file contains the code that implements the functions in Perl's
18 * UNIVERSAL package, such as UNIVERSAL->can().
20 * It is also used to store XS functions that need to be present in
21 * miniperl for a lack of a better place to put them. It might be
22 * clever to move them to seperate XS files which would then be pulled
23 * in by some to-be-written build process.
27 #define PERL_IN_UNIVERSAL_C
31 #include "perliol.h" /* For the PERLIO_F_XXX */
35 * Contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
36 * The main guts of traverse_isa was actually copied from gv_fetchmeth
40 S_isa_lookup(pTHX_ HV *stash, const char * const name, const HV* const name_stash)
48 /* A stash/class can go by many names (ie. User == main::User), so
49 we compare the stash itself just in case */
50 if (name_stash && ((const HV *)stash == name_stash))
53 hvname = HvNAME_get(stash);
55 if (strEQ(hvname, name))
58 if (strEQ(name, "UNIVERSAL"))
61 stash_linear_isa = mro_get_linear_isa(stash);
62 svp = AvARRAY(stash_linear_isa) + 1;
63 items = AvFILLp(stash_linear_isa);
65 SV* const basename_sv = *svp++;
66 HV* const basestash = gv_stashsv(basename_sv, 0);
68 if (ckWARN(WARN_SYNTAX))
69 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
70 "Can't locate package %"SVf" for the parents of %s",
71 SVfARG(basename_sv), hvname);
74 if(name_stash == basestash || strEQ(name, SvPVX(basename_sv)))
82 =head1 SV Manipulation Functions
84 =for apidoc sv_derived_from
86 Returns a boolean indicating whether the SV is derived from the specified class
87 I<at the C level>. To check derivation at the Perl level, call C<isa()> as a
94 Perl_sv_derived_from(pTHX_ SV *sv, const char *name)
104 type = sv_reftype(sv,0);
105 if (type && strEQ(type,name))
107 stash = SvOBJECT(sv) ? SvSTASH(sv) : NULL;
110 stash = gv_stashsv(sv, 0);
114 HV * const name_stash = gv_stashpv(name, 0);
115 return isa_lookup(stash, name, name_stash);
125 Returns a boolean indicating whether the SV performs a specific, named role.
126 The SV can be a Perl object or the name of a Perl class.
134 Perl_sv_does(pTHX_ SV *sv, const char *name)
136 const char *classname;
146 if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv))
147 || (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv))))
150 if (sv_isobject(sv)) {
151 classname = sv_reftype(SvRV(sv),TRUE);
153 classname = SvPV_nolen(sv);
156 if (strEQ(name,classname))
161 XPUSHs(sv_2mortal(newSVpv(name, 0)));
164 methodname = sv_2mortal(newSVpv("isa", 0));
165 /* ugly hack: use the SvSCREAM flag so S_method_common
166 * can figure out we're calling DOES() and not isa(),
167 * and report eventual errors correctly. --rgs */
168 SvSCREAM_on(methodname);
169 call_sv(methodname, G_SCALAR | G_METHOD);
172 does_it = SvTRUE( TOPs );
180 Perl_get_re_arg( pTHX_ SV *sv, U32 flags, MAGIC **mgp) {
186 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
187 SvTYPE(sv) == SVt_PVMG &&
188 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
191 return (regexp *)mg->mg_obj;
194 if (mgp) *mgp = NULL;
195 return ((flags && PL_curpm) ? PM_GETRE(PL_curpm) : NULL);
199 PERL_XS_EXPORT_C void XS_UNIVERSAL_isa(pTHX_ CV *cv);
200 PERL_XS_EXPORT_C void XS_UNIVERSAL_can(pTHX_ CV *cv);
201 PERL_XS_EXPORT_C void XS_UNIVERSAL_DOES(pTHX_ CV *cv);
202 PERL_XS_EXPORT_C void XS_UNIVERSAL_VERSION(pTHX_ CV *cv);
204 XS(XS_version_stringify);
205 XS(XS_version_numify);
206 XS(XS_version_normal);
208 XS(XS_version_boolean);
209 #ifdef HASATTRIBUTE_NORETURN
210 XS(XS_version_noop) __attribute__noreturn__;
214 XS(XS_version_is_alpha);
221 XS(XS_utf8_downgrade);
222 XS(XS_utf8_unicode_to_native);
223 XS(XS_utf8_native_to_unicode);
224 XS(XS_Internals_SvREADONLY);
225 XS(XS_Internals_SvREFCNT);
226 XS(XS_Internals_hv_clear_placehold);
227 XS(XS_PerlIO_get_layers);
228 XS(XS_Regexp_DESTROY);
229 XS(XS_Internals_hash_seed);
230 XS(XS_Internals_rehash_seed);
231 XS(XS_Internals_HvREHASH);
232 XS(XS_Internals_inc_sub_generation);
236 XS(XS_re_regnames_count);
237 XS(XS_Tie_Hash_NamedCapture_FETCH);
238 XS(XS_Tie_Hash_NamedCapture_STORE);
239 XS(XS_Tie_Hash_NamedCapture_DELETE);
240 XS(XS_Tie_Hash_NamedCapture_CLEAR);
241 XS(XS_Tie_Hash_NamedCapture_EXISTS);
242 XS(XS_Tie_Hash_NamedCapture_FIRSTKEY);
243 XS(XS_Tie_Hash_NamedCapture_NEXTKEY);
244 XS(XS_Tie_Hash_NamedCapture_SCALAR);
245 XS(XS_Tie_Hash_NamedCapture_flags);
248 Perl_boot_core_UNIVERSAL(pTHX)
251 static const char file[] = __FILE__;
253 newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
254 newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
255 newXS("UNIVERSAL::DOES", XS_UNIVERSAL_DOES, file);
256 newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);
258 /* register the overloading (type 'A') magic */
259 PL_amagic_generation++;
260 /* Make it findable via fetchmethod */
261 newXS("version::()", XS_version_noop, file);
262 newXS("version::new", XS_version_new, file);
263 newXS("version::(\"\"", XS_version_stringify, file);
264 newXS("version::stringify", XS_version_stringify, file);
265 newXS("version::(0+", XS_version_numify, file);
266 newXS("version::numify", XS_version_numify, file);
267 newXS("version::normal", XS_version_normal, file);
268 newXS("version::(cmp", XS_version_vcmp, file);
269 newXS("version::(<=>", XS_version_vcmp, file);
270 newXS("version::vcmp", XS_version_vcmp, file);
271 newXS("version::(bool", XS_version_boolean, file);
272 newXS("version::boolean", XS_version_boolean, file);
273 newXS("version::(nomethod", XS_version_noop, file);
274 newXS("version::noop", XS_version_noop, file);
275 newXS("version::is_alpha", XS_version_is_alpha, file);
276 newXS("version::qv", XS_version_qv, file);
278 newXS("utf8::is_utf8", XS_utf8_is_utf8, file);
279 newXS("utf8::valid", XS_utf8_valid, file);
280 newXS("utf8::encode", XS_utf8_encode, file);
281 newXS("utf8::decode", XS_utf8_decode, file);
282 newXS("utf8::upgrade", XS_utf8_upgrade, file);
283 newXS("utf8::downgrade", XS_utf8_downgrade, file);
284 newXS("utf8::native_to_unicode", XS_utf8_native_to_unicode, file);
285 newXS("utf8::unicode_to_native", XS_utf8_unicode_to_native, file);
286 newXSproto("Internals::SvREADONLY",XS_Internals_SvREADONLY, file, "\\[$%@];$");
287 newXSproto("Internals::SvREFCNT",XS_Internals_SvREFCNT, file, "\\[$%@];$");
288 newXSproto("Internals::hv_clear_placeholders",
289 XS_Internals_hv_clear_placehold, file, "\\%");
290 newXSproto("PerlIO::get_layers",
291 XS_PerlIO_get_layers, file, "*;@");
292 newXS("Regexp::DESTROY", XS_Regexp_DESTROY, file);
293 newXSproto("Internals::hash_seed",XS_Internals_hash_seed, file, "");
294 newXSproto("Internals::rehash_seed",XS_Internals_rehash_seed, file, "");
295 newXSproto("Internals::HvREHASH", XS_Internals_HvREHASH, file, "\\%");
296 newXSproto("re::is_regexp", XS_re_is_regexp, file, "$");
297 newXSproto("re::regname", XS_re_regname, file, ";$$");
298 newXSproto("re::regnames", XS_re_regnames, file, ";$");
299 newXSproto("re::regnames_count", XS_re_regnames_count, file, "");
300 newXS("Tie::Hash::NamedCapture::FETCH", XS_Tie_Hash_NamedCapture_FETCH, file);
301 newXS("Tie::Hash::NamedCapture::STORE", XS_Tie_Hash_NamedCapture_STORE, file);
302 newXS("Tie::Hash::NamedCapture::DELETE", XS_Tie_Hash_NamedCapture_DELETE, file);
303 newXS("Tie::Hash::NamedCapture::CLEAR", XS_Tie_Hash_NamedCapture_CLEAR, file);
304 newXS("Tie::Hash::NamedCapture::EXISTS", XS_Tie_Hash_NamedCapture_EXISTS, file);
305 newXS("Tie::Hash::NamedCapture::FIRSTKEY", XS_Tie_Hash_NamedCapture_FIRSTKEY, file);
306 newXS("Tie::Hash::NamedCapture::NEXTKEY", XS_Tie_Hash_NamedCapture_NEXTKEY, file);
307 newXS("Tie::Hash::NamedCapture::SCALAR", XS_Tie_Hash_NamedCapture_SCALAR, file);
308 newXS("Tie::Hash::NamedCapture::flags", XS_Tie_Hash_NamedCapture_flags, file);
319 Perl_croak(aTHX_ "Usage: UNIVERSAL::isa(reference, kind)");
321 SV * const sv = ST(0);
326 if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv))
327 || (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv))))
330 name = SvPV_nolen_const(ST(1));
332 ST(0) = boolSV(sv_derived_from(sv, name));
348 Perl_croak(aTHX_ "Usage: UNIVERSAL::can(object-ref, method)");
354 if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv))
355 || (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv))))
358 name = SvPV_nolen_const(ST(1));
367 pkg = gv_stashsv(sv, 0);
371 GV * const gv = gv_fetchmethod_autoload(pkg, name, FALSE);
373 rv = sv_2mortal(newRV((SV*)GvCV(gv)));
380 XS(XS_UNIVERSAL_DOES)
387 Perl_croak(aTHX_ "Usage: invocant->DOES(kind)");
389 SV * const sv = ST(0);
392 name = SvPV_nolen_const(ST(1));
393 if (sv_does( sv, name ))
400 XS(XS_UNIVERSAL_VERSION)
412 sv = (SV*)SvRV(ST(0));
414 Perl_croak(aTHX_ "Cannot find version of an unblessed reference");
418 pkg = gv_stashsv(ST(0), 0);
421 gvp = pkg ? (GV**)hv_fetchs(pkg, "VERSION", FALSE) : NULL;
423 if (gvp && isGV(gv = *gvp) && (sv = GvSV(gv)) && SvOK(sv)) {
424 SV * const nsv = sv_newmortal();
427 if ( !sv_derived_from(sv, "version"))
428 upg_version(sv, FALSE);
432 sv = (SV*)&PL_sv_undef;
441 const char * const name = HvNAME_get(pkg);
443 "%s does not define $%s::VERSION--version check failed",
447 "%s defines neither package nor VERSION--version check failed",
448 SvPVx_nolen_const(ST(0)) );
452 if ( !sv_derived_from(req, "version")) {
453 /* req may very well be R/O, so create a new object */
454 req = sv_2mortal( new_version(req) );
457 if ( vcmp( req, sv ) > 0 ) {
458 if ( hv_exists((HV*)SvRV(req), "qv", 2 ) ) {
459 Perl_croak(aTHX_ "%s version %"SVf" required--"
460 "this is only version %"SVf"", HvNAME_get(pkg),
461 SVfARG(vnormal(req)),
462 SVfARG(vnormal(sv)));
464 Perl_croak(aTHX_ "%s version %"SVf" required--"
465 "this is only version %"SVf"", HvNAME_get(pkg),
466 SVfARG(vstringify(req)),
467 SVfARG(vstringify(sv)));
473 if ( SvOK(sv) && sv_derived_from(sv, "version") ) {
474 ST(0) = vstringify(sv);
488 Perl_croak(aTHX_ "Usage: version::new(class, version)");
493 const char * const classname =
494 sv_isobject(ST(0)) /* get the class if called as an object method */
495 ? HvNAME(SvSTASH(SvRV(ST(0))))
496 : (char *)SvPV_nolen(ST(0));
498 if ( items == 1 || vs == &PL_sv_undef ) { /* no param or explicit undef */
499 /* create empty object */
503 else if ( items == 3 ) {
505 Perl_sv_setpvf(aTHX_ vs,"v%s",SvPV_nolen_const(ST(2)));
508 rv = new_version(vs);
509 if ( strcmp(classname,"version") != 0 ) /* inherited new() */
510 sv_bless(rv, gv_stashpv(classname, GV_ADD));
512 PUSHs(sv_2mortal(rv));
518 XS(XS_version_stringify)
524 Perl_croak(aTHX_ "Usage: version::stringify(lobj, ...)");
529 if (sv_derived_from(ST(0), "version")) {
533 Perl_croak(aTHX_ "lobj is not of type version");
535 PUSHs(sv_2mortal(vstringify(lobj)));
542 XS(XS_version_numify)
548 Perl_croak(aTHX_ "Usage: version::numify(lobj, ...)");
553 if (sv_derived_from(ST(0), "version")) {
557 Perl_croak(aTHX_ "lobj is not of type version");
559 PUSHs(sv_2mortal(vnumify(lobj)));
566 XS(XS_version_normal)
572 Perl_croak(aTHX_ "Usage: version::normal(lobj, ...)");
577 if (sv_derived_from(ST(0), "version")) {
581 Perl_croak(aTHX_ "lobj is not of type version");
583 PUSHs(sv_2mortal(vnormal(lobj)));
596 Perl_croak(aTHX_ "Usage: version::vcmp(lobj, ...)");
601 if (sv_derived_from(ST(0), "version")) {
605 Perl_croak(aTHX_ "lobj is not of type version");
611 const IV swap = (IV)SvIV(ST(2));
613 if ( ! sv_derived_from(robj, "version") )
615 robj = new_version(robj);
621 rs = newSViv(vcmp(rvs,lobj));
625 rs = newSViv(vcmp(lobj,rvs));
628 PUSHs(sv_2mortal(rs));
636 XS(XS_version_boolean)
642 Perl_croak(aTHX_ "Usage: version::boolean(lobj, ...)");
644 if (sv_derived_from(ST(0), "version")) {
645 SV * const lobj = SvRV(ST(0));
646 SV * const rs = newSViv( vcmp(lobj,new_version(newSVpvs("0"))) );
647 PUSHs(sv_2mortal(rs));
652 Perl_croak(aTHX_ "lobj is not of type version");
661 Perl_croak(aTHX_ "Usage: version::noop(lobj, ...)");
662 if (sv_derived_from(ST(0), "version"))
663 Perl_croak(aTHX_ "operation not supported with version object");
665 Perl_croak(aTHX_ "lobj is not of type version");
666 #ifndef HASATTRIBUTE_NORETURN
671 XS(XS_version_is_alpha)
677 Perl_croak(aTHX_ "Usage: version::is_alpha(lobj)");
679 if (sv_derived_from(ST(0), "version")) {
680 SV * const lobj = ST(0);
681 if ( hv_exists((HV*)SvRV(lobj), "alpha", 5 ) )
689 Perl_croak(aTHX_ "lobj is not of type version");
698 Perl_croak(aTHX_ "Usage: version::qv(ver)");
702 if ( !SvVOK(ver) ) { /* only need to do with if not already v-string */
703 SV * const rv = sv_newmortal();
704 sv_setsv(rv,ver); /* make a duplicate */
705 upg_version(rv, TRUE);
710 PUSHs(sv_2mortal(new_version(ver)));
724 Perl_croak(aTHX_ "Usage: utf8::is_utf8(sv)");
726 const SV * const sv = ST(0);
741 Perl_croak(aTHX_ "Usage: utf8::valid(sv)");
743 SV * const sv = ST(0);
745 const char * const s = SvPV_const(sv,len);
746 if (!SvUTF8(sv) || is_utf8_string((const U8*)s,len))
760 Perl_croak(aTHX_ "Usage: utf8::encode(sv)");
761 sv_utf8_encode(ST(0));
771 Perl_croak(aTHX_ "Usage: utf8::decode(sv)");
773 SV * const sv = ST(0);
774 const bool RETVAL = sv_utf8_decode(sv);
775 ST(0) = boolSV(RETVAL);
787 Perl_croak(aTHX_ "Usage: utf8::upgrade(sv)");
789 SV * const sv = ST(0);
793 RETVAL = sv_utf8_upgrade(sv);
794 XSprePUSH; PUSHi((IV)RETVAL);
799 XS(XS_utf8_downgrade)
804 if (items < 1 || items > 2)
805 Perl_croak(aTHX_ "Usage: utf8::downgrade(sv, failok=0)");
807 SV * const sv = ST(0);
808 const bool failok = (items < 2) ? 0 : (int)SvIV(ST(1));
809 const bool RETVAL = sv_utf8_downgrade(sv, failok);
811 ST(0) = boolSV(RETVAL);
817 XS(XS_utf8_native_to_unicode)
821 const UV uv = SvUV(ST(0));
825 Perl_croak(aTHX_ "Usage: utf8::native_to_unicode(sv)");
827 ST(0) = sv_2mortal(newSViv(NATIVE_TO_UNI(uv)));
831 XS(XS_utf8_unicode_to_native)
835 const UV uv = SvUV(ST(0));
839 Perl_croak(aTHX_ "Usage: utf8::unicode_to_native(sv)");
841 ST(0) = sv_2mortal(newSViv(UNI_TO_NATIVE(uv)));
845 XS(XS_Internals_SvREADONLY) /* This is dangerous stuff. */
849 SV * const sv = SvRV(ST(0));
858 else if (items == 2) {
864 /* I hope you really know what you are doing. */
869 XSRETURN_UNDEF; /* Can't happen. */
872 XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */
876 SV * const sv = SvRV(ST(0));
880 XSRETURN_IV(SvREFCNT(sv) - 1); /* Minus the ref created for us. */
881 else if (items == 2) {
882 /* I hope you really know what you are doing. */
883 SvREFCNT(sv) = SvIV(ST(1));
884 XSRETURN_IV(SvREFCNT(sv));
886 XSRETURN_UNDEF; /* Can't happen. */
889 XS(XS_Internals_hv_clear_placehold)
896 Perl_croak(aTHX_ "Usage: UNIVERSAL::hv_clear_placeholders(hv)");
898 HV * const hv = (HV *) SvRV(ST(0));
899 hv_clear_placeholders(hv);
904 XS(XS_Regexp_DESTROY)
910 XS(XS_PerlIO_get_layers)
915 if (items < 1 || items % 2 == 0)
916 Perl_croak(aTHX_ "Usage: PerlIO_get_layers(filehandle[,args])");
923 bool details = FALSE;
927 for (svp = MARK + 2; svp <= SP; svp += 2) {
928 SV * const * const varp = svp;
929 SV * const * const valp = svp + 1;
931 const char * const key = SvPV_const(*varp, klen);
935 if (klen == 5 && memEQ(key, "input", 5)) {
936 input = SvTRUE(*valp);
941 if (klen == 6 && memEQ(key, "output", 6)) {
942 input = !SvTRUE(*valp);
947 if (klen == 7 && memEQ(key, "details", 7)) {
948 details = SvTRUE(*valp);
955 "get_layers: unknown argument '%s'",
967 if (SvROK(sv) && isGV(SvRV(sv)))
970 gv = gv_fetchsv(sv, 0, SVt_PVIO);
973 if (gv && (io = GvIO(gv))) {
975 AV* const av = PerlIO_get_layers(aTHX_ input ?
976 IoIFP(io) : IoOFP(io));
978 const I32 last = av_len(av);
981 for (i = last; i >= 0; i -= 3) {
982 SV * const * const namsvp = av_fetch(av, i - 2, FALSE);
983 SV * const * const argsvp = av_fetch(av, i - 1, FALSE);
984 SV * const * const flgsvp = av_fetch(av, i, FALSE);
986 const bool namok = namsvp && *namsvp && SvPOK(*namsvp);
987 const bool argok = argsvp && *argsvp && SvPOK(*argsvp);
988 const bool flgok = flgsvp && *flgsvp && SvIOK(*flgsvp);
992 ? newSVpvn(SvPVX_const(*namsvp), SvCUR(*namsvp))
995 ? newSVpvn(SvPVX_const(*argsvp), SvCUR(*argsvp))
998 XPUSHi(SvIVX(*flgsvp));
1000 XPUSHs(&PL_sv_undef);
1005 XPUSHs(Perl_newSVpvf(aTHX_ "%"SVf"(%"SVf")",
1009 XPUSHs(Perl_newSVpvf(aTHX_ "%"SVf,
1012 XPUSHs(&PL_sv_undef);
1015 const IV flags = SvIVX(*flgsvp);
1017 if (flags & PERLIO_F_UTF8) {
1018 XPUSHs(newSVpvs("utf8"));
1035 XS(XS_Internals_hash_seed)
1038 /* Using dXSARGS would also have dITEM and dSP,
1039 * which define 2 unused local variables. */
1041 PERL_UNUSED_ARG(cv);
1042 PERL_UNUSED_VAR(mark);
1043 XSRETURN_UV(PERL_HASH_SEED);
1046 XS(XS_Internals_rehash_seed)
1049 /* Using dXSARGS would also have dITEM and dSP,
1050 * which define 2 unused local variables. */
1052 PERL_UNUSED_ARG(cv);
1053 PERL_UNUSED_VAR(mark);
1054 XSRETURN_UV(PL_rehash_seed);
1057 XS(XS_Internals_HvREHASH) /* Subject to change */
1061 PERL_UNUSED_ARG(cv);
1063 const HV * const hv = (HV *) SvRV(ST(0));
1064 if (items == 1 && SvTYPE(hv) == SVt_PVHV) {
1071 Perl_croak(aTHX_ "Internals::HvREHASH $hashref");
1079 Perl_croak(aTHX_ "Usage: %s(%s)", "re::is_regexp", "sv");
1080 PERL_UNUSED_VAR(cv); /* -W */
1081 PERL_UNUSED_VAR(ax); /* -Wall */
1085 if ( Perl_get_re_arg( aTHX_ sv, 0, NULL ) )
1097 XS(XS_re_regnames_count)
1099 REGEXP *rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1105 Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames_count", "");
1112 ret = CALLREG_NAMED_BUFF_COUNT(rx);
1133 if (items < 1 || items > 2)
1134 Perl_croak(aTHX_ "Usage: %s(%s)", "re::regname", "name[, all ]");
1138 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1143 if (items == 2 && SvTRUE(ST(1))) {
1144 flags = RXf_HASH_ALL;
1146 flags = RXf_HASH_ONE;
1148 ret = CALLREG_NAMED_BUFF_FETCH(rx, ST(0), (flags | RXf_HASH_REGNAME));
1154 XPUSHs(SvREFCNT_inc(ret));
1174 Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames", "[all]");
1176 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1181 if (items == 1 && SvTRUE(ST(0))) {
1182 flags = RXf_HASH_ALL;
1184 flags = RXf_HASH_ONE;
1189 ret = CALLREG_NAMED_BUFF_ALL(rx, (flags | RXf_HASH_REGNAMES));
1198 av = (AV*)SvRV(ret);
1199 length = av_len(av);
1201 for (i = 0; i <= length; i++) {
1202 entry = av_fetch(av, i, FALSE);
1205 Perl_croak(aTHX_ "NULL array element in re::regnames()");
1213 XS(XS_Tie_Hash_NamedCapture_FETCH)
1222 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::STORE($key, $flags)");
1224 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1231 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1232 ret = CALLREG_NAMED_BUFF_FETCH(rx, ST(1), flags);
1240 XPUSHs(SvREFCNT_inc(ret));
1247 XS(XS_Tie_Hash_NamedCapture_STORE)
1255 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::STORE($key, $value, $flags)");
1257 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1261 Perl_croak(aTHX_ PL_no_modify);
1268 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1269 CALLREG_NAMED_BUFF_STORE(rx,ST(1), ST(2), flags);
1272 XS(XS_Tie_Hash_NamedCapture_DELETE)
1276 REGEXP * rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1280 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::DELETE($key, $flags)");
1283 Perl_croak(aTHX_ PL_no_modify);
1287 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1288 CALLREG_NAMED_BUFF_DELETE(rx, ST(1), flags);
1291 XS(XS_Tie_Hash_NamedCapture_CLEAR)
1299 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::CLEAR($flags)");
1301 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1304 Perl_croak(aTHX_ PL_no_modify);
1308 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1309 CALLREG_NAMED_BUFF_CLEAR(rx, flags);
1312 XS(XS_Tie_Hash_NamedCapture_EXISTS)
1321 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::EXISTS($key, $flags)");
1323 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1330 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1331 ret = CALLREG_NAMED_BUFF_EXISTS(rx, ST(1), flags);
1340 XS(XS_Tie_Hash_NamedCapture_FIRSTKEY)
1349 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::FIRSTKEY()");
1351 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1358 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1359 ret = CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags);
1364 XPUSHs(SvREFCNT_inc(ret));
1372 XS(XS_Tie_Hash_NamedCapture_NEXTKEY)
1381 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::NEXTKEY($lastkey)");
1383 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1390 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1391 ret = CALLREG_NAMED_BUFF_NEXTKEY(rx, ST(1), flags);
1403 XS(XS_Tie_Hash_NamedCapture_SCALAR)
1412 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::SCALAR()");
1414 rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
1421 flags = (U32)INT2PTR(IV,SvIV(SvRV((SV*)ST(0))));
1422 ret = CALLREG_NAMED_BUFF_SCALAR(rx, flags);
1435 XS(XS_Tie_Hash_NamedCapture_flags)
1441 Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::flags()");
1443 XPUSHs(sv_2mortal(newSVuv(RXf_HASH_ONE)));
1444 XPUSHs(sv_2mortal(newSVuv(RXf_HASH_ALL)));
1452 * c-indentation-style: bsd
1454 * indent-tabs-mode: t
1457 * ex: set ts=8 sts=4 sw=4 noet: