refactor(ffi): return null ptr instead of aborting in C API (#2478)
Make C API functions that return pointers return null in case of a panic, instead of aborting. Add ffi_fn! macro rules that enable default error values to be returned by writing "?= <value>" after an ffi function's body.
This commit is contained in:
@@ -189,7 +189,7 @@ ffi_fn! {
|
||||
/// Creates a new task executor.
|
||||
fn hyper_executor_new() -> *const hyper_executor {
|
||||
Arc::into_raw(hyper_executor::new())
|
||||
}
|
||||
} ?= ptr::null()
|
||||
}
|
||||
|
||||
ffi_fn! {
|
||||
@@ -230,7 +230,7 @@ ffi_fn! {
|
||||
Some(task) => Box::into_raw(task),
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
} ?= ptr::null_mut()
|
||||
}
|
||||
|
||||
// ===== impl hyper_task =====
|
||||
@@ -303,7 +303,7 @@ ffi_fn! {
|
||||
} else {
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
} ?= ptr::null_mut()
|
||||
}
|
||||
|
||||
ffi_fn! {
|
||||
@@ -341,7 +341,7 @@ ffi_fn! {
|
||||
}
|
||||
|
||||
unsafe { &*task }.userdata.0
|
||||
}
|
||||
} ?= ptr::null_mut()
|
||||
}
|
||||
|
||||
// ===== impl AsTaskType =====
|
||||
@@ -405,7 +405,7 @@ ffi_fn! {
|
||||
fn hyper_context_waker(cx: *mut hyper_context<'_>) -> *mut hyper_waker {
|
||||
let waker = unsafe { &mut *cx }.0.waker().clone();
|
||||
Box::into_raw(Box::new(hyper_waker { waker }))
|
||||
}
|
||||
} ?= ptr::null_mut()
|
||||
}
|
||||
|
||||
// ===== impl hyper_waker =====
|
||||
|
||||
Reference in New Issue
Block a user