]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Be explicit with take_ptr calls
authorMatt Corallo <git@bluematt.me>
Wed, 25 Nov 2020 18:25:18 +0000 (13:25 -0500)
committerMatt Corallo <git@bluematt.me>
Tue, 2 Feb 2021 22:04:31 +0000 (17:04 -0500)
If you try to call take_ptr on a pointer to an object which
implements Deref, rustc hits the deref recursion limit.

To avoid this, we can explicitly tell rustc that we want to treat
the pointer as a pointer and call take_ptr on it directly.

c-bindings-gen/src/types.rs

index 4e84f1430648bbc6e44f9b1cc33d56b2cf1c3bad..b5bd87e1abf83ad3bf74aff57fe93eca542c6fc4 100644 (file)
@@ -798,8 +798,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                match full_path {
                        "Result" if !is_ref => {
                                Some(("match ",
-                                               vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw({}.contents.result.take_ptr()) }})", var_name)),
-                                                    ("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw({}.contents.err.take_ptr()) }})", var_name))],
+                                               vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.result)) }})", var_name)),
+                                                    ("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.err)) }})", var_name))],
                                                ")}"))
                        },
                        "Vec"|"Slice" if !is_ref => {