Start addressing some bugs in new Rust code #10
Reference in New Issue
Block a user
Delete Branch "trurl/wmaker:refactor/riir"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The Rust replacements for WMHashTable and WMArray cause segfaults when called into from existing C code. This is largely due to deficiencies on my part. (The WMHashTable rewrite was committed prematurely, and I seem to have misunderstood what the signature of callbacks passed to the WMArray interface should be.) This PR addresses some of these problems.
@@ -226,7 +218,7 @@ pub mod ffi {(*array).items.pop().map(|p| p.as_ptr())Could you use
.cast()here instead ofas(and similarly elsewhere)?I'm not sure I can do this. Is there a
.cast()method for converting between raw pointer and non-raw-pointer types? For example, most of the time this file usesas, it's casting ausizeto some flavor ofvoid*.oh, hmm. No, not really, then. In that case, I'd recommend using the "provenance" based functions, though:
.with_addrand so forth, if that's reasonable: https://doc.rust-lang.org/std/ptr/index.html#strict-provenanceI don't see how I can reasonably use
with_addrto retain provenance when converting values stored in the array fromusizeback to pointers. The problem lies in how this API is used by existing code: the caller may provide arbitrary integers to functions likeWMInsertInArray. When those values are queried by C code, they may be cast back to integers or dereferenced. The knowledge of whether the value is a real address with proper provenance is only in the programmer's head. As you have suggested, I'd have to track something at runtime or split this into two different array types (one forusizes, one for* mut c_voids).I do hope to be rid of
WMArraysooner or later, so for now I think I'll just keep the casts as-is.b39e16d6b2toe0fc92bf51@@ -2,3 +2,3 @@pub struct Array {items: Vec<NonNull<c_void>>,items: Vec<usize>,I had thought at one point that it might be nice to try to make this generic over some type T, and bifurcate usage between
c_voidandusize, but looking at the sheer volume of places this code is used, I think that would be tedious and premature. It's a bummer that we have to do a lot of pointer casting as a result, but ... c'est la vie.On the bright side, ditching
WMArrayandWMHashTablewill be possible soon-ish.