void hsignature_fini(hsignature_t *sig) { int i; for (i = 0; i < sig->range_len; ++i) hrange_fini(&sig->range[i]); free(sig->range); free(sig->name); *sig = HSIGNATURE_INITIALIZER; }
void hsignature_fini(hsignature_t *sig) { int i; for (i = 0; i < sig->range_len; ++i) { free(sig->range[i].name); if (sig->range[i].type == HVAL_STR) { sig->range[i].name = NULL; hrange_fini(&sig->range[i]); } } free(sig->range); free(sig->name); *sig = HSIGNATURE_INITIALIZER; }
int hrange_copy(hrange_t *dst, const hrange_t *src) { int i; hrange_fini(dst); dst->name = stralloc(src->name); if (!dst->name) return -1; dst->type = src->type; switch (dst->type) { case HVAL_INT: memcpy(&dst->bounds.i, &src->bounds.i, sizeof(int_bounds_t)); break; case HVAL_REAL: memcpy(&dst->bounds.r, &src->bounds.r, sizeof(real_bounds_t)); break; case HVAL_STR: dst->bounds.s.set = (char **) malloc(src->bounds.s.set_len * sizeof(char *)); if (!dst->bounds.s.set) return -1; dst->bounds.s.set_len = src->bounds.s.set_len; dst->bounds.s.set_cap = src->bounds.s.set_len; for (i = 0; i < dst->bounds.s.set_len; ++i) { dst->bounds.s.set[i] = stralloc(src->bounds.s.set[i]); if (!dst->bounds.s.set[i]) return -1; } break; default: errno = EINVAL; return -1; } return 0; }