Skip to content

Commit 7914804

Browse files
committed
add tests
1 parent 1a80f75 commit 7914804

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

graalpython/com.oracle.graal.python.cext/include/cpython/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ _PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
155155
/* Call a callable without any arguments */
156156
static inline PyObject *
157157
_PyObject_CallNoArg(PyObject *func) {
158-
return PyObject_CallObject(func, NULL);
158+
return PyObject_CallObject(func, NULL); /* Truffle change: redirect to PyObject_CallObject until _PyObject_Vectorcall is implemented */
159159
}
160160

161161
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ PyObject * PyObject_GetAttr(PyObject *v, PyObject *name) {
433433
return NULL;
434434
}
435435

436-
int
437-
_PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
436+
// taken from CPython "Objects/object.c"
437+
int _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
438438
{
439439
PyTypeObject *tp = Py_TYPE(v);
440440

@@ -446,6 +446,18 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
446446
return -1;
447447
}
448448

449+
/* Truffle change: this fast path is only applicable to cpython
450+
if (tp->tp_getattro == PyObject_GenericGetAttr) {
451+
*result = _PyObject_GenericGetAttrWithDict(v, name, NULL, 1);
452+
if (*result != NULL) {
453+
return 1;
454+
}
455+
if (PyErr_Occurred()) {
456+
return -1;
457+
}
458+
return 0;
459+
}
460+
*/
449461
if (tp->tp_getattro != NULL) {
450462
*result = (*tp->tp_getattro)(v, name);
451463
}
@@ -472,8 +484,8 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
472484
return 0;
473485
}
474486

475-
int
476-
_PyObject_LookupAttrId(PyObject *v, _Py_Identifier *name, PyObject **result)
487+
// taken from CPython "Objects/object.c"
488+
int _PyObject_LookupAttrId(PyObject *v, _Py_Identifier *name, PyObject **result)
477489
{
478490
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
479491
if (!oname) {

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_functions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ def forgiving_len(o):
147147
argspec="OOO",
148148
callfunction="wrap_PyObject_Call",
149149
)
150+
test__PyObject_CallNoArg = CPyExtFunction(
151+
lambda args: args[0](),
152+
lambda: (
153+
(dict, ),
154+
(list, ),
155+
),
156+
arguments=["PyObject* callable"],
157+
argspec="O",
158+
)
150159
test_PyObject_CallObject = CPyExtFunction(
151160
lambda args: args[0](*args[1]),
152161
lambda: (

0 commit comments

Comments
 (0)