use warnings;
use Carp;
-our $VERSION = '0.86';
+our $VERSION = '0.87';
require XSLoader;
START_MY_CXT
+int
+S_myset_set(pTHX_ SV* sv, MAGIC* mg)
+{
+ SV *isv = (SV*)mg->mg_ptr;
+
+ PERL_UNUSED_ARG(sv);
+ SvIVX(isv)++;
+ return 0;
+}
+
MGVTBL vtbl_foo, vtbl_bar;
+MGVTBL vtbl_myset = { 0, S_myset_set, 0, 0, 0, 0, 0, 0 };
+
/* indirect functions to test the [pa]MY_CXT macros */
OUTPUT:
RETVAL
+
+ # attach ext magic to the SV pointed to by rsv that only has set magic,
+ # where that magic's job is to increment thingy
+
+void
+sv_magic_myset(SV *rsv, SV *thingy)
+CODE:
+ sv_magicext(SvRV(rsv), NULL, PERL_MAGIC_ext, &vtbl_myset,
+ (const char *)thingy, 0);
+
+
+
bool
test_isBLANK_uni(UV ord)
CODE:
eval { sv_magic(\!0, $foo) };
is $@, "", 'PERL_MAGIC_ext is permitted on read-only things';
+# assigning to an array/hash with only set magic should call that magic
+
+{
+ my (@a, %h, $i);
+
+ sv_magic_myset(\@a, $i);
+ sv_magic_myset(\%h, $i);
+
+ $i = 0;
+ @a = (1,2);
+ is($i, 2, "array with set magic");
+
+ $i = 0;
+ @a = ();
+ is($i, 0, "array () with set magic");
+
+ {
+ local $TODO = "HVs don't call set magic - not sure if should";
+
+ $i = 0;
+ %h = qw(a 1 b 2);
+ is($i, 4, "hash with set magic");
+ }
+
+ $i = 0;
+ %h = qw();
+ is($i, 0, "hash () with set magic");
+}
+
done_testing;
tmps_base -= nelems;
- if (SvRMAGICAL(ary) || SvREADONLY(ary) || !AvREAL(ary)) {
+ if (SvMAGICAL(ary) || SvREADONLY(ary) || !AvREAL(ary)) {
/* for arrays we can't cheat with, use the official API */
av_extend(ary, nelems - 1);
for (i = 0; i < nelems; i++) {