@@ -50,16 +50,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
50
50
. memory ( )
51
51
. read_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
52
52
let path = std:: str:: from_utf8 ( path_bytes)
53
- . map_err ( |_| err_unsup_format ! ( "{:?} is not a valid utf-8 string" , path_bytes) ) ?
54
- . to_owned ( ) ;
55
- let fd = File :: open ( & path) . map ( |file| {
53
+ . map_err ( |_| err_unsup_format ! ( "{:?} is not a valid utf-8 string" , path_bytes) ) ?;
54
+ let fd = File :: open ( path) . map ( |file| {
56
55
let mut fh = & mut this. machine . file_handler ;
57
56
fh. low += 1 ;
58
57
fh. handles . insert ( fh. low , FileHandle { file, flag } ) ;
59
58
fh. low
60
59
} ) ;
61
60
62
- this. consume_result :: < i32 > ( fd, - 1 )
61
+ this. consume_result ( fd)
63
62
}
64
63
65
64
fn fcntl (
@@ -94,7 +93,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
94
93
}
95
94
Ok ( 0 )
96
95
} else if cmd == this. eval_libc_i32 ( "F_GETFD" ) ? {
97
- this. get_handle_and ( fd, |handle| Ok ( handle. flag ) , - 1 )
96
+ this. get_handle_and ( fd, |handle| Ok ( handle. flag ) )
98
97
} else {
99
98
throw_unsup_format ! ( "Unsupported command {:#x}" , cmd) ;
100
99
}
@@ -111,8 +110,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
111
110
112
111
this. remove_handle_and (
113
112
fd,
114
- |handle, this| this. consume_result :: < i32 > ( handle. file . sync_all ( ) . map ( |_| 0 ) , -1 ) ,
115
- -1 ,
113
+ |handle, this| this. consume_result ( handle. file . sync_all ( ) . map ( |_| 0i32 ) ) ,
116
114
)
117
115
}
118
116
@@ -148,13 +146,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
148
146
. map ( |bytes| bytes as i64 ) ;
149
147
// Reinsert the file handle
150
148
this. machine . file_handler . handles . insert ( fd, handle) ;
151
- this. consume_result :: < i64 > ( bytes, - 1 )
149
+ this. consume_result ( bytes)
152
150
} ,
153
- -1 ,
154
151
)
155
152
}
156
153
157
- fn get_handle_and < F , T > ( & mut self , fd : i32 , f : F , t : T ) -> InterpResult < ' tcx , T >
154
+ fn get_handle_and < F , T : From < i32 > > ( & mut self , fd : i32 , f : F ) -> InterpResult < ' tcx , T >
158
155
where
159
156
F : Fn ( & FileHandle ) -> InterpResult < ' tcx , T > ,
160
157
{
@@ -163,11 +160,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
163
160
f ( handle)
164
161
} else {
165
162
this. machine . last_error = this. eval_libc_i32 ( "EBADF" ) ? as u32 ;
166
- Ok ( t )
163
+ Ok ( ( - 1 ) . into ( ) )
167
164
}
168
165
}
169
166
170
- fn remove_handle_and < F , T > ( & mut self , fd : i32 , mut f : F , t : T ) -> InterpResult < ' tcx , T >
167
+ fn remove_handle_and < F , T : From < i32 > > ( & mut self , fd : i32 , mut f : F ) -> InterpResult < ' tcx , T >
171
168
where
172
169
F : FnMut ( FileHandle , & mut MiriEvalContext < ' mir , ' tcx > ) -> InterpResult < ' tcx , T > ,
173
170
{
@@ -176,16 +173,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
176
173
f ( handle, this)
177
174
} else {
178
175
this. machine . last_error = this. eval_libc_i32 ( "EBADF" ) ? as u32 ;
179
- Ok ( t )
176
+ Ok ( ( - 1 ) . into ( ) )
180
177
}
181
178
}
182
179
183
- fn consume_result < T > ( & mut self , result : std:: io:: Result < T > , t : T ) -> InterpResult < ' tcx , T > {
180
+ fn consume_result < T : From < i32 > > ( & mut self , result : std:: io:: Result < T > ) -> InterpResult < ' tcx , T > {
184
181
match result {
185
182
Ok ( ok) => Ok ( ok) ,
186
183
Err ( e) => {
187
184
self . eval_context_mut ( ) . machine . last_error = e. raw_os_error ( ) . unwrap ( ) as u32 ;
188
- Ok ( t )
185
+ Ok ( ( - 1 ) . into ( ) )
189
186
}
190
187
}
191
188
}
0 commit comments