mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Rationalize the APIs of array element/slice access functions.
The four functions array_ref, array_set, array_get_slice, array_set_slice have traditionally declared their array inputs and results as being of type "ArrayType *". This is a lie, and has been since Berkeley days, because they actually also support "fixed-length array" types such as "name" and "point"; not to mention that the inputs could be toasted. These values should be declared Datum instead to avoid confusion. The current coding already risks possible misoptimization by compilers, and it'll get worse when "expanded" array representations become a valid alternative. However, there's a fair amount of code using array_ref and array_set with arrays that *are* known to be ArrayType structures, and there might be more such places in third-party code. Rather than cluttering those call sites with PointerGetDatum/DatumGetArrayTypeP cruft, what I did was to rename the existing functions to array_get_element/array_set_element, fix their signatures, then reincarnate array_ref/array_set as backwards compatibility wrappers. array_get_slice/array_set_slice have no such constituency in the core code, and probably not in third-party code either, so I just changed their APIs.
This commit is contained in:
@@ -248,19 +248,26 @@ extern Datum array_remove(PG_FUNCTION_ARGS);
|
||||
extern Datum array_replace(PG_FUNCTION_ARGS);
|
||||
extern Datum width_bucket_array(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign,
|
||||
bool *isNull);
|
||||
extern Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx,
|
||||
Datum dataValue, bool isNull,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign);
|
||||
extern Datum array_get_slice(Datum arraydatum, int nSubscripts,
|
||||
int *upperIndx, int *lowerIndx,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign);
|
||||
extern Datum array_set_slice(Datum arraydatum, int nSubscripts,
|
||||
int *upperIndx, int *lowerIndx,
|
||||
Datum srcArrayDatum, bool isNull,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign);
|
||||
|
||||
extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign,
|
||||
bool *isNull);
|
||||
extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
|
||||
Datum dataValue, bool isNull,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign);
|
||||
extern ArrayType *array_get_slice(ArrayType *array, int nSubscripts,
|
||||
int *upperIndx, int *lowerIndx,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign);
|
||||
extern ArrayType *array_set_slice(ArrayType *array, int nSubscripts,
|
||||
int *upperIndx, int *lowerIndx,
|
||||
ArrayType *srcArray, bool isNull,
|
||||
int arraytyplen, int elmlen, bool elmbyval, char elmalign);
|
||||
|
||||
extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType,
|
||||
ArrayMapState *amstate);
|
||||
|
Reference in New Issue
Block a user