Re: custom function for converting human readable sizes to bytes - Mailing list pgsql-hackers

From Vitaly Burovoy
Subject Re: custom function for converting human readable sizes to bytes
Date
Msg-id CAKOSWN=w37cahg93D1vmoftn0+_QzvgQQ1VBFOD=Fh6op3qmMA@mail.gmail.com
Whole thread Raw
In response to Re: custom function for converting human readable sizes to bytes  (Vitaly Burovoy <vitaly.burovoy@gmail.com>)
Responses Re: custom function for converting human readable sizes to bytes
List pgsql-hackers
On 2/16/16, Vitaly Burovoy <vitaly.burovoy@gmail.com> wrote:
> On 2/16/16, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>> Fixing that in parse_memory_unit() would be messy because it assumes a
>> base unit of kB, so it would require a negative multiplier, and
>> pg_size_bytes() would have to be taught to divide by the magnitude of
>> negative multipliers in the same way that guc.c does.

Now parse_memory_unit returns -1024 for bytes as divider, constant
"bytes" has moved there.
Add new memory_units_bytes_hint which differs from an original
memory_units_int by "bytes" size unit.
Allow hintmsg be NULL and if so, skip setting dereferenced variable to
memory_units_bytes_hint.

>> ISTM that it would be far less code, and much simpler and more
>> readable to just parse the supported units directly in
>> pg_size_bytes(), rather than trying to share code with guc.c, when the
>> supported units are actually different and may well diverge further in
>> the future.
>
> Initially it was not shared with guc.c and now it is by the letter[1]
> of Oleksandr Shulgin and Robert Haas.
>
>> I'll try to hack something up, and see what it looks like.
>>
>> Regards,
>> Dean

Current version contains correct hint message, it passes tests.
Besides mentioned above there are some comment rewordings, and
variable renaming.

[1]http://www.postgresql.org/message-id/CA+TgmoaNoT7uGjsbiBFUQgacHk2LZrypMKJVVUgp5r197YUvTg@mail.gmail.com

--
Best regards,
Vitaly Burovoy

Attachment

pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: proposal: function parse_ident
Next
From: Michael Paquier
Date:
Subject: Re: exposing pg_controldata and pg_config as functions