Thread: [COMMITTERS] pgsql: Add new function dsa_allocate0.

[COMMITTERS] pgsql: Add new function dsa_allocate0.

From
Robert Haas
Date:
Add new function dsa_allocate0.

This does the same thing as dsa_allocate, except that the memory
is guaranteed to be zero-filled on return.

Dilip Kumar, adjusted by me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/9acb85597f1223ac26a5b19a9345849c43d0ff54

Modified Files
--------------
src/backend/utils/mmgr/dsa.c | 16 ++++++++++++++++
src/include/utils/dsa.h      |  1 +
2 files changed, 17 insertions(+)


Re: [COMMITTERS] pgsql: Add new function dsa_allocate0.

From
Thomas Munro
Date:
On Fri, Feb 17, 2017 at 7:02 AM, Robert Haas <rhaas@postgresql.org> wrote:
> Add new function dsa_allocate0.
>
> This does the same thing as dsa_allocate, except that the memory
> is guaranteed to be zero-filled on return.
>
> Dilip Kumar, adjusted by me.
>
> Branch
> ------
> master
>
> Details
> -------
> http://git.postgresql.org/pg/commitdiff/9acb85597f1223ac26a5b19a9345849c43d0ff54
>
> Modified Files
> --------------
> src/backend/utils/mmgr/dsa.c | 16 ++++++++++++++++
> src/include/utils/dsa.h      |  1 +
> 2 files changed, 17 insertions(+)

Hmm.  This will segfault if you're out of memory.

--
Thomas Munro
http://www.enterprisedb.com


Re: [COMMITTERS] pgsql: Add new function dsa_allocate0.

From
Thomas Munro
Date:
On Fri, Feb 17, 2017 at 11:34 AM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Fri, Feb 17, 2017 at 7:02 AM, Robert Haas <rhaas@postgresql.org> wrote:
>> http://git.postgresql.org/pg/commitdiff/9acb85597f1223ac26a5b19a9345849c43d0ff54
> Hmm.  This will segfault if you're out of memory.

Or to provide a more useful response... maybe this should be like the
attached?  Or maybe people think that dsa_allocate should throw on
failure to allocate, like palloc?

--
Thomas Munro
http://www.enterprisedb.com

Attachment

Re: [COMMITTERS] pgsql: Add new function dsa_allocate0.

From
Michael Paquier
Date:
On Fri, Feb 17, 2017 at 12:03 PM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Fri, Feb 17, 2017 at 11:34 AM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
>> On Fri, Feb 17, 2017 at 7:02 AM, Robert Haas <rhaas@postgresql.org> wrote:
>>> http://git.postgresql.org/pg/commitdiff/9acb85597f1223ac26a5b19a9345849c43d0ff54
>> Hmm.  This will segfault if you're out of memory.
>
> Or to provide a more useful response... maybe this should be like the
> attached?  Or maybe people think that dsa_allocate should throw on
> failure to allocate, like palloc?

     dp = dsa_allocate(area, size);
-    object = dsa_get_address(area, dp);
-    memset(object, 0, size);
+    if (DsaPointerIsValid(dp))
+        memset(dsa_get_address(area, dp), 0, size);
What you are proposing here looks like the right answer to me. Like
dsa_allocate, dsa_allocate0 should allow users to fallback to other
methods if what is returned is InvalidDsaPointer for consistency.
--
Michael