6 Create a new Imager context object.
12 im_context_new(void) {
13 im_context_t ctx = malloc(sizeof(im_context_struct));
19 ctx->error_sp = IM_ERROR_COUNT-1;
20 for (i = 0; i < IM_ERROR_COUNT; ++i) {
21 ctx->error_alloc[i] = 0;
22 ctx->error_stack[i].msg = NULL;
23 ctx->error_stack[i].code = 0;
31 ctx->max_bytes = DEF_BYTES_LIMIT;
37 =item im_context_delete(ctx)
39 Release memory used by an Imager context object.
45 im_context_delete(im_context_t ctx) {
48 for (i = 0; i < IM_ERROR_COUNT; ++i) {
49 if (ctx->error_stack[i].msg)
50 myfree(ctx->error_stack[i].msg);
61 =item im_context_clone(ctx)
63 Clone an Imager context object, returning the result.
69 im_context_clone(im_context_t ctx) {
70 im_context_t nctx = malloc(sizeof(im_context_struct));
76 nctx->error_sp = ctx->error_sp;
77 for (i = 0; i < IM_ERROR_COUNT; ++i) {
78 if (ctx->error_stack[i].msg) {
79 size_t sz = ctx->error_alloc[i];
80 nctx->error_alloc[i] = sz;
81 nctx->error_stack[i].msg = mymalloc(sz);
82 memcpy(nctx->error_stack[i].msg, ctx->error_stack[i].msg, sz);
85 nctx->error_alloc[i] = 0;
86 nctx->error_stack[i].msg = NULL;
88 nctx->error_stack[i].code = ctx->error_stack[i].code;
91 nctx->log_level = ctx->log_level;
93 /* disable buffering, this isn't perfect */
94 setvbuf(ctx->lg_file, NULL, _IONBF, 0);
96 /* clone that and disable buffering some more */
97 nctx->lg_file = fdopen(fileno(ctx->lg_file), "a");
99 setvbuf(nctx->lg_file, NULL, _IONBF, 0);
102 nctx->lg_file = NULL;
105 nctx->max_width = ctx->max_width;
106 nctx->max_height = ctx->max_height;
107 nctx->max_bytes = ctx->max_bytes;