diff options
author | Pavan Deolasee | 2017-06-14 05:42:18 +0000 |
---|---|---|
committer | Pavan Deolasee | 2017-06-14 05:42:18 +0000 |
commit | 15dd5274c323fb93e4e3ea9ad2185aaaec10f79c (patch) | |
tree | 9dafb4c7f735d9429ea461dc792933af87493c33 /src/backend/utils/adt/arrayfuncs.c | |
parent | dfbb88e3bbb526dcb204b456b9e5cfd9d10d0d0a (diff) | |
parent | d5cb3bab564e0927ffac7c8729eacf181a12dd40 (diff) |
Merge from PG master upto d5cb3bab564e0927ffac7c8729eacf181a12dd40
This is the result of the "git merge remotes/PGSQL/master" upto the said commit
point. We have done some basic analysis, fixed compilation problems etc, but
bulk of the logical problems in conflict resolution etc will be handled by
subsequent commits.
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 8ee878e112..2c21a43d73 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -4,7 +4,7 @@ * Support functions for arrays. * * Portions Copyright (c) 2012-2014, TransLattice, Inc. - * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * @@ -4980,9 +4980,7 @@ initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext) if (subcontext) arr_context = AllocSetContextCreate(rcontext, "accumArrayResult", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); + ALLOCSET_DEFAULT_SIZES); astate = (ArrayBuildState *) MemoryContextAlloc(arr_context, sizeof(ArrayBuildState)); @@ -5184,9 +5182,7 @@ initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, if (subcontext) arr_context = AllocSetContextCreate(rcontext, "accumArrayResultArr", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); + ALLOCSET_DEFAULT_SIZES); /* Note we initialize all fields to zero */ astate = (ArrayBuildStateArr *) @@ -5761,25 +5757,19 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs, /* * Params checks */ - if (ARR_NDIM(dims) != 1) + if (ARR_NDIM(dims) > 1) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("wrong number of array subscripts"), errdetail("Dimension array must be one dimensional."))); - if (ARR_LBOUND(dims)[0] != 1) - ereport(ERROR, - (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), - errmsg("wrong range of array subscripts"), - errdetail("Lower bound of dimension array must be one."))); - if (array_contains_nulls(dims)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("dimension values cannot be null"))); dimv = (int *) ARR_DATA_PTR(dims); - ndims = ARR_DIMS(dims)[0]; + ndims = (ARR_NDIM(dims) > 0) ? ARR_DIMS(dims)[0] : 0; if (ndims < 0) /* we do allow zero-dimension arrays */ ereport(ERROR, @@ -5793,24 +5783,18 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs, if (lbs != NULL) { - if (ARR_NDIM(lbs) != 1) + if (ARR_NDIM(lbs) > 1) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("wrong number of array subscripts"), errdetail("Dimension array must be one dimensional."))); - if (ARR_LBOUND(lbs)[0] != 1) - ereport(ERROR, - (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), - errmsg("wrong range of array subscripts"), - errdetail("Lower bound of dimension array must be one."))); - if (array_contains_nulls(lbs)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("dimension values cannot be null"))); - if (ARR_DIMS(lbs)[0] != ndims) + if (ndims != ((ARR_NDIM(lbs) > 0) ? ARR_DIMS(lbs)[0] : 0)) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("wrong number of array subscripts"), @@ -5828,12 +5812,12 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs, lbsv = deflbs; } + nitems = ArrayGetNItems(ndims, dimv); + /* fast track for empty array */ - if (ndims == 0) + if (nitems <= 0) return construct_empty_array(elmtype); - nitems = ArrayGetNItems(ndims, dimv); - /* * We arrange to look up info about element type only once per series of * calls, assuming the element type doesn't change underneath us. |