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



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to