Previously CassDataType was just an enum, held inside Arc. User was given a pointer to CassDataType using Arc::as_ptr or Arc::into_ptr. There are however some functions that mutate the data - and they were given the very same pointers.
Current code was most likely sound - but I'm not completely sure, Rust reference is very confusing in this aspect.
It was however very confusing - when a programmer reads or writes a function that that *mut CassDataType it is not obivious that this data lies inside Arc and so has shared ownership.
To make this more explicit this commit puts CassDataType inside UnsafeCell. Now each access needs to use .get_unchecked() and .get_mut_unchecked() methods and an unsafe block / function, so it will be easier to spot aliasing ^ mutability problems in the future.
In the future we can use Arc::get_mut_unchecked() for this purpose, but it's not yet stabilised.
Pre-review checklist
[x] I have split my patch into logically separate commits.
[x] All commit messages clearly explain what they change and why.
[x] PR description sums up the changes and reasons why they should be introduced.
[ ] I have enabled appropriate tests in .github/workflows/build.yml in gtest_filter.
[ ] I have enabled appropriate tests in .github/workflows/cassandra.yml in gtest_filter.
Previously
CassDataType
was just an enum, held insideArc
. User was given a pointer toCassDataType
usingArc::as_ptr
orArc::into_ptr
. There are however some functions that mutate the data - and they were given the very same pointers. Current code was most likely sound - but I'm not completely sure, Rust reference is very confusing in this aspect. It was however very confusing - when a programmer reads or writes a function that that *mut CassDataType it is not obivious that this data lies inside Arc and so has shared ownership.To make this more explicit this commit puts
CassDataType
inside UnsafeCell. Now each access needs to use.get_unchecked()
and.get_mut_unchecked()
methods and an unsafe block / function, so it will be easier to spot aliasing ^ mutability problems in the future.In the future we can use
Arc::get_mut_unchecked()
for this purpose, but it's not yet stabilised.Pre-review checklist
.github/workflows/build.yml
ingtest_filter
..github/workflows/cassandra.yml
ingtest_filter
.