]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Test how arguments are passed to the data callback
[perl/modules/Variable-Magic.git] / Magic.xs
index ba230455e8bfff3bf05a590a8ea017acf39bdf23..82bf5dd022c5a614e9f15095f7f72a1c7cdd0453 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -181,6 +181,7 @@ typedef struct {
 STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, AV *args) {
 #define vmg_data_new(C, S, A) vmg_data_new(aTHX_ (C), (S), (A))
  SV *nsv;
+ I32 i, alen = (args == NULL) ? 0 : av_len(args);
 
  dSP;
  int count;
@@ -189,11 +190,10 @@ STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, AV *args) {
  SAVETMPS;
 
  PUSHMARK(SP);
- XPUSHs(sv_2mortal(newRV_inc(sv)));
- if (args != NULL) {
-  I32 i, alen = av_len(args);
-  for (i = 0; i < alen; ++i) { XPUSHs(*av_fetch(args, i, 0)); }
- }
+ EXTEND(SP, alen + 1);
+ PUSHs(sv_2mortal(newRV_inc(sv)));
+ for (i = 0; i < alen; ++i)
+  PUSHs(*av_fetch(args, i, 0));
  PUTBACK;
 
  count = call_sv(ctor, G_SCALAR);
@@ -266,17 +266,18 @@ STATIC UV vmg_cast(pTHX_ SV *sv, SV *wiz, AV *args) {
  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_flags   = mg->mg_flags
 #if MGf_COPY
-                | MGf_COPY
+ if (w->cb_copy)
+  mg->mg_flags |= MGf_COPY;
 #endif /* MGf_COPY */
 #if MGf_DUP
-                | MGf_DUP
+ if (w->cb_dup)
+  mg->mg_flags |= MGf_DUP;
 #endif /* MGf_DUP */
 #if MGf_LOCAL
-                | MGf_LOCAL
+ if (w->cb_local)
+  mg->mg_flags |= MGf_LOCAL;
 #endif /* MGf_LOCAL */
-                ;
 
 #if VMG_UVAR
  if (w->uvar && SvTYPE(sv) >= SVt_PVHV) {