Removed nested FLEXIBLE_ARRAY_MEMBER for Windows

This commit is contained in:
Andrew Kane
2022-12-07 19:53:48 -08:00
parent d376011087
commit 9c9489e888
2 changed files with 6 additions and 4 deletions

View File

@@ -83,7 +83,7 @@ typedef struct VectorArrayData
int length;
int maxlen;
int dim;
Vector items[FLEXIBLE_ARRAY_MEMBER];
Vector *items;
} VectorArrayData;
typedef VectorArrayData * VectorArray;
@@ -204,8 +204,8 @@ typedef struct IvfflatScanOpaqueData
typedef IvfflatScanOpaqueData * IvfflatScanOpaque;
#define VECTOR_ARRAY_SIZE(_length, _dim) (offsetof(VectorArrayData, items) + _length * VECTOR_SIZE(_dim))
#define VECTOR_ARRAY_OFFSET(_arr, _offset) ((char*) _arr + offsetof(VectorArrayData, items) + (_offset) * VECTOR_SIZE(_arr->dim))
#define VECTOR_ARRAY_SIZE(_length, _dim) (sizeof(VectorArrayData) + (_length) * VECTOR_SIZE(_dim))
#define VECTOR_ARRAY_OFFSET(_arr, _offset) ((char*) _arr->items + (_offset) * VECTOR_SIZE(_arr->dim))
#define VectorArrayGet(_arr, _offset) ((Vector *) VECTOR_ARRAY_OFFSET(_arr, _offset))
#define VectorArraySet(_arr, _offset, _val) (memcpy(VECTOR_ARRAY_OFFSET(_arr, _offset), _val, VECTOR_SIZE(_arr->dim)))

View File

@@ -10,11 +10,12 @@
VectorArray
VectorArrayInit(int maxlen, int dimensions)
{
VectorArray res = palloc_extended(VECTOR_ARRAY_SIZE(maxlen, dimensions), MCXT_ALLOC_ZERO | MCXT_ALLOC_HUGE);
VectorArray res = palloc(sizeof(VectorArrayData));
res->length = 0;
res->maxlen = maxlen;
res->dim = dimensions;
res->items = palloc_extended(maxlen * VECTOR_SIZE(dimensions), MCXT_ALLOC_ZERO | MCXT_ALLOC_HUGE);
return res;
}
@@ -24,6 +25,7 @@ VectorArrayInit(int maxlen, int dimensions)
void
VectorArrayFree(VectorArray arr)
{
pfree(arr->items);
pfree(arr);
}