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

fix(node): implement libuv APIs needed to support npm:sqlite3 #25893

Merged
merged 17 commits into from
Oct 2, 2024

Conversation

nathanwhit
Copy link
Member

Fixes #24740.

Implements the uv_mutex_* and uv_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.

cli/napi/uv.rs Outdated
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_lock(lock: *mut uv_mutex_t) {
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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>()
}],
}
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nathanwhit nathanwhit merged commit bbd4ae1 into denoland:main Oct 2, 2024
17 checks passed
@nathanwhit nathanwhit deleted the libuv-polyfill branch October 2, 2024 17:43
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.

Bug: dyld[3532]: missing symbol called in sqlite3
3 participants