Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vTIge-00GPHw-1k for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Dec 2025 11:48:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vTIgc-00B497-0a for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Dec 2025 11:48:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vTIgb-00B48z-2q for pgsql-hackers@lists.postgresql.org; Wed, 10 Dec 2025 11:48:50 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vTIga-004Fj7-0L for pgsql-hackers@postgresql.org; Wed, 10 Dec 2025 11:48:49 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-298287a26c3so90185275ad.0 for ; Wed, 10 Dec 2025 03:48:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765367325; x=1765972125; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=y1taRnOtPTG0F/rNfOszFXMmH5jPk4McFB9vMQN5iS4=; b=ZL2UbTpjklOm+ymL1MKZZe3kt9zcZp1BDB5CD1equ8k4+d0TIzBXPwzp0SWaztpQQc 99BV6DqNg+s0JiQITsfHyhlXcK+DVkjrUzeRL/j5gKK+SHK+639AlbOGxw5AalAfcGnP dXaE+9MByYZdGSbUMDv9utLDT35fHVOFrctPROK8f+ITIGkn79kxf5vC9wKMalJk/SZw lW32Bu3Ce0cMs8hf+WOFo/WeXbgnWUi0Vx2sc5x2J1Bqf9Hc0OoCtIKDDM4L4eRzCjHk loGRkeFkjTQYUHQApQeb9iIMAkZgd1jeLndjTyynWB4fAh7uUMFJXKAPqwE+5Afsr4So 04/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765367325; x=1765972125; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y1taRnOtPTG0F/rNfOszFXMmH5jPk4McFB9vMQN5iS4=; b=YXZA0NjrhKgLWQDsVaJ2MkMCmKOUMPLPlobRdaDEoM6/7tFDby2BRcZQIySAszolQv tmyjy/0MyamFC23AOktFcMXEaPAGWD5NghHaIxYPDWBw2AG8r/olVHIBAuMlhT2kVjb5 hTUFOZAwqv7AcFtD0MTxsHox31Ao4gXc96zTVpjI7a81mPlKJJN4piUm79ZB5IYDb3oS I2NrvDkBMNtRyQj2XbC4zTEV+thetIrvWKPFb8pdW/UDayCZFjXKQiLpSMFDXyRkzIxa QhsonMhYs8Q4ynVu32DzToTjZxT4Eg8QbNf7NZJTKYKNI4vlvhqceBGGOgXAOd+Y700q 98GA== X-Forwarded-Encrypted: i=1; AJvYcCVtzZKLAOshPVCBqzqlZzVJ9w1xuDN1RP84IZ4gT9xu9Nu3N/iNYkSk55mtourJkANDlVfSg65UvXNO1XvG@postgresql.org X-Gm-Message-State: AOJu0YysMUYNCnHi0fgCBGxzvwsUd2EmZoSuEOKIeJPvOI3M/NvLf5MM jmwv8CQDpfIhD9oAtcsmOCL83XbN9euxDERLIC/oes5AhH9XBARU98QK X-Gm-Gg: AY/fxX5CDFUIouEDAOzxsF5QtcBEr2sKyqZ0xzTeA8tWbEfN0MiSQ+UIFjcSLgPAesz EjENG/GaDH9T/BqPedSTWP4OQfqEBVbBfjbKpDg6J1jp+eCofCbvvkxYET5fUJHhDWxkT5Cmb4H 7FI96b0yvL+b0/FTmmg90PxQxHI4q2DRH/kkid6ImyoRx7wxwgQ+iTkKFRHtp6U956TLKol/AW8 Ew5vfzAKi8yr15b5yX7JDt1rAIWpq+t+MNQlQ1m9XdIZ1kWKIRz5NZri7HQEjNfm7Jtz8IZ9iNO j+weJ9FY8yqMDKZhNjgB1W+yVqsAF2pLR6jJaiNxBcXQObowQWGF9Lw+1YzFTW+gOZ4IyMJGoyZ BC7Dyb9zbhXrm4rXEkzbF0tnIKQo9eHt27GUAJWK5+yjeALBUHxmzMPUGe3y6XqfZeyXjbrhXWE 0fmbbASDy7pDSgAM3Zbs4GeQRA1Q+xj2NUWKl/qlZsgGBKBVS1/HVT5bZzZhA+X6f7W0v6flY= X-Google-Smtp-Source: AGHT+IGuGYM7hYeeQuGf+JUF36jgdVv/3uX/+WiiKYrgsl1ybh7F8Zp9MsWRoxpND9oisb5q3UZjmA== X-Received: by 2002:a17:902:c952:b0:298:485d:5576 with SMTP id d9443c01a7336-29ec22ca921mr18536855ad.8.1765367325478; Wed, 10 Dec 2025 03:48:45 -0800 (PST) Received: from [10.255.187.72] (vip-148-139-2-229.cust.service-now.com. [148.139.2.229]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29daeae2552sm180222815ad.88.2025.12.10.03.48.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Dec 2025 03:48:45 -0800 (PST) Message-ID: Date: Wed, 10 Dec 2025 12:48:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Consistently use palloc_object() and palloc_array() To: Michael Paquier Cc: Tom Lane , Thomas Munro , Chao Li , pgsql-hackers References: <524587.1764365323@sss.pgh.pa.us> <1e7f0c17-a965-4d5b-ad88-b435a4d97490@gmail.com> <143d3184-b575-49bd-8bc1-f37f45f010cc@gmail.com> <534126.1764722446@sss.pgh.pa.us> <4ab4a12b-49e9-4ebf-9055-225c8055fed0@gmail.com> Content-Language: en-US From: David Geier In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Michael! Thanks for continuing applying the patches. On 09.12.2025 23:37, Michael Paquier wrote: > On Fri, Dec 05, 2025 at 04:41:41PM +0900, Michael Paquier wrote: >> Thanks. That's a lot to digest. > > Digesting a bit more now.. > > - char *ret = palloc(sizeof(buf)); > + char *ret = palloc_array(char, sizeof(buf)) > > This one in dumputils.c is right, but I am not sure that it is an > improvement compared to the statu-quo. Apart from saving casts, using the _array() and _object() variants improves readability as it's clear from the used macro what the code intents to do. For example. without knowing the type of buf, it's not immediately clear if this is allocating an array of the size of buf, or if it's allocating an object (e.g. if buf happened to be some struct that represents a buffer object). The amount of allocated memory would of course be the same, but how it's going to be used can be nicely derived from the used macro. > Here is a list of the files where I have noticed tha addition of > casts, which are not required anymore: > brin_tuple.c. > gistbuildbuffers.c. > genam.c. > nbtdedup.c. > nbtree.c. > nbtsort.c. > index.c > execGrouping.c > execMain.c > relnode.c > partbounds.c > mcv.c > spell.c > arrayfuncs.c > partcache.c > > Perhaps you have used a semi-automatic process and missed these? Do you mean in these files I forgot removing casts that got unnecessary after using _array() / _object()? It's possible that I missed some, given the large amount. Please fix them as you see fit. > One can argue that this one in bernouilli.c is not really necessary, > tsm_state is actually a void *. As stated above: this change is not only about saving casts but the macros convey the intent much better than a call to palloc(). > Among the 300-ish files changed in the backend, 48 of them had their > builds slightly change. The list of them is attached. Do you mean the disassembly because the number of lines of code changes? -- David Geier