Skip to content

Commit

Permalink
Add optional argument names to all extern "C" fn types
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Nov 29, 2023
1 parent 589ea5a commit 0a44231
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 182 deletions.
114 changes: 57 additions & 57 deletions internal/api/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
114 changes: 57 additions & 57 deletions libwasmvm/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions libwasmvm/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
>,
}
Expand Down
50 changes: 25 additions & 25 deletions libwasmvm/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,46 @@ 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
// Note: we cannot set gas_meter on the returned GoIter due to cgo memory safety.
// 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,
>,
}
Expand Down
Loading

0 comments on commit 0a44231

Please sign in to comment.