package Short; use Inline C; use strict; # no strict 'refs'; 1; ## # __DATA__ __C__ #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif typedef struct { UV index; UV simtime; } Thing; // -------------------------------------------------------- // shamelessly stolen from Inline::C-Cookbook // SV* newthing( const char * classname ) { Thing * thing; SV * obj; SV * obj_ref; Newx( thing, 1, Thing ); thing->index = 0; thing->simtime = 0; obj = newSViv( (IV)thing ); obj_ref = newRV_noinc(obj); sv_bless( obj_ref, gv_stashpv( classname, GV_ADD ) ); SvREADONLY_on( obj ); return obj_ref; } // -------------------------------------------------------- // void DESTROY(SV* obj) { Thing* thing = (Thing*)SvIV(SvRV(obj)); printf("FREE thing size : %d\n", sizeof( thing ) ); Safefree( thing ); } // -------------------------------------------------------- // void bump( SV* obj, UV simtime ) { Thing* thing = (Thing*)SvIV(SvRV(obj)); printf("obj size : %lu\n", sizeof( obj ) ); printf("obj val : %lx\n", (unsigned long)obj ); printf("thing size : %d\n", sizeof( thing ) ); printf("thing val : %lu\n", (unsigned long)thing ); printf("thing simtime p : %lu\n", simtime ); printf("thing simtime A : %lu\n", thing->simtime ); printf("thing index A : %lu\n", thing->index ); thing->simtime = simtime; thing->index += 1; printf("thing simtime B : %lu\n", thing->simtime ); printf("thing index B : %lu\n", thing->index ); }