Code notes

You should probably put some board guidelines in this file - include/rules.html.
Board look: Blue Moon Futaba Headline Pseud0ch Toothpaste VIPPER

PerlXS - Pass an (integer) array to C function (4)

1 Name: dagur : 2008-12-30 12:50 ID:4b47teUm [Del]

Using Array Value (AV) functions, it's possible to access Perl arrays in C. The following code snippet copies integer values from Perl into a typical C int array.

    void
set_site_divider(site_divider)
AV* site_divider
CODE:
I32 l = av_len(site_divider) + 1;
unsigned int *cpy = malloc(sizeof(*cpy) * l);

int i = 0;
for (; i < l; i++) {
SV *site = av_shift(site_divider);
cpy[i] = SvIV(site);
}
set_site_divider(cpy);

av_shift pops the first scalar value (SV) from the array, and SvIV returns the int value stored in the scalar.

The document perlguts contains more functions to manipulate SV's and AV's.

For referance, the C function:

   void set_site_divider(unsigned int *s) {
site_divider = s;
}

And the function call from perl:

   DocInfo::Store::set_site_divider([5, 6, 7, 8, 9]);

2 Name: ikke dagur : 2009-08-26 01:31 ID:UxbKXUja [Del]

:o

3 Name: JA : 2011-09-28 13:00 ID:emyiL0mO [Del]

ABC = ABC
PRINT ABC

4 Name: Anonymous : 2012-04-14 05:25 ID:aE+g8nLG (Image: 320x240 jpg, 17 kb) [Del]

src/1334373916907.jpg: 320x240, 17 kb
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification:
Image:

PerlXS - Return list of values (1)

1 Name: dagur : 2008-12-28 13:41 ID:PNUMgxOF [Del]

PPCODE allows us to modify the return stack of the function call, like following:

    void
docinfo_get(doc_id)
unsigned int doc_id
INIT:
static docinfo *nfo;
PPCODE:
docinfo_get(&nfo, doc_id);
XPUSHs(sv_2mortal(newSVnv(nfo->word_count)));
XPUSHs(sv_2mortal(newSViv(nfo->score)));
XPUSHs(sv_2mortal(newSViv(nfo->site_id)));
XPUSHs(sv_2mortal(newSVnv(nfo->rating)));
XPUSHs(sv_2mortal(newSVnv(nfo->img_size)));

docinfo_get loads values into the struct docinfo, then these values are pushed as a list out to perl. newSViv is a scalar integer value and newSVnv is a numeric value.

For referance, docinfo_get just loads a value from a glib hash table:

  void docinfo_get(docinfo **dst, guint doc_id) {
*dst = g_hash_table_lookup(doc_hash, &doc_id);
}

The function call from perl:

  my ($wc, $score, $site_id, $rating, $img_size) = DocInfo::Store::docinfo_get($docid);
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification:
Image:

New thread

Title:
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification:
Image: