Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command got signal SEGV. #118

Open
mimoo opened this issue Mar 7, 2023 · 6 comments
Open

Command got signal SEGV. #118

mimoo opened this issue Mar 7, 2023 · 6 comments

Comments

@mimoo
Copy link
Contributor

mimoo commented Mar 7, 2023

I'm getting the error in the title at the moment, and I see that I'm the first one talking about that in the issues :D hopefully I'll find some solution that will help the next guy.

@mimoo
Copy link
Contributor Author

mimoo commented Mar 7, 2023

I'm wondering if it could be that I implement FromValue on references on my custom types:

        unsafe impl<'a> ocaml::FromValue<'a> for &$name {
            fn from_value(value: ocaml::Value) -> Self {
                let x: ocaml::Pointer<Self> = ocaml::FromValue::from_value(value);
                x.as_ref()
            }
        }

or if in the last stable version I still need to implement a finalizer to call drop (I was under the impression that we didn't have to do these anymore as it was the default, but maybe that's only in the beta since the tests use a finalizer on this repo at the tag of the latest stable)

@mimoo
Copy link
Contributor Author

mimoo commented Mar 7, 2023

OK so I isolated the exported Rust function that was crashing (using lldb), and I changed the parameter from &MyOpaqueType to ocaml::Pointer<MyOpaqueType> and it works. I guess I need to implement FromValue on T and not &T

@mimoo
Copy link
Contributor Author

mimoo commented Mar 7, 2023

it's kind of weird because to book actually works with references: https://zshipko.github.io/ocaml-rs/02_type_conversion.html (and it doesn't even have to implement FromValue, I'm guessing the last beta version implements it for you with custom!?)

@mimoo
Copy link
Contributor Author

mimoo commented Mar 7, 2023

the examples in the tests seem to only use ocaml::Pointer<_> as arguments of functions as well

@zshipko
Copy link
Owner

zshipko commented Mar 7, 2023

Yeah, in the latest version FromValue is implemented for &T and &mut T where T: Custom:

unsafe impl<T: Custom> FromValue for &T {

They use Pointer to do the conversion.

@mimoo
Copy link
Contributor Author

mimoo commented Mar 7, 2023

do you know why I was getting this errors with that implementation?

unsafe impl<'a> ocaml::FromValue<'a> for &$name {
            fn from_value(value: ocaml::Value) -> Self {
                let x: ocaml::Pointer<Self> = ocaml::FromValue::from_value(value);
                x.as_ref()
            }
        }

in any case now things work by using ocaml::Pointer<_> everywhere, but I would have expected that to work : o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants