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 1o7E7Z-0004wn-Jl for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 10:43:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7E7Y-00069g-Eb for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 10:43:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7E7X-00069U-0N for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 10:43:32 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7E7T-00036h-OU for pgsql-hackers@postgresql.org; Fri, 01 Jul 2022 10:43:29 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 444A95C0210; Fri, 1 Jul 2022 06:43:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 01 Jul 2022 06:43:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1656672204; x=1656758604; bh=yZ81wXJhjQ 1X9301PSjtSI9AsMmZFr2tLEZ66xgnhZ8=; b=QES46SmLY2zwPvw+L3e7Wsyh8O V4ic83uspfXEWETwlB8Vn8CCA7Ofr3ZLLZ0S16TH9s6xq/m0rOsFf7LitAVsrUPN 3Ro+4UXFMegKMq/pM+kISSNmbieUmG+i+oxsCUn/nXeUrLdUvhAePanJ1JZORUdU 5m937bhtDkDG3Q0UHC/4dSGud0peN7wWBBfrsKGCrX2vaR6/ONWpwJLfDT66PeG/ XtCfQ33wzT8qsdKNTdy2OSrGMyBinrZ9cOps9We4K9zXDlu+nP/tk5nCvwBNGHiO frkcUVSJMSBEyrIXcgv1t5tt7Tio2fnwjb1dLnp3PsgsOwBykPvN4Lhy1QVA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1656672204; x=1656758604; bh=yZ81wXJhjQ1X9301PSjtSI9AsMmZ Fr2tLEZ66xgnhZ8=; b=naqrEN4MwXTjHZGSEIHoQNrDnt7e0t4bITQrtJfnznaL JfO08ddmFmUsA89iGxmN1+Y1qgO+3Lvnv/t9lJKIwzwtOBu/48v3LJ8rBbRhmWTD Zc2f91sy7649BJZixeazcjS7epEC6DI1qdiIBiAiZEN0pqktFyYpMz03ytQxnMnk 9zcyCMYKA9kfI9IWcLFe8M78gpYgzpHoVzF7Lu6CJqG6ZOBlv/cnCfLKodbYS6og xwwU0kN6bspHA6nmHSrM5mKEPOa3ZoTewV7RWo6vb50I+8HtvT+Y1m2qa/u/leyH kZPvRVJgYK+dxo0Z32qPVTM/bk3RwszKzp1FwHohyg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudehfedgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufhffjgfkfgggtgesthdtredttderjeenucfhrhhomhepffgrghhf ihhnnhgpkfhlmhgrrhhipgforghnnhhsnohkvghruceoihhlmhgrrhhisehilhhmrghrih drohhrgheqnecuggftrfgrthhtvghrnhepgeehhffhgfefteffgeduiedvueettefgleff vdehffdukeduteejiefhfeegvdelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepihhlmhgrrhhisehilhhmrghrihdrohhrgh X-ME-Proxy: Feedback-ID: i1ff147bf:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Jul 2022 06:43:23 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: Peter Eisentraut Cc: Tom Lane , pgsql-hackers Subject: Re: Refactor construct_array() and deconstruct_array() for built-in types References: <2914356f-9e5f-8c59-2995-5997fc48bcba@enterprisedb.com> <1844517.1651502932@sss.pgh.pa.us> Date: Fri, 01 Jul 2022 11:43:21 +0100 In-Reply-To: (Peter Eisentraut's message of "Fri, 1 Jul 2022 11:41:37 +0200") Message-ID: <871qv5kt9y.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Eisentraut writes: > On 02.05.22 16:48, Tom Lane wrote: >> Peter Eisentraut writes: >>> There are many calls to construct_array() and deconstruct_array() for >>> built-in types, for example, when dealing with system catalog columns. >>> These all hardcode the type attributes necessary to pass to these functions. >> >>> To simplify this a bit, add construct_array_builtin(), >>> deconstruct_array_builtin() as wrappers that centralize this hardcoded >>> knowledge. This simplifies many call sites and reduces the amount of >>> hardcoded stuff that is spread around. >> >>> I also considered having genbki.pl generate lookup tables for these >>> hardcoded values, similar to schemapg.h, but that ultimately seemed >>> excessive. >> +1 --- the added overhead of the switch statements is probably a >> reasonable price to pay for the notational simplification and >> bug-proofing. >> One minor coding gripe is that compilers that don't know that >> elog(ERROR) >> doesn't return will certainly generate "use of possibly-uninitialized >> variable" complaints. Suggest inserting "return NULL;" or similar into >> the default: cases. I'd also use more specific error wording to help >> people find where they need to add code when they make use of a new type; >> maybe like "type %u not supported by construct_array_builtin". > > I have pushed this with the improvements you had suggested. I dind't pay much attention to this thread earlier, but I was struck by the duplication of the switch statement determining the elemlen, elembyval, and elemalign values between the construct and deconstruct functions. How about a common function they can both call? Something like: static void builtin_type_details(Oid elemtype, int *elemlen, bool *elembyval, char *elemalign); - ilmari