-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Port bg builtin to Rust #9621
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
Port bg builtin to Rust #9621
Conversation
I think you need to alias the type in an extern C++ section back to the underlying rust type to be able to use it interchangeably. |
I've tried to put the following above the
But that results in the following error:
In that trait's documentation example (https://docs.rs/cxx/latest/cxx/trait.ExternType.html) it seems like both Types must be |
I think we need an explicit impl of ExternType for all types that we reuse across bridges
see also https://github.com/dtolnay/cxx/pull/465/files and dtolnay/cxx#942 (comment) |
Oh, thank you very much! Somehow I missed this cxx issue 😞 |
This still doesn't seem to work for me. I've committed what I have tried so far. What am I missing? |
So the scenario is: JobGroup is a Rust object that lives in a C++ struct. We try to access it from Rust. Maybe we can expose a raw pointer and cast that to a JobGroup (assuming the object is never moved or lives in shared_ptr or something) Another, secondary problem is that |
0d76954
to
b3869cf
Compare
b3869cf
to
9e4ebd4
Compare
I've now fixed this with a |
/// Mark whether we are in the foreground.
pub fn set_is_foreground(&self, in_foreground: bool) {
self.is_foreground.store(in_foreground, Ordering::Relaxed);
} How is this legal? Should be |
@krobelus it's a concept known as interior mutability. The Interior mutability means making a method mutate the internal state in a way that's compatible with multiple instances of pointers/references to I intentionally used internal mutability here to allow rw access to the JobGroup when multiple threads or objects hold live references to it at the same time. It's also why @clemenswasser is able to use the shared_ptr to mutate the JobGroup without needing to get a separate mutable reference. |
@clemenswasser I think the reason your attempt at using the The only other option would be transmute from the dumb autocxx |
Description
I had to replace some
job_t
references to indices to avoid ownership/aliasing issues with the mutable reference toparser_t
(e. g.send_to_bg
). I also had to introduce someconst
"hacks" ascxx::SharedPtr
doesn't currently allow for mutable access dtolnay/cxx#885 (I'm not really happy with this myself, so if anyone has some safer and moreconst
correct alternatives would be great).I could observe the following correct behavior of the ported version:
@mqudsi while rebasing your #9608 seems to have broken my PR.
Do you know how I can call the
set_is_foreground
on the Rust opaque type returned by C++?Fixes issue #
TODOs: