-
Notifications
You must be signed in to change notification settings - Fork 48
Free the map target when the object is destroyed #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
PR Verification FAILED |
The build success notification is broken, real failing build here: https://github.com/intel-innersource/applications.simulators.simics.simics-base/actions/runs/15248158485 (and nitpick: the "destoryed" typo remains in the commit msg) |
Regarding test, what we possibly could do would be to add an internal function |
method destroy() default { | ||
SIM_free_map_target(this.map_target); | ||
this.map_target = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding build errors: one thing you can do is to wrap this in a group _internal_destructor is destroy
to avoid clashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a solution, but is it desirable to always and unconditionally free the map target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding build errors: one thing you can do is to wrap this in a
group _internal_destructor is destroy
to avoid clashes.
Would that be preferred? I could fix these particular build errors in pcie-downstream-port and cxl-downstream-port in the base repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a solution, but is it desirable to always and unconditionally free the map target?
If the object is deleted, is there any scenario where not freeing the map target makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was about to say. The build issues are due to various sporadic destroy_tmpl
templates scattered across the repo that was a workaround before the destroy
template was officially added. These could be addressed by simply cleaning up the old usages of destroy_tmpl
and using destroy
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a solution, but is it desirable to always and unconditionally free the map target?
If the object is deleted, is there any scenario where not freeing the map target makes sense?
Dunno. I figure not, save, peraps, some extremely bad exotic interactions, which would constitute separate bugs in their own right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or well -- perhaps there'd be merit in making it an overridable method of the connect, because that'd allow the user to act on the connected object before freeing it (by calling default()
). An internal destructor would make that impossible. But I don't know how realistic such a use case would be.
In general, the question of overrides are something to consider. If there is a destroy()
specified, and the user doesn't call default()
(whether they be because the code precedes this PR or because they forgot), then the map target won't get freed. Having an internal destructor object prevents that situation from occurring. Another consideration is that destroy
of subobjects are guaranteed to be called first before their parent objects. This means there is no issue if there's a custom destroy
of the connect that also frees the map target -- because this internal destructor will set the map_target
to NULL
, and SIM_free_map_target
is a noop on NULL
.
So there are pros and cons here. I'm leaning towards the internal destructor, though.
I tried to make changes to
src/tools/dmlc/test/1.4/lib/T_map_target_connect.py
to test this, but I couldn't find a good way to check if the map target had been free:d. Let me know if you think this is OK or if you have a good way of testing this.