If the first 4 arguments are for specifying ways to output 2 strings, then you can get simpler than that!
int
tdSensor( protocol, protocolLen, model, modelLen, id, dataTypes )
SV * protocol
int protocolLen
SV * model
int modelLen
int & id
int & dataTypes
CODE:
{
STRLEN n_a;
(void) SvPV_force( protocol, n_a );
(void) SvPV_force( model, n_a );
SvGROW( protocol, protocolLen );
SvGROW( model, modelLen );
}
RETVAL = tdSensor(
SvPV(protocol), protocolLen, SvPV(model), modelLen, &id, &data
+Types );
SvCUR_set( protocol, strlen(SvPV(protocol)) );
SvCUR_set( model, strlen(SvPV(model)) );
OUTPUT:
RETVAL
id
dataTypes
But much simpler (and less likely to be buggy) than even that is:
int
_tdSensor( protocol, protocolLen, model, modelLen, id, dataTypes )
char * protocol
int protocolLen
char * model
int modelLen
int & id
int & dataTypes
CODE:
RETVAL = tdSensor( protocol, protocolLen, model, modelLen, &id, &d
+ataTypes );
OUTPUT:
RETVAL
id
dataTypes
Plus
sub tdSensor {
my( $protocolLen, $modelLen ) = @_;
$protcolLen ||= 1024;
$modelLen ||= 1024;
my $protocol = '\0' x $protcolLen;
my $model = '\0' x $modelLen;
my $id = 0;
my $dataTypes = 0;
my $ret = _tdSensor(
$protocol, $protocolLen, $model, $modelLen, $id, $dataTypes );
s/\0.*//
for $protocol, $model;
return( $ret, $protocol, $model, $id, $dataTypes );
}
Which has the significant advantage of making it much easier to improve the interface without having to futz with the super finicky XS part of the code.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.