rust-mobile / rust-mobile/ndk

Add static bound for add_fd_with_callback

Open
#504 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.3k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

Since the callback is leaking into memory, should we add a 'static constraint to it to make sure it's always valid, otherwise a JNIEnv <'local> is captured here, and it compiles. But the JNIEnv is only valid in the scope of the native method on_create

//native jni method
pub fn on_create(mut env: JNIEnv, jactivity: JObject) {
    ThreadLooper::for_thread()
        .unwrap()
        .add_fd_with_callback(fd, FdEvent::INPUT, move || {
            env.call_method(obj, name, sig, args);
        })?;
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search for add_fd_with_callback and inspect how its callback is stored and invoked. Confirm the shown on_create example cannot capture the scoped JNIEnv, then add coverage that verifies the callback requires a 'static lifetime and run the relevant Rust tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
mobile-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.