From 0a442311a8d8c35810fd6a8e64fbe77a709a971b Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 29 Nov 2023 19:21:41 +0100 Subject: [PATCH] Add optional argument names to all extern "C" fn types --- internal/api/bindings.h | 114 +++++++++++++++++++------------------- libwasmvm/bindings.h | 114 +++++++++++++++++++------------------- libwasmvm/src/api.rs | 20 +++---- libwasmvm/src/db.rs | 50 ++++++++--------- libwasmvm/src/iterator.rs | 42 +++++++------- libwasmvm/src/querier.rs | 12 ++-- libwasmvm/src/vtables.rs | 12 ++-- 7 files changed, 182 insertions(+), 182 deletions(-) diff --git a/internal/api/bindings.h b/internal/api/bindings.h index bf03c9e24..ff919d36b 100644 --- a/internal/api/bindings.h +++ b/internal/api/bindings.h @@ -255,22 +255,22 @@ typedef struct iterator_t { } iterator_t; typedef struct IteratorVtable { - int32_t (*next)(struct iterator_t, - struct gas_meter_t*, - uint64_t*, - struct UnmanagedVector*, - struct UnmanagedVector*, - struct UnmanagedVector*); - int32_t (*next_key)(struct iterator_t, - struct gas_meter_t*, - uint64_t*, - struct UnmanagedVector*, - struct UnmanagedVector*); - int32_t (*next_value)(struct iterator_t, - struct gas_meter_t*, - uint64_t*, - struct UnmanagedVector*, - struct UnmanagedVector*); + int32_t (*next)(struct iterator_t iterator, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct UnmanagedVector *key_out, + struct UnmanagedVector *value_out, + struct UnmanagedVector *err_msg_out); + int32_t (*next_key)(struct iterator_t iterator, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct UnmanagedVector *key_out, + struct UnmanagedVector *err_msg_out); + int32_t (*next_value)(struct iterator_t iterator, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct UnmanagedVector *value_out, + struct UnmanagedVector *err_msg_out); } IteratorVtable; typedef struct GoIter { @@ -280,31 +280,31 @@ typedef struct GoIter { } GoIter; typedef struct DbVtable { - int32_t (*read_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*); - int32_t (*write_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct U8SliceView, - struct UnmanagedVector*); - int32_t (*remove_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct UnmanagedVector*); - int32_t (*scan_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct U8SliceView, - int32_t, - struct GoIter*, - struct UnmanagedVector*); + int32_t (*read_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView key, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out); + int32_t (*write_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView key, + struct U8SliceView value, + struct UnmanagedVector *err_msg_out); + int32_t (*remove_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView key, + struct UnmanagedVector *err_msg_out); + int32_t (*scan_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView start, + struct U8SliceView end, + int32_t order, + struct GoIter *iterator_out, + struct UnmanagedVector *err_msg_out); } DbVtable; typedef struct Db { @@ -318,16 +318,16 @@ typedef struct api_t { } api_t; typedef struct GoApiVtable { - int32_t (*humanize_address)(const struct api_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*, - uint64_t*); - int32_t (*canonicalize_address)(const struct api_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*, - uint64_t*); + int32_t (*humanize_address)(const struct api_t *api, + struct U8SliceView input, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out, + uint64_t *gas_used); + int32_t (*canonicalize_address)(const struct api_t *api, + struct U8SliceView input, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out, + uint64_t *gas_used); } GoApiVtable; typedef struct GoApi { @@ -340,12 +340,12 @@ typedef struct querier_t { } querier_t; typedef struct QuerierVtable { - int32_t (*query_external)(const struct querier_t*, - uint64_t, - uint64_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*); + int32_t (*query_external)(const struct querier_t *querier, + uint64_t gas_limit, + uint64_t *gas_used, + struct U8SliceView request, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out); } QuerierVtable; typedef struct GoQuerier { diff --git a/libwasmvm/bindings.h b/libwasmvm/bindings.h index bf03c9e24..ff919d36b 100644 --- a/libwasmvm/bindings.h +++ b/libwasmvm/bindings.h @@ -255,22 +255,22 @@ typedef struct iterator_t { } iterator_t; typedef struct IteratorVtable { - int32_t (*next)(struct iterator_t, - struct gas_meter_t*, - uint64_t*, - struct UnmanagedVector*, - struct UnmanagedVector*, - struct UnmanagedVector*); - int32_t (*next_key)(struct iterator_t, - struct gas_meter_t*, - uint64_t*, - struct UnmanagedVector*, - struct UnmanagedVector*); - int32_t (*next_value)(struct iterator_t, - struct gas_meter_t*, - uint64_t*, - struct UnmanagedVector*, - struct UnmanagedVector*); + int32_t (*next)(struct iterator_t iterator, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct UnmanagedVector *key_out, + struct UnmanagedVector *value_out, + struct UnmanagedVector *err_msg_out); + int32_t (*next_key)(struct iterator_t iterator, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct UnmanagedVector *key_out, + struct UnmanagedVector *err_msg_out); + int32_t (*next_value)(struct iterator_t iterator, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct UnmanagedVector *value_out, + struct UnmanagedVector *err_msg_out); } IteratorVtable; typedef struct GoIter { @@ -280,31 +280,31 @@ typedef struct GoIter { } GoIter; typedef struct DbVtable { - int32_t (*read_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*); - int32_t (*write_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct U8SliceView, - struct UnmanagedVector*); - int32_t (*remove_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct UnmanagedVector*); - int32_t (*scan_db)(struct db_t*, - struct gas_meter_t*, - uint64_t*, - struct U8SliceView, - struct U8SliceView, - int32_t, - struct GoIter*, - struct UnmanagedVector*); + int32_t (*read_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView key, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out); + int32_t (*write_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView key, + struct U8SliceView value, + struct UnmanagedVector *err_msg_out); + int32_t (*remove_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView key, + struct UnmanagedVector *err_msg_out); + int32_t (*scan_db)(struct db_t *db, + struct gas_meter_t *gas_meter, + uint64_t *gas_used, + struct U8SliceView start, + struct U8SliceView end, + int32_t order, + struct GoIter *iterator_out, + struct UnmanagedVector *err_msg_out); } DbVtable; typedef struct Db { @@ -318,16 +318,16 @@ typedef struct api_t { } api_t; typedef struct GoApiVtable { - int32_t (*humanize_address)(const struct api_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*, - uint64_t*); - int32_t (*canonicalize_address)(const struct api_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*, - uint64_t*); + int32_t (*humanize_address)(const struct api_t *api, + struct U8SliceView input, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out, + uint64_t *gas_used); + int32_t (*canonicalize_address)(const struct api_t *api, + struct U8SliceView input, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out, + uint64_t *gas_used); } GoApiVtable; typedef struct GoApi { @@ -340,12 +340,12 @@ typedef struct querier_t { } querier_t; typedef struct QuerierVtable { - int32_t (*query_external)(const struct querier_t*, - uint64_t, - uint64_t*, - struct U8SliceView, - struct UnmanagedVector*, - struct UnmanagedVector*); + int32_t (*query_external)(const struct querier_t *querier, + uint64_t gas_limit, + uint64_t *gas_used, + struct U8SliceView request, + struct UnmanagedVector *result_out, + struct UnmanagedVector *err_msg_out); } QuerierVtable; typedef struct GoQuerier { diff --git a/libwasmvm/src/api.rs b/libwasmvm/src/api.rs index b1784d8e0..1efc5b286 100644 --- a/libwasmvm/src/api.rs +++ b/libwasmvm/src/api.rs @@ -18,20 +18,20 @@ pub struct api_t { pub struct GoApiVtable { pub humanize_address: Option< extern "C" fn( - *const api_t, - U8SliceView, - *mut UnmanagedVector, // human output - *mut UnmanagedVector, // error message output - *mut u64, + api: *const api_t, + input: U8SliceView, + result_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, + gas_used: *mut u64, ) -> i32, >, pub canonicalize_address: Option< extern "C" fn( - *const api_t, - U8SliceView, - *mut UnmanagedVector, // canonical output - *mut UnmanagedVector, // error message output - *mut u64, + api: *const api_t, + input: U8SliceView, + result_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, + gas_used: *mut u64, ) -> i32, >, } diff --git a/libwasmvm/src/db.rs b/libwasmvm/src/db.rs index f762c92ed..b67651d61 100644 --- a/libwasmvm/src/db.rs +++ b/libwasmvm/src/db.rs @@ -16,31 +16,31 @@ pub struct db_t { pub struct DbVtable { pub read_db: Option< extern "C" fn( - *mut db_t, - *mut gas_meter_t, - *mut u64, - U8SliceView, - *mut UnmanagedVector, // result output - *mut UnmanagedVector, // error message output + db: *mut db_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + key: U8SliceView, + result_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, pub write_db: Option< extern "C" fn( - *mut db_t, - *mut gas_meter_t, - *mut u64, - U8SliceView, - U8SliceView, - *mut UnmanagedVector, // error message output + db: *mut db_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + key: U8SliceView, + value: U8SliceView, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, pub remove_db: Option< extern "C" fn( - *mut db_t, - *mut gas_meter_t, - *mut u64, - U8SliceView, - *mut UnmanagedVector, // error message output + db: *mut db_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + key: U8SliceView, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, // order -> Ascending = 1, Descending = 2 @@ -48,14 +48,14 @@ pub struct DbVtable { // Since we have the pointer in rust already, we must set that manually pub scan_db: Option< extern "C" fn( - *mut db_t, - *mut gas_meter_t, - *mut u64, - U8SliceView, - U8SliceView, - i32, - *mut GoIter, - *mut UnmanagedVector, // error message output + db: *mut db_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + start: U8SliceView, + end: U8SliceView, + order: i32, + iterator_out: *mut GoIter, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, } diff --git a/libwasmvm/src/iterator.rs b/libwasmvm/src/iterator.rs index 27cef5c28..46fd237bc 100644 --- a/libwasmvm/src/iterator.rs +++ b/libwasmvm/src/iterator.rs @@ -22,30 +22,30 @@ pub struct iterator_t { pub struct IteratorVtable { pub next: Option< extern "C" fn( - iterator_t, - *mut gas_meter_t, - *mut u64, - *mut UnmanagedVector, // key output - *mut UnmanagedVector, // value output - *mut UnmanagedVector, // error message output + iterator: iterator_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + key_out: *mut UnmanagedVector, + value_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, pub next_key: Option< extern "C" fn( - iterator_t, - *mut gas_meter_t, - *mut u64, - *mut UnmanagedVector, // key output - *mut UnmanagedVector, // error message output + iterator: iterator_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + key_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, pub next_value: Option< extern "C" fn( - iterator_t, - *mut gas_meter_t, - *mut u64, - *mut UnmanagedVector, // value output - *mut UnmanagedVector, // error message output + iterator: iterator_t, + gas_meter: *mut gas_meter_t, + gas_used: *mut u64, + value_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, } @@ -141,11 +141,11 @@ impl GoIter { fn next_key_or_val( &mut self, next: extern "C" fn( - iterator_t, - *mut gas_meter_t, - *mut u64, - *mut UnmanagedVector, // output - *mut UnmanagedVector, // error message output + iterator: iterator_t, + gas_meter: *mut gas_meter_t, + gas_limit: *mut u64, + result_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, ) -> i32, ) -> BackendResult>> { let mut output = UnmanagedVector::default(); diff --git a/libwasmvm/src/querier.rs b/libwasmvm/src/querier.rs index ba40faabf..f0d2f7b2a 100644 --- a/libwasmvm/src/querier.rs +++ b/libwasmvm/src/querier.rs @@ -18,12 +18,12 @@ pub struct QuerierVtable { // We return errors through the return buffer, but may return non-zero error codes on panic pub query_external: Option< extern "C" fn( - *const querier_t, - u64, - *mut u64, - U8SliceView, - *mut UnmanagedVector, // result output - *mut UnmanagedVector, // error message output + querier: *const querier_t, + gas_limit: u64, + gas_used: *mut u64, + request: U8SliceView, + result_out: *mut UnmanagedVector, + err_msg_out: *mut UnmanagedVector, ) -> i32, >, } diff --git a/libwasmvm/src/vtables.rs b/libwasmvm/src/vtables.rs index 642021874..bd16517d5 100644 --- a/libwasmvm/src/vtables.rs +++ b/libwasmvm/src/vtables.rs @@ -21,12 +21,12 @@ /// pub struct IteratorVtable { /// pub next: Option< /// extern "C" fn( -/// iterator_t, -/// *mut gas_meter_t, -/// *mut u64, -/// *mut UnmanagedVector, // key output -/// *mut UnmanagedVector, // value output -/// *mut UnmanagedVector, // error message output +/// iterator: iterator_t, +/// gas_meter: *mut gas_meter_t, +/// gas_used: *mut u64, +/// key_out: *mut UnmanagedVector, +/// value_out: *mut UnmanagedVector, +/// err_msg_out: *mut UnmanagedVector, /// ) -> i32, /// >, /// // ...