Skip to content

Commit 11c5523

Browse files
committed
Switch arguments from OCamlRooted to &OCamlRooted
1 parent 5707460 commit 11c5523

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@
356356
//! ocaml_export! {
357357
//! // The first parameter is a name to which the GC frame handle will be bound to.
358358
//! // The remaining parameters and return value must have a declared type of `OCaml<T>`.
359-
//! fn rust_twice(cr, num: OCamlRooted<OCamlInt>) -> OCaml<OCamlInt> {
359+
//! fn rust_twice(cr, num: &OCamlRooted<OCamlInt>) -> OCaml<OCamlInt> {
360360
//! let num: i64 = num.to_rust(cr);
361361
//! unsafe { OCaml::of_i64_unchecked(num * 2) }
362362
//! }
363363
//!
364-
//! fn rust_increment_bytes(cr, bytes: OCamlRooted<OCamlBytes>, first_n: OCamlRooted<OCamlInt>) -> OCaml<OCamlBytes> {
364+
//! fn rust_increment_bytes(cr, bytes: &OCamlRooted<OCamlBytes>, first_n: &OCamlRooted<OCamlInt>) -> OCaml<OCamlBytes> {
365365
//! let first_n: i64 = first_n.to_rust(cr);
366366
//! let first_n = first_n as usize;
367367
//! let mut vec: Vec<u8> = bytes.to_rust(cr);

src/macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ macro_rules! ocaml {
162162
/// ```
163163
/// # use ocaml_interop::*;
164164
/// ocaml_export! {
165-
/// fn rust_twice(cr, num: OCamlRooted<OCamlInt>) -> OCaml<OCamlInt> {
165+
/// fn rust_twice(cr, num: &OCamlRooted<OCamlInt>) -> OCaml<OCamlInt> {
166166
/// let num: i64 = num.to_rust(cr);
167167
/// unsafe { OCaml::of_i64_unchecked(num * 2) }
168168
/// }
169169
///
170-
/// fn rust_twice_boxed_i32(cr, num: OCamlRooted<OCamlInt32>) -> OCaml<OCamlInt32> {
170+
/// fn rust_twice_boxed_i32(cr, num: &OCamlRooted<OCamlInt32>) -> OCaml<OCamlInt32> {
171171
/// let num: i32 = num.to_rust(cr);
172172
/// let result = num * 2;
173173
/// ocaml_alloc!(result.to_ocaml(cr))
@@ -177,13 +177,13 @@ macro_rules! ocaml {
177177
/// num * num2
178178
/// }
179179
///
180-
/// fn rust_twice_boxed_float(cr, num: OCamlRooted<OCamlFloat>) -> OCaml<OCamlFloat> {
180+
/// fn rust_twice_boxed_float(cr, num: &OCamlRooted<OCamlFloat>) -> OCaml<OCamlFloat> {
181181
/// let num: f64 = num.to_rust(cr);
182182
/// let result = num * 2.0;
183183
/// ocaml_alloc!(result.to_ocaml(cr))
184184
/// }
185185
///
186-
/// fn rust_increment_ints_list(cr, ints: OCamlRooted<OCamlList<OCamlInt>>) -> OCaml<OCamlList<OCamlInt>> {
186+
/// fn rust_increment_ints_list(cr, ints: &OCamlRooted<OCamlList<OCamlInt>>) -> OCaml<OCamlList<OCamlInt>> {
187187
/// let mut vec: Vec<i64> = ints.to_rust(cr);
188188
///
189189
/// for i in 0..vec.len() {
@@ -193,7 +193,7 @@ macro_rules! ocaml {
193193
/// ocaml_alloc!(vec.to_ocaml(cr))
194194
/// }
195195
///
196-
/// fn rust_make_tuple(cr, fst: OCamlRooted<String>, snd: OCamlRooted<OCamlInt>) -> OCaml<(String, OCamlInt)> {
196+
/// fn rust_make_tuple(cr, fst: &OCamlRooted<String>, snd: &OCamlRooted<OCamlInt>) -> OCaml<(String, OCamlInt)> {
197197
/// let fst: String = fst.to_rust(cr);
198198
/// let snd: i64 = snd.to_rust(cr);
199199
/// let tuple = (fst, snd);
@@ -1292,10 +1292,10 @@ macro_rules! expand_rooted_args_init {
12921292

12931293
// Other values are wrapped in `OCamlRooted<T>` as given the same lifetime as the OCaml runtime handle borrow.
12941294
(($root:ident), $arg:ident : $typ:ty) =>
1295-
(let $arg : $typ = unsafe { $root.keep_raw($arg) };);
1295+
(let $arg : $typ = unsafe { &$root.keep_raw($arg) };);
12961296

12971297
(($root:ident $($roots:ident)*), $arg:ident : $typ:ty, $($args:tt)*) => {
1298-
let $arg : $typ = unsafe { $root.keep_raw($arg) };
1298+
let $arg : $typ = unsafe { &$root.keep_raw($arg) };
12991299
$crate::expand_rooted_args_init!(($($roots)*), $($args)*)
13001300
};
13011301
}

testing/ocaml-caller/rust/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ enum PolymorphicMovement {
2121
}
2222

2323
ocaml_export! {
24-
fn rust_twice(cr, num: OCamlRooted<OCamlInt>) -> OCaml<OCamlInt> {
24+
fn rust_twice(cr, num: &OCamlRooted<OCamlInt>) -> OCaml<OCamlInt> {
2525
let num: i64 = num.to_rust(cr);
2626
unsafe { OCaml::of_i64_unchecked(num * 2) }
2727
}
2828

29-
fn rust_twice_boxed_i64(cr, num: OCamlRooted<OCamlInt64>) -> OCaml<OCamlInt64> {
29+
fn rust_twice_boxed_i64(cr, num: &OCamlRooted<OCamlInt64>) -> OCaml<OCamlInt64> {
3030
let num: i64 = num.to_rust(cr);
3131
let result = num * 2;
3232
result.to_ocaml(cr)
3333
}
3434

35-
fn rust_twice_boxed_i32(cr, num: OCamlRooted<OCamlInt32>) -> OCaml<OCamlInt32> {
35+
fn rust_twice_boxed_i32(cr, num: &OCamlRooted<OCamlInt32>) -> OCaml<OCamlInt32> {
3636
let num: i32 = num.to_rust(cr);
3737
let result = num * 2;
3838
result.to_ocaml(cr)
@@ -42,7 +42,7 @@ ocaml_export! {
4242
num * num2
4343
}
4444

45-
fn rust_twice_boxed_float(cr, num: OCamlRooted<OCamlFloat>) -> OCaml<OCamlFloat> {
45+
fn rust_twice_boxed_float(cr, num: &OCamlRooted<OCamlFloat>) -> OCaml<OCamlFloat> {
4646
let num: f64 = num.to_rust(cr);
4747
let result = num * 2.0;
4848
result.to_ocaml(cr)
@@ -52,7 +52,7 @@ ocaml_export! {
5252
num * 2.0
5353
}
5454

55-
fn rust_increment_bytes(cr, bytes: OCamlRooted<OCamlBytes>, first_n: OCamlRooted<OCamlInt>) -> OCaml<OCamlBytes> {
55+
fn rust_increment_bytes(cr, bytes: &OCamlRooted<OCamlBytes>, first_n: &OCamlRooted<OCamlInt>) -> OCaml<OCamlBytes> {
5656
let first_n: i64 = first_n.to_rust(cr);
5757
let first_n = first_n as usize;
5858
let mut vec: Vec<u8> = bytes.to_rust(cr);
@@ -64,7 +64,7 @@ ocaml_export! {
6464
vec.to_ocaml(cr)
6565
}
6666

67-
fn rust_increment_ints_list(cr, ints: OCamlRooted<OCamlList<OCamlInt>>) -> OCaml<OCamlList<OCamlInt>> {
67+
fn rust_increment_ints_list(cr, ints: &OCamlRooted<OCamlList<OCamlInt>>) -> OCaml<OCamlList<OCamlInt>> {
6868
let mut vec: Vec<i64> = ints.to_rust(cr);
6969

7070
for i in 0..vec.len() {
@@ -74,45 +74,45 @@ ocaml_export! {
7474
vec.to_ocaml(cr)
7575
}
7676

77-
fn rust_make_tuple(cr, fst: OCamlRooted<String>, snd: OCamlRooted<OCamlInt>) -> OCaml<(String, OCamlInt)> {
77+
fn rust_make_tuple(cr, fst: &OCamlRooted<String>, snd: &OCamlRooted<OCamlInt>) -> OCaml<(String, OCamlInt)> {
7878
let fst: String = fst.to_rust(cr);
7979
let snd: i64 = snd.to_rust(cr);
8080
let tuple = (fst, snd);
8181
tuple.to_ocaml(cr)
8282
}
8383

84-
fn rust_make_some(cr, value: OCamlRooted<String>) -> OCaml<Option<String>> {
84+
fn rust_make_some(cr, value: &OCamlRooted<String>) -> OCaml<Option<String>> {
8585
let value: String = value.to_rust(cr);
8686
let some_value = Some(value);
8787
some_value.to_ocaml(cr)
8888
}
8989

90-
fn rust_make_ok(cr, value: OCamlRooted<OCamlInt>) -> OCaml<Result<OCamlInt, String>> {
90+
fn rust_make_ok(cr, value: &OCamlRooted<OCamlInt>) -> OCaml<Result<OCamlInt, String>> {
9191
let value: i64 = value.to_rust(cr);
9292
let ok_value: Result<i64, String> = Ok(value);
9393
to_ocaml!(cr, ok_value)
9494
}
9595

96-
fn rust_make_error(cr, value: OCamlRooted<String>) -> OCaml<Result<OCamlInt, String>> {
96+
fn rust_make_error(cr, value: &OCamlRooted<String>) -> OCaml<Result<OCamlInt, String>> {
9797
let value: String = value.to_rust(cr);
9898
let error_value: Result<i64, String> = Err(value);
9999
to_ocaml!(cr, error_value)
100100
}
101101

102-
fn rust_sleep_releasing(cr, millis: OCamlRooted<OCamlInt>) {
102+
fn rust_sleep_releasing(cr, millis: &OCamlRooted<OCamlInt>) {
103103
let millis: i64 = millis.to_rust(cr);
104104
cr.releasing_runtime(|| thread::sleep(time::Duration::from_millis(millis as u64)));
105105
OCaml::unit()
106106
}
107107

108-
fn rust_sleep(cr, millis: OCamlRooted<OCamlInt>) {
108+
fn rust_sleep(cr, millis: &OCamlRooted<OCamlInt>) {
109109
let millis: i64 = millis.to_rust(cr);
110110
thread::sleep(time::Duration::from_millis(millis as u64));
111111
OCaml::unit()
112112
}
113113

114-
fn rust_string_of_movement(cr, movement: OCamlRooted<PolymorphicMovement>) -> OCaml<String> {
115-
let movement = cr.get(&movement);
114+
fn rust_string_of_movement(cr, movement: &OCamlRooted<PolymorphicMovement>) -> OCaml<String> {
115+
let movement = cr.get(movement);
116116
let pm = ocaml_unpack_variant! {
117117
movement => {
118118
Step(count: OCamlInt) => { Movement::Step {count} },
@@ -129,8 +129,8 @@ ocaml_export! {
129129
to_ocaml!(cr, s)
130130
}
131131

132-
fn rust_string_of_polymorphic_movement(cr, polymorphic_movement: OCamlRooted<PolymorphicMovement>) -> OCaml<String> {
133-
let polymorphic_movement = cr.get(&polymorphic_movement);
132+
fn rust_string_of_polymorphic_movement(cr, polymorphic_movement: &OCamlRooted<PolymorphicMovement>) -> OCaml<String> {
133+
let polymorphic_movement = cr.get(polymorphic_movement);
134134
let pm = ocaml_unpack_polymorphic_variant! {
135135
polymorphic_movement => {
136136
Step(count: OCamlInt) => { PolymorphicMovement::Step {count} },

0 commit comments

Comments
 (0)