File tree Expand file tree Collapse file tree 1 file changed +6
-11
lines changed
Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change 88//! [libyaml]: https://pyyaml.org/wiki/LibYAML
99
1010use std:: error:: Error ;
11- use std:: ffi:: { CStr , c_char, c_void} ;
11+ use std:: ffi:: { c_char, c_void, CStr } ;
1212use std:: fmt:: Display ;
1313use std:: io:: { self , Read } ;
1414use std:: mem:: MaybeUninit ;
@@ -44,21 +44,16 @@ where
4444 R : Read ,
4545{
4646 pub ( super ) fn new ( reader : R ) -> Parser < R > {
47- let mut parser: Box < yaml_parser_t > ;
48-
4947 // SAFETY: This comes from libyaml, which we assume is implemented
5048 // correctly. We expect initialization functions to properly handle
5149 // uninitialized memory; empirical tests in Miri show this to be true.
52- unsafe {
53- // TODO: Use Box::new_uninit and Box::assume_init if our MSRV hits
54- // or exceeds 1.82.
55- let mut uninit = Box :: new ( MaybeUninit :: < yaml_parser_t > :: uninit ( ) ) ;
56- if yaml_parser_initialize ( uninit. as_mut_ptr ( ) ) . ok {
57- parser = Box :: from_raw ( Box :: into_raw ( uninit) . cast ( ) ) ;
58- } else {
50+ let mut parser = unsafe {
51+ let mut uninit = Box :: new_uninit ( ) ;
52+ if yaml_parser_initialize ( uninit. as_mut_ptr ( ) ) . fail {
5953 panic ! ( "out of memory for yaml_parser_initialize" ) ;
6054 }
61- }
55+ uninit. assume_init ( )
56+ } ;
6257
6358 // libyaml needs a raw ReadState<R> pointer for Self::read_handler.
6459 // Since mutable access through a Box invalidates derived pointers,
You can’t perform that action at this time.
0 commit comments