1
- use crate :: argconv:: { free_boxed , ptr_to_ref , ptr_to_ref_mut } ;
1
+ use crate :: argconv:: { ArcFFI , BoxFFI } ;
2
2
use crate :: cass_error:: CassError ;
3
3
use crate :: cass_types:: CassConsistency ;
4
4
use crate :: cass_types:: { make_batch_type, CassBatchType } ;
@@ -19,6 +19,8 @@ pub struct CassBatch {
19
19
pub ( crate ) exec_profile : Option < PerStatementExecProfile > ,
20
20
}
21
21
22
+ impl BoxFFI for CassBatch { }
23
+
22
24
#[ derive( Clone ) ]
23
25
pub struct CassBatchState {
24
26
pub batch : Batch ,
@@ -28,7 +30,7 @@ pub struct CassBatchState {
28
30
#[ no_mangle]
29
31
pub unsafe extern "C" fn cass_batch_new ( type_ : CassBatchType ) -> * mut CassBatch {
30
32
if let Some ( batch_type) = make_batch_type ( type_) {
31
- Box :: into_raw ( Box :: new ( CassBatch {
33
+ BoxFFI :: into_ptr ( Box :: new ( CassBatch {
32
34
state : Arc :: new ( CassBatchState {
33
35
batch : Batch :: new ( batch_type) ,
34
36
bound_values : Vec :: new ( ) ,
@@ -43,15 +45,15 @@ pub unsafe extern "C" fn cass_batch_new(type_: CassBatchType) -> *mut CassBatch
43
45
44
46
#[ no_mangle]
45
47
pub unsafe extern "C" fn cass_batch_free ( batch : * mut CassBatch ) {
46
- free_boxed ( batch)
48
+ BoxFFI :: free ( batch) ;
47
49
}
48
50
49
51
#[ no_mangle]
50
52
pub unsafe extern "C" fn cass_batch_set_consistency (
51
53
batch : * mut CassBatch ,
52
54
consistency : CassConsistency ,
53
55
) -> CassError {
54
- let batch = ptr_to_ref_mut ( batch) ;
56
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
55
57
let consistency = match consistency. try_into ( ) . ok ( ) {
56
58
Some ( c) => c,
57
59
None => return CassError :: CASS_ERROR_LIB_BAD_PARAMS ,
@@ -68,7 +70,7 @@ pub unsafe extern "C" fn cass_batch_set_serial_consistency(
68
70
batch : * mut CassBatch ,
69
71
serial_consistency : CassConsistency ,
70
72
) -> CassError {
71
- let batch = ptr_to_ref_mut ( batch) ;
73
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
72
74
let serial_consistency = match serial_consistency. try_into ( ) . ok ( ) {
73
75
Some ( c) => c,
74
76
None => return CassError :: CASS_ERROR_LIB_BAD_PARAMS ,
@@ -85,10 +87,10 @@ pub unsafe extern "C" fn cass_batch_set_retry_policy(
85
87
batch : * mut CassBatch ,
86
88
retry_policy : * const CassRetryPolicy ,
87
89
) -> CassError {
88
- let batch = ptr_to_ref_mut ( batch) ;
90
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
89
91
90
92
let maybe_arced_retry_policy: Option < Arc < dyn scylla:: retry_policy:: RetryPolicy > > =
91
- retry_policy . as_ref ( ) . map ( |policy| match policy {
93
+ ArcFFI :: as_maybe_ref ( retry_policy ) . map ( |policy| match policy {
92
94
CassRetryPolicy :: DefaultRetryPolicy ( default) => {
93
95
default. clone ( ) as Arc < dyn scylla:: retry_policy:: RetryPolicy >
94
96
}
@@ -108,7 +110,7 @@ pub unsafe extern "C" fn cass_batch_set_timestamp(
108
110
batch : * mut CassBatch ,
109
111
timestamp : cass_int64_t ,
110
112
) -> CassError {
111
- let batch = ptr_to_ref_mut ( batch) ;
113
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
112
114
113
115
Arc :: make_mut ( & mut batch. state )
114
116
. batch
@@ -122,7 +124,7 @@ pub unsafe extern "C" fn cass_batch_set_request_timeout(
122
124
batch : * mut CassBatch ,
123
125
timeout_ms : cass_uint64_t ,
124
126
) -> CassError {
125
- let batch = ptr_to_ref_mut ( batch) ;
127
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
126
128
batch. batch_request_timeout_ms = Some ( timeout_ms) ;
127
129
128
130
CassError :: CASS_OK
@@ -133,7 +135,7 @@ pub unsafe extern "C" fn cass_batch_set_is_idempotent(
133
135
batch : * mut CassBatch ,
134
136
is_idempotent : cass_bool_t ,
135
137
) -> CassError {
136
- let batch = ptr_to_ref_mut ( batch) ;
138
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
137
139
Arc :: make_mut ( & mut batch. state )
138
140
. batch
139
141
. set_is_idempotent ( is_idempotent != 0 ) ;
@@ -146,7 +148,7 @@ pub unsafe extern "C" fn cass_batch_set_tracing(
146
148
batch : * mut CassBatch ,
147
149
enabled : cass_bool_t ,
148
150
) -> CassError {
149
- let batch = ptr_to_ref_mut ( batch) ;
151
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
150
152
Arc :: make_mut ( & mut batch. state )
151
153
. batch
152
154
. set_tracing ( enabled != 0 ) ;
@@ -159,9 +161,9 @@ pub unsafe extern "C" fn cass_batch_add_statement(
159
161
batch : * mut CassBatch ,
160
162
statement : * const CassStatement ,
161
163
) -> CassError {
162
- let batch = ptr_to_ref_mut ( batch) ;
164
+ let batch = BoxFFI :: as_mut_ref ( batch) ;
163
165
let state = Arc :: make_mut ( & mut batch. state ) ;
164
- let statement = ptr_to_ref ( statement) ;
166
+ let statement = BoxFFI :: as_ref ( statement) ;
165
167
166
168
match & statement. statement {
167
169
Statement :: Simple ( q) => state. batch . append_statement ( q. query . clone ( ) ) ,
0 commit comments