77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.78 1999/04/04 20:10:12 tgl Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.79 1999/05/12 04:38:24 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -92,11 +92,10 @@ static intgetNotice(PGconn *conn);
9292 * PGRESULT_SEP_ALLOC_THRESHOLD: objects bigger than this are given separate
9393 * blocks, instead of being crammed into a regular allocation block.
9494 * Requirements for correct function are:
95- * PGRESULT_ALIGN_BOUNDARY >= sizeof(pointer)
96- *to ensure the initial pointer in a block is not overwritten.
9795 * PGRESULT_ALIGN_BOUNDARY must be a multiple of the alignment requirements
98- *of all machine data types.
99- * PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_ALIGN_BOUNDARY <=
96+ *of all machine data types. (Currently this is set from configure
97+ *tests, so it should be OK automatically.)
98+ * PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_BLOCK_OVERHEAD <=
10099 *PGRESULT_DATA_BLOCKSIZE
101100 *pqResultAlloc assumes an object smaller than the threshold will fit
102101 *in a new block.
@@ -105,8 +104,14 @@ static intgetNotice(PGconn *conn);
105104 * ----------------
106105 */
107106
107+ #ifdef MAX
108+ #undef MAX
109+ #endif
110+ #define MAX (a ,b ) ((a) > (b) ? (a) : (b))
111+
108112#define PGRESULT_DATA_BLOCKSIZE 2048
109113#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF/* from configure */
114+ #define PGRESULT_BLOCK_OVERHEAD MAX(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
110115#define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)
111116
112117
@@ -213,10 +218,10 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
213218 */
214219if (nBytes >=PGRESULT_SEP_ALLOC_THRESHOLD )
215220{
216- block = (PGresult_data * )malloc (nBytes + PGRESULT_ALIGN_BOUNDARY );
221+ block = (PGresult_data * )malloc (nBytes + PGRESULT_BLOCK_OVERHEAD );
217222if (!block )
218223return NULL ;
219- space = block -> space + PGRESULT_ALIGN_BOUNDARY ;
224+ space = block -> space + PGRESULT_BLOCK_OVERHEAD ;
220225if (res -> curBlock )
221226{
222227/* Tuck special block below the active block, so that we don't
@@ -244,8 +249,8 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
244249if (isBinary )
245250{
246251/* object needs full alignment */
247- res -> curOffset = PGRESULT_ALIGN_BOUNDARY ;
248- res -> spaceLeft = PGRESULT_DATA_BLOCKSIZE - PGRESULT_ALIGN_BOUNDARY ;
252+ res -> curOffset = PGRESULT_BLOCK_OVERHEAD ;
253+ res -> spaceLeft = PGRESULT_DATA_BLOCKSIZE - PGRESULT_BLOCK_OVERHEAD ;
249254}
250255else
251256{