diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-16 16:26:48 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-16 16:26:48 +0000 |
commit | 09a016ee7c5c81580b27db3bd193b38cb3bd4f0e (patch) | |
tree | 90d0fad103f7aa592451f493a3d091ca9db7c866 /fitz | |
parent | 1f8cccdeca9cf9082061b40d66fc8201c8b3ce80 (diff) | |
download | mupdf-09a016ee7c5c81580b27db3bd193b38cb3bd4f0e.tar.xz |
Add fz_malloc_struct, and make code use it.
The new fz_malloc_struct(A,B) macro allocates sizeof(B) bytes using
fz_malloc, and then passes the resultant pointer to Memento_label
to label it with "B".
This costs nothing in non-memento builds, but gives much nicer
listings of leaked blocks when memento is enabled.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/base_hash.c | 2 | ||||
-rw-r--r-- | fitz/base_object.c | 11 | ||||
-rw-r--r-- | fitz/dev_list.c | 6 | ||||
-rw-r--r-- | fitz/dev_null.c | 2 | ||||
-rw-r--r-- | fitz/dev_text.c | 4 | ||||
-rw-r--r-- | fitz/filt_basic.c | 12 | ||||
-rw-r--r-- | fitz/filt_dctd.c | 2 | ||||
-rw-r--r-- | fitz/filt_faxd.c | 74 | ||||
-rw-r--r-- | fitz/filt_flate.c | 2 | ||||
-rw-r--r-- | fitz/filt_jbig2d.c | 2 | ||||
-rw-r--r-- | fitz/filt_lzwd.c | 2 | ||||
-rw-r--r-- | fitz/filt_predict.c | 2 | ||||
-rw-r--r-- | fitz/fitz.h | 3 | ||||
-rw-r--r-- | fitz/res_bitmap.c | 2 | ||||
-rw-r--r-- | fitz/res_font.c | 4 | ||||
-rw-r--r-- | fitz/res_path.c | 4 | ||||
-rw-r--r-- | fitz/res_pixmap.c | 2 | ||||
-rw-r--r-- | fitz/res_store.c | 4 | ||||
-rw-r--r-- | fitz/res_text.c | 4 | ||||
-rw-r--r-- | fitz/stm_buffer.c | 2 | ||||
-rw-r--r-- | fitz/stm_open.c | 4 |
21 files changed, 88 insertions, 62 deletions
diff --git a/fitz/base_hash.c b/fitz/base_hash.c index 79943a1d..02acc8f1 100644 --- a/fitz/base_hash.c +++ b/fitz/base_hash.c @@ -49,7 +49,7 @@ fz_new_hash_table(fz_context *ctx, int initialsize, int keylen) assert(keylen <= MAX_KEY_LEN); - table = fz_malloc(ctx, sizeof(fz_hash_table)); + table = fz_malloc_struct(ctx, fz_hash_table); table->ctx = ctx; table->keylen = keylen; table->size = initialsize; diff --git a/fitz/base_object.c b/fitz/base_object.c index ced40414..a0e3ecc0 100644 --- a/fitz/base_object.c +++ b/fitz/base_object.c @@ -57,6 +57,7 @@ fz_obj * fz_new_null(fz_context *ctx) { fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(null)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_NULL; @@ -67,6 +68,7 @@ fz_obj * fz_new_bool(fz_context *ctx, int b) { fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(bool)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_BOOL; @@ -78,6 +80,7 @@ fz_obj * fz_new_int(fz_context *ctx, int i) { fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(int)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_INT; @@ -89,6 +92,7 @@ fz_obj * fz_new_real(fz_context *ctx, float f) { fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(real)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_REAL; @@ -100,6 +104,7 @@ fz_obj * fz_new_string(fz_context *ctx, char *str, int len) { fz_obj *obj = fz_malloc(ctx, offsetof(fz_obj, u.s.buf) + len + 1); + Memento_label(obj, "fz_obj(string)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_STRING; @@ -113,6 +118,7 @@ fz_obj * fz_new_name(fz_context *ctx, char *str) { fz_obj *obj = fz_malloc(ctx, offsetof(fz_obj, u.n) + strlen(str) + 1); + Memento_label(obj, "fz_obj(name)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_NAME; @@ -124,6 +130,7 @@ fz_obj * fz_new_indirect(fz_context *ctx, int num, int gen, void *xref) { fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(indirect)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_INDIRECT; @@ -382,6 +389,7 @@ fz_new_array(fz_context *ctx, int initialcap) int i; obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(array)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_ARRAY; @@ -392,6 +400,7 @@ fz_new_array(fz_context *ctx, int initialcap) fz_try(ctx) { obj->u.a.items = fz_malloc_array(ctx, obj->u.a.cap, sizeof(fz_obj*)); + Memento_label(obj->u.a.items, "fz_obj(array items)"); } fz_catch(ctx) { @@ -537,6 +546,7 @@ fz_new_dict(fz_context *ctx, int initialcap) int i; obj = fz_malloc(ctx, sizeof(fz_obj)); + Memento_label(obj, "fz_obj(dict)"); obj->ctx = ctx; obj->refs = 1; obj->kind = FZ_DICT; @@ -548,6 +558,7 @@ fz_new_dict(fz_context *ctx, int initialcap) fz_try(ctx) { obj->u.d.items = fz_malloc_array(ctx, obj->u.d.cap, sizeof(struct keyval)); + Memento_label(obj->u.d.items, "fz_obj(dict items)"); } fz_catch(ctx) { diff --git a/fitz/dev_list.c b/fitz/dev_list.c index 47e8b069..03c65f49 100644 --- a/fitz/dev_list.c +++ b/fitz/dev_list.c @@ -70,7 +70,7 @@ fz_new_display_node(fz_context *ctx, fz_display_command cmd, fz_matrix ctm, fz_display_node *node; int i; - node = fz_malloc(ctx, sizeof(fz_display_node)); + node = fz_malloc_struct(ctx, fz_display_node); node->cmd = cmd; node->next = NULL; node->rect = fz_empty_rect; @@ -99,7 +99,7 @@ fz_new_display_node(fz_context *ctx, fz_display_command cmd, fz_matrix ctm, static fz_stroke_state * fz_clone_stroke_state(fz_context *ctx, fz_stroke_state *stroke) { - fz_stroke_state *newstroke = fz_malloc(ctx, sizeof(fz_stroke_state)); + fz_stroke_state *newstroke = fz_malloc_struct(ctx, fz_stroke_state); *newstroke = *stroke; return newstroke; } @@ -482,7 +482,7 @@ fz_new_list_device(fz_context *ctx, fz_display_list *list) fz_display_list * fz_new_display_list(fz_context *ctx) { - fz_display_list *list = fz_malloc(ctx, sizeof(fz_display_list)); + fz_display_list *list = fz_malloc_struct(ctx, fz_display_list); list->first = NULL; list->last = NULL; list->top = 0; diff --git a/fitz/dev_null.c b/fitz/dev_null.c index 4638d802..183c4e21 100644 --- a/fitz/dev_null.c +++ b/fitz/dev_null.c @@ -3,7 +3,7 @@ fz_device * fz_new_device(fz_context *ctx, void *user) { - fz_device *dev = fz_malloc(ctx, sizeof(fz_device)); + fz_device *dev = fz_malloc_struct(ctx, fz_device); memset(dev, 0, sizeof *dev); dev->hints = 0; dev->flags = 0; diff --git a/fitz/dev_text.c b/fitz/dev_text.c index bf304778..d5b6ccf7 100644 --- a/fitz/dev_text.c +++ b/fitz/dev_text.c @@ -20,7 +20,7 @@ fz_text_span * fz_new_text_span(fz_context *ctx) { fz_text_span *span; - span = fz_malloc(ctx, sizeof(fz_text_span)); + span = fz_malloc_struct(ctx, fz_text_span); span->font = NULL; span->wmode = 0; span->size = 0; @@ -409,7 +409,7 @@ fz_device * fz_new_text_device(fz_context *ctx, fz_text_span *root) { fz_device *dev; - fz_text_device *tdev = fz_malloc(ctx, sizeof(fz_text_device)); + fz_text_device *tdev = fz_malloc_struct(ctx, fz_text_device); tdev->head = root; tdev->span = root; tdev->point.x = -1; diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c index 7e5f2f21..1096f266 100644 --- a/fitz/filt_basic.c +++ b/fitz/filt_basic.c @@ -43,7 +43,7 @@ fz_open_null(fz_stream *chain, int len) fz_context *ctx = chain->ctx; assert(chain); - state = fz_malloc(ctx, sizeof(struct null_filter)); + state = fz_malloc_struct(ctx, struct null_filter); state->chain = chain; state->remain = len; @@ -156,7 +156,7 @@ fz_open_ahxd(fz_stream *chain) { fz_ahxd *state; - state = fz_malloc(chain->ctx, sizeof(fz_ahxd)); + state = fz_malloc_struct(chain->ctx, fz_ahxd); state->chain = chain; state->eod = 0; @@ -294,7 +294,7 @@ fz_open_a85d(fz_stream *chain) fz_a85d *state; assert(chain); - state = fz_malloc(chain->ctx, sizeof(fz_a85d)); + state = fz_malloc_struct(chain->ctx, fz_a85d); state->chain = chain; state->rp = state->bp; state->wp = state->bp; @@ -382,7 +382,7 @@ fz_open_rld(fz_stream *chain) fz_rld *state; assert(chain); - state = fz_malloc(chain->ctx, sizeof(fz_rld)); + state = fz_malloc_struct(chain->ctx, fz_rld); state->chain = chain; state->run = 0; state->n = 0; @@ -425,7 +425,7 @@ fz_open_arc4(fz_stream *chain, unsigned char *key, unsigned keylen) { fz_arc4c *state; - state = fz_malloc(chain->ctx, sizeof(fz_arc4c)); + state = fz_malloc_struct(chain->ctx, fz_arc4c); state->chain = chain; fz_arc4_init(&state->arc4, key, keylen); @@ -508,7 +508,7 @@ fz_open_aesd(fz_stream *chain, unsigned char *key, unsigned keylen) fz_aesd *state; assert(chain); - state = fz_malloc(chain->ctx, sizeof(fz_aesd)); + state = fz_malloc_struct(chain->ctx, fz_aesd); state->chain = chain; aes_setkey_dec(&state->aes, key, keylen * 8); state->ivcount = 0; diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 355cca91..5fb1a933 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -208,7 +208,7 @@ fz_open_dctd(fz_stream *chain, fz_obj *params) fz_dctd *state; fz_obj *obj; - state = fz_malloc(chain->ctx, sizeof(fz_dctd)); + state = fz_malloc_struct(chain->ctx, fz_dctd); memset(state, 0, sizeof(fz_dctd)); state->ctx = chain->ctx; state->chain = chain; diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index 98430e0d..be88eda1 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -665,10 +665,11 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fz_faxd *fax; fz_obj *obj; fz_context *ctx; + fz_stream *stream; assert(chain); ctx = chain->ctx; - fax = fz_malloc(ctx, sizeof(fz_faxd)); + fax = fz_malloc_struct(ctx, fz_faxd); fax->chain = chain; fax->ref = NULL; @@ -682,45 +683,56 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fax->end_of_block = 1; fax->black_is_1 = 0; - obj = fz_dict_gets(params, "K"); - if (obj) fax->k = fz_to_int(obj); + fz_try(ctx) + { + obj = fz_dict_gets(params, "K"); + if (obj) fax->k = fz_to_int(obj); - obj = fz_dict_gets(params, "EndOfLine"); - if (obj) fax->end_of_line = fz_to_bool(obj); + obj = fz_dict_gets(params, "EndOfLine"); + if (obj) fax->end_of_line = fz_to_bool(obj); - obj = fz_dict_gets(params, "EncodedByteAlign"); - if (obj) fax->encoded_byte_align = fz_to_bool(obj); + obj = fz_dict_gets(params, "EncodedByteAlign"); + if (obj) fax->encoded_byte_align = fz_to_bool(obj); - obj = fz_dict_gets(params, "Columns"); - if (obj) fax->columns = fz_to_int(obj); + obj = fz_dict_gets(params, "Columns"); + if (obj) fax->columns = fz_to_int(obj); - obj = fz_dict_gets(params, "Rows"); - if (obj) fax->rows = fz_to_int(obj); + obj = fz_dict_gets(params, "Rows"); + if (obj) fax->rows = fz_to_int(obj); - obj = fz_dict_gets(params, "EndOfBlock"); - if (obj) fax->end_of_block = fz_to_bool(obj); + obj = fz_dict_gets(params, "EndOfBlock"); + if (obj) fax->end_of_block = fz_to_bool(obj); - obj = fz_dict_gets(params, "BlackIs1"); - if (obj) fax->black_is_1 = fz_to_bool(obj); + obj = fz_dict_gets(params, "BlackIs1"); + if (obj) fax->black_is_1 = fz_to_bool(obj); - fax->stride = ((fax->columns - 1) >> 3) + 1; - fax->ridx = 0; - fax->bidx = 32; - fax->word = 0; + fax->stride = ((fax->columns - 1) >> 3) + 1; + fax->ridx = 0; + fax->bidx = 32; + fax->word = 0; - fax->stage = STATE_NORMAL; - fax->a = -1; - fax->c = 0; - fax->dim = fax->k < 0 ? 2 : 1; - fax->eolc = 0; + fax->stage = STATE_NORMAL; + fax->a = -1; + fax->c = 0; + fax->dim = fax->k < 0 ? 2 : 1; + fax->eolc = 0; - fax->ref = fz_malloc(ctx, fax->stride); - fax->dst = fz_malloc(ctx, fax->stride); - fax->rp = fax->dst; - fax->wp = fax->dst + fax->stride; + fax->ref = fz_malloc(ctx, fax->stride); + fax->dst = fz_malloc(ctx, fax->stride); + fax->rp = fax->dst; + fax->wp = fax->dst + fax->stride; - memset(fax->ref, 0, fax->stride); - memset(fax->dst, 0, fax->stride); + memset(fax->ref, 0, fax->stride); + memset(fax->dst, 0, fax->stride); - return fz_new_stream(ctx, fax, read_faxd, close_faxd); + stream = fz_new_stream(ctx, fax, read_faxd, close_faxd); + } + fz_catch(ctx) + { + fz_free(ctx, fax->dst); + fz_free(ctx, fax->ref); + fz_free(ctx, fax); + fz_rethrow(ctx); + } + return stream; } diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index 9b3370c4..aafb0fc7 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -90,7 +90,7 @@ fz_open_flated(fz_stream *chain) fz_var(code); - state = fz_malloc(ctx, sizeof(fz_flate)); + state = fz_malloc_struct(ctx, fz_flate); state->chain = chain; state->z.zalloc = zalloc; diff --git a/fitz/filt_jbig2d.c b/fitz/filt_jbig2d.c index e2ae4d93..e90be9f8 100644 --- a/fitz/filt_jbig2d.c +++ b/fitz/filt_jbig2d.c @@ -83,7 +83,7 @@ fz_open_jbig2d(fz_stream *chain, fz_buffer *globals) { fz_jbig2d *state; - state = fz_malloc(chain->ctx, sizeof(fz_jbig2d)); + state = fz_malloc_struct(chain->ctx, fz_jbig2d); state->chain = chain; state->ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, NULL, NULL, NULL); state->gctx = NULL; diff --git a/fitz/filt_lzwd.c b/fitz/filt_lzwd.c index 7ca78fc3..eda52669 100644 --- a/fitz/filt_lzwd.c +++ b/fitz/filt_lzwd.c @@ -171,7 +171,7 @@ fz_open_lzwd(fz_stream *chain, fz_obj *params) int i; assert(chain); - lzw = fz_malloc(chain->ctx, sizeof(fz_lzwd)); + lzw = fz_malloc_struct(chain->ctx, fz_lzwd); lzw->chain = chain; lzw->eod = 0; lzw->early_change = 1; diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c index d640373e..72b91439 100644 --- a/fitz/filt_predict.c +++ b/fitz/filt_predict.c @@ -194,7 +194,7 @@ fz_open_predict(fz_stream *chain, fz_obj *params) fz_obj *obj; fz_context *ctx = chain->ctx; - state = fz_malloc(ctx, sizeof(fz_predict)); + state = fz_malloc_struct(ctx, fz_predict); state->chain = chain; state->predictor = 1; diff --git a/fitz/fitz.h b/fitz/fitz.h index 4989b22f..b4c3cd15 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -189,6 +189,9 @@ void *fz_calloc_no_throw(fz_context *ctx, unsigned int count, unsigned int size) void *fz_resize_array_no_throw(fz_context *ctx, void *p, unsigned int count, unsigned int size); char *fz_strdup_no_throw(fz_context *ctx, char *s); +#define fz_malloc_struct(CTX, STRUCT) \ + Memento_label(fz_malloc(CTX,sizeof(STRUCT)), #STRUCT) + /* runtime (hah!) test for endian-ness */ int fz_is_big_endian(void); diff --git a/fitz/res_bitmap.c b/fitz/res_bitmap.c index 02bb6f44..c381fc3c 100644 --- a/fitz/res_bitmap.c +++ b/fitz/res_bitmap.c @@ -5,7 +5,7 @@ fz_new_bitmap(fz_context *ctx, int w, int h, int n) { fz_bitmap *bit; - bit = fz_malloc(ctx, sizeof(fz_bitmap)); + bit = fz_malloc_struct(ctx, fz_bitmap); bit->refs = 1; bit->w = w; bit->h = h; diff --git a/fitz/res_font.c b/fitz/res_font.c index 60374746..38d6fdf1 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -11,7 +11,7 @@ fz_new_font(fz_context *ctx, char *name) { fz_font *font; - font = fz_malloc(ctx, sizeof(fz_font)); + font = fz_malloc_struct(ctx, fz_font); font->refs = 1; if (name) @@ -124,7 +124,7 @@ struct ft_error void fz_new_font_context(fz_context *ctx) { - ctx->font = fz_malloc(ctx, sizeof(*ctx->font)); + ctx->font = fz_malloc_struct(ctx, fz_font_context); ctx->font->ftlib = NULL; ctx->font->ftlib_refs = 0; } diff --git a/fitz/res_path.c b/fitz/res_path.c index 894e25a8..995afc57 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -6,7 +6,7 @@ fz_new_path(fz_context *ctx) { fz_path *path; - path = fz_malloc(ctx, sizeof(fz_path)); + path = fz_malloc_struct(ctx, fz_path); path->len = 0; path->cap = 0; path->items = NULL; @@ -20,7 +20,7 @@ fz_clone_path(fz_context *ctx, fz_path *old) fz_path *path; assert(old); - path = fz_malloc(ctx, sizeof(fz_path)); + path = fz_malloc_struct(ctx, fz_path); path->len = old->len; path->cap = old->len; path->items = fz_malloc_array(ctx, path->cap, sizeof(fz_path_item)); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index a9a89f9f..1f81e0e1 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -31,7 +31,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h { fz_pixmap *pix; - pix = fz_malloc(ctx, sizeof(fz_pixmap)); + pix = fz_malloc_struct(ctx, fz_pixmap); FZ_INIT_STORABLE(pix, 1, fz_free_pixmap_imp); pix->x = 0; pix->y = 0; diff --git a/fitz/res_store.c b/fitz/res_store.c index a76a9bb1..ab55e6af 100644 --- a/fitz/res_store.c +++ b/fitz/res_store.c @@ -38,7 +38,7 @@ void fz_new_store_context(fz_context *ctx, unsigned int max) { fz_store *store; - store = fz_malloc(ctx, sizeof(fz_store)); + store = fz_malloc_struct(ctx, fz_store); fz_try(ctx) { store->hash = fz_new_hash_table(ctx, 4096, sizeof(struct refkey)); @@ -175,7 +175,7 @@ fz_store_item(fz_context *ctx, fz_obj *key, void *val_, unsigned int itemsize) if (!store) return; - item = fz_malloc(ctx, sizeof(*item)); + item = fz_malloc_struct(ctx, fz_item); /* LOCK */ size = store->size + itemsize; if (store->max != FZ_STORE_UNLIMITED && size > store->max && ensure_space(ctx, size - store->max)) diff --git a/fitz/res_text.c b/fitz/res_text.c index 5eaf12b0..b8c5c5fd 100644 --- a/fitz/res_text.c +++ b/fitz/res_text.c @@ -5,7 +5,7 @@ fz_new_text(fz_context *ctx, fz_font *font, fz_matrix trm, int wmode) { fz_text *text; - text = fz_malloc(ctx, sizeof(fz_text)); + text = fz_malloc_struct(ctx, fz_text); text->font = fz_keep_font(font); text->trm = trm; text->wmode = wmode; @@ -29,7 +29,7 @@ fz_clone_text(fz_context *ctx, fz_text *old) { fz_text *text; - text = fz_malloc(ctx, sizeof(fz_text)); + text = fz_malloc_struct(ctx, fz_text); text->font = fz_keep_font(old->font); text->trm = old->trm; text->wmode = old->wmode; diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c index 0f846987..f01e5b19 100644 --- a/fitz/stm_buffer.c +++ b/fitz/stm_buffer.c @@ -7,7 +7,7 @@ fz_new_buffer(fz_context *ctx, int size) size = size > 1 ? size : 16; - b = fz_malloc(ctx, sizeof(fz_buffer)); + b = fz_malloc_struct(ctx, fz_buffer); b->refs = 1; fz_try(ctx) { diff --git a/fitz/stm_open.c b/fitz/stm_open.c index 733b4c6a..dfb4ed8d 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -7,7 +7,7 @@ fz_new_stream(fz_context *ctx, void *state, { fz_stream *stm; - stm = fz_malloc(ctx, sizeof(fz_stream)); + stm = fz_malloc_struct(ctx, fz_stream); stm->refs = 1; stm->error = 0; @@ -86,7 +86,7 @@ fz_open_fd(fz_context *ctx, int fd) fz_stream *stm; int *state; - state = fz_malloc(ctx, sizeof(int)); + state = fz_malloc_struct(ctx, int); *state = fd; fz_try(ctx) |