Skip to content

Commit 2864340

Browse files
committed
Properly group gc conditionally defined functions
1 parent 75ac484 commit 2864340

3 files changed

Lines changed: 14 additions & 31 deletions

File tree

crates/c-api/include/wasmtime/func.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ NATIVE_WASM_TYPE(double, F64, f64)
8181

8282
#undef NATIVE_WASM_TYPE
8383

84+
#ifdef WASMTIME_FEATURE_GC
8485
/// Type information for `externref`, represented on the host as an optional
8586
/// `ExternRef`.
8687
template <> struct WasmType<std::optional<ExternRef>> {
@@ -103,7 +104,6 @@ template <> struct WasmType<std::optional<ExternRef>> {
103104
}
104105
}
105106

106-
#ifdef WASMTIME_FEATURE_GC
107107
static std::optional<ExternRef> load(Store::Context cx,
108108
wasmtime_val_raw_t *p) {
109109
if (p->externref == 0) {
@@ -113,8 +113,8 @@ template <> struct WasmType<std::optional<ExternRef>> {
113113
wasmtime_externref_from_raw(cx.capi(), p->externref, &val);
114114
return ExternRef(val);
115115
}
116-
#endif // WASMTIME_FEATURE_GC
117116
};
117+
#endif // WASMTIME_FEATURE_GC
118118

119119
/// Type information for the `V128` host value used as a wasm value.
120120
template <> struct WasmType<V128> {

crates/c-api/include/wasmtime/val.h

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
extern "C" {
1616
#endif
1717

18+
1819
/**
1920
* \typedef wasmtime_anyref_t
2021
* \brief Convenience alias for #wasmtime_anyref
@@ -52,6 +53,7 @@ typedef struct wasmtime_anyref {
5253
void *__private3;
5354
} wasmtime_anyref_t;
5455

56+
#ifdef WASMTIME_FEATURE_GC
5557
/// \brief Helper function to initialize the `ref` provided to a null anyref
5658
/// value.
5759
static inline void wasmtime_anyref_set_null(wasmtime_anyref_t *ref) {
@@ -67,6 +69,7 @@ static inline bool wasmtime_anyref_is_null(const wasmtime_anyref_t *ref) {
6769
return ref->store_id == 0;
6870
}
6971

72+
7073
/**
7174
* \brief Creates a new reference pointing to the same data that `anyref`
7275
* points to (depending on the configured collector this might increase a
@@ -92,7 +95,6 @@ WASM_API_EXTERN void wasmtime_anyref_clone(const wasmtime_anyref_t *anyref,
9295
*/
9396
WASM_API_EXTERN void wasmtime_anyref_unroot(wasmtime_anyref_t *ref);
9497

95-
#ifdef WASMTIME_FEATURE_GC
9698
/**
9799
* \brief Converts a raw `anyref` value coming from #wasmtime_val_raw_t into
98100
* a #wasmtime_anyref_t.
@@ -103,9 +105,7 @@ WASM_API_EXTERN void wasmtime_anyref_unroot(wasmtime_anyref_t *ref);
103105
WASM_API_EXTERN void wasmtime_anyref_from_raw(wasmtime_context_t *context,
104106
uint32_t raw,
105107
wasmtime_anyref_t *out);
106-
#endif // WASMTIME_FEATURE_GC
107108

108-
#ifdef WASMTIME_FEATURE_GC
109109
/**
110110
* \brief Converts a #wasmtime_anyref_t to a raw value suitable for storing
111111
* into a #wasmtime_val_raw_t.
@@ -118,9 +118,7 @@ WASM_API_EXTERN void wasmtime_anyref_from_raw(wasmtime_context_t *context,
118118
*/
119119
WASM_API_EXTERN uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context,
120120
const wasmtime_anyref_t *ref);
121-
#endif // WASMTIME_FEATURE_GC
122121

123-
#ifdef WASMTIME_FEATURE_GC
124122
/**
125123
* \brief Create a new `i31ref` value.
126124
*
@@ -132,10 +130,7 @@ WASM_API_EXTERN uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context,
132130
WASM_API_EXTERN void wasmtime_anyref_from_i31(wasmtime_context_t *context,
133131
uint32_t i31val,
134132
wasmtime_anyref_t *out);
135-
#endif // WASMTIME_FEATURE_GC
136-
137133

138-
#ifdef WASMTIME_FEATURE_GC
139134
/**
140135
* \brief Get the `anyref`'s underlying `i31ref` value, zero extended, if any.
141136
*
@@ -148,9 +143,7 @@ WASM_API_EXTERN void wasmtime_anyref_from_i31(wasmtime_context_t *context,
148143
WASM_API_EXTERN bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context,
149144
const wasmtime_anyref_t *anyref,
150145
uint32_t *dst);
151-
#endif // WASMTIME_FEATURE_GC
152146

153-
#ifdef WASMTIME_FEATURE_GC
154147
/**
155148
* \brief Get the `anyref`'s underlying `i31ref` value, sign extended, if any.
156149
*
@@ -163,7 +156,6 @@ WASM_API_EXTERN bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context,
163156
WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
164157
const wasmtime_anyref_t *anyref,
165158
int32_t *dst);
166-
#endif // WASMTIME_FEATURE_GC
167159

168160
/**
169161
* \typedef wasmtime_externref_t
@@ -186,6 +178,8 @@ WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
186178
* `wasmtime_externref_set_null`. Null can be tested for with the
187179
* `wasmtime_externref_is_null` function.
188180
*/
181+
#endif // WASMTIME_FEATURE_GC
182+
189183
typedef struct wasmtime_externref {
190184
/// Internal metadata tracking within the store, embedders should not
191185
/// configure or modify these fields.
@@ -198,6 +192,7 @@ typedef struct wasmtime_externref {
198192
void *__private3;
199193
} wasmtime_externref_t;
200194

195+
#ifdef WASMTIME_FEATURE_GC
201196
/// \brief Helper function to initialize the `ref` provided to a null externref
202197
/// value.
203198
static inline void wasmtime_externref_set_null(wasmtime_externref_t *ref) {
@@ -213,7 +208,6 @@ static inline bool wasmtime_externref_is_null(const wasmtime_externref_t *ref) {
213208
return ref->store_id == 0;
214209
}
215210

216-
#ifdef WASMTIME_FEATURE_GC
217211
/**
218212
* \brief Create a new `externref` value.
219213
*
@@ -241,10 +235,7 @@ WASM_API_EXTERN bool wasmtime_externref_new(wasmtime_context_t *context,
241235
void *data,
242236
void (*finalizer)(void *),
243237
wasmtime_externref_t *out);
244-
#endif // WASMTIME_FEATURE_GC
245-
246238

247-
#ifdef WASMTIME_FEATURE_GC
248239
/**
249240
* \brief Get an `externref`'s wrapped data
250241
*
@@ -253,7 +244,6 @@ WASM_API_EXTERN bool wasmtime_externref_new(wasmtime_context_t *context,
253244
*/
254245
WASM_API_EXTERN void *wasmtime_externref_data(wasmtime_context_t *context,
255246
const wasmtime_externref_t *data);
256-
#endif // WASMTIME_FEATURE_GC
257247

258248
/**
259249
* \brief Creates a new reference pointing to the same data that `ref` points
@@ -280,7 +270,6 @@ WASM_API_EXTERN void wasmtime_externref_clone(const wasmtime_externref_t *ref,
280270
*/
281271
WASM_API_EXTERN void wasmtime_externref_unroot(wasmtime_externref_t *ref);
282272

283-
#ifdef WASMTIME_FEATURE_GC
284273
/**
285274
* \brief Converts a raw `externref` value coming from #wasmtime_val_raw_t into
286275
* a #wasmtime_externref_t.
@@ -291,9 +280,7 @@ WASM_API_EXTERN void wasmtime_externref_unroot(wasmtime_externref_t *ref);
291280
WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context,
292281
uint32_t raw,
293282
wasmtime_externref_t *out);
294-
#endif // WASMTIME_FEATURE_GC
295283

296-
#ifdef WASMTIME_FEATURE_GC
297284
/**
298285
* \brief Converts a #wasmtime_externref_t to a raw value suitable for storing
299286
* into a #wasmtime_val_raw_t.
@@ -334,6 +321,7 @@ typedef uint8_t wasmtime_valkind_t;
334321
/// stored in little-endian order.
335322
typedef uint8_t wasmtime_v128[16];
336323

324+
337325
/**
338326
* \typedef wasmtime_valunion_t
339327
* \brief Convenience alias for #wasmtime_valunion

crates/c-api/include/wasmtime/val.hh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace wasmtime {
1414

15+
#ifdef WASMTIME_FEATURE_GC
1516
/**
1617
* \brief Representation of a WebAssembly `externref` value.
1718
*
@@ -66,7 +67,6 @@ public:
6667

6768
~ExternRef() { wasmtime_externref_unroot(&val); }
6869

69-
#ifdef WASMTIME_FEATURE_GC
7070
/// Creates a new `externref` value from the provided argument.
7171
///
7272
/// Note that `val` should be safe to send across threads and should own any
@@ -80,33 +80,29 @@ public:
8080
abort();
8181
}
8282
}
83-
#endif // WASMTIME_FEATURE_GC
8483

85-
#ifdef WASMTIME_FEATURE_GC
8684
/// Returns the underlying host data associated with this `ExternRef`.
8785
std::any &data(Store::Context cx) {
8886
return *static_cast<std::any *>(wasmtime_externref_data(cx.ptr, &val));
8987
}
90-
#endif // WASMTIME_FEATURE_GC
9188

92-
#ifdef WASMTIME_FEATURE_GC
9389
/// Consumes ownership of the underlying `wasmtime_externref_t` and returns
9490
/// the result of `wasmtime_externref_to_raw`.
9591
uint32_t take_raw(Store::Context cx) {
9692
uint32_t ret = wasmtime_externref_to_raw(cx.capi(), &val);
9793
wasmtime_externref_set_null(&val);
9894
return ret;
9995
}
100-
#endif // WASMTIME_FEATURE_GC
10196

102-
#ifdef WASMTIME_FEATURE_GC
10397
/// Returns `wasmtime_externref_to_raw`.
10498
uint32_t borrow_raw(Store::Context cx) const {
10599
return wasmtime_externref_to_raw(cx.capi(), &val);
106100
}
107-
#endif // WASMTIME_FEATURE_GC
108101
};
102+
#endif // WASMTIME_FEATURE_GC
109103

104+
105+
#ifdef WASMTIME_FEATURE_GC
110106
/**
111107
* \brief Representation of a WebAssembly `anyref` value.
112108
*/
@@ -174,16 +170,15 @@ public:
174170
return std::nullopt;
175171
}
176172

177-
#ifdef WASMTIME_FEATURE_GC
178173
/// \brief If this is an `i31`, get the value sign-extended.
179174
std::optional<int32_t> i31(Store::Context cx) const {
180175
int32_t ret = 0;
181176
if (wasmtime_anyref_i31_get_s(cx.ptr, &val, &ret))
182177
return ret;
183178
return std::nullopt;
184179
}
185-
#endif // WASMTIME_FEATURE_GC
186180
};
181+
#endif // WASMTIME_FEATURE_GC
187182

188183
/// \brief Container for the `v128` WebAssembly type.
189184
struct V128 {

0 commit comments

Comments
 (0)