Skip to content

Commit f368c94

Browse files
committed
1. Fixed error with empty array ( '{}' ),
test data changed to include such data 2. Test a dimension of an array ( we support only one-dimension) Oleg Bartunov
1 parent f8683e8 commit f368c94

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

contrib/intarray/_int.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
3737
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
3838

39-
#define ARRISNULL(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 1 )
39+
#define ARRISNULL(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : ( ( ARR_NDIM(x) ) ? (elog(ERROR,"Array is not one-dimentional: %d dimentions", ARR_NDIM(x)),1) : 1 ) ) : 1 )
40+
#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 0 )
4041

4142
#define SORT(x) \
4243
do { \
@@ -300,15 +301,16 @@ g_int_compress(PG_FUNCTION_ARGS)
300301

301302
if (ARRISNULL(r))
302303
{
303-
#ifdef GIST_DEBUG
304-
elog(NOTICE, "COMP IN: NULL");
305-
#endif
306-
if (r)
307-
if (r != (ArrayType *) DatumGetPointer(entry->key))
308-
pfree(r);
309-
310-
gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
304+
if ( ARRISVOID(r) ) {
305+
ArrayType *out = new_intArrayType( 0 );
306+
gistentryinit(*retval, PointerGetDatum(out),
307+
entry->rel, entry->page, entry->offset, VARSIZE(out), FALSE);
308+
} else {
309+
gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
311310
0, FALSE);
311+
}
312+
if (r) pfree(r);
313+
312314
PG_RETURN_POINTER(retval);
313315
}
314316

@@ -371,14 +373,20 @@ g_int_decompress(PG_FUNCTION_ARGS)
371373
else
372374
in = NULL;
373375

374-
if (entry->bytes < ARR_OVERHEAD(NDIM) || ARRISNULL(in))
376+
if (ARRISNULL(in))
375377
{
376378
retval = palloc(sizeof(GISTENTRY));
377379

380+
if ( ARRISVOID(in) ) {
381+
r = new_intArrayType( 0 );
382+
gistentryinit(*retval, PointerGetDatum(r),
383+
entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
384+
} else {
385+
gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
386+
}
378387
if (in)
379388
if (in != (ArrayType *) DatumGetPointer(entry->key))
380389
pfree(in);
381-
gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
382390
#ifdef GIST_DEBUG
383391
elog(NOTICE, "DECOMP IN: NULL");
384392
#endif
@@ -1137,10 +1145,17 @@ g_intbig_compress(PG_FUNCTION_ARGS)
11371145

11381146
if (ARRISNULL(in))
11391147
{
1148+
if ( ARRISVOID(in) ) {
1149+
r = new_intArrayType( SIGLENINT );
1150+
gistentryinit(*retval, PointerGetDatum(r),
1151+
entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
1152+
} else {
1153+
gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
1154+
0, FALSE);
1155+
}
11401156
if (in)
11411157
if (in != (ArrayType *) DatumGetPointer(entry->key))
11421158
pfree(in);
1143-
gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
11441159
PG_RETURN_POINTER (retval);
11451160
}
11461161

contrib/intarray/data/test__int.data

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{79,83,16,63,32}
55
{52,41,61,79,94,87}
66
{76,59,39,36,21}
7-
\N
7+
{}
88
{41,79,76,96,3}
99
{25,59,5,96,32}
1010
{92,58,12,57}
@@ -57,7 +57,7 @@
5757
{58,1,39,48}
5858
{78,36,70,92}
5959
{43,3,22,95,51}
60-
\N
60+
{}
6161
{88,64,25,64,86}
6262
{34,6,49,90,25}
6363
{86,35,13,22}
@@ -76,12 +76,12 @@
7676
{89,11,67,55,73}
7777
{78,39,84,63,62,45}
7878
{50,63,8}
79-
\N
79+
{}
8080
{96,36,58,65,96}
8181
{59,86,41,30}
8282
{90,60,39,47,19}
8383
{70,100,73,99}
84-
\N
84+
{}
8585
{85,14,39}
8686
{76,53}
8787
{96,38,52,13,87,85}
@@ -95,7 +95,7 @@
9595
{84,93,36,95,34,69}
9696
{66,25,5,40}
9797
{77,6,57,42}
98-
\N
98+
{}
9999
{88,81,85,37,12}
100100
{56,73,38}
101101
{70,70,6,19}
@@ -176,7 +176,7 @@
176176
{31,48}
177177
{28,35,18}
178178
{77,55,100,73,57,62}
179-
\N
179+
{}
180180
{14,59,53}
181181
{98,3}
182182
{13,56}
@@ -188,7 +188,7 @@
188188
{41,76,39,84,32}
189189
{94,66,47}
190190
{55,28}
191-
\N
191+
{}
192192
{94,65,59,20}
193193
{55,50,56,14,58}
194194
{14,94,52,25,69,95}
@@ -203,7 +203,7 @@
203203
{46,69}
204204
{35,54}
205205
{36,79,54}
206-
\N
206+
{}
207207
{63,78}
208208
{12,86,52,29,60,30}
209209
{29,27,58,86,42,62}
@@ -215,7 +215,7 @@
215215
{14,85,14,26,3}
216216
{46,71,10,16}
217217
{30,63}
218-
\N
218+
{}
219219
{91,30,56}
220220
{46,36,68,91,36,88}
221221
{24,61}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy