Skip to content

Commit 72257f9

Browse files
committed
simplehash: Additional tweaks to make specifying an allocator work.
Even if we don't emit definitions for SH_ALLOCATE and SH_FREE, we still need prototypes. The user can't define them before including simplehash.h because SH_TYPE isn't available yet. For the allocator to be able to access private_data, it needs to become an argument to SH_CREATE. Previously we relied on callers to set that after returning from SH_CREATE, but SH_CREATE calls SH_ALLOCATE before returning. Dilip Kumar, reviewed by me.
1 parent 3f3d60d commit 72257f9

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/backend/executor/execGrouping.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ BuildTupleHashTable(int numCols, AttrNumber *keyColIdx,
330330
else
331331
hashtable->hash_iv = 0;
332332

333-
hashtable->hashtab = tuplehash_create(tablecxt, nbuckets);
334-
hashtable->hashtab->private_data = hashtable;
333+
hashtable->hashtab = tuplehash_create(tablecxt, nbuckets, hashtable);
335334

336335
return hashtable;
337336
}

src/backend/nodes/tidbitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ tbm_create_pagetable(TIDBitmap *tbm)
244244
Assert(tbm->status != TBM_HASH);
245245
Assert(tbm->pagetable == NULL);
246246

247-
tbm->pagetable = pagetable_create(tbm->mcxt, 128);
247+
tbm->pagetable = pagetable_create(tbm->mcxt, 128, NULL);
248248

249249
/* If entry1 is valid, push it into the hashtable */
250250
if (tbm->status == TBM_ONE_PAGE)

src/include/lib/simplehash.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ typedef struct SH_ITERATOR
137137
} SH_ITERATOR;
138138

139139
/* externally visible function prototypes */
140-
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements);
140+
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements,
141+
void *private_data);
141142
SH_SCOPE void SH_DESTROY(SH_TYPE *tb);
142143
SH_SCOPE void SH_GROW(SH_TYPE *tb, uint32 newsize);
143144
SH_SCOPE SH_ELEMENT_TYPE *SH_INSERT(SH_TYPE *tb, SH_KEY_TYPE key, bool *found);
@@ -280,6 +281,10 @@ SH_ENTRY_HASH(SH_TYPE *tb, SH_ELEMENT_TYPE * entry)
280281
#endif
281282
}
282283

284+
/* default memory allocator function */
285+
static inline void *SH_ALLOCATE(SH_TYPE *type, Size size);
286+
static inline void SH_FREE(SH_TYPE *type, void *pointer);
287+
283288
#ifndef SH_USE_NONDEFAULT_ALLOCATOR
284289

285290
/* default memory allocator function */
@@ -309,13 +314,14 @@ SH_FREE(SH_TYPE *type, void *pointer)
309314
* the passed-in context.
310315
*/
311316
SH_SCOPE SH_TYPE *
312-
SH_CREATE(MemoryContext ctx, uint32 nelements)
317+
SH_CREATE(MemoryContext ctx, uint32 nelements, void *private_data)
313318
{
314319
SH_TYPE *tb;
315320
uint64 size;
316321

317322
tb = MemoryContextAllocZero(ctx, sizeof(SH_TYPE));
318323
tb->ctx = ctx;
324+
tb->private_data = private_data;
319325

320326
/* increase nelements by fillfactor, want to store nelements elements */
321327
size = Min((double) SH_MAX_SIZE, ((double) nelements) / SH_FILLFACTOR);

0 commit comments

Comments
 (0)