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

Generation Err with param type std::sync::MutexGuard<> #2094

Closed
dbsxdbsx opened this issue Jun 16, 2024 · 3 comments
Closed

Generation Err with param type std::sync::MutexGuard<> #2094

dbsxdbsx opened this issue Jun 16, 2024 · 3 comments

Comments

@dbsxdbsx
Copy link
Contributor

dbsxdbsx commented Jun 16, 2024

Issue

When transferring an old project from FRB V1 to FRB V2, I accidentally found that param type std::sync::MutexGuard<> is not supported. For example:

// my real example
pub(crate) fn get_unside_piece_by_pos(
    board_array: &std::sync::MutexGuard<[u8; 256]>,
    board_pos: u8,
) -> PieceType {
...
}
// the same issued example
pub fn test_mutex_guard(board_array: &std::sync::MutexGuard<u8>) {
    println!("{}", board_array);
}

The generation is finished with no error, but the output frb_generated.rs has the below error:
image
along with 2 errors within frb_generated.io.rs related to code:

#[no_mangle]
pub extern "C" fn frbgen_meng_ru_ling_shi_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerstdsyncMutexGuardu8(
    ptr: *const std::ffi::c_void,
) {
    MoiArc::<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<std :: sync :: MutexGuard < u8 >>>::increment_strong_count(ptr as _);
}

#[no_mangle]
pub extern "C" fn frbgen_meng_ru_ling_shi_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerstdsyncMutexGuardu8(
    ptr: *const std::ffi::c_void,
) {
    MoiArc::<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<std :: sync :: MutexGuard < u8 >>>::decrement_strong_count(ptr as _);
}

Should be supported?

Here, I said I found it accidentally, which means that the fn get_unside_piece_by_pos is not planned to be exposed. It is used in another module. And it is used in an exposed API like this:

pub(crate) static BOARD_ARRAY: Lazy<Mutex<[u8; 256]>> = Lazy::new(|| Mutex::new([0; 256]));
...

pub fn is_legal_move(src_row: u8, src_col: u8, dst_row: u8, dst_col: u8) -> bool {
    let src_pos = crate::chess::get_board_pos_from_row_col(src_row, src_col);
    let dst_pos = crate::chess::get_board_pos_from_row_col(dst_row, dst_col);

    // get src piece|
    let board_array = BOARD_ARRAY.lock().unwrap();
    let unside_src_piece = crate::chess::get_unside_piece_by_pos(&board_array, src_pos);   // here it used !

    ...
}

So practically, I can ignore it.

But now I wonder whether the type std::sync::MutexGuard<...> is useful for an API fn in some (corner) cases?
If this kind of type is really useful, then hopefully, it could be supported in the future.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jun 16, 2024

Looks like the guard has some lifetime, thus it may not be supported until #2093.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jun 16, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Jun 16, 2024

Lifetime is supported in new version

@fzyzcjy fzyzcjy closed this as completed Jun 16, 2024
@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jun 16, 2024
Copy link
Contributor

github-actions bot commented Jul 1, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants