Skip to content

Commit 3d18a2d

Browse files
committed
Fix Rust enum representation to match C ABI
1 parent ad518a7 commit 3d18a2d

File tree

12 files changed

+165
-165
lines changed

12 files changed

+165
-165
lines changed

src/algorithm/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate libc;
33
use array::Array;
44
use defines::{AfError, BinaryOp};
55
use error::HANDLE_ERROR;
6-
use self::libc::{c_int, uint8_t, c_uint, c_double};
6+
use self::libc::{c_int, c_uint, c_double};
77
use util::{AfArray, MutAfArray, MutDouble, MutUint};
88
use util::{HasAfEnum, Scanable, RealNumber};
99

@@ -44,9 +44,9 @@ extern {
4444
fn af_sort_by_key(out_keys: MutAfArray, out_vals: MutAfArray,
4545
in_keys: AfArray, in_vals: AfArray, dim: c_uint, ascend: c_int) -> c_int;
4646

47-
fn af_scan(out: MutAfArray, inp: AfArray, dim: c_int, op: uint8_t, inclusive: c_int) -> c_int;
47+
fn af_scan(out: MutAfArray, inp: AfArray, dim: c_int, op: c_uint, inclusive: c_int) -> c_int;
4848
fn af_scan_by_key(out: MutAfArray, key: AfArray, inp: AfArray,
49-
dim: c_int, op: uint8_t, inclusive: c_int) -> c_int;
49+
dim: c_int, op: c_uint, inclusive: c_int) -> c_int;
5050
}
5151

5252
macro_rules! dim_reduce_func_def {
@@ -922,7 +922,7 @@ pub fn scan<T>(input: &Array<T>, dim: i32,
922922
let mut temp : i64 = 0;
923923
unsafe {
924924
let err_val = af_scan(&mut temp as MutAfArray, input.get() as AfArray,
925-
dim as c_int, op as uint8_t, inclusive as c_int);
925+
dim as c_int, op as c_uint, inclusive as c_int);
926926
HANDLE_ERROR(AfError::from(err_val));
927927
}
928928
temp.into()
@@ -953,7 +953,7 @@ pub fn scan_by_key<K, V>(key: &Array<K>, input: &Array<V>,
953953
unsafe {
954954
let err_val = af_scan_by_key(&mut temp as MutAfArray, key.get() as AfArray,
955955
input.get() as AfArray, dim as c_int,
956-
op as uint8_t, inclusive as c_int);
956+
op as c_uint, inclusive as c_int);
957957
HANDLE_ERROR(AfError::from(err_val));
958958
}
959959
temp.into()

src/array.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use dim4::Dim4;
44
use defines::{AfError, DType, Backend};
55
use error::HANDLE_ERROR;
66
use util::{AfArray, DimT, HasAfEnum, MutAfArray, MutVoidPtr};
7-
use self::libc::{uint8_t, c_void, c_int, c_uint, c_longlong, c_char};
7+
use self::libc::{c_void, c_int, c_uint, c_longlong, c_char};
88
use std::marker::PhantomData;
99
use std::ffi::CString;
1010

@@ -16,13 +16,13 @@ use std::ffi::CString;
1616
#[allow(dead_code)]
1717
extern {
1818
fn af_create_array(out: MutAfArray, data: *const c_void,
19-
ndims: c_uint, dims: *const DimT, aftype: uint8_t) -> c_int;
19+
ndims: c_uint, dims: *const DimT, aftype: c_uint) -> c_int;
2020

21-
fn af_create_handle(out: MutAfArray, ndims: c_uint, dims: *const DimT, aftype: uint8_t) -> c_int;
21+
fn af_create_handle(out: MutAfArray, ndims: c_uint, dims: *const DimT, aftype: c_uint) -> c_int;
2222

2323
fn af_get_elements(out: MutAfArray, arr: AfArray) -> c_int;
2424

25-
fn af_get_type(out: *mut c_int, arr: AfArray) -> c_int;
25+
fn af_get_type(out: *mut c_uint, arr: AfArray) -> c_int;
2626

2727
fn af_get_dims(dim0: *mut c_longlong, dim1: *mut c_longlong, dim2: *mut c_longlong,
2828
dim3: *mut c_longlong, arr: AfArray) -> c_int;
@@ -75,15 +75,15 @@ extern {
7575

7676
fn af_print_array_gen(exp: *const c_char, arr: AfArray, precision: c_int) -> c_int;
7777

78-
fn af_cast(out: MutAfArray, arr: AfArray, aftype: uint8_t) -> c_int;
78+
fn af_cast(out: MutAfArray, arr: AfArray, aftype: c_uint) -> c_int;
7979

80-
fn af_get_backend_id(backend: *mut c_int, input: AfArray) -> c_int;
80+
fn af_get_backend_id(backend: *mut c_uint, input: AfArray) -> c_int;
8181

8282
fn af_get_device_id(device: *mut c_int, input: AfArray) -> c_int;
8383

8484
fn af_create_strided_array(arr: MutAfArray, data: *const c_void, offset: DimT,
8585
ndims: c_uint, dims: *const DimT, strides: *const DimT,
86-
aftype: uint8_t, stype: uint8_t) -> c_int;
86+
aftype: c_uint, stype: c_uint) -> c_int;
8787

8888
fn af_get_strides(s0: *mut DimT, s1: *mut DimT, s2: *mut DimT, s3: *mut DimT,
8989
arr: AfArray) -> c_int;
@@ -155,7 +155,7 @@ impl<T> Array<T> where T: HasAfEnum {
155155
slice.as_ptr() as *const c_void,
156156
dims.ndims() as c_uint,
157157
dims.get().as_ptr() as * const c_longlong,
158-
aftype as uint8_t);
158+
aftype as c_uint);
159159
HANDLE_ERROR(AfError::from(err_val));
160160
}
161161
temp.into()
@@ -176,7 +176,7 @@ impl<T> Array<T> where T: HasAfEnum {
176176
dims.ndims() as c_uint,
177177
dims.get().as_ptr() as * const c_longlong,
178178
strides.get().as_ptr() as * const c_longlong,
179-
aftype as uint8_t, 1);
179+
aftype as c_uint, 1 as c_uint);
180180
HANDLE_ERROR(AfError::from(err_val));
181181
}
182182
temp.into()
@@ -198,7 +198,7 @@ impl<T> Array<T> where T: HasAfEnum {
198198
let err_val = af_create_handle(&mut temp as MutAfArray,
199199
dims.ndims() as c_uint,
200200
dims.get().as_ptr() as * const c_longlong,
201-
aftype as uint8_t);
201+
aftype as c_uint);
202202
HANDLE_ERROR(AfError::from(err_val));
203203
temp.into()
204204
}
@@ -212,8 +212,8 @@ impl<T> Array<T> where T: HasAfEnum {
212212
/// was active when Array was created.
213213
pub fn get_backend(&self) -> Backend {
214214
unsafe {
215-
let mut ret_val: i32 = 0;
216-
let err_val = af_get_backend_id(&mut ret_val as *mut c_int, self.handle as AfArray);
215+
let mut ret_val: u32 = 0;
216+
let err_val = af_get_backend_id(&mut ret_val as *mut c_uint, self.handle as AfArray);
217217
HANDLE_ERROR(AfError::from(err_val));
218218
match (err_val, ret_val) {
219219
(0, 1) => Backend::CPU,
@@ -251,8 +251,8 @@ impl<T> Array<T> where T: HasAfEnum {
251251
/// Returns the Array data type
252252
pub fn get_type(&self) -> DType {
253253
unsafe {
254-
let mut ret_val: i32 = 0;
255-
let err_val = af_get_type(&mut ret_val as *mut c_int, self.handle as AfArray);
254+
let mut ret_val: u32 = 0;
255+
let err_val = af_get_type(&mut ret_val as *mut c_uint, self.handle as AfArray);
256256
HANDLE_ERROR(AfError::from(err_val));
257257
DType::from(ret_val)
258258
}
@@ -364,7 +364,7 @@ impl<T> Array<T> where T: HasAfEnum {
364364
let trgt_type = O::get_af_dtype();
365365
let mut temp: i64 = 0;
366366
unsafe {
367-
let err_val = af_cast(&mut temp as MutAfArray, self.handle as AfArray, trgt_type as uint8_t);
367+
let err_val = af_cast(&mut temp as MutAfArray, self.handle as AfArray, trgt_type as c_uint);
368368
HANDLE_ERROR(AfError::from(err_val));
369369
}
370370
temp.into()

src/data/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use array::Array;
55
use dim4::Dim4;
66
use defines::{AfError};
77
use error::HANDLE_ERROR;
8-
use self::libc::{uint8_t, c_int, c_uint, c_double};
8+
use self::libc::{c_int, c_uint, c_double};
99
use self::num::Complex;
1010
use util::{AfArray, DimT, HasAfEnum, Intl, MutAfArray, Uintl};
1111
use std::vec::Vec;
@@ -25,12 +25,12 @@ extern {
2525
ndims: c_uint, dims: *const DimT) -> c_int;
2626

2727
fn af_range(out: MutAfArray, ndims: c_uint, dims: *const DimT,
28-
seq_dims: c_int, afdtype: uint8_t) -> c_int;
28+
seq_dims: c_int, afdtype: c_uint) -> c_int;
2929

3030
fn af_iota(out: MutAfArray, ndims: c_uint, dims: *const DimT,
31-
t_ndims: c_uint, tdims: *const DimT, afdtype: uint8_t) -> c_int;
31+
t_ndims: c_uint, tdims: *const DimT, afdtype: c_uint) -> c_int;
3232

33-
fn af_identity(out: MutAfArray, ndims: c_uint, dims: *const DimT, afdtype: uint8_t) -> c_int;
33+
fn af_identity(out: MutAfArray, ndims: c_uint, dims: *const DimT, afdtype: c_uint) -> c_int;
3434
fn af_diag_create(out: MutAfArray, arr: AfArray, num: c_int) -> c_int;
3535
fn af_diag_extract(out: MutAfArray, arr: AfArray, num: c_int) -> c_int;
3636
fn af_join(out: MutAfArray, dim: c_int, first: AfArray, second: AfArray) -> c_int;
@@ -243,7 +243,7 @@ pub fn range<T: HasAfEnum>(dims: Dim4, seq_dim: i32) -> Array<T> {
243243
unsafe {
244244
let err_val = af_range(&mut temp as MutAfArray,
245245
dims.ndims() as c_uint, dims.get().as_ptr() as *const DimT,
246-
seq_dim as c_int, aftype as uint8_t);
246+
seq_dim as c_int, aftype as c_uint);
247247
HANDLE_ERROR(AfError::from(err_val));
248248
}
249249
temp.into()
@@ -269,7 +269,7 @@ pub fn iota<T: HasAfEnum>(dims: Dim4, tdims: Dim4) -> Array<T> {
269269
let err_val =af_iota(&mut temp as MutAfArray,
270270
dims.ndims() as c_uint, dims.get().as_ptr() as *const DimT,
271271
tdims.ndims() as c_uint, tdims.get().as_ptr() as *const DimT,
272-
aftype as uint8_t);
272+
aftype as c_uint);
273273
HANDLE_ERROR(AfError::from(err_val));
274274
}
275275
temp.into()
@@ -291,7 +291,7 @@ pub fn identity<T: HasAfEnum>(dims: Dim4) -> Array<T> {
291291
unsafe {
292292
let err_val = af_identity(&mut temp as MutAfArray,
293293
dims.ndims() as c_uint, dims.get().as_ptr() as *const DimT,
294-
aftype as uint8_t);
294+
aftype as c_uint);
295295
HANDLE_ERROR(AfError::from(err_val));
296296
}
297297
temp.into()

0 commit comments

Comments
 (0)