Skip to content

Commit fafee7f

Browse files
committed
Use static_assertions to verify the safety of init_type_hierarchy
1 parent 2a42772 commit fafee7f

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ cfg-if = "0.1.10"
7979
timsort = "0.1"
8080
thiserror = "1.0"
8181
atty = "0.2"
82+
static_assertions = "1.1"
8283

8384
## unicode stuff
8485
unicode_names2 = "0.4"

vm/src/pyobjectrc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ pub(crate) fn init_type_hierarchy() -> (PyTypeRef, PyTypeRef) {
410410
type PyTypeObj = PyObject<PyType>;
411411
type UninitRef<T> = PyRwLock<PyRc<MaybeUninit<PyInner<T>>>>;
412412

413+
// We cast between these 2 types, so make sure (at compile time) that there's no change in
414+
// layout when we wrap PyInner<PyTypeObj> in MaybeUninit<>
415+
static_assertions::assert_eq_size!(MaybeUninit<PyInner<PyTypeObj>>, PyInner<PyTypeObj>);
416+
static_assertions::assert_eq_align!(MaybeUninit<PyInner<PyTypeObj>>, PyInner<PyTypeObj>);
417+
413418
let type_payload = PyType {
414419
name: PyTypeRef::NAME.to_owned(),
415420
base: None,

0 commit comments

Comments
 (0)