Skip to content

Commit

Permalink
Merge pull request #18307 from voutilad/sr-sys-unsafe
Browse files Browse the repository at this point in the history
Wrap certain `wasm32-wasi` ABI unsafe calls in `unsafe` to fix the build.
  • Loading branch information
michael-redpanda committed May 14, 2024
2 parents 49980ec + 6f0a9ba commit 31705d2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
55 changes: 32 additions & 23 deletions src/transform-sdk/rust/sr-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ pub struct AbiSchemaRegistryClient {}

impl AbiSchemaRegistryClient {
pub fn new() -> AbiSchemaRegistryClient {
abi::check();
unsafe {
abi::check();
}
Self {}
}
}

impl SchemaRegistryClientImpl for AbiSchemaRegistryClient {
fn lookup_schema_by_id(&self, id: SchemaId) -> Result<Schema> {
let mut length: i32 = 0;
let errno = abi::get_schema_definition_len(id.0, &mut length);
let errno = unsafe { abi::get_schema_definition_len(id.0, &mut length) };
if errno != 0 {
return Err(SchemaRegistryError::Unknown(errno));
}
let mut buf = vec![0; length as usize];
let errno_or_amt = get_schema_definition(id.0, buf.as_mut_ptr(), buf.len() as i32);
let errno_or_amt =
unsafe { get_schema_definition(id.0, buf.as_mut_ptr(), buf.len() as i32) };
if errno_or_amt < 0 {
return Err(SchemaRegistryError::Unknown(errno_or_amt));
}
Expand All @@ -61,23 +64,27 @@ impl SchemaRegistryClientImpl for AbiSchemaRegistryClient {
version: SchemaVersion,
) -> Result<SubjectSchema> {
let mut length: i32 = 0;
let errno = abi::get_schema_subject_len(
subject.as_ptr(),
subject.len() as i32,
version.0,
&mut length,
);
let errno = unsafe {
abi::get_schema_subject_len(
subject.as_ptr(),
subject.len() as i32,
version.0,
&mut length,
)
};
if errno != 0 {
return Err(SchemaRegistryError::Unknown(errno));
}
let mut buf = vec![0; length as usize];
let errno_or_amt = get_schema_subject(
subject.as_ptr(),
subject.len() as i32,
version.0,
buf.as_mut_ptr(),
buf.len() as i32,
);
let errno_or_amt = unsafe {
get_schema_subject(
subject.as_ptr(),
subject.len() as i32,
version.0,
buf.as_mut_ptr(),
buf.len() as i32,
)
};
if errno_or_amt < 0 {
return Err(SchemaRegistryError::Unknown(errno_or_amt));
}
Expand All @@ -96,13 +103,15 @@ impl SchemaRegistryClientImpl for AbiSchemaRegistryClient {
// version here (take it as a parameter to this method), we should bump the ABI and
// expose that method.
let schema_version: i32 = 0;
let errno = abi::create_subject_schema(
subject.as_ptr(),
subject.len() as i32,
buf.as_ptr(),
buf.len() as i32,
&mut schema_id,
);
let errno = unsafe {
abi::create_subject_schema(
subject.as_ptr(),
subject.len() as i32,
buf.as_ptr(),
buf.len() as i32,
&mut schema_id,
)
};
if errno != 0 {
return Err(SchemaRegistryError::Unknown(errno));
}
Expand Down
12 changes: 6 additions & 6 deletions src/transform-sdk/rust/sr-sys/src/stub_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub(crate) fn check() {
pub(crate) unsafe fn check() {
panic!();
}

pub(crate) fn get_schema_definition_len(_schema_id: i32, _len: *mut i32) -> i32 {
pub(crate) unsafe fn get_schema_definition_len(_schema_id: i32, _len: *mut i32) -> i32 {
panic!();
}

pub(crate) fn get_schema_definition(_schema_id: i32, _buf: *mut u8, _len: i32) -> i32 {
pub(crate) unsafe fn get_schema_definition(_schema_id: i32, _buf: *mut u8, _len: i32) -> i32 {
panic!();
}

pub(crate) fn get_schema_subject_len(
pub(crate) unsafe fn get_schema_subject_len(
_subject: *const u8,
_subject_len: i32,
_version: i32,
Expand All @@ -33,7 +33,7 @@ pub(crate) fn get_schema_subject_len(
panic!();
}

pub(crate) fn get_schema_subject(
pub(crate) unsafe fn get_schema_subject(
_subject: *const u8,
_subject_len: i32,
_version: i32,
Expand All @@ -43,7 +43,7 @@ pub(crate) fn get_schema_subject(
panic!();
}

pub(crate) fn create_subject_schema(
pub(crate) unsafe fn create_subject_schema(
_subject: *const u8,
_subject_len: i32,
_buf: *const u8,
Expand Down

0 comments on commit 31705d2

Please sign in to comment.