Skip to content

Commit ac2f4e3

Browse files
committed
fix: use c_char instead of i8 when handling C strings
1 parent 8aea37c commit ac2f4e3

File tree

11 files changed

+28
-16
lines changed

11 files changed

+28
-16
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
# image: ubuntu:20.10
1414
strategy:
1515
matrix:
16-
os: [ubuntu-24.04, macos-latest]
16+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-latest]
1717
rust:
1818
- stable
1919
steps:
@@ -32,7 +32,7 @@ jobs:
3232
- uses: Swatinem/[email protected]
3333
- uses: taiki-e/install-action@cargo-hack
3434
- run: sudo apt-get update -y
35-
if: matrix.os == 'ubuntu-24.04'
35+
if: (matrix.os == 'ubuntu-24.04') || (matrix.os == 'ubuntu-24.04-arm')
3636
- name: update toolchain
3737
run: rustup toolchain install
3838
- name: cargo check (powerset)

src/metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,14 @@ pub use crate::sys::MetadataError;
239239
#[cfg(test)]
240240
mod tests {
241241
use super::*;
242+
use std::ffi::c_char;
242243

243244
#[test]
244245
fn test_vec8_cast_to_c_string() {
245246
let v: Vec<u8> = vec![0, 1, b'\0', 2, 3];
246247
let c = v.as_ptr() as *const libc::c_char;
247248
for (i, vi) in v.iter().enumerate() {
248-
assert_eq!(*vi as i8, unsafe { *c.add(i) });
249+
assert_eq!(*vi as c_char, unsafe { *c.add(i) });
249250
}
250251

251252
let _ = match Some(&v) {

src/sys/edge_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::newtypes::EdgeId;
@@ -64,7 +65,7 @@ impl EdgeTable {
6465
right,
6566
parent,
6667
child,
67-
metadata.as_ptr().cast::<i8>(),
68+
metadata.as_ptr().cast::<c_char>(),
6869
metadata.len() as u64,
6970
))
7071
}

src/sys/individual_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::bindings::tsk_size_t;
@@ -65,7 +66,7 @@ impl IndividualTable {
6566
location.len() as u64,
6667
parents.as_ptr(),
6768
parents.len() as u64,
68-
metadata.as_ptr().cast::<i8>(),
69+
metadata.as_ptr().cast::<c_char>(),
6970
metadata.len() as u64,
7071
))
7172
}

src/sys/migration_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::newtypes::MigrationId;
@@ -71,7 +72,7 @@ impl MigrationTable {
7172
source,
7273
dest,
7374
time,
74-
metadata.as_ptr().cast::<i8>(),
75+
metadata.as_ptr().cast::<c_char>(),
7576
metadata.len() as u64,
7677
))
7778
}

src/sys/mutation_table.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::newtypes::MutationId;
@@ -70,14 +71,14 @@ impl MutationTable {
7071
parent,
7172
time,
7273
match derived_state {
73-
Some(d) => d.as_ptr() as *const i8,
74+
Some(d) => d.as_ptr() as *const c_char,
7475
None => std::ptr::null(),
7576
},
7677
match derived_state {
7778
Some(d) => d.len() as u64,
7879
None => 0,
7980
},
80-
metadata.as_ptr().cast::<i8>(),
81+
metadata.as_ptr().cast::<c_char>(),
8182
metadata.len() as u64,
8283
))
8384
}

src/sys/node_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::flags::NodeFlags;
@@ -80,7 +81,7 @@ impl NodeTable {
8081
time.into().into(),
8182
population.into().into(),
8283
individual.into().into(),
83-
metadata.as_ptr().cast::<i8>(),
84+
metadata.as_ptr().cast::<c_char>(),
8485
metadata.len() as u64,
8586
)
8687
} {

src/sys/population_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::bindings::tsk_id_t;
@@ -44,7 +45,7 @@ impl PopulationTable {
4445
unsafe {
4546
Ok(tsk_population_table_add_row(
4647
self.as_mut(),
47-
metadata.as_ptr().cast::<i8>(),
48+
metadata.as_ptr().cast::<c_char>(),
4849
metadata.len() as u64,
4950
))
5051
}

src/sys/provenance_table.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::bindings::tsk_provenance_table_t;
1010
use super::bindings::tsk_size_t;
1111
use super::tskbox::TskBox;
1212
use super::TskitError;
13+
use std::ffi::c_char;
1314

1415
#[derive(Debug)]
1516
pub struct ProvenanceTable(TskBox<tsk_provenance_table_t>);
@@ -49,9 +50,9 @@ impl ProvenanceTable {
4950
let rv = unsafe {
5051
tsk_provenance_table_add_row(
5152
self.as_mut(),
52-
timestamp.as_ptr() as *mut i8,
53+
timestamp.as_ptr() as *const c_char,
5354
timestamp.len() as tsk_size_t,
54-
record.as_ptr() as *mut i8,
55+
record.as_ptr() as *const c_char,
5556
record.len() as tsk_size_t,
5657
)
5758
};

src/sys/site_table.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::c_char;
12
use std::ptr::NonNull;
23

34
use super::bindings::tsk_size_t;
@@ -58,14 +59,14 @@ impl SiteTable {
5859
self.as_mut(),
5960
position,
6061
match ancestral_state {
61-
Some(d) => d.as_ptr() as *const i8,
62+
Some(d) => d.as_ptr() as *const c_char,
6263
None => std::ptr::null(),
6364
},
6465
match ancestral_state {
6566
Some(d) => d.len() as u64,
6667
None => 0,
6768
},
68-
metadata.as_ptr().cast::<i8>(),
69+
metadata.as_ptr().cast::<c_char>(),
6970
metadata.len() as u64,
7071
))
7172
}

0 commit comments

Comments
 (0)