Skip to content

Commit 6a3da62

Browse files
z2665fede1024
authored andcommitted
Fix arm build (fede1024#134)
* change to c_char
1 parent 5d5a485 commit 6a3da62

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

src/client.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::os::raw::c_void;
99
use std::ptr;
1010
use std::string::ToString;
1111
use std::time::Duration;
12+
use std::os::raw::c_char;
1213

1314
use serde_json;
1415

@@ -123,7 +124,7 @@ impl<C: ClientContext> Client<C> {
123124
unsafe { rdsys::rd_kafka_conf_set_error_cb(native_config.ptr(), Some(native_error_cb::<C>)) };
124125

125126
let client_ptr = unsafe {
126-
rdsys::rd_kafka_new(rd_kafka_type, native_config.ptr_move(), errstr.as_ptr() as *mut i8, errstr.len())
127+
rdsys::rd_kafka_new(rd_kafka_type, native_config.ptr_move(), errstr.as_ptr() as *mut c_char, errstr.len())
127128
};
128129
trace!("Create new librdkafka client {:p}", client_ptr);
129130

@@ -271,7 +272,7 @@ impl Drop for NativeTopic {
271272

272273
pub(crate) unsafe extern "C" fn native_log_cb<C: ClientContext>(
273274
client: *const RDKafka, level: i32,
274-
fac: *const i8, buf: *const i8) {
275+
fac: *const c_char, buf: *const c_char) {
275276
let fac = CStr::from_ptr(fac).to_string_lossy();
276277
let log_message = CStr::from_ptr(buf).to_string_lossy();
277278

@@ -281,7 +282,7 @@ pub(crate) unsafe extern "C" fn native_log_cb<C: ClientContext>(
281282
}
282283

283284
pub(crate) unsafe extern "C" fn native_stats_cb<C: ClientContext>(
284-
_conf: *mut RDKafka, json: *mut i8, json_len: usize,
285+
_conf: *mut RDKafka, json: *mut c_char, json_len: usize,
285286
opaque: *mut c_void) -> i32 {
286287
let context = Box::from_raw(opaque as *mut C);
287288

@@ -302,7 +303,7 @@ pub(crate) unsafe extern "C" fn native_stats_cb<C: ClientContext>(
302303
}
303304

304305
pub(crate) unsafe extern "C" fn native_error_cb<C: ClientContext>(
305-
_client: *mut RDKafka, err: i32, reason: *const i8,
306+
_client: *mut RDKafka, err: i32, reason: *const c_char,
306307
opaque: *mut c_void) {
307308
let err = rdsys::primitive_to_rd_kafka_resp_err_t(err)
308309
.expect("global error not an rd_kafka_resp_err_t");

src/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::util::bytes_cstr_to_owned;
2929
use std::collections::HashMap;
3030
use std::ffi::CString;
3131
use std::mem;
32+
use std::os::raw::c_char;
3233

3334
const ERR_LEN: usize = 256;
3435

@@ -151,7 +152,7 @@ impl ClientConfig {
151152
let value_c = CString::new(value.to_string())?;
152153
let ret = unsafe {
153154
rdsys::rd_kafka_conf_set(conf, key_c.as_ptr(), value_c.as_ptr(),
154-
errstr.as_ptr() as *mut i8, errstr.len())
155+
errstr.as_ptr() as *mut c_char, errstr.len())
155156
};
156157
if ret.is_error() {
157158
let descr = unsafe { bytes_cstr_to_owned(&errstr) };

src/consumer/base_consumer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<C: ConsumerContext> Consumer<C> for BaseConsumer<C> {
176176
}
177177
let ret_code = unsafe { rdsys::rd_kafka_subscribe(self.client.native_ptr(), tpl.ptr()) };
178178
if ret_code.is_error() {
179-
let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(ret_code)) };
179+
let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(ret_code) as *const i8) };
180180
return Err(KafkaError::Subscription(error));
181181
};
182182
Ok(())
@@ -189,7 +189,7 @@ impl<C: ConsumerContext> Consumer<C> for BaseConsumer<C> {
189189
fn assign(&self, assignment: &TopicPartitionList) -> KafkaResult<()> {
190190
let ret_code = unsafe { rdsys::rd_kafka_assign(self.client.native_ptr(), assignment.ptr()) };
191191
if ret_code.is_error() {
192-
let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(ret_code)) };
192+
let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(ret_code) as *const i8) };
193193
return Err(KafkaError::Subscription(error));
194194
};
195195
Ok(())

src/consumer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait ConsumerContext: ClientContext {
5151
}
5252
RDKafkaRespErr::RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS => Rebalance::Revoke,
5353
_ => {
54-
let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(err)) };
54+
let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(err) as *const i8) };
5555
error!("Error rebalancing: {}", error);
5656
Rebalance::Error(error)
5757
}

src/util.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::os::raw::c_void;
66
use std::ptr;
77
use std::slice;
88
use std::time::{Duration, SystemTime, UNIX_EPOCH};
9+
use std::os::raw::c_char;
910

1011
/// Return a tuple representing the version of `librdkafka` in
1112
/// hexadecimal and string format.
@@ -102,12 +103,12 @@ impl<T: Send + Sync> IntoOpaque for Box<T> {
102103
// TODO: check if the implementation returns a copy of the data and update the documentation
103104
/// Converts a byte array representing a C string into a String.
104105
pub unsafe fn bytes_cstr_to_owned(bytes_cstr: &[i8]) -> String {
105-
CStr::from_ptr(bytes_cstr.as_ptr()).to_string_lossy().into_owned()
106+
CStr::from_ptr(bytes_cstr.as_ptr() as *const c_char).to_string_lossy().into_owned()
106107
}
107108

108109
/// Converts a C string into a String.
109110
pub unsafe fn cstr_to_owned(cstr: *const i8) -> String {
110-
CStr::from_ptr(cstr).to_string_lossy().into_owned()
111+
CStr::from_ptr(cstr as *const c_char).to_string_lossy().into_owned()
111112
}
112113

113114
#[cfg(test)]

0 commit comments

Comments
 (0)