6 Create a new Imager context object.
12 im_context_new(void) {
13 im_context_t ctx = mymalloc(sizeof(im_context_struct));
16 ctx->error_sp = IM_ERROR_COUNT-1;
17 for (i = 0; i < IM_ERROR_COUNT; ++i) {
18 ctx->error_alloc[i] = 0;
19 ctx->error_stack[i].msg = NULL;
20 ctx->error_stack[i].code = 0;
31 =item im_context_delete(ctx)
33 Release memory used by an Imager context object.
39 im_context_delete(im_context_t ctx) {
42 for (i = 0; i < IM_ERROR_COUNT; ++i) {
43 if (ctx->error_stack[i].msg)
44 myfree(ctx->error_stack[i].msg);
53 =item im_context_clone(ctx)
55 Clone an Imager context object, returning the result.
61 im_context_clone(im_context_t ctx) {
62 im_context_t nctx = mymalloc(sizeof(im_context_struct));
65 nctx->error_sp = ctx->error_sp;
66 for (i = 0; i < IM_ERROR_COUNT; ++i) {
67 if (ctx->error_stack[i].msg) {
68 size_t sz = ctx->error_alloc[i];
69 nctx->error_alloc[i] = sz;
70 nctx->error_stack[i].msg = mymalloc(sz);
71 memcpy(nctx->error_stack[i].msg, ctx->error_stack[i].msg, sz);
74 nctx->error_alloc[i] = 0;
75 nctx->error_stack[i].msg = NULL;
77 nctx->error_stack[i].code = ctx->error_stack[i].code;
80 nctx->log_level = ctx->log_level;
82 /* disable buffering, this isn't perfect */
83 setvbuf(ctx->lg_file, NULL, _IONBF, 0);
85 /* clone that and disable buffering some more */
86 nctx->lg_file = fdopen(fileno(ctx->lg_file), "a");
88 setvbuf(nctx->lg_file, NULL, _IONBF, 0);