Skip to content

Commit 7bb5f53

Browse files
ViralBShahclaude
andauthored
Prefix public bitfield macros with LBT_ to avoid namespace pollution (#177)
* 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) <noreply@anthropic.com> * Drop the unprefixed bitfield macro aliases 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) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2789a73 commit 7bb5f53

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void clear_forwarding_mark(int32_t symbol_idx, int32_t interface) {
6060
continue;
6161
}
6262

63-
BITFIELD_CLEAR(lbt_config.loaded_libs[idx]->active_forwards, symbol_idx);
63+
LBT_BITFIELD_CLEAR(lbt_config.loaded_libs[idx]->active_forwards, symbol_idx);
6464
}
6565
}
6666

src/libblastrampoline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ LBT_DLLEXPORT int32_t lbt_forward(const char * libname, int32_t clear, int32_t v
407407

408408
if (addr != NULL && addr != self_symbol_addr) {
409409
lbt_set_forward_by_index(symbol_idx, addr, interface, complex_retstyle, f2c, verbose);
410-
BITFIELD_SET(forwards, symbol_idx);
410+
LBT_BITFIELD_SET(forwards, symbol_idx);
411411
nforwards++;
412412
}
413413
}

src/libblastrampoline.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ extern "C" {
3838
# define LBT_HIDDEN __attribute__ ((visibility("hidden")))
3939
#endif
4040

41-
#define BF_CHUNK(array, idx) (array[((uint32_t)(idx/8))])
42-
#define BF_MASK(idx) ((uint8_t)(0x1 << (idx % 8)))
43-
#define BITFIELD_GET(array, idx) ((BF_CHUNK(array, idx) & BF_MASK(idx)) >> (idx % 8))
44-
#define BITFIELD_CLEAR(array, idx) BF_CHUNK(array, idx) &= ~(BF_MASK(idx))
45-
#define BITFIELD_SET(array, idx) BF_CHUNK(array, idx) |= BF_MASK(idx)
41+
#define LBT_BF_CHUNK(array, idx) (array[((uint32_t)(idx/8))])
42+
#define LBT_BF_MASK(idx) ((uint8_t)(0x1 << (idx % 8)))
43+
#define LBT_BITFIELD_GET(array, idx) ((LBT_BF_CHUNK(array, idx) & LBT_BF_MASK(idx)) >> (idx % 8))
44+
#define LBT_BITFIELD_CLEAR(array, idx) LBT_BF_CHUNK(array, idx) &= ~(LBT_BF_MASK(idx))
45+
#define LBT_BITFIELD_SET(array, idx) LBT_BF_CHUNK(array, idx) |= LBT_BF_MASK(idx)
4646

4747

4848
// The metadata stored on each loaded library
@@ -55,7 +55,7 @@ typedef struct {
5555
// Common values are `""` or `"64_"`.
5656
const char * suffix;
5757
// bitfield (in uint8_t form) representing the active forwards for this library.
58-
// Use the `BITFIELD_{SET,GET}` macros to look at particular indices within this field.
58+
// Use the `LBT_BITFIELD_{SET,GET}` macros to look at particular indices within this field.
5959
// Note that if you use the footgun API (e.g. "lbt_set_forward()") these values will be
6060
// zeroed out and you must track them manually if you need to.
6161
uint8_t * active_forwards;

0 commit comments

Comments
 (0)