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

Cargo clippy reports modules using the map handler with params as being unsafe #19

Open
beeb opened this issue Aug 13, 2023 · 1 comment

Comments

@beeb
Copy link

beeb commented Aug 13, 2023

When using params as the first argument to a map module, clippy will report:

error: this public function might dereference a raw pointer but is not marked `unsafe`
#[substreams::handlers::map]
pub fn map_pools_created(params: String, block: Block) -> Result<Pools, Error> {
     // ...
}

This doesn't prevent code compilation but is definitely quite annoying. Adding the unsafe keyword to my module function definition doesn't solve the problem, because (I suspect) the underlying macro produces output that doesn't have the unsafe keyword.

I see the following when I expand the map proc macro:

#[no_mangle]
pub extern "C" fn map_pools_created(
    params_ptr: *mut u8,
    params_len: usize,
    block_ptr: *mut u8,
    block_len: usize,
) {
    substreams::register_panic_hook();
    let func = || -> Result<Pools, Error> {
        let params: String = std::mem::ManuallyDrop::new(unsafe {
            String::from_raw_parts(params_ptr, params_len, params_len)
        })
        .to_string();
    // ...
}

which indeed contains some unsafe code.

@beeb beeb changed the title Cargo clippy reports modules using the map handler as being unsafe Cargo clippy reports modules using the map handler with params as being unsafe Aug 13, 2023
@maoueh
Copy link
Contributor

maoueh commented Nov 10, 2023

Is there a way that in the macro we disable clippy for this line?

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