diotalevi has asked for the wisdom of the Perl Monks concerning the following question:

In trying to get somewhere with [id://???] I wrote a quick XS library to gain access to some perl internal variables. My initial thought was to create an accessor for each variable I was interested in and just write a normal perl sub to format and print them. No such luck. My XSUB accessors returned globs instead of integers. I think this is really basic stuff but it still eluded me.

All I did was a basic `h2xs -n Devel::DebugScope`, edit the created .xs file to add my functions and run it. Eventually I just punted and did the dump right from the C code. I've included that bit as well.

MODULE = Devel::DebugScope PACKAGE = Devel::DebugScope + PREFIX = ds_ I32 ds_scopestack_ix() CODE: RETVAL = PL_scopestack_ix; int ds_savestack_ix() CODE: RETVAL = PL_savestack_ix; void dump_scope() CODE: printf("scopestack_ix: %d\n", PL_scopestack_ix); printf("savestack_ix: %d\n", PL_savestack_ix); __END__ print savestack_ix() returns "*main::savestack_ix" This is the part that eludes me. It should just be an integer and wher +e the glob comes from... *shrug*

Fun Fun Fun in the Fluffy Chair

Replies are listed 'Best First'.
Re: XS code returns GLOB instead of IV
by MarkM (Curate) on Dec 23, 2002 at 21:13 UTC

    The CODE: section defines RETVAL but does not implicitly return RETVAL according to the perlxs manpage. Effectively, an undefined single value is being returned from all of your functions.

    To solve this, model the functions according to the following form:

    I32 ds_scopestack_ix() CODE: RETVAL = PL_scopestack_ix; OUTPUT: RETVAL

    Good luck!

Re: XS code returns GLOB instead of IV
by MarkM (Curate) on Dec 23, 2002 at 20:47 UTC

    I am not familiar with what you are trying to do, but...

    GLOB components need to be dereferenced to see their components. For example, if you are expecting an integer, then you are probably looking for the SCALAR component of the GLOB. Try: print ${savestack_ix()}

    Update: This does not describe the real problem that diotalevi is experiencing. See my later answer for the proper solution.

      Unfortunately that's not the problem. I'm getting a glob where I should be getting an integer. If I were expecting a glob then yes, I'd want to ask for the scalar part of it.


      Fun Fun Fun in the Fluffy Chair