From 3f89878e3e1aa4aa95e9e0f3a3fa0ded664ee0dd Mon Sep 17 00:00:00 2001 From: Godwottery Date: Sun, 20 Jan 2019 19:24:16 +0100 Subject: [PATCH] Compile and use on Windows (#36) * Add PGDLLEXPORT to functions called externally * Make it compile with Visual Studio (it doesn't support #ifdef in macros) * Add explicit type-cast so silence compiler warnings. * Replace {INT_MAX | INT32_MAX } with PG_INT32_MAX (cherry picked from commit 4a5dc561697d969a6711829d028ef65431b50823) --- hypopg.c | 8 ++++---- hypopg_index.c | 5 ++--- include/hypopg_index.h | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hypopg.c b/hypopg.c index 419938a..3153e78 100644 --- a/hypopg.c +++ b/hypopg.c @@ -31,10 +31,10 @@ MemoryContext HypoMemoryContext; /*--- Functions --- */ -void _PG_init(void); -void _PG_fini(void); +PGDLLEXPORT void _PG_init(void); +PGDLLEXPORT void _PG_fini(void); -Datum hypopg_reset(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg_reset(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(hypopg_reset); @@ -334,7 +334,7 @@ hypo_get_relation_info_hook(PlannerInfo *root, /* * Reset statistics. */ -Datum +PGDLLEXPORT Datum hypopg_reset(PG_FUNCTION_ARGS) { hypo_index_reset(); diff --git a/hypopg_index.c b/hypopg_index.c index 935817b..ed97529 100644 --- a/hypopg_index.c +++ b/hypopg_index.c @@ -1668,8 +1668,7 @@ hypo_estimate_index(hypoIndex *entry, RelOptInfo *rel) - (fillfactor == 0 ? BTREE_DEFAULT_FILLFACTOR : fillfactor) + additional_bloat) / 100; - entry->pages = - entry->tuples * line_size * bloat_factor / usable_page_size; + entry->pages = (BlockNumber) (entry->tuples * line_size * bloat_factor / usable_page_size); #if PG_VERSION_NUM >= 90300 entry->tree_height = -1; /* TODO */ #endif @@ -1751,7 +1750,7 @@ hypo_estimate_index(hypoIndex *entry, RelOptInfo *rel) sizeof_SignType * bloomLength; entry->pages = 1; /* meta page */ - entry->pages += ceil( + entry->pages += (BlockNumber) ceil( ((double) entry->tuples * line_size) / usable_page_size); } #endif diff --git a/include/hypopg_index.h b/include/hypopg_index.h index fc00af1..3738533 100644 --- a/include/hypopg_index.h +++ b/include/hypopg_index.h @@ -111,12 +111,12 @@ extern List *hypoIndexes; void hypo_index_reset(void); -Datum hypopg(PG_FUNCTION_ARGS); -Datum hypopg_create_index(PG_FUNCTION_ARGS); -Datum hypopg_drop_index(PG_FUNCTION_ARGS); -Datum hypopg_relation_size(PG_FUNCTION_ARGS); -Datum hypopg_get_indexdef(PG_FUNCTION_ARGS); -Datum hypopg_reset_index(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg_create_index(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg_drop_index(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg_relation_size(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg_get_indexdef(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hypopg_reset_index(PG_FUNCTION_ARGS); extern explain_get_index_name_hook_type prev_explain_get_index_name_hook; const char *hypo_explain_get_index_name_hook(Oid indexId);