Example #1
0
void
region_test_truncate()
{
	header();

	struct region region;

	region_create(&region, &cache);

	void *ptr = region_alloc(&region, 10);

	fail_unless(ptr);

	size_t used = region_used(&region);

	region_alloc(&region, 10000);
	region_alloc(&region, 10000000);

	region_truncate(&region, used);

	fail_unless(region_used(&region) == used);

	region_free(&region);

	footer();
}
Example #2
0
File: utils.c Project: UPPMAX/irods
ExprType *instantiate(ExprType *type, Hashtable *type_table, int replaceFreeVars, Region *r) {
    ExprType **paramTypes;
    int i;
    ExprType *typeInst;
    int changed = 0;

    switch(getNodeType(type)) {
        case T_VAR:
            typeInst = dereference(type, type_table, r);
            if(typeInst == type) {
                return replaceFreeVars?newSimpType(T_UNSPECED, r): type;
            } else {
                return instantiate(typeInst, type_table, replaceFreeVars, r);
            }
        default:
            if(type->degree != 0) {
                paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*type->degree);
                for(i=0;i<type->degree;i++) {
                    paramTypes[i] = instantiate(type->subtrees[i], type_table, replaceFreeVars, r);
                    if(paramTypes[i]!=type->subtrees[i]) {
                        changed = 1;
                    }
                }
            }
            if(changed) {
                ExprType *inst = (ExprType *) region_alloc(r, sizeof(ExprType));
                memcpy(inst, type, sizeof(ExprType));
                inst->subtrees = paramTypes;
                return inst;
            } else {
                return type;
            }

    }
}
Example #3
0
stack_type*
stack_create(struct region* region, size_t size)
{
	stack_type* stack = (stack_type*)region_alloc(region,
		sizeof(stack_type));
	stack->capacity = size;
	stack->num = 0;
	stack->data = (void**) region_alloc(region, sizeof(void*)*size);
	memset(stack->data, 0, sizeof(void*)*size);
	return stack;
}
Example #4
0
TypingConstraint *newTypingConstraint(ExprType *a, ExprType *b, NodeType type, Node *node, Region *r) {
    TypingConstraint *tc = (TypingConstraint *)region_alloc(r, sizeof (TypingConstraint));
    memset(tc, 0, sizeof(TypingConstraint));
    tc->subtrees = (Node **)region_alloc(r, sizeof(Node *)*4);
    TC_A(tc) = a;
    TC_B(tc) = b;
    setNodeType(tc, type);
    TC_NODE(tc) = node;
    TC_NEXT(tc) = NULL;
    tc->degree = 4;
    return tc;
}
Example #5
0
/*
 * setup parse
 */
void
zonec_setup_parser(namedb_type* db)
{
	region_type* rr_region = region_create(xalloc, free);
	parser = zparser_create(db->region, rr_region, db);
	assert(parser);
	/* Unique pointers used to mark errors.	 */
	error_dname = (dname_type *) region_alloc(db->region, 1);
	error_domain = (domain_type *) region_alloc(db->region, 1);
	/* Open the network database */
	setprotoent(1);
	setservent(1);
}
Example #6
0
File: utils.c Project: UPPMAX/irods
ExprType *dupTypeAux(ExprType *ty, Region *r, Hashtable *varTable) {
    ExprType **paramTypes;
    int i;
    ExprType *newt;
    ExprType *exist;
    char *name;
    char buf[128];
    switch(getNodeType(ty)) {
        case T_CONS:
            paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*T_CONS_ARITY(ty));
            for(i=0;i<T_CONS_ARITY(ty);i++) {
                paramTypes[i] = dupTypeAux(T_CONS_TYPE_ARG(ty, i),r,varTable);
            }
            newt = newConsType(T_CONS_ARITY(ty), T_CONS_TYPE_NAME(ty), paramTypes, r);
            newt->option = ty->option;
            break;
        case T_TUPLE:
            paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*T_CONS_ARITY(ty));
            for(i=0;i<T_CONS_ARITY(ty);i++) {
                paramTypes[i] = dupTypeAux(T_CONS_TYPE_ARG(ty, i),r,varTable);
            }
            newt = newTupleType(T_CONS_ARITY(ty), paramTypes, r);
            newt->option = ty->option;
            break;
        case T_VAR:
            name = getTVarName(T_VAR_ID(ty), buf);
            exist = (ExprType *)lookupFromHashTable(varTable, name);
            if(exist != NULL)
                newt = exist;
            else {
                newt = newTVar2(T_VAR_NUM_DISJUNCTS(ty), T_VAR_DISJUNCTS(ty), r);
                insertIntoHashTable(varTable, name, newt);

            }
            newt->option = ty->option;
            break;
        case T_FLEX:
            paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*1);
            paramTypes[0] = dupTypeAux(ty->subtrees[0],r,varTable);
            newt = newExprType(T_FLEX, 1, paramTypes, r);
            newt->option = ty->option;
            break;

        default:
            newt = ty;
            break;
    }
	return newt;
}
Example #7
0
static int
read_rdata_atom(namedb_type *db, uint16_t type, int index, uint32_t domain_count, domain_type **domains, rdata_atom_type *result)
{
    uint8_t data[65536];

    if (rdata_atom_is_domain(type, index)) {
        result->domain = read_domain(db, domain_count, domains);
        if (!result->domain)
            return 0;
    } else {
        uint16_t size;

        if (fread(&size, sizeof(size), 1, db->fd) != 1)
            return 0;
        size = ntohs(size);
        if (fread(data, sizeof(uint8_t), size, db->fd) != size)
            return 0;

        result->data = (uint16_t *) region_alloc(
                           db->region, sizeof(uint16_t) + size);
        memcpy(result->data, &size, sizeof(uint16_t));
        memcpy((uint8_t *) result->data + sizeof(uint16_t), data, size);
    }

    return 1;
}
Example #8
0
Env *newEnv(Hashtable *current, Env *previous, Env *callerEnv, Region *r) {
    Env *env = (Env *)region_alloc(r, sizeof(Env));
    env->current = current;
    env->previous = previous;
    env->lower = callerEnv;
    return env;
}
Example #9
0
Res* newRes(Region *r) {
	Res *res1 = (Res *) region_alloc(r,sizeof (Res));
	memset(res1, 0, sizeof(Res));
        setNodeType(res1, N_VAL);
        setIOType(res1, IO_TYPE_INPUT);
	return res1;
}
Example #10
0
/* used in cpRes only */
Res* newCollRes2(int size, Region *r) {
	Res *res1 = newRes(r);
        res1->exprType = NULL;
        res1->degree = size;
        res1->subtrees = (Res **)region_alloc(r, sizeof(Res *)*size);
	return res1;
}
Example #11
0
Res* newCollRes(int size, ExprType *elemType, Region *r) {
	Res *res1 = newRes(r);
        res1->exprType = newCollType(elemType, r);
        res1->degree = size;
        res1->subtrees = (Res **)region_alloc(r, sizeof(Res *)*size);
	return res1;
}
Example #12
0
FunctionDesc *newExternalFD(Node *type, Region *r) {
    FunctionDesc *desc = (FunctionDesc *) region_alloc(r, sizeof(FunctionDesc));
    memset(desc, 0, sizeof(FunctionDesc));
    desc->exprType = type;
    setNodeType(desc, N_FD_EXTERNAL);
    return desc;
}
Example #13
0
/*
 * Allocate SIZE+sizeof(uint16_t) bytes and store SIZE in the first
 * element.  Return a pointer to the allocation.
 */
static uint16_t *
alloc_rdata(region_type *region, size_t size)
{
	uint16_t *result = region_alloc(region, sizeof(uint16_t) + size);
	*result = size;
	return result;
}
Example #14
0
/**
 * Used for TXT RR's to grow with undefined number of strings.
 */
void
zadd_rdata_txt_wireformat(uint16_t *data, int first)
{
	rdata_atom_type *rd;
	if (parser->current_rr.rdata_count >= MAXRDATALEN) {
		zc_error_prev_line("too many rdata txt elements");
		return;
	}
	
	/* First STR in str_seq, allocate 65K in first unused rdata
	 * else find last used rdata */
	if (first) {
		rd = &parser->current_rr.rdatas[parser->current_rr.rdata_count];
		if ((rd->data = (uint16_t *) region_alloc(parser->rr_region,
			sizeof(uint16_t) + 65535 * sizeof(uint8_t))) == NULL) {
			zc_error_prev_line("Could not allocate memory for TXT RR");
			return;
		}
		parser->current_rr.rdata_count++;
		rd->data[0] = 0;
	}
	else
		rd = &parser->current_rr.rdatas[parser->current_rr.rdata_count-1];
	
	if ((size_t)rd->data[0] + (size_t)data[0] > 65535) {
		zc_error_prev_line("too large rdata element");
		return;
	}
	
	memcpy((uint8_t *)rd->data + 2 + rd->data[0], data + 1, data[0]);
	rd->data[0] += data[0];
}
Example #15
0
pattern_options_t*
pattern_options_create(region_type* region)
{
	pattern_options_t* p;
	p = (pattern_options_t*)region_alloc(region, sizeof(pattern_options_t));
	p->node = *RBTREE_NULL;
	p->pname = 0;
	p->zonefile = 0;
	p->zonestats = 0;
	p->allow_notify = 0;
	p->request_xfr = 0;
	p->notify = 0;
	p->provide_xfr = 0;
	p->outgoing_interface = 0;
	p->notify_retry = 5;
	p->notify_retry_is_default = 1;
	p->allow_axfr_fallback = 1;
	p->allow_axfr_fallback_is_default = 1;
	p->implicit = 0;
	p->xfrd_flags = 0;
#ifdef RATELIMIT
	p->rrl_whitelist = 0;
#endif
	return p;
}
Example #16
0
/** add tsig_key contents */
void
key_options_setup(region_type* region, key_options_t* key)
{
	uint8_t data[16384]; /* 16KB */
	int size;
	if(!key->tsig_key) {
		/* create it */
		key->tsig_key = (tsig_key_type *) region_alloc(region,
			sizeof(tsig_key_type));
		/* create name */
		key->tsig_key->name = dname_parse(region, key->name);
		if(!key->tsig_key->name) {
			log_msg(LOG_ERR, "Failed to parse tsig key name %s",
				key->name);
			/* key and base64 were checked during syntax parse */
			exit(1);
		}
		key->tsig_key->size = 0;
		key->tsig_key->data = NULL;
	}
	size = b64_pton(key->secret, data, sizeof(data));
	if(size == -1) {
		log_msg(LOG_ERR, "Failed to parse tsig key data %s",
			key->name);
		/* key and base64 were checked during syntax parse */
		exit(1);
	}
	key->tsig_key->size = size;
	key->tsig_key->data = (uint8_t *)region_alloc_init(region, data, size);
}
Example #17
0
FunctionDesc *newConstructorFD2(Node *type, Region *r) {
    FunctionDesc *desc = (FunctionDesc *) region_alloc(r, sizeof(FunctionDesc));
    memset(desc, 0, sizeof(FunctionDesc));
    desc->exprType = type;
    setNodeType(desc, N_FD_CONSTRUCTOR);
    return desc;
}
Example #18
0
/*
 * The main server simply waits for signals and child processes to
 * terminate.  Child processes are restarted as necessary.
 */
void
server_main(struct nsd *nsd)
{
	region_type *server_region = region_create(xalloc, free);
	netio_handler_type xfrd_listener;

	/* Ensure we are the main process */
	assert(nsd->server_kind == NSD_SERVER_MAIN);

	xfrd_listener.user_data = (struct ipc_handler_conn_data*)region_alloc(
		server_region, sizeof(struct ipc_handler_conn_data));
	xfrd_listener.fd = -1;
	((struct ipc_handler_conn_data*)xfrd_listener.user_data)->nsd = nsd;
	((struct ipc_handler_conn_data*)xfrd_listener.user_data)->conn =
		xfrd_tcp_create(server_region);

				nsd->pid = 0;
				nsd->child_count = 0;
				nsd->server_kind = NSD_SERVER_UDP;
				nsd->this_child = &nsd->children[0];
				/* remove signal flags inherited from parent
				   the parent will handle them. */
				nsd->signal_hint_reload = 0;
				nsd->signal_hint_child = 0;
				nsd->signal_hint_quit = 0;
				nsd->signal_hint_shutdown = 0;
				nsd->signal_hint_stats = 0;
				nsd->signal_hint_statsusr = 0;
				close(nsd->this_child->child_fd);
				nsd->this_child->child_fd = -1;
				server_child(nsd);
				abort();
}
Example #19
0
const dname_type *
dname_replace(region_type* region,
		const dname_type* name,
		const dname_type* src,
		const dname_type* dest)
{
	/* nomenclature: name is said to be <x>.<src>. x can be null. */
	dname_type* res;
	int x_labels = name->label_count - src->label_count;
	int x_len = name->name_size - src->name_size;
	int i;
	assert(dname_is_subdomain(name, src));

	/* check if final size is acceptable */
	if(x_len+dest->name_size > MAXDOMAINLEN)
		return NULL;

	res = (dname_type*)region_alloc(region, sizeof(dname_type) +
		(x_labels+dest->label_count + x_len+dest->name_size)
		*sizeof(uint8_t));
	res->name_size = x_len+dest->name_size;
	res->label_count = x_labels+dest->label_count;
	for(i=0; i<dest->label_count; i++)
		((uint8_t*)dname_label_offsets(res))[i] =
			dname_label_offsets(dest)[i] + x_len;
	for(i=dest->label_count; i<res->label_count; i++)
		((uint8_t*)dname_label_offsets(res))[i] =
			dname_label_offsets(name)[i - dest->label_count +
				src->label_count];
	memcpy((uint8_t*)dname_name(res), dname_name(name), x_len);
	memcpy((uint8_t*)dname_name(res)+x_len, dname_name(dest), dest->name_size);
	assert(dname_is_subdomain(res, dest));
	return res;
}
Example #20
0
File: utils.c Project: UPPMAX/irods
/**
 * Unify non tvar or union types.
 * return The most general instance if unifiable
 *        NULL if not
 */
ExprType* unifyNonTvars(ExprType *type, ExprType *expected, Hashtable *varTypes, Region *r) {
	if(getNodeType(type) == T_CONS && getNodeType(expected) == T_CONS) {
		if(strcmp(T_CONS_TYPE_NAME(type), T_CONS_TYPE_NAME(expected)) == 0
			&& T_CONS_ARITY(type) == T_CONS_ARITY(expected)) {
            ExprType **subtrees = (ExprType **) region_alloc(r, sizeof(ExprType *) * T_CONS_ARITY(expected));

			int i;
			for(i=0;i<T_CONS_ARITY(type);i++) {
				ExprType *elemType = unifyWith(
                                        T_CONS_TYPE_ARG(type, i),
                                        T_CONS_TYPE_ARG(expected, i),
                                        varTypes,r); /* unifyWithCoercion performs dereference */
				if(elemType == NULL) {
					return NULL;
				}
				subtrees[i] = elemType;
			}
			return dereference(newConsType(T_CONS_ARITY(expected), T_CONS_TYPE_NAME(expected), subtrees, r), varTypes, r);
		} else {
			return NULL;
		}
        } else if(getNodeType(type) == T_IRODS || getNodeType(expected) == T_IRODS) {
                if(strcmp(type->text, expected->text)!=0) {
                        return NULL;
                }
                return expected;
	} else if(getNodeType(expected) == getNodeType(type)) { /* primitive types */
                return expected;
	} else {
            return newErrorType(RE_TYPE_ERROR, r);
	}
}
Example #21
0
void key_options_tsig_add(nsd_options_t* opt)
{
	key_options_t* optkey;
	uint8_t data[4000];
	tsig_key_type* tsigkey;
	const dname_type* dname;
	int size;

	for(optkey = opt->keys; optkey; optkey = optkey->next)
	{
		dname = dname_parse(opt->region, optkey->name);
		if(!dname) {
			log_msg(LOG_ERR, "Failed to parse tsig key name %s", optkey->name);
			continue;
		}
		size = b64_pton(optkey->secret, data, sizeof(data));
		if(size == -1) {
			log_msg(LOG_ERR, "Failed to parse tsig key data %s", optkey->name);
			continue;
		}
		tsigkey = (tsig_key_type *) region_alloc(opt->region, sizeof(tsig_key_type));
		tsigkey->name = dname;
		tsigkey->size = size;
		tsigkey->data = (uint8_t *) region_alloc_init(opt->region, data, tsigkey->size);
		tsig_add_key(tsigkey);
		optkey->tsig_key = tsigkey;
	}
}
Example #22
0
static int
sys_sbrk(uint32_t inc)
{
	// LAB3: your code sbrk here...
	region_alloc(curenv, (void *)(curenv->env_cur_brk + inc), inc);
	return curenv->env_cur_brk;
}
Example #23
0
uint16_t *
alloc_rdata_init(region_type *region, const void *data, size_t size)
{
	uint16_t *result = region_alloc(region, sizeof(uint16_t) + size);
	*result = size;
	memcpy(result + 1, data, size);
	return result;
}
Example #24
0
Res* newStringBasedRes(Region *r, char *s) {
	Res *res1 = newRes(r);
        RES_STRING_STR_LEN(res1) = strlen(s);
        int size = (RES_STRING_STR_LEN(res1)+1)*sizeof(char);
        res1->text = (char *)region_alloc(r, size);
        memcpy(res1->text, s, size);
	return res1;
}
Example #25
0
FunctionDesc *newFunctionFD(char *type, SmsiFuncTypePtr func, Region *r) {
    FunctionDesc *desc = (FunctionDesc *) region_alloc(r, sizeof(FunctionDesc));
    memset(desc, 0, sizeof(FunctionDesc));
    FD_SMSI_FUNC_PTR_LVAL(desc) = func;
    desc->exprType = type == NULL? NULL:parseFuncTypeFromString(type, r);
    setNodeType(desc, N_FD_FUNCTION);
    return desc;
}
void *
region_alloc_zero(region_type *region, size_t size)
{
	void *result = region_alloc(region, size);
	if (!result) return NULL;
	memset(result, 0, size);
	return result;
}
void *
region_alloc_init(region_type *region, const void *init, size_t size)
{
	void *result = region_alloc(region, size);
	if (!result) return NULL;
	memcpy(result, init, size);
	return result;
}
Example #28
0
FunctionDesc *newRuleIndexListFD(RuleIndexList *ruleIndexList, ExprType *type, Region *r) {
    FunctionDesc *desc = (FunctionDesc *) region_alloc(r, sizeof(FunctionDesc));
    memset(desc, 0, sizeof(FunctionDesc));
    FD_RULE_INDEX_LIST_LVAL(desc) = ruleIndexList;
    desc->exprType = type;
    setNodeType(desc, N_FD_RULE_INDEX_LIST);
    return desc;
}
Example #29
0
FunctionDesc *newDeconstructorFD(char *type, int proj, Region *r) {
    FunctionDesc *desc = (FunctionDesc *) region_alloc(r, sizeof(FunctionDesc));
    memset(desc, 0, sizeof(FunctionDesc));
    desc->exprType = type == NULL? NULL:parseFuncTypeFromString(type, r);
    setNodeType(desc, N_FD_DECONSTRUCTOR);
    FD_PROJ(desc) = proj;
    return desc;
}
Example #30
0
// initialize
void render_init(void) {
 
  // scrolling boot region
  region_alloc((region*)(&bootScrollRegion));
  scroll_init(&bootScroll, &bootScrollRegion);

  print_dbg("\r\n init rendering regions.. ");
  // screen regions allocated here
  region_alloc((region*)(&headRegion_pr));
  region_alloc((region*)(&(footRegion_pr[0])));
  region_alloc((region*)(&(footRegion_pr[1])));
  region_alloc((region*)(&(footRegion_pr[2])));
  region_alloc((region*)(&(footRegion_pr[3])));
  //  region_alloc((region*)(&selectRegion_pr));
  region_alloc((region*)(&lineRegion_pr));

  headRegion = &headRegion_pr;
  footRegion[0] = &(footRegion_pr[0]);
  footRegion[1] = &(footRegion_pr[1]);
  footRegion[2] = &(footRegion_pr[2]);
  footRegion[3] = &(footRegion_pr[3]);
  //  selectRegion = &selectRegion_pr;
  lineRegion = &lineRegion_pr;

}