Closed ringabout closed 1 month ago
I don't understand this. Surely the finalizer can call destroy(x[])
?
type
FooObj = object
Foo = ref FooObj
data: int
proc delete(self: Foo) =
self.data = 0
new(result, delete)
the new finalizer creates a wrapper around the delete
function
proc deleteHook(self: var FooObj) =
delete(self)
Then deleteHook
is bound to the FooObj
. The non-var destructor requires deleteHook
to be immutable, i.e., delete
to be immutable.
That only means that new
got more picky about the finalizer's requirements, not that it needs to be removed entirely.
not that it needs to be removed entirely.
the fact that one call to NewFinalize changes the behavior for all instances of that type is a major wart - getting rid of this atrocity would do the language good.
the fact that one call to NewFinalize changes the behavior for all instances of that type is a major wart - getting rid of this atrocity would do the language good.
That is not an issue anymore with arc/orc anyway and it's now done consistently. Afaik.
Succeeded by https://github.com/nim-lang/Nim/pull/24354
The
new
function supports a finalizer with aref T
type, which is not compatible with the non-var destructor. Because in a finailizer, users are free to modify the parameter. You cannot wrap it without make it mutable in a non-var destructor, e.g.