diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-05-12 04:38:24 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-05-12 04:38:24 +0000 |
commit | a36a7a16ebd5c7e0e3247f8657854fefec59dbe7 (patch) | |
tree | fb71185b9a9e6f2f2a5b2dce7553add4b670dac4 | |
parent | 5085132c6d3f5ea9c5dec18ee6a2a70ddf4e91b5 (diff) | |
download | postgresql-a36a7a16ebd5c7e0e3247f8657854fefec59dbe7.tar.gz postgresql-a36a7a16ebd5c7e0e3247f8657854fefec59dbe7.zip |
Fix bogus assumption that MAXALIGN is at least sizeof(pointer).
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 7a7a9076fe0..7c1540ae159 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.78 1999/04/04 20:10:12 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.79 1999/05/12 04:38:24 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -92,11 +92,10 @@ static int getNotice(PGconn *conn); * PGRESULT_SEP_ALLOC_THRESHOLD: objects bigger than this are given separate * blocks, instead of being crammed into a regular allocation block. * Requirements for correct function are: - * PGRESULT_ALIGN_BOUNDARY >= sizeof(pointer) - * to ensure the initial pointer in a block is not overwritten. * PGRESULT_ALIGN_BOUNDARY must be a multiple of the alignment requirements - * of all machine data types. - * PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_ALIGN_BOUNDARY <= + * of all machine data types. (Currently this is set from configure + * tests, so it should be OK automatically.) + * PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_BLOCK_OVERHEAD <= * PGRESULT_DATA_BLOCKSIZE * pqResultAlloc assumes an object smaller than the threshold will fit * in a new block. @@ -105,8 +104,14 @@ static int getNotice(PGconn *conn); * ---------------- */ +#ifdef MAX +#undef MAX +#endif +#define MAX(a,b) ((a) > (b) ? (a) : (b)) + #define PGRESULT_DATA_BLOCKSIZE 2048 #define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF /* from configure */ +#define PGRESULT_BLOCK_OVERHEAD MAX(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY) #define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2) @@ -213,10 +218,10 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary) */ if (nBytes >= PGRESULT_SEP_ALLOC_THRESHOLD) { - block = (PGresult_data *) malloc(nBytes + PGRESULT_ALIGN_BOUNDARY); + block = (PGresult_data *) malloc(nBytes + PGRESULT_BLOCK_OVERHEAD); if (! block) return NULL; - space = block->space + PGRESULT_ALIGN_BOUNDARY; + space = block->space + PGRESULT_BLOCK_OVERHEAD; if (res->curBlock) { /* Tuck special block below the active block, so that we don't @@ -244,8 +249,8 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary) if (isBinary) { /* object needs full alignment */ - res->curOffset = PGRESULT_ALIGN_BOUNDARY; - res->spaceLeft = PGRESULT_DATA_BLOCKSIZE - PGRESULT_ALIGN_BOUNDARY; + res->curOffset = PGRESULT_BLOCK_OVERHEAD; + res->spaceLeft = PGRESULT_DATA_BLOCKSIZE - PGRESULT_BLOCK_OVERHEAD; } else { |