@@ -899,91 +899,65 @@ cdef int _smv_managed_tensor_allocator(
899899cdef int _smv_managed_tensor_from_py_object_no_sync(
900900 void* py_object,
901901 DLManagedTensorVersioned** out,
902- ) noexcept with gil:
902+ ) except -1 with gil:
903903 cdef DLManagedTensorVersioned* dlm_tensor_ver = NULL
904- cdef object caught = None
905904 if out == NULL:
906- cpython.PyErr_SetString(RuntimeError, b"out cannot be NULL")
907- return -1
905+ raise RuntimeError("out cannot be NULL")
908906 out[0] = NULL
909907 cdef object obj = <object>py_object
910908 if not isinstance(obj, StridedMemoryView):
911- cpython.PyErr_SetString(TypeError, b"py_object must be a StridedMemoryView")
912- return -1
909+ raise TypeError("py_object must be a StridedMemoryView")
913910 try:
914911 dlm_tensor_ver = _smv_allocate_dlm_tensor_versioned()
915912 _smv_fill_managed_tensor_versioned(dlm_tensor_ver, <StridedMemoryView>obj)
916- except Exception as exc:
913+ except BaseException:
914+ # Rollback must also run for KeyboardInterrupt.
917915 _smv_versioned_deleter(dlm_tensor_ver)
918- caught = exc
919- if caught is not None:
920- cpython.PyErr_SetObject(type(caught), caught)
921- return -1
916+ raise
922917 out[0] = dlm_tensor_ver
923918 return 0
924919
925920
926921cdef int _smv_managed_tensor_to_py_object_no_sync(
927922 DLManagedTensorVersioned* tensor,
928923 void** out_py_object,
929- ) noexcept with gil:
930- cdef object capsule
931- cdef object py_view
932- cdef object caught = None
924+ ) except -1 with gil:
933925 if out_py_object == NULL:
934- cpython.PyErr_SetString(RuntimeError, b"out_py_object cannot be NULL")
935- return -1
926+ raise RuntimeError("out_py_object cannot be NULL")
936927 out_py_object[0] = NULL
937928 if tensor == NULL:
938- cpython.PyErr_SetString(RuntimeError, b"tensor cannot be NULL")
939- return -1
940- try:
941- capsule = cpython.PyCapsule_New(
942- <void*>tensor,
943- DLPACK_VERSIONED_TENSOR_UNUSED_NAME,
944- _smv_pycapsule_deleter,
945- )
946- py_view = _smv_from_dlpack_capsule(capsule, capsule)
947- cpython.Py_INCREF(py_view)
948- out_py_object[0] = <void*>py_view
949- except Exception as exc:
950- caught = exc
951- if caught is not None:
952- cpython.PyErr_SetObject(type(caught), caught)
953- return -1
929+ raise RuntimeError("tensor cannot be NULL")
930+ cdef object capsule = cpython.PyCapsule_New(
931+ <void*>tensor,
932+ DLPACK_VERSIONED_TENSOR_UNUSED_NAME,
933+ _smv_pycapsule_deleter,
934+ )
935+ cdef object py_view = _smv_from_dlpack_capsule(capsule, capsule)
936+ cpython.Py_INCREF(py_view)
937+ out_py_object[0] = <void*>py_view
954938 return 0
955939
956940
957941cdef int _smv_dltensor_from_py_object_no_sync(
958942 void* py_object,
959943 DLTensor* out,
960- ) noexcept with gil:
961- cdef object caught = None
944+ ) except -1 with gil:
962945 if out == NULL:
963- cpython.PyErr_SetString(RuntimeError, b"out cannot be NULL")
964- return -1
946+ raise RuntimeError("out cannot be NULL")
965947 cdef object obj = <object>py_object
966948 if not isinstance(obj, StridedMemoryView):
967- cpython.PyErr_SetString(TypeError, b"py_object must be a StridedMemoryView")
968- return -1
969- try:
970- _smv_setup_dltensor_borrowed(out, <StridedMemoryView>obj)
971- except Exception as exc:
972- caught = exc
973- if caught is not None:
974- cpython.PyErr_SetObject(type(caught), caught)
975- return -1
949+ raise TypeError("py_object must be a StridedMemoryView")
950+ _smv_setup_dltensor_borrowed(out, <StridedMemoryView>obj)
976951 return 0
977952
978953
979954cdef int _smv_current_work_stream(
980955 _DLDeviceType device_type,
981956 int32_t device_id,
982957 void** out_current_stream,
983- ) noexcept with gil:
958+ ) except -1 with gil:
984959 if out_current_stream == NULL:
985- cpython.PyErr_SetString(RuntimeError, b"out_current_stream cannot be NULL")
986- return -1
960+ raise RuntimeError("out_current_stream cannot be NULL")
987961 # cuda.core has no global/current stream state today.
988962 out_current_stream[0] = NULL
989963 return 0
0 commit comments