An xs-function has a reference to a hash as its input, like this:
my $h = {KEY => 123, VAL => 0};
bla::bla( $h );
The xs-function updates $h->{VAL} during its execution.Inside itself the xs-function call a C-library function. Its prototype is: int cbla (int key, int *val);
The question:
Can i get a pointer to int-value saved in the hash?
Or in other words: I can get SV saved in the hash. Can i get a pointer to a memory slot in the SV where 'int' saved?
'&(SvIV(something))' does not work!
May be there is another way to resolve a such problem, is there?
Oleg T
PS:
Sample code:
#
# Function: cx_getvalue(conn, rec)
# Description:
# 'conn' is an output from cx_connect;
# 'rec' is a hash like this:
# $rec = {CHAN => $chan, VALUE => $value, TAG => $tag};
#
# after execution of the function, $rec{CHAN} will remain unchanged,
# $rec{VALUE} will contain value from channel $chan, $rec{TAG} will
# contain a 'freshness' tag;
#int
cx_dummy (conn, rec)
int conn
SV * rec
INIT:
SV * rec_tag_name;
SV * rec_value_name;
SV * rec_chan_name;
SV * rec_value_val;
SV * rec_tag_val;
SV * rec_chan_val;
HE * he; RETVAL = 0;
# Create SV* for the rec hash keys for a comfortable use in hv_*_ent.
rec_tag_name = sv_2mortal(newSVpv(CX_REC_TAG_NAME, 0));
rec_value_name = sv_2mortal(newSVpv(CX_REC_VALUE_NAME, 0));
rec_chan_name = sv_2mortal(newSVpv(CX_REC_CHAN_NAME, 0));
# Check if 'rec' has keys 'CHAN', 'TAG'. If it hasn't, we must create them. # If there is not 'CHAN' key, we must give up with error. if ((!SvROK(rec)) || (SvTYPE(SvRV(rec)) != SVt_PVHV) || (NULL == (he = hv_fetch_ent((HV *)SvRV(rec), rec_chan_name, 0, 0))) ){ croak("Check if a second parameter is defined properly!!!"); } else { rec_chan_val = HeVAL(he); printf("%p\n", ); } # allocate memory for others keys if it hasn't allocated yet. if (!hv_exists_ent((HV *)SvRV(rec), rec_value_name, 0)){ rec_value_val = newSViv(2); if (NULL == hv_store_ent((HV *)SvRV(rec), rec_value_name, rec_value_val, 0)){ SvREFCNT_dec(rec_value_val); warn("hv_store_ent: failed!!!"); RETVAL = -1; } } if (!hv_exists_ent((HV *)SvRV(rec), rec_tag_name, 0)){ rec_tag_val = newSViv(3); if (NULL == hv_store_ent((HV *)SvRV(rec), rec_tag_name, rec_tag_val, 0)){ SvREFCNT_dec(rec_tag_val); warn("hv_store_ent: failed!!!"); RETVAL = -1; } } printf("%d %d %d\n", SvIV(rec_chan_val), SvIV(rec_value_val), SvIV(rec_tag_val)); CODE: if (RETVAL == 0){ } OUTPUT: RETVAL
