Re: Consistently use palloc_object() and palloc_array()
David Geier <geidav.pg@gmail.com>
From: David Geier <geidav.pg@gmail.com>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Chao Li <li.evan.chao@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-12-02T15:13:01Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
btree_gist: Fix memory allocation formula
- 5cf03552fbb4 19 (unreleased) landed
-
Use palloc_object() and palloc_array(), the last change
- 4f7dacc5b82a 19 (unreleased) landed
-
pg_buffercache: Fix memory allocation formula
- 580b5c2f397f 18.2 landed
- 3f83de20ba2e 19 (unreleased) landed
-
Fix allocation formula in llvmjit_expr.c
- 0c67dbcc4e39 14.21 landed
- 07ddf6197b78 15.16 landed
- 5a4dc4aabd03 16.12 landed
- 0bab0c3b74af 17.8 landed
- 5b7bbf16db34 18.2 landed
- 06761b6096b6 19 (unreleased) landed
-
Use palloc_object() and palloc_array() in backend code
- 1b105f9472bd 19 (unreleased) landed
-
Use palloc_object() and palloc_array() in more areas of the tree
- 0c3c5c3b06a3 19 (unreleased) landed
-
Use more palloc_object() and palloc_array() in contrib/
- 31d3847a37be 19 (unreleased) landed
On 28.11.2025 23:31, Thomas Munro wrote:
> On Sat, Nov 29, 2025 at 10:47 AM David Geier <geidav.pg@gmail.com> wrote:
>> I intentionally tried to avoid any semantic changes but it's of course
>> possible something slipped through by accident.
>
> Do you expect the generated code to be identical? Is it?
In the majority of cases yes. However, there are a few cases where a
small change in the C code can yield to differences in the generated code:
I used the following bash script to create the disassembly of all object
files in the build directory. I ran this script twice, once on master
and once on the patched branch. The directory needs to be adapted
accordingly in the script.
find . -name "*.o" -print0 | while IFS= read -r -d '' file; do
mkdir -p ~/Desktop/master/"$(dirname "$file")"
if objdump -drwC -Mintel "$file" > ~/Desktop/master/"$file".dis
2>/dev/null; then
echo " ✓ Disassembled to ~/Desktop/master/$file.dis"
else
echo " ✗ Failed to disassemble $file"
fi
done
There are 54 files that show changes in the generated code. I didn't
look through all files but the changes are largely caused by the same
reasons:
1) If the refactoring introduces a change in the number of lines, the
__LINE__ macro used by elog.h will cause a change in the disassembly.
This is the reason for the majority of changes.
2) fuzzystrmatch.c: contains a functional change. We allocate 1 byte
more now but that is safe, see [1].
3) pg_buffercache_pages.c: Functional change. Type used in
palloc_array() changed from uint64 to int, as the rest of the code only
uses an integer.
4) trgm_op.c: Contains arithmetic expressions in the calls to
palloc_array() where now the brackets are placed differently, e.g.
sizeof(type) * a * b vs sizeof(type) * (a * b). That's the reason for
many differences.
So reviewing this patch can now be done by only going through all files
that have changes in the disassembly. This is only 54 out of which most
are because of changes in the number of LOC or where the brackets are
placed.
[1] https://www.postgresql.org/message-id/524587.1764365323%40sss.pgh.pa.us
--
David Geier