Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit251282d

Browse files
committed
Tweak behavior of array slicing operations: seems like it ought to be
okay to omit low-order dimensions when accessing an array slice.
1 parent861c336 commit251282d

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

‎src/backend/utils/adt/arrayfuncs.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.76 2002/03/16 22:47:13 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.77 2002/03/20 19:41:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -907,10 +907,10 @@ array_get_slice(ArrayType *array,
907907
* with an empty slice, return NULL (should it be an empty array
908908
* instead?)
909909
*/
910-
if (ndim!=nSubscripts||ndim <=0||ndim>MAXDIM)
910+
if (ndim<nSubscripts||ndim <=0||ndim>MAXDIM)
911911
RETURN_NULL(ArrayType*);
912912

913-
for (i=0;i<ndim;i++)
913+
for (i=0;i<nSubscripts;i++)
914914
{
915915
if (lowerIndx[i]<lb[i])
916916
lowerIndx[i]=lb[i];
@@ -919,8 +919,16 @@ array_get_slice(ArrayType *array,
919919
if (lowerIndx[i]>upperIndx[i])
920920
RETURN_NULL(ArrayType*);
921921
}
922+
/* fill any missing subscript positions with full array range */
923+
for (;i<ndim;i++)
924+
{
925+
lowerIndx[i]=lb[i];
926+
upperIndx[i]=dim[i]+lb[i]-1;
927+
if (lowerIndx[i]>upperIndx[i])
928+
RETURN_NULL(ArrayType*);
929+
}
922930

923-
mda_get_range(nSubscripts,span,lowerIndx,upperIndx);
931+
mda_get_range(ndim,span,lowerIndx,upperIndx);
924932

925933
bytes=array_slice_size(ndim,dim,lb,arraydataptr,
926934
elmlen,lowerIndx,upperIndx);
@@ -1120,6 +1128,9 @@ array_set(ArrayType *array,
11201128
* A new array is returned, just like the old except for the
11211129
* modified range.
11221130
*
1131+
* NOTE: we assume it is OK to scribble on the provided index arrays
1132+
* lowerIndx[] and upperIndx[]. These are generally just temporaries.
1133+
*
11231134
* NOTE: For assignments, we throw an error for silly subscripts etc,
11241135
* rather than returning a NULL as the fetch operations do. The reasoning
11251136
* is that returning a NULL would cause the user's whole array to be replaced
@@ -1172,7 +1183,7 @@ array_set_slice(ArrayType *array,
11721183
/* note: we assume srcArray contains no toasted elements */
11731184

11741185
ndim=ARR_NDIM(array);
1175-
if (ndim!=nSubscripts||ndim <=0||ndim>MAXDIM)
1186+
if (ndim<nSubscripts||ndim <=0||ndim>MAXDIM)
11761187
elog(ERROR,"Invalid array subscripts");
11771188

11781189
/* copy dim/lb since we may modify them */
@@ -1185,7 +1196,7 @@ array_set_slice(ArrayType *array,
11851196
* extend the array as long as no hole is created. An empty slice is
11861197
* an error, too.
11871198
*/
1188-
for (i=0;i<ndim;i++)
1199+
for (i=0;i<nSubscripts;i++)
11891200
{
11901201
if (lowerIndx[i]>upperIndx[i])
11911202
elog(ERROR,"Invalid array subscripts");
@@ -1207,6 +1218,14 @@ array_set_slice(ArrayType *array,
12071218
elog(ERROR,"Invalid array subscripts");
12081219
}
12091220
}
1221+
/* fill any missing subscript positions with full array range */
1222+
for (;i<ndim;i++)
1223+
{
1224+
lowerIndx[i]=lb[i];
1225+
upperIndx[i]=dim[i]+lb[i]-1;
1226+
if (lowerIndx[i]>upperIndx[i])
1227+
elog(ERROR,"Invalid array subscripts");
1228+
}
12101229

12111230
/*
12121231
* Make sure source array has enough entries. Note we ignore the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp