Created
November 3, 2014 02:55
-
-
Save ivan-krukov/0668a5019513a31860fc to your computer and use it in GitHub Desktop.
Get a structure pointer from perl's SV containing T_PTRREF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct datum { | |
int number; | |
} datum; | |
typedef datum * table; | |
TYPEMAP: <<END | |
table T_PTRREF | |
END | |
data | |
init() | |
INIT: | |
unsigned int SIZE = 10; | |
table t = (table)malloc(SIZE*sizeof(datum)); | |
int i; | |
CODE: | |
for (i = 0; i < SIZE; i++) { | |
datum d; | |
d.number = i*i; | |
t[i]=d; | |
} | |
RETVAL = t; | |
OUTPUT: | |
RETVAL | |
void | |
dealloc(self) | |
HV *self; | |
CODE: | |
SV** table = hv_fetch(self, "table", 5, 0); | |
IV t = SvIV( (SV*)SvRV( *table ) ); | |
genetic_code foo = INT2PTR( table, t ); | |
printf(">>%d\n",foo[4].number); | |
free(t); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment