X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=universal.c;h=ef4f5b306676e6156b589c04b2805b451321c600;hb=7f61b687036bb8a098a2e70b387919a448b7bd62;hp=ea797aea28c74a68d9c5f9909e941459bd8c9daa;hpb=55497cffdd24c959994f9a8ddd56db8ce85e1c5b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/universal.c b/universal.c index ea797ae..ef4f5b3 100644 --- a/universal.c +++ b/universal.c @@ -1,18 +1,13 @@ #include "EXTERN.h" #include "perl.h" -#include "XSUB.h" /* * Contributed by Graham Barr * The main guts of traverse_isa was actually copied from gv_fetchmeth */ -static SV * -isa_lookup(stash, name, len, level) -HV *stash; -char *name; -int len; -int level; +STATIC SV * +isa_lookup(HV *stash, char *name, int len, int level) { AV* av; GV* gv; @@ -26,7 +21,7 @@ int level; return &sv_yes; if (level > 100) - croak("Recursive inheritance detected"); + croak("Recursive inheritance detected in package '%s'", HvNAME(stash)); gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, FALSE); @@ -52,7 +47,8 @@ int level; } if(hv) { SV** svp = AvARRAY(av); - I32 items = AvFILL(av) + 1; + /* NOTE: No support for tied ISA */ + I32 items = AvFILLp(av) + 1; while (items--) { SV* sv = *svp++; HV* basestash = gv_stashsv(sv, FALSE); @@ -71,13 +67,11 @@ int level; } } - return &sv_no; + return boolSV(strEQ(name, "UNIVERSAL")); } bool -sv_derived_from(sv, name) -SV * sv ; -char * name ; +sv_derived_from(SV *sv, char *name) { SV *rv; char *type; @@ -106,6 +100,11 @@ char * name ; } +#ifdef PERL_OBJECT +#define NO_XSLOCKS +#endif /* PERL_OBJECT */ + +#include "XSUB.h" static XS(XS_UNIVERSAL_isa) @@ -120,8 +119,7 @@ XS(XS_UNIVERSAL_isa) sv = ST(0); name = (char *)SvPV(ST(1),na); - ST(0) = (sv_derived_from(sv, name) ? &sv_yes : &sv_no) ; - + ST(0) = boolSV(sv_derived_from(sv, name)); XSRETURN(1); } @@ -132,8 +130,7 @@ XS(XS_UNIVERSAL_can) SV *sv; char *name; SV *rv; - GV *gv; - CV *cvp; + HV *pkg = NULL; if (items != 2) croak("Usage: UNIVERSAL::can(object-ref, method)"); @@ -142,40 +139,22 @@ XS(XS_UNIVERSAL_can) name = (char *)SvPV(ST(1),na); rv = &sv_undef; - if(SvROK(sv) && (sv = (SV*)SvRV(sv)) && SvOBJECT(sv)) { - gv = gv_fetchmethod(SvSTASH(sv), name); - - if(gv && GvCV(gv)) { - /* If the sub is only a stub then we may have a gv to AUTOLOAD */ - GV **gvp = (GV**)hv_fetch(GvSTASH(gv), name, strlen(name), TRUE); - if(gvp && (cvp = GvCV(*gvp))) { - rv = sv_newmortal(); - sv_setsv(rv, newRV((SV*)cvp)); - } - } + if(SvROK(sv)) { + sv = (SV*)SvRV(sv); + if(SvOBJECT(sv)) + pkg = SvSTASH(sv); + } + else { + pkg = gv_stashsv(sv, FALSE); } - ST(0) = rv; - XSRETURN(1); -} - -static -XS(XS_UNIVERSAL_is_instance) -{ - dXSARGS; - ST(0) = SvROK(ST(0)) ? &sv_yes : &sv_no; - XSRETURN(1); -} - -static -XS(XS_UNIVERSAL_class) -{ - dXSARGS; - if(SvROK(ST(0)) && SvOBJECT(SvRV(ST(0)))) { - SV *sv = sv_newmortal(); - sv_setpv(sv, HvNAME(SvSTASH(SvRV(ST(0))))); - ST(0) = sv; + if (pkg) { + GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE); + if (gv && isGV(gv)) + rv = sv_2mortal(newRV((SV*)GvCV(gv))); } + + ST(0) = rv; XSRETURN(1); } @@ -188,6 +167,7 @@ XS(XS_UNIVERSAL_VERSION) GV *gv; SV *sv; char *undef; + double req; if(SvROK(ST(0))) { sv = (SV*)SvRV(ST(0)); @@ -212,23 +192,27 @@ XS(XS_UNIVERSAL_VERSION) undef = "(undef)"; } - if(items > 1 && (undef || SvNV(ST(1)) > SvNV(sv))) + if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv)))) croak("%s version %s required--this is only version %s", - HvNAME(pkg),SvPV(ST(1),na),undef ? undef : SvPV(sv,na)); + HvNAME(pkg), SvPV(ST(1),na), undef ? undef : SvPV(sv,na)); ST(0) = sv; XSRETURN(1); } +#ifdef PERL_OBJECT +#undef boot_core_UNIVERSAL +#define boot_core_UNIVERSAL CPerlObj::Perl_boot_core_UNIVERSAL +#define pPerl this +#endif + void -boot_core_UNIVERSAL() +boot_core_UNIVERSAL(void) { char *file = __FILE__; newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file); newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file); - newXS("UNIVERSAL::class", XS_UNIVERSAL_class, file); - newXS("UNIVERSAL::is_instance", XS_UNIVERSAL_is_instance, file); newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file); }