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
Solve memory leak to fix issue #7210 #7247
Conversation
…ove memory leaks.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
@ysheffer thank you for submitting this to the Numba issue tracker. It seems like your PR is doing a lot of cosmetics to the code in addition to implementing the feature. Do you think you could submit this PR with only the feature and not the cosmetics, as this makes it harder to review. Thanks! |
Redefined MOD_INIT sections in _num_threads.c, _omppool.cpp, tbbpool.cpp, workqueue.c.
@esc Thank you for your comment. Sure thing, I have updated the PR accordinaglly. |
@ysheffer thank you for making those changes, I have added it to the queue for review. |
numba/_pymodule.h
Outdated
@@ -24,5 +24,10 @@ | |||
#define PyInt_Type PyLong_Type | |||
#define PyInt_Check PyLong_Check | |||
#define PyInt_CheckExact PyLong_CheckExact | |||
// Define object attribute using a temporary variable to avoid memory leak | |||
#define SetAttrStringFromVoidPointer(m, name, tmp) \ |
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.
I think you had better wrap these three lines with a do { } while (false)
block and declare a temporary variable in the block instead of using an external variable.
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.
@Snape3058 thanks, agree.
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.
This is now applied, but I used while (0)
instead of while (false)
because false
is not defined everywhere the macro is used.
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.
@ysheffer Many thanks for the patch, couple of minor things to look at else looks good.
numba/_pymodule.h
Outdated
@@ -24,5 +24,10 @@ | |||
#define PyInt_Type PyLong_Type | |||
#define PyInt_Check PyLong_Check | |||
#define PyInt_CheckExact PyLong_CheckExact | |||
// Define object attribute using a temporary variable to avoid memory leak | |||
#define SetAttrStringFromVoidPointer(m, name, tmp) \ |
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.
@Snape3058 thanks, agree.
Co-authored-by: stuartarchibald <stuartarchibald@users.noreply.github.com>
This avoids it needing to have a temp passed in. Formatting is also altered slightly to match that of existing code.
@stuartarchibald This should be ready for another look now. |
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.
@ysheffer Congratulations on your first contribution to Numba! |
Added a macro to _pymodule.h and set attributes in _num_threads.c, _omppool.cpp,
tbbpool.cpp, workqueue.c using a temporary variable to solve memory leak and fix #7210 .