MemoryContext and NodeTags

From: Thomas Hallgren <thomas(dot)hallgren(at)home(dot)se>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: MemoryContext and NodeTags
Date: 2005-10-17 13:32:03
Message-ID: 4353A7D3.7000509@home.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I'm rewriting parts of PL/Java to be more secure. One of the areas where
I'd like to improve things concerns ownership of allocated structures.
Many structures, such as TupleDesc, HeapTuple, ErrorData, etc. can be
copied into another MemoryContext for safe keeping. PL/Java uses this
when creating Java wrappers for such objects.

Prior to the rewrite, I maintained mappings from pointers to Java
wrappers in a hash table. Now, I instead have a special MemoryContext
that can hold a reference to the Java wrapper in the chunk header. Both
simpler and more efficient (I also have wet dreams about a future
MemoryContext that allocates shared memory). But, at present, and
because of this macro:

/*
* MemoryContextIsValid
* True iff memory context is valid.
*
* Add new context types to the set accepted by this macro.
*/
#define MemoryContextIsValid(context) \
((context) != NULL && \
(IsA((context), AllocSetContext)))

I have to cheat and claim that this MemoryContext has the NodeType of
T_AllocSetContext.

I have a proposal:
The NodeTag T_MemoryContext has the value of 600 and the next occupied
entry is T_Value which is 650.
- Reserve half of that range for PostgreSQL specific contexts (today you
only use one), and the other half for custom contexts.
- Change the above macro to consider values between 601 and 649 as valid
tags. The likelihood of an invalid context hitting that range is second
to none.
- Accept patches to nodes/nodes.h for new custom tags (properly
motivated of course).

What do you think? Would a patch that implements this proposal and adds
a T_PLJavaContext NodeTag be accepted?

Regards,
Thomas Hallgren

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anand Kumria 2005-10-17 13:35:15 SIGSEGV in Postgres 8.0.3 (libpq4)
Previous Message Dave Cramer 2005-10-17 13:12:35 Re: PostgreSQL roadmap for 8.2 and beyond.