-
Notifications
You must be signed in to change notification settings - Fork 0
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
Problem getting a ref to DUT #24
Conversation
Yeah... this was one of those things that made me completely rethink how I'd program in Rust, though, it also made me understand what you were saying about not wanting to deal with memory issues and such. I was pretty annoyed for a while but then realized it genuinely is just Rust doing its job. It'd be easy in C++, but then someone else (or me by mistake) could go in wipe out the data structure by accident and then.. invalid memory accesses! What I ended up in doing in pin collections was passing a reference to the container around to all the functions. Its a bit messy, but it gets us around having to give it a lifetime parameter, and from doing any of that Ref stuff, which I think we might be able to force, but it won't be very friendly. Could do the same: just pass the model itself to each and every function call... That'll be cumbersome though, so I wonder if adding a static structure in I think that'll be closest we can get to backtracking without passing the object itself to every function, or introducing lifetimes. I already tried a custom lifetime, but then found out pyo3 doesn't support them and the only way around that is it make it a static lifetime anyway. |
I just stumbled on some pointer stuff that Rust does allow. Might be able to use this to store pointers to the DUT from the subblocks. Now we're getting back to the C++ world though. |
Hi @coreyeng, OK I played around with it a bit and changed it to make the DUT a (mutable) singleton in Rust rather than being part of the (Python memory owned) PyDUT class. I think this works much better, I actually had something similar originally but I was lead astray by the groupthink on Stackoverflow about globals being bad. It is behind a Mutex to avoid any future issues with multi-threading, so to get a read-only lock on the DUT do: let dut = origen::DUT.lock().unwrap(); and for a mutable version it is just: let mut dut = origen::DUT.lock().unwrap(); The result returned from I've made the tests green and I would propose merging this if you are happy to so that you can use it too. |
Also fixed and removed all the manual error conversion from |
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.
Looks good to me!
Hi @coreyeng,
This isn't ready to merge, but I opened it for discussion with you.
So I started trying to implement
dut.memory_maps
which would return a Python class defined in Rust along the lines of how we have been discussing in #21That all went fine initially and
dut.db.memory_maps("some.path")
returns the object defined from Rust - https://github.com/Origen-SDK/o2/blob/block_loader/rust/origen/pyapi/src/memory_map.rs#L12At the time of executing that function to instantiate the object I have full access to the Rust DUT as planned.
However, I've now hit a roadblock.
My plan was to store a copy of the path to the model with the MemoryMaps struct and then use that to resolve the model any time I needed to get data from it.
However, I very quickly realized when trying to implement
dut.db.memory_maps("some.path").len()
, that when you get down to methods of the MemoryMaps struct itself, you no longer have access to the DUT!!! - https://github.com/Origen-SDK/o2/blob/block_loader/rust/origen/pyapi/src/memory_map.rs#L39I think the only way around this problem is going to be to store some kind of magic reference to either the relevant model or the top-level DUT itself within the MemoryMaps struct (and all others like it).
But damned if I know how...