Thank you! This looks interesting - and definately a new area of Perl for me... I tried to compile it but ran into an error:
TellStick.xs:70:10: error: ‘sv’ undeclared (first use in this function +)
I guess sv needs to be declared. And there was a typo for NewSViv. So now it looks like
if (rv == TELLSTICK_SUCCESS) { HV* hv = newHV(); SV *sv = newSV(0); sv = newSVpv(protocol, 0); hv_stores(hv, "protocol", sv); sv = newSVpv(model, 0); hv_stores(hv, "model", sv); sv = newSViv(id); hv_stores(hv, "id", sv); sv = newSViv(dataTypes); hv_stores(hv, "dataTypes", sv); RETVAL = newRV_noinc(hv); } else { RETVAL = &PL_sv_undef; }
There were some compilation warnings as well, don't know if they are important:
In file included from /usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/perl +.h:5102:0, from TellStick.xs:2: TellStick.xs: In function ‘XS_TellStick_tdSensor’: TellStick.xs:76:31: warning: passing argument 2 of ‘Perl_newRV_noinc’ +from incompatible pointer type RETVAL = newRV_noinc(hv); ^ /usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/embed.h:371:48: note: in d +efinition of macro ‘newRV_noinc’ #define newRV_noinc(a) Perl_newRV_noinc(aTHX_ a) ^ In file included from /usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/perl +.h:5061:0, from TellStick.xs:2: /usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/proto.h:2874:19: note: exp +ected ‘struct SV * const’ but argument is of type ‘struct HV *’ PERL_CALLCONV SV* Perl_newRV_noinc(pTHX_ SV *const sv)
But the code works!!!

I get the correct values:

protocol: mandolyn, model: temperaturehumidity, sensorId: 51, dataType +s: 3 protocol: mandolyn, model: temperaturehumidity, sensorId: 61, dataType +s: 3
Thank you very much for your help! Now I have a way forward for implementing the rest of fucntion in the C library.


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.