0001-use-uintptr_t-for-Datum.patch
application/octet-stream
Filename: 0001-use-uintptr_t-for-Datum.patch
Type: application/octet-stream
Part: 0
Message:
Re: [PATCH] Windows x64 [repost]
Patch
Format: format-patch
Series: patch 0001
Subject: use uintptr_t for Datum
| File | + | − |
|---|---|---|
| src/backend/access/common/heaptuple.c | 3 | 3 |
| src/backend/access/hash/hashfunc.c | 1 | 1 |
| src/backend/storage/lmgr/lwlock.c | 1 | 1 |
| src/include/access/tupmacs.h | 1 | 1 |
| src/include/c.h | 7 | 4 |
| src/include/pg_config.h.win32 | 7 | 0 |
| src/include/postgres.h | 2 | 2 |
| src/interfaces/ecpg/ecpglib/data.c | 4 | 4 |
From b6e51007eb3bfb9dd4333dfa1bfd479a049d70f0 Mon Sep 17 00:00:00 2001
From: Tsutomu Yamada <tsutomu@sraoss.co.jp>
Date: Wed, 26 Aug 2009 21:39:32 +0900
Subject: [PATCH 1/3] use uintptr_t for Datum
fix typedef, and pointer arithmetics.
for LLP64 (Windows x64)
---
src/backend/access/common/heaptuple.c | 6 +++---
src/backend/access/hash/hashfunc.c | 2 +-
src/backend/storage/lmgr/lwlock.c | 2 +-
src/include/access/tupmacs.h | 2 +-
src/include/c.h | 11 +++++++----
src/include/pg_config.h.win32 | 7 +++++++
src/include/postgres.h | 4 ++--
src/interfaces/ecpg/ecpglib/data.c | 8 ++++----
8 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index a86716e..f429f68 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -192,7 +192,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
if (att[i]->attbyval)
{
/* pass-by-value */
- data = (char *) att_align_nominal((long) data, att[i]->attalign);
+ data = (char *) att_align_nominal(data, att[i]->attalign);
store_att_byval(data, values[i], att[i]->attlen);
data_length = att[i]->attlen;
}
@@ -226,7 +226,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
else
{
/* full 4-byte header varlena */
- data = (char *) att_align_nominal((long) data,
+ data = (char *) att_align_nominal(data,
att[i]->attalign);
data_length = VARSIZE(val);
memcpy(data, val, data_length);
@@ -243,7 +243,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
else
{
/* fixed-length pass-by-reference */
- data = (char *) att_align_nominal((long) data, att[i]->attalign);
+ data = (char *) att_align_nominal(data, att[i]->attalign);
Assert(att[i]->attlen > 0);
data_length = att[i]->attlen;
memcpy(data, DatumGetPointer(values[i]), data_length);
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index a38103e..d3efb29 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -319,7 +319,7 @@ hash_any(register const unsigned char *k, register int keylen)
a = b = c = 0x9e3779b9 + len + 3923095;
/* If the source pointer is word-aligned, we use word-wide fetches */
- if (((long) k & UINT32_ALIGN_MASK) == 0)
+ if (((intptr_t) k & UINT32_ALIGN_MASK) == 0)
{
/* Code path for aligned source data */
register const uint32 *ka = (const uint32 *) k;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index f2ccbe1..5d88b02 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -245,7 +245,7 @@ CreateLWLocks(void)
ptr += 2 * sizeof(int);
/* Ensure desired alignment of LWLock array */
- ptr += LWLOCK_PADDED_SIZE - ((unsigned long) ptr) % LWLOCK_PADDED_SIZE;
+ ptr += LWLOCK_PADDED_SIZE - ((uintptr_t) ptr) % LWLOCK_PADDED_SIZE;
LWLockArray = (LWLockPadded *) ptr;
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index 7666aaa..82ee422 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -142,7 +142,7 @@
#define att_align_nominal(cur_offset, attalign) \
( \
((attalign) == 'i') ? INTALIGN(cur_offset) : \
- (((attalign) == 'c') ? (long) (cur_offset) : \
+ (((attalign) == 'c') ? (intptr_t) (cur_offset) : \
(((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
( \
AssertMacro((attalign) == 's'), \
diff --git a/src/include/c.h b/src/include/c.h
index 44efac4..acaec39 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -72,6 +72,9 @@
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <sys/types.h>
#include <errno.h>
@@ -492,7 +495,7 @@ typedef NameData *Name;
* True iff pointer is properly aligned to point to the given type.
*/
#define PointerIsAligned(pointer, type) \
- (((long)(pointer) % (sizeof (type))) == 0)
+ (((intptr_t)(pointer) % (sizeof (type))) == 0)
#define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
@@ -538,7 +541,7 @@ typedef NameData *Name;
*/
#define TYPEALIGN(ALIGNVAL,LEN) \
- (((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1)))
+ (((intptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((intptr_t) ((ALIGNVAL) - 1)))
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
@@ -549,7 +552,7 @@ typedef NameData *Name;
#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
- (((long) (LEN)) & ~((long) ((ALIGNVAL) - 1)))
+ (((intptr_t) (LEN)) & ~((intptr_t) ((ALIGNVAL) - 1)))
#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
@@ -630,7 +633,7 @@ typedef NameData *Name;
int _val = (val); \
Size _len = (len); \
\
- if ((((long) _vstart) & LONG_ALIGN_MASK) == 0 && \
+ if ((((intptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \
(_len & LONG_ALIGN_MASK) == 0 && \
_val == 0 && \
_len <= MEMSET_LOOP_LIMIT && \
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index a3b3b73..b1981fd 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -347,7 +347,11 @@
/* #undef HAVE_SRANDOM */
/* Define to 1 if you have the <stdint.h> header file. */
+#ifdef _MSC_VER
+/* #undef HAVE_STDINT_H */
+#else
#define HAVE_STDINT_H 1
+#endif
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
@@ -591,6 +595,9 @@
/* The size of a `unsigned long', as computed by sizeof. */
#define SIZEOF_UNSIGNED_LONG 4
+/* The size of `void *', as computed by sizeof. */
+#define SIZEOF_VOID_P 4
+
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
diff --git a/src/include/postgres.h b/src/include/postgres.h
index 26dfecc..e0d04c1 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -305,9 +305,9 @@ typedef struct
* or short may contain garbage when called as if it returned Datum.
*/
-typedef unsigned long Datum; /* XXX sizeof(long) >= sizeof(void *) */
+typedef uintptr_t Datum; /* XXX sizeof(long) >= sizeof(void *) */
-#define SIZEOF_DATUM SIZEOF_UNSIGNED_LONG
+#define SIZEOF_DATUM SIZEOF_VOID_P
typedef Datum *DatumPtr;
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index d468de6..12ee7a8 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -162,11 +162,11 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (binary)
{
if (varcharsize == 0 || varcharsize * offset >= size)
- memcpy((char *) ((long) var + offset * act_tuple),
+ memcpy((char *) (var + offset * act_tuple),
pval, size);
else
{
- memcpy((char *) ((long) var + offset * act_tuple),
+ memcpy((char *) (var + offset * act_tuple),
pval, varcharsize * offset);
if (varcharsize * offset < size)
@@ -371,7 +371,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_unsigned_char:
case ECPGt_string:
{
- char *str = (char *) ((long) var + offset * act_tuple);
+ char *str = (char *) (var + offset * act_tuple);
if (varcharsize == 0 || varcharsize > size)
{
strncpy(str, pval, size + 1);
@@ -426,7 +426,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_varchar:
{
struct ECPGgeneric_varchar *variable =
- (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
+ (struct ECPGgeneric_varchar *) (var + offset * act_tuple);
variable->len = size;
if (varcharsize == 0)
--
1.6.4