P
Pavel Hlavnicka
Hi all,
Abstract: If I assign some magic to a value returned from FIRSTKEY (tie
method) this magic is not present as this value is passed to NEXTKEY.
My XS provides functions for hash 'tie' magic (TIEHASH, FETCH...), all
went fine until I started with FIRSTKEY and NEXTKEY. My extension works
with a complex C++ library and for a hash iteration I need to keep some
library specific iteration key. My idea was to use `~` or `U` magic and
associate it with a key returned from FIRSTKEY and use it later in
NEXTKEY. Like this:
SV *
FIRSTKEY(obj)
SV * obj
PREINIT:
AG_SLOT_ENTRY entry;
char * name;
CODE:
// -------- following really does not matter -------
frame = SV2FRAME(obj);
entry = frame -> GetStartSlot(); //C++ API I use
if (entry) {
name = frame -> getName(entry);
RETVAL = newSVpv((const char*)name, 0);
// ------- here I assign some magic to RETVAL --------
sv_magic(RETVAL, sv_2mortal(newSVuv(PTR2UV(entry))),
PERL_MAGIC_ext, NULL, 0);
} else {
RETVAL = &PL_sv_undef;
}
OUTPUT:
RETVAL
SV*
NEXTKEY(obj, last)
SV * obj;
SV * last;
PREINIT:
AG_SLOT_ENTRY entry;
char * name;
CODE:
frame = SV2FRAME(obj);
MAGIC * magic = mg_find(last, PERL_MAGIC_ext);
// --------- OOPS magic is always null ------------
What's really confusing is that SvTYPE(last) still claims some magic is
present, but there is no magic assigned to this SV at all
(SvMAGIC(last) is NULL)
Using Perl 5.8.5, Fedora 3 vanilla.
Any answer to this long message would be really appreciated!!
Thx
Pavel
P.S.:
I have a XS wrapper round C++ library, my XS is compiled with g++ as
described e.g. here <http://www.johnkeiser.com/perl-xs-c++.html>
Actually I do not suppose this affects my problem.
Abstract: If I assign some magic to a value returned from FIRSTKEY (tie
method) this magic is not present as this value is passed to NEXTKEY.
My XS provides functions for hash 'tie' magic (TIEHASH, FETCH...), all
went fine until I started with FIRSTKEY and NEXTKEY. My extension works
with a complex C++ library and for a hash iteration I need to keep some
library specific iteration key. My idea was to use `~` or `U` magic and
associate it with a key returned from FIRSTKEY and use it later in
NEXTKEY. Like this:
SV *
FIRSTKEY(obj)
SV * obj
PREINIT:
AG_SLOT_ENTRY entry;
char * name;
CODE:
// -------- following really does not matter -------
frame = SV2FRAME(obj);
entry = frame -> GetStartSlot(); //C++ API I use
if (entry) {
name = frame -> getName(entry);
RETVAL = newSVpv((const char*)name, 0);
// ------- here I assign some magic to RETVAL --------
sv_magic(RETVAL, sv_2mortal(newSVuv(PTR2UV(entry))),
PERL_MAGIC_ext, NULL, 0);
} else {
RETVAL = &PL_sv_undef;
}
OUTPUT:
RETVAL
SV*
NEXTKEY(obj, last)
SV * obj;
SV * last;
PREINIT:
AG_SLOT_ENTRY entry;
char * name;
CODE:
frame = SV2FRAME(obj);
MAGIC * magic = mg_find(last, PERL_MAGIC_ext);
// --------- OOPS magic is always null ------------
What's really confusing is that SvTYPE(last) still claims some magic is
present, but there is no magic assigned to this SV at all
(SvMAGIC(last) is NULL)
Using Perl 5.8.5, Fedora 3 vanilla.
Any answer to this long message would be really appreciated!!
Thx
Pavel
P.S.:
I have a XS wrapper round C++ library, my XS is compiled with g++ as
described e.g. here <http://www.johnkeiser.com/perl-xs-c++.html>
Actually I do not suppose this affects my problem.