Skip to content

Commit 8628bae

Browse files
committed
Add spidir_funcref_is_* utilities to C API
1 parent 3e5b868 commit 8628bae

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

c-api-tests/cases/call.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ void caller_builder_callback(spidir_builder_handle_t builder, void* ctx) {
3838

3939
spidir_value_t args[] = {ptr, ival};
4040

41+
ASSERT(spidir_funcref_get_kind(func_ctx->extfunc) ==
42+
SPIDIR_FUNCREF_EXTERNAL);
43+
ASSERT(spidir_funcref_is_external(func_ctx->extfunc));
44+
ASSERT(spidir_funcref_get_kind(func_ctx->infunc) ==
45+
SPIDIR_FUNCREF_INTERNAL);
46+
ASSERT(spidir_funcref_is_internal(func_ctx->infunc));
47+
4148
spidir_builder_build_call(builder, func_ctx->extfunc, 2, args);
4249
spidir_value_t ext_ret =
4350
spidir_builder_build_call(builder, func_ctx->extfunc2, 2, args);

c-api/include/spidir/module.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ spidir_funcref_get_kind(spidir_funcref_t func) {
236236
return func.id >> 32;
237237
}
238238

239+
/// Queries whether a function reference points to an internal function.
240+
///
241+
/// @param[in] func The reference to query.
242+
/// @return True if `func` refers to an internal function.
243+
static inline bool spidir_funcref_is_internal(spidir_funcref_t func) {
244+
return spidir_funcref_get_kind(func) == SPIDIR_FUNCREF_INTERNAL;
245+
}
246+
247+
/// Queries whether a function reference points to an external function.
248+
///
249+
/// @param[in] func The reference to query.
250+
/// @return True if `func` refers to an external function.
251+
static inline bool spidir_funcref_is_external(spidir_funcref_t func) {
252+
return spidir_funcref_get_kind(func) == SPIDIR_FUNCREF_EXTERNAL;
253+
}
254+
239255
/// Returns the module-internal function pointed to by a reference previously
240256
/// created with `spidir_funcref_make_internal`.
241257
///

0 commit comments

Comments
 (0)