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 1puJBT-0005Ze-RT for pgsql-hackers@arkaria.postgresql.org; Wed, 03 May 2023 20:34:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1puJAU-0002Yn-En for pgsql-hackers@arkaria.postgresql.org; Wed, 03 May 2023 20:33:42 +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 1puJAU-0002Ye-5d for pgsql-hackers@lists.postgresql.org; Wed, 03 May 2023 20:33:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1puJAQ-000PDQ-J2 for pgsql-hackers@postgresql.org; Wed, 03 May 2023 20:33:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 343KXWx43012767; Wed, 3 May 2023 16:33:32 -0400 From: Tom Lane To: Nathan Bossart cc: Andres Freund , Xing Guo , pgsql-hackers@postgresql.org Subject: Re: PL/Python: Fix return in the middle of PG_TRY() block. In-reply-to: <20230503202116.GA2110623@nathanxps13> References: <20230112184433.GA2104952@nathanxps13> <20230113054900.b7onkvwtkrykeu3z@awork3.anarazel.de> <20230113180335.GA2160040@nathanxps13> <1864041.1673882943@sss.pgh.pa.us> <20230120010711.jpqbaelpgmuvt2vq@awork3.anarazel.de> <20230120190201.GC4106863@nathanxps13> <20230503202116.GA2110623@nathanxps13> Comments: In-reply-to Nathan Bossart message dated "Wed, 03 May 2023 13:21:16 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3012765.1683146012.1@sss.pgh.pa.us> Date: Wed, 03 May 2023 16:33:32 -0400 Message-ID: <3012766.1683146012@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Bossart writes: > Here's a new version of the patch. Besides adding comments and a commit > message, I made sure to decrement the reference count for pltargs in the > PG_CATCH block (which means that pltargs likely needs to be volatile). Hmm, actually I think these changes should allow you to *remove* some volatile markers. IIUC, you need volatile for variables that are declared outside PG_TRY but modified within it. That is the case for these pointers as the code stands, but your patch is changing them to the non-risky case where they are assigned once before entering PG_TRY. (My mental model of this is that without "volatile", the compiler may keep the variable in a register, creating the hazard that longjmp will revert the variable's value to what it was at setjmp time thanks to the register save/restore that those functions do. But if it hasn't changed value since entering PG_TRY, then that doesn't matter.) > I'm > not too wild about moving the chunk of code for pltargs like this, but I > haven't thought of a better option. We could error instead of returning > NULL, but IIUC that would go against d0aa965's stated purpose. Agreed, throwing an error in these situations doesn't improve matters. regards, tom lane