| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Some efforts to get rid of "long" in our codebase |
| Date: | 2025-11-06 12:17:01 |
| Message-ID: | f7d10dfa-6958-43fb-8907-9851576f614a@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 06/11/2025 13:46, David Rowley wrote:
> I've attached a couple of patches to get the ball rolling.
Thanks!
> 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.
Unsigned makes sense for these.
> @@ -476,7 +476,7 @@ CatCachePrintStats(int code, Datum arg)
>
> if (cache->cc_ntup == 0 && cache->cc_searches == 0)
> continue; /* don't print unused caches */
> - elog(DEBUG2, "catcache %s/%u: %d tup, %ld srch, %ld+%ld=%ld hits, %ld+%ld=%ld loads, %ld invals, %d lists, %ld lsrch, %ld lhits",
> + elog(DEBUG2, "catcache %s/%u: %d tup, %" PRIu64 " srch, %" PRIu64 "+%" PRIu64 "=%" PRIu64 " hits, %" PRIu64 "+%" PRIu64 "=%" PRIu64 " loads, %" PRIu64 " invals, %d lists, %" PRIu64 " lsrch, %" PRIu64 " lhits",
> cache->cc_relname,
> cache->cc_indexoid,
> cache->cc_ntup,
Unfortunately PRIu64 makes these much longer and less readable. I don't
think there's much we can do about that though. Perhaps split the format
string to multiple lines?
> 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.
Let's use size_t instead of Size in new code, per previous discussions
(https://www.postgresql.org/message-id/flat/CA%2BRLCQyVqb9Xxni6x2iJYTawMbJv5gZY2fzNaw39%3D_yOtu_QKw%40mail.gmail.com#74391f75a649df13920f87360e361183)
- Heikki
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mats Kindahl | 2025-11-06 12:34:54 | Re: Refactor StringInfo usage in subscriptioncmds.c |
| Previous Message | Amit Kapila | 2025-11-06 12:09:50 | Re: Refactor StringInfo usage in subscriptioncmds.c |