static void __wheap_resz(ctl_wheap_t h, size_t nu_z) { /* round nu_z to multiple of wid */ nu_z = ((nu_z - 1U) / RBITS_WIDTH + 1U) * RBITS_WIDTH; h->cells = recalloc(h->cells, h->z, nu_z); h->colours = recalloc(h->colours, h->z, nu_z); h->rbits = recalloc(h->rbits, h->z / RBITS_WIDTH, nu_z / RBITS_WIDTH); h->z = nu_z; return; }
static srpaf_t truf_rpaf_find(truf_sym_t sym) { size_t hx = truf_sym_hx(sym); while (1) { /* just try what we've got */ for (size_t mod = 64U; mod <= zstk; mod *= 2U) { size_t off = get_off(hx, mod); if (LIKELY(rstk[off].sym.u == sym.u)) { /* found him */ return rstk + off; } else if (rstk[off].sym.u == 0U) { /* found empty slot */ rstk[off].sym = sym; /* init the rpaf cell */ rstk[off].rpaf->refprc = NANPX; rstk[off].rpaf->cruflo = ZEROPX; nstk++; return rstk + off; } } /* quite a lot of collisions, resize then */ rstk = recalloc(rstk, zstk, 2U * zstk, sizeof(*rstk)); zstk *= 2U; } }
static string copy_into_buf(string buf, string s, int *i, int *lbuf, int l) { if (*i + l > *lbuf) { *lbuf += *i + l - *lbuf + 128; buf = (string) recalloc(buf, *lbuf); } strcpy(buf + *i, s); *i += l; return buf; }
frame make_trsl_paren_frame(frame f) { int l = strlen(f->code); string trl; if (l + 2 >= f->cl) { f->code = (string) recalloc(f->code, l + 2); f->cl = l + 2; } trl = strchr(f->code, TRLC) + 1; memmove(trl + 1, trl, strlen(trl) + 1); trl[0] = '('; trl = strchr(trl, TRLC); memmove(trl + 1, trl, strlen(trl) + 1); trl[0] = ')'; return f; }
void test(buffer_t *buf, mark_t *cur) { int i; int is_all_zero; thing_t *things; int nsize = 1024; things = calloc(1, sizeof(thing_t)); things->a = 1; things->b = 2; things = recalloc(things, 1, nsize, sizeof(thing_t)); ASSERT("preserve_a", 1, things->a); ASSERT("preserve_b", 2, things->b); is_all_zero = 1; for (i = 1; i < nsize; i++) { if (things[i].a != 0 || things[i].b != 0) { is_all_zero = 0; break; } } ASSERT("zerod", 1, is_all_zero); }
static frame make_trsl_frame(frame f1, frame f2, rtype type, void (*merge_fn)(string, string, string, va_list), ...) { frame knv = NULL; string c = coerce_from_atom[type - T_NUMBER]; char cv1[12], cv2[12]; int f1s = f1->type == T_SLOT; int f2s = f2->type == T_SLOT; string check = " " QSM " idTrue : idFalse) : idNull"; string trcb; char buf[512]; va_list ap; va_start(ap, merge_fn); NORET(f1->code); NORET(f2->code); if (!det_type(type) || type == T_OBJECT) type = T_ATOM; if (f1s) knv = prepare_knv_frame(f1, knv, cv1, c); else if (trcb = strchr(f1->code, TRLC)) knv = prepare_trsl_frame(f1, knv, trcb); else if (type == T_ATOM || type == T_BOOL) { f1 = prepare_frame(f1, type); if (member(f1->code, block_args, 0, 0, 0, 1) || !member(f1->code, block_decls, 0, 0, 0, 1)) { knv = make_lknv_frame(f1, ++vcount, 1, type); f1->cl = 8; f1->code = (string) recalloc(f1->code, f1->cl); sprintf(f1->code, "_v%d", vcount); } } if (f2s) knv = prepare_knv_frame(f2, knv, cv2, c); else if (trcb = strchr(f2->code, TRLC)) knv = prepare_trsl_frame(f2, knv, trcb); else if (type == T_ATOM || type == T_BOOL) { f2 = prepare_frame(f2, type); if (member(f2->code, block_args, 0, 0, 0, 1) || !member(f2->code, block_decls, 0, 0, 0, 1)) { frame knv1 = make_lknv_frame(f2, ++vcount, 1, type); knv = knv ? merge_frames(T_CBOOL, T_UNKNOWN, knv, knv1, knv->cl + knv1->cl + 7, knv->code, " "AMP AMP" " NST TABS, knv1->code, "") : knv1; f2->cl = 8; f2->code = (string) recalloc(f2->code, f2->cl); sprintf(f2->code, "_v%d", vcount); } } if (knv) f1->decls = merge_decl_lists(T_UNKNOWN, f1->decls, knv->decls); (*merge_fn)(buf, f1s ? cv1 : NORET(f1->code), f2s ? cv2 : NORET(f2->code), ap); if (knv) { f1 = merge_frames(T_BOOL, type, f1, f2, knv->cl + strlen(buf) + strlen(check) + 12, RET, knv->code, " " QSM NST TABS " (", TRL, buf, TRL, check, ""); mcfree(knv->code); mcfree(knv); } else f1 = merge_frames(T_BOOL, type, f1, f2, strlen(buf) + 4, RET, TRL, buf, TRL, ""); va_end(ap); f1->block = -1; return f1; }