Overview
| Artifact ID: | 81049b579961ec215db56c4dd58f9b57aec49d0469b37ca38926ce4d60d8659b |
|---|---|
| Ticket: | 656fe3c8163aea1bbf10552962fcc79cb49c5bad
Tcl_DictObjPut() - poor usability |
| User & Date: | dkf on 2024-05-25 12:44:56 |
Changes
- icomment:
The branch [more-dict-c-funcs](https://core.tcl-lang.org/tcl/timeline?r=more-dict-c-funcs) has some ideas on this. ## Branch Description The branch has four new functions: int TclDictGet(Tcl_Interp *interp, Tcl_Obj *dictPtr, const char *key, Tcl_Obj **valuePtrPtr); int TclDictPut(Tcl_Interp *interp, Tcl_Obj *dictPtr, const char *key, Tcl_Obj *valuePtr); int TclDictPutString(Tcl_Interp *interp, Tcl_Obj *dictPtr, const char *key, const char *value); int TclDictRemove(Tcl_Interp *interp, Tcl_Obj *dictPtr, const char *key); The functions make those operations available without having to explicitly make a key object (and a value object from a classic NUL-terminated C string, for `TclDictPutString()`) and handle reference counts correctly so that the objects they make internally won't leak. `TclDictPut()` also will dispose of a zero-ref `valuePtr` on error; the `valuePtr` must be distinct from the `dictPtr` (it always is in our internal uses; the reality is that the `Put` functions are almost always used with a `NULL` interpreter and a dictionary that's never been exposed to user scripts). It might be nice to have `TclDictPutInt()` or something like that — we could certainly make use of it! — but it isn't critical. They're currently `MODULE_SCOPE` but bringing them out to `tclInt.decls` would be acceptable (or to `tcl.decls` with the obvious name change; a public API would need a TIP but I wouldn't see that as a problem, as I'm sure I have the API reasonably correct). ## Related Changes The branch includes uses of those functions. Sometimes this results in quite a bit more readable code (especially in `TclDefaultBgErrorHandlerObjCmd()` in tclEvent.c). I've no plans to do a varargs `TclDictGet`; I'm not convinced that would be worth it.
- login: "dkf"
- mimetype: "text/x-markdown"