[issue47128] Enhance Argument Clinic's NoneType return converter to give `void`

2022-03-28 Thread Oleg Iarygin


Oleg Iarygin  added the comment:

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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47128] Enhance Argument Clinic's NoneType return converter to give `void`

2022-03-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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.

--
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47128] Enhance Argument Clinic's NoneType return converter to give `void`

2022-03-26 Thread Oleg Iarygin


Oleg Iarygin  added the comment:

> The function should return different values for success and error

It does, and a `void` return type enforces it. Here is the trick:

> An important convention throughout the Python interpreter is the following: 
> when a function fails, it should set an exception condition and return an 
> error value (usually -1 or a NULL pointer).
>
> - 
> https://docs.python.org/3/extending/extending.html#intermezzo-errors-and-exceptions

Previously, a function could return NULL but forget to call `PyErr_*()`.  With 
`void`, however, the function has no other choise but to properly set the error 
indicator so the Clinic's part will see it and return NULL finishing the 
convention.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47128] Enhance Argument Clinic's NoneType return converter to give `void`

2022-03-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

The function should return different values for success and error. Functions 
which do not do this have bad design.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47128] Enhance Argument Clinic's NoneType return converter to give `void`

2022-03-26 Thread Oleg Iarygin


Change by Oleg Iarygin :


--
keywords: +patch
pull_requests: +30205
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/32126

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47128] Enhance Argument Clinic's NoneType return converter to give `void`

2022-03-26 Thread Oleg Iarygin


New submission from Oleg Iarygin :

The attached PR makes the following possible (note that the impl has a `void` 
return type):

/*[clinic input]
_io._IOBase.writelines -> NoneType
lines: object
/
[clinic start generated code]*/

static void
_io__IOBase_writelines_impl(PyObject *self, PyObject *lines)
/*[clinic end generated code: output=f3feca36db72dbd1 
input=286ba711cb7291ad]*/

Previously, the return type would be `Object *` with generated replacement of 
non-Py_None values to NULL on the other side.

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;
}

--
components: Argument Clinic
messages: 416062
nosy: arhadthedev, larry
priority: normal
severity: normal
status: open
title: Enhance Argument Clinic's NoneType return converter to give `void`
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com