Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Unified Diff: Modules/_operator.c

Issue 29259: Add tp_fastcall to PyTypeObject: support FASTCALL calling convention for all callable objects
Patch Set: Created 2 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_sys.py ('k') | Objects/abstract.c » ('j') | Objects/abstract.c » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/_operator.c Wed Jan 25 23:33:27 2017 +0100
+++ b/Modules/_operator.c Thu Jan 26 02:43:18 2017 +0100
@@ -988,24 +988,29 @@ itemgetter_traverse(itemgetterobject *ig
}
static PyObject *
-itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw)
+itemgetter_call(itemgetterobject *ig, PyObject **args, Py_ssize_t nargs,
+ PyObject *kwnames)
{
PyObject *obj, *result;
Py_ssize_t i, nitems=ig->nitems;
- if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw))
+ if (kwnames != NULL && !_PyArg_NoStackKeywords("itemgetter", kwnames)) {
return NULL;
- if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj))
+ }
+ if (!_PyArg_UnpackStack(args, nargs, "itemgetter", 1, 1, &obj)) {
return NULL;
- if (nitems == 1)
+ }
+ if (nitems == 1) {
return PyObject_GetItem(obj, ig->item);
+ }
assert(PyTuple_Check(ig->item));
assert(PyTuple_GET_SIZE(ig->item) == nitems);
result = PyTuple_New(nitems);
- if (result == NULL)
+ if (result == NULL) {
return NULL;
+ }
for (i=0 ; i < nitems ; i++) {
PyObject *item, *val;
@@ -1078,7 +1083,7 @@ static PyTypeObject itemgetter_type = {
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
- (ternaryfunc)itemgetter_call, /* tp_call */
+ 0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
@@ -1102,7 +1107,8 @@ static PyTypeObject itemgetter_type = {
0, /* tp_init */
0, /* tp_alloc */
itemgetter_new, /* tp_new */
- 0, /* tp_free */
+
+ .tp_fastcall = (fastternaryfunc)itemgetter_call,
};
@@ -1278,24 +1284,30 @@ dotted_getattr(PyObject *obj, PyObject *
}
static PyObject *
-attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
+attrgetter_call(attrgetterobject *ag, PyObject **args, Py_ssize_t nargs,
+ PyObject *kwnames)
{
PyObject *obj, *result;
Py_ssize_t i, nattrs=ag->nattrs;
- if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw))
+ if (kwnames != NULL && !_PyArg_NoStackKeywords("attrgetter", kwnames)) {
return NULL;
- if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj))
+ }
+ if (!_PyArg_UnpackStack(args, nargs, "attrgetter", 1, 1, &obj)) {
return NULL;
- if (ag->nattrs == 1) /* ag->attr is always a tuple */
+ }
+ /* ag->attr is always a tuple */
+ if (ag->nattrs == 1) {
return dotted_getattr(obj, PyTuple_GET_ITEM(ag->attr, 0));
+ }
assert(PyTuple_Check(ag->attr));
assert(PyTuple_GET_SIZE(ag->attr) == nattrs);
result = PyTuple_New(nattrs);
- if (result == NULL)
+ if (result == NULL) {
return NULL;
+ }
for (i=0 ; i < nattrs ; i++) {
PyObject *attr, *val;
@@ -1310,6 +1322,7 @@ attrgetter_call(attrgetterobject *ag, Py
return result;
}
+
static PyObject *
dotjoinattr(PyObject *attr, PyObject **attrsep)
{
@@ -1422,7 +1435,7 @@ static PyTypeObject attrgetter_type = {
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
- (ternaryfunc)attrgetter_call, /* tp_call */
+ 0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
@@ -1446,7 +1459,8 @@ static PyTypeObject attrgetter_type = {
0, /* tp_init */
0, /* tp_alloc */
attrgetter_new, /* tp_new */
- 0, /* tp_free */
+
+ .tp_fastcall = (fastternaryfunc)attrgetter_call,
};
@@ -1523,13 +1537,14 @@ methodcaller_traverse(methodcallerobject
}
static PyObject *
-methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw)
+methodcaller_call(methodcallerobject *mc, PyObject **args,
+ Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *method, *obj, *result;
- if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw))
+ if (kwnames != NULL && !_PyArg_NoStackKeywords("methodcaller", kwnames))
return NULL;
- if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj))
+ if (!_PyArg_UnpackStack(args, nargs, "methodcaller", 1, 1, &obj))
return NULL;
method = PyObject_GetAttr(obj, mc->name);
if (method == NULL)
@@ -1686,7 +1701,7 @@ static PyTypeObject methodcaller_type =
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
- (ternaryfunc)methodcaller_call, /* tp_call */
+ 0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
@@ -1710,7 +1725,8 @@ static PyTypeObject methodcaller_type =
0, /* tp_init */
0, /* tp_alloc */
methodcaller_new, /* tp_new */
- 0, /* tp_free */
+
+ .tp_fastcall = (fastternaryfunc)methodcaller_call,
};
« no previous file with comments | « Lib/test/test_sys.py ('k') | Objects/abstract.c » ('j') | Objects/abstract.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+