using xs -- trouble dereferencing

J

Jim

Hello,

trying what i thought was going to be straightforward.

a constraint that i am working with is not modifying the C code or the
Perl code; keeping all translation stuff in "xs glue space". i have
created a small xs file to help me understand this with "simple"
subroutines.

a line such as:
$retval = tryxs( \$num );
when tryxs is a perl routine, i can modify $num by dereferencing with
$$num. fine.

appearantly, the normal way of allowing $num to be modified in C code
is to _not_ dereference, requiring a change to my perl code.
therefore, i cannot use XS's & unary operator.

what i have so far for tryxs.xs is:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

#include <stdio.h>

MODULE = tryxs PACKAGE = tryxs

void
tryxs( p )
SV * p
PREINIT:
IV j = 0;
SV * z;
CODE:
j = SvIV( SvRV( p ));
j += 1000;
printf( "num : %d\n", j );
z = newSViv( j );
OUTPUT:
p sv_setref_pv( ST(0), Nullch, (void*)z);

what i see:
- "j" does get the scalar sent by perl
- no matter how change the "output" section so far, with various
functions and macros from perlxs, perlguts, and perlapi, $num does not
get the modified value.

i am unsure what combination of macros and functions will allow me to
put the new value on the perl stack.

any ideas out there?

much thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top