Author: Jan Nijtmans <[email protected]> State: Draft Type: Project Created: 11-05-2023 Tcl-Version: 9.0 Tcl-Branch: tip-668
The normal functions
Tcl_Realloc() (and a few more)
result in a Panic when the memory allocation fails. There are
which return a NULL-pointer in this case. The advantage of the
Attempt form of those functions is that we no longer have to
check before the function-call whether the
isn't too big, we can just make the call and check afterwards
whether it was possible or not. This TIP proposes to make this
behavior available to the normal
Tcl_Realloc() have been removed,
Tcl_AttemptRealloc() renamed to
Tcl_Realloc(). This means that everything will
keep functioning as before. The only visible change is that
instead of panicing, those functions might unexpectedly
return a NULL-pointer. Most likely, those null-pointers
eventually result in a null-pointer-exception, which is
just as bad as panicing.
Implementation is in Tcl branch "tip-668".
Tcl_Realloc() calls should
check their result, and handle a clean recovery when
allocation fails. Some newer code (like the improved list
implementation) already does that by using the Attempt*
functions. This change eliminates the need for special
Attempt*-functions, it just provides this for all
normal functions. This makes
behave the same as the standard C
which also return a null-pointer on failure.
This document has been placed in the public domain.