Skip to content

Commit ac0c557

Browse files
WhatAmISupposedToPutHerejannau
authored andcommitted
Revert "adt: drop adt_next_property_offset()"
This reverts commit bfe4027. Signed-off-by: Sasha Finkelstein <[email protected]>
1 parent 44e8951 commit ac0c557

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

rust/src/adt.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,21 @@ pub unsafe extern "C" fn adt_first_property_offset(_dt: *const c_void, offset: c
655655
unsafe { p.sub(adt as usize) as c_int }
656656
}
657657

658+
// This function has load-bearing UB on the C side... The sound Rust equivalent
659+
// breaks this. Recreate the UB here rather than call the new Rust function.
660+
#[no_mangle]
661+
pub unsafe extern "C" fn adt_next_property_offset(_dt: *const c_void, offset: c_int) -> c_int {
662+
let ptr: usize = unsafe { adt.add(offset as usize) as usize };
663+
let p = ADTProperty::from_ptr(ptr).unwrap();
664+
unsafe {
665+
p.as_ptr()
666+
.add(size_of::<[c_char; 32]>())
667+
.add(size_of::<u32>())
668+
.add((p.size as usize + (ADT_ALIGN - 1)) & !(ADT_ALIGN - 1))
669+
.sub(adt as usize) as c_int
670+
}
671+
}
672+
658673
#[no_mangle]
659674
pub unsafe extern "C" fn adt_first_child_offset(_dt: *const c_void, offset: c_int) -> c_int {
660675
let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode };

src/adt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ int adt_get_property_count(const void *adt, int offset);
3232

3333
int adt_first_property_offset(const void *adt, int offset);
3434

35+
int adt_next_property_offset(const void *adt, int offset);
36+
3537
const struct adt_property *adt_get_property_by_offset(const void *adt, int offset);
3638

3739
int adt_get_child_count(const void *adt, int offset);

0 commit comments

Comments
 (0)