GV** gvp;
HV* hv = Nullhv;
SV* subgen = Nullsv;
+ const char *hvname;
/* A stash/class can go by many names (ie. User == main::User), so
we compare the stash itself just in case */
if (name_stash && (stash == name_stash))
return &PL_sv_yes;
- if (strEQ(HvNAME(stash), name))
+ hvname = HvNAME_get(stash);
+
+ if (strEQ(hvname, name))
return &PL_sv_yes;
if (strEQ(name, "UNIVERSAL"))
if (level > 100)
Perl_croak(aTHX_ "Recursive inheritance detected in package '%s'",
- HvNAME(stash));
+ hvname);
gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, FALSE);
SV** svp = (SV**)hv_fetch(hv, name, len, FALSE);
if (svp && (sv = *svp) != (SV*)&PL_sv_undef) {
DEBUG_o( Perl_deb(aTHX_ "Using cached ISA %s for package %s\n",
- name, HvNAME(stash)) );
+ name, hvname) );
return sv;
}
}
else {
DEBUG_o( Perl_deb(aTHX_ "ISA Cache in package %s is stale\n",
- HvNAME(stash)) );
+ hvname) );
hv_clear(hv);
sv_setiv(subgen, PL_sub_generation);
}
if (!basestash) {
if (ckWARN(WARN_MISC))
Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
- "Can't locate package %"SVf" for @%s::ISA",
- sv, HvNAME(stash));
+ "Can't locate package %"SVf" for @%s::ISA",
+ sv, hvname);
continue;
}
if (&PL_sv_yes == isa_lookup(basestash, name, name_stash,
bool
Perl_sv_derived_from(pTHX_ SV *sv, const char *name)
{
- const char *type;
- HV *stash;
+ const char *type = Nullch;
+ HV *stash = Nullhv;
HV *name_stash;
- stash = Nullhv;
- type = Nullch;
-
if (SvGMAGICAL(sv))
mg_get(sv) ;
XS(XS_version_new);
XS(XS_version_stringify);
XS(XS_version_numify);
+XS(XS_version_normal);
XS(XS_version_vcmp);
XS(XS_version_boolean);
+#ifdef HASATTRIBUTE_NORETURN
+XS(XS_version_noop) __attribute__noreturn__;
+#else
XS(XS_version_noop);
+#endif
XS(XS_version_is_alpha);
XS(XS_version_qv);
XS(XS_utf8_is_utf8);
newXS("version::stringify", XS_version_stringify, file);
newXS("version::(0+", XS_version_numify, file);
newXS("version::numify", XS_version_numify, file);
+ newXS("version::normal", XS_version_normal, file);
newXS("version::(cmp", XS_version_vcmp, file);
newXS("version::(<=>", XS_version_vcmp, file);
newXS("version::vcmp", XS_version_vcmp, file);
dXSARGS;
SV *sv;
const char *name;
- STRLEN n_a;
if (items != 2)
Perl_croak(aTHX_ "Usage: UNIVERSAL::isa(reference, kind)");
|| (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv))))
XSRETURN_UNDEF;
- name = (const char *)SvPV(ST(1),n_a);
+ name = SvPV_nolen_const(ST(1));
ST(0) = boolSV(sv_derived_from(sv, name));
XSRETURN(1);
const char *name;
SV *rv;
HV *pkg = NULL;
- STRLEN n_a;
if (items != 2)
Perl_croak(aTHX_ "Usage: UNIVERSAL::can(object-ref, method)");
|| (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv))))
XSRETURN_UNDEF;
- name = (const char *)SvPV(ST(1),n_a);
+ name = SvPV_nolen_const(ST(1));
rv = &PL_sv_undef;
if (SvROK(sv)) {
}
if (items > 1) {
- STRLEN len;
SV *req = ST(1);
if (undef) {
- if (pkg)
- Perl_croak(aTHX_
- "%s does not define $%s::VERSION--version check failed",
- HvNAME(pkg), HvNAME(pkg));
- else {
- const char *str = SvPVx(ST(0), len);
-
- Perl_croak(aTHX_
- "%s defines neither package nor VERSION--version check failed", str);
+ if (pkg) {
+ const char *name = HvNAME_get(pkg);
+ Perl_croak(aTHX_
+ "%s does not define $%s::VERSION--version check failed",
+ name, name);
+ } else {
+ Perl_croak(aTHX_
+ "%s defines neither package nor VERSION--version check failed",
+ SvPVx_nolen_const(ST(0)) );
}
}
if ( vcmp( req, sv ) > 0 )
Perl_croak(aTHX_ "%s version %"SVf" (%"SVf") required--"
- "this is only version %"SVf" (%"SVf")", HvNAME(pkg),
+ "this is only version %"SVf" (%"SVf")", HvNAME_get(pkg),
vnumify(req),vnormal(req),vnumify(sv),vnormal(sv));
}
Perl_croak(aTHX_ "Usage: version::new(class, version)");
SP -= items;
{
- const char *classname = SvPV_nolen(ST(0));
SV *vs = ST(1);
SV *rv;
- if (items == 3 )
- {
- vs = sv_newmortal();
- Perl_sv_setpvf(aTHX_ vs,"v%s",SvPV_nolen(ST(2)));
+ const char *classname;
+
+ /* get the class if called as an object method */
+ if ( sv_isobject(ST(0)) ) {
+ classname = HvNAME(SvSTASH(SvRV(ST(0))));
+ }
+ else {
+ classname = (char *)SvPV_nolen(ST(0));
+ }
+
+ if ( items == 1 ) {
+ /* no parameter provided */
+ if ( sv_isobject(ST(0)) ) {
+ /* copy existing object */
+ vs = ST(0);
+ }
+ else {
+ /* create empty object */
+ vs = sv_newmortal();
+ sv_setpv(vs,"");
+ }
+ }
+ else if ( items == 3 ) {
+ vs = sv_newmortal();
+ Perl_sv_setpvf(aTHX_ vs,"v%s",SvPV_nolen_const(ST(2)));
}
rv = new_version(vs);
Perl_croak(aTHX_ "Usage: version::stringify(lobj, ...)");
SP -= items;
{
- SV * lobj;
+ SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
Perl_croak(aTHX_ "Usage: version::numify(lobj, ...)");
SP -= items;
{
- SV * lobj;
+ SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
}
}
+XS(XS_version_normal)
+{
+ dXSARGS;
+ if (items < 1)
+ Perl_croak(aTHX_ "Usage: version::normal(lobj, ...)");
+ SP -= items;
+ {
+ SV * lobj = Nullsv;
+
+ if (sv_derived_from(ST(0), "version")) {
+ lobj = SvRV(ST(0));
+ }
+ else
+ Perl_croak(aTHX_ "lobj is not of type version");
+
+ PUSHs(sv_2mortal(vnormal(lobj)));
+
+ PUTBACK;
+ return;
+ }
+}
+
XS(XS_version_vcmp)
{
dXSARGS;
Perl_croak(aTHX_ "Usage: version::vcmp(lobj, ...)");
SP -= items;
{
- SV * lobj;
+ SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
Perl_croak(aTHX_ "Usage: version::boolean(lobj, ...)");
SP -= items;
{
- SV * lobj;
+ SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- /* XXX If tmp serves a purpose, explain it. */
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
XS(XS_version_noop)
{
- dXSARGS;
- if (items < 1)
- Perl_croak(aTHX_ "Usage: version::noop(lobj, ...)");
- {
- SV * lobj;
-
- if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
- }
- else
- Perl_croak(aTHX_ "lobj is not of type version");
-
- {
- Perl_croak(aTHX_ "operation not supported with version object");
- }
-
- }
- XSRETURN_EMPTY;
+ dXSARGS;
+ if (items < 1)
+ Perl_croak(aTHX_ "Usage: version::noop(lobj, ...)");
+ if (sv_derived_from(ST(0), "version"))
+ Perl_croak(aTHX_ "operation not supported with version object");
+ else
+ Perl_croak(aTHX_ "lobj is not of type version");
+#ifndef HASATTRIBUTE_NORETURN
+ XSRETURN_EMPTY;
+#endif
}
XS(XS_version_is_alpha)
Perl_croak(aTHX_ "Usage: version::is_alpha(lobj)");
SP -= items;
{
- SV *lobj;
+ SV * lobj = Nullsv;
- if (sv_derived_from(ST(0), "version")) {
- /* XXX If tmp serves a purpose, explain it. */
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
- }
+ if (sv_derived_from(ST(0), "version"))
+ lobj = ST(0);
else
Perl_croak(aTHX_ "lobj is not of type version");
{
- const I32 len = av_len((AV *)lobj);
- const I32 digit = SvIVX(*av_fetch((AV *)lobj, len, 0));
- if ( digit < 0 )
+ if ( hv_exists((HV*)SvRV(lobj), "alpha", 5 ) )
XSRETURN_YES;
else
XSRETURN_NO;
SV * sv = ST(0);
{
STRLEN len;
- const char *s = SvPV(sv,len);
+ const char *s = SvPV_const(sv,len);
if (!SvUTF8(sv) || is_utf8_string((const U8*)s,len))
XSRETURN_YES;
else
SV **varp = svp;
SV **valp = svp + 1;
STRLEN klen;
- const char *key = SvPV(*varp, klen);
+ const char *key = SvPV_const(*varp, klen);
switch (*key) {
case 'i':
if (details) {
XPUSHs(namok ?
- newSVpv(SvPVX(*namsvp), 0) : &PL_sv_undef);
+ newSVpv(SvPVX_const(*namsvp), 0) : &PL_sv_undef);
XPUSHs(argok ?
- newSVpv(SvPVX(*argsvp), 0) : &PL_sv_undef);
+ newSVpv(SvPVX_const(*argsvp), 0) : &PL_sv_undef);
if (flgok)
XPUSHi(SvIVX(*flgsvp));
else
{
/* Using dXSARGS would also have dITEM and dSP,
* which define 2 unused local variables. */
- dMARK; dAX;
+ dAXMARK;
+ (void)mark;
XSRETURN_UV(PERL_HASH_SEED);
}
{
/* Using dXSARGS would also have dITEM and dSP,
* which define 2 unused local variables. */
- dMARK; dAX;
+ dAXMARK;
+ (void)mark;
XSRETURN_UV(PL_rehash_seed);
}
* indent-tabs-mode: t
* End:
*
- * vim: shiftwidth=4:
-*/
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */