Skip to content

Commit 96d7c9a

Browse files
bartlomiejuclaude
andcommitted
fix: address CI failures in crdtp bindings
- Add unsafe blocks inside unsafe fn from_raw (Rust 2024 edition requirement) - Make into_raw methods pub(crate) to avoid private-interfaces warnings - Make UberDispatcher::channel private (only used internally) - Remove unused crdtp__FrontendChannel__BASE__SIZE and crdtp__vec_u8__data - Remove size assertion that depended on deleted SIZE function Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 64c6ff9 commit 96d7c9a

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/crdtp.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ unsafe extern "C" {
1111
fn crdtp__FrontendChannel__BASE__CONSTRUCT(
1212
buf: *mut MaybeUninit<RawFrontendChannel>,
1313
);
14-
fn crdtp__FrontendChannel__BASE__SIZE() -> usize;
1514

1615
fn crdtp__Serializable__DELETE(this: *mut RawSerializable);
1716
fn crdtp__Serializable__AppendSerialized(
@@ -98,7 +97,6 @@ unsafe extern "C" {
9897
fn crdtp__vec_u8__new() -> *mut CppVecU8;
9998
fn crdtp__vec_u8__DELETE(this: *mut CppVecU8);
10099
fn crdtp__vec_u8__size(this: *const CppVecU8) -> usize;
101-
fn crdtp__vec_u8__data(this: *const CppVecU8) -> *const u8;
102100
fn crdtp__vec_u8__copy(this: *const CppVecU8, out: *mut u8);
103101

104102
fn crdtp__json__ConvertJSONToCBOR(
@@ -184,7 +182,7 @@ impl Serializable {
184182
}
185183
}
186184

187-
pub fn into_raw(self) -> *mut RawSerializable {
185+
pub(crate) fn into_raw(self) -> *mut RawSerializable {
188186
let ptr = self.ptr;
189187
std::mem::forget(self);
190188
ptr
@@ -363,7 +361,7 @@ impl DispatchResponse {
363361
}
364362
}
365363

366-
pub fn into_raw(self) -> *mut DispatchResponseWrapper {
364+
pub(crate) fn into_raw(self) -> *mut DispatchResponseWrapper {
367365
let ptr = self.ptr;
368366
std::mem::forget(self);
369367
ptr
@@ -404,11 +402,6 @@ pub struct FrontendChannel {
404402
impl FrontendChannel {
405403
/// Create a new FrontendChannel wrapping the given implementation.
406404
pub fn new(imp: Box<dyn FrontendChannelImpl>) -> Pin<Box<Self>> {
407-
// Ensure our RawFrontendChannel is large enough for the C++ object.
408-
assert!(
409-
std::mem::size_of::<RawFrontendChannel>()
410-
>= unsafe { crdtp__FrontendChannel__BASE__SIZE() }
411-
);
412405
let mut channel = Box::new(Self {
413406
raw: UnsafeCell::new(unsafe { MaybeUninit::zeroed().assume_init() }),
414407
imp,
@@ -426,10 +419,12 @@ impl FrontendChannel {
426419
}
427420

428421
unsafe fn from_raw<'a>(ptr: *mut RawFrontendChannel) -> &'a mut Self {
429-
let channel_ptr = ptr as *mut u8;
430-
let offset = std::mem::offset_of!(FrontendChannel, raw);
431-
let self_ptr = channel_ptr.sub(offset) as *mut Self;
432-
&mut *self_ptr
422+
unsafe {
423+
let channel_ptr = ptr as *mut u8;
424+
let offset = std::mem::offset_of!(FrontendChannel, raw);
425+
let self_ptr = channel_ptr.sub(offset) as *mut Self;
426+
&mut *self_ptr
427+
}
433428
}
434429
}
435430

@@ -522,8 +517,8 @@ impl UberDispatcher {
522517
}
523518
}
524519

525-
/// Get the frontend channel.
526-
pub fn channel(&mut self) -> *mut RawFrontendChannel {
520+
/// Get the frontend channel (internal use only).
521+
fn channel(&mut self) -> *mut RawFrontendChannel {
527522
unsafe { crdtp__UberDispatcher__channel(self) }
528523
}
529524

src/crdtp_binding.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ void crdtp__FrontendChannel__BASE__CONSTRUCT(
5050
construct_in_place<crdtp__FrontendChannel__BASE>(buf);
5151
}
5252

53-
size_t crdtp__FrontendChannel__BASE__SIZE() {
54-
return sizeof(crdtp__FrontendChannel__BASE);
55-
}
56-
5753
void crdtp__Serializable__DELETE(Serializable* self) { delete self; }
5854

5955
// Serialize once into a caller-provided CppVecU8 to avoid double-serialization.
@@ -246,10 +242,6 @@ size_t crdtp__vec_u8__size(const std::vector<uint8_t>* self) {
246242
return self->size();
247243
}
248244

249-
const uint8_t* crdtp__vec_u8__data(const std::vector<uint8_t>* self) {
250-
return self->data();
251-
}
252-
253245
void crdtp__vec_u8__copy(const std::vector<uint8_t>* self, uint8_t* out) {
254246
memcpy(out, self->data(), self->size());
255247
}

0 commit comments

Comments
 (0)