This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
More VMS patches from Peter Prymmer.
[perl5.git] / universal.c
index 63c6910..6ccff2f 100644 (file)
@@ -73,6 +73,16 @@ S_isa_lookup(pTHX_ HV *stash, const char *name, int len, int level)
     return boolSV(strEQ(name, "UNIVERSAL"));
 }
 
+/*
+=for apidoc sv_derived_from
+
+Returns a boolean indicating whether the SV is derived from the specified
+class.  This is the function that implements C<UNIVERSAL::isa>.  It works
+for class names as well as for objects.
+
+=cut
+*/
+
 bool
 Perl_sv_derived_from(pTHX_ SV *sv, const char *name)
 {
@@ -103,9 +113,19 @@ Perl_sv_derived_from(pTHX_ SV *sv, const char *name)
  
 }
 
-#ifdef PERL_OBJECT
-#define NO_XSLOCKS
-#endif  /* PERL_OBJECT */
+void XS_UNIVERSAL_isa(pTHXo_ CV *cv);
+void XS_UNIVERSAL_can(pTHXo_ CV *cv);
+void XS_UNIVERSAL_VERSION(pTHXo_ CV *cv);
+
+void
+Perl_boot_core_UNIVERSAL(pTHX)
+{
+    char *file = __FILE__;
+
+    newXS("UNIVERSAL::isa",             XS_UNIVERSAL_isa,         file);
+    newXS("UNIVERSAL::can",             XS_UNIVERSAL_can,         file);
+    newXS("UNIVERSAL::VERSION",        XS_UNIVERSAL_VERSION,     file);
+}
 
 #include "XSUB.h"
 
@@ -120,6 +140,10 @@ XS(XS_UNIVERSAL_isa)
        Perl_croak(aTHX_ "Usage: UNIVERSAL::isa(reference, kind)");
 
     sv = ST(0);
+
+    if (!SvOK(sv) || !(SvROK(sv) || SvCUR(sv)))
+       XSRETURN_UNDEF;
+
     name = (char *)SvPV(ST(1),n_a);
 
     ST(0) = boolSV(sv_derived_from(sv, name));
@@ -139,6 +163,10 @@ XS(XS_UNIVERSAL_can)
        Perl_croak(aTHX_ "Usage: UNIVERSAL::can(object-ref, method)");
 
     sv = ST(0);
+
+    if (!SvOK(sv) || !(SvROK(sv) || SvCUR(sv)))
+       XSRETURN_UNDEF;
+
     name = (char *)SvPV(ST(1),n_a);
     rv = &PL_sv_undef;
 
@@ -169,7 +197,7 @@ XS(XS_UNIVERSAL_VERSION)
     GV *gv;
     SV *sv;
     char *undef;
-    double req;
+    NV req;
 
     if(SvROK(ST(0))) {
         sv = (SV*)SvRV(ST(0));
@@ -183,7 +211,7 @@ XS(XS_UNIVERSAL_VERSION)
 
     gvp = pkg ? (GV**)hv_fetch(pkg,"VERSION",7,FALSE) : Null(GV**);
 
-    if (gvp && (gv = *gvp) != (GV*)&PL_sv_undef && (sv = GvSV(gv))) {
+    if (gvp && isGV(gv = *gvp) && SvOK(sv = GvSV(gv))) {
         SV *nsv = sv_newmortal();
         sv_setsv(nsv, sv);
         sv = nsv;
@@ -205,18 +233,3 @@ XS(XS_UNIVERSAL_VERSION)
     XSRETURN(1);
 }
 
-#ifdef PERL_OBJECT
-#undef  boot_core_UNIVERSAL
-#define boot_core_UNIVERSAL CPerlObj::Perl_boot_core_UNIVERSAL
-#define pPerl this
-#endif
-
-void
-Perl_boot_core_UNIVERSAL(pTHX)
-{
-    char *file = __FILE__;
-
-    newXS("UNIVERSAL::isa",             XS_UNIVERSAL_isa,         file);
-    newXS("UNIVERSAL::can",             XS_UNIVERSAL_can,         file);
-    newXS("UNIVERSAL::VERSION",        XS_UNIVERSAL_VERSION,     file);
-}