@@ -1287,29 +1287,28 @@ static int DPEXRT_sycl_queue_from_python(NRT_api_functions *nrt,
1287
1287
static PyObject * DPEXRT_sycl_queue_to_python (NRT_api_functions * nrt ,
1288
1288
queuestruct_t * queuestruct )
1289
1289
{
1290
- PyObject * orig_queue = NULL ;
1291
-
1292
- orig_queue = nrt -> get_data (queuestruct -> meminfo );
1293
- // FIXME: Better error checking is needed to enforce the boxing of the queue
1294
- // object. For now, only the minimal is done as the returning of SyclQueue
1295
- // from a dpjit function should not be a used often and the dpctl C API for
1296
- // type checking etc. is not ready.
1297
- if (orig_queue == NULL ) {
1298
- PyErr_Format (PyExc_ValueError ,
1299
- "In 'box_from_queuestruct_parent', "
1300
- "failed to create a new dpctl.SyclQueue object." );
1301
- return NULL ;
1290
+ PyObject * queue_obj = NULL ;
1291
+
1292
+ queue_obj = nrt -> get_data (queuestruct -> meminfo );
1293
+
1294
+ if (queue_obj == NULL ) {
1295
+ // Make create copy of queue_ref so we don't need to manage nrt lifetime
1296
+ // from python object.
1297
+ queue_obj = SyclQueue_Make (queuestruct -> queue_ref );
1298
+ }
1299
+ else {
1300
+ // Unfortunately we can not optimize (nrt->release that triggers
1301
+ // Py_DECREF() from the destructor) and Py_INCREF() because nrt may need
1302
+ // the object even if we return it to python.
1303
+ // We need to increase reference count because we are returning new
1304
+ // reference to the same queue.
1305
+ Py_INCREF (queue_obj );
1302
1306
}
1303
1307
1304
- // TODO: is there any way to release meminfo without calling dtor so we dont
1305
- // call incref, decref one after another.
1306
- // We need to increase reference count because we are returning new
1307
- // reference to the same queue.
1308
- Py_INCREF (orig_queue );
1309
1308
// We need to release meminfo since we are taking ownership back.
1310
1309
nrt -> release (queuestruct -> meminfo );
1311
1310
1312
- return orig_queue ;
1311
+ return queue_obj ;
1313
1312
}
1314
1313
1315
1314
/*----------------------------------------------------------------------------*/
0 commit comments