diff options
author | 2018-04-03 10:04:47 -0700 | |
---|---|---|
committer | 2018-04-03 10:09:05 -0700 | |
commit | 655b2663e7d2609b0f578b9ef3c1401de22dc5c2 (patch) | |
tree | 61ac9426556a65f99edf99a23fa491d329d70016 /tensorflow/python/platform | |
parent | cfc886ac6064a04c71dd6c52e8c21ebec91eae50 (diff) |
Apply "Raise exception in SWIG on bad TF_Status" to base.i
Minor fixes to make this work.
PiperOrigin-RevId: 191457070
Diffstat (limited to 'tensorflow/python/platform')
-rw-r--r-- | tensorflow/python/platform/base.i | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tensorflow/python/platform/base.i b/tensorflow/python/platform/base.i index dbefca2be9..478dd46f7e 100644 --- a/tensorflow/python/platform/base.i +++ b/tensorflow/python/platform/base.i @@ -229,3 +229,25 @@ _COPY_TYPEMAPS(unsigned int, mode_t); %define final %enddef %define override %enddef #endif + +// Typemaps to automatically raise a Python exception from bad output TF_Status. +// TODO(b/77295559): expand this to all TF_Status* output params and deprecate +// raise_exception_on_not_ok_status (currently it only affects the C API). +%typemap(in, numinputs=0) TF_Status* status (TF_Status* status) { + $1 = TF_NewStatus(); +} + +%typemap(freearg) (TF_Status* status) { + TF_DeleteStatus($1); +} + +%typemap(argout) TF_Status* status { + TF_Code code = TF_GetCode($1); + if (code != TF_OK) { + PyObject* exc = tensorflow::PyExceptionRegistry::Lookup(code); + // Arguments to OpError. + PyObject* exc_args = Py_BuildValue("sss", nullptr, nullptr, TF_Message($1)); + SWIG_SetErrorObj(exc, exc_args); + SWIG_fail; + } +} |