Skip to content

Commit

Permalink
wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Mar 30, 2024
1 parent 9c70c71 commit e36421f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/byondapi-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "byondapi"
version = "0.4.3"
version = "0.4.4"
authors = ["tigercat2000 <[email protected]>"]
edition = "2021"
description = "Idiomatic Rust bindings for BYONDAPI"
Expand Down
4 changes: 1 addition & 3 deletions crates/byondapi-rs/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ pub fn byond_block(corner1: ByondXYZ, corner2: ByondXYZ) -> Result<Vec<ByondValu
}

BUFFER.with_borrow_mut(|buff| -> Result<Vec<ByondValue>, Error> {
let initial_len = buff.capacity() as u32;
let mut len = buff.capacity() as u32;
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
let initial_res = unsafe {
byond().Byond_Block(&corner1.0, &corner2.0, buff.as_mut_ptr().cast(), &mut len)
};
match (initial_res, len) {
(false, 1..) => {
debug_assert!(len > initial_len);
buff.reserve_exact((len - initial_len) as usize);
buff.reserve_exact(len as usize);
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
unsafe {
map_byond_error!(byond().Byond_Block(
Expand Down
4 changes: 1 addition & 3 deletions crates/byondapi-rs/src/value/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ impl ByondValue {
}

let bytes = BUFFER.with_borrow_mut(|buff| -> Result<Vec<u8>, Error> {
let initial_len = buff.capacity() as u32;
let mut len = buff.capacity() as u32;
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
let initial_res =
unsafe { byond().Byond_ToString(&self.0, buff.as_mut_ptr().cast(), &mut len) };
match (initial_res, len) {
(false, 1..) => {
debug_assert!(len > initial_len);
buff.reserve_exact((len - initial_len) as usize);
buff.reserve_exact(len as usize);
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
unsafe {
map_byond_error!(byond().Byond_ToString(
Expand Down
8 changes: 2 additions & 6 deletions crates/byondapi-rs/src/value/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ impl ByondValue {
}

BUFFER.with_borrow_mut(|buff| -> Result<Vec<ByondValue>, Error> {
let initial_len = buff.capacity() as u32;
let mut len = buff.capacity() as u32;

// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
let initial_res =
unsafe { byond().Byond_ReadList(&self.0, buff.as_mut_ptr().cast(), &mut len) };
match (initial_res, len) {
(false, 1..) => {
debug_assert!(len > initial_len);
buff.reserve_exact((len - initial_len) as usize);
buff.reserve_exact(len as usize);
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
unsafe {
map_byond_error!(byond().Byond_ReadList(
Expand Down Expand Up @@ -58,16 +56,14 @@ impl ByondValue {
}

BUFFER.with_borrow_mut(|buff| -> Result<Vec<ByondValue>, Error> {
let initial_len = buff.capacity() as u32;
let mut len = buff.capacity() as u32;

// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
let initial_res =
unsafe { byond().Byond_ReadListAssoc(&self.0, buff.as_mut_ptr().cast(), &mut len) };
match (initial_res, len) {
(false, 1..) => {
debug_assert!(len > initial_len);
buff.reserve_exact((len - initial_len) as usize);
buff.reserve_exact(len as usize);
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
unsafe {
map_byond_error!(byond().Byond_ReadListAssoc(
Expand Down

0 comments on commit e36421f

Please sign in to comment.