Skip to content

Commit 1e75898

Browse files
fix build
1 parent d192d41 commit 1e75898

File tree

2 files changed

+97
-48
lines changed

2 files changed

+97
-48
lines changed

bindings/c/include/opendal.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ typedef struct Option_Receiver_Result_Buffer Option_Receiver_Result_Buffer;
117117

118118
typedef struct Option_Receiver_Result_Metadata Option_Receiver_Result_Metadata;
119119

120-
typedef struct Operator Operator;
121-
122120
/**
123121
* \brief opendal_bytes carries raw-bytes with its length
124122
*
@@ -466,7 +464,7 @@ typedef struct opendal_async_operator {
466464
/**
467465
* Internal pointer to the Rust async Operator.
468466
*/
469-
Operator *inner;
467+
void *inner;
470468
} opendal_async_operator;
471469

472470
/**
@@ -774,14 +772,6 @@ typedef struct opendal_result_writer_write {
774772
extern "C" {
775773
#endif // __cplusplus
776774

777-
extern const enum opendal_future_status OPENDAL_FUTURE_PENDING;
778-
779-
extern const enum opendal_future_status OPENDAL_FUTURE_READY;
780-
781-
extern const enum opendal_future_status OPENDAL_FUTURE_ERROR;
782-
783-
extern const enum opendal_future_status OPENDAL_FUTURE_CANCELED;
784-
785775
/**
786776
* \brief Frees the opendal_error, ok to call on NULL
787777
*/
@@ -1513,6 +1503,11 @@ struct opendal_result_future_stat opendal_async_operator_stat(const struct opend
15131503

15141504
struct opendal_result_stat opendal_future_stat_await(struct opendal_future_stat *future);
15151505

1506+
enum opendal_future_status opendal_future_stat_poll(struct opendal_future_stat *future,
1507+
struct opendal_result_stat *out);
1508+
1509+
bool opendal_future_stat_is_ready(const struct opendal_future_stat *future);
1510+
15161511
/**
15171512
* \brief Cancel and free a stat future without awaiting it.
15181513
*/
@@ -1529,6 +1524,11 @@ struct opendal_result_future_read opendal_async_operator_read(const struct opend
15291524

15301525
struct opendal_result_read opendal_future_read_await(struct opendal_future_read *future);
15311526

1527+
enum opendal_future_status opendal_future_read_poll(struct opendal_future_read *future,
1528+
struct opendal_result_read *out);
1529+
1530+
bool opendal_future_read_is_ready(const struct opendal_future_read *future);
1531+
15321532
/**
15331533
* \brief Cancel and free a read future without awaiting it.
15341534
*/
@@ -1543,6 +1543,11 @@ struct opendal_result_future_write opendal_async_operator_write(const struct ope
15431543

15441544
struct opendal_error *opendal_future_write_await(struct opendal_future_write *future);
15451545

1546+
enum opendal_future_status opendal_future_write_poll(struct opendal_future_write *future,
1547+
struct opendal_error **error_out);
1548+
1549+
bool opendal_future_write_is_ready(const struct opendal_future_write *future);
1550+
15461551
/**
15471552
* \brief Cancel and free a write future without awaiting it.
15481553
*/
@@ -1556,6 +1561,11 @@ struct opendal_result_future_delete opendal_async_operator_delete(const struct o
15561561

15571562
struct opendal_error *opendal_future_delete_await(struct opendal_future_delete *future);
15581563

1564+
enum opendal_future_status opendal_future_delete_poll(struct opendal_future_delete *future,
1565+
struct opendal_error **error_out);
1566+
1567+
bool opendal_future_delete_is_ready(const struct opendal_future_delete *future);
1568+
15591569
/**
15601570
* \brief Cancel and free a delete future without awaiting it.
15611571
*/

bindings/c/src/async_operator.rs

Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use std::collections::HashMap;
19+
use std::ffi::c_void;
1920
use std::os::raw::c_char;
2021
use std::str::FromStr;
2122
use tokio::sync::oneshot;
@@ -34,6 +35,7 @@ use crate::types::opendal_operator_options; // Keep this
3435

3536
/// Status returned by non-blocking future polling.
3637
#[repr(C)]
38+
#[derive(Copy, Clone)]
3739
pub enum opendal_future_status {
3840
/// Future is still pending.
3941
OPENDAL_FUTURE_PENDING = 0,
@@ -45,26 +47,9 @@ pub enum opendal_future_status {
4547
OPENDAL_FUTURE_CANCELED = 3,
4648
}
4749

48-
#[no_mangle]
49-
pub static OPENDAL_FUTURE_PENDING: opendal_future_status =
50-
opendal_future_status::OPENDAL_FUTURE_PENDING;
51-
#[no_mangle]
52-
pub static OPENDAL_FUTURE_READY: opendal_future_status =
53-
opendal_future_status::OPENDAL_FUTURE_READY;
54-
#[no_mangle]
55-
pub static OPENDAL_FUTURE_ERROR: opendal_future_status =
56-
opendal_future_status::OPENDAL_FUTURE_ERROR;
57-
#[no_mangle]
58-
pub static OPENDAL_FUTURE_CANCELED: opendal_future_status =
59-
opendal_future_status::OPENDAL_FUTURE_CANCELED;
60-
6150
macro_rules! impl_poll_result {
62-
($fn_name:ident, $future_ty:ty, $out_ty:ty, $ok_ctor:expr, $err_ctor:expr) => {
63-
#[no_mangle]
64-
pub unsafe extern "C" fn $fn_name(
65-
future: *mut $future_ty,
66-
out: *mut $out_ty,
67-
) -> opendal_future_status {
51+
($fn_impl:ident, $future_ty:ty, $out_ty:ty, $ok_ctor:expr, $err_ctor:expr) => {
52+
unsafe fn $fn_impl(future: *mut $future_ty, out: *mut $out_ty) -> opendal_future_status {
6853
if future.is_null() || out.is_null() {
6954
return opendal_future_status::OPENDAL_FUTURE_ERROR;
7055
}
@@ -118,9 +103,8 @@ macro_rules! impl_poll_result {
118103
}
119104

120105
macro_rules! impl_poll_error_only {
121-
($fn_name:ident, $future_ty:ty) => {
122-
#[no_mangle]
123-
pub unsafe extern "C" fn $fn_name(
106+
($fn_impl:ident, $future_ty:ty) => {
107+
unsafe fn $fn_impl(
124108
future: *mut $future_ty,
125109
error_out: *mut *mut opendal_error,
126110
) -> opendal_future_status {
@@ -174,9 +158,8 @@ macro_rules! impl_poll_error_only {
174158
}
175159

176160
macro_rules! impl_is_ready_fn {
177-
($fn_name:ident, $future_ty:ty) => {
178-
#[no_mangle]
179-
pub unsafe extern "C" fn $fn_name(future: *const $future_ty) -> bool {
161+
($fn_impl:ident, $future_ty:ty) => {
162+
unsafe fn $fn_impl(future: *const $future_ty) -> bool {
180163
if future.is_null() {
181164
return false;
182165
}
@@ -390,7 +373,7 @@ unsafe impl Send for opendal_result_future_delete {}
390373
#[repr(C)]
391374
pub struct opendal_async_operator {
392375
/// Internal pointer to the Rust async Operator.
393-
inner: *mut core::Operator,
376+
inner: *mut c_void,
394377
}
395378

396379
impl opendal_async_operator {
@@ -402,7 +385,7 @@ impl opendal_async_operator {
402385
/// and that the lifetime of the returned reference does not exceed the lifetime
403386
/// of the `opendal_async_operator`.
404387
pub(crate) unsafe fn as_ref(&self) -> &core::Operator {
405-
&*self.inner
388+
&*(self.inner as *mut core::Operator)
406389
}
407390
}
408391

@@ -463,7 +446,7 @@ pub unsafe extern "C" fn opendal_async_operator_new(
463446
op = op.layer(core::layers::RetryLayer::new());
464447

465448
let async_op = Box::into_raw(Box::new(opendal_async_operator {
466-
inner: Box::into_raw(Box::new(op)),
449+
inner: Box::into_raw(Box::new(op)) as *mut c_void,
467450
}));
468451

469452
// We reuse opendal_result_operator_new, but the `op` field now points
@@ -490,7 +473,7 @@ pub unsafe extern "C" fn opendal_async_operator_new(
490473
pub unsafe extern "C" fn opendal_async_operator_free(op: *const opendal_async_operator) {
491474
if !op.is_null() {
492475
// Drop the inner Operator
493-
drop(Box::from_raw((*op).inner));
476+
drop(Box::from_raw((*op).inner as *mut core::Operator));
494477
// Drop the container struct itself
495478
drop(Box::from_raw(op as *mut opendal_async_operator));
496479
}
@@ -587,7 +570,7 @@ pub unsafe extern "C" fn opendal_future_stat_await(
587570
}
588571

589572
impl_poll_result!(
590-
opendal_future_stat_poll,
573+
opendal_future_stat_poll_impl,
591574
opendal_future_stat,
592575
opendal_result_stat,
593576
|metadata| opendal_result_stat {
@@ -600,7 +583,20 @@ impl_poll_result!(
600583
}
601584
);
602585

603-
impl_is_ready_fn!(opendal_future_stat_is_ready, opendal_future_stat);
586+
#[no_mangle]
587+
pub unsafe extern "C" fn opendal_future_stat_poll(
588+
future: *mut opendal_future_stat,
589+
out: *mut opendal_result_stat,
590+
) -> opendal_future_status {
591+
opendal_future_stat_poll_impl(future, out)
592+
}
593+
594+
impl_is_ready_fn!(opendal_future_stat_is_ready_impl, opendal_future_stat);
595+
596+
#[no_mangle]
597+
pub unsafe extern "C" fn opendal_future_stat_is_ready(future: *const opendal_future_stat) -> bool {
598+
opendal_future_stat_is_ready_impl(future)
599+
}
604600

605601
/// \brief Cancel and free a stat future without awaiting it.
606602
#[no_mangle]
@@ -706,7 +702,7 @@ pub unsafe extern "C" fn opendal_future_read_await(
706702
}
707703

708704
impl_poll_result!(
709-
opendal_future_read_poll,
705+
opendal_future_read_poll_impl,
710706
opendal_future_read,
711707
opendal_result_read,
712708
|buffer| opendal_result_read {
@@ -719,7 +715,20 @@ impl_poll_result!(
719715
}
720716
);
721717

722-
impl_is_ready_fn!(opendal_future_read_is_ready, opendal_future_read);
718+
#[no_mangle]
719+
pub unsafe extern "C" fn opendal_future_read_poll(
720+
future: *mut opendal_future_read,
721+
out: *mut opendal_result_read,
722+
) -> opendal_future_status {
723+
opendal_future_read_poll_impl(future, out)
724+
}
725+
726+
impl_is_ready_fn!(opendal_future_read_is_ready_impl, opendal_future_read);
727+
728+
#[no_mangle]
729+
pub unsafe extern "C" fn opendal_future_read_is_ready(future: *const opendal_future_read) -> bool {
730+
opendal_future_read_is_ready_impl(future)
731+
}
723732

724733
/// \brief Cancel and free a read future without awaiting it.
725734
#[no_mangle]
@@ -820,9 +829,24 @@ pub unsafe extern "C" fn opendal_future_write_await(
820829
opendal_future_write_await_impl(future)
821830
}
822831

823-
impl_poll_error_only!(opendal_future_write_poll, opendal_future_write);
832+
impl_poll_error_only!(opendal_future_write_poll_impl, opendal_future_write);
833+
834+
#[no_mangle]
835+
pub unsafe extern "C" fn opendal_future_write_poll(
836+
future: *mut opendal_future_write,
837+
error_out: *mut *mut opendal_error,
838+
) -> opendal_future_status {
839+
opendal_future_write_poll_impl(future, error_out)
840+
}
841+
842+
impl_is_ready_fn!(opendal_future_write_is_ready_impl, opendal_future_write);
824843

825-
impl_is_ready_fn!(opendal_future_write_is_ready, opendal_future_write);
844+
#[no_mangle]
845+
pub unsafe extern "C" fn opendal_future_write_is_ready(
846+
future: *const opendal_future_write,
847+
) -> bool {
848+
opendal_future_write_is_ready_impl(future)
849+
}
826850

827851
/// \brief Cancel and free a write future without awaiting it.
828852
#[no_mangle]
@@ -912,9 +936,24 @@ pub unsafe extern "C" fn opendal_future_delete_await(
912936
opendal_future_delete_await_impl(future)
913937
}
914938

915-
impl_poll_error_only!(opendal_future_delete_poll, opendal_future_delete);
939+
impl_poll_error_only!(opendal_future_delete_poll_impl, opendal_future_delete);
940+
941+
#[no_mangle]
942+
pub unsafe extern "C" fn opendal_future_delete_poll(
943+
future: *mut opendal_future_delete,
944+
error_out: *mut *mut opendal_error,
945+
) -> opendal_future_status {
946+
opendal_future_delete_poll_impl(future, error_out)
947+
}
948+
949+
impl_is_ready_fn!(opendal_future_delete_is_ready_impl, opendal_future_delete);
916950

917-
impl_is_ready_fn!(opendal_future_delete_is_ready, opendal_future_delete);
951+
#[no_mangle]
952+
pub unsafe extern "C" fn opendal_future_delete_is_ready(
953+
future: *const opendal_future_delete,
954+
) -> bool {
955+
opendal_future_delete_is_ready_impl(future)
956+
}
918957

919958
/// \brief Cancel and free a delete future without awaiting it.
920959
#[no_mangle]

0 commit comments

Comments
 (0)