myfree(ctx->error_stack[i].msg);
}
#ifdef IMAGER_LOG
- if (ctx->lg_file)
+ if (ctx->lg_file && ctx->own_log)
fclose(ctx->lg_file);
#endif
Clone an Imager context object, returning the result.
+The error stack is not copied from the original context.
+
=cut
*/
}
nctx->slot_alloc = slot_count;
- nctx->error_sp = ctx->error_sp;
+ nctx->error_sp = IM_ERROR_COUNT-1;
for (i = 0; i < IM_ERROR_COUNT; ++i) {
- if (ctx->error_stack[i].msg) {
- size_t sz = ctx->error_alloc[i];
- nctx->error_alloc[i] = sz;
- nctx->error_stack[i].msg = mymalloc(sz);
- memcpy(nctx->error_stack[i].msg, ctx->error_stack[i].msg, sz);
- }
- else {
- nctx->error_alloc[i] = 0;
- nctx->error_stack[i].msg = NULL;
- }
- nctx->error_stack[i].code = ctx->error_stack[i].code;
+ nctx->error_alloc[i] = 0;
+ nctx->error_stack[i].msg = NULL;
}
#ifdef IMAGER_LOG
nctx->log_level = ctx->log_level;
if (ctx->lg_file) {
- /* disable buffering, this isn't perfect */
- setvbuf(ctx->lg_file, NULL, _IONBF, 0);
-
- /* clone that and disable buffering some more */
- nctx->lg_file = fdopen(fileno(ctx->lg_file), "a");
- if (nctx->lg_file)
- setvbuf(nctx->lg_file, NULL, _IONBF, 0);
+ if (ctx->own_log) {
+ int newfd = dup(fileno(ctx->lg_file));
+ nctx->own_log = 1;
+ nctx->lg_file = fdopen(newfd, "w");
+ if (nctx->lg_file)
+ setvbuf(nctx->lg_file, NULL, _IONBF, BUFSIZ);
+ }
+ else {
+ /* stderr */
+ nctx->lg_file = ctx->lg_file;
+ nctx->own_log = 0;
+ }
}
else {
nctx->lg_file = NULL;