Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqYUk-0007HA-7i for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Nov 2022 11:34:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oqYUj-0001mc-3l for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Nov 2022 11:34:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqYUi-0001mS-PZ for pgsql-hackers@lists.postgresql.org; Thu, 03 Nov 2022 11:34:48 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oqYUg-0003qA-Na for pgsql-hackers@lists.postgresql.org; Thu, 03 Nov 2022 11:34:48 +0000 Received: by mail-lj1-x22e.google.com with SMTP id u11so1815905ljk.6 for ; Thu, 03 Nov 2022 04:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:content-language:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=JyFaencYtwowP12z2IUKIUKstl4JLcOeDYywtCBIhEY=; b=K278SFFgHN7/bDlp7B57HcA2fi5ZIy9e//kkrlLfNoA8zv1nhqRfu3AZEVq4f7wfdG GKnzmSzSR+uAdBiGz+6CxR4Yi9SZuBuoC8OR4yNQaytiFa2UjLijoSDvg6oIuwANF3Nu ZMCWZqZgkCBKq4BdXPNvCwsPG9wAoWEK2wNEEt0tt7fhH7HmZduyulX7N92RCjcghMNm Cy1VNIAotrkERouHe/AI1me2XOs6B6fBadv0ZYpCKfPqnk8U5c8jYCfjLWDDcO5uIkHU TeHWV/NpE0eno5BEm0Xdwco/bmhXYGvc1kPURNIiulm+4+wdHBX1Z5Mbne60lbR2zsdA TAsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:content-language:subject:from:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JyFaencYtwowP12z2IUKIUKstl4JLcOeDYywtCBIhEY=; b=O2gW+HjAX5OWCal2zvrxrS2NFAC8ZZO2ICpjPV/HILzSeTHyVtmTWAqASr6J0/ewzy Yk/J3ZRQ3JuJGJYSakSIvmrFi0aLgwFoRjUEG2A5Ny1OnDh34wBd02TahkUdGV50fDE/ dWFCqw9jeDe84KPuQ/5DDdKFwfX+fC1xWHpr4eiOaAjZJ/LPkZIgD20r2/r+0vlSsquS mrCLMITEyXSHKGpXG/uqlwffKLrque9Rnw7zh2d2rJih7BeFUciptnfz66mbBqculoIA yVHbXx86yrLvnQM+Ajrpt5n1YZmIu7D1TUS4HfVCzaUrWtkqR1+0YymRcC2B9oQyU1wA pdyw== X-Gm-Message-State: ACrzQf0ZXuXjDVJ8i+Tn4Hn3Aray3duwpU08XDmRU84o/BO0nzNJv+NX Y9rL1aocVdksC+cT1Oy580aBNoyucaI= X-Google-Smtp-Source: AMsMyM6jyF5zY205/Ill7CKvXBm1KkgxICq7KXcGCrnhNQV4u2BDjGhJadQHRy/5xBwOM14v4/bhWQ== X-Received: by 2002:a05:651c:17a2:b0:277:f00:1841 with SMTP id bn34-20020a05651c17a200b002770f001841mr11983144ljb.166.1667475284636; Thu, 03 Nov 2022 04:34:44 -0700 (PDT) Received: from [172.16.209.129] ([165.225.206.252]) by smtp.gmail.com with ESMTPSA id p2-20020ac24ec2000000b004a4251c7f75sm97342lfr.202.2022.11.03.04.34.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Nov 2022 04:34:44 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------yVRu8FR4PqcMaZBfCm86yKWu" Message-ID: Date: Thu, 3 Nov 2022 12:34:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 From: David Geier Subject: Add explicit casts in four places to simplehash.h Content-Language: en-US To: PostgreSQL Developers List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------yVRu8FR4PqcMaZBfCm86yKWu Content-Type: multipart/alternative; boundary="------------pVtIL9dq5aHmI1NSHtj1Tg2F" --------------pVtIL9dq5aHmI1NSHtj1Tg2F Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi hackers, While working on an extension, I found that simplehash.h is missing explicit casts in four places. Without these casts, compiling code including simplehash.h yields warnings if the code is compiled with -Wc++-compat. PostgreSQL seems to mostly prefer omitting the explicit casts, however there are many places where an explicit cast is actually used. Among many others, see e.g. bool.c:     state = (BoolAggState *) MemoryContextAlloc(agg_context, sizeof(BoolAggState)); domains.c:    my_extra = (DomainIOData *) MemoryContextAlloc(mcxt, sizeof(DomainIOData)); What about, while not being strictly necessary for PostgreSQL itself, also adding such casts to simplehash.h so that it can be used in code where -Wc++-compat is enabled? Attached is a small patch that adds the aforementioned casts. Thanks for your consideration! -- David Geier (ServiceNow) --------------pVtIL9dq5aHmI1NSHtj1Tg2F Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi hackers,

While working on an extension, I found that simplehash.h is missing explicit casts in four places. Without these casts, compiling code including simplehash.h yields warnings if the code is compiled with -Wc++-compat.

PostgreSQL seems to mostly prefer omitting the explicit casts, however there are many places where an explicit cast is actually used. Among many others, see e.g.

bool.c:
    state = (BoolAggState *) MemoryContextAlloc(agg_context, sizeof(BoolAggState));

domains.c:
   my_extra = (DomainIOData *) MemoryContextAlloc(mcxt, sizeof(DomainIOData));

What about, while not being strictly necessary for PostgreSQL itself, also adding such casts to simplehash.h so that it can be used in code where -Wc++-compat is enabled?

Attached is a small patch that adds the aforementioned casts.
Thanks for your consideration!

--
David Geier
(ServiceNow)

--------------pVtIL9dq5aHmI1NSHtj1Tg2F-- --------------yVRu8FR4PqcMaZBfCm86yKWu Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-explicit-casts-to-simplehash.h.patch" Content-Disposition: attachment; filename="0001-Add-explicit-casts-to-simplehash.h.patch" Content-Transfer-Encoding: base64 RnJvbSBkMjY2NWI0MDY1MjI3ZmZhNmVmZDM3ZWU5MTJlNGFkZDA4Mjg2OWNiIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBEYXZpZCBHZWllciA8Z2VpZGF2LnBnQGdtYWlsLmNv bT4KRGF0ZTogVGh1LCAzIE5vdiAyMDIyIDEyOjI4OjA4ICswMTAwClN1YmplY3Q6IFtQQVRD SF0gQWRkIGV4cGxpY2l0IGNhc3RzIHRvIHNpbXBsZWhhc2guaAoKV2l0aG91dCB0aGVzZSBj YXN0cyBjb21waWxhdGlvbiB5aWVsZHMgd2FybmluZ3Mgd2hlbiBjb21waWxpbmcgdGhlCmNv ZGUgd2l0aCAtV2MrKy1jb21wYXQuCi0tLQogc3JjL2luY2x1ZGUvbGliL3NpbXBsZWhhc2gu aCB8IDggKysrKy0tLS0KIDEgZmlsZSBjaGFuZ2VkLCA0IGluc2VydGlvbnMoKyksIDQgZGVs ZXRpb25zKC0pCgpkaWZmIC0tZ2l0IGEvc3JjL2luY2x1ZGUvbGliL3NpbXBsZWhhc2guaCBi L3NyYy9pbmNsdWRlL2xpYi9zaW1wbGVoYXNoLmgKaW5kZXggMzI5Njg3YzFhNS4uY2RmYWU1 MzdhMSAxMDA2NDQKLS0tIGEvc3JjL2luY2x1ZGUvbGliL3NpbXBsZWhhc2guaAorKysgYi9z cmMvaW5jbHVkZS9saWIvc2ltcGxlaGFzaC5oCkBA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