Пример #1
0
static kcontext_t* new_hcontext(CTX ctx0)
{
	kcontext_t *ctx;
	static volatile size_t ctxid_counter = 0;
	if(ctx0 == NULL) {
		ctxid_counter = 0;
		ctx = (kcontext_t*)malloc(sizeof(kcontext_t));
		knh_bzero(ctx, sizeof(kcontext_t));
	}
	else {
		KNH_ASSERT_CTX0(ctx0);
		ctx = (kcontext_t*)KNH_MALLOC(ctx0, sizeof(kcontext_t));
		knh_bzero(ctx, sizeof(kcontext_t));
	}
	ctx->flag = 0;
	ctx->ctxid = ctxid_counter;
	ctxid_counter++;
//	ctx->freeObjectList = NULL;
//	ctx->freeMemoryList = NULL;
	ctx->parent = ctx;
	ctx->api2 = getapi2();
	{
		kuintptr_t i = 0, ch;
		kuint_t t = knh_rand();
		ch = t % 26;
		ctx->trace[i] = 'A' + ch;
		for(i = 1; i < 9; i++) {
			t = t / 36;
			if (t == 0) t = knh_rand();
			ch = t % 36;
			ctx->trace[i] = (ch < 10) ? '0' + ch : 'A' + (ch - 10);
		}
	}
	ctx->seq = 0;
	ctx->ctxobjNC = NULL;
	if(ctx0 == NULL) {
		const char *ptrace = knh_getenv(K_DEOS_TRACE);
		if(ptrace == NULL) {
			ptrace = "$(setenv " K_DEOS_TRACE ")";
		}
		KNH_NTRACE2(ctx, "konoha:newtrace", K_NOTICE, KNH_LDATA(
					LOG_s("parent", ptrace)
#if defined(K_USING_POSIX_)
					, LOG_u("ppid", getppid())
#endif /* !defined(K_USING_POSIX_) */
					));
	}
	else {
		KNH_NTRACE2(ctx, "konoha:newtrace", K_NOTICE, KNH_LDATA(LOG_s("parent", ctx0->trace), LOG_u("seq", ctx0->seq)));
	}
	return ctx;
}
Пример #2
0
static void CommonContext_init(CTX, kcontext_t *o)
{
	KNH_ASSERT_CTX0(_ctx);
	DBG_ASSERT(o->script != NULL);
	DBG_ASSERT(o->gma != NULL);
	KINITv(o->enc, ctx->share->enc);
	KINITv(o->in,  ctx->share->in);
	KINITv(o->out, ctx->share->out);
	KINITv(o->err, ctx->share->err);
	KINITv(o->e, K_NULL);
	KINITv(o->evaled, K_NULL);
	KINITv(o->errmsgs, new_Array0(_ctx, 0));
	KINITv(o->gcstack, new_Array0(_ctx, 0));
#ifndef K_USING_STRINGPOOL
	KINITv(o->symbolDictMap, new_DictMap0(_ctx, 256, 0/*isCaseMap*/, "Context.symbolDictMap"));
#endif
//	KINITv(o->constPools, new_Array0(_ctx, 0));
	o->ctxlock = knh_mutex_malloc(_ctx);
}