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.94.2) (envelope-from ) id 1u7AaT-00BsMt-FB for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Apr 2025 10:10:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u7AaQ-00D47k-UO for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Apr 2025 10:10:43 +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.94.2) (envelope-from ) id 1u7AaQ-00D47b-JQ for pgsql-hackers@lists.postgresql.org; Tue, 22 Apr 2025 10:10:43 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u7AaN-001O4a-32 for pgsql-hackers@lists.postgresql.org; Tue, 22 Apr 2025 10:10:43 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 7293D34B8F8 for ; Tue, 22 Apr 2025 12:10:40 +0200 (CEST) Received: from s979.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id 625CE34DD00; Tue, 22 Apr 2025 12:10:40 +0200 (CEST) Received: from s471.loopia.se (unknown [172.22.191.6]) by s979.loopia.se (Postfix) with ESMTP id 5EB8210BC4C8; Tue, 22 Apr 2025 12:10:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s471.loopia.se (amavisd-new); dkim=pass (2048-bit key) header.d=yesql.se Received: from s899.loopia.se ([172.22.191.5]) by s471.loopia.se (s471.loopia.se [172.22.190.35]) (amavisd-new, port 10024) with UTF8LMTP id bdiKsuEQRd5P; Tue, 22 Apr 2025 12:10:40 +0200 (CEST) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 90.229.0.9 Received: from smtpclient.apple (unknown [90.229.0.9]) (Authenticated sender: daniel@yesql.se) by s899.loopia.se (Postfix) with ESMTPSA id BC3662C8BABA; Tue, 22 Apr 2025 12:10:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yesql.se; s=loopiadkim1707475645; t=1745316639; bh=XmlcjUQ5NwnZLTXIdsk84xCArDvUStYP8BK+ar4rcvA=; h=From:Subject:Date:In-Reply-To:Cc:To:References; b=PJnWNtydDtGSW4seqAi5+X5jo4BQnFkomRtZnCbISQ+FokcPW7ZEUYM0nIo8zFvxW aKqvOG7S/5Fubz36BRM3JOiksI/tYokTMyw4Gl2vcxg6N5MvQT+VCrKCyGs8uj+LSL vKjIdyMgw8lQ7mWuuwxSyEje4vs7cqNGBXQBzb9rqjsDIMGiIjt0RdYa7lIHeVV8lp 8RwVB8eXS1vJUssZdkA0VyhawoHEcMpRmb5oR3jSTxn19fUBOaYrolEPlRCjpWNthL V7ZURnWpuon0aYc5GoK+Tu9YjD/8iG0IfxLncG9NUceJQi+kD3KQaw9NnNCBDc6Nff GICjkg9msSYzQ== From: Daniel Gustafsson Message-Id: <0C92C876-09A3-483C-82C5-E26F0C1B34B5@yesql.se> Content-Type: multipart/mixed; boundary="Apple-Mail=_0BAD372B-A8CE-4356-B2C0-344EA112A4D5" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: jsonapi: scary new warnings with LTO enabled Date: Tue, 22 Apr 2025 12:10:29 +0200 In-Reply-To: Cc: Tom Lane , PostgreSQL Developers To: Jacob Champion References: <2074634.1744839761@sss.pgh.pa.us> <0A3CF5C4-9947-42E3-89A9-34FCF7BA95BA@yesql.se> <2078511.1744841564@sss.pgh.pa.us> <2084687.1744844690@sss.pgh.pa.us> <2087556.1744846124@sss.pgh.pa.us> <0A596D8B-24F3-408F-B89B-B42014B00A05@yesql.se> <2202326.1744903233@sss.pgh.pa.us> <25801148-284F-41F9-A279-A4CF92623C77@yesql.se> <102E1997-FB99-4091-926C-9A8BB3EA168E@yesql.se> X-Mailer: Apple Mail (2.3776.700.51.11.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_0BAD372B-A8CE-4356-B2C0-344EA112A4D5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 21 Apr 2025, at 20:58, Jacob Champion = wrote: > Personally, I'm fine with can't-fail APIs, as long as they're > documented as such. (I think the deferred error API was probably > chosen so that src/common JSON clients could be written without a lot > of pain?) My preference is that no operation can silently work on a failed object, = but it's not a hill (even more so given where we are in the cycle). The = attached v3 allocates via the JSON api, no specific error handling should be = required as it's already handled today. -- Daniel Gustafsson --Apple-Mail=_0BAD372B-A8CE-4356-B2C0-344EA112A4D5 Content-Disposition: attachment; filename=v3-0001-Allocate-JsonLexContexts-on-the-heap-to-avoid-war.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v3-0001-Allocate-JsonLexContexts-on-the-heap-to-avoid-war.patch" Content-Transfer-Encoding: quoted-printable =46rom=20fe421d657aaa361dfb796e28c96975bed97f79f5=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Daniel=20Gustafsson=20= =0ADate:=20Thu,=2017=20Apr=202025=2023:18:58=20= +0200=0ASubject:=20[PATCH=20v3]=20Allocate=20JsonLexContexts=20on=20the=20= heap=20to=20avoid=20warnings=0A=0AThe=20stack=20allocated=20= JsonLexContexts,=20in=20combination=20with=20codepaths=0Ausing=20goto,=20= were=20causing=20warnings=20when=20compiling=20with=20LTO=20enabled=0Aas=20= the=20optimizer=20is=20unable=20to=20figure=20out=20that=20is=20safe.=20=20= Rather=20than=0Acontort=20the=20code=20with=20workarounds=20for=20this=20= simply=20heap=20allocate=20the=0Astructs=20instead=20as=20these=20are=20= not=20in=20any=20performance=20critical=20paths.=0A=0AReported-by:=20Tom=20= Lane=20=0AReviewed-by:=20Jacob=20Champion=20= =0AReviewed-by:=20Tom=20Lane=20= =0ADiscussion:=20= https://postgr.es/m/2074634.1744839761@sss.pgh.pa.us=0A---=0A=20= src/interfaces/libpq/fe-auth-oauth.c=20=20=20=20=20=20=20=20=20=20|=2012=20= +++++-----=0A=20.../test_json_parser_incremental.c=20=20=20=20=20=20=20=20= =20=20=20=20|=2023=20+++++++++++--------=0A=202=20files=20changed,=2020=20= insertions(+),=2015=20deletions(-)=0A=0Adiff=20--git=20= a/src/interfaces/libpq/fe-auth-oauth.c=20= b/src/interfaces/libpq/fe-auth-oauth.c=0Aindex=20= cf1a25e2ccc..52d2b286625=20100644=0A---=20= a/src/interfaces/libpq/fe-auth-oauth.c=0A+++=20= b/src/interfaces/libpq/fe-auth-oauth.c=0A@@=20-476,7=20+476,7=20@@=20= issuer_from_well_known_uri(PGconn=20*conn,=20const=20char=20*wkuri)=0A=20= static=20bool=0A=20handle_oauth_sasl_error(PGconn=20*conn,=20const=20= char=20*msg,=20int=20msglen)=0A=20{=0A-=09JsonLexContext=20lex=20=3D=20= {0};=0A+=09JsonLexContext=20*lex;=0A=20=09JsonSemAction=20sem=20=3D=20= {0};=0A=20=09JsonParseErrorType=20err;=0A=20=09struct=20json_ctx=20ctx=20= =3D=20{0};=0A@@=20-504,8=20+504,8=20@@=20handle_oauth_sasl_error(PGconn=20= *conn,=20const=20char=20*msg,=20int=20msglen)=0A=20=09=09return=20false;=0A= =20=09}=0A=20=0A-=09makeJsonLexContextCstringLen(&lex,=20msg,=20msglen,=20= PG_UTF8,=20true);=0A-=09setJsonLexContextOwnsTokens(&lex,=20true);=09/*=20= must=20not=20leak=20on=20error=20*/=0A+=09lex=20=3D=20= makeJsonLexContextCstringLen(NULL,=20msg,=20msglen,=20PG_UTF8,=20true);=0A= +=09setJsonLexContextOwnsTokens(lex,=20true);=09/*=20must=20not=20leak=20= on=20error=20*/=0A=20=0A=20=09initPQExpBuffer(&ctx.errbuf);=0A=20=09= sem.semstate=20=3D=20&ctx;=0A@@=20-516,7=20+516,7=20@@=20= handle_oauth_sasl_error(PGconn=20*conn,=20const=20char=20*msg,=20int=20= msglen)=0A=20=09sem.array_start=20=3D=20oauth_json_array_start;=0A=20=09= sem.scalar=20=3D=20oauth_json_scalar;=0A=20=0A-=09err=20=3D=20= pg_parse_json(&lex,=20&sem);=0A+=09err=20=3D=20pg_parse_json(lex,=20= &sem);=0A=20=0A=20=09if=20(err=20=3D=3D=20JSON_SEM_ACTION_FAILED)=0A=20=09= {=0A@@=20-535,7=20+535,7=20@@=20handle_oauth_sasl_error(PGconn=20*conn,=20= const=20char=20*msg,=20int=20msglen)=0A=20=09=09}=0A=20=09}=0A=20=09else=20= if=20(err=20!=3D=20JSON_SUCCESS)=0A-=09=09errmsg=20=3D=20= json_errdetail(err,=20&lex);=0A+=09=09errmsg=20=3D=20json_errdetail(err,=20= lex);=0A=20=0A=20=09if=20(errmsg)=0A=20=09=09= libpq_append_conn_error(conn,=0A@@=20-544,7=20+544,7=20@@=20= handle_oauth_sasl_error(PGconn=20*conn,=20const=20char=20*msg,=20int=20= msglen)=0A=20=0A=20=09/*=20Don't=20need=20the=20error=20buffer=20or=20= the=20JSON=20lexer=20anymore.=20*/=0A=20=09termPQExpBuffer(&ctx.errbuf);=0A= -=09freeJsonLexContext(&lex);=0A+=09freeJsonLexContext(lex);=0A=20=0A=20=09= if=20(errmsg)=0A=20=09=09goto=20cleanup;=0Adiff=20--git=20= a/src/test/modules/test_json_parser/test_json_parser_incremental.c=20= b/src/test/modules/test_json_parser/test_json_parser_incremental.c=0A= index=20a529ee47e9b..d1e3e4ab4ea=20100644=0A---=20= a/src/test/modules/test_json_parser/test_json_parser_incremental.c=0A+++=20= b/src/test/modules/test_json_parser/test_json_parser_incremental.c=0A@@=20= -84,7=20+84,7=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09char=09=09= buff[BUFSIZE];=0A=20=09FILE=09=20=20=20*json_file;=0A=20=09= JsonParseErrorType=20result;=0A-=09JsonLexContext=20lex;=0A+=09= JsonLexContext=20*lex;=0A=20=09StringInfoData=20json;=0A=20=09int=09=09=09= n_read;=0A=20=09size_t=09=09chunk_size=20=3D=20DEFAULT_CHUNK_SIZE;=0A@@=20= -98,6=20+98,10=20@@=20main(int=20argc,=20char=20**argv)=0A=20=0A=20=09= pg_logging_init(argv[0]);=0A=20=0A+=09lex=20=3D=20calloc(1,=20= sizeof(JsonLexContext));=0A+=09if=20(!lex)=0A+=09=09pg_fatal("out=20of=20= memory");=0A+=0A=20=09while=20((c=20=3D=20getopt(argc,=20argv,=20= "c:os"))=20!=3D=20-1)=0A=20=09{=0A=20=09=09switch=20(c)=0A@@=20-113,7=20= +117,7=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09=09=09case=20= 's':=09=09=09/*=20do=20semantic=20processing=20*/=0A=20=09=09=09=09= testsem=20=3D=20&sem;=0A=20=09=09=09=09sem.semstate=20=3D=20= palloc(sizeof(struct=20DoState));=0A-=09=09=09=09((struct=20DoState=20*)=20= sem.semstate)->lex=20=3D=20&lex;=0A+=09=09=09=09((struct=20DoState=20*)=20= sem.semstate)->lex=20=3D=20lex;=0A=20=09=09=09=09((struct=20DoState=20*)=20= sem.semstate)->buf=20=3D=20makeStringInfo();=0A=20=09=09=09=09= need_strings=20=3D=20true;=0A=20=09=09=09=09break;=0A@@=20-131,8=20= +135,8=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09=09exit(1);=0A=20= =09}=0A=20=0A-=09makeJsonLexContextIncremental(&lex,=20PG_UTF8,=20= need_strings);=0A-=09setJsonLexContextOwnsTokens(&lex,=20= lex_owns_tokens);=0A+=09makeJsonLexContextIncremental(lex,=20PG_UTF8,=20= need_strings);=0A+=09setJsonLexContextOwnsTokens(lex,=20= lex_owns_tokens);=0A=20=09initStringInfo(&json);=0A=20=0A=20=09if=20= ((json_file=20=3D=20fopen(testfile,=20PG_BINARY_R))=20=3D=3D=20NULL)=0A= @@=20-165,12=20+169,12=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09=09= bytes_left=20-=3D=20n_read;=0A=20=09=09if=20(bytes_left=20>=200)=0A=20=09= =09{=0A-=09=09=09result=20=3D=20pg_parse_json_incremental(&lex,=20= testsem,=0A+=09=09=09result=20=3D=20pg_parse_json_incremental(lex,=20= testsem,=0A=20=09=09=09=09=09=09=09=09=09=09=09=20=20=20json.data,=20= n_read,=0A=20=09=09=09=09=09=09=09=09=09=09=09=20=20=20false);=0A=20=09=09= =09if=20(result=20!=3D=20JSON_INCOMPLETE)=0A=20=09=09=09{=0A-=09=09=09=09= fprintf(stderr,=20"%s\n",=20json_errdetail(result,=20&lex));=0A+=09=09=09= =09fprintf(stderr,=20"%s\n",=20json_errdetail(result,=20lex));=0A=20=09=09= =09=09ret=20=3D=201;=0A=20=09=09=09=09goto=20cleanup;=0A=20=09=09=09}=0A= @@=20-178,12=20+182,12=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09=09= }=0A=20=09=09else=0A=20=09=09{=0A-=09=09=09result=20=3D=20= pg_parse_json_incremental(&lex,=20testsem,=0A+=09=09=09result=20=3D=20= pg_parse_json_incremental(lex,=20testsem,=0A=20=09=09=09=09=09=09=09=09=09= =09=09=20=20=20json.data,=20n_read,=0A=20=09=09=09=09=09=09=09=09=09=09=09= =20=20=20true);=0A=20=09=09=09if=20(result=20!=3D=20JSON_SUCCESS)=0A=20=09= =09=09{=0A-=09=09=09=09fprintf(stderr,=20"%s\n",=20= json_errdetail(result,=20&lex));=0A+=09=09=09=09fprintf(stderr,=20= "%s\n",=20json_errdetail(result,=20lex));=0A=20=09=09=09=09ret=20=3D=20= 1;=0A=20=09=09=09=09goto=20cleanup;=0A=20=09=09=09}=0A@@=20-195,8=20= +199,9=20@@=20main(int=20argc,=20char=20**argv)=0A=20=0A=20cleanup:=0A=20= =09fclose(json_file);=0A-=09freeJsonLexContext(&lex);=0A+=09= freeJsonLexContext(lex);=0A=20=09free(json.data);=0A+=09free(lex);=0A=20=0A= =20=09return=20ret;=0A=20}=0A--=20=0A2.39.3=20(Apple=20Git-146)=0A=0A= --Apple-Mail=_0BAD372B-A8CE-4356-B2C0-344EA112A4D5--