/* --- User-level functions implementation --------------------------------- */
+STATIC const MAGIC *vmg_find(pTHX_ const SV *sv, SV *wiz) {
+#define vmg_find(S, W) vmg_find(aTHX_ (S), (W))
+ const MAGIC *mg, *moremagic;
+ UV wid;
+
+ if (SvTYPE(sv) < SVt_PVMG)
+ return NULL;
+
+ wid = vmg_wizard_id(wiz);
+ for (mg = SvMAGIC(sv); mg; mg = moremagic) {
+ moremagic = mg->mg_moremagic;
+ if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
+ UV zid = vmg_wizard_id(mg->mg_ptr);
+ if (zid == wid)
+ return mg;
+ }
+ }
+
+ return NULL;
+}
+
/* ... Construct private data .............................................. */
STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, AV *args) {
STATIC SV *vmg_data_get(pTHX_ SV *sv, SV *wiz) {
#define vmg_data_get(S, W) vmg_data_get(aTHX_ (S), (W))
- MAGIC *mg, *moremagic;
-
- if (SvTYPE(sv) >= SVt_PVMG) {
- UV wid = vmg_wizard_id(wiz);
- for (mg = SvMAGIC(sv); mg; mg = moremagic) {
- moremagic = mg->mg_moremagic;
- if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
- UV zid = vmg_wizard_id(mg->mg_ptr);
- if (zid == wid)
- break;
- }
- }
- if (mg)
- return mg->mg_obj;
- }
-
- return NULL;
+ const MAGIC *mg = vmg_find(sv, wiz);
+ return mg ? mg->mg_obj : NULL;
}
/* ... Magic cast/dispell .................................................. */
STATIC UV vmg_cast(pTHX_ SV *sv, SV *wiz, AV *args) {
#define vmg_cast(S, W, A) vmg_cast(aTHX_ (S), (W), (A))
- MAGIC *mg = NULL, *moremagic = NULL;
- SV *data;
- const MGWIZ *w = vmg_wizard_mgwiz(wiz);
- U32 oldgmg = SvGMAGICAL(sv);
+ MAGIC *mg, *moremagic = NULL;
+ SV *data;
+ const MGWIZ *w;
+ U32 oldgmg;
- if (SvTYPE(sv) >= SVt_PVMG) {
- UV wid = vmg_wizard_id(wiz);
- for (mg = SvMAGIC(sv); mg; mg = moremagic) {
- moremagic = mg->mg_moremagic;
- if (mg->mg_type == PERL_MAGIC_ext && mg->mg_private == SIG_WIZ) {
- UV zid = vmg_wizard_id(mg->mg_ptr);
- if (zid == wid)
- break;
- }
- }
- if (mg)
- return 1;
- }
+ if (vmg_find(sv, wiz))
+ return 1;
+
+ w = vmg_wizard_mgwiz(wiz);
+ oldgmg = SvGMAGICAL(sv);
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);