-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Enhance Argument Clinic's NoneType return converter to give void
#91284
Comments
The attached PR makes the following possible (note that the impl has a
static void
_io__IOBase_writelines_impl(PyObject *self, PyObject *lines)
/*[clinic end generated code: output=f3feca36db72dbd1 input=286ba711cb7291ad]*/ Previously, the return type would be So now there is no need to track whether NULL or Py_None should be returned. Or should it be Py_RETURN_NONE? Argument Clinic does it by itself returning NULL on errors and PyNone otherwise: static PyObject *
_io__IOBase_writelines(PyObject *self, PyObject *lines)
{
PyObject *return_value = NULL;
_io__IOBase_writelines_impl(self, lines);
if (PyErr_Occurred()) {
goto exit;
}
return_value = Py_None;
Py_INCREF(Py_None);
exit:
return return_value;
} |
The function should return different values for success and error. Functions which do not do this have bad design. |
It does, and a
Previously, a function could return NULL but forget to call |
It is simpler and faster to return NULL than call PyErr_Occurred(). There is a special macro PY_RETURN_NONE, so there is no problem with returning None either. I do not think it would make the code better. |
Actually, you're right. For now, PyErr_Occurred is a GIL lock plus a memory access. While the access is cheap because of a L1 cache hit, the GIL takes its toll in a hot path. So I'm closing the PR until GIL removal is done so no performance penalty will be imposed. I could use _PyErr_Occurred because "Currently Argument Clinic is considered internal-only for CPython", but it requires extra modifications of the clinic that is undesirable. |
Not relevant anymore; see #32126 (comment). |
void
#32126Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: