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 1pGOP5-0002Vp-P5 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Jan 2023 18:03:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pGOP4-00085X-6v for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Jan 2023 18:03:46 +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 1pGOP3-00085O-RJ for pgsql-hackers@lists.postgresql.org; Fri, 13 Jan 2023 18:03:45 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pGOOx-0007ZK-5M for pgsql-hackers@postgresql.org; Fri, 13 Jan 2023 18:03:44 +0000 Received: by mail-pg1-x52e.google.com with SMTP id 36so15494142pgp.10 for ; Fri, 13 Jan 2023 10:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7dG6W2R5Rp9xEZu/f7pxmsinqq4rCdCrE3fIWPKajt0=; b=OitqzsSP4GtVGnnELA9tydkDhvwKNyE7TUj0N7QB51kr7y1i0bQZI0qs2AJE8rvNsj ZehncmkqzW4/IVgLrDJqqRegL4nQ/le+kt0KGCElzwKEsKXLFTZqQ2H4K8mMb718qyyy y1o1JRDT+HoKloCEtiV1W3JnxJtbYp+mv+sPBR7glBncJA2RWjkLKfKTiBZ0KsAhx3XX eklKPu+InUB3tULBctRwQ7+loKkAQnaxlxwv0RTxtOzibxhV+t9Rq9Xehrxz9PI0be6U 2qbmOx0T6y+y1SRLjpv8lKGkpvEtFJlUKYbnIc3VLP+XYWK/oUXCnuLgkDbKftSxx6of O+ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7dG6W2R5Rp9xEZu/f7pxmsinqq4rCdCrE3fIWPKajt0=; b=Uqn7x0u/cMg5/fXJukdHl1OdJbFSMuhGBZnFaQ4tCfPl5s0u3Ff3ucTCAAixSJ8FZ/ Ji/kWG0CJ6bquCI2xL/Bx5+YRGWexXvav6+mm1LoePE8aVOAMp//hXYbQpSpUuv7YIZa HtZUsFCKp2/Yau7XsSj8apjitdQO8K5p4DCiJtO0wB96xn9jyxon9uQN2jlNiOyNxMf0 JP1kHIo4kCkjCR+TiXA6eqvYXyoXgHRg3Gb/LuwEwo942neHP+P6rpf/9cyE+2nAebsL HtSlXpFnOB/7U77am0Lk8ewDPFr1plp29OpsE2KBRrJu2rmUy1Lg4OTWlmindb2VDexj M8Wg== X-Gm-Message-State: AFqh2kpQxR9G9vo3ILZx2GvuCf+Jv6IM7t6F0k+YZmYgSvxMFUE4757C zvHZjlvK3DAcarc/oBzx+9FmGlY5S1o= X-Google-Smtp-Source: AMrXdXs8o2/kSz4fJx35Z46HxPV+lXz1peCrlYc8IMVDhzfka7VXxHWY4g5OOkfz9N0IFRSThX74Ng== X-Received: by 2002:aa7:98ce:0:b0:58b:25f9:52c1 with SMTP id e14-20020aa798ce000000b0058b25f952c1mr12704609pfm.31.1673633018028; Fri, 13 Jan 2023 10:03:38 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id i15-20020a62870f000000b005890c5ed925sm9446882pfe.198.2023.01.13.10.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:03:37 -0800 (PST) Date: Fri, 13 Jan 2023 10:03:35 -0800 From: Nathan Bossart To: Andres Freund Cc: Xing Guo , pgsql-hackers@postgresql.org Subject: Re: PL/Python: Fix return in the middle of PG_TRY() block. Message-ID: <20230113180335.GA2160040@nathanxps13> References: <20230112184433.GA2104952@nathanxps13> <20230113054900.b7onkvwtkrykeu3z@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230113054900.b7onkvwtkrykeu3z@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 12, 2023 at 09:49:00PM -0800, Andres Freund wrote: > On 2023-01-12 10:44:33 -0800, Nathan Bossart wrote: >> There's another "return" later on in this PG_TRY block. I wonder if it's >> possible to detect this sort of thing at compile time. > > Clang provides some annotations that allow to detect this kind of thing. I > hacked up a test for this, and it finds quite a bit of prolematic > code. Nice! > plpython is, uh, not being good? But also in plperl, pltcl. Yikes. > ../../../../home/andres/src/postgresql/src/pl/tcl/pltcl.c:1830:1: warning: no_returns_in_pg_try 'no_returns_handle' is not held on every path through here [-Wthread-safety-analysis] > } > ^ > ../../../../home/andres/src/postgresql/src/pl/tcl/pltcl.c:1809:2: note: no_returns_in_pg_try acquired here > PG_CATCH(); > ^ > ../../../../home/andres/src/postgresql/src/include/utils/elog.h:433:7: note: expanded from macro 'PG_CATCH' > no_returns_start(no_returns_handle##__VA_ARGS__) > ^ > > Not perfect digestible, but also not too bad. I pushed the > no_returns_start()/no_returns_stop() calls into all the PG_TRY related macros, > because that causes the warning to point to block that the problem is > in. E.g. above the first warning points to PG_TRY, the second to > PG_CATCH. It'd work to just put it into PG_TRY and PG_END_TRY. This seems roughly as digestible as the pg_prevent_errno_in_scope stuff. However, on my macOS machine with clang 14.0.0, the messages say "mutex" instead of "no_returns_in_pg_try," which is unfortunate since that's the part that would clue me into what the problem is. I suppose it'd be easy enough to figure out after a grep or two, though. > Clearly this would need a bunch more work, but it seems promising? I think > there'd be other uses than this. +1 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com