Closed yrashk closed 9 months ago
There is no way to replace a fy_node's content 'under the covers' so to speak. By design a fy_node is uniquely identified by it's pointer in memory, so altering the node contents breaks this assumption.
On top of that each node may contain allocated resources that are dependent on the type (for instance key nodes are inserted in hashes for fast retrieval).
This is a very peculiar usage pattern, what are you trying to do?
I am essentially replacing nodes in a list I am iterating in. Right now I am doing this by removing and adding nodes but that's rather brittle (although works)
Due to the design decision that a node is uniquely identified by it's pointer, having that assumption change (i.e. same node pointer but different content) make this impossible.
Workaround is to remove and create new nodes.
I have a case where I want to replace (say, a scalar) node with an entirely different node type. I am doing this while iterating a list (which makes it even more complicated).
I couldn't find anything that would address this. Do you have any opinions on this, and would you be open in PR to address this need?
My current handwavy thinking suggests that since all fy_nodes are of the same type and size, something like an "in place" create would have solved my issue. Something along the lines of splitting
fy_node_alloc
intofy_node_alloc
andfy_node_init
(wherefy_node_alloc
will continue callingfy_node_init
) and generalizingcreate
functions to something likefy_node_create_TYPE_allocated
(that would take allocated memory and type and do its own initialization usingfy_node_init
). The only potentially missing piece here would be the ability to getsizeof(struct fy_node)
for which a new function will be needed so that external programs can allocate memory independently.What do you think?