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

struct Clang should not implement Send #26

Open
nagisa opened this issue May 16, 2020 · 1 comment
Open

struct Clang should not implement Send #26

nagisa opened this issue May 16, 2020 · 1 comment

Comments

@nagisa
Copy link

nagisa commented May 16, 2020

Creating an instance of Clang involves calling clang-sys::load() which dynamically loads the clang library for the currently executing thread.

With Clang: Send (which is implemented automatically due to the auto-trait rules) the abstraction leaks when you do something like:

let clang = Clang::new();
std::thread::spawn(|| {
    /* use clang here */
});

When code is written this way, clang attempts to directly access functions from libclang without checking whether the library is loaded and fail at the assert here.

This bug occurred in actual code here https:/twistedfall/opencv-rust/blob/master/build.rs#L99-L116

Ultimately I think using thread-local storage here is really an instance of superfluous complexity and the library would be way better off with plain global shared variable with an atomic and a std::sync::Once or a lazy_static.

@twistedfall
Copy link

Just in case you can now work around that problem in opencv crate with clang-runtime feature.

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

No branches or pull requests

2 participants