Hi there,
I'm not a Perl expert (I mean the Perl as script lang, and C API), but I would like to solve a problem.
There is a library, written in C, and there are several bindings (Perl, Python, Tcl). SWIG is used to generate the bindings. I found a bug in this part of code: if the type of a variable is "int [NUMBER]" (a fixed length array), then that variable isn't accessible through bindings.
I found a solution for Python (I'm working in Python in many projects - both with interpreter and with C API). I'd like to solve this for Perl too, but it doesn't work.
Here is the (last) code, what I try:
#ifdef SWIGPERL
%typemap(out) int [ANY] {
AV * av = newAV();
int i = 0,len = 0;
printf("len: %d\n", $1_dim0);
len = $1_dim0;
for (i = 0; i < len ; i++) {
SV* perlval = newSV(0);
sv_setiv(perlval, (IV)$1i);
av_store(av, i, perlval);
}
$result = newRV_noinc((SV *)av);
}
#endif
The name of the variable is "m" in C source, and that a structure. It has a member, called "ilist" (integer list). In Python, I can access to this list like this:
print m.ilist // produces [0, 3, 6, ....]
In Perl, I just get this:
#!/usr/bin/perl
use example1;
my @m = $example1::m->{ilist};
foreach(@m) {
print $i, "'", $_, "'\n";
$i=$i+1;
}
this produces:
0''
and nothing more.
What em'I missing?
Any helps are welcome!
Thanks,
a.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.