[HACKERS] Custom allocators in libpq - Mailing list pgsql-hackers

From Aaron Patterson
Subject [HACKERS] Custom allocators in libpq
Date
Msg-id 20170828172834.GA71455@TC.local
Whole thread Raw
Responses Re: [HACKERS] Custom allocators in libpq  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello!

I would like to be able to configure libpq with custom malloc functions.
The reason is that we have a Ruby wrapper that exposes libpq in Ruby.
The problem is that Ruby's GC doesn't know how much memory has been
allocated by libpq, so no pressure is applied to the GC when it should
be.  Ruby exports malloc functions that automatically apply GC pressure,
and I'd like to be able to configure libpq to use those malloc
functions.

I've attached two patches that add this functionality.  The first patch
introduces a new function `PQunescapeByteaConn` which takes a
connection (so we have a place to get the malloc functions).  We already
have `PQescapeBytea` and `PQescapeByteaConn`, this first patch gives us
the analogous `PQunescapeBytea` and `PQunescapeByteaConn`.

The second patch adds malloc function pointer fields to `PGEvent`,
`pg_result`, and `pg_conn` structs, and changes libpq internals to use
those allocators rather than directly calling `malloc`.

This patch doesn't replace all malloc calls to the configured ones, just
the mallocs related to creating result objects (which is what I'm
concerned with).

If there's something I'm missing, please let me know.  This is my first
patch to libpq, so I look forward to hearing feedback.  Thanks for your
time!

-- 
Aaron Patterson
http://tenderlovemaking.com/

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachment

pgsql-hackers by date:

Previous
From: Antonin Houska
Date:
Subject: [HACKERS] Write operations in parallel mode
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] [BUGS] [postgresql 10 beta3] unrecognized node type: 90