-
-
Notifications
You must be signed in to change notification settings - Fork 11k
MAINT: Ensure that parsing errors are passed on even in tests. #11173
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
MAINT: Ensure that parsing errors are passed on even in tests. #11173
Conversation
@@ -280,13 +280,21 @@ addUfuncs(PyObject *dictionary) { | |||
"inner on the last dimension and broadcast on the rest \n" | |||
" \"(i),(i)->()\" \n", | |||
0, inner1d_signature); | |||
/* yes, this should not happen, but I just spent an hour looking for |
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.
Multiline comments like so:
/*
* blah
* blah
*/
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.
done
cdac054
to
a72fb26
Compare
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.
LGTM
Can you change |
@@ -280,13 +280,23 @@ addUfuncs(PyObject *dictionary) { | |||
"inner on the last dimension and broadcast on the rest \n" | |||
" \"(i),(i)->()\" \n", | |||
0, inner1d_signature); | |||
/* | |||
* yes, this should not happen, but I (MHvK) just spent an hour looking at |
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.
Not sure this comment is necessary - any PyObject *
allocation can fail due to memory limits, so we should always check results like this.
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.
Well, I'll maybe leave this as a breadcrump for the future - or to remind myself of hours waster...
@@ -372,10 +391,12 @@ static struct PyModuleDef moduledef = { | |||
#endif | |||
|
|||
#if defined(NPY_PY3K) | |||
#define RETVAL m | |||
#define RETVAL_SUCCESS m | |||
#define RETVAL_FAILURE 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.
In multiarraymodule.c
we use
#if defined(NPY_PY3K)
#define RETVAL(x) x
PyMODINIT_FUNC PyInit_multiarray(void) {
#else
#define RETVAL(x)
PyMODINIT_FUNC initmultiarray(void) {
#endif
would be nice to have a consistent macro here
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.
Wasn't aware of that - like it much better, so will change.
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.
A clear improvement, but I think we could be a little more consistent with how we do things elsewhere here
6aaed56
to
4a47c42
Compare
if (PyErr_Occurred()) { | ||
if (addUfuncs(d) < 0) { | ||
Py_DECREF(m); | ||
if (PyErr_Occurred()) { |
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.
Either:
- Testing
PyErr_Occurred()
is pointless - There is a bug in
PyUFunc_FromFuncAndDataAndSignature
which fails to set an exception correctly
I'm assuming the former, meaning you can just call PyErr_Print()
unconditionally
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.
Maybe I was being overly defensive here, but the docs for PyErr_Print
are very specific that one should be sure an error is set otherwise bad things happen. Normally, of course, we'd just return NULL
here and let downstream take care of it, but here we're setting a new error and I thought it was useful to at least print the old one.
But if you think this really doesn't make sense, I'll take it out (I had it out when I first added the return value).
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 suppose my point is that addUfuncs() < 0
is already our test to be sure that an error is set. If we returned -1 but forgot to set an error, that's a bug.
Also it seems that PyErr_Print
is perfectly ok with there being no error anyway. So I'd say keep the PyErr_Print(), but drop the condition guarding it.
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.
So much for trusting the documentation... OK, condition dropped.
*/ | ||
if (f == NULL) { | ||
return -1; | ||
} | ||
PyDict_SetItemString(dictionary, "inner1d", f); |
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.
In principle we should be checking the return value of PyDict_SetItemString
too, but I'm happy for you to declare that out of scope for this PR.
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, let's do that - I think if we're just calling standard python interface routines, we can be a bit more cavalier; we mostly need to guard against our own mistakes!
4a47c42
to
e88c23e
Compare
To avoid it wasting a few hours of someone else's time if they edit the gufunc signature parser.
e88c23e
to
0091127
Compare
Thanks Marten |
To avoid it wasting a few hours of someone else's time if they edit the gufunc signature parser....
cc @mattip, since he may just have suffered similar problems...