Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: returning an object in XS

by bipham (Novice)
on Feb 29, 2012 at 20:40 UTC ( [id://957027]=note: print w/replies, xml ) Need Help??


in reply to Re: returning an object in XS
in thread returning an object in XS

Hi Ikegami, After I fixed it, it passed but then it gives me another error shown below

*** glibc detected *** free(): invalid next size (fast): 0x000000000089aaa0 *** Abort

I don't know what happen, would you please help? The code is posted below. By the way, is that possible you can scan thru my code to see if I am doing what I supposed to do?

Thanks Ikehami,
MODULE = nDB PACKAGE = geom REQUIRE: 1.925 SV* get_bbox(rects) SV* rects INIT: rect* result; rect** arrRects; I32 nRects = 0; SV* sv; SV* rv = newRV_noinc(sv); if (rv == NULL) warn("RV has not been created sucessfully!\n"); SV** ssv; double minx,miny,maxx,maxy,tmp_minx,tmp_miny,tmp_maxx,tmp_maxy; int n; if ((!SvROK(rects))||(SvTYPE(SvRV(rects)) != SVt_PVAV)||((nRects = +av_len((AV*)SvRV(rects))) < 0)) { XSRETURN_UNDEF; } arrRects = (rect**)safemalloc(sizeof(rect*)*(nRects)); for (n=0;n<=nRects;n++) { ssv = av_fetch((AV*)SvRV(rects), n, 0); if (ssv != NULL) { arrRects[n] = (rect*)malloc(sizeof(rect)); if (arrRects[n] == NULL) { warn("get_bbox: unable to malloc rect\n"); } else { arrRects[n] = (rect*)SvIV((SV*)SvRV(*ssv)); } } } CODE: minx = (*arrRects)->x1(); miny = (*arrRects)->y1(); maxx = (*arrRects)->x2(); maxy = (*arrRects)->y2(); for (n=1;n<=nRects;n++) { tmp_minx = (*(arrRects+n))->x1(); tmp_miny = (*(arrRects+n))->y1(); tmp_maxx = (*(arrRects+n))->x2(); tmp_maxy = (*(arrRects+n))->y2(); if (tmp_minx < minx) minx = tmp_minx; if (tmp_miny < miny) miny = tmp_miny; if (tmp_maxx > maxx) maxx = tmp_maxx; if (tmp_maxy > maxy) maxy = tmp_maxy; } result = (rect*)malloc(sizeof(rect*)); rect r(minx,miny,maxx,maxy); *result = r; sv_setref_iv(rv,"rect",(IV) result); RETVAL = rv; OUTPUT: RETVAL

Replies are listed 'Best First'.
Re^3: returning an object in XS
by bipham (Novice) on Feb 29, 2012 at 21:15 UTC

    Oh I found it. The line

    result = (rect*)safemalloc(sizeof(rect*));

    should be

    result = (rect*)safemalloc(sizeof(rect));

    Regards,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://957027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-18 00:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found