Thanks, But it still is a mystery... By using "int & " instead of "int *", the C-code looks alright and the C-function is called with the right parameters. But the value that the C-funtion writes to the int pointers are not passed back to perl.

Example in the generated C-file:

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); }
I added two printf for debugging (best debug tool...) and when I run it with like this:
... 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
So it gets the correct value (51), but that is not passed back.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.