-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix(node): implement libuv APIs needed to support npm:sqlite3
#25893
Conversation
cli/napi/uv.rs
Outdated
} | ||
|
||
#[no_mangle] | ||
unsafe extern "C" fn uv_mutex_lock(lock: *mut uv_mutex_t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these could be written in terms of std::sync::Mutex
and gain safety and platform compat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, though I went with parking_lot::Mutex
instead to avoid having to store the guard with a fake lifetime.
unsafe { | ||
*uv_loop = env_ptr.cast(); | ||
} | ||
0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i worry slightly that by allowing node-api modules to progress beyond calling this function, we may see an increase in reports of symbol resolution crashes that were previously just runtime errors.
- size_of::<uv_async_cb>() | ||
- size_of::<napi_async_work>() | ||
}], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add smth like this just to be sure.
const _: () = assert!(std::mem::size_of::<uv_async_t>() == UV_ASYNC_SIZE)
or maybe a test which compares it to the uv_sys_lite
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #24740.
Implements the
uv_mutex_*
anduv_async_*
APIs.The mutex API is implemented exactly as libuv, a thin wrapper over the OS's native mutex.
The async API is implemented in terms of napi_async_work. As documented in the napi docs, you really shouldn't call
napi_queue_async_work
multiple times (it is documented as undefined behavior). However, our implementation doesn't have any issue with this, so I believe it suits our purpose here.