Skip to content

treewide: change *const to *mut based on cassandra.h #225

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

Merged
merged 4 commits into from
Mar 11, 2025

Conversation

muzarski
Copy link
Contributor

@muzarski muzarski commented Mar 11, 2025

There are some types that are shared (Arc), but are mutable from cpp-driver perspective.

For some reason, there were some discrepancies between C API (defined in cassandra.h) and rust binding functions. On C side, the pointer would be T* (non-const), while on Rust side it would be *const T. This PR fixes those discrepancies, so we are consistent with cassandra.h

While going over these types, I found out that for example CassResult unnecessarily implements ArcFFI. I'll address it in a separate PR (because there are other things to adjust as well). Nvm, I just didn't notice that CassResult is cloned in cass_future_get_result - this is because we use .clone() here and not Arc::clone(). I'll change it then, so it's easier to spot in the future.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • [ ] I have implemented Rust unit tests for the features/changes 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.

@muzarski muzarski requested review from Lorak-mmk and wprzytula March 11, 2025 11:19
@muzarski muzarski self-assigned this Mar 11, 2025
@muzarski muzarski added this to the 0.4 milestone Mar 11, 2025
@muzarski
Copy link
Contributor Author

I see that there are other types with this issue. I'll address them as well.

There was some reasoning in the comment to `cass_data_type_new`
why the type was changed to *const. I think it is misleading to change the return type.
Thus, I'm changing it back to *mut (and in other places, so we are consistent with cassandra.h).
@muzarski muzarski requested review from wprzytula and Lorak-mmk and removed request for wprzytula March 11, 2025 12:18
@muzarski muzarski changed the title cass_types: change *const to *mut based on cassandra.h treewide: change *const to *mut based on cassandra.h Mar 11, 2025
Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no harm in this change.

I don't know in general what pointer types should we used.
There are 2 competing semantics, Rust one (mut = exclusive, const = shared) and C++ one (mut = logically mutable, const = logically immutable). Afaik *const and *mut are not strictly bound to any of them.
IIUC, this PR aligns them with C++ semantics, right?

@muzarski
Copy link
Contributor Author

IIUC, this PR aligns them with C++ semantics, right?

Correct. Take for example some type T, that is shared but can be mutated. In rust, we would represent it as e.g. Arc<Mutex<T>> or Arc<UnsafeCell<T>>. From C perspective (and cpp-driver API), this is just a * (not const *), because we can mutate it.

@muzarski muzarski merged commit 8c859b0 into scylladb:master Mar 11, 2025
11 checks passed
@muzarski muzarski deleted the cassdatatype-mut branch March 11, 2025 18:35
@muzarski muzarski mentioned this pull request Apr 14, 2025
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

Successfully merging this pull request may close these issues.

3 participants