I have a piece of code in XS land that reads data from an
external source and populates a scalar that's passed
in to it (ala sysread).  It doesn't seem to work if I
pass a shared variable in to it though.  Is there any
documentation that talks about how to work with shared
scalars from XS?

Here's more detailed information about what's happening:

I'm redoing my program to add threading and the buffer I'm
storing data in is shared now.  I don't want to copy data
around too much since it can be big and the application is
a PerlFS filesystem and I'm trying to keep it speedy.

(On a related note, if anyone cares PerlFS is getting threading
support.  I'll be putting the new perlfsd up on Sourceforge as
soon as I get everything working and turn all the debugging code
off.  So far it seems to be a big improvement.)


If I call it like this:

  $bytes_read = $tag->funny_internal_function_name( $tag, 
$shared_array->[BUFFER], $offset, $length, $options)

$shared_array->[BUFFER] stays empty.


If I call it like this:

  my ($tmp);
  $bytes_read = $tag->funny_internal_function_name( $tag, $tmp, $offset, 
$length, $options)
  $shared_array->[BUFFER] = $tmp;

Everything seems to work right.  Is there something magical about shared
variables that makes them unable to be modified like non-shared scalars
from XS land?  Is there any way to fill in these new fun shared scalars
from XS?

Thanks
        -Eric



For those who care, my XS code looks like this:

void
funny_internal_function_name (pTag, pValue, pOffset, pReadLength, pOptions)
        const FPTagRef pTag
        const FPLong pOffset
        const FPLong pReadLength
        const FPLong pOptions
        SV * pValue
    PREINIT:
        FPStreamRef pStream;
        char * value;
    CODE:
        sv_setpvn( pValue, "", 0);
        value = (char *) SvGROW(pValue, pReadLength);
        
                **stuf you don't care about that writes to the buffer
                **referred to by "value" and returns a length in pReadLength

SvCUR_set(pValue, pReadLength);

Reply via email to