At 10:56 Uhr +0100 21.08.2003, Nick Ing-Simmons wrote:
These hashes are called 'stashes'. So comparing stash is fine.

Sorry, I copy-pasted the wrong entry, I've meant cop_stashpv. pp_caller returns CopSTASHPV(), and this macro accesses cop_stashpv if USE_ITHREADS is true, and HvNAME(CopSTASH(x)) otherwise. In the name of portability I probably have to be content with the resulting char*. Now I'm wondering if this one is "stable" as well.


>
PS.2: am I correct assuming that calling an xs function "changes" the
"current" namespace to the namespace as defined in the .xs file?

No. That is one of things that does not happen when calling an XSUB. But saddly this was not fool-proof.

package Foo;
somexsub(anotherfunc());

When in somexsub() then current package was _probably_ Foo.
But if anotherfunc() (which was called to create your args) is
a function-in-perl and has been imported - then I _think_ the
"current package" _used_ be left pointing there.
This may have been fixed by now.

A side-effect of the "no" above is of another XSUB calls yours
(via call_sv() say) then the "calling package" is not clearly
defined - do you want the package of the current statement or
the one that provided the calling XSUB?

I'm not sure what you mean with "the [statement] that provided the calling XSUB".


I'd like to do about this in perl:
 package Foo;
 use Class::PredefinedFields # or alike, name not yet decided
   -base=> qw(Bar Baz), # optional (without -base, inherit from
                 # Class::PredefinedFields), in this case multiple
                 # inheritance; Bar and Baz should be inherited from
                 # Class::PredefinedFields as well;
   -our=> qw(a b c),
   -my=> qw(d); # Bar or Baz may also have defined d, but we override it here
 # (-our might also be called -public and -my may be -private, which
 #  would be preferred by me, but I know there are ppl who think perl
 #  shouldn't be like other languages)

 package main;
 my $obj= new Foo;
 $obj->{d}=1; # throws an exception at runtime, unless Bar or Baz defined
              # d as being public.

Class::PredefinedFields::new() (which may be an XS function as well) does create a perl hash and tie's it into Class::PredefinedFields::Tie.
Class::PredefinedFields::Tie::{TIEHASH,FETCH,STORE,...} are implemented in XS.


Class::PredefinedFields::Tie::{FETCH,STORE,..} must know that $obj->{d}=1 is in package main.

(And Class::PredefinedFields::import must know that use Class::PredefinedFields is in package Foo, but I'm not yet sure I'll implement the import function in XS.)

The other thing to stir into the mix is the effect of eval {}
which complicates the stack stuff...

I've noticed the several cx_type's. But it shouldn't matter since I simply want the *last* statement that's calling me.


 >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..

PL_curcop is a pointer to the current context-op. So you _may_ be able to get away with PL_curcop->cop_stash but you need to try it under various "strange" cases and check you always get what you expect.

Coool, works (on 5.6.1)! Even simpler than I expected :)
(Well since cop_stash does not exist when compiling with ithreads, maybe I should use CopSTASHPV(PL_curcop).)
I'll see if it will be enough in all cases.


Thanks,
Christian.

Reply via email to