@@ -1384,33 +1384,32 @@ static int DPEXRT_sycl_event_from_python(NRT_api_functions *nrt,
1384
1384
static PyObject * DPEXRT_sycl_event_to_python (NRT_api_functions * nrt ,
1385
1385
eventstruct_t * eventstruct )
1386
1386
{
1387
- PyObject * orig_event = NULL ;
1387
+ PyObject * event_obj = NULL ;
1388
1388
PyGILState_STATE gstate ;
1389
1389
1390
- orig_event = nrt -> get_data (eventstruct -> meminfo );
1391
- // FIXME: Better error checking is needed to enforce the boxing of the event
1392
- // object. For now, only the minimal is done as the returning of SyclEvent
1393
- // from a dpjit function should not be a used often and the dpctl C API for
1394
- // type checking etc. is not ready.
1395
- if (orig_event == NULL ) {
1396
- PyErr_Format (PyExc_ValueError ,
1397
- "In 'box_from_eventstruct_parent', "
1398
- "failed to create a new dpctl.SyclEvent object." );
1399
- return NULL ;
1400
- }
1390
+ event_obj = nrt -> get_data (eventstruct -> meminfo );
1401
1391
1402
1392
DPEXRT_DEBUG (
1403
1393
drt_debug_print ("DPEXRT-DEBUG: In DPEXRT_sycl_event_to_python.\n" ););
1404
1394
1405
- // TODO: is there any way to release meminfo without calling dtor so we dont
1406
- // call incref, decref one after another.
1407
- // We need to increase reference count because we are returning new
1408
- // reference to the same event.
1409
- Py_INCREF (orig_event );
1395
+ if (event_obj == NULL ) {
1396
+ // Make create copy of event_ref so we don't need to manage nrt lifetime
1397
+ // from python object.
1398
+ event_obj = SyclEvent_Make (eventstruct -> event_ref );
1399
+ }
1400
+ else {
1401
+ // Unfortunately we can not optimize (nrt->release that triggers
1402
+ // Py_DECREF() from the destructor) and Py_INCREF() because nrt may need
1403
+ // the object even if we return it to python.
1404
+ // We need to increase reference count because we are returning new
1405
+ // reference to the same event.
1406
+ Py_INCREF (event_obj );
1407
+ }
1408
+
1410
1409
// We need to release meminfo since we are taking ownership back.
1411
1410
nrt -> release (eventstruct -> meminfo );
1412
1411
1413
- return orig_event ;
1412
+ return event_obj ;
1414
1413
}
1415
1414
1416
1415
/*----------------------------------------------------------------------------*/
0 commit comments