Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get a structure pointer from perl's SV containing T_PTRREF
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
You can’t perform that action at this time.