@@ -545,6 +545,7 @@ def test_cpython_api(memory_ctor):
545
545
mem_q_ref_fn_cap = mod .__pyx_capi__ ["Memory_GetQueueRef" ]
546
546
mem_ctx_ref_fn_cap = mod .__pyx_capi__ ["Memory_GetContextRef" ]
547
547
mem_nby_fn_cap = mod .__pyx_capi__ ["Memory_GetNumBytes" ]
548
+ mem_make_fn_cap = mod .__pyx_capi__ ["Memory_Make" ]
548
549
# construct Python callable to invoke functions
549
550
cap_ptr_fn = ctypes .pythonapi .PyCapsule_GetPointer
550
551
cap_ptr_fn .restype = ctypes .c_void_p
@@ -561,11 +562,23 @@ def test_cpython_api(memory_ctor):
561
562
mem_nby_fn_ptr = cap_ptr_fn (
562
563
mem_nby_fn_cap , b"size_t (struct Py_MemoryObject *)"
563
564
)
565
+ mem_make_fn_ptr = cap_ptr_fn (
566
+ mem_make_fn_cap ,
567
+ b"PyObject *(DPCTLSyclUSMRef, size_t, DPCTLSyclQueueRef, PyObject *)" ,
568
+ )
564
569
callable_maker = ctypes .PYFUNCTYPE (ctypes .c_void_p , ctypes .py_object )
565
570
get_ptr_fn = callable_maker (mem_ptr_fn_ptr )
566
571
get_ctx_ref_fn = callable_maker (mem_ctx_ref_fn_ptr )
567
572
get_q_ref_fn = callable_maker (mem_q_ref_fn_ptr )
568
573
get_nby_fn = callable_maker (mem_nby_fn_ptr )
574
+ make_callable_maker = ctypes .PYFUNCTYPE (
575
+ ctypes .py_object ,
576
+ ctypes .c_void_p ,
577
+ ctypes .c_size_t ,
578
+ ctypes .c_void_p ,
579
+ ctypes .py_object ,
580
+ )
581
+ make_fn = make_callable_maker (mem_make_fn_ptr )
569
582
570
583
capi_ptr = get_ptr_fn (mobj )
571
584
direct_ptr = mobj ._pointer
@@ -580,6 +593,15 @@ def test_cpython_api(memory_ctor):
580
593
direct_nbytes = mobj .nbytes
581
594
assert capi_nbytes == direct_nbytes
582
595
596
+ mobj2 = make_fn (
597
+ mobj ._pointer ,
598
+ ctypes .c_size_t (mobj .nbytes ),
599
+ mobj .sycl_queue .addressof_ref (),
600
+ mobj ,
601
+ )
602
+ assert mobj2 ._pointer == mobj ._pointer
603
+ assert mobj2 .reference_obj is mobj
604
+
583
605
584
606
def test_memory_construction_from_other_memory_objects ():
585
607
try :
0 commit comments