Skip to content

Commit dfa3290

Browse files
knizhnikpashkinelfe
authored andcommitted
Fix incompatibility with PG14
Due to vanilla change 8597a48d01b geo_decls.h can not be used with redefinition of EPSILON anymore. Private versions of macro are copied from PG code.
1 parent 7ff66ac commit dfa3290

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

gnomo.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#include <postgres.h>
22
#include <fmgr.h>
33

4-
#include <utils/geo_decls.h> /* Point */
5-
6-
#include <point.h> /* SPoint */
74
#include <gnomo.h>
5+
#include <point.h> /* SPoint from pgsphere */
86

97
#include <math.h>
108

path.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,26 @@ spherepath_in(PG_FUNCTION_ARGS)
506506
char *c = PG_GETARG_CSTRING(0);
507507
int32 i, nelem;
508508
void sphere_yyparse(void);
509-
SPoint *arr;
510509

511510
init_buffer(c);
512511
sphere_yyparse();
513512

514513
nelem = get_path_count();
515-
if (nelem > 1)
514+
if (nelem > MAX_POINTS)
516515
{
517-
arr = (SPoint *)palloc(sizeof(SPoint)*nelem);
516+
reset_buffer();
517+
elog(ERROR, "spherepath_in: too much points");
518+
PG_RETURN_NULL();
519+
}
520+
else if (nelem > 1)
521+
{
522+
SPoint arr[MAX_POINTS];
518523

519524
for (i = 0; i < nelem; i++)
520525
{
521526
get_path_elem(i, &arr[i].lng, &arr[i].lat);
522527
}
523528
path = spherepath_from_array(&arr[0], nelem);
524-
pfree(arr);
525529
}
526530
else
527531
{

pg_sphere.h

+50-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
#include "postgres.h"
3737
#include "fmgr.h"
38-
#include "utils/geo_decls.h"
3938
#include "utils/array.h"
4039
#include "utils/elog.h"
4140
#include "utils/builtins.h"
@@ -46,6 +45,56 @@
4645

4746
#include "pgs_util.h"
4847

48+
#define EPSILON 1.0E-09
49+
50+
#define FPzero(A) (fabs(A) <= EPSILON)
51+
52+
static inline bool
53+
FPeq(double A, double B)
54+
{
55+
return A == B || fabs(A - B) <= EPSILON;
56+
}
57+
58+
static inline bool
59+
FPne(double A, double B)
60+
{
61+
return A != B && fabs(A - B) > EPSILON;
62+
}
63+
64+
static inline bool
65+
FPlt(double A, double B)
66+
{
67+
return A + EPSILON < B;
68+
}
69+
70+
static inline bool
71+
FPle(double A, double B)
72+
{
73+
return A <= B + EPSILON;
74+
}
75+
76+
static inline bool
77+
FPgt(double A, double B)
78+
{
79+
return A > B + EPSILON;
80+
}
81+
82+
static inline bool
83+
FPge(double A, double B)
84+
{
85+
return A + EPSILON >= B;
86+
}
87+
88+
/*---------------------------------------------------------------------
89+
* Point - (x,y)
90+
*-------------------------------------------------------------------*/
91+
typedef struct
92+
{
93+
float8 x,
94+
y;
95+
} Point;
96+
4997
void sphere_yyparse(void);
5098

5199
#endif
100+

polygon.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -815,24 +815,29 @@ spherepoly_in(PG_FUNCTION_ARGS)
815815
char *c = PG_GETARG_CSTRING(0);
816816
int32 i,
817817
nelem;
818-
SPoint *arr;
819818

820819
void sphere_yyparse(void);
821820

822821
init_buffer(c);
823822
sphere_yyparse();
824823

825824
nelem = get_path_count();
825+
if (nelem > MAX_POINTS)
826+
{
827+
reset_buffer();
828+
elog(ERROR, "spherepoly_in: too much points");
829+
PG_RETURN_NULL();
830+
831+
}
826832
if (nelem > 2)
827833
{
828-
arr = (SPoint *)palloc(sizeof(SPoint)*nelem);
834+
SPoint arr[MAX_POINTS];
829835

830836
for (i = 0; i < nelem; i++)
831837
{
832838
get_path_elem(i, &arr[i].lng, &arr[i].lat);
833839
}
834840
poly = spherepoly_from_array(&arr[0], nelem);
835-
pfree(arr);
836841
}
837842
else
838843
{
@@ -894,12 +899,11 @@ spherepoly_area(PG_FUNCTION_ARGS)
894899
{
895900
SPOLY *poly = PG_GETARG_SPOLY(0);
896901
int32 i;
897-
SPoint *s;
902+
SPoint s[MAX_POINTS + 2];
898903
SPoint stmp[2];
899904
SEuler se;
900905
float8 sum = 0.0;
901906

902-
s=(SPoint *)palloc(sizeof(SPoint)*(poly->npts + 2));
903907
memcpy((void *) &s[1],
904908
(void *) &poly->p[0],
905909
poly->npts * sizeof(SPoint));
@@ -939,7 +943,6 @@ spherepoly_area(PG_FUNCTION_ARGS)
939943
sum = 0.0;
940944
}
941945

942-
pfree(s);
943946
PG_RETURN_FLOAT8(sum);
944947
}
945948

polygon.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef struct
1717
SPoint p[1]; /* variable length array of SPoints */
1818
} SPOLY;
1919

20+
#define MAX_POINTS 1024
2021

2122
/* Polygon and ellipse */
2223
#define PGS_ELLIPSE_POLY_AVOID 0 /* ellipse avoids polygon */

0 commit comments

Comments
 (0)