Skip to content

Commit

Permalink
Rename rbtree.c functions to use "rbt" prefix not "rb" prefix.
Browse files Browse the repository at this point in the history
The "rb" prefix is used by Ruby, so that our existing code results
in name collisions that break plruby.  We discussed ways to prevent
that by adjusting dynamic linker options, but it seems that at best
we'd move the pain to other cases.  Renaming to avoid the collision
is the only portable fix anyway.  Fortunately, our rbtree code is
not (yet?) widely used --- in core, there's only a single usage
in GIN --- so it seems likely that we can get away with a rename.

I chose to do this basically as s/rb/rbt/g, except for places where
there already was a "t" after "rb".  The patch could have been made
smaller by only touching linker-visible symbols, but it would have
resulted in oddly inconsistent-looking code.  Better to make it look
like "rbt" was the plan all along.

Back-patch to v10.  The rbtree.c code exists back to 9.5, but
rb_iterate() which is the actual immediate source of pain was added
in v10, so it seems like changing the names before that would have
more risk than benefit.

Per report from Pavel Raiskup.

Discussion: https://postgr.es/m/4738198.8KVIIDhgEB@nb.usersys.redhat.com
  • Loading branch information
tglsfdc committed Nov 6, 2018
1 parent c63d9eb commit b2e754c
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 235 deletions.
32 changes: 16 additions & 16 deletions src/backend/access/gin/ginbulk.c
Expand Up @@ -27,7 +27,7 @@

/* Combiner function for rbtree.c */
static void
ginCombineData(RBNode *existing, const RBNode *newdata, void *arg)
ginCombineData(RBTNode *existing, const RBTNode *newdata, void *arg)
{
GinEntryAccumulator *eo = (GinEntryAccumulator *) existing;
const GinEntryAccumulator *en = (const GinEntryAccumulator *) newdata;
Expand Down Expand Up @@ -69,7 +69,7 @@ ginCombineData(RBNode *existing, const RBNode *newdata, void *arg)

/* Comparator function for rbtree.c */
static int
cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
cmpEntryAccumulator(const RBTNode *a, const RBTNode *b, void *arg)
{
const GinEntryAccumulator *ea = (const GinEntryAccumulator *) a;
const GinEntryAccumulator *eb = (const GinEntryAccumulator *) b;
Expand All @@ -81,15 +81,15 @@ cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
}

/* Allocator function for rbtree.c */
static RBNode *
static RBTNode *
ginAllocEntryAccumulator(void *arg)
{
BuildAccumulator *accum = (BuildAccumulator *) arg;
GinEntryAccumulator *ea;

/*
* Allocate memory by rather big chunks to decrease overhead. We have no
* need to reclaim RBNodes individually, so this costs nothing.
* need to reclaim RBTNodes individually, so this costs nothing.
*/
if (accum->entryallocator == NULL || accum->eas_used >= DEF_NENTRY)
{
Expand All @@ -98,11 +98,11 @@ ginAllocEntryAccumulator(void *arg)
accum->eas_used = 0;
}

/* Allocate new RBNode from current chunk */
/* Allocate new RBTNode from current chunk */
ea = accum->entryallocator + accum->eas_used;
accum->eas_used++;

return (RBNode *) ea;
return (RBTNode *) ea;
}

void
Expand All @@ -112,12 +112,12 @@ ginInitBA(BuildAccumulator *accum)
accum->allocatedMemory = 0;
accum->entryallocator = NULL;
accum->eas_used = 0;
accum->tree = rb_create(sizeof(GinEntryAccumulator),
cmpEntryAccumulator,
ginCombineData,
ginAllocEntryAccumulator,
NULL, /* no freefunc needed */
(void *) accum);
accum->tree = rbt_create(sizeof(GinEntryAccumulator),
cmpEntryAccumulator,
ginCombineData,
ginAllocEntryAccumulator,
NULL, /* no freefunc needed */
(void *) accum);
}

/*
Expand Down Expand Up @@ -162,8 +162,8 @@ ginInsertBAEntry(BuildAccumulator *accum,
/* temporarily set up single-entry itempointer list */
eatmp.list = heapptr;

ea = (GinEntryAccumulator *) rb_insert(accum->tree, (RBNode *) &eatmp,
&isNew);
ea = (GinEntryAccumulator *) rbt_insert(accum->tree, (RBTNode *) &eatmp,
&isNew);

if (isNew)
{
Expand Down Expand Up @@ -255,7 +255,7 @@ qsortCompareItemPointers(const void *a, const void *b)
void
ginBeginBAScan(BuildAccumulator *accum)
{
rb_begin_iterate(accum->tree, LeftRightWalk, &accum->tree_walk);
rbt_begin_iterate(accum->tree, LeftRightWalk, &accum->tree_walk);
}

/*
Expand All @@ -271,7 +271,7 @@ ginGetBAEntry(BuildAccumulator *accum,
GinEntryAccumulator *entry;
ItemPointerData *list;

entry = (GinEntryAccumulator *) rb_iterate(&accum->tree_walk);
entry = (GinEntryAccumulator *) rbt_iterate(&accum->tree_walk);

if (entry == NULL)
return NULL; /* no more entries */
Expand Down

0 comments on commit b2e754c

Please sign in to comment.