Permalink
Browse files

[rt #69243] re-work XS for i_getcolors()

 - use a default for count instead of doing it manually

 - properly extend the stack for the returned colour list

 - use malloc_temp() instead of mymalloc()
  • Loading branch information...
1 parent befd4be commit 1592522f80f2b8921de105692df3a84b2cae728f @tonycoz committed May 22, 2013
Showing with 4 additions and 9 deletions.
  1. +4 −9 Imager.xs
View
@@ -3151,29 +3151,24 @@ i_setcolors(im, index, ...)
RETVAL
void
-i_getcolors(im, index, ...)
+i_getcolors(im, index, count=1)
Imager::ImgRaw im
int index
+ int count
PREINIT:
i_color *colors;
- int count = 1;
int i;
PPCODE:
- if (items > 3)
- croak("i_getcolors: too many arguments");
- if (items == 3)
- count = SvIV(ST(2));
if (count < 1)
croak("i_getcolors: count must be positive");
- colors = mymalloc(sizeof(i_color) * count);
+ colors = malloc_temp(aTHX_ sizeof(i_color) * count);
if (i_getcolors(im, index, colors, count)) {
+ EXTEND(SP, count);
for (i = 0; i < count; ++i) {
SV *sv = make_i_color_sv(aTHX_ colors+i);
PUSHs(sv);
}
}
- myfree(colors);
-
undef_neg_int
i_colorcount(im)

0 comments on commit 1592522

Please sign in to comment.