Skip to content

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

@beeb

Description

@beeb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions