From ccd7e848f6bb50492afc2426663f9a4d36e03a3f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 27 Sep 2024 16:35:27 +0200 Subject: [PATCH] WASM ABI: Strip leading underscore from syscall names (#1705) --- .../bindings-csharp/Runtime/Internal/FFI.cs | 35 ++++---- .../Runtime/Internal/IReducer.cs | 2 +- .../Runtime/Internal/ITable.cs | 16 ++-- .../Runtime/Internal/Module.cs | 4 +- crates/bindings-csharp/Runtime/Log.cs | 2 +- .../bindings-csharp/Runtime/LogStopwatch.cs | 4 +- crates/bindings-csharp/Runtime/bindings.c | 34 ++++---- .../Runtime/build/SpacetimeDB.Runtime.targets | 26 +++--- crates/bindings-sys/src/lib.rs | 80 +++++++++---------- crates/bindings/src/log_stopwatch.rs | 4 +- crates/bindings/src/rt.rs | 4 +- crates/cli/src/subcommands/generate/mod.rs | 4 +- .../core/src/host/wasmtime/wasmtime_module.rs | 2 +- 13 files changed, 107 insertions(+), 110 deletions(-) diff --git a/crates/bindings-csharp/Runtime/Internal/FFI.cs b/crates/bindings-csharp/Runtime/Internal/FFI.cs index 444a90b6c2..96cd1d543e 100644 --- a/crates/bindings-csharp/Runtime/Internal/FFI.cs +++ b/crates/bindings-csharp/Runtime/Internal/FFI.cs @@ -115,26 +115,23 @@ public readonly record struct RowIter(uint Handle) } [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _table_id_from_name( + public static partial CheckedStatus table_id_from_name( [In] byte[] name, uint name_len, out TableId out_ ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _datastore_table_row_count( - TableId table_id, - out ulong out_ - ); + public static partial CheckedStatus datastore_table_row_count(TableId table_id, out ulong out_); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _datastore_table_scan_bsatn( + public static partial CheckedStatus datastore_table_scan_bsatn( TableId table_id, out RowIter out_ ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _iter_by_col_eq( + public static partial CheckedStatus iter_by_col_eq( TableId table_id, ColId col_id, [In] byte[] value, @@ -143,14 +140,14 @@ out RowIter out_ ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _datastore_insert_bsatn( + public static partial CheckedStatus datastore_insert_bsatn( TableId table_id, Span row, ref uint row_len ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _delete_by_col_eq( + public static partial CheckedStatus delete_by_col_eq( TableId table_id, ColId col_id, [In] byte[] value, @@ -159,7 +156,7 @@ out uint out_ ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _iter_start_filtered( + public static partial CheckedStatus iter_start_filtered( TableId table_id, [In] byte[] filter, uint filter_len, @@ -167,17 +164,17 @@ out RowIter out_ ); [LibraryImport(StdbNamespace)] - public static partial Errno _row_iter_bsatn_advance( + public static partial Errno row_iter_bsatn_advance( RowIter iter_handle, [MarshalUsing(CountElementName = nameof(buffer_len))] [Out] byte[] buffer, ref uint buffer_len ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _row_iter_bsatn_close(RowIter iter_handle); + public static partial CheckedStatus row_iter_bsatn_close(RowIter iter_handle); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _datastore_delete_all_by_eq_bsatn( + public static partial CheckedStatus datastore_delete_all_by_eq_bsatn( TableId table_id, [In] byte[] relation, uint relation_len, @@ -185,7 +182,7 @@ out uint out_ ); [LibraryImport(StdbNamespace)] - public static partial void _volatile_nonatomic_schedule_immediate( + public static partial void volatile_nonatomic_schedule_immediate( [In] byte[] name, uint name_len, [In] byte[] args, @@ -203,7 +200,7 @@ public enum LogLevel : byte } [LibraryImport(StdbNamespace)] - public static partial void _console_log( + public static partial void console_log( LogLevel level, [In] byte[] target, uint target_len, @@ -215,14 +212,14 @@ uint message_len ); [LibraryImport(StdbNamespace)] - public static partial Errno _bytes_source_read( + public static partial Errno bytes_source_read( BytesSource source, Span buffer, ref uint buffer_len ); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _bytes_sink_write( + public static partial CheckedStatus bytes_sink_write( BytesSink sink, ReadOnlySpan buffer, ref uint buffer_len @@ -254,8 +251,8 @@ internal static class ConsoleTimerIdMarshaller } [LibraryImport(StdbNamespace)] - public static partial ConsoleTimerId _console_timer_start([In] byte[] name, uint name_len); + public static partial ConsoleTimerId console_timer_start([In] byte[] name, uint name_len); [LibraryImport(StdbNamespace)] - public static partial CheckedStatus _console_timer_end(ConsoleTimerId stopwatch_id); + public static partial CheckedStatus console_timer_end(ConsoleTimerId stopwatch_id); } diff --git a/crates/bindings-csharp/Runtime/Internal/IReducer.cs b/crates/bindings-csharp/Runtime/Internal/IReducer.cs index 3624c06f6e..0a4f6fe75c 100644 --- a/crates/bindings-csharp/Runtime/Internal/IReducer.cs +++ b/crates/bindings-csharp/Runtime/Internal/IReducer.cs @@ -17,7 +17,7 @@ public static void VolatileNonatomicScheduleImmediate(string name, MemoryStream var name_bytes = Encoding.UTF8.GetBytes(name); var args_bytes = args.ToArray(); - FFI._volatile_nonatomic_schedule_immediate( + FFI.volatile_nonatomic_schedule_immediate( name_bytes, (uint)name_bytes.Length, args_bytes, diff --git a/crates/bindings-csharp/Runtime/Internal/ITable.cs b/crates/bindings-csharp/Runtime/Internal/ITable.cs index f5d820ee34..d8f496648b 100644 --- a/crates/bindings-csharp/Runtime/Internal/ITable.cs +++ b/crates/bindings-csharp/Runtime/Internal/ITable.cs @@ -37,7 +37,7 @@ public bool MoveNext() while (true) { buffer_len = (uint)buffer.Length; - var ret = FFI._row_iter_bsatn_advance(handle, buffer, ref buffer_len); + var ret = FFI.row_iter_bsatn_advance(handle, buffer, ref buffer_len); if (ret == Errno.EXHAUSTED) { handle = FFI.RowIter.INVALID; @@ -74,7 +74,7 @@ public void Dispose() { if (handle != FFI.RowIter.INVALID) { - FFI._row_iter_bsatn_close(handle); + FFI.row_iter_bsatn_close(handle); handle = FFI.RowIter.INVALID; // Avoid running ~RowIter if Dispose was executed successfully. GC.SuppressFinalize(this); @@ -120,20 +120,20 @@ public IEnumerable Parse() private class RawTableIter(FFI.TableId tableId) : RawTableIterBase { protected override void IterStart(out FFI.RowIter handle) => - FFI._datastore_table_scan_bsatn(tableId, out handle); + FFI.datastore_table_scan_bsatn(tableId, out handle); } private class RawTableIterFiltered(FFI.TableId tableId, byte[] filterBytes) : RawTableIterBase { protected override void IterStart(out FFI.RowIter handle) => - FFI._iter_start_filtered(tableId, filterBytes, (uint)filterBytes.Length, out handle); + FFI.iter_start_filtered(tableId, filterBytes, (uint)filterBytes.Length, out handle); } private class RawTableIterByColEq(FFI.TableId tableId, FFI.ColId colId, byte[] value) : RawTableIterBase { protected override void IterStart(out FFI.RowIter handle) => - FFI._iter_by_col_eq(tableId, colId, value, (uint)value.Length, out handle); + FFI.iter_by_col_eq(tableId, colId, value, (uint)value.Length, out handle); } // Note: this must be Lazy to ensure that we don't try to get the tableId during startup, before the module is initialized. @@ -141,7 +141,7 @@ protected override void IterStart(out FFI.RowIter handle) => new(() => { var name_bytes = System.Text.Encoding.UTF8.GetBytes(typeof(View).Name); - FFI._table_id_from_name(name_bytes, (uint)name_bytes.Length, out var out_); + FFI.table_id_from_name(name_bytes, (uint)name_bytes.Length, out var out_); return out_; }); @@ -159,7 +159,7 @@ protected static T Insert(T row) // Insert the row. var bytes = IStructuralReadWrite.ToBytes(row); var bytes_len = (uint)bytes.Length; - FFI._datastore_insert_bsatn(tableId, bytes, ref bytes_len); + FFI.datastore_insert_bsatn(tableId, bytes, ref bytes_len); // Write back any generated column values. using var stream = new MemoryStream(bytes, 0, (int)bytes_len); @@ -190,7 +190,7 @@ public static ColEq Where(ushort colId, TCol colValue, TColRW rw) public bool Delete() { - FFI._delete_by_col_eq(tableId, colId, value, (uint)value.Length, out var out_); + FFI.delete_by_col_eq(tableId, colId, value, (uint)value.Length, out var out_); return out_ > 0; } diff --git a/crates/bindings-csharp/Runtime/Internal/Module.cs b/crates/bindings-csharp/Runtime/Internal/Module.cs index 5a4452fe60..109b9bb096 100644 --- a/crates/bindings-csharp/Runtime/Internal/Module.cs +++ b/crates/bindings-csharp/Runtime/Internal/Module.cs @@ -121,7 +121,7 @@ private static byte[] Consume(this BytesSource source) // Write into the spare capacity of the buffer. var spare = buffer.AsSpan((int)written); var buf_len = (uint)spare.Length; - var ret = FFI._bytes_source_read(source, spare, ref buf_len); + var ret = FFI.bytes_source_read(source, spare, ref buf_len); written += buf_len; switch (ret) { @@ -155,7 +155,7 @@ private static void Write(this BytesSink sink, byte[] bytes) { var written = (uint)bytes.Length; var buffer = bytes.AsSpan((int)start); - FFI._bytes_sink_write(sink, buffer, ref written); + FFI.bytes_sink_write(sink, buffer, ref written); start += written; } } diff --git a/crates/bindings-csharp/Runtime/Log.cs b/crates/bindings-csharp/Runtime/Log.cs index 400170c46c..757157c0e4 100644 --- a/crates/bindings-csharp/Runtime/Log.cs +++ b/crates/bindings-csharp/Runtime/Log.cs @@ -165,7 +165,7 @@ uint lineNumber var filename_bytes = Encoding.UTF8.GetBytes(filename); var text_bytes = Encoding.UTF8.GetBytes(text); - FFI._console_log( + FFI.console_log( level, target_bytes, (uint)target_bytes.Length, diff --git a/crates/bindings-csharp/Runtime/LogStopwatch.cs b/crates/bindings-csharp/Runtime/LogStopwatch.cs index effb2d5785..4804e1e77a 100644 --- a/crates/bindings-csharp/Runtime/LogStopwatch.cs +++ b/crates/bindings-csharp/Runtime/LogStopwatch.cs @@ -11,7 +11,7 @@ public sealed class LogStopwatch : IDisposable public LogStopwatch(string name) { var name_bytes = Encoding.UTF8.GetBytes(name); - StopwatchId = FFI._console_timer_start(name_bytes, (uint)name_bytes.Length); + StopwatchId = FFI.console_timer_start(name_bytes, (uint)name_bytes.Length); } void IDisposable.Dispose() @@ -24,7 +24,7 @@ void IDisposable.Dispose() public void End() { - FFI._console_timer_end(StopwatchId); + FFI.console_timer_end(StopwatchId); WasStopped = true; } } diff --git a/crates/bindings-csharp/Runtime/bindings.c b/crates/bindings-csharp/Runtime/bindings.c index 1ce9b03a09..561aeefc16 100644 --- a/crates/bindings-csharp/Runtime/bindings.c +++ b/crates/bindings-csharp/Runtime/bindings.c @@ -36,54 +36,54 @@ OPAQUE_TYPEDEF(ConsoleTimerId, uint32_t); #define IMPORT(ret, name, params, args) STDB_EXTERN(name) ret name params; #endif -IMPORT(void, _console_log, +IMPORT(void, console_log, (LogLevel level, const uint8_t* target_ptr, uint32_t target_len, const uint8_t* filename_ptr, uint32_t filename_len, uint32_t line_number, const uint8_t* message_ptr, uint32_t message_len), (level, target_ptr, target_len, filename_ptr, filename_len, line_number, message_ptr, message_len)); -IMPORT(Status, _table_id_from_name, +IMPORT(Status, table_id_from_name, (const uint8_t* name, uint32_t name_len, TableId* id), (name, name_len, id)); -IMPORT(Status, _datastore_table_row_count, +IMPORT(Status, datastore_table_row_count, (TableId table_id, uint64_t* count), (table_id, count)); -IMPORT(Status, _datastore_table_scan_bsatn, (TableId table_id, RowIter* iter), +IMPORT(Status, datastore_table_scan_bsatn, (TableId table_id, RowIter* iter), (table_id, iter)); -IMPORT(Status, _iter_by_col_eq, +IMPORT(Status, iter_by_col_eq, (TableId table_id, ColId col_id, const uint8_t* value, uint32_t value_len, RowIter* iter), (table_id, col_id, value, value_len, iter)); -IMPORT(Status, _datastore_insert_bsatn, (TableId table_id, const uint8_t* row_ptr, size_t* row_len_ptr), +IMPORT(Status, datastore_insert_bsatn, (TableId table_id, const uint8_t* row_ptr, size_t* row_len_ptr), (table_id, row_ptr, row_len_ptr)); -IMPORT(Status, _delete_by_col_eq, +IMPORT(Status, delete_by_col_eq, (TableId table_id, ColId col_id, const uint8_t* value, uint32_t value_len, uint32_t* num_deleted), (table_id, col_id, value, value_len, num_deleted)); -IMPORT(Status, _iter_start_filtered, +IMPORT(Status, iter_start_filtered, (TableId table_id, const uint8_t* filter, uint32_t filter_len, RowIter* iter), (table_id, filter, filter_len, iter)); -IMPORT(int16_t, _row_iter_bsatn_advance, +IMPORT(int16_t, row_iter_bsatn_advance, (RowIter iter, uint8_t* buffer_ptr, size_t* buffer_len_ptr), (iter, buffer_ptr, buffer_len_ptr)); -IMPORT(uint16_t, _row_iter_bsatn_close, (RowIter iter), (iter)); -IMPORT(Status, _datastore_delete_all_by_eq_bsatn, +IMPORT(uint16_t, row_iter_bsatn_close, (RowIter iter), (iter)); +IMPORT(Status, datastore_delete_all_by_eq_bsatn, (TableId table_id, const uint8_t* rel_ptr, uint32_t rel_len, uint32_t* num_deleted), (table_id, rel_ptr, rel_len, num_deleted)); -IMPORT(void, _volatile_nonatomic_schedule_immediate, +IMPORT(void, volatile_nonatomic_schedule_immediate, (const uint8_t* name, size_t name_len, const uint8_t* args, size_t args_len), (name, name_len, args, args_len)); -IMPORT(int16_t, _bytes_source_read, (BytesSource source, uint8_t* buffer_ptr, size_t* buffer_len_ptr), +IMPORT(int16_t, bytes_source_read, (BytesSource source, uint8_t* buffer_ptr, size_t* buffer_len_ptr), (source, buffer_ptr, buffer_len_ptr)); -IMPORT(uint16_t, _bytes_sink_write, (BytesSink sink, const uint8_t* buffer_ptr, size_t* buffer_len_ptr), +IMPORT(uint16_t, bytes_sink_write, (BytesSink sink, const uint8_t* buffer_ptr, size_t* buffer_len_ptr), (sink, buffer_ptr, buffer_len_ptr)); -IMPORT(ConsoleTimerId, _console_timer_start, +IMPORT(ConsoleTimerId, console_timer_start, (const uint8_t* name, size_t name_len), (name, name_len)); -IMPORT(Status, _console_timer_end, +IMPORT(Status, console_timer_end, (ConsoleTimerId stopwatch_id), (stopwatch_id)); @@ -236,7 +236,7 @@ int32_t WASI_NAME(fd_write)(__wasi_fd_t fd, const __wasi_ciovec_t* iovs, // Note: this will produce ugly broken output, but there's not much we can // do about it until we have proper line-buffered WASI writer in the core. // It's better than nothing though. - _console_log((LogLevel){fd == STDERR_FILENO ? /*WARN*/ 1 : /*INFO*/ + console_log((LogLevel){fd == STDERR_FILENO ? /*WARN*/ 1 : /*INFO*/ 2}, CSTR("wasi"), CSTR(__FILE__), __LINE__, iovs[i].buf, iovs[i].buf_len); diff --git a/crates/bindings-csharp/Runtime/build/SpacetimeDB.Runtime.targets b/crates/bindings-csharp/Runtime/build/SpacetimeDB.Runtime.targets index b8ff3f8e54..cb1d087f30 100644 --- a/crates/bindings-csharp/Runtime/build/SpacetimeDB.Runtime.targets +++ b/crates/bindings-csharp/Runtime/build/SpacetimeDB.Runtime.targets @@ -3,19 +3,19 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/crates/bindings-sys/src/lib.rs b/crates/bindings-sys/src/lib.rs index 07f7dadaa2..52012a91f2 100644 --- a/crates/bindings-sys/src/lib.rs +++ b/crates/bindings-sys/src/lib.rs @@ -38,7 +38,7 @@ pub mod raw { /// /// - `NOT_IN_TRANSACTION`, when called outside of a transaction. /// - `NO_SUCH_TABLE`, when `name` is not the name of a table. - pub fn _table_id_from_name(name: *const u8, name_len: usize, out: *mut TableId) -> u16; + pub fn table_id_from_name(name: *const u8, name_len: usize, out: *mut TableId) -> u16; /// Queries the `index_id` associated with the given (index) `name` /// where `name` is the UTF-8 slice in WASM memory at `name_ptr[..name_len]`. @@ -58,7 +58,7 @@ pub mod raw { /// /// - `NOT_IN_TRANSACTION`, when called outside of a transaction. /// - `NO_SUCH_INDEX`, when `name` is not the name of an index. - pub fn _index_id_from_name(name_ptr: *const u8, name_len: usize, out: *mut IndexId) -> u16; + pub fn index_id_from_name(name_ptr: *const u8, name_len: usize, out: *mut IndexId) -> u16; /// Writes the number of rows currently in table identified by `table_id` to `out`. /// @@ -73,7 +73,7 @@ pub mod raw { /// /// - `NOT_IN_TRANSACTION`, when called outside of a transaction. /// - `NO_SUCH_TABLE`, when `table_id` is not a known ID of a table. - pub fn _datastore_table_row_count(table_id: TableId, out: *mut u64) -> u16; + pub fn datastore_table_row_count(table_id: TableId, out: *mut u64) -> u16; /// Starts iteration on each row, as BSATN-encoded, of a table identified by `table_id`. /// @@ -90,7 +90,7 @@ pub mod raw { /// /// - `NOT_IN_TRANSACTION`, when called outside of a transaction. /// - `NO_SUCH_TABLE`, when `table_id` is not a known ID of a table. - pub fn _datastore_table_scan_bsatn(table_id: TableId, out: *mut RowIter) -> u16; + pub fn datastore_table_scan_bsatn(table_id: TableId, out: *mut RowIter) -> u16; /// Finds all rows in the index identified by `index_id`, /// according to the: @@ -154,7 +154,7 @@ pub mod raw { /// Or when `rstart` or `rend` cannot be decoded to an `Bound` /// where the inner `AlgebraicValue`s are /// typed at the `prefix_elems + 1` `AlgebraicType` of the index's key type. - pub fn _datastore_btree_scan_bsatn( + pub fn datastore_btree_scan_bsatn( index_id: IndexId, prefix_ptr: *const u8, prefix_len: usize, @@ -181,7 +181,7 @@ pub mod raw { /// - `(val, val_len)` cannot be decoded to an `AlgebraicValue` /// typed at the `AlgebraicType` of the column, /// - `val + val_len` overflows a 64-bit integer - pub fn _iter_by_col_eq( + pub fn iter_by_col_eq( table_id: TableId, col_id: ColId, val: *const u8, @@ -206,7 +206,7 @@ pub mod raw { /// according to the `AlgebraicType` that the table's schema specifies for `col_id`. /// - `value + value_len` overflows a 64-bit integer /// - writing to `out` would overflow a 32-bit integer - pub fn _delete_by_col_eq( + pub fn delete_by_col_eq( table_id: TableId, col_id: ColId, value: *const u8, @@ -250,7 +250,7 @@ pub mod raw { /// Or when `rstart` or `rend` cannot be decoded to an `Bound` /// where the inner `AlgebraicValue`s are /// typed at the `prefix_elems + 1` `AlgebraicType` of the index's key type. - pub fn _datastore_delete_by_btree_scan_bsatn( + pub fn datastore_delete_by_btree_scan_bsatn( index_id: IndexId, prefix_ptr: *const u8, prefix_len: usize, @@ -288,7 +288,7 @@ pub mod raw { /// - `NO_SUCH_TABLE`, when `table_id` is not a known ID of a table. /// - `BSATN_DECODE_ERROR`, when `rel` cannot be decoded to `Vec` /// where each `ProductValue` is typed at the `ProductType` the table's schema specifies. - pub fn _datastore_delete_all_by_eq_bsatn( + pub fn datastore_delete_all_by_eq_bsatn( table_id: TableId, rel_ptr: *const u8, rel_len: usize, @@ -308,7 +308,7 @@ pub mod raw { /// - a table with the provided `table_id` doesn't exist /// - `(filter, filter_len)` doesn't decode to a filter expression /// - `filter + filter_len` overflows a 64-bit integer - pub fn _iter_start_filtered(table_id: TableId, filter: *const u8, filter_len: usize, out: *mut RowIter) -> u16; + pub fn iter_start_filtered(table_id: TableId, filter: *const u8, filter_len: usize, out: *mut RowIter) -> u16; /// Reads rows from the given iterator registered under `iter`. /// @@ -340,7 +340,7 @@ pub mod raw { /// - `BUFFER_TOO_SMALL`, when there are rows left but they cannot fit in `buffer`. /// When this occurs, `buffer_len` is set to the size of the next item in the iterator. /// To make progress, the caller should reallocate the buffer to at least that size and try again. - pub fn _row_iter_bsatn_advance(iter: RowIter, buffer_ptr: *mut u8, buffer_len_ptr: *mut usize) -> i16; + pub fn row_iter_bsatn_advance(iter: RowIter, buffer_ptr: *mut u8, buffer_len_ptr: *mut usize) -> i16; /// Destroys the iterator registered under `iter`. /// @@ -352,7 +352,7 @@ pub mod raw { /// Returns an error: /// /// - `NO_SUCH_ITER`, when `iter` is not a valid iterator. - pub fn _row_iter_bsatn_close(iter: RowIter) -> u16; + pub fn row_iter_bsatn_close(iter: RowIter) -> u16; /// Inserts a row into the table identified by `table_id`, /// where the row is read from the byte string `row = row_ptr[..row_len]` in WASM memory @@ -387,7 +387,7 @@ pub mod raw { /// typed at the `ProductType` the table's schema specifies. /// - `UNIQUE_ALREADY_EXISTS`, when inserting `row` would violate a unique constraint. /// - `SCHEDULE_AT_DELAY_TOO_LONG`, when the delay specified in the row was too long. - pub fn _datastore_insert_bsatn(table_id: TableId, row_ptr: *mut u8, row_len_ptr: *mut usize) -> u16; + pub fn datastore_insert_bsatn(table_id: TableId, row_ptr: *mut u8, row_len_ptr: *mut usize) -> u16; /// Schedules a reducer to be called asynchronously, nonatomically, /// and immediately on a best effort basis. @@ -399,7 +399,7 @@ pub mod raw { /// - `name` does not point to valid UTF-8 /// - `name + name_len` or `args + args_len` overflow a 64-bit integer #[cfg(feature = "unstable_abi")] - pub fn _volatile_nonatomic_schedule_immediate( + pub fn volatile_nonatomic_schedule_immediate( name: *const u8, name_len: usize, args: *const u8, @@ -424,7 +424,7 @@ pub mod raw { /// /// - `NO_SUCH_BYTES`, when `sink` is not a valid bytes sink. /// - `NO_SPACE`, when there is no room for more bytes in `sink`. - pub fn _bytes_sink_write(sink: BytesSink, buffer_ptr: *const u8, buffer_len_ptr: *mut usize) -> u16; + pub fn bytes_sink_write(sink: BytesSink, buffer_ptr: *const u8, buffer_len_ptr: *mut usize) -> u16; /// Reads bytes from `source`, registered in the host environment, /// and stores them in the memory pointed to by `buffer = buffer_ptr[..buffer_len]`. @@ -489,7 +489,7 @@ pub mod raw { /// // ... /// } /// ``` - pub fn _bytes_source_read(source: BytesSource, buffer_ptr: *mut u8, buffer_len_ptr: *mut usize) -> i16; + pub fn bytes_source_read(source: BytesSource, buffer_ptr: *mut u8, buffer_len_ptr: *mut usize) -> i16; /// Logs at `level` a `message` message occuring in `filename:line_number` /// with [`target`](target) being the module path at the `log!` invocation site. @@ -512,7 +512,7 @@ pub mod raw { /// - `message` is not NULL and `message_ptr[..message_len]` is not in bounds of WASM memory. /// /// [target]: https://docs.rs/log/latest/log/struct.Record.html#method.target - pub fn _console_log( + pub fn console_log( level: u8, target_ptr: *const u8, target_len: usize, @@ -534,7 +534,7 @@ pub mod raw { /// /// Traps if: /// - `name_ptr` is NULL or `name` is not in bounds of WASM memory. - pub fn _console_timer_start(name_ptr: *const u8, name_len: usize) -> u32; + pub fn console_timer_start(name_ptr: *const u8, name_len: usize) -> u32; /// End a timing span. /// @@ -550,7 +550,7 @@ pub mod raw { /// /// Returns an error: /// - `NO_SUCH_CONSOLE_TIMER`, when `timer_id` does not exist. - pub fn _console_timer_end(timer_id: u32) -> u16; + pub fn console_timer_end(timer_id: u32) -> u16; } /// What strategy does the database index use? @@ -565,17 +565,17 @@ pub mod raw { Hash = 1, } - /// The error log level. See [`_console_log`]. + /// The error log level. See [`console_log`]. pub const LOG_LEVEL_ERROR: u8 = 0; - /// The warn log level. See [`_console_log`]. + /// The warn log level. See [`console_log`]. pub const LOG_LEVEL_WARN: u8 = 1; - /// The info log level. See [`_console_log`]. + /// The info log level. See [`console_log`]. pub const LOG_LEVEL_INFO: u8 = 2; - /// The debug log level. See [`_console_log`]. + /// The debug log level. See [`console_log`]. pub const LOG_LEVEL_DEBUG: u8 = 3; - /// The trace log level. See [`_console_log`]. + /// The trace log level. See [`console_log`]. pub const LOG_LEVEL_TRACE: u8 = 4; - /// The panic log level. See [`_console_log`]. + /// The panic log level. See [`console_log`]. /// /// A panic level is emitted just before a fatal error causes the WASM module to trap. pub const LOG_LEVEL_PANIC: u8 = 101; @@ -743,7 +743,7 @@ unsafe fn call(f: impl FnOnce(*mut T) -> u16) -> Result { /// - `NO_SUCH_TABLE`, when `name` is not the name of a table. #[inline] pub fn table_id_from_name(name: &str) -> Result { - unsafe { call(|out| raw::_table_id_from_name(name.as_ptr(), name.len(), out)) } + unsafe { call(|out| raw::table_id_from_name(name.as_ptr(), name.len(), out)) } } /// Queries the `index_id` associated with the given (index) `name`. @@ -758,7 +758,7 @@ pub fn table_id_from_name(name: &str) -> Result { /// - `NO_SUCH_INDEX`, when `name` is not the name of an index. #[inline] pub fn index_id_from_name(name: &str) -> Result { - unsafe { call(|out| raw::_index_id_from_name(name.as_ptr(), name.len(), out)) } + unsafe { call(|out| raw::index_id_from_name(name.as_ptr(), name.len(), out)) } } /// Returns the number of rows currently in table identified by `table_id`. @@ -771,7 +771,7 @@ pub fn index_id_from_name(name: &str) -> Result { /// - `NO_SUCH_TABLE`, when `table_id` is not a known ID of a table. #[inline] pub fn datastore_table_row_count(table_id: TableId) -> Result { - unsafe { call(|out| raw::_datastore_table_row_count(table_id, out)) } + unsafe { call(|out| raw::datastore_table_row_count(table_id, out)) } } /// Finds all rows in the table identified by `table_id`, @@ -792,7 +792,7 @@ pub fn datastore_table_row_count(table_id: TableId) -> Result { /// typed at the `AlgebraicType` of the column #[inline] pub fn iter_by_col_eq(table_id: TableId, col_id: ColId, val: &[u8]) -> Result { - let raw = unsafe { call(|out| raw::_iter_by_col_eq(table_id, col_id, val.as_ptr(), val.len(), out)) }?; + let raw = unsafe { call(|out| raw::iter_by_col_eq(table_id, col_id, val.as_ptr(), val.len(), out)) }?; Ok(RowIter { raw }) } @@ -812,7 +812,7 @@ pub fn iter_by_col_eq(table_id: TableId, col_id: ColId, val: &[u8]) -> Result Result<&[u8], Errno> { let row_ptr = row.as_mut_ptr(); let row_len = &mut row.len(); - cvt(unsafe { raw::_datastore_insert_bsatn(table_id, row_ptr, row_len) }).map(|()| &row[..*row_len]) + cvt(unsafe { raw::datastore_insert_bsatn(table_id, row_ptr, row_len) }).map(|()| &row[..*row_len]) } /// Deletes all rows in the table identified by `table_id` @@ -829,7 +829,7 @@ pub fn insert(table_id: TableId, row: &mut [u8]) -> Result<&[u8], Errno> { /// - `col_id` does not identify a column of the table #[inline] pub fn delete_by_col_eq(table_id: TableId, col_id: ColId, value: &[u8]) -> Result { - unsafe { call(|out| raw::_delete_by_col_eq(table_id, col_id, value.as_ptr(), value.len(), out)) } + unsafe { call(|out| raw::delete_by_col_eq(table_id, col_id, value.as_ptr(), value.len(), out)) } } /// Deletes those rows, in the table identified by `table_id`, @@ -854,7 +854,7 @@ pub fn delete_by_col_eq(table_id: TableId, col_id: ColId, value: &[u8]) -> Resul /// where each `ProductValue` is typed at the `ProductType` the table's schema specifies. #[inline] pub fn datastore_delete_all_by_eq_bsatn(table_id: TableId, relation: &[u8]) -> Result { - unsafe { call(|out| raw::_datastore_delete_all_by_eq_bsatn(table_id, relation.as_ptr(), relation.len(), out)) } + unsafe { call(|out| raw::datastore_delete_all_by_eq_bsatn(table_id, relation.as_ptr(), relation.len(), out)) } } /// Starts iteration on each row, as BSATN-encoded, of a table identified by `table_id`. @@ -868,7 +868,7 @@ pub fn datastore_delete_all_by_eq_bsatn(table_id: TableId, relation: &[u8]) -> R /// - `NOT_IN_TRANSACTION`, when called outside of a transaction. /// - `NO_SUCH_TABLE`, when `table_id` is not a known ID of a table. pub fn datastore_table_scan_bsatn(table_id: TableId) -> Result { - let raw = unsafe { call(|out| raw::_datastore_table_scan_bsatn(table_id, out))? }; + let raw = unsafe { call(|out| raw::datastore_table_scan_bsatn(table_id, out))? }; Ok(RowIter { raw }) } @@ -930,7 +930,7 @@ pub fn datastore_btree_scan_bsatn( ) -> Result { let raw = unsafe { call(|out| { - raw::_datastore_btree_scan_bsatn( + raw::datastore_btree_scan_bsatn( index_id, prefix.as_ptr(), prefix.len(), @@ -978,7 +978,7 @@ pub fn datastore_delete_by_btree_scan_bsatn( ) -> Result { unsafe { call(|out| { - raw::_datastore_delete_by_btree_scan_bsatn( + raw::datastore_delete_by_btree_scan_bsatn( index_id, prefix.as_ptr(), prefix.len(), @@ -1000,7 +1000,7 @@ pub fn datastore_delete_by_btree_scan_bsatn( /// - `NO_SUCH_TABLE`, if `table_id` doesn't exist. #[inline] pub fn iter_filtered(table_id: TableId, filter: &[u8]) -> Result { - let raw = unsafe { call(|out| raw::_iter_start_filtered(table_id, filter.as_ptr(), filter.len(), out))? }; + let raw = unsafe { call(|out| raw::iter_start_filtered(table_id, filter.as_ptr(), filter.len(), out))? }; Ok(RowIter { raw }) } @@ -1039,7 +1039,7 @@ pub fn console_log( let opt_ptr = |b: Option<&str>| b.map_or(ptr::null(), |b| b.as_ptr()); let opt_len = |b: Option<&str>| b.map_or(0, |b| b.len()); unsafe { - raw::_console_log( + raw::console_log( level as u8, opt_ptr(target), opt_len(target), @@ -1059,7 +1059,7 @@ pub fn console_log( #[cfg(feature = "unstable_abi")] #[inline] pub fn volatile_nonatomic_schedule_immediate(name: &str, args: &[u8]) { - unsafe { raw::_volatile_nonatomic_schedule_immediate(name.as_ptr(), name.len(), args.as_ptr(), args.len()) } + unsafe { raw::volatile_nonatomic_schedule_immediate(name.as_ptr(), name.len(), args.as_ptr(), args.len()) } } pub struct RowIter { @@ -1076,7 +1076,7 @@ impl RowIter { loop { let buf_ptr = buf.spare_capacity_mut(); let mut buf_len = buf_ptr.len(); - let ret = unsafe { raw::_row_iter_bsatn_advance(self.raw, buf_ptr.as_mut_ptr().cast(), &mut buf_len) }; + let ret = unsafe { raw::row_iter_bsatn_advance(self.raw, buf_ptr.as_mut_ptr().cast(), &mut buf_len) }; if let -1 | 0 = ret { // SAFETY: `_row_iter_bsatn_advance` just wrote `buf_len` bytes into the end of `buf`. unsafe { buf.set_len(buf.len() + buf_len) }; @@ -1109,7 +1109,7 @@ impl Drop for RowIter { return; } unsafe { - raw::_row_iter_bsatn_close(self.raw); + raw::row_iter_bsatn_close(self.raw); } } } diff --git a/crates/bindings/src/log_stopwatch.rs b/crates/bindings/src/log_stopwatch.rs index b1081865a2..a7f0c7ece0 100644 --- a/crates/bindings/src/log_stopwatch.rs +++ b/crates/bindings/src/log_stopwatch.rs @@ -5,7 +5,7 @@ pub struct LogStopwatch { impl LogStopwatch { pub fn new(name: &str) -> Self { let name = name.as_bytes(); - let id = unsafe { spacetimedb_bindings_sys::raw::_console_timer_start(name.as_ptr(), name.len()) }; + let id = unsafe { spacetimedb_bindings_sys::raw::console_timer_start(name.as_ptr(), name.len()) }; Self { stopwatch_id: id } } @@ -17,7 +17,7 @@ impl LogStopwatch { impl std::ops::Drop for LogStopwatch { fn drop(&mut self) { unsafe { - spacetimedb_bindings_sys::raw::_console_timer_end(self.stopwatch_id); + spacetimedb_bindings_sys::raw::console_timer_end(self.stopwatch_id); } } } diff --git a/crates/bindings/src/rt.rs b/crates/bindings/src/rt.rs index 8113601cbb..05a76b2a06 100644 --- a/crates/bindings/src/rt.rs +++ b/crates/bindings/src/rt.rs @@ -528,7 +528,7 @@ fn read_bytes_source_into(source: BytesSource, buf: &mut Vec) { let spare_len = buf_ptr.len(); let mut buf_len = buf_ptr.len(); let buf_ptr = buf_ptr.as_mut_ptr().cast(); - let ret = unsafe { sys::raw::_bytes_source_read(source, buf_ptr, &mut buf_len) }; + let ret = unsafe { sys::raw::bytes_source_read(source, buf_ptr, &mut buf_len) }; if ret <= 0 { // SAFETY: `bytes_source_read` just appended `spare_len` bytes to `buf`. unsafe { buf.set_len(buf.len() + spare_len) }; @@ -554,7 +554,7 @@ fn read_bytes_source_into(source: BytesSource, buf: &mut Vec) { fn write_to_sink(sink: BytesSink, mut buf: &[u8]) { loop { let len = &mut buf.len(); - match unsafe { sys::raw::_bytes_sink_write(sink, buf.as_ptr(), len) } { + match unsafe { sys::raw::bytes_sink_write(sink, buf.as_ptr(), len) } { 0 => { // Set `buf` to remainder and bail if it's empty. (_, buf) = buf.split_at(*len); diff --git a/crates/cli/src/subcommands/generate/mod.rs b/crates/cli/src/subcommands/generate/mod.rs index f33fe4d33a..79d403a671 100644 --- a/crates/cli/src/subcommands/generate/mod.rs +++ b/crates/cli/src/subcommands/generate/mod.rs @@ -437,7 +437,7 @@ pub fn extract_descriptions(wasm_file: &Path) -> anyhow::Result { let module_name = &*format!("spacetime_{MODULE_ABI_MAJOR_VERSION}.0"); linker.func_wrap( module_name, - "_console_log", + "console_log", |mut caller: Caller<'_, WasmCtx>, _level: u32, _target_ptr: u32, @@ -452,7 +452,7 @@ pub fn extract_descriptions(wasm_file: &Path) -> anyhow::Result { println!("from wasm: {}", String::from_utf8_lossy(slice)); }, )?; - linker.func_wrap(module_name, "_bytes_sink_write", WasmCtx::bytes_sink_write)?; + linker.func_wrap(module_name, "bytes_sink_write", WasmCtx::bytes_sink_write)?; let instance = linker.instantiate(&mut store, &module)?; let memory = Mem::extract(&instance, &mut store)?; store.data_mut().mem = Some(memory); diff --git a/crates/core/src/host/wasmtime/wasmtime_module.rs b/crates/core/src/host/wasmtime/wasmtime_module.rs index 8013634173..9ecc9e8809 100644 --- a/crates/core/src/host/wasmtime/wasmtime_module.rs +++ b/crates/core/src/host/wasmtime/wasmtime_module.rs @@ -41,7 +41,7 @@ impl WasmtimeModule { const _: () = assert!(WasmtimeModule::IMPLEMENTED_ABI.major == spacetimedb_lib::MODULE_ABI_MAJOR_VERSION); macro_rules! link_functions { ($($module:literal :: $func:ident,)*) => { - linker$(.func_wrap($module, concat!("_", stringify!($func)), WasmInstanceEnv::$func)?)*; + linker$(.func_wrap($module, stringify!($func), WasmInstanceEnv::$func)?)*; } } abi_funcs!(link_functions);