aboutsummaryrefslogtreecommitdiff
path: root/contrib/intarray/_int.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-08-04 19:35:32 +0000
committerBruce Momjian <bruce@momjian.us>2001-08-04 19:35:32 +0000
commitf368c94fd6c170dbcfb348a99aeacae8ef20b6f9 (patch)
tree21a84d650662903b0f897378943dd55b06687b98 /contrib/intarray/_int.c
parentf8683e8a9c9369d1713e9a13867a0541ac56787e (diff)
downloadpostgresql-f368c94fd6c170dbcfb348a99aeacae8ef20b6f9.tar.gz
postgresql-f368c94fd6c170dbcfb348a99aeacae8ef20b6f9.zip
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
Diffstat (limited to 'contrib/intarray/_int.c')
-rw-r--r--contrib/intarray/_int.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/contrib/intarray/_int.c b/contrib/intarray/_int.c
index 56d15dac011..8a90a77641e 100644
--- a/contrib/intarray/_int.c
+++ b/contrib/intarray/_int.c
@@ -36,7 +36,8 @@
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
-#define ARRISNULL(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 1 )
+#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 )
+#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 0 )
#define SORT(x) \
do { \
@@ -300,15 +301,16 @@ g_int_compress(PG_FUNCTION_ARGS)
if (ARRISNULL(r))
{
-#ifdef GIST_DEBUG
- elog(NOTICE, "COMP IN: NULL");
-#endif
- if (r)
- if (r != (ArrayType *) DatumGetPointer(entry->key))
- pfree(r);
-
- gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
+ if ( ARRISVOID(r) ) {
+ ArrayType *out = new_intArrayType( 0 );
+ gistentryinit(*retval, PointerGetDatum(out),
+ entry->rel, entry->page, entry->offset, VARSIZE(out), FALSE);
+ } else {
+ gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
0, FALSE);
+ }
+ if (r) pfree(r);
+
PG_RETURN_POINTER(retval);
}
@@ -371,14 +373,20 @@ g_int_decompress(PG_FUNCTION_ARGS)
else
in = NULL;
- if (entry->bytes < ARR_OVERHEAD(NDIM) || ARRISNULL(in))
+ if (ARRISNULL(in))
{
retval = palloc(sizeof(GISTENTRY));
+ if ( ARRISVOID(in) ) {
+ r = new_intArrayType( 0 );
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ } else {
+ gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
+ }
if (in)
if (in != (ArrayType *) DatumGetPointer(entry->key))
pfree(in);
- gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
#ifdef GIST_DEBUG
elog(NOTICE, "DECOMP IN: NULL");
#endif
@@ -1137,10 +1145,17 @@ g_intbig_compress(PG_FUNCTION_ARGS)
if (ARRISNULL(in))
{
+ if ( ARRISVOID(in) ) {
+ r = new_intArrayType( SIGLENINT );
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ } else {
+ gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
+ 0, FALSE);
+ }
if (in)
if (in != (ArrayType *) DatumGetPointer(entry->key))
pfree(in);
- gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
PG_RETURN_POINTER (retval);
}