Skip to content

Instantly share code, notes, and snippets.

@ivan-krukov
Created November 3, 2014 02:55
Show Gist options
  • Save ivan-krukov/0668a5019513a31860fc to your computer and use it in GitHub Desktop.
Save ivan-krukov/0668a5019513a31860fc to your computer and use it in GitHub Desktop.
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