START_MY_CXT
-im_context_t fallback_context;
-
static void
start_context(pTHX) {
dMY_CXT;
MY_CXT.ctx = im_context_new();
sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
-
- /* Ideally we'd free this reference, but the error message memory
- was never released on exit, so the associated memory here is reasonable
- to keep.
- With logging enabled we always need at least one context, since
- objects may be released fairly late and attempt to get the log file.
- */
- im_context_refinc(MY_CXT.ctx, "start_context");
- fallback_context = MY_CXT.ctx;
}
static im_context_t
dTHX;
dMY_CXT;
- return MY_CXT.ctx ? MY_CXT.ctx : fallback_context;
+ return MY_CXT.ctx;
}
#else
static void
start_context(pTHX) {
perl_context = im_context_new();
- im_context_refinc(perl_context, "start_context");
+
+ /* just so it gets destroyed */
+ sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", perl_context);
}
static im_context_t
static void *
malloc_temp(pTHX_ size_t size) {
- SV *sv = sv_2mortal(newSV(size));
+ void *result;
+ Newx(result, size, char);
+ SAVEFREEPV(result);
- return SvPVX(sv);
+ return result;
}
static void *
calloc_temp(pTHX_ size_t size) {
- void *result = malloc_temp(aTHX_ size);
- memset(result, 0, size);
+ void *result;
+ Newxz(result, size, char);
+ SAVEFREEPV(result);
return result;
}
#define i_img_dimPtr(size) ((i_img_dim *)calloc_temp(aTHX_ sizeof(i_img_dim) * (size)))
#define SvI_img_dim(sv, pname) (SvIV(sv))
-#define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color *) * (size)))
+#define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color) * (size)))
#define SvI_color(sv, pname) S_sv_to_i_color(aTHX_ sv, pname)
unsigned char b
unsigned char a
PPCODE:
- ICL_set_internal(cl, r, g, b, a);
+ cl->rgba.r = r;
+ cl->rgba.g = g;
+ cl->rgba.b = b;
+ cl->rgba.a = a;
EXTEND(SP, 1);
PUSHs(ST(0));
work = mymalloc(len);
count = i_tt_has_chars(handle, text, len, utf8, work);
if (GIMME_V == G_ARRAY) {
- EXTEND(SP, count);
- for (i = 0; i < count; ++i) {
- PUSHs(boolSV(work[i]));
- }
+ if (count) {
+ EXTEND(SP, count);
+ for (i = 0; i < count; ++i) {
+ PUSHs(boolSV(work[i]));
+ }
+ }
}
else {
EXTEND(SP, 1);
if (!av_store(av, 1, sv)) {
SvREFCNT_dec(sv);
}
- PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
+ XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
++i;
}
num = num <= av_len(ac) ? num : av_len(ac);
num++;
if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
- xo = mymalloc( sizeof(i_img_dim) * num );
- yo = mymalloc( sizeof(i_img_dim) * num );
- ival = mymalloc( sizeof(i_color) * num );
+ xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
+ yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
+ ival = malloc_temp(aTHX_ sizeof(i_color) * num );
for(i = 0; i<num; i++) {
xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
PUSHs(sv_c);
}
ip_cleanup_quant_opts(aTHX_ &quant);
+ myfree(imgs);
void
}
}
RETVAL = i_addcolors(im, colors, items-1);
+ myfree(colors);
OUTPUT:
RETVAL