Esempio n. 1
0
Object *knh_getClassConstNULL(Ctx *ctx, knh_class_t cid, knh_bytes_t name)
{
	DBG_ASSERT_cid(cid);
	if(ClassTBL(cid).constDictCaseMapNULL == NULL) return NULL;
	knh_DictCaseMap_t *cmap = ClassTBL(cid).constDictCaseMapNULL;
	Object *value = NULL;
	OLD_LOCK(ctx, LOCK_SYSTBL, NULL);
	int res = knh_DictCaseMap_index(cmap, name);
	if(res != -1) {
		value = knh_DictCaseMap_valueAt(cmap, res);
	}
	OLD_UNLOCK(ctx, LOCK_SYSTBL, NULL);
	return value;
}
Esempio n. 2
0
kfileid_t knh_getURI(CTX, kbytes_t t)
{
	OLD_LOCK(_ctx, LOCK_SYSTBL, NULL);
	kindex_t idx = knh_DictSet_index(_ctx->share->urnDictSet, t);
	if(idx == -1) {
		kString *s = new_kString(t.text, t.len, SPOL_POOL);
		idx = kArray_size(_ctx->share->urns);
		knh_DictSet_set(_ctx, ctx->share->urnDictSet, s, idx);
		kArray_add(ctx->share->urns, s);
		KNH_NTRACE2(_ctx, "konoha:newfileid", K_OK, KNH_LDATA(LOG_s("urn", S_text(s)), LOG_i("fileid", idx)));
	}
	else {
		idx = knh_DictSet_valueAt(_ctx->share->urnDictSet, idx);
	}
	OLD_UNLOCK(_ctx, LOCK_SYSTBL, NULL);
	return (kfileid_t)idx;
}
Esempio n. 3
0
kuri_t knh_getURI(CTX ctx, kbytes_t t)
{
    OLD_LOCK(ctx, LOCK_SYSTBL, NULL);
    kindex_t idx = knh_DictSet_index(ctx->share->urnDictSet, t);
    if(idx == -1) {
        kString *s = new_String2(ctx, CLASS_String, t.text, t.len, SPOL_POOLALWAYS);
        idx = knh_Array_size(ctx->share->urns);
        knh_DictSet_set(ctx, ctx->share->urnDictSet, s, idx);
        knh_Array_add(ctx, ctx->share->urns, s);
        KNH_NTRACE2(ctx, "konoha:newuri", K_OK, KNH_LDATA(LOG_s("urn", S_totext(s)), LOG_i("uri", idx)));
    }
    else {
        idx = knh_DictSet_valueAt(ctx->share->urnDictSet, idx);
    }
    OLD_UNLOCK(ctx, LOCK_SYSTBL, NULL);
    return (kuri_t)idx;
}
Esempio n. 4
0
static knh_fieldn_t knh_getname(Ctx *ctx, knh_bytes_t n, knh_fieldn_t def)
{
	OLD_LOCK(ctx, LOCK_SYSTBL, NULL);
	knh_index_t idx = knh_DictCaseSet_index(DP(ctx->sys)->nameDictCaseSet, n);
	if(idx == -1) {
		if(def == FN_NEWID) {
			idx = knh_addname(ctx, new_S(ctx, n), knh_DictCaseSet_set);
		}
		else {
			idx = def - MN_OPSIZE;
		}
	}
	else {
		idx = knh_DictCaseSet_valueAt(DP(ctx->sys)->nameDictCaseSet, idx) - 1;
	}
	OLD_UNLOCK(ctx, LOCK_SYSTBL, NULL);
	return (knh_fieldn_t)idx + MN_OPSIZE;
}
Esempio n. 5
0
static ksymbol_t getSymbol(CTX, kbytes_t n, ksymbol_t def)
{
	OLD_LOCK(_ctx, LOCK_SYSTBL, NULL);
	kindex_t idx = knh_DictSet_index(_ctx->share->symbolDictCaseSet, n);
	if(idx == -1) {
		if(def == FN_NEWID) {
			idx = addSymbol(_ctx, n);
		}
		else {
			idx = def - MN_OPSIZE;
		}
	}
	else {
		idx = knh_DictSet_valueAt(_ctx->share->symbolDictCaseSet, idx) - 1;
	}
	OLD_UNLOCK(_ctx, LOCK_SYSTBL, NULL);
	return (ksymbol_t)idx + MN_OPSIZE;
}
Esempio n. 6
0
int knh_addClassConst(Ctx *ctx, knh_class_t cid, knh_String_t* name, Object *value)
{
	int ret;
	knh_DictCaseMap_t *cmap = ClassTBL(cid).constDictCaseMapNULL;
	DBG_ASSERT_cid(cid);
	if(cmap == NULL) {
		knh_ClassTBL_t *t = pClassTBL(ctx, cid);
		cmap = new_DictCaseMap0(ctx, 0);
		KNH_INITv(t->constDictCaseMapNULL, cmap);
	}
	DBG_ASSERT(IS_Map(cmap));
	OLD_LOCK(ctx, LOCK_SYSTBL, NULL);
	int idx = knh_DictCaseMap_index(cmap, S_tobytes(name));
	if(idx != -1) {
		ret =  0;
		goto L_UNLOCK;
	}
	knh_DictCaseMap_set(ctx, cmap, name, value);
	ret = 1;

	L_UNLOCK:
	OLD_UNLOCK(ctx, LOCK_SYSTBL, NULL);
	return ret;
}
Esempio n. 7
0
int knh_addClassConst(CTX, kcid_t cid, kString* name, Object *value)
{
	int ret;
	kDictMap *cmap = ClassTBL(cid)->constDictCaseMapNULL;
	DBG_ASSERT_cid(cid);
	if(cmap == NULL) {
		kclass_t *t = varClassTBL(cid);
		cmap = new_DictMap0(_ctx, 0, 1/*isCaseMap*/, "ClassTBL.constDictMap");
		KINITv(t->constDictCaseMapNULL, cmap);
	}
	DBG_ASSERT(IS_Map(cmap));
	OLD_LOCK(_ctx, LOCK_SYSTBL, NULL);
	int idx = knh_DictMap_index(cmap, S_tobytes(name));
	if(idx != -1) {
		ret =  0;
		goto L_UNLOCK;
	}
	knh_DictMap_set(_ctx, cmap, name, value);
	ret = 1;

	L_UNLOCK:
	OLD_UNLOCK(_ctx, LOCK_SYSTBL, NULL);
	return ret;
}