Skip to content

Commit

Permalink
fix: segment fault caused by weak
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamEECS committed Dec 5, 2023
1 parent fbed0c6 commit 0fa4283
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions taos-optin/src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,42 +1313,41 @@ impl RawRes {
Poll::Ready(item)
} else {
current.in_use = true;
let param = Box::new((Arc::downgrade(state), self.c.clone(), cx.waker().clone()));
let param = Box::new((state.clone(), self.c.clone(), cx.waker().clone()));
#[no_mangle]
unsafe extern "C" fn taos_optin_fetch_rows_callback(
param: *mut c_void,
res: *mut TAOS_RES,
num_of_rows: c_int,
) {
let param = param as *mut (Weak<UnsafeCell<BlockState>>, Arc<ApiEntry>, Waker);
let param = param as *mut (Arc<UnsafeCell<BlockState>>, Arc<ApiEntry>, Waker);
let param = Box::from_raw(param);
if let Some(state) = param.0.upgrade() {
let state = &mut *state.get();
let api = &*param.1;
// state.done = true;
state.in_use = false;
if num_of_rows < 0 {
// error
state.result.replace(Err(RawError::new_with_context(
num_of_rows,
api.err_str(res),
"fetch_rows_a",
)));
let state = param.0;
let state = &mut *state.get();
let api = &*param.1;
// state.done = true;
state.in_use = false;
if num_of_rows < 0 {
// error
state.result.replace(Err(RawError::new_with_context(
num_of_rows,
api.err_str(res),
"fetch_rows_a",
)));
} else {
// success
if num_of_rows > 0 {
// has a block
let block = (param.1.taos_result_block.unwrap())(res).read() as _;
state
.result
.replace(Ok(Some((block, num_of_rows as usize))));
} else {
// success
if num_of_rows > 0 {
// has a block
let block = (param.1.taos_result_block.unwrap())(res).read() as _;
state
.result
.replace(Ok(Some((block, num_of_rows as usize))));
} else {
// retrieving completed
state.result.replace(Ok(None));
}
// retrieving completed
state.result.replace(Ok(None));
}
param.2.wake()
}
param.2.wake()
}
unsafe {
(self.c.taos_fetch_rows_a)(
Expand Down

0 comments on commit 0fa4283

Please sign in to comment.