Example #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;
}
Example #2
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;
}
Example #3
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;
}