From 4c87d1be761efdf8f6198b15e8876ee90dd2d71c Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Sat, 6 Jun 2026 16:07:17 +0000 Subject: [PATCH 1/2] Prefix public bitfield macros with `LBT_` to avoid namespace pollution `src/libblastrampoline.h` is the public header, but it defined the unprefixed macros `BF_CHUNK`, `BF_MASK`, and `BITFIELD_{GET,SET,CLEAR}` into every consumer's namespace. `BF_MASK` in particular is a likely collision. Rename them to `LBT_`-prefixed names (`LBT_BF_CHUNK`, `LBT_BF_MASK`, `LBT_BITFIELD_{GET,SET,CLEAR}`) and update the in-tree usages. The three documented public macros (`BITFIELD_{GET,SET,CLEAR}`, referenced from the `active_forwards` docstring) are kept as backwards-compatible aliases so existing consumers don't break; `BF_CHUNK`/`BF_MASK` were internal helpers and are renamed without aliases. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/config.c | 2 +- src/libblastrampoline.c | 2 +- src/libblastrampoline.h | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/config.c b/src/config.c index b558fc2..8efa069 100644 --- a/src/config.c +++ b/src/config.c @@ -60,7 +60,7 @@ void clear_forwarding_mark(int32_t symbol_idx, int32_t interface) { continue; } - BITFIELD_CLEAR(lbt_config.loaded_libs[idx]->active_forwards, symbol_idx); + LBT_BITFIELD_CLEAR(lbt_config.loaded_libs[idx]->active_forwards, symbol_idx); } } diff --git a/src/libblastrampoline.c b/src/libblastrampoline.c index 9ef79ee..39833ab 100644 --- a/src/libblastrampoline.c +++ b/src/libblastrampoline.c @@ -407,7 +407,7 @@ LBT_DLLEXPORT int32_t lbt_forward(const char * libname, int32_t clear, int32_t v if (addr != NULL && addr != self_symbol_addr) { lbt_set_forward_by_index(symbol_idx, addr, interface, complex_retstyle, f2c, verbose); - BITFIELD_SET(forwards, symbol_idx); + LBT_BITFIELD_SET(forwards, symbol_idx); nforwards++; } } diff --git a/src/libblastrampoline.h b/src/libblastrampoline.h index 250e82b..3042b18 100644 --- a/src/libblastrampoline.h +++ b/src/libblastrampoline.h @@ -38,11 +38,18 @@ extern "C" { # define LBT_HIDDEN __attribute__ ((visibility("hidden"))) #endif -#define BF_CHUNK(array, idx) (array[((uint32_t)(idx/8))]) -#define BF_MASK(idx) ((uint8_t)(0x1 << (idx % 8))) -#define BITFIELD_GET(array, idx) ((BF_CHUNK(array, idx) & BF_MASK(idx)) >> (idx % 8)) -#define BITFIELD_CLEAR(array, idx) BF_CHUNK(array, idx) &= ~(BF_MASK(idx)) -#define BITFIELD_SET(array, idx) BF_CHUNK(array, idx) |= BF_MASK(idx) +#define LBT_BF_CHUNK(array, idx) (array[((uint32_t)(idx/8))]) +#define LBT_BF_MASK(idx) ((uint8_t)(0x1 << (idx % 8))) +#define LBT_BITFIELD_GET(array, idx) ((LBT_BF_CHUNK(array, idx) & LBT_BF_MASK(idx)) >> (idx % 8)) +#define LBT_BITFIELD_CLEAR(array, idx) LBT_BF_CHUNK(array, idx) &= ~(LBT_BF_MASK(idx)) +#define LBT_BITFIELD_SET(array, idx) LBT_BF_CHUNK(array, idx) |= LBT_BF_MASK(idx) + +// Backwards-compatible unprefixed aliases for the documented public macros. +// Prefer the `LBT_`-prefixed names above; these unprefixed ones are kept so that +// existing consumers reading the `active_forwards` bitfield do not break. +#define BITFIELD_GET(array, idx) LBT_BITFIELD_GET(array, idx) +#define BITFIELD_CLEAR(array, idx) LBT_BITFIELD_CLEAR(array, idx) +#define BITFIELD_SET(array, idx) LBT_BITFIELD_SET(array, idx) // The metadata stored on each loaded library @@ -55,7 +62,7 @@ typedef struct { // Common values are `""` or `"64_"`. const char * suffix; // bitfield (in uint8_t form) representing the active forwards for this library. - // Use the `BITFIELD_{SET,GET}` macros to look at particular indices within this field. + // Use the `LBT_BITFIELD_{SET,GET}` macros to look at particular indices within this field. // Note that if you use the footgun API (e.g. "lbt_set_forward()") these values will be // zeroed out and you must track them manually if you need to. uint8_t * active_forwards; From 9d27eeee455c73c17f5fd63b15653a03de5e8fab Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Sat, 6 Jun 2026 23:15:53 +0000 Subject: [PATCH 2/2] Drop the unprefixed bitfield macro aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per review discussion, remove the backwards-compatible `BITFIELD_{GET,SET,CLEAR}` aliases and keep only the `LBT_`-prefixed macros. These are compile-time-only helper macros (not exported symbols), so removing them does not affect the ABI / soversion — no major version bump required. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/libblastrampoline.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libblastrampoline.h b/src/libblastrampoline.h index 3042b18..0293cd9 100644 --- a/src/libblastrampoline.h +++ b/src/libblastrampoline.h @@ -44,13 +44,6 @@ extern "C" { #define LBT_BITFIELD_CLEAR(array, idx) LBT_BF_CHUNK(array, idx) &= ~(LBT_BF_MASK(idx)) #define LBT_BITFIELD_SET(array, idx) LBT_BF_CHUNK(array, idx) |= LBT_BF_MASK(idx) -// Backwards-compatible unprefixed aliases for the documented public macros. -// Prefer the `LBT_`-prefixed names above; these unprefixed ones are kept so that -// existing consumers reading the `active_forwards` bitfield do not break. -#define BITFIELD_GET(array, idx) LBT_BITFIELD_GET(array, idx) -#define BITFIELD_CLEAR(array, idx) LBT_BITFIELD_CLEAR(array, idx) -#define BITFIELD_SET(array, idx) LBT_BITFIELD_SET(array, idx) - // The metadata stored on each loaded library typedef struct {