Skip to content

Commit 1a80f75

Browse files
committed
add couple of native missing functions
1 parent 1b5226e commit 1a80f75

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
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_Vectorcall(func, NULL, 0, NULL);
158+
return PyObject_CallObject(func, NULL);
159159
}
160160

161161
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ PyObject* PyDict_GetItemWithError(PyObject* d, PyObject* k) {
6767
return UPCALL_CEXT_BORROWED(_jls_PyDict_GetItemWithError, native_to_java(d), native_to_java(k));
6868
}
6969

70+
PyObject *
71+
_PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
72+
{
73+
PyObject *kv;
74+
kv = _PyUnicode_FromId(key); /* borrowed */
75+
if (kv == NULL)
76+
return NULL;
77+
return PyDict_GetItemWithError(dp, kv);
78+
}
79+
7080
PyObject* _PyDict_GetItemId(PyObject* d, _Py_Identifier* id) {
7181
return PyDict_GetItemString(d, id->string);
7282
}

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

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

436+
int
437+
_PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
438+
{
439+
PyTypeObject *tp = Py_TYPE(v);
440+
441+
if (!PyUnicode_Check(name)) {
442+
PyErr_Format(PyExc_TypeError,
443+
"attribute name must be string, not '%.200s'",
444+
name->ob_type->tp_name);
445+
*result = NULL;
446+
return -1;
447+
}
448+
449+
if (tp->tp_getattro != NULL) {
450+
*result = (*tp->tp_getattro)(v, name);
451+
}
452+
else if (tp->tp_getattr != NULL) {
453+
const char *name_str = PyUnicode_AsUTF8(name);
454+
if (name_str == NULL) {
455+
*result = NULL;
456+
return -1;
457+
}
458+
*result = (*tp->tp_getattr)(v, (char *)name_str);
459+
}
460+
else {
461+
*result = NULL;
462+
return 0;
463+
}
464+
465+
if (*result != NULL) {
466+
return 1;
467+
}
468+
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
469+
return -1;
470+
}
471+
PyErr_Clear();
472+
return 0;
473+
}
474+
475+
int
476+
_PyObject_LookupAttrId(PyObject *v, _Py_Identifier *name, PyObject **result)
477+
{
478+
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
479+
if (!oname) {
480+
*result = NULL;
481+
return -1;
482+
}
483+
return _PyObject_LookupAttr(v, oname, result);
484+
}
485+
436486
UPCALL_ID(PyObject_GenericGetAttr);
437487
PyObject* PyObject_GenericGetAttr(PyObject* obj, PyObject* attr) {
438488
PyTypeObject *tp = Py_TYPE(obj);
@@ -486,6 +536,17 @@ int PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) {
486536
return -1;
487537
}
488538

539+
// taken from CPython "Objects/object.c"
540+
int _PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
541+
{
542+
int result;
543+
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
544+
if (!oname)
545+
return -1;
546+
result = PyObject_SetAttr(v, oname, w);
547+
return result;
548+
}
549+
489550
UPCALL_ID(PyObject_GenericSetAttr);
490551
int PyObject_GenericSetAttr(PyObject* obj, PyObject* attr, PyObject* value) {
491552
PyTypeObject *tp = Py_TYPE(obj);

0 commit comments

Comments
 (0)