From 97bd50b9d33722b59cc51386cb5462cb140932ab Mon Sep 17 00:00:00 2001 From: "kj4tmp@gmail.com" Date: Sun, 9 Mar 2025 23:47:55 -0700 Subject: [PATCH] drop macro --- .github/workflows/main.yml | 2 -- src/macros.zig | 61 ++++++++++++++++++++++++++++++++++++++ src/root.zig | 7 +++-- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f5ffaf..ca91405 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,8 +6,6 @@ on: pull_request: branches: - main - schedule: - - cron: '20 0 * * *' jobs: build: diff --git a/src/macros.zig b/src/macros.zig index 4ae8f5a..eeffa0a 100644 --- a/src/macros.zig +++ b/src/macros.zig @@ -123,3 +123,64 @@ pub fn move(value: anytype) Moved(std.meta.Child(@TypeOf(value))) { }; return converter(value); } + +pub fn drop(value: anytype) void { + const dropper = switch (std.meta.Child(@TypeOf(value))) { + c.z_moved_alloc_layout_t => c.z_alloc_layout_drop, + c.z_moved_bytes_t => c.z_bytes_drop, + c.z_moved_bytes_writer_t => c.z_bytes_writer_drop, + c.z_moved_chunk_alloc_result_t => c.z_chunk_alloc_result_drop, + c.z_moved_closure_hello_t => c.z_closure_hello_drop, + c.z_moved_closure_matching_status_t => c.z_closure_matching_status_drop, + c.z_moved_closure_query_t => c.z_closure_query_drop, + c.z_moved_closure_reply_t => c.z_closure_reply_drop, + c.z_moved_closure_sample_t => c.z_closure_sample_drop, + c.z_moved_closure_zid_t => c.z_closure_zid_drop, + c.z_moved_condvar_t => c.z_condvar_drop, + c.z_moved_config_t => c.z_config_drop, + c.z_moved_encoding_t => c.z_encoding_drop, + c.z_moved_fifo_handler_query_t => c.z_fifo_handler_query_drop, + c.z_moved_fifo_handler_reply_t => c.z_fifo_handler_reply_drop, + c.z_moved_fifo_handler_sample_t => c.z_fifo_handler_sample_drop, + c.z_moved_hello_t => c.z_hello_drop, + c.z_moved_keyexpr_t => c.z_keyexpr_drop, + c.z_moved_liveliness_token_t => c.z_liveliness_token_drop, + c.z_moved_matching_listener_t => c.z_matching_listener_drop, + c.z_moved_memory_layout_t => c.z_memory_layout_drop, + c.z_moved_mutex_t => c.z_mutex_drop, + c.z_moved_publisher_t => c.z_publisher_drop, + c.z_moved_querier_t => c.z_querier_drop, + c.z_moved_query_t => c.z_query_drop, + c.z_moved_queryable_t => c.z_queryable_drop, + c.z_moved_reply_t => c.z_reply_drop, + c.z_moved_reply_err_t => c.z_reply_err_drop, + c.z_moved_ring_handler_query_t => c.z_ring_handler_query_drop, + c.z_moved_ring_handler_reply_t => c.z_ring_handler_reply_drop, + c.z_moved_ring_handler_sample_t => c.z_ring_handler_sample_drop, + c.z_moved_sample_t => c.z_sample_drop, + c.z_moved_session_t => c.z_session_drop, + c.z_moved_shm_client_t => c.z_shm_client_drop, + c.z_moved_shm_client_storage_t => c.z_shm_client_storage_drop, + c.z_moved_shm_t => c.z_shm_drop, + c.z_moved_shm_mut_t => c.z_shm_mut_drop, + c.z_moved_shm_provider_t => c.z_shm_provider_drop, + c.z_moved_slice_t => c.z_slice_drop, + c.z_moved_source_info_t => c.z_source_info_drop, + c.z_moved_string_array_t => c.z_string_array_drop, + c.z_moved_string_t => c.z_string_drop, + c.z_moved_subscriber_t => c.z_subscriber_drop, + c.z_moved_task_t => c.z_task_drop, + c.zc_moved_closure_log_t => c.zc_closure_log_drop, + c.zc_moved_concurrent_close_handle_t => c.zc_concurrent_close_handle_drop, + c.zc_moved_shm_client_list_t => c.zc_shm_client_list_drop, + c.ze_moved_advanced_publisher_t => c.ze_advanced_publisher_drop, + c.ze_moved_advanced_subscriber_t => c.ze_advanced_subscriber_drop, + c.ze_moved_closure_miss_t => c.ze_closure_miss_drop, + c.ze_moved_publication_cache_t => c.ze_publication_cache_drop, + c.ze_moved_querying_subscriber_t => c.ze_querying_subscriber_drop, + c.ze_moved_sample_miss_listener_t => c.ze_sample_miss_listener_drop, + c.ze_moved_serializer_t => c.ze_serializer_drop, + else => comptime unreachable, + }; + dropper(value); +} diff --git a/src/root.zig b/src/root.zig index ee4fae7..c171dda 100644 --- a/src/root.zig +++ b/src/root.zig @@ -4,6 +4,7 @@ pub const c = @import("zenoh_c"); pub const macros = @import("macros.zig"); const move = macros.move; +const drop = macros.drop; pub const Error = error{ZenohError}; @@ -41,7 +42,7 @@ pub const Config = struct { } pub fn deinit(self: *Config) void { - c.z_config_drop(move(&self._c)); + drop(move(&self._c)); } }; @@ -73,7 +74,7 @@ pub const Session = struct { } pub fn deinit(self: *Session) void { - c.z_session_drop(move(&self._c)); + drop(move(&self._c)); } pub const CloseOptions = struct { @@ -136,7 +137,7 @@ pub const Bytes = struct { } pub fn deinit(self: *Bytes) void { - c.z_bytes_drop(move(&self._c)); + drop(move(&self._c)); } };