Tcl-C API: What's wrong with THIS Tcl_DecrRefCount ?
Sujet : Tcl-C API: What's wrong with THIS Tcl_DecrRefCount ?
De : aldo.w.buratti (at) *nospam* gmail.com (abu)
Groupes : comp.lang.tclDate : 05. Mar 2025, 21:41:25
Autres entêtes
Organisation : RetroBBS
Message-ID : <c57da1ef228b98fd021f184c03d90e81@www.rocksolidbbs.com>
User-Agent : Rocksolid Light
I have some unexèpected result with this (over-simplified) C code (using
the Tcl-C API), and I don't understandard what's wrong.
Please could you tell me what's wrong with this Tcl-C code ?
--
This is (in plain Tcl) what I'm trying to achive.
This may seem silly, but it's just an oversimplified case.
----
proc fun {} {
# build a list of values
set A [list]
foreach element {100.0 200.0 300.0} { lappend A $element }
# -- now extract and return the 1st element
set v [lindex $A 0]
return $v
}
----
And here's its adaption in C (using the Tcl-C API)
---
int CMD_fun { ClientData clientData, Tcl_Interp *interp, int argc, const
char *argv[]) {
Tcl_Obj* aList = Tcl_NewListObj(0,NULL);
for (int i=1 ; i <= 3; ++i) {
Tcl_ListObjAppendElement(interp, aList , Tcl_NewDoubleObj(i*100.0));
}
//extract the 1st element (-> 100.0) and incr its RefCount
Tcl_Obj* resultObj;
Tcl_ListObjIndex(interp,aList,0,&resultObj);
Tcl_IncrRefCount(resultObj);
// free aList
Tcl_DecrRefCount(aList); // the listObj, and all its elements are
released, but the first
Tcl_SetObjResult( interp, resultObj );
return TCL_OK;
}
..
Tcl_CreateObjCommand( interp, "cfun" , CMD_fun, (ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL) ;
..
---
This works as expected (return 100.0), but if called 100.000 times,
I see an abnormal growth in memory (Megabytes).
What's wrong ?
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal