Skip to content

Conversation

@cathy-sjh
Copy link
Contributor

@cathy-sjh cathy-sjh commented Aug 14, 2024

1、The following code will make an error, the Box::into_raw(empty struct) will return 0x1

#[napi]
pub struct ZeroStruct;

#[napi]
impl ZeroStruct {
  #[napi(constructor)]
  pub fn new() -> Self {
    ZeroStruct
  }
}

#[napi(catch_unwind)]
pub fn return_zero_struct() -> ZeroStruct {
  ZeroStruct
}

2、The ownership of the CString passed to cffi will be taken in map function. When passed to cffi, the ctring memory has already been released

@cathy-sjh cathy-sjh changed the title The ownership of the CString will be taken in map function The ownership of the CString passed to cffi will be taken in map function Aug 14, 2024
…x1`, and it will be overwritten by the others instance of the same class
@cathy-sjh cathy-sjh changed the title The ownership of the CString passed to cffi will be taken in map function Some Bugfix: 1、empty struct。2、CString ownership Aug 16, 2024
@Brooooooklyn Brooooooklyn changed the title Some Bugfix: 1、empty struct。2、CString ownership fix: ffi lifetime and pointer sound issues Aug 18, 2024
@Brooooooklyn Brooooooklyn changed the title fix: ffi lifetime and pointer sound issues fix(napi,napi-derive): ffi lifetime and pointer sound issues Aug 18, 2024
@Brooooooklyn Brooooooklyn merged commit 09a79ed into napi-rs:main Aug 18, 2024
Brooooooklyn pushed a commit that referenced this pull request Sep 12, 2024
* The ownership of the CString will be taken in map function

* for empty struct like `#[napi] struct A;`, the `value_ref` will be `0x1`, and it will be overwritten by the others instance of the same class
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

Successfully merging this pull request may close these issues.

2 participants