File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -195,3 +195,26 @@ def test_addressof_ref():
195
195
ev = dpctl .SyclEvent ()
196
196
ref = ev .addressof_ref ()
197
197
assert type (ref ) is int
198
+
199
+
200
+ def test_cpython_api ():
201
+ import ctypes
202
+ import sys
203
+
204
+ ev = dpctl .SyclEvent ()
205
+ mod = sys .modules [ev .__class__ .__module__ ]
206
+ # get capsule storign get_event_ref function ptr
207
+ ev_ref_fn_cap = mod .__pyx_capi__ ["get_event_ref" ]
208
+ # construct Python callable to invoke "get_event_ref"
209
+ cap_ptr_fn = ctypes .pythonapi .PyCapsule_GetPointer
210
+ cap_ptr_fn .restype = ctypes .c_void_p
211
+ cap_ptr_fn .argtypes = [ctypes .py_object , ctypes .c_char_p ]
212
+ ev_ref_fn_ptr = cap_ptr_fn (
213
+ ev_ref_fn_cap , b"DPCTLSyclEventRef (struct PySyclEventObject *)"
214
+ )
215
+ callable_maker = ctypes .PYFUNCTYPE (ctypes .c_void_p , ctypes .py_object )
216
+ get_event_ref_fn = callable_maker (ev_ref_fn_ptr )
217
+
218
+ r2 = ev .addressof_ref ()
219
+ r1 = get_event_ref_fn (ev )
220
+ assert r1 == r2
You can’t perform that action at this time.
0 commit comments