[click] uninitialize() deprecated
Eddie Kohler
kohler at icir.org
Fri Apr 5 13:06:43 EST 2002
Hey all, a heads up about Element::uninitialize().
Element::uninitialize() was a poor interface, as it was called too
infrequently: i.e., only if the element had initialized successfully. The
user had to explicitly free memory---usually via an explicit call to
uninitialize()---if initialization failed, or if configure() succeeded but
initialize() was never called. This was a pain, so people didn't do it, or
did it incorrectly, leading to double-frees and memory leaks.
Solution: deprecate uninitialize(), and add a new
Element::cleanup(CleanupStage) method. This method is _always_ called,
exactly once, at some point before the element is deleted. The CleanupStage
argument, an enumerated value, says how far the element was initialized:
not at all (CLEANUP_NO_ROUTER), configure() failed
(CLEANUP_CONFIGURE_FAILED), configure() succeeded but initialize() was not
called (CLEANUP_CONFIGURED), initialize() failed
(CLEANUP_INITIALIZE_FAILED), initialize() succeeded but the router as a
whole failed (CLEANUP_INITIALIZED), and the router initialized
successfully, including this element (CLEANUP_ROUTER_INITIALIZED). So
uninitialize() corresponded to "stage >= CLEANUP_INITIALIZED".
The default implementation of cleanup() calls uninitialize() when
appropriate, so this change should be source-compatible. However, at some
point in the future, we will remove uninitialize() altogether.
All elements in the 'elements/' hierarchy now use cleanup(CleanupStage)
instead of uninitialize(). This may have introduced some bugs, although I
hope not. If so, as always, complain to the list!
Eddie
More information about the click
mailing list