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

In reply to Re^2: returning an object in XS by bipham
in thread returning an object in XS by bipham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.