* macro makeNode. eg. to create a Resdom node, use makeNode(Resdom)
*
*/
-Node *newNodeMacroHolder;
+Node *
+newNode(Size size, NodeTag tag)
+{
+ Node *newNode;
+ Assert(size >= sizeof(Node)); /* need the tag, at least */
+
+ newNode = (Node *) palloc(size);
+ MemSet((char *) newNode, 0, size);
+ newNode->type = tag;
+ return newNode;
+}
return (*context->methods->alloc) (context, size);
}
-/*
- * MemoryContextAllocZero
- * Like MemoryContextAlloc, but clears allocated memory
- *
- * We could just call MemoryContextAlloc then clear the memory, but this
- * function is called too many times, so we have a separate version.
- */
-void *
-MemoryContextAllocZero(MemoryContext context, Size size)
-{
- void *ret;
-
- AssertArg(MemoryContextIsValid(context));
-
- if (!AllocSizeIsValid(size))
- elog(ERROR, "MemoryContextAllocZero: invalid request size %lu",
- (unsigned long) size);
-
- ret = (*context->methods->alloc) (context, size);
- MemSet(ret, 0, size);
- return ret;
-}
-
/*
* pfree
* Release an allocated chunk.
#define nodeTag(nodeptr) (((Node*)(nodeptr))->type)
-/*
- * There is no way to dereference the palloc'ed pointer to assign the
- * tag, and return the pointer itself, so we need a holder variable.
- * Fortunately, this function isn't recursive so we just define
- * a global variable for this purpose.
- */
-extern Node *newNodeMacroHolder;
-
-#define newNode(size, tag) \
-( \
- AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
-\
- newNodeMacroHolder = (Node *) palloc0(size), \
- newNodeMacroHolder->type = (tag), \
- newNodeMacroHolder \
-)
-
-
#define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
#define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
* ----------------------------------------------------------------
*/
+/*
+ * nodes/nodes.c
+ */
+extern Node *newNode(Size size, NodeTag tag);
+
/*
* nodes/{outfuncs.c,print.c}
*/
* Fundamental memory-allocation operations (more are in utils/memutils.h)
*/
extern void *MemoryContextAlloc(MemoryContext context, Size size);
-extern void *MemoryContextAllocZero(MemoryContext context, Size size);
#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
-#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz))
-
extern void pfree(void *pointer);
extern void *repalloc(void *pointer, Size size);