This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: C API: provide new object protocol helper
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 3.8
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Bartosz Gołaszewski, cheryl.sabella, jdemeyer, pablogsal, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2018-06-11 09:54 by Bartosz Gołaszewski, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7625 closed python-dev, 2018-06-11 09:57
Messages (5)
msg319288 - (view) Author: Bartosz Gołaszewski (Bartosz Gołaszewski) * Date: 2018-06-11 09:54
If we want to call an object's method from C code and pass it the args and kwargs tuples unchanged, we need to first retrieve the callable object using PyObject_GetAttrString(), then call it using PyObject_Call().

I would like to propose wrapping the two calls in a new helper.
msg319289 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-06-11 10:19
Is this case common enough for adding special API? The name PyObject_CallMethodArgs looks too similar to the existing name PyObject_CallMethodObjArgs, this will make confusion. If add an API that accepts the method name as C string, you need to add also an API for method name passed as Python string and a private API for method name passed as `struct _Py_Identifier *`. Adding new API has a non-zero cost. It adds maintenance burden for core developers, it increases the number of things that should be learned by users, and can leads to generating less optimal code by the compiler, because it will need to analyze more code in the same file, and it can optimize less common paths and left more common paths unoptimized.

Are you aware that you can pass the args tuple unchanged by using PyObject_CallMethod()? PyObject_CallMethod(obj, name, "O", args)
msg319296 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-11 11:34
> PyObject_CallMethodArgs(PyObject *obj, const char *name, PyObject *args, PyObject *kwargs)

This API is not efficient. It requires to create a temporary tuple and dictionary to pass position and keyword arguments. Look at FASTCALL which has a very different API. Sadly, FASTCALL APIs are currently private.
msg342777 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-05-17 23:54
It seems that this issue is languishing without any additional comments from the OP.  Should it be closed as rejected?  Thanks!
msg349048 - (view) Author: Jeroen Demeyer (jdemeyer) * (Python triager) Date: 2019-08-05 12:13
I agree with rejecting and closing this issue.
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 78010
2019-08-05 12:51:57serhiy.storchakasetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2019-08-05 12:13:55jdemeyersetnosy: + jdemeyer
messages: + msg349048
2019-05-17 23:54:42cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg342777
2018-06-14 13:56:08pablogsalsetnosy: + pablogsal
2018-06-11 11:34:08vstinnersetmessages: + msg319296
2018-06-11 10:19:00serhiy.storchakasetnosy: + vstinner, serhiy.storchaka
messages: + msg319289
2018-06-11 09:57:33python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request7244
2018-06-11 09:54:30Bartosz Gołaszewskicreate