Skip to content

Commit 101cf64

Browse files
committed
防止用户定义的属性名称与API冲突
kbengine#556
1 parent 5bab96c commit 101cf64

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

kbe/src/lib/entitydef/entitydef.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,19 +575,50 @@ bool EntityDef::loadAllDefDescriptions(const std::string& moduleName,
575575
bool EntityDef::validDefPropertyName(ScriptDefModule* pScriptModule, const std::string& name)
576576
{
577577
int i = 0;
578-
while(true)
578+
579+
while (true)
579580
{
580581
std::string limited = ENTITY_LIMITED_PROPERTYS[i];
581582

582-
if(limited == "")
583+
if (limited == "")
583584
break;
584585

585-
if(name == limited)
586+
if (name == limited)
586587
return false;
587588

588589
++i;
589590
};
590591

592+
PyObject* pyKBEModule =
593+
PyImport_ImportModule(const_cast<char*>("KBEngine"));
594+
595+
PyObject* pyEntityModule =
596+
PyObject_GetAttrString(pyKBEModule, const_cast<char *>("Entity"));
597+
598+
Py_DECREF(pyKBEModule);
599+
600+
if (pyEntityModule != NULL)
601+
{
602+
PyObject* pyEntityAttr =
603+
PyObject_GetAttrString(pyEntityModule, const_cast<char *>(name.c_str()));
604+
605+
if (pyEntityAttr != NULL)
606+
{
607+
Py_DECREF(pyEntityAttr);
608+
Py_DECREF(pyEntityModule);
609+
return false;
610+
}
611+
else
612+
{
613+
PyErr_Clear();
614+
}
615+
}
616+
else
617+
{
618+
PyErr_Clear();
619+
}
620+
621+
Py_XDECREF(pyEntityModule);
591622
return true;
592623
}
593624

@@ -1388,6 +1419,7 @@ bool EntityDef::checkDefMethod(ScriptDefModule* pScriptModule,
13881419
ERROR_MSG(fmt::format("EntityDef::checkDefMethod: class {} does not have method[{}], defined in {}.def!\n",
13891420
moduleName.c_str(), iter->first.c_str(), moduleName));
13901421

1422+
PyErr_Clear();
13911423
return false;
13921424
}
13931425
}

0 commit comments

Comments
 (0)