Deutsch English Français Italiano |
<vbfp4d$utpf$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: aotto1968 <aotto1968@t-online.de> Newsgroups: comp.lang.tcl Subject: Nice example about the "inefficiently" of the tcl "c" api. Date: Fri, 6 Sep 2024 22:36:27 +0200 Organization: A noiseless patient Spider Lines: 75 Message-ID: <vbfp4d$utpf$1@dont-email.me> References: <v9ggb7$2dcu$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 06 Sep 2024 22:36:30 +0200 (CEST) Injection-Info: dont-email.me; posting-host="4263aaf3b0413c1000797201802cbbc6"; logging-data="1013551"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MgXA4sGLCW3Mha8TclzIiFy8b/v+cdbU=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:9iulK3SoOX5+MMW3mVc/NlLkWds= In-Reply-To: <v9ggb7$2dcu$1@dont-email.me> Content-Language: en-US Bytes: 3040 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; } }