Skip to content

Commit dbce850

Browse files
authored
fix: use correct macro in async header (#265)
1 parent b034c85 commit dbce850

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

dylib/dylib.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cstring>
22
#include <cassert>
3+
#include <type_traits>
34
#include "ecsact/runtime/dylib.h"
45

56
#ifdef ECSACT_ASYNC_API_LOAD_AT_RUNTIME
@@ -47,10 +48,14 @@ FOR_EACH_ECSACT_SERIALIZE_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN);
4748
#define HAS_FN_CHECK(fn_name, target_fn_name) \
4849
if(std::strcmp(target_fn_name, #fn_name) == 0) return true
4950

50-
#define ASSIGN_FN_IF(fn_name, target_fn_name, fn_ptr) \
51-
if(std::strcmp(#fn_name, target_fn_name) == 0) { \
52-
fn_name = reinterpret_cast<decltype(fn_name)>(fn_ptr); \
53-
} \
51+
#define ASSIGN_FN_IF(fn_name, target_fn_name, fn_ptr) \
52+
static_assert( \
53+
std::is_pointer_v<decltype(fn_name)>, \
54+
"Ecsact dylib may only be used for functions available at runtime" \
55+
); \
56+
if(std::strcmp(#fn_name, target_fn_name) == 0) { \
57+
fn_name = reinterpret_cast<decltype(fn_name)>(fn_ptr); \
58+
} \
5459
static_assert(true, "macro requires ;")
5560

5661
bool ecsact_dylib_has_fn(const char* fn_name) {

dylib/index.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def cc_ecsact_dylib(name = None, srcs = [], ecsact_modules = [], deps = [], defi
2626
name = name,
2727
deps = deps + ["@ecsact_runtime//:dylib", "@ecsact_runtime//dylib:util"] + ["@ecsact_runtime//:{}".format(m) for m in ecsact_modules],
2828
srcs = srcs + ["@ecsact_runtime//dylib:dylib.cc"],
29+
local_defines = ["ECSACT_{}_API_EXPORT".format(m.upper()) for m in ecsact_modules],
2930
defines = #
3031
defines +
3132
["ECSACT_{}_API_LOAD_AT_RUNTIME".format(m.upper()) for m in ecsact_modules],

ecsact/runtime/async.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,22 +213,24 @@ ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void);
213213
* fields must be supplied as a sequential array in declaration order,
214214
* otherwise may be NULL.
215215
*/
216-
ECSACT_CORE_API_FN(ecsact_async_request_id, ecsact_async_stream)
216+
ECSACT_ASYNC_API_FN(ecsact_async_request_id, ecsact_async_stream)
217217
( //
218218
ecsact_entity_id entity,
219219
ecsact_component_id component_id,
220220
const void* component_data,
221221
const void* indexed_field_values
222222
);
223223

224-
#define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \
225-
fn(ecsact_async_enqueue_execution_options, __VA_ARGS__); \
226-
fn(ecsact_async_flush_events, __VA_ARGS__); \
227-
fn(ecsact_async_connect, __VA_ARGS__); \
228-
fn(ecsact_async_disconnect, __VA_ARGS__); \
229-
fn(ecsact_async_get_current_tick, __VA_ARGS__); \
230-
fn(ecsact_async_stream, __VA_ARGS__)
224+
#ifdef ECSACT_MSVC_TRADITIONAL
225+
# define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) ECSACT_MSVC_TRADITIONAL_ERROR()
226+
#else
227+
# define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \
228+
fn(ecsact_async_enqueue_execution_options, __VA_ARGS__); \
229+
fn(ecsact_async_flush_events, __VA_ARGS__); \
230+
fn(ecsact_async_connect, __VA_ARGS__); \
231+
fn(ecsact_async_disconnect, __VA_ARGS__); \
232+
fn(ecsact_async_get_current_tick, __VA_ARGS__); \
233+
fn(ecsact_async_stream, __VA_ARGS__)
234+
#endif
231235

232-
#undef ECSACT_ASYNC_API
233-
#undef ECSACT_ASYNC_API_FN
234236
#endif // ECSACT_RUNTIME_ASYNC_H

0 commit comments

Comments
 (0)