Hi All,
I'm working on a set of tools that must run on both solaris and linux. I've written a set of packages using Inline::C, primarily to manipulate large arrays. The code compiles and runs correctly on linux.
It compiles and runs on solaris too, but I'm not getting the results I'm looking for.
The code below is the smallest version of the code I can come up with to demonstrate the problem. The newthing() function is intended to return a pointer to a blessed object, in this case our small struct Thing. In the interest of full disclosure, newthing() was stolen almost verbatim from Inline::C-Cookbook (thanks!).
That reference may be used from the perl side to call $thingref->bump() from the perl side. The bump function should increment thing->index, and assign the simtime parameter to thing->simtime.
The problem is that the solaris version does not increment the index, and does not appear to handle the simtime parameter correctly. Both values stay at zero when they should be non-zero (recall that this runs correctly on linux). A sample of the output follows the code.
My first quess was that I've got a type mismatch somewhere. Changing the type of the obj parameter to bump() from SV * to UV * or IV * compiles, but produces this message at runtime:
Can't locate object method "bump" via package "Short" at ./p_passi +ng_blessed line 58.
... and I am obviously guessing.
The version of perl on both systems is 5.18.4.
perl -V on solaris returns this (among other things):
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='of +f_t', lseeksize=8
I suspect that somewhere along the line, my object has been misallocated, and it is the difference between ivsize and ptrsize that is the source of the issue... but again, I'm guessing.
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 ); }
Sample Output
# --------------------- Devel::Peek::Dump output so we can compare values: SV = IV(0x2bf2d8) at 0x2bf2d8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x2216b0 SV = PVMG(0x4372c8) at 0x2216b0 REFCNT = 1 FLAGS = (OBJECT,IOK,READONLY,pIOK) IV = 7888424 NV = 0 PV = 0 STASH = 0x30a5e8 "Short" # --------------------- perl passing simtime: 20 obj size : 4 obj val : 2bf2d8 thing size : 4 thing val : 7888424 thing simtime p : 0 << should be 20 thing simtime A : 0 thing index A : 0 thing simtime B : 0 << should be 20 thing index B : 0 << should be 1 perl passing simtime: 40 obj size : 4 obj val : 2bf2d8 thing size : 4 thing val : 7888424 thing simtime p : 0 << should be 40 thing simtime A : 0 thing index A : 0 thing simtime B : 0 << should be 40 thing index B : 0 << should be 2 FREE thing size : 4
Thanks in advance,
In reply to Inline C solaris vs linux by ccgcube
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |