Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
May 30, 2018

Conversation

mhvk
Copy link
Contributor

@mhvk mhvk commented May 27, 2018

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...

@@ -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
Copy link
Member

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
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mhvk mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch from cdac054 to a72fb26 Compare May 28, 2018 00:59
Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eric-wieser
Copy link
Member

Can you change addUfuncs to return an error code too?

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

@eric-wieser eric-wieser May 29, 2018

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

Copy link
Contributor Author

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.

Copy link
Member

@eric-wieser eric-wieser left a 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

@mhvk mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch 2 times, most recently from 6aaed56 to 4a47c42 Compare May 29, 2018 13:09
if (PyErr_Occurred()) {
if (addUfuncs(d) < 0) {
Py_DECREF(m);
if (PyErr_Occurred()) {
Copy link
Member

@eric-wieser eric-wieser May 29, 2018

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

Copy link
Contributor Author

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).

Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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!

@mhvk mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch from 4a47c42 to e88c23e Compare May 29, 2018 19:02
To avoid it wasting a few hours of someone else's time if they
edit the gufunc signature parser.
@mhvk mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch from e88c23e to 0091127 Compare May 29, 2018 21:00
@mattip mattip merged commit 896393b into numpy:master May 30, 2018
@mattip
Copy link
Member

mattip commented May 30, 2018

Thanks Marten

@mhvk mhvk deleted the gufunc-avoid-wasting-time-writing-parser branch May 30, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants