File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,13 @@ impl Status {
417
417
Ok ( status)
418
418
}
419
419
420
+ /// Creates a status and sets its code and message.
421
+ pub fn new_set_lossy ( code : Code , msg : & str ) -> Status {
422
+ let mut status = Status :: new ( ) ;
423
+ status. set_lossy ( code, msg) ;
424
+ status
425
+ }
426
+
420
427
/// Returns the status's code.
421
428
pub fn code ( & self ) -> Code {
422
429
unsafe { Code :: from_int ( tf:: TF_GetCode ( self . inner ) as u32 ) }
@@ -445,6 +452,26 @@ impl Status {
445
452
Ok ( ( ) )
446
453
}
447
454
455
+ /// Sets the code and message.
456
+ pub fn set_lossy ( & mut self , code : Code , msg : & str ) {
457
+ let message = match CString :: new ( msg) {
458
+ Ok ( x) => x,
459
+ Err ( e) => {
460
+ let pos = e. nul_position ( ) ;
461
+ let mut truncated_bytes = e. into_vec ( ) ;
462
+ truncated_bytes. truncate ( pos) ;
463
+ let mut new_msg: Vec < u8 > = "(original error truncated due to internal nul byte) "
464
+ . as_bytes ( )
465
+ . into ( ) ;
466
+ new_msg. extend ( & truncated_bytes) ;
467
+ unsafe { CString :: from_vec_unchecked ( new_msg) }
468
+ }
469
+ } ;
470
+ unsafe {
471
+ tf:: TF_SetStatus ( self . inner , code. to_c ( ) , message. as_ptr ( ) ) ;
472
+ }
473
+ }
474
+
448
475
/// Returns a mutable pointer to the inner tensorflow Status `TF_Status`.
449
476
fn inner ( & mut self ) -> * mut tf:: TF_Status {
450
477
self . inner
You can’t perform that action at this time.
0 commit comments