Add TF_SetStatusFromIOError to the C API.
This is needed so that plugins can set Status (TF_Status) from an error code without needing to directly call tensorflow::IOError. We don't want to call tensorflow::IOError from plugins because that would enlarge the space that we have to watch out for ABI compatibility. Part of work for modular filesystem plugins. For more details, consult the RFC at https://github.com/tensorflow/community/blob/master/rfcs/20190506-filesystem-plugin-modular-tensorflow.md PiperOrigin-RevId: 278921539 Change-Id: I8ac3e3a0d8147f901aefa1e301d774fff6055a99
This commit is contained in:
parent
786d2e112e
commit
7ba9011750
@ -17,7 +17,9 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/c/tf_status_internal.h"
|
||||
#include "tensorflow/core/lib/core/status.h"
|
||||
#include "tensorflow/core/platform/error.h"
|
||||
|
||||
using ::tensorflow::IOError;
|
||||
using ::tensorflow::Status;
|
||||
using ::tensorflow::error::Code;
|
||||
|
||||
@ -33,6 +35,12 @@ void TF_SetStatus(TF_Status* s, TF_Code code, const char* msg) {
|
||||
s->status = Status(static_cast<Code>(code), tensorflow::StringPiece(msg));
|
||||
}
|
||||
|
||||
void TF_SetStatusFromIOError(TF_Status* s, int error_code,
|
||||
const char* context) {
|
||||
// TODO(mihaimaruseac): Handle windows when changing its filesystem
|
||||
s->status = IOError(context, error_code);
|
||||
}
|
||||
|
||||
TF_Code TF_GetCode(const TF_Status* s) {
|
||||
return static_cast<TF_Code>(s->status.code());
|
||||
}
|
||||
|
@ -72,6 +72,12 @@ TF_CAPI_EXPORT extern void TF_DeleteStatus(TF_Status*);
|
||||
TF_CAPI_EXPORT extern void TF_SetStatus(TF_Status* s, TF_Code code,
|
||||
const char* msg);
|
||||
|
||||
// Convert from an I/O error code (e.g., errno) to a TF_Status value.
|
||||
// Any previous information is lost. Prefer to use this instead of TF_SetStatus
|
||||
// when the error comes from I/O operations.
|
||||
TF_CAPI_EXPORT extern void TF_SetStatusFromIOError(TF_Status* s, int error_code,
|
||||
const char* context);
|
||||
|
||||
// Return the code record in *s.
|
||||
TF_CAPI_EXPORT extern TF_Code TF_GetCode(const TF_Status* s);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user