Sujet : Nice example about the "inefficiently" of the tcl "c" api.
De : aotto1968 (at) *nospam* t-online.de (aotto1968)
Groupes : comp.lang.tclDate : 06. Sep 2024, 21:36:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbfp4d$utpf$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Down is the "C" code of the C-Function to test the an "object" to be valid.
1. in "python"
bool MK(TestObject) (
PyObject * pyO,
PyTypeObject * typeO,
MK_OBJ * objP,
MkTestClassE * flagP
) {
MkTestClassE flag = MkTestClassE_NONE_OBJECT;
MK_OBJ obj = NULL;
if (pyO == Py_None) {
flag=MkTestClassE_NULL; goto end;
}
if (!PyObject_TypeCheck(pyO,typeO)) {
flag=MkTestClassE_WRONG_CLASS; goto end;
}
MK_MNG objM = VAL2MNG(pyO);
if (objM == NULL) { flag=MkTestClassE_NULL ; goto end; };
obj = MkObj(objM);
if (obj == NULL) { flag=MkTestClassE_INVALID_SIGNATURE ; goto end; };
flag = MkTestClassE_OK;
end:
if (flagP) *flagP = flag;
if (objP) *objP = obj;
switch(flag) {
case MkTestClassE_NONE_OBJECT : return false;
default : return true;
}
}
2. same in "Tcl"
( tcl "C"-Api has "no" function to test if an object has an "given" type etc. )
bool MK(TestObject) (
OT_Prefix_ARGS
Tcl_Obj * tclO,
MK_OBJ * objP,
MkTestClassE * flagP
) {
MkTestClassE flag = MkTestClassE_NONE_OBJECT;
int len=0;
MK_STRN str = Tcl_GetStringFromObj(tclO,&len);
if (len == 0 || MkStringIsNULL(MkStringCreate(len,str))) {
flag=MkTestClassE_NULL; goto end;
}
Tcl_Object tclObj = Tcl_GetObjectFromObj (interp, tclO);
if (tclObj == NULL) {
Tcl_ResetResult(interp);
flag=MkTestClassE_NONE_OBJECT; goto end;
};
objM = Tcl_ObjectGetMetadata(tclObj, &MK(AtomMeta));
/* NULL or wrong class etc */
if (objM == NULL) { flag=MkTestClassE_NULL ; goto end; };
objM = MkObj(objM);
if (objM == NULL) { flag=MkTestClassE_INVALID_SIGNATURE ; goto end; };
flag = MkTestClassE_OK;
if (objP) *objP = objM;
end:
if (flagP) *flagP = flag;
switch(flag) {
case MkTestClassE_NONE_OBJECT : return false;
default : return true;
}
}