| Ticket UUID: | 1357401 | ||
| Title: | Add Tcl_DStringClear & Tcl_DStringAppendDString to tcl.h | ||
| Type: | RFE | Created on: | 2005-11-15 14:11:20 |
| Submitter: | nobody | Assigned to: | dkf |
| Subsystem: | 10. Objects | Severity: | |
| Priority: | 5 Medium | Last modified: | 2012-07-04 22:14:38 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | None | ||
| Description: | ||||
The following two simple DString macros would be
useful both in the Tcl core itself and for the general
Tcl extension writer.
#define Tcl_DStringClear(dsPtr) \
((dsPtr)->string[((dsPtr)->length = 0)] = '\0')
#define Tcl_DStringAppendDString(dsPtr,ds2Ptr) \
Tcl_DStringAppend((dsPtr), \
Tcl_DStringValue(ds2Ptr), \
Tcl_DStringLength(ds2Ptr) \
)
The first, Tcl_DStringClear, simply clears an already
Init'd DString's buffer.
For cases where this is useful (to reuse a DString), the
core currently either does a Tcl_DStringFree() or
a Tcl_DStringSetLength(...,0) neither of which is ideal.
In particular using Tcl_DStringFree might free a malloc'd
buffer which might have to be re-malloced.
The new macro would also help documenting the
code's intention.
The second is simply a wrapper around
Tcl_DStringAppend which simplifies and self documents
the code so that it is obvious that what is being
appended is a Tcl_DString.
| ||||
| User Comments: | ||||
dkf added on 2012-07-03 15:33:25:
I'd be inclined to put them in tclInt.h to start out with. Also, TclDStringAppendObj would be reasonable and we already have TclDStringResult. These sorts of things would be long-term suitable for promoting to the public API (though probably always as functions; macros are too likely to have surprising side-effects). dkf added on 2012-07-03 21:54:18:
There are now Tcl-internal implementations of these in 8.6; keeping this FRQ open as they're candidates for future exposure. nijtmans added on 2012-07-04 19:47:36:
Win32 build broken now: tclWinReg.o:tclWinReg.c:(.text+0x12e5): undefined reference to `_TclDStringAppendObj' Recommended to revert your changes in tclWinReg.c. dkf added on 2012-07-04 20:41:31:
oops; fixed nijtmans added on 2012-07-04 22:14:38:
Fix confirmed | ||||
