Skip to content
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

Wrap certain wasm32-wasi ABI unsafe calls in unsafe to fix the build. #18307

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading