(I've just subscribed to this list)
I'm writing a package sensitive hash (for building objects with package private data, and more), and for this I need to know in which package the caller of my code is (currently I'm using tie, and it remains to be seen how fast it will be, from what I see the tie implementation creates and deletes one (or more?) SV('s) upon each access; if anyone knows a faster way I'll be glad to hear).
I've tried to understand pp_caller, and copied most code from it into an own function (I don't like the overhead of setting up the perl stack and call into a perl function just to find out who was the last caller..), but it doesn't work as expected. I seems like the way pp_caller walks the stack is in the reverse order of how perl's caller() function works (i.e. caller(0) is the last index my code is going to finds, and the first package my code finds is about the last one caller() will return in while (defined($pack=caller($n))){$n++}), and apart from being a bit weird I don't know how to find out hen I'm at the end of the stack.
(Here's my current code: http://pflanze.mine.nu/~chris/scratch/caller/caller.h (sorry for it being in a header file) )
I don't yet understand how the stack (or stacks, man perlhack tells me about the different stacks, but I don't know where they all are located in the C code) works, i.e. the curstackinfo with its next/prev pointers vs. its cxstack member which seems to be a C array (where I don't know how long it is).
(I also don't understand what dopoptosub_at does.)
PS. the best thing to recognize the caller package would be a pointer that doesn't change, so I don't need to verify the whole package name but only compare the pointer. Is cop_stash from struct cop (as returned by pp_caller) such a reliable pointer?
PS.2: am I correct assuming that calling an xs function "changes" the "current" namespace to the namespace as defined in the .xs file? Is there any way to easily get at the current namespace (i.e. the __PACKAGE__ value) from xs? If the current namespace is not changed then this value would already be what I'm looking for..
Thanks for any help, Christian.
