Skip to content

Commit

Permalink
Use PyObject_CallNoArgs where applicable
Browse files Browse the repository at this point in the history
* PyObject_CallNoArgs was added in 3.9, pythoncapi_compat.h enables support for 3.8.
* Docs say it's the "most efficient way to call a callable Python object without any argument"
  • Loading branch information
Starbuck5 committed Jul 26, 2024
1 parent 0547247 commit da19260
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src_c/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pg_mod_autoinit(const char *modname)
}

if (funcobj) {
temp = PyObject_CallObject(funcobj, NULL);
temp = PyObject_CallNoArgs(funcobj);
if (temp) {
Py_DECREF(temp);
ret = 1;
Expand Down Expand Up @@ -305,7 +305,7 @@ pg_mod_autoquit(const char *modname)
PyErr_Clear();

if (funcobj) {
temp = PyObject_CallObject(funcobj, NULL);
temp = PyObject_CallNoArgs(funcobj);
Py_XDECREF(temp);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ _pg_quit(void)
}

if (PyCallable_Check(quit)) {
temp = PyObject_CallObject(quit, NULL);
temp = PyObject_CallNoArgs(quit);
if (temp)
Py_DECREF(temp);
else
Expand Down
2 changes: 1 addition & 1 deletion src_c/geometry_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pgCircle_FromObject(PyObject *obj, pgCircleBase *out)

if (PyCallable_Check(circleattr)) /*call if it's a method*/
{
PyObject *circleresult = PyObject_CallObject(circleattr, NULL);
PyObject *circleresult = PyObject_CallNoArgs(circleattr);
Py_DECREF(circleattr);
if (!circleresult) {
PyErr_Clear();
Expand Down
2 changes: 1 addition & 1 deletion src_c/rect_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ RectExport_RectFromObject(PyObject *obj, InnerRect *temp)
InnerRect *returnrect;
/*call if it's a method*/
if (PyCallable_Check(rectattr)) {
PyObject *rectresult = PyObject_CallObject(rectattr, NULL);
PyObject *rectresult = PyObject_CallNoArgs(rectattr);
Py_DECREF(rectattr);
if (rectresult == NULL) {
PyErr_Clear();
Expand Down
8 changes: 4 additions & 4 deletions src_c/rwobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ _pg_rw_size(SDL_RWops *context)

/* Current file position; need to restore it later.
*/
pos = PyObject_CallFunction(helper->tell, NULL);
pos = PyObject_CallNoArgs(helper->tell);
if (!pos) {
PyErr_Print();
goto end;
Expand All @@ -327,7 +327,7 @@ _pg_rw_size(SDL_RWops *context)

/* Record file size.
*/
tmp = PyObject_CallFunction(helper->tell, NULL);
tmp = PyObject_CallNoArgs(helper->tell);
if (!tmp) {
PyErr_Print();
goto end;
Expand Down Expand Up @@ -398,7 +398,7 @@ _pg_rw_close(SDL_RWops *context)
PyGILState_STATE state = PyGILState_Ensure();

if (helper->close) {
result = PyObject_CallFunction(helper->close, NULL);
result = PyObject_CallNoArgs(helper->close);
if (!result) {
PyErr_Print();
retval = -1;
Expand Down Expand Up @@ -479,7 +479,7 @@ _pg_rw_seek(SDL_RWops *context, Sint64 offset, int whence)
Py_DECREF(result);
}

result = PyObject_CallFunction(helper->tell, NULL);
result = PyObject_CallNoArgs(helper->tell);
if (!result) {
PyErr_Print();
retval = -1;
Expand Down

0 comments on commit da19260

Please sign in to comment.