Beispiel #1
0
ktap_proto *kp_obj_newproto(ktap_state *ks)
{
	ktap_proto *f;
	f = (ktap_proto *)kp_obj_newobject(ks, KTAP_TYPE_PROTO, sizeof(*f), NULL);
	f->k = NULL;
 	f->sizek = 0;
	f->p = NULL;
	f->sizep = 0;
	f->code = NULL;
	f->cache = NULL;
	f->sizecode = 0;
	f->lineinfo = NULL;
	f->sizelineinfo = 0;
	f->upvalues = NULL;
	f->sizeupvalues = 0;
	f->numparams = 0;
	f->is_vararg = 0;
	f->maxstacksize = 0;
	f->locvars = NULL;
	f->sizelocvars = 0;
	f->linedefined = 0;
	f->lastlinedefined = 0;
	f->source = NULL;
	return f;
}
Beispiel #2
0
ktap_upval *kp_obj_newupval(ktap_state *ks)
{
	ktap_upval *uv;

	uv = &kp_obj_newobject(ks, KTAP_TYPE_UPVAL, sizeof(ktap_upval), NULL)->uv;
	uv->v = &uv->u.value;
	set_nil(uv->v);
	return uv;
}
Beispiel #3
0
Datei: cdata.c Projekt: ktap/ktap
ktap_cdata_t *kp_cdata_new(ktap_state_t *ks, csymbol_id id)
{
	ktap_cdata_t *cd;

	cd = &kp_obj_newobject(ks, KTAP_TYPE_CDATA, sizeof(ktap_cdata_t), NULL)->cd;
	cd_set_csym_id(cd, id);

	return cd;
}
Beispiel #4
0
static ktap_btrace *kp_obj_newbacktrace(ktap_state *ks, int nr_entries,
				    ktap_gcobject **list)
{
	ktap_btrace *bt;
	int size = sizeof(ktap_btrace) + nr_entries * sizeof(unsigned long);

	bt = &kp_obj_newobject(ks, KTAP_TYPE_BTRACE, size, list)->bt;
	bt->nr_entries = nr_entries;
	return bt;
}
Beispiel #5
0
ktap_closure *kp_obj_newclosure(ktap_state *ks, int n)
{
	ktap_closure *cl;
	int size = sizeof(ktap_closure) + sizeof(ktap_upval *) * (n - 1);

	cl = (ktap_closure *)kp_obj_newobject(ks, KTAP_TYPE_CLOSURE, size, NULL);
	cl->p = NULL;
	cl->nupvalues = n;
	while (n--)
		cl->upvals[n] = NULL;

	return cl;
}
Beispiel #6
0
/*
 * allocate raw object with size.
 * The raw object allocated will be free when ktap thread exit,
 * so user don't have to free it.
 */
void *kp_rawobj_alloc(ktap_state *ks, int size)
{
	ktap_rawobj *obj;
	void *addr;
	
	addr = kp_zalloc(ks, size);
	if (unlikely(!addr)) {
		kp_error(ks, "alloc raw object size %d failed\n", size);
		return NULL;
	}

	obj = &kp_obj_newobject(ks, KTAP_TYPE_RAW, sizeof(ktap_rawobj), NULL)->rawobj;
	if (unlikely(!obj)) {
		kp_free(ks, addr);
		kp_error(ks, "alloc raw object failed\n");
		return NULL;
	}

	obj->v = addr;

	/* return address of allocated memory, not raw object */
	return addr;
}