-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
BUG: PyDataMem_SetHandler check capsule name
#26529
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
Conversation
|
If you look at what is failing, you should find that it is failing when |
PyDataMem_SetHandler check capsule namePyDataMem_SetHandler check capsule name
|
I placed the mem_handler check after the null check and all the tests pass now |
|
LGTM, adding that constant seems fine also (it's used in at least one more place, but OK). Would you be up for adding a test? The memory handler tests should be easy to expand to do that I suspect and it's nice to add one, if just to cover the code. |
|
I have made a few changes given your last feedback:
|
| handler = PyDataMem_DefaultHandler; | ||
| } | ||
| if (!PyCapsule_IsValid(handler, MEM_HANDLER_CAPSULE_NAME)) { | ||
| PyErr_SetString(PyExc_ValueError, "Capsule must be named 'mem_handler'"); |
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.
Does it make sense to throw this exception? This will only run under the hood right?
If it doesn't make sense, what's the appropriate way to handle this?
P.S: This is my first time reading numpy's C code.
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 think this is fine, no reason to bike-shed the error type.
numpy/_core/tests/test_mem_policy.py
Outdated
| return old; | ||
| """), | ||
| ("set_wrong_capsule_name_data_policy", "METH_NOARGS", """ | ||
| PyObject *secret_data = |
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 used the same struct for the secret_data_policy. Is this ok or should I create a struct just for this test?
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's can be anything here really. But let's rename the object (will just apply the suggestion though).
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.
Thanks for the test follow up!
numpy/_core/tests/test_mem_policy.py
Outdated
| return old; | ||
| """), | ||
| ("set_wrong_capsule_name_data_policy", "METH_NOARGS", """ | ||
| PyObject *secret_data = |
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's can be anything here really. But let's rename the object (will just apply the suggestion though).
| handler = PyDataMem_DefaultHandler; | ||
| } | ||
| if (!PyCapsule_IsValid(handler, MEM_HANDLER_CAPSULE_NAME)) { | ||
| PyErr_SetString(PyExc_ValueError, "Capsule must be named 'mem_handler'"); |
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 think this is fine, no reason to bike-shed the error type.

Closes #26137.
Tests capsule name and sets
PyErrif not valid: