Skip to content

Commit 4755bd9

Browse files
Source-code compatibility fixes for compiling on Windows.
1 parent 5c83e40 commit 4755bd9

File tree

11 files changed

+105
-75
lines changed

11 files changed

+105
-75
lines changed

pg_diffix/utils.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
/* Calculates the length of an array. */
1313
#define ARRAY_LENGTH(arr) ((sizeof(arr)) / sizeof(arr[0]))
1414

15-
/* clang-format off */
16-
1715
/* Loops through given hash table entries. */
18-
#define foreach_entry(entry, table, prefix) \
19-
for (prefix##_iterator entry##__iterator = ({ prefix##_start_iterate(table, &entry##__iterator); entry##__iterator; }); \
20-
(entry = prefix##_iterate(table, &entry##__iterator)) != NULL;)
21-
22-
/* clang-format on */
16+
#define foreach_entry(entry, table, prefix) \
17+
prefix##_iterator entry##__iterator##__LINE__; \
18+
prefix##_start_iterate(table, &entry##__iterator##__LINE__); \
19+
while ((entry = prefix##_iterate(table, &entry##__iterator##__LINE__)) != NULL)
2320

2421
/*-------------------------------------------------------------------------
2522
* Hash utils

src/aggregation/bucket_scan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nodes/makefuncs.h"
88
#include "nodes/nodeFuncs.h"
99
#include "optimizer/cost.h"
10+
#include "optimizer/optimizer.h"
1011
#include "optimizer/tlist.h"
1112
#include "utils/datum.h"
1213

@@ -761,8 +762,6 @@ static List *make_scan_tlist(List *flat_agg_tlist, int num_labels, int num_aggs)
761762
return scan_tlist;
762763
}
763764

764-
extern double cpu_tuple_cost; /* optimizer/path/costsize.c. */
765-
766765
Plan *make_bucket_scan(Plan *left_tree, AnonymizationContext *anon_context)
767766
{
768767
if (!IsA(left_tree, Agg))

src/aggregation/common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
extern MemoryContext get_current_bucket_context(void);
2020
extern bool aggref_shares_state(Aggref *aggref);
2121

22-
PG_FUNCTION_INFO_V1(anon_agg_state_input);
23-
PG_FUNCTION_INFO_V1(anon_agg_state_output);
24-
PG_FUNCTION_INFO_V1(anon_agg_state_transfn);
25-
PG_FUNCTION_INFO_V1(anon_agg_state_finalfn);
22+
PGDLLEXPORT PG_FUNCTION_INFO_V1(anon_agg_state_input);
23+
PGDLLEXPORT PG_FUNCTION_INFO_V1(anon_agg_state_output);
24+
PGDLLEXPORT PG_FUNCTION_INFO_V1(anon_agg_state_transfn);
25+
PGDLLEXPORT PG_FUNCTION_INFO_V1(anon_agg_state_finalfn);
2626

2727
ArgsDescriptor *build_args_desc(Aggref *aggref)
2828
{

src/aggregation/count_histogram.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ typedef struct Int64ToInt64Entry
7474
#define SH_DEFINE
7575
#include "lib/simplehash.h"
7676

77-
PG_FUNCTION_INFO_V1(count_histogram_transfn);
78-
PG_FUNCTION_INFO_V1(count_histogram_finalfn);
77+
PGDLLEXPORT PG_FUNCTION_INFO_V1(count_histogram_transfn);
78+
PGDLLEXPORT PG_FUNCTION_INFO_V1(count_histogram_finalfn);
7979

8080
typedef struct CountHistogramState
8181
{

src/aggregation/noise.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "common/sha2.h"
44

55
#include <limits.h>
6+
#define _USE_MATH_DEFINES
67
#include <math.h>
78

89
#include "pg_diffix/aggregation/noise.h"

src/auth.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ void auth_init(void)
2929

3030
static inline bool is_personal_label(const char *seclabel)
3131
{
32-
return strcasecmp(seclabel, "personal") == 0;
32+
return pg_strcasecmp(seclabel, "personal") == 0;
3333
}
3434

3535
static inline bool is_public_label(const char *seclabel)
3636
{
37-
return strcasecmp(seclabel, "public") == 0;
37+
return pg_strcasecmp(seclabel, "public") == 0;
3838
}
3939

4040
static inline bool is_aid_label(const char *seclabel)
4141
{
42-
return strcasecmp(seclabel, "aid") == 0;
42+
return pg_strcasecmp(seclabel, "aid") == 0;
4343
}
4444

4545
static inline bool is_not_filterable_label(const char *seclabel)
4646
{
47-
return strcasecmp(seclabel, "not_filterable") == 0;
47+
return pg_strcasecmp(seclabel, "not_filterable") == 0;
4848
}
4949

5050
static inline bool is_anonymized_trusted_label(const char *seclabel)
5151
{
52-
return strcasecmp(seclabel, "anonymized_trusted") == 0;
52+
return pg_strcasecmp(seclabel, "anonymized_trusted") == 0;
5353
}
5454

5555
static inline bool is_anonymized_untrusted_label(const char *seclabel)
5656
{
57-
return strcasecmp(seclabel, "anonymized_untrusted") == 0;
57+
return pg_strcasecmp(seclabel, "anonymized_untrusted") == 0;
5858
}
5959

6060
static inline bool is_direct_label(const char *seclabel)
6161
{
62-
return strcasecmp(seclabel, "direct") == 0;
62+
return pg_strcasecmp(seclabel, "direct") == 0;
6363
}
6464

6565
#define FAIL_ON_INVALID_LABEL(seclabel) \
@@ -238,7 +238,7 @@ static char *level_to_string(AccessLevel level)
238238
}
239239
}
240240

241-
PG_FUNCTION_INFO_V1(access_level);
241+
PGDLLEXPORT PG_FUNCTION_INFO_V1(access_level);
242242

243243
Datum access_level(PG_FUNCTION_ARGS)
244244
{

src/oid_cache.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void oid_cache_init(void)
2020
if (g_loaded)
2121
return;
2222

23-
g_oid_cache.count_star = lookup_function(NULL, "count", 0, (Oid[]){});
23+
g_oid_cache.count_star = lookup_function(NULL, "count", 0, NULL);
2424
g_oid_cache.count_value = lookup_function(NULL, "count", 1, (Oid[]){ANYOID});
2525
g_oid_cache.sum_int2 = lookup_function(NULL, "sum", 1, (Oid[]){INT2OID});
2626
g_oid_cache.sum_int4 = lookup_function(NULL, "sum", 1, (Oid[]){INT4OID});
@@ -37,26 +37,26 @@ void oid_cache_init(void)
3737
g_oid_cache.count_histogram = lookup_function("diffix", "count_histogram", 1, (Oid[]){ANYOID});
3838
g_oid_cache.count_histogram_int8 = lookup_function("diffix", "count_histogram", 2, (Oid[]){ANYOID, INT8OID});
3939

40-
g_oid_cache.count_star_noise = lookup_function("diffix", "count_noise", 0, (Oid[]){});
40+
g_oid_cache.count_star_noise = lookup_function("diffix", "count_noise", 0, NULL);
4141
g_oid_cache.count_value_noise = lookup_function("diffix", "count_noise", 1, (Oid[]){ANYOID});
4242
g_oid_cache.sum_noise = lookup_function("diffix", "sum_noise", 1, (Oid[]){ANYOID});
4343
g_oid_cache.avg_noise = lookup_function("diffix", "avg_noise", 1, (Oid[]){ANYOID});
4444

45-
g_oid_cache.low_count = lookup_function("diffix", "low_count", -1, (Oid[]){});
46-
g_oid_cache.anon_count_distinct = lookup_function("diffix", "anon_count_distinct", -1, (Oid[]){});
47-
g_oid_cache.anon_count_star = lookup_function("diffix", "anon_count_star", -1, (Oid[]){});
48-
g_oid_cache.anon_count_value = lookup_function("diffix", "anon_count_value", -1, (Oid[]){});
49-
g_oid_cache.anon_sum = lookup_function("diffix", "anon_sum", -1, (Oid[]){});
50-
g_oid_cache.anon_count_histogram = lookup_function("diffix", "anon_count_histogram", -1, (Oid[]){});
45+
g_oid_cache.low_count = lookup_function("diffix", "low_count", -1, NULL);
46+
g_oid_cache.anon_count_distinct = lookup_function("diffix", "anon_count_distinct", -1, NULL);
47+
g_oid_cache.anon_count_star = lookup_function("diffix", "anon_count_star", -1, NULL);
48+
g_oid_cache.anon_count_value = lookup_function("diffix", "anon_count_value", -1, NULL);
49+
g_oid_cache.anon_sum = lookup_function("diffix", "anon_sum", -1, NULL);
50+
g_oid_cache.anon_count_histogram = lookup_function("diffix", "anon_count_histogram", -1, NULL);
5151

52-
g_oid_cache.anon_count_distinct_noise = lookup_function("diffix", "anon_count_distinct_noise", -1, (Oid[]){});
53-
g_oid_cache.anon_count_star_noise = lookup_function("diffix", "anon_count_star_noise", -1, (Oid[]){});
54-
g_oid_cache.anon_count_value_noise = lookup_function("diffix", "anon_count_value_noise", -1, (Oid[]){});
55-
g_oid_cache.anon_sum_noise = lookup_function("diffix", "anon_sum_noise", -1, (Oid[]){});
52+
g_oid_cache.anon_count_distinct_noise = lookup_function("diffix", "anon_count_distinct_noise", -1, NULL);
53+
g_oid_cache.anon_count_star_noise = lookup_function("diffix", "anon_count_star_noise", -1, NULL);
54+
g_oid_cache.anon_count_value_noise = lookup_function("diffix", "anon_count_value_noise", -1, NULL);
55+
g_oid_cache.anon_sum_noise = lookup_function("diffix", "anon_sum_noise", -1, NULL);
5656

5757
g_oid_cache.anon_agg_state = get_func_rettype(g_oid_cache.anon_count_star);
5858

59-
g_oid_cache.is_suppress_bin = lookup_function("diffix", "is_suppress_bin", 0, (Oid[]){});
59+
g_oid_cache.is_suppress_bin = lookup_function("diffix", "is_suppress_bin", 0, NULL);
6060

6161
g_oid_cache.round_by_nn = lookup_function("diffix", "round_by", 2, (Oid[]){NUMERICOID, NUMERICOID});
6262
g_oid_cache.round_by_dd = lookup_function("diffix", "round_by", 2, (Oid[]){FLOAT8OID, FLOAT8OID});

src/pg_diffix.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111
#include "pg_diffix/utils.h"
1212

1313
#include <limits.h>
14+
15+
#ifdef _WIN64
16+
#define __WORDSIZE 64
17+
#endif
18+
1419
#if __WORDSIZE != 64
1520
#error "This module requires a 64-bit target architecture!"
1621
#endif
1722

1823
PG_MODULE_MAGIC;
1924

20-
void _PG_init(void);
21-
void _PG_fini(void);
25+
PGDLLEXPORT void _PG_init(void);
26+
PGDLLEXPORT void _PG_fini(void);
2227

2328
void _PG_init(void)
2429
{
@@ -39,14 +44,14 @@ void _PG_fini(void)
3944
hooks_cleanup();
4045
}
4146

42-
PG_FUNCTION_INFO_V1(placeholder_func);
47+
PGDLLEXPORT PG_FUNCTION_INFO_V1(placeholder_func);
4348

4449
Datum placeholder_func(PG_FUNCTION_ARGS)
4550
{
4651
return PG_GETARG_DATUM(0);
4752
}
4853

49-
PG_FUNCTION_INFO_V1(internal_qual_wrapper);
54+
PGDLLEXPORT PG_FUNCTION_INFO_V1(internal_qual_wrapper);
5055

5156
Datum internal_qual_wrapper(PG_FUNCTION_ARGS)
5257
{

src/query/allowed_objects.c

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "catalog/pg_type.h"
55
#include "utils/builtins.h"
66
#include "utils/fmgroids.h"
7-
#include "utils/fmgrtab.h"
87
#include "utils/lsyscache.h"
98
#include "utils/memutils.h"
109

@@ -35,39 +34,39 @@ typedef struct FunctionByOid
3534

3635
static const FunctionByName g_allowed_builtins[] = {
3736
/* rounding casts */
38-
(FunctionByName){.name = "ftoi2", .primary_arg = 0},
39-
(FunctionByName){.name = "ftoi4", .primary_arg = 0},
40-
(FunctionByName){.name = "ftoi8", .primary_arg = 0},
41-
(FunctionByName){.name = "dtoi2", .primary_arg = 0},
42-
(FunctionByName){.name = "dtoi4", .primary_arg = 0},
43-
(FunctionByName){.name = "dtoi8", .primary_arg = 0},
44-
(FunctionByName){.name = "numeric_int2", .primary_arg = 0},
45-
(FunctionByName){.name = "numeric_int4", .primary_arg = 0},
46-
(FunctionByName){.name = "numeric_int8", .primary_arg = 0},
37+
{.name = "ftoi2", .primary_arg = 0},
38+
{.name = "ftoi4", .primary_arg = 0},
39+
{.name = "ftoi8", .primary_arg = 0},
40+
{.name = "dtoi2", .primary_arg = 0},
41+
{.name = "dtoi4", .primary_arg = 0},
42+
{.name = "dtoi8", .primary_arg = 0},
43+
{.name = "numeric_int2", .primary_arg = 0},
44+
{.name = "numeric_int4", .primary_arg = 0},
45+
{.name = "numeric_int8", .primary_arg = 0},
4746
/* substring */
48-
(FunctionByName){.name = "text_substr", .primary_arg = 0},
49-
(FunctionByName){.name = "text_substr_no_len", .primary_arg = 0},
50-
(FunctionByName){.name = "bytea_substr", .primary_arg = 0},
51-
(FunctionByName){.name = "bytea_substr_no_len", .primary_arg = 0},
47+
{.name = "text_substr", .primary_arg = 0},
48+
{.name = "text_substr_no_len", .primary_arg = 0},
49+
{.name = "bytea_substr", .primary_arg = 0},
50+
{.name = "bytea_substr_no_len", .primary_arg = 0},
5251
/* numeric generalization */
53-
(FunctionByName){.name = "dround", .primary_arg = 0},
54-
(FunctionByName){.name = "numeric_round", .primary_arg = 0},
55-
(FunctionByName){.name = "dceil", .primary_arg = 0},
56-
(FunctionByName){.name = "numeric_ceil", .primary_arg = 0},
57-
(FunctionByName){.name = "dfloor", .primary_arg = 0},
58-
(FunctionByName){.name = "numeric_floor", .primary_arg = 0},
52+
{.name = "dround", .primary_arg = 0},
53+
{.name = "numeric_round", .primary_arg = 0},
54+
{.name = "dceil", .primary_arg = 0},
55+
{.name = "numeric_ceil", .primary_arg = 0},
56+
{.name = "dfloor", .primary_arg = 0},
57+
{.name = "numeric_floor", .primary_arg = 0},
5958
/* width_bucket */
60-
(FunctionByName){.name = "width_bucket_float8", .primary_arg = 0},
61-
(FunctionByName){.name = "width_bucket_numeric", .primary_arg = 0},
59+
{.name = "width_bucket_float8", .primary_arg = 0},
60+
{.name = "width_bucket_numeric", .primary_arg = 0},
6261
/* date_trunc */
63-
(FunctionByName){.name = "timestamptz_trunc", .primary_arg = 1},
64-
(FunctionByName){.name = "timestamp_trunc", .primary_arg = 1},
62+
{.name = "timestamptz_trunc", .primary_arg = 1},
63+
{.name = "timestamp_trunc", .primary_arg = 1},
6564
/* extract & date_part*/
66-
(FunctionByName){.name = "extract_date", .primary_arg = 1},
67-
(FunctionByName){.name = "extract_timestamp", .primary_arg = 1},
68-
(FunctionByName){.name = "extract_timestamptz", .primary_arg = 1},
69-
(FunctionByName){.name = "timestamp_part", .primary_arg = 1},
70-
(FunctionByName){.name = "timestamptz_part", .primary_arg = 1},
65+
{.name = "extract_date", .primary_arg = 1},
66+
{.name = "extract_timestamp", .primary_arg = 1},
67+
{.name = "extract_timestamptz", .primary_arg = 1},
68+
{.name = "timestamp_part", .primary_arg = 1},
69+
{.name = "timestamptz_part", .primary_arg = 1},
7170
/**/
7271
};
7372

@@ -93,8 +92,8 @@ static const char *const g_implicit_range_builtins_untrusted[] = {
9392
#endif
9493

9594
static const FunctionByOid g_allowed_builtins_extra[] = {
96-
(FunctionByOid){.funcid = F_NUMERIC_ROUND_INT, .primary_arg = 0},
97-
(FunctionByOid){.funcid = F_DATE_PART_TEXT_DATE, .primary_arg = 1},
95+
{.funcid = F_NUMERIC_ROUND_INT, .primary_arg = 0},
96+
{.funcid = F_DATE_PART_TEXT_DATE, .primary_arg = 1},
9897
/**/
9998
};
10099

@@ -167,6 +166,35 @@ static const Oid *const g_implicit_range_udfs_untrusted[] = {
167166
&g_oid_cache.floor_by_dd,
168167
};
169168

169+
/* Taken from fmgrtab.h. */
170+
typedef struct
171+
{
172+
Oid foid; /* OID of the function */
173+
short nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable count */
174+
bool strict; /* T if function is "strict" */
175+
bool retset; /* T if function returns a set */
176+
const char *funcName; /* C name of the function */
177+
PGFunction func; /* pointer to compiled function */
178+
} FmgrBuiltin;
179+
180+
#define InvalidOidBuiltinMapping PG_UINT16_MAX
181+
182+
#ifdef WIN32
183+
/* On Windows, FMGR exports have to be linked dynamically. */
184+
#define FMGRIMPORTTYPE PGDLLIMPORT
185+
#else
186+
#define FMGRIMPORTTYPE
187+
#endif
188+
189+
/*
190+
* This table stores info about all the built-in functions (ie, functions
191+
* that are compiled into the Postgres executable).
192+
*/
193+
extern FMGRIMPORTTYPE const FmgrBuiltin fmgr_builtins[];
194+
extern FMGRIMPORTTYPE const int fmgr_nbuiltins;
195+
extern FMGRIMPORTTYPE const Oid fmgr_last_builtin_oid;
196+
extern FMGRIMPORTTYPE const uint16 fmgr_builtin_oid_index[];
197+
170198
/* Taken from fmgr.c. */
171199
static const FmgrBuiltin *fmgr_isbuiltin(Oid id)
172200
{

src/query/anonymization.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ static Node *rewrite_to_avg_aggregator(Aggref *aggref, List *aid_refs)
276276

277277
Expr *count_aggref = make_safe_anon_count_value(aggref);
278278

279-
FuncExpr *cast_sum;
280-
FuncExpr *cast_count;
281-
FuncExpr *division;
279+
FuncExpr *cast_sum = NULL;
280+
FuncExpr *cast_count = NULL;
281+
FuncExpr *division = NULL;
282282

283283
/*
284284
* The typing of the anon avg(col) is based on the original sum(col) and avg(col) typing,

0 commit comments

Comments
 (0)