Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #29: It works the way the Wang did, what's the problem


comp / comp.lang.tcl / what happen to tcl C api ?

SubjectAuthor
* what happen to tcl C api ?aotto1968
`- Re: what happen to tcl C api ?aotto1968

1
Subject: what happen to tcl C api ?
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 19 Jan 2025 09:47 UTC
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: what happen to tcl C api ?
Date: Sun, 19 Jan 2025 10:47:36 +0100
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <vmihnq$24c6l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 19 Jan 2025 10:47:38 +0100 (CET)
Injection-Info: dont-email.me; posting-host="3da57d183ec623340eca6a2638b336b1";
logging-data="2240725"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GBgHy3JuF5Ze29FhLXDSNBWpiR8yvoyA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AsjFon+g1ef06BFU96EyK8AKxP0=
Content-Language: en-US
View all headers

what happened to the tcl "C" api?

i remember that about 20 years ago, when i wrote the tcl-c compiler, the language "tcl" was the language with one of the best
"c" api support. back then, not only the "public" documented c api could be used but also the semi-public api where every tcl
command was accessible with "tcl_?Cmd?ObjCmd" (e.g. Tcl_IncrObjCmd for "incr").

today almost the entire tcl api is "private" and therefore unusable for the extension writer. This means that a simple command
like "incr" which already has a "C" API in Tcl can only be called via Tcl-EvalXX OR has to be laboriously reconstructed from the
Tcl source code using "copy-past". The reason for the (make everything private mode) seems to be the "stubs" subsystem where
every API function has to be exported using Tcl's internal "table")

Here are some numbers
1) is a version of "incr" that works using the "limited public tcl-c-api "Tcl_ObjGetVar/SetVar" etc
2) is a version that works using "Tcl_Eval"

=> even WITHOUT the direct use of "Tcl_IncrObjCmd" the "handwritten" solution is better than the Tcl_Eval solution. I rate the
NON-exported Tcl_IncrObjCmd solution as MUCH better than my "hand-written" solution.

=> and now the summary: Question: Why did the TCL community "throw away" TCL's massive technological lead just to become one of
the slowest languages ​​ever?

# modification via PUBLIC tcl-api
set start1 0
> 0
::myooX::_IncrIndex1 start1
> 1
::myooX::_IncrIndex1 start1 2
> 3
::myooX::_IncrIndex1 start1 -1
> 2
set start1
> 2

# modification via tcl-eval-api
set start2 0
> 0
::myooX::_IncrIndex2 start2
> 1
::myooX::_IncrIndex2 start2 2
> 3
::myooX::_IncrIndex2 start2 -1
> 2
set start2
> 2

time { ::myooX::_IncrIndex1 start1 } 1000
> 0.84 microseconds per iteration
time { ::myooX::_IncrIndex2 start2 } 1000
> 0.983 microseconds per iteration

Subject: Re: what happen to tcl C api ?
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 19 Jan 2025 09:59 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: what happen to tcl C api ?
Date: Sun, 19 Jan 2025 10:59:29 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <vmiie1$24c6l$2@dont-email.me>
References: <vmihnq$24c6l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 19 Jan 2025 10:59:33 +0100 (CET)
Injection-Info: dont-email.me; posting-host="3da57d183ec623340eca6a2638b336b1";
logging-data="2240725"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tdeSLC8SXCrpJl0mz1QDc7D376p4COas="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:3tfoG/ozlM/C4svF/7b9JOfDmm4=
In-Reply-To: <vmihnq$24c6l$1@dont-email.me>
Content-Language: en-US
View all headers

below is the code used for testing:
MOX_ ... is the internal name from me for various tcl api-types
RL_ ... is a helper to build the objc/objv array to finally call the Tcl_EvalObjv api-command

int NS(_IncrIndex1) (OBJCMD_ARGS) {
MOX_SETUP_hdl_static;
if (objc < (1+__skip) || objc > (2+__skip)) {
Tcl_WrongNumArgs(interp,__skip,objv,"... expect: varName ?increment?");
return TCL_ERROR;
}
MOX_OBJ_T varNameO = objv[__skip++];
MOX_OBJ_T incrO = __skip < objc ? objv[__skip++] : NULL;
int incrI=1;
if (incrO) {
if (Tcl_GetIntFromObj(interp,incrO,&incrI) == TCL_ERROR) return TCL_ERROR;
}
MOX_OBJ_T varO = Tcl_ObjGetVar2(interp,varNameO,NULL,TCL_LEAVE_ERR_MSG);
if (varO == NULL) return TCL_ERROR;
int varI;
if (Tcl_GetIntFromObj(interp,varO,&varI) == TCL_ERROR) return TCL_ERROR;
MOX_OBJ_T newO = Tcl_ObjSetVar2(interp,varNameO,NULL, Tcl_NewIntObj(varI+incrI), TCL_LEAVE_ERR_MSG);
if (newO== NULL) return TCL_ERROR;
Tcl_SetObjResult(interp,newO);
return TCL_OK;
};
MoxObjDelete(_IncrIndex1);

int NS(_IncrIndex2) (OBJCMD_ARGS) {
MOX_SETUP_hdl_static;
if (objc < (1+__skip) || objc > (2+__skip)) {
Tcl_WrongNumArgs(interp,__skip,objv,"... expect: varName ?increment?");
return TCL_ERROR;
}
if (objc == 2) {
RL_init( 2, RL_NewS(0,"incr") ) ; RL_O(1,objv[1]) ;
return RL_EvalEx(TCL_LEAVE_ERR_MSG);
} else {
RL_init( 3, RL_NewS(0,"incr") ) ; RL_O(1,objv[1]) ; RL_O(2,objv[2]) ;
return RL_EvalEx(TCL_LEAVE_ERR_MSG);
}
};
MoxObjDelete(_IncrIndex2);

1

rocksolid light 0.9.8
clearnet tor