Christian Jaeger <[EMAIL PROTECTED]> writes:
>>Suppose in some .xs file I have
>>
>>MODULE = Bar PACKAGE = Bar
>>
>>DoCall(SV *hvref)
>>CODE:
>>  {
>>   SV **svp = hv_fetch((HV *)SvRV(hvref),"d",1,0);  // will call your FETCH
>>  }
>>
>>
>>And then over in perl:
>>
>>package Foo;
>>Bar::DoCall(\%oneofYourHahes);
>>
>>Should you be checking Bar (the notional package name of XSUB accessing
>>the hash) or Foo (the "current package")?
>
>Package Bar is the relevant one. It's Bar's author who accesses the 
>hash and thus it's him who should have set up the hash the way he 
>wants to access it later on.
>
>But I guess there's no way for me to learn that there's a package 
>"Bar" involved, right?

That is what I was trying to warn you about. Usage like above 
is possibly obscure. But could happen if someone used one of these
hashes with Tk or DBI or ...

>
>>
>>  >
>>  >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.
>>
>>If you get into stack tracing though the eval {} still gets you
>>
>>eval { $obj->{d} = 1 };
>>
>>You _immediate_ "caller" is the eval.
>>An presumably user put it there so he can "catch" your croak-s ...
>
>Hmm, I see.
>
>Well, the eval in this case should have the correct package, so it 
>should not be a problem in your example, but it might be here:
>  package A;
>  eval {  package B;
>          $obj->{d} = 1 };
>
>So you mean that CopSTASHPV(PL_curcop) will return "A" in that case?

Don't know.

>
>In my caller test code I don't see that problem since I'm calling an 
>xsub (Chj::Caller::caller) in the normal way, like
>
>  package A;
>  eval {  package B;
>          print Chj::caller::caller,"\n" }; # prints correctly "B"
>
>I'll have to see how tie behaves.
>
>Christian.

Reply via email to