return sig;
}
+STATIC U16 vmg_wizard_sig(pTHX_ SV *wiz) {
+#define vmg_wizard_sig(W) vmg_wizard_sig(aTHX_ (W))
+ char buf[8];
+ U16 sig;
+
+ if (SvROK(wiz)) {
+ sig = SV2MGWIZ(SvRV(wiz))->sig;
+ } else if (SvOK(wiz)) {
+ sig = vmg_sv2sig(wiz);
+ } else {
+ croak(vmg_invalid_wiz);
+ }
+
+ dMY_CXT;
+
+ if (!hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0))
+ sig = 0;
+
+ return sig;
+}
+
+STATIC SV *vmg_wizard_wiz(pTHX_ SV *wiz) {
+#define vmg_wizard_wiz(W) vmg_wizard_wiz(aTHX_ (W))
+ char buf[8];
+ SV **old;
+ U16 sig;
+
+ if (SvROK(wiz)) {
+ wiz = SvRV(wiz);
+#if VMG_MULTIPLICITY
+ if (SV2MGWIZ(wiz)->owner == aTHX)
+ return wiz;
+#endif /* VMG_MULTIPLICITY */
+ sig = SV2MGWIZ(wiz)->sig;
+ } else if (SvOK(wiz)) {
+ sig = vmg_sv2sig(wiz);
+ } else {
+ croak(vmg_invalid_wiz);
+ }
+
+ dMY_CXT;
+
+ return (old = hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0))
+ ? *old : NULL;
+}
+
#define VMG_SET_CB(S, N) \
cb = (S); \
w->cb_ ## N = (SvOK(cb) && SvROK(cb)) ? newRV_inc(SvRV(cb)) : NULL;
AV *args = NULL;
SV *ret;
CODE:
- dMY_CXT;
- if (SvROK(wiz)) {
- wiz = SvRV(wiz);
- } else if (SvOK(wiz)) {
- char buf[8];
- SV **old;
- U16 sig = vmg_sv2sig(wiz);
- if ((old = hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0))) {
- wiz = *old;
- } else {
- XSRETURN_UNDEF;
- }
- } else {
- croak(vmg_invalid_sig);
- }
+ wiz = vmg_wizard_wiz(wiz);
+ if (!wiz)
+ XSRETURN_UNDEF;
if (items > 2) {
I32 i;
args = newAV();
SV *data;
U16 sig;
CODE:
- dMY_CXT;
- if (SvROK(wiz)) {
- sig = SV2MGWIZ(SvRV(wiz))->sig;
- } else if (SvOK(wiz)) {
- char buf[8];
- sig = vmg_sv2sig(wiz);
- if (!hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0)) {
- XSRETURN_UNDEF;
- }
- } else {
- croak(vmg_invalid_wiz);
- }
+ sig = vmg_wizard_sig(wiz);
+ if (!sig)
+ XSRETURN_UNDEF;
data = vmg_data_get(SvRV(sv), sig);
if (!data) { XSRETURN_UNDEF; }
ST(0) = data;
PREINIT:
U16 sig;
CODE:
- dMY_CXT;
- if (SvROK(wiz)) {
- sig = SV2MGWIZ(SvRV(wiz))->sig;
- } else if (SvOK(wiz)) {
- char buf[8];
- sig = vmg_sv2sig(wiz);
- if (!hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0)) {
- XSRETURN_UNDEF;
- }
- } else {
- croak(vmg_invalid_wiz);
- }
+ sig = vmg_wizard_sig(wiz);
+ if (!sig)
+ XSRETURN_UNDEF;
RETVAL = newSVuv(vmg_dispell(SvRV(sv), sig));
OUTPUT:
RETVAL
is($res, undef, 'cast from obsolete signature returns undef');
$res = eval { cast $c, undef };
-like($@, qr/Invalid\s+numeric\s+signature\s+at\s+\Q$0\E/, 'cast from undef croaks');
+like($@, qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/, 'cast from undef croaks');
is($res, undef, 'cast from undef doesn\'t return anything');