Lines Matching refs:ctx

114 static unsigned long	*save_mapped_sequence(idn_ucsmap_t ctx,
122 idn_ucsmap_t ctx;
128 if ((ctx = malloc(sizeof(*ctx))) == NULL) {
133 ctx->entry_size = 0;
134 ctx->nentries = 0;
135 ctx->entries = NULL;
136 ctx->mapdata = NULL;
137 ctx->mapdata_size = 0;
138 ctx->mapdata_used = 0;
139 ctx->fixed = 0;
140 ctx->refcnt = 1;
141 *ctxp = ctx;
146 idn_ucsmap_destroy(idn_ucsmap_t ctx) {
147 assert(ctx != NULL && ctx->refcnt > 0);
151 if (--ctx->refcnt == 0) {
152 if (ctx->entries != NULL)
153 free(ctx->entries);
154 if (ctx->mapdata != NULL)
155 free_mapbuf(ctx->mapdata);
156 free(ctx);
161 idn_ucsmap_incrref(idn_ucsmap_t ctx) {
162 assert(ctx != NULL && ctx->refcnt > 0);
164 ctx->refcnt++;
168 idn_ucsmap_add(idn_ucsmap_t ctx, unsigned long ucs,
174 assert(ctx != NULL && ctx->refcnt > 0);
179 if (ctx->fixed) {
191 if (ctx->nentries >= ctx->entry_size) {
192 if (ctx->entry_size == 0)
193 ctx->entry_size = INIT_SIZE;
195 ctx->entry_size *= 2;
196 newbuf = realloc(ctx->entries, sizeof(*e) * ctx->entry_size);
199 ctx->entries = newbuf;
201 e = &ctx->entries[ctx->nentries];
207 e->map = save_mapped_sequence(ctx, map, maplen);
217 ctx->nentries++;
223 idn_ucsmap_fix(idn_ucsmap_t ctx) {
228 assert(ctx != NULL && ctx->refcnt > 0);
232 if (ctx->fixed)
235 ctx->fixed = 1;
239 ctx->hash[i].entry = NULL;
240 ctx->hash[i].n = 0;
243 if (ctx->nentries == 0)
247 qsort(ctx->entries, ctx->nentries, sizeof(ucsmap_entry_t), comp_entry);
256 for (i = 0, e = ctx->entries; i < ctx->nentries; i++, e++) {
258 ctx->hash[e->hidx].entry = e;
261 ctx->hash[last_hidx].n++;
266 idn_ucsmap_map(idn_ucsmap_t ctx, unsigned long v, unsigned long *to,
273 assert(ctx != NULL && ctx->refcnt > 0 && to != NULL &&
278 if (!ctx->fixed) {
285 if ((n = ctx->hash[hash].n) == 0)
289 e = ctx->hash[hash].entry;
326 save_mapped_sequence(idn_ucsmap_t ctx, unsigned long *map, size_t maplen) {
332 * If the current buffer (the first one in the ctx->mapdata list)
336 if (ctx->mapdata_used + maplen > ctx->mapdata_size) {
345 buf->next = ctx->mapdata;
346 ctx->mapdata = buf;
347 ctx->mapdata_size = allocsize;
348 ctx->mapdata_used = 0;
350 p = ctx->mapdata->buf + ctx->mapdata_used;
352 ctx->mapdata_used += maplen;