Skip to content

Commit 4778eab

Browse files
committed
Replace PyObject_CallFunction() with fastcall
Replace PyObject_CallFunction(func, "O", arg) and PyObject_CallFunction(func, "O", arg, NULL) with _PyObject_CallArg1(func, arg) Replace PyObject_CallFunction(func, NULL) with _PyObject_CallNoArg(func) _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack.
1 parent 842cfff commit 4778eab

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

Modules/_collectionsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ deque_copy(PyObject *deque)
538538
return NULL;
539539
}
540540
if (old_deque->maxlen < 0)
541-
return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "O", deque, NULL);
541+
return _PyObject_CallArg1((PyObject *)(Py_TYPE(deque)), deque);
542542
else
543543
return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
544544
deque, old_deque->maxlen, NULL);

Modules/_elementtree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,7 @@ expat_set_error(enum XML_Error error_code, Py_ssize_t line, Py_ssize_t column,
28312831
if (errmsg == NULL)
28322832
return;
28332833

2834-
error = PyObject_CallFunction(st->parseerror_obj, "O", errmsg);
2834+
error = _PyObject_CallArg1(st->parseerror_obj, errmsg);
28352835
Py_DECREF(errmsg);
28362836
if (!error)
28372837
return;
@@ -2894,7 +2894,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
28942894
(TreeBuilderObject*) self->target, value
28952895
);
28962896
else if (self->handle_data)
2897-
res = PyObject_CallFunction(self->handle_data, "O", value);
2897+
res = _PyObject_CallArg1(self->handle_data, value);
28982898
else
28992899
res = NULL;
29002900
Py_XDECREF(res);
@@ -3004,7 +3004,7 @@ expat_data_handler(XMLParserObject* self, const XML_Char* data_in,
30043004
/* shortcut */
30053005
res = treebuilder_handle_data((TreeBuilderObject*) self->target, data);
30063006
else if (self->handle_data)
3007-
res = PyObject_CallFunction(self->handle_data, "O", data);
3007+
res = _PyObject_CallArg1(self->handle_data, data);
30083008
else
30093009
res = NULL;
30103010

@@ -3031,7 +3031,7 @@ expat_end_handler(XMLParserObject* self, const XML_Char* tag_in)
30313031
else if (self->handle_end) {
30323032
tag = makeuniversal(self, tag_in);
30333033
if (tag) {
3034-
res = PyObject_CallFunction(self->handle_end, "O", tag);
3034+
res = _PyObject_CallArg1(self->handle_end, tag);
30353035
Py_DECREF(tag);
30363036
}
30373037
}
@@ -3090,7 +3090,7 @@ expat_comment_handler(XMLParserObject* self, const XML_Char* comment_in)
30903090
if (self->handle_comment) {
30913091
comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict");
30923092
if (comment) {
3093-
res = PyObject_CallFunction(self->handle_comment, "O", comment);
3093+
res = _PyObject_CallArg1(self->handle_comment, comment);
30943094
Py_XDECREF(res);
30953095
Py_DECREF(comment);
30963096
}

Modules/pyexpat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ set_error(xmlparseobject *self, enum XML_Error code)
119119
XML_ErrorString(code), lineno, column);
120120
if (buffer == NULL)
121121
return NULL;
122-
err = PyObject_CallFunction(ErrorObject, "O", buffer);
122+
err = _PyObject_CallArg1(ErrorObject, buffer);
123123
Py_DECREF(buffer);
124124
if ( err != NULL
125125
&& set_error_attr(err, "code", code)

Modules/readline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ on_hook(PyObject *func)
868868
int result = 0;
869869
if (func != NULL) {
870870
PyObject *r;
871-
r = PyObject_CallFunction(func, NULL);
871+
r = _PyObject_CallNoArg(func);
872872
if (r == NULL)
873873
goto error;
874874
if (r == Py_None)

Objects/genobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ async_gen_init_hooks(PyAsyncGenObject *o)
13411341
PyObject *res;
13421342

13431343
Py_INCREF(firstiter);
1344-
res = PyObject_CallFunction(firstiter, "O", o);
1344+
res = _PyObject_CallArg1(firstiter, o);
13451345
Py_DECREF(firstiter);
13461346
if (res == NULL) {
13471347
return 1;

Python/_warnings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ warn_explicit(PyObject *category, PyObject *message,
476476
}
477477
else {
478478
text = message;
479-
message = PyObject_CallFunction(category, "O", message);
479+
message = _PyObject_CallArg1(category, message);
480480
if (message == NULL)
481481
goto cleanup;
482482
}

Python/codecs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ PyObject *codec_makeincrementalcodec(PyObject *codec_info,
284284
if (errors)
285285
ret = PyObject_CallFunction(inccodec, "s", errors);
286286
else
287-
ret = PyObject_CallFunction(inccodec, NULL);
287+
ret = _PyObject_CallNoArg(inccodec);
288288
Py_DECREF(inccodec);
289289
return ret;
290290
}
@@ -322,7 +322,7 @@ PyObject *codec_getstreamcodec(const char *encoding,
322322
if (errors != NULL)
323323
streamcodec = PyObject_CallFunction(codeccls, "Os", stream, errors);
324324
else
325-
streamcodec = PyObject_CallFunction(codeccls, "O", stream);
325+
streamcodec = _PyObject_CallArg1(codeccls, stream);
326326
Py_DECREF(codecs);
327327
return streamcodec;
328328
}

Python/marshal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ r_object(RFILE *p)
12741274

12751275
if (n == 0 && type == TYPE_FROZENSET) {
12761276
/* call frozenset() to get the empty frozenset singleton */
1277-
v = PyObject_CallFunction((PyObject*)&PyFrozenSet_Type, NULL);
1277+
v = _PyObject_CallNoArg((PyObject*)&PyFrozenSet_Type);
12781278
if (v == NULL)
12791279
break;
12801280
R_REF(v);

0 commit comments

Comments
 (0)