Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85d02a6

Browse files
committed
Redefine Datum as uintptr_t, instead of unsigned long.
This is more in keeping with modern practice, and is a first step towardsporting to Win64 (which has sizeof(pointer) > sizeof(long)).Tsutomu Yamada, Magnus Hagander, Tom Lane
1 parent8abb011 commit85d02a6

File tree

16 files changed

+470
-142
lines changed

16 files changed

+470
-142
lines changed

‎configure

Lines changed: 395 additions & 82 deletions
Large diffs are not rendered by default.

‎configure.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.616 2009/12/11 02:21:21 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.617 2009/12/31 19:41:33 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -1095,6 +1095,8 @@ PGAC_STRUCT_SOCKADDR_UN
10951095
PGAC_STRUCT_SOCKADDR_STORAGE
10961096
PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
10971097
PGAC_STRUCT_ADDRINFO
1098+
AC_TYPE_INTPTR_T
1099+
AC_TYPE_UINTPTR_T
10981100

10991101
AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
11001102
[#include <sys/param.h>
@@ -1555,12 +1557,10 @@ if test $pgac_need_repl_snprintf = yes; then
15551557
AC_LIBOBJ(snprintf)
15561558
fi
15571559

1558-
# Need a #define for the size of Datum (unsigned long)
1559-
AC_CHECK_SIZEOF([unsigned long])
1560-
1561-
# And check size of void *, size_t (enables tweaks for > 32bit address space)
1560+
# Check size of void *, size_t (enables tweaks for > 32bit address space)
15621561
AC_CHECK_SIZEOF([void *])
15631562
AC_CHECK_SIZEOF([size_t])
1563+
AC_CHECK_SIZEOF([long])
15641564

15651565
# Decide whether float4 is passed by value: user-selectable, enabled by default
15661566
AC_MSG_CHECKING([whether to build with float4 passed by value])
@@ -1577,7 +1577,7 @@ AC_DEFINE_UNQUOTED([FLOAT4PASSBYVAL], [$float4passbyval], [float4 values are pas
15771577
# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
15781578
# If not, trying to select it is an error.
15791579
AC_MSG_CHECKING([whether to build with float8 passed by value])
1580-
if test $ac_cv_sizeof_unsigned_long -ge 8 ; then
1580+
if test $ac_cv_sizeof_void_p -ge 8 ; then
15811581
PGAC_ARG_BOOL(enable, float8-byval, yes, [disable float8 passed by value])
15821582
else
15831583
PGAC_ARG_BOOL(enable, float8-byval, no, [disable float8 passed by value])

‎src/backend/access/common/heaptuple.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*
5151
*
5252
* IDENTIFICATION
53-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.127 2009/06/11 14:48:53 momjian Exp $
53+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.128 2009/12/31 19:41:33 tgl Exp $
5454
*
5555
*-------------------------------------------------------------------------
5656
*/
@@ -192,7 +192,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
192192
if (att[i]->attbyval)
193193
{
194194
/* pass-by-value */
195-
data= (char*)att_align_nominal((long)data,att[i]->attalign);
195+
data= (char*)att_align_nominal(data,att[i]->attalign);
196196
store_att_byval(data,values[i],att[i]->attlen);
197197
data_length=att[i]->attlen;
198198
}
@@ -226,7 +226,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
226226
else
227227
{
228228
/* full 4-byte header varlena */
229-
data= (char*)att_align_nominal((long)data,
229+
data= (char*)att_align_nominal(data,
230230
att[i]->attalign);
231231
data_length=VARSIZE(val);
232232
memcpy(data,val,data_length);
@@ -243,7 +243,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
243243
else
244244
{
245245
/* fixed-length pass-by-reference */
246-
data= (char*)att_align_nominal((long)data,att[i]->attalign);
246+
data= (char*)att_align_nominal(data,att[i]->attalign);
247247
Assert(att[i]->attlen>0);
248248
data_length=att[i]->attlen;
249249
memcpy(data,DatumGetPointer(values[i]),data_length);

‎src/backend/access/hash/hashfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashfunc.c,v 1.59 2009/06/11 14:48:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashfunc.c,v 1.60 2009/12/31 19:41:33 tgl Exp $
1212
*
1313
* NOTES
1414
* These functions are stored in pg_amproc.For each operator class
@@ -319,7 +319,7 @@ hash_any(register const unsigned char *k, register int keylen)
319319
a=b=c=0x9e3779b9+len+3923095;
320320

321321
/* If the source pointer is word-aligned, we use word-wide fetches */
322-
if (((long)k&UINT32_ALIGN_MASK)==0)
322+
if (((intptr_t)k&UINT32_ALIGN_MASK)==0)
323323
{
324324
/* Code path for aligned source data */
325325
registerconstuint32*ka= (constuint32*)k;

‎src/backend/port/hpux/tas.c.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tas(lock)
2020
* LDCWX requires that we align the "semaphore" to a 16-byte
2121
* boundary. The actual datum is a single word (4 bytes).
2222
*/
23-
lock = ((long) lock + 15) & ~15;
23+
lock = ((uintptr_t) lock + 15) & ~15;
2424

2525
/*
2626
* The LDCWX instruction atomically clears the target word and

‎src/backend/storage/lmgr/lwlock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.53 2009/01/01 17:23:48 momjian Exp $
18+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.54 2009/12/31 19:41:34 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -245,7 +245,7 @@ CreateLWLocks(void)
245245
ptr+=2*sizeof(int);
246246

247247
/* Ensure desired alignment of LWLock array */
248-
ptr+=LWLOCK_PADDED_SIZE- ((unsigned long)ptr) %LWLOCK_PADDED_SIZE;
248+
ptr+=LWLOCK_PADDED_SIZE- ((uintptr_t)ptr) %LWLOCK_PADDED_SIZE;
249249

250250
LWLockArray= (LWLockPadded*)ptr;
251251

‎src/backend/utils/misc/guc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.529 2009/12/21 01:34:11 rhaas Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.530 2009/12/31 19:41:34 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -87,7 +87,8 @@
8787
#endif
8888

8989
/* upper limit for GUC variables measured in kilobytes of memory */
90-
#ifSIZEOF_SIZE_T>4
90+
/* note that various places assume the byte size fits in a "long" variable */
91+
#ifSIZEOF_SIZE_T>4&&SIZEOF_LONG>4
9192
#defineMAX_KILOBYTESINT_MAX
9293
#else
9394
#defineMAX_KILOBYTES(INT_MAX / 1024)

‎src/include/access/tupmacs.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/tupmacs.h,v 1.36 2009/01/01 17:23:56 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/tupmacs.h,v 1.37 2009/12/31 19:41:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -100,7 +100,8 @@
100100
*/
101101
#defineatt_align_datum(cur_offset,attalign,attlen,attdatum) \
102102
( \
103-
((attlen) == -1 && VARATT_IS_SHORT(DatumGetPointer(attdatum))) ? (long) (cur_offset) : \
103+
((attlen) == -1 && VARATT_IS_SHORT(DatumGetPointer(attdatum))) ? \
104+
(intptr_t) (cur_offset) : \
104105
att_align_nominal(cur_offset, attalign) \
105106
)
106107

@@ -115,12 +116,13 @@
115116
* aligned 4-byte length word; in either case we need not align.)
116117
*
117118
* Note: some callers pass a "char *" pointer for cur_offset. This is
118-
* a bit of a hack butworks OK onallknown platforms. It ought to be
119-
*cleaned up someday, though.
119+
* a bit of a hack butshould workallright as long as intptr_t is the
120+
*correct width.
120121
*/
121122
#defineatt_align_pointer(cur_offset,attalign,attlen,attptr) \
122123
( \
123-
((attlen) == -1 && VARATT_NOT_PAD_BYTE(attptr)) ? (long) (cur_offset) : \
124+
((attlen) == -1 && VARATT_NOT_PAD_BYTE(attptr)) ? \
125+
(intptr_t) (cur_offset) : \
124126
att_align_nominal(cur_offset, attalign) \
125127
)
126128

@@ -142,7 +144,7 @@
142144
#defineatt_align_nominal(cur_offset,attalign) \
143145
( \
144146
((attalign) == 'i') ? INTALIGN(cur_offset) : \
145-
(((attalign) == 'c') ? (long) (cur_offset) : \
147+
(((attalign) == 'c') ? (intptr_t) (cur_offset) : \
146148
(((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
147149
( \
148150
AssertMacro((attalign) == 's'), \

‎src/include/c.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/c.h,v 1.236 2009/06/11 14:49:08 momjian Exp $
15+
* $PostgreSQL: pgsql/src/include/c.h,v 1.237 2009/12/31 19:41:35 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -72,6 +72,9 @@
7272
#ifdefHAVE_STRINGS_H
7373
#include<strings.h>
7474
#endif
75+
#ifdefHAVE_STDINT_H
76+
#include<stdint.h>
77+
#endif
7578
#include<sys/types.h>
7679

7780
#include<errno.h>
@@ -492,7 +495,7 @@ typedef NameData *Name;
492495
*True iff pointer is properly aligned to point to the given type.
493496
*/
494497
#definePointerIsAligned(pointer,type) \
495-
(((long)(pointer) % (sizeof (type))) == 0)
498+
(((intptr_t)(pointer) % (sizeof (type))) == 0)
496499

497500
#defineOidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
498501

@@ -538,7 +541,7 @@ typedef NameData *Name;
538541
*/
539542

540543
#defineTYPEALIGN(ALIGNVAL,LEN) \
541-
(((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1)))
544+
(((intptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((intptr_t) ((ALIGNVAL) - 1)))
542545

543546
#defineSHORTALIGN(LEN)TYPEALIGN(ALIGNOF_SHORT, (LEN))
544547
#defineINTALIGN(LEN)TYPEALIGN(ALIGNOF_INT, (LEN))
@@ -549,7 +552,7 @@ typedef NameData *Name;
549552
#defineBUFFERALIGN(LEN)TYPEALIGN(ALIGNOF_BUFFER, (LEN))
550553

551554
#defineTYPEALIGN_DOWN(ALIGNVAL,LEN) \
552-
(((long) (LEN)) & ~((long) ((ALIGNVAL) - 1)))
555+
(((intptr_t) (LEN)) & ~((intptr_t) ((ALIGNVAL) - 1)))
553556

554557
#defineSHORTALIGN_DOWN(LEN)TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
555558
#defineINTALIGN_DOWN(LEN)TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
@@ -630,7 +633,7 @@ typedef NameData *Name;
630633
int_val= (val); \
631634
Size_len= (len); \
632635
\
633-
if ((((long)_vstart)&LONG_ALIGN_MASK)==0&& \
636+
if ((((intptr_t)_vstart)&LONG_ALIGN_MASK)==0&& \
634637
(_len&LONG_ALIGN_MASK)==0&& \
635638
_val==0&& \
636639
_len <=MEMSET_LOOP_LIMIT&& \

‎src/include/pg_config.h.in

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@
236236
/* Define to 1 if the system has the type `int8'. */
237237
#undef HAVE_INT8
238238

239+
/* Define to 1 if the system has the type `intptr_t'. */
240+
#undef HAVE_INTPTR_T
241+
239242
/* Define to 1 if you have the <inttypes.h> header file. */
240243
#undef HAVE_INTTYPES_H
241244

@@ -599,6 +602,9 @@
599602
/* Define to 1 if the system has the type `uint8'. */
600603
#undef HAVE_UINT8
601604

605+
/* Define to 1 if the system has the type `uintptr_t'. */
606+
#undef HAVE_UINTPTR_T
607+
602608
/* Define to 1 if the system has the type `union semun'. */
603609
#undef HAVE_UNION_SEMUN
604610

@@ -705,15 +711,15 @@
705711
RELSEG_SIZE requires an initdb. */
706712
#undef RELSEG_SIZE
707713

714+
/* The size of `long', as computed by sizeof. */
715+
#undef SIZEOF_LONG
716+
708717
/* The size of `off_t', as computed by sizeof. */
709718
#undef SIZEOF_OFF_T
710719

711720
/* The size of `size_t', as computed by sizeof. */
712721
#undef SIZEOF_SIZE_T
713722

714-
/* The size of `unsigned long', as computed by sizeof. */
715-
#undef SIZEOF_UNSIGNED_LONG
716-
717723
/* The size of `void *', as computed by sizeof. */
718724
#undef SIZEOF_VOID_P
719725

@@ -827,9 +833,17 @@
827833
#undef inline
828834
#endif
829835

836+
/* Define to the type of a signed integer type wide enough to hold a pointer,
837+
if such a type exists, and if the system does not define it. */
838+
#undef intptr_t
839+
830840
/* Define to empty if the C compiler does not understand signed types. */
831841
#undef signed
832842

843+
/* Define to the type of an unsigned integer type wide enough to hold a
844+
pointer, if such a type exists, and if the system does not define it. */
845+
#undef uintptr_t
846+
833847
/* Define to empty if the keyword `volatile' does not work. Warning: valid
834848
code using `volatile' can become incorrect without. Disable with care. */
835849
#undef volatile

‎src/include/pg_config.h.win32

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
/* #undef HAVE_SRANDOM */
348348

349349
/* Define to 1 if you have the <stdint.h> header file. */
350-
#define HAVE_STDINT_H1
350+
/* #undef HAVE_STDINT_H*/
351351

352352
/* Define to 1 if you have the <stdlib.h> header file. */
353353
#define HAVE_STDLIB_H 1
@@ -585,11 +585,14 @@
585585
your system. */
586586
/* #undef PTHREAD_CREATE_JOINABLE */
587587

588-
/* The size of a `size_t', as computed by sizeof. */
588+
/* The size of `long', as computed by sizeof. */
589+
#define SIZEOF_LONG 4
590+
591+
/* The size of `size_t', as computed by sizeof. */
589592
#define SIZEOF_SIZE_T 4
590593

591-
/* The size ofa `unsigned long', as computed by sizeof. */
592-
#defineSIZEOF_UNSIGNED_LONG 4
594+
/* The size of`void *', as computed by sizeof. */
595+
#defineSIZEOF_VOID_P 4
593596

594597
/* Define to 1 if you have the ANSI C header files. */
595598
#define STDC_HEADERS 1

‎src/include/postgres.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1995, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.92 2009/01/01 17:23:55 momjian Exp $
13+
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.93 2009/12/31 19:41:35 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -285,16 +285,10 @@ typedef struct
285285

286286
/*
287287
* Port Notes:
288-
*Postgres makes the following assumption about machines:
289-
*
290-
*sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
291-
*
292-
*Postgres also assumes that
288+
*Postgres makes the following assumptions about datatype sizes:
293289
*
290+
*sizeof(Datum) == sizeof(void *) == 4 or 8
294291
*sizeof(char) == 1
295-
*
296-
*and that
297-
*
298292
*sizeof(short) == 2
299293
*
300294
* When a type narrower than Datum is stored in a Datum, we place it in the
@@ -305,9 +299,9 @@ typedef struct
305299
* or short may contain garbage when called as if it returned Datum.
306300
*/
307301

308-
typedefunsigned longDatum;/* XXX sizeof(long) >= sizeof(void *) */
302+
typedefuintptr_tDatum;
309303

310-
#defineSIZEOF_DATUMSIZEOF_UNSIGNED_LONG
304+
#defineSIZEOF_DATUMSIZEOF_VOID_P
311305

312306
typedefDatum*DatumPtr;
313307

‎src/include/storage/s_lock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
6767
* Portions Copyright (c) 1994, Regents of the University of California
6868
*
69-
* $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.167 2009/07/27 05:31:05 tgl Exp $
69+
* $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.168 2009/12/31 19:41:36 tgl Exp $
7070
*
7171
*-------------------------------------------------------------------------
7272
*/
@@ -683,7 +683,7 @@ typedef struct
683683
intsema[4];
684684
}slock_t;
685685

686-
#defineTAS_ACTIVE_WORD(lock)((volatile int *) (((long) (lock) + 15) & ~15))
686+
#defineTAS_ACTIVE_WORD(lock)((volatile int *) (((uintptr_t) (lock) + 15) & ~15))
687687

688688
#if defined(__GNUC__)
689689

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp