Skip to content

Commit

Permalink
drop macro
Browse files Browse the repository at this point in the history
  • Loading branch information
kj4tmp committed Mar 10, 2025
1 parent 02905d7 commit 97bd50b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
pull_request:
branches:
- main
schedule:
- cron: '20 0 * * *'

jobs:
build:
Expand Down
61 changes: 61 additions & 0 deletions src/macros.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 4 additions & 3 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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));
}
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
};

Expand Down

0 comments on commit 97bd50b

Please # to comment.