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

missing lifetime specifier in pointer #82

Open
crackcomm opened this issue Nov 10, 2021 · 2 comments
Open

missing lifetime specifier in pointer #82

crackcomm opened this issue Nov 10, 2021 · 2 comments

Comments

@crackcomm
Copy link
Contributor

I stumbled onto a bizarre error raised by the borrow checker if at least one of the function arguments is a reference and return type is ocaml::Pointer.

Example code that raised the error:

struct Keypair(schnorrkel::Keypair);
ocaml::custom!(Keypair);
struct Signature(schnorrkel::Signature);
ocaml::custom!(Signature);

#[ocaml::func]
pub unsafe fn keypair_sign(
    keypair: ocaml::Pointer<Keypair>,
    ctx: &[u8],
    bytes: &[u8],
) -> ocaml::Pointer<Signature> {
    let ctx = schnorrkel::signing_context(ctx);
    let signature = keypair.as_ref().0.sign(ctx.bytes(bytes));
    ocaml::Pointer::alloc_custom(Signature(signature))
}

It's not possible to make keypair_sign<'a> (a hack anyways) since OCaml functions may not contain generics but it is possible to hack using in_band_lifetimes feature:

#![feature(in_band_lifetimes)]

struct Keypair(schnorrkel::Keypair);
ocaml::custom!(Keypair);
struct Signature(schnorrkel::Signature);
ocaml::custom!(Signature);

#[ocaml::func]
pub unsafe fn keypair_sign(
    keypair: ocaml::Pointer<Keypair>,
    ctx: &'a [u8],
    bytes: &[u8],
) -> ocaml::Pointer<'a, Signature> {
    let ctx = schnorrkel::signing_context(ctx);
    let signature = keypair.as_ref().0.sign(ctx.bytes(bytes));
    ocaml::Pointer::alloc_custom(Signature(signature))
}

This error is not raised when arguments are Vec<u8> etc.

@zshipko
Copy link
Owner

zshipko commented Nov 10, 2021

Hm, interesting. I don't have an immediate fix for this but will try to come up with something. Thanks for reporting!

@cdmistman
Copy link

cdmistman commented Dec 6, 2022

feature(in_band_lifetimes) was removed from nightly when rust-lang/rust#93845 landed; this issue can probably be closed ah, but the issue with lifetimes still isn't resolved 🤦

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

3 participants