|
| 1 | +/* |
| 2 | + * Fallback <stdatomic.h> for bindgen. |
| 3 | + * |
| 4 | + * Some libclang builds ship a <stdatomic.h> that silently provides no |
| 5 | + * declarations. This makes any header that relies on C11 atomics |
| 6 | + * (e.g. mimalloc) unparseable by bindgen. |
| 7 | + * |
| 8 | + * This file provides the standard C11 atomics API with non-atomic stubs. |
| 9 | + * Bindgen only needs correct type layouts -- it never executes atomic |
| 10 | + * operations -- so plain loads/stores are sufficient. |
| 11 | + * |
| 12 | + * The build script adds this directory via -isystem so it shadows a |
| 13 | + * broken system header while remaining invisible when the real header |
| 14 | + * works (libclang picks whichever it finds first on the include path). |
| 15 | + */ |
| 16 | +#ifndef _STDATOMIC_BINDGEN_FALLBACK_H |
| 17 | +#define _STDATOMIC_BINDGEN_FALLBACK_H |
| 18 | + |
| 19 | +/* Strip _Atomic qualifier -- bindgen cares about layout, not atomicity. */ |
| 20 | +#define _Atomic(tp) tp |
| 21 | + |
| 22 | +typedef enum { |
| 23 | + memory_order_relaxed, |
| 24 | + memory_order_consume, |
| 25 | + memory_order_acquire, |
| 26 | + memory_order_release, |
| 27 | + memory_order_acq_rel, |
| 28 | + memory_order_seq_cst |
| 29 | +} memory_order; |
| 30 | + |
| 31 | +#define ATOMIC_VAR_INIT(value) (value) |
| 32 | + |
| 33 | +#define atomic_load_explicit(p, mo) (*(p)) |
| 34 | +#define atomic_store_explicit(p, v, mo) ((void)(*(p) = (v))) |
| 35 | +#define atomic_fetch_add_explicit(p, v, mo) (*(p)) |
| 36 | +#define atomic_fetch_sub_explicit(p, v, mo) (*(p)) |
| 37 | +#define atomic_fetch_or_explicit(p, v, mo) (*(p)) |
| 38 | +#define atomic_fetch_and_explicit(p, v, mo) (*(p)) |
| 39 | +#define atomic_compare_exchange_weak_explicit(p, e, d, s, f) 1 |
| 40 | +#define atomic_compare_exchange_strong_explicit(p, e, d, s, f) 1 |
| 41 | +#define atomic_exchange_explicit(p, v, mo) (*(p)) |
| 42 | +#define atomic_thread_fence(mo) ((void)0) |
| 43 | + |
| 44 | +#endif /* _STDATOMIC_BINDGEN_FALLBACK_H */ |
0 commit comments