Skip to content

Commit c362748

Browse files
committed
intrinsified PyObject_XXX
1 parent 90875d7 commit c362748

File tree

5 files changed

+648
-360
lines changed

5 files changed

+648
-360
lines changed

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def compile_module(self, name):
7272
type,
7373
lambda: ([], 12, sys.modules)
7474
)
75-
75+
7676
# Below are the PyObject_* identifiers that we know are used in numpy
77-
77+
7878
def is_buffer(x):
7979
__breakpoint__()
8080
if (isinstance(x, bytes) or isinstance(x, bytearray) or isinstance(x, array.array)):
@@ -103,7 +103,7 @@ def forgiving_len(o):
103103
)
104104
test_PyObject_Size = CPyExtFunction(
105105
forgiving_len,
106-
lambda: ([], [1, 2, 3, 4], (1,), sys.modules),
106+
lambda: ([], [1, 2, 3, 4], (1,), {1:1}, sys.modules),
107107
resultspec="i",
108108
)
109109
# PyObject_MALLOC
@@ -130,7 +130,7 @@ def forgiving_len(o):
130130
(kwonly_fun, tuple(), {"x": 456, "y": 789}),
131131
(sum, ("hello, world",), None),
132132
(kwonly_fun, tuple(), None),
133-
)
133+
)
134134

135135
test_PyObject_Call = CPyExtFunction(
136136
lambda args: args[0](*args[1], **args[2]) if args[2] else args[0](*args[1], **dict()),
@@ -184,7 +184,7 @@ def forgiving_len(o):
184184
argspec="Os",
185185
callfunction="PyObject_CallFunction",
186186
)
187-
187+
188188
class MyObject():
189189

190190
def foo(self, *args, **kwargs):
@@ -386,6 +386,18 @@ def setattrstring(args):
386386
resultspec="i",
387387
cmpfunc=unhandled_error_compare
388388
)
389+
test_PyObject_HasAttr = CPyExtFunction(
390+
lambda args: 1 if hasattr(*args) else 0,
391+
lambda: (
392+
(TestPyObject.MyObject, "foo"),
393+
([], "__len__"),
394+
([], "foobar"),
395+
),
396+
arguments=["PyObject* object", "PyObject* attr"],
397+
argspec="OO",
398+
resultspec="i",
399+
)
400+
389401
test_PyObject_HasAttrString = CPyExtFunction(
390402
lambda args: 1 if hasattr(*args) else 0,
391403
lambda: (
@@ -397,6 +409,23 @@ def setattrstring(args):
397409
argspec="Os",
398410
resultspec="i",
399411
)
412+
413+
def _ref_hash_not_implemented(args):
414+
if sys.version_info.minor >= 6:
415+
raise SystemError
416+
else:
417+
raise TypeError
418+
419+
test_PyObject_HashNotImplemented = CPyExtFunction(
420+
_ref_hash_not_implemented,
421+
lambda: (
422+
("foo",),
423+
),
424+
arguments=["PyObject* object"],
425+
argspec="O",
426+
resultspec="i",
427+
cmpfunc=unhandled_error_compare
428+
)
400429
__PyObject_GetAttr_ARGS = (
401430
(MyObject(), "foo"),
402431
([], "__len__"),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
import com.oracle.graal.python.builtins.modules.cext.PythonCextIterBuiltins;
125125
import com.oracle.graal.python.builtins.modules.cext.PythonCextModuleBuiltins;
126126
import com.oracle.graal.python.builtins.modules.cext.PythonCextNamespaceBuiltins;
127+
import com.oracle.graal.python.builtins.modules.cext.PythonCextObjectBuiltins;
127128
import com.oracle.graal.python.builtins.modules.cext.PythonCextPythonRunBuiltins;
128129
import com.oracle.graal.python.builtins.modules.cext.PythonCextSetBuiltins;
129130
import com.oracle.graal.python.builtins.modules.cext.PythonCextUnicodeBuiltins;
@@ -502,6 +503,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed)
502503
new PythonCextLongBuiltins(),
503504
new PythonCextMemoryViewBuiltins(),
504505
new PythonCextModuleBuiltins(),
506+
new PythonCextObjectBuiltins(),
505507
new PythonCextPythonRunBuiltins(),
506508
new PythonCextNamespaceBuiltins(),
507509
new PythonCextSetBuiltins(),

0 commit comments

Comments
 (0)