/* --- Signatures ---------------------------------------------------------- */
-#define SIG_MIN ((U16) (1u << 8))
+#define SIG_MIN ((U16) 0u)
#define SIG_MAX ((U16) ((1u << 16) - 1))
#define SIG_NBR (SIG_MAX - SIG_MIN + 1)
-#define SIG_WIZ ((U16) ((1u << 8) - 1))
+
+#define SIG_WZO ((U16) (0x3891))
+#define SIG_WIZ ((U16) (0x3892))
/* ... Generate signatures ................................................. */
if (SvTYPE(sv) >= SVt_PVMG) {
for (mg = SvMAGIC(sv); mg; mg = moremagic) {
moremagic = mg->mg_moremagic;
- if ((mg->mg_type == PERL_MAGIC_ext) && (mg->mg_private == sig)) { break; }
+ if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
+ MGWIZ *w = SV2MGWIZ(mg->mg_ptr);
+ if (w->sig == sig)
+ break;
+ }
}
- if (mg) { return mg->mg_obj; }
+ if (mg)
+ return mg->mg_obj;
}
return NULL;
if (SvTYPE(sv) >= SVt_PVMG) {
for (mg = SvMAGIC(sv); mg; mg = moremagic) {
moremagic = mg->mg_moremagic;
- if ((mg->mg_type == PERL_MAGIC_ext) && (mg->mg_private == w->sig)) { break; }
+ if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
+ MGWIZ *z = SV2MGWIZ(mg->mg_ptr);
+ if (z->sig == w->sig)
+ break;
+ }
}
- if (mg) { return 1; }
+ if (mg)
+ return 1;
}
data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args) : NULL;
mg = sv_magicext(sv, data, PERL_MAGIC_ext, w->vtbl, (const char *) wiz, HEf_SVKEY);
- mg->mg_private = w->sig;
+ mg->mg_private = SIG_WIZ;
#if MGf_COPY
if (w->cb_copy)
mg->mg_flags |= MGf_COPY;
for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic) {
moremagic = mg->mg_moremagic;
- if (mg->mg_type == PERL_MAGIC_ext) {
- if (mg->mg_private == sig) {
+ if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
+ MGWIZ *w = SV2MGWIZ(mg->mg_ptr);
+ if (w->sig == sig) {
#if VMG_UVAR
/* If the current has no uvar, short-circuit uvar deletion. */
- uvars = (SV2MGWIZ(mg->mg_ptr)->uvar) ? (uvars + 1) : 0;
+ uvars = w->uvar ? (uvars + 1) : 0;
#endif /* VMG_UVAR */
break;
#if VMG_UVAR
- } else if ((mg->mg_private >= SIG_MIN) &&
- (mg->mg_private <= SIG_MAX) &&
- SV2MGWIZ(mg->mg_ptr)->uvar) {
+ } else if (w->uvar) {
++uvars;
/* We can't break here since we need to find the ext magic to delete. */
#endif /* VMG_UVAR */
/* mg was the first ext magic in the chain that had uvar */
for (mg = moremagic; mg; mg = mg->mg_moremagic) {
- if ((mg->mg_type == PERL_MAGIC_ext) &&
- (mg->mg_private >= SIG_MIN) &&
- (mg->mg_private <= SIG_MAX) &&
- SV2MGWIZ(mg->mg_ptr)->uvar) {
- ++uvars;
- break;
+ if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
+ MGWIZ *w = SV2MGWIZ(mg->mg_ptr);
+ if (w->uvar) {
+ ++uvars;
+ break;
+ }
}
}
default:
continue;
}
- if (mg->mg_private < SIG_MIN || mg->mg_private > SIG_MAX) continue;
+ if (mg->mg_private != SIG_WIZ) continue;
w = SV2MGWIZ(mg->mg_ptr);
switch (w->uvar) {
case 0:
STATIC U16 vmg_sv2sig(pTHX_ SV *sv) {
#define vmg_sv2sig(S) vmg_sv2sig(aTHX_ (S))
- U16 sig;
+ IV sig;
if (SvIOK(sv)) {
- sig = SvUVX(sv);
+ sig = SvIVX(sv);
} else if (SvNOK(sv)) {
sig = SvNVX(sv);
} else if ((SvPOK(sv) && grok_number(SvPVX(sv), SvCUR(sv), NULL))) {
- sig = SvUV(sv);
+ sig = SvIV(sv);
} else {
croak(vmg_invalid_sig);
}
- if (sig < SIG_MIN) { sig += SIG_MIN; }
- if (sig > SIG_MAX) { sig %= SIG_MAX + 1; }
+
+ if (sig < SIG_MIN || sig > SIG_MAX)
+ croak(vmg_invalid_sig);
return sig;
}
{
dMY_CXT;
if (!hv_fetch(MY_CXT.wizards, buf, sprintf(buf, "%u", sig), 0))
- sig = 0;
+ croak(vmg_invalid_wiz);
}
+
return sig;
}
w = vmg_wizard_clone(w);
sv = MGWIZ2SV(w);
mg = sv_magicext(sv, NULL, PERL_MAGIC_ext, &vmg_wizard_vtbl, NULL, 0);
- mg->mg_private = SIG_WIZ;
+ mg->mg_private = SIG_WZO;
SvREADONLY_on(sv);
if (!hv_store(hv, sig, len, sv, HeHASH(key))) croak("%s during CLONE", vmg_globstorefail);
}
sv = MGWIZ2SV(w);
mg = sv_magicext(sv, NULL, PERL_MAGIC_ext, &vmg_wizard_vtbl, NULL, 0);
- mg->mg_private = SIG_WIZ;
+ mg->mg_private = SIG_WZO;
SvREADONLY_on(sv);
if (!hv_store(MY_CXT.wizards, buf, sprintf(buf, "%u", sig), sv, 0)) croak(vmg_globstorefail);
SV *data;
U16 sig;
PPCODE:
- sig = vmg_wizard_sig(wiz);
- if (!sig)
- XSRETURN_UNDEF;
+ sig = vmg_wizard_sig(wiz);
data = vmg_data_get(SvRV(sv), sig);
if (!data) { XSRETURN_UNDEF; }
ST(0) = data;
U16 sig;
CODE:
sig = vmg_wizard_sig(wiz);
- if (!sig)
- XSRETURN_UNDEF;
RETVAL = newSVuv(vmg_dispell(SvRV(sv), sig));
OUTPUT:
RETVAL