Re: [PATCH] OAuth: fix performance bug with stuck multiplexer events

From: Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>
To: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Daniel Gustafsson <daniel(at)yesql(dot)se>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: [PATCH] OAuth: fix performance bug with stuck multiplexer events
Date: 2025-08-08 21:16:22
Message-ID: 87cy95h5uh.fsf@wibble.ilmari.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com> writes:

> On Fri, Aug 8, 2025 at 1:07 PM Dagfinn Ilmari Mannsåker
> <ilmari(at)ilmari(dot)org> wrote:
>> $ perl -MJSON::PP=encode_json -E 'say encode_json([1, 2, 3])'
>> [1,2,3]
>>
>> $ perl -MJSON::PP=encode_json -E 'say encode_json([1 => (2, 3)])'
>> [1,2,3]
>
> I swear, this language.
>
> But:
>
> $ perl -MJSON::PP=encode_json -E 'say encode_json(1,2)'
> Too many arguments for JSON::PP::encode_json at -e line 1, near "2)
> $ perl -MJSON::PP=encode_json -E 'say encode_json((1,2))'
> 2
>
> So what's going on there? (Google is not very helpful for these sorts
> of Perl problems; I don't even know how to describe this.)

That's because encode_json has a prototype[1], which changes how the
argument list is parsed: no longer just as a flat list of values like a
normal function. Specifically, it has a prototype of '$', which means
it only takes one argument, which is evaluated in scalar context. So
the first example is a syntax error, but in the second example the
parenthesised expression is the single argument. Becuse it's in scalar
context, the comma is actually the scalar comma operator, not the list
element separator, so the return value is the right-hand side of the
comma (just like in C), not the length of the would-be list.
Onfusingly, they are both 2 here (which is why 1,2,3,... are bad values
to use when exploring presedence/context issues in Perl, sorry for doing
that in my example). More clearly (fsvo):

$ perl -MJSON::PP=encode_json -E 'say encode_json((11,12))'
12

- ilmari

[1] https://perldoc.perl.org/perlsub#Prototypes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-08-08 21:23:13 Re: Broken ./configure checks for __cpuid() and __cpuidex()
Previous Message Andres Freund 2025-08-08 21:12:58 Re: Custom pgstat support performance regression for simple queries