7 Create a new Imager context object.
13 im_context_new(void) {
14 im_context_t ctx = malloc(sizeof(im_context_struct));
20 ctx->error_sp = IM_ERROR_COUNT-1;
21 for (i = 0; i < IM_ERROR_COUNT; ++i) {
22 ctx->error_alloc[i] = 0;
23 ctx->error_stack[i].msg = NULL;
24 ctx->error_stack[i].code = 0;
32 ctx->max_bytes = DEF_BYTES_LIMIT;
36 #ifdef IMAGER_TRACE_CONTEXT
37 fprintf(stderr, "im_context: created %p\n", ctx);
44 =item im_context_refinc(ctx, where)
46 Add a new reference to the context.
52 im_context_refinc(im_context_t ctx, const char *where) {
55 #ifdef IMAGER_TRACE_CONTEXT
56 fprintf(stderr, "im_context:%s: refinc %p (count now %lu)\n", where,
57 ctx, (unsigned long)ctx->refcount);
62 =item im_context_refdec(ctx)
64 Release memory used by an Imager context object.
70 im_context_refdec(im_context_t ctx, const char *where) {
73 im_assert(ctx->refcount > 0);
77 #ifdef IMAGER_TRACE_CONTEXT
78 fprintf(stderr, "im_context:%s: delete %p (count now %lu)\n", where,
79 ctx, (unsigned long)ctx->refcount);
82 if (ctx->refcount != 0)
85 for (i = 0; i < IM_ERROR_COUNT; ++i) {
86 if (ctx->error_stack[i].msg)
87 myfree(ctx->error_stack[i].msg);
98 =item im_context_clone(ctx)
100 Clone an Imager context object, returning the result.
106 im_context_clone(im_context_t ctx, const char *where) {
107 im_context_t nctx = malloc(sizeof(im_context_struct));
113 nctx->error_sp = ctx->error_sp;
114 for (i = 0; i < IM_ERROR_COUNT; ++i) {
115 if (ctx->error_stack[i].msg) {
116 size_t sz = ctx->error_alloc[i];
117 nctx->error_alloc[i] = sz;
118 nctx->error_stack[i].msg = mymalloc(sz);
119 memcpy(nctx->error_stack[i].msg, ctx->error_stack[i].msg, sz);
122 nctx->error_alloc[i] = 0;
123 nctx->error_stack[i].msg = NULL;
125 nctx->error_stack[i].code = ctx->error_stack[i].code;
128 nctx->log_level = ctx->log_level;
130 /* disable buffering, this isn't perfect */
131 setvbuf(ctx->lg_file, NULL, _IONBF, 0);
133 /* clone that and disable buffering some more */
134 nctx->lg_file = fdopen(fileno(ctx->lg_file), "a");
136 setvbuf(nctx->lg_file, NULL, _IONBF, 0);
139 nctx->lg_file = NULL;
142 nctx->max_width = ctx->max_width;
143 nctx->max_height = ctx->max_height;
144 nctx->max_bytes = ctx->max_bytes;
147 #ifdef IMAGER_TRACE_CONTEXT
148 fprintf(stderr, "im_context:%s: cloned %p to %p\n", where, ctx, nctx);