Example in the generated C-file:
I added two printf for debugging (best debug tool...) and when I run it with like this:XS_EUPXS(XS_TellStick_tdSensor); /* prototype to pass -Wmissing-protot +ypes */ XS_EUPXS(XS_TellStick_tdSensor) { dVAR; dXSARGS; if (items != 6) croak_xs_usage(cv, "protocol, protocolLen, model, modelLen, id, d +ataTypes"); { char * protocol = (char *)SvPV_nolen(ST(0)) ; int protocolLen = (int)SvIV(ST(1)) ; char * model = (char *)SvPV_nolen(ST(2)) ; int modelLen = (int)SvIV(ST(3)) ; int id = (int)SvIV(ST(4)) ; int dataTypes = (int)SvIV(ST(5)) ; int RETVAL; dXSTARG; printf("id1: %d\n", id); RETVAL = tdSensor(protocol, protocolLen, model, modelLen, &id, &da +taTypes); printf("id2: %d\n", id); XSprePUSH; PUSHi((IV)RETVAL); } XSRETURN(1); }
So it gets the correct value (51), but that is not passed back.... my $sensorId = 1; TellStick::tdSensor($protocol, 25, $model, 25, $sensorId, $dataTypes); print "protocol: $protocol, model: $model, sensorId: $sensorId, dataT +ypes: $dataTypes\n"; I get the output id1: 1 id2: 51 protocol: mandolyn, model: temperaturehumidity, sensorId: 1, dataTypes +: 2
It looks like the XS code only sees the id parameter as an input value (casting it right), but no output is generated (except the return value). The string arguments (protocol, model), seems to work in modifying what the value is pointing to.
Should I somehow use "int *" in the XS anyway, but writing some special code for INPUT/OUTPUT in the typemap? Or is there some other way of returing the correct value?In reply to Re^2: Passing integer pointer in XS? (&)
by martin67
in thread Passing integer pointer in XS?
by martin67
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |