Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

Commit 2c8f6f5

Browse files
author
Filippo Costa
committed
Replace RuntimePtr with *mut c_void
1 parent fed94e4 commit 2c8f6f5

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

crates/runtime-ffi/src/api.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ lazy_static! {
2020
static ref INITIALIZED: Mutex<bool> = Mutex::new(false);
2121
}
2222

23-
type RuntimePtr = *mut c_void;
24-
2523
/// Initializes the SVM library.
2624
#[must_use]
2725
#[no_mangle]
@@ -59,7 +57,7 @@ pub unsafe extern "C" fn svm_free_result(_result: svm_result_t) {}
5957
#[must_use]
6058
#[no_mangle]
6159
pub unsafe extern "C" fn svm_runtime_create(
62-
runtime_ptr: *mut RuntimePtr,
60+
runtime_ptr: *mut *mut c_void,
6361
path: *const u8,
6462
path_len: u32,
6563
) -> svm_result_t {
@@ -111,7 +109,7 @@ pub unsafe extern "C" fn svm_runtime_create(
111109
///
112110
#[must_use]
113111
#[no_mangle]
114-
pub extern "C" fn svm_runtime_destroy(runtime: RuntimePtr) -> svm_result_t {
112+
pub extern "C" fn svm_runtime_destroy(runtime: *mut c_void) -> svm_result_t {
115113
if RUNTIME_TRACKER.free(runtime).is_some() {
116114
svm_result_t::OK
117115
} else {
@@ -150,7 +148,7 @@ pub extern "C" fn svm_runtimes_count() -> u64 {
150148
#[must_use]
151149
#[no_mangle]
152150
pub unsafe extern "C" fn svm_validate_deploy(
153-
runtime: RuntimePtr,
151+
runtime: *mut c_void,
154152
message: *const u8,
155153
message_size: u32,
156154
) -> svm_result_t {
@@ -189,7 +187,7 @@ pub unsafe extern "C" fn svm_validate_deploy(
189187
#[must_use]
190188
#[no_mangle]
191189
pub unsafe extern "C" fn svm_validate_spawn(
192-
runtime: RuntimePtr,
190+
runtime: *mut c_void,
193191
message: *const u8,
194192
message_size: u32,
195193
) -> svm_result_t {
@@ -222,7 +220,7 @@ pub unsafe extern "C" fn svm_validate_spawn(
222220
#[must_use]
223221
#[no_mangle]
224222
pub unsafe extern "C" fn svm_validate_call(
225-
runtime: RuntimePtr,
223+
runtime: *mut c_void,
226224
message: *const u8,
227225
message_size: u32,
228226
) -> svm_result_t {
@@ -265,7 +263,7 @@ pub unsafe extern "C" fn svm_validate_call(
265263
#[must_use]
266264
#[no_mangle]
267265
pub unsafe extern "C" fn svm_deploy(
268-
runtime: RuntimePtr,
266+
runtime: *mut c_void,
269267
envelope: *const u8,
270268
message: *const u8,
271269
message_size: u32,
@@ -312,7 +310,7 @@ pub unsafe extern "C" fn svm_deploy(
312310
#[must_use]
313311
#[no_mangle]
314312
pub unsafe extern "C" fn svm_spawn(
315-
runtime: RuntimePtr,
313+
runtime: *mut c_void,
316314
envelope: *const u8,
317315
message: *const u8,
318316
message_size: u32,
@@ -363,7 +361,7 @@ pub unsafe extern "C" fn svm_spawn(
363361
#[must_use]
364362
#[no_mangle]
365363
pub unsafe extern "C" fn svm_verify(
366-
runtime: RuntimePtr,
364+
runtime: *mut c_void,
367365
envelope: *const u8,
368366
message: *const u8,
369367
message_size: u32,
@@ -411,7 +409,7 @@ pub unsafe extern "C" fn svm_verify(
411409
#[must_use]
412410
#[no_mangle]
413411
pub unsafe extern "C" fn svm_call(
414-
runtime: RuntimePtr,
412+
runtime: *mut c_void,
415413
envelope: *const u8,
416414
message: *const u8,
417415
message_size: u32,
@@ -448,7 +446,7 @@ pub unsafe extern "C" fn svm_call(
448446
///
449447
#[must_use]
450448
#[no_mangle]
451-
pub unsafe extern "C" fn svm_uncommitted_changes(runtime_ptr: RuntimePtr) -> svm_result_t {
449+
pub unsafe extern "C" fn svm_uncommitted_changes(runtime_ptr: *mut c_void) -> svm_result_t {
452450
catch_unwind_or_fail(|| {
453451
let runtime = get_runtime(runtime_ptr);
454452
if runtime.has_uncommitted_changes()? {
@@ -463,7 +461,7 @@ pub unsafe extern "C" fn svm_uncommitted_changes(runtime_ptr: RuntimePtr) -> svm
463461
#[must_use]
464462
#[no_mangle]
465463
pub unsafe extern "C" fn svm_layer_info(
466-
runtime_ptr: RuntimePtr,
464+
runtime_ptr: *mut c_void,
467465
hash: *mut u8,
468466
layer: *mut u64,
469467
) -> svm_result_t {
@@ -481,7 +479,7 @@ pub unsafe extern "C" fn svm_layer_info(
481479
/// Undos all changes after the given layer.
482480
#[must_use]
483481
#[no_mangle]
484-
pub unsafe extern "C" fn svm_rewind(runtime_ptr: RuntimePtr, layer_id: u64) -> svm_result_t {
482+
pub unsafe extern "C" fn svm_rewind(runtime_ptr: *mut c_void, layer_id: u64) -> svm_result_t {
485483
catch_unwind_or_fail(|| {
486484
get_runtime(runtime_ptr).rewind(Layer(layer_id))?;
487485
svm_result_t::OK
@@ -491,7 +489,7 @@ pub unsafe extern "C" fn svm_rewind(runtime_ptr: RuntimePtr, layer_id: u64) -> s
491489
/// Commits all written data to persistent storage.
492490
#[must_use]
493491
#[no_mangle]
494-
pub unsafe extern "C" fn svm_commit(runtime_ptr: RuntimePtr) -> svm_result_t {
492+
pub unsafe extern "C" fn svm_commit(runtime_ptr: *mut c_void) -> svm_result_t {
495493
catch_unwind_or_fail(|| {
496494
get_runtime(runtime_ptr).commit()?;
497495
svm_result_t::OK
@@ -523,7 +521,7 @@ impl svm_account {
523521
#[must_use]
524522
#[no_mangle]
525523
pub unsafe extern "C" fn svm_get_account(
526-
runtime_ptr: RuntimePtr,
524+
runtime_ptr: *mut c_void,
527525
account_addr: *const u8,
528526
account: *mut svm_account,
529527
) -> svm_result_t {
@@ -548,7 +546,7 @@ pub unsafe extern "C" fn svm_get_account(
548546
#[no_mangle]
549547
#[must_use]
550548
pub unsafe extern "C" fn svm_create_account(
551-
runtime_ptr: RuntimePtr,
549+
runtime_ptr: *mut c_void,
552550
addr: *const u8,
553551
balance: u64,
554552
counter_upper_bits: u64,
@@ -568,7 +566,7 @@ pub unsafe extern "C" fn svm_create_account(
568566
#[no_mangle]
569567
#[must_use]
570568
pub unsafe extern "C" fn svm_increase_balance(
571-
runtime_ptr: RuntimePtr,
569+
runtime_ptr: *mut c_void,
572570
addr: *const u8,
573571
additional_balance: u64,
574572
) -> svm_result_t {
@@ -605,7 +603,7 @@ pub unsafe extern "C" fn svm_transfer(
605603
}
606604

607605
unsafe fn svm_runtime_action<F, C>(
608-
runtime_ptr: RuntimePtr,
606+
runtime_ptr: *mut c_void,
609607
envelope: *const u8,
610608
message: *const u8,
611609
message_size: u32,
@@ -632,7 +630,7 @@ where
632630
}
633631

634632
unsafe fn svm_validate<F>(
635-
runtime_ptr: RuntimePtr,
633+
runtime_ptr: *mut c_void,
636634
message: *const u8,
637635
message_size: u32,
638636
validate_f: F,
@@ -658,7 +656,7 @@ where
658656
})
659657
}
660658

661-
unsafe fn get_runtime(runtime_ptr: RuntimePtr) -> &'static mut Runtime {
659+
unsafe fn get_runtime(runtime_ptr: *mut c_void) -> &'static mut Runtime {
662660
RUNTIME_TRACKER
663661
.get(runtime_ptr)
664662
.expect("The given runtime pointer doesn't point to a valid runtime.")

0 commit comments

Comments
 (0)