Thread

  1. Some efforts to get rid of "long" in our codebase

    David Rowley <dgrowleyml@gmail.com> — 2025-11-06T11:46:56Z

    I was playing around with the following imperfect regex to try and get
    an idea of how many "long" usages we have.
    
    git grep -E "^\s*(static)?\s*(unsigned)?\s*long\b" -- '*.c' '*.h' | wc -l
    
    REL_13_STABLE -> 486
    REL_14_STABLE -> 482
    REL_15_STABLE -> 476
    REL_16_STABLE -> 485
    REL_17_STABLE -> 449
    REL_18_STABLE -> 439
    master -> 386
    
    (Generally trending downwards with quite a good reduction since v18)
    
    Many of the "long" usages are genuine, e.g for compatibility with
    library functions, or in snprintf.c for the %ld and %lu format
    specifiers; those we need. However, many of these we don't need. Many
    are a possible source of bugs due to not all platforms we support
    having the same idea about how wide longs are. We've had and fixed
    bugs around this before.
    
    I've attached a couple of patches to get the ball rolling.
    
    0001: CATCACHE_STATS is using signed longs as counters for cache
    hits/misses etc. I've changed this to uint64 rather than int64 as I
    didn't see the need to have a signed type to count the occurrences of
    an event. Maybe there's an anti-universe where negative occurrences
    are a thing, but they're not in this one. If something goes awry with
    the counters and that causes the subtraction that's being done to
    wrap, then we're more likely to notice the bug via the excessively
    large number the wrap would end up displaying.
    
    0002: MemSet / MemSetAligned macros. It's probably about time someone
    made these disappear, but that's likely for another thread with more
    research than I'd like to do here. I replaced "long" with "Size". I
    also considered "uintptr_t", but after some reading of the C standard,
    I settled on Size as it seems it's possible for platforms to exist
    where the pointer width is smaller than the processor's width. I
    suspect it might not matter for the platforms we support? Size could
    also be smaller than the processor's width, but I feel that's less
    likely.
    
    Which yields a drop in the Ocean fewer longs...
    
    0001+0002 -> 367
    
    David