summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-12-01 13:43:22 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-12-01 13:43:22 (GMT)
commit27580c1fb5e8cb756304f523006d832d2e3532e7 (patch)
treef25f5c8e7a05f3d3d4049050459fecd7e81a5b46 /Modules
parent8be1c39eb3416e9d85c7e3ccd4794969588c8030 (diff)
downloadcpython-27580c1fb5e8cb756304f523006d832d2e3532e7.zip
cpython-27580c1fb5e8cb756304f523006d832d2e3532e7.tar.gz
cpython-27580c1fb5e8cb756304f523006d832d2e3532e7.tar.bz2
Replace PyObject_CallFunctionObjArgs() with fastcall
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_asynciomodule.c12
-rw-r--r--Modules/_csv.c2
-rw-r--r--Modules/_elementtree.c2
-rw-r--r--Modules/_json.c12
-rw-r--r--Modules/_ssl.c2
-rw-r--r--Modules/_struct.c2
-rw-r--r--Modules/_testbuffer.c10
-rw-r--r--Modules/gcmodule.c2
-rw-r--r--Modules/itertoolsmodule.c10
-rw-r--r--Modules/mathmodule.c6
-rw-r--r--Modules/posixmodule.c4
11 files changed, 31 insertions, 33 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index b65fc02..19503a8 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -721,8 +721,7 @@ static PyObject *
_asyncio_Future__repr_info_impl(FutureObj *self)
/*[clinic end generated code: output=fa69e901bd176cfb input=f21504d8e2ae1ca2]*/
{
- return PyObject_CallFunctionObjArgs(
- asyncio_future_repr_info_func, self, NULL);
+ return _PyObject_CallArg1(asyncio_future_repr_info_func, self);
}
/*[clinic input]
@@ -1535,8 +1534,7 @@ static PyObject *
_asyncio_Task__repr_info_impl(TaskObj *self)
/*[clinic end generated code: output=6a490eb66d5ba34b input=3c6d051ed3ddec8b]*/
{
- return PyObject_CallFunctionObjArgs(
- asyncio_task_repr_info_func, self, NULL);
+ return _PyObject_CallArg1(asyncio_task_repr_info_func, self);
}
/*[clinic input]
@@ -1896,7 +1894,7 @@ task_set_error_soon(TaskObj *task, PyObject *et, const char *format, ...)
return NULL;
}
- PyObject *e = PyObject_CallFunctionObjArgs(et, msg, NULL);
+ PyObject *e = _PyObject_CallArg1(et, msg);
Py_DECREF(msg);
if (e == NULL) {
return NULL;
@@ -1946,7 +1944,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
if (!exc) {
/* exc was not a CancelledError */
- exc = PyObject_CallFunctionObjArgs(asyncio_CancelledError, NULL);
+ exc = _PyObject_CallNoArg(asyncio_CancelledError);
if (!exc) {
goto fail;
}
@@ -2176,7 +2174,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
}
/* Check if `result` is a generator */
- o = PyObject_CallFunctionObjArgs(inspect_isgenerator, result, NULL);
+ o = _PyObject_CallArg1(inspect_isgenerator, result);
if (o == NULL) {
/* An exception in inspect.isgenerator */
goto fail;
diff --git a/Modules/_csv.c b/Modules/_csv.c
index e5324ae..08907db 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -1259,7 +1259,7 @@ csv_writerow(WriterObj *self, PyObject *seq)
(void *) self->rec, self->rec_len);
if (line == NULL)
return NULL;
- result = PyObject_CallFunctionObjArgs(self->writeline, line, NULL);
+ result = _PyObject_CallArg1(self->writeline, line);
Py_DECREF(line);
return result;
}
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 71245c2..f3e1e9f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2457,7 +2457,7 @@ treebuilder_append_event(TreeBuilderObject *self, PyObject *action,
PyObject *event = PyTuple_Pack(2, action, node);
if (event == NULL)
return -1;
- res = PyObject_CallFunctionObjArgs(self->events_append, event, NULL);
+ res = _PyObject_CallArg1(self->events_append, event);
Py_DECREF(event);
if (res == NULL)
return -1;
diff --git a/Modules/_json.c b/Modules/_json.c
index d3dbf98..da7b2ed 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -813,14 +813,14 @@ _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ss
*next_idx_ptr = idx + 1;
if (has_pairs_hook) {
- val = PyObject_CallFunctionObjArgs(s->object_pairs_hook, rval, NULL);
+ val = _PyObject_CallArg1(s->object_pairs_hook, rval);
Py_DECREF(rval);
return val;
}
/* if object_hook is not None: rval = object_hook(rval) */
if (s->object_hook != Py_None) {
- val = PyObject_CallFunctionObjArgs(s->object_hook, rval, NULL);
+ val = _PyObject_CallArg1(s->object_hook, rval);
Py_DECREF(rval);
return val;
}
@@ -924,7 +924,7 @@ _parse_constant(PyScannerObject *s, const char *constant, Py_ssize_t idx, Py_ssi
return NULL;
/* rval = parse_constant(constant) */
- rval = PyObject_CallFunctionObjArgs(s->parse_constant, cstr, NULL);
+ rval = _PyObject_CallArg1(s->parse_constant, cstr);
idx += PyUnicode_GET_LENGTH(cstr);
Py_DECREF(cstr);
*next_idx_ptr = idx;
@@ -1023,7 +1023,7 @@ _match_number_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_
idx - start);
if (numstr == NULL)
return NULL;
- rval = PyObject_CallFunctionObjArgs(custom_func, numstr, NULL);
+ rval = _PyObject_CallArg1(custom_func, numstr);
}
else {
Py_ssize_t i, n;
@@ -1475,7 +1475,7 @@ encoder_encode_string(PyEncoderObject *s, PyObject *obj)
if (s->fast_encode)
return s->fast_encode(NULL, obj);
else
- return PyObject_CallFunctionObjArgs(s->encoder, obj, NULL);
+ return _PyObject_CallArg1(s->encoder, obj);
}
static int
@@ -1553,7 +1553,7 @@ encoder_listencode_obj(PyEncoderObject *s, _PyAccu *acc,
return -1;
}
}
- newobj = PyObject_CallFunctionObjArgs(s->defaultfn, obj, NULL);
+ newobj = _PyObject_CallArg1(s->defaultfn, obj);
if (newobj == NULL) {
Py_XDECREF(ident);
return -1;
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index b198857..6003476 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3197,7 +3197,7 @@ _password_callback(char *buf, int size, int rwflag, void *userdata)
PySSL_END_ALLOW_THREADS_S(pw_info->thread_state);
if (pw_info->callable) {
- fn_ret = PyObject_CallFunctionObjArgs(pw_info->callable, NULL);
+ fn_ret = _PyObject_CallNoArg(pw_info->callable);
if (!fn_ret) {
/* TODO: It would be nice to move _ctypes_add_traceback() into the
core python API, so we could use it to add a frame here */
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 1d7a935..4ef5c89 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -2046,7 +2046,7 @@ cache_struct(PyObject *fmt)
return s_object;
}
- s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL);
+ s_object = _PyObject_CallArg1((PyObject *)(&PyStructType), fmt);
if (s_object != NULL) {
if (PyDict_Size(cache) >= MAXCACHE)
PyDict_Clear(cache);
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
index 13d3ccc..bf22f29 100644
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -312,7 +312,7 @@ pack_from_list(PyObject *obj, PyObject *items, PyObject *format,
assert(PyObject_CheckBuffer(obj));
assert(PyList_Check(items) || PyTuple_Check(items));
- structobj = PyObject_CallFunctionObjArgs(Struct, format, NULL);
+ structobj = _PyObject_CallArg1(Struct, format);
if (structobj == NULL)
return -1;
@@ -406,7 +406,7 @@ pack_single(char *ptr, PyObject *item, const char *fmt, Py_ssize_t itemsize)
if (format == NULL)
goto out;
- structobj = PyObject_CallFunctionObjArgs(Struct, format, NULL);
+ structobj = _PyObject_CallArg1(Struct, format);
if (structobj == NULL)
goto out;
@@ -620,7 +620,7 @@ unpack_rec(PyObject *unpack_from, char *ptr, PyObject *mview, char *item,
if (ndim == 0) {
memcpy(item, ptr, itemsize);
- x = PyObject_CallFunctionObjArgs(unpack_from, mview, NULL);
+ x = _PyObject_CallArg1(unpack_from, mview);
if (x == NULL)
return NULL;
if (PyTuple_GET_SIZE(x) == 1) {
@@ -696,7 +696,7 @@ ndarray_as_list(NDArrayObject *nd)
if (format == NULL)
goto out;
- structobj = PyObject_CallFunctionObjArgs(Struct, format, NULL);
+ structobj = _PyObject_CallArg1(Struct, format);
Py_DECREF(format);
if (structobj == NULL)
goto out;
@@ -788,7 +788,7 @@ get_itemsize(PyObject *format)
PyObject *tmp;
Py_ssize_t itemsize;
- tmp = PyObject_CallFunctionObjArgs(calcsize, format, NULL);
+ tmp = _PyObject_CallArg1(calcsize, format);
if (tmp == NULL)
return -1;
itemsize = PyLong_AsSsize_t(tmp);
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 754348e..a53cf20 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -709,7 +709,7 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
assert(callback != NULL);
/* copy-paste of weakrefobject.c's handle_callback() */
- temp = PyObject_CallFunctionObjArgs(callback, wr, NULL);
+ temp = _PyObject_CallArg1(callback, wr);
if (temp == NULL)
PyErr_WriteUnraisable(callback);
else
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 6bf04cb..5ea69a0 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -101,7 +101,7 @@ groupby_next(groupbyobject *gbo)
newkey = newvalue;
Py_INCREF(newvalue);
} else {
- newkey = PyObject_CallFunctionObjArgs(gbo->keyfunc, newvalue, NULL);
+ newkey = _PyObject_CallArg1(gbo->keyfunc, newvalue);
if (newkey == NULL) {
Py_DECREF(newvalue);
return NULL;
@@ -293,7 +293,7 @@ _grouper_next(_grouperobject *igo)
newkey = newvalue;
Py_INCREF(newvalue);
} else {
- newkey = PyObject_CallFunctionObjArgs(gbo->keyfunc, newvalue, NULL);
+ newkey = _PyObject_CallArg1(gbo->keyfunc, newvalue);
if (newkey == NULL) {
Py_DECREF(newvalue);
return NULL;
@@ -1130,7 +1130,7 @@ dropwhile_next(dropwhileobject *lz)
if (lz->start == 1)
return item;
- good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
+ good = _PyObject_CallArg1(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
@@ -1296,7 +1296,7 @@ takewhile_next(takewhileobject *lz)
if (item == NULL)
return NULL;
- good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
+ good = _PyObject_CallArg1(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
@@ -3824,7 +3824,7 @@ filterfalse_next(filterfalseobject *lz)
ok = PyObject_IsTrue(item);
} else {
PyObject *good;
- good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
+ good = _PyObject_CallArg1(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 95ea4f7..e7e34ef 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -951,7 +951,7 @@ static PyObject * math_ceil(PyObject *self, PyObject *number) {
return NULL;
return math_1_to_int(number, ceil, 0);
}
- result = PyObject_CallFunctionObjArgs(method, NULL);
+ result = _PyObject_CallNoArg(method);
Py_DECREF(method);
return result;
}
@@ -991,7 +991,7 @@ static PyObject * math_floor(PyObject *self, PyObject *number) {
return NULL;
return math_1_to_int(number, floor, 0);
}
- result = PyObject_CallFunctionObjArgs(method, NULL);
+ result = _PyObject_CallNoArg(method);
Py_DECREF(method);
return result;
}
@@ -1542,7 +1542,7 @@ math_trunc(PyObject *self, PyObject *number)
Py_TYPE(number)->tp_name);
return NULL;
}
- result = PyObject_CallFunctionObjArgs(trunc, NULL);
+ result = _PyObject_CallNoArg(trunc);
Py_DECREF(trunc);
return result;
}
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 2e9eb9e..129ff1c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -902,7 +902,7 @@ path_converter(PyObject *o, void *p)
goto error_exit;
}
- o = to_cleanup = PyObject_CallFunctionObjArgs(func, NULL);
+ o = to_cleanup = _PyObject_CallNoArg(func);
Py_DECREF(func);
if (NULL == o) {
goto error_exit;
@@ -12041,7 +12041,7 @@ PyOS_FSPath(PyObject *path)
Py_TYPE(path)->tp_name);
}
- path_repr = PyObject_CallFunctionObjArgs(func, NULL);
+ path_repr = _PyObject_CallNoArg(func);
Py_DECREF(func);
if (NULL == path_repr) {
return NULL;