Tcl_InitStringRep design issues
This can lead to an invalid ckrealloc call: Tcl_InitStringRep(objPtr, NULL, 0); Tcl_InitStringRep(objPtr, NULL, 0); Also, there's nothing in place to detect when a truncation call does not actually truncate, and to deal with possible memory allocation failure in that circumstance.
e7511df3a1[9899c273ab] Rewrite Tcl_InitStringRep to account for all encounters with the non-allocated empty string rep. check-in2021-11-08 00:06:27
Fix committed.
It looks like this 'redesign' is only partially done.
Yes, Tcl_InitStringRep can now handle allocation failures by returning NULL, but many callers of this function don't check for the NULL value. In other words: Tcl_InitStringRep() behaves like Tcl_AttemptInitStringRep(). This is OK, but callers should translate this NULL to either a panic or a proper error-handling.
I'll have a look.
Proposed further fix [here]
Needs a TIP
I think, the new "Attempt" series is a good idea. It is backward compatible and cleans-up a big drawback, that a library may not act on a memory issue.
In the idea of a library, a panic should never happen, but always, an error should be reported...
I can understand that cleaning this up in TCL and friends is a big task, as the error path is just often not there.
It is a bit like "encoding now throws an error". New error path - many hidden issues.
Thanks for going this way, Harald
See ticket [78f44214]. This command is undocumented in the docs. But the introducing TIP documented the NULL return on memory error.
It might be ok to do so and not to add an Attempt version of it.
Harald
> It might be ok to do so and not to add an Attempt version of it
Yeah, better fix the callers then.
Thanks!
Jan Nijtmans
I think [this] fixes all callers.
Closing