Permalink
Browse files

Autoconfiscate selection of 64-bit int type for 64-bit large object API.

Get rid of the fundamentally indefensible assumption that "long long int"
exists and is exactly 64 bits wide on every platform Postgres runs on.
Instead let the configure script select the type to use for "pg_int64".

This is a bit of a pain in the rear since we do not want to pollute client
namespace with all the random symbols that pg_config.h defines; instead
we have to create a separate generated header file, "pg_config_ext.h".
But now that the infrastructure is there, we might have the ability to
add some other stuff that's long been wanting in this area.
  • Loading branch information...
tglsfdc committed Oct 8, 2012
1 parent ea72bb8 commit 95d035e66d8e4371d35830d81f39face03cd4c45
View
@@ -24238,7 +24238,9 @@ _ACEOF
fi
-if test x"$HAVE_LONG_INT_64" = x"no" ; then
+if test x"$HAVE_LONG_INT_64" = x"yes" ; then
+ pg_int64_type="long int"
+else
{ $as_echo "$as_me:$LINENO: checking whether long long int is 64 bits" >&5
$as_echo_n "checking whether long long int is 64 bits... " >&6; }
if test "${pgac_cv_type_long_long_int_64+set}" = set; then
@@ -24374,14 +24376,21 @@ _ACEOF
fi
- if test x"$HAVE_LONG_LONG_INT_64" = x"no" ; then
+ if test x"$HAVE_LONG_LONG_INT_64" = x"yes" ; then
+ pg_int64_type="long long int"
+ else
{ { $as_echo "$as_me:$LINENO: error: Cannot find a working 64-bit integer type." >&5
$as_echo "$as_me: error: Cannot find a working 64-bit integer type." >&2;}
{ (exit 1); exit 1; }; }
fi
fi
+cat >>confdefs.h <<_ACEOF
+#define PG_INT64_TYPE $pg_int64_type
+_ACEOF
+
+
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
cat >conftest.$ac_ext <<_ACEOF
@@ -29930,6 +29939,9 @@ fi
ac_config_headers="$ac_config_headers src/include/pg_config.h"
+ac_config_headers="$ac_config_headers src/include/pg_config_ext.h"
+
+
ac_config_headers="$ac_config_headers src/interfaces/ecpg/include/ecpg_config.h"
@@ -30550,6 +30562,7 @@ do
"src/Makefile.port") CONFIG_LINKS="$CONFIG_LINKS src/Makefile.port:src/makefiles/Makefile.${template}" ;;
"check_win32_symlinks") CONFIG_COMMANDS="$CONFIG_COMMANDS check_win32_symlinks" ;;
"src/include/pg_config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/include/pg_config.h" ;;
+ "src/include/pg_config_ext.h") CONFIG_HEADERS="$CONFIG_HEADERS src/include/pg_config_ext.h" ;;
"src/interfaces/ecpg/include/ecpg_config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/interfaces/ecpg/include/ecpg_config.h" ;;
*) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
@@ -31220,6 +31233,10 @@ $as_echo "$as_me: WARNING: *** link for $FILE -- please fix by hand" >&2;}
"src/include/pg_config.h":H)
# Update timestamp for pg_config.h (see Makefile.global)
echo >src/include/stamp-h
+ ;;
+ "src/include/pg_config_ext.h":H)
+# Update timestamp for pg_config_ext.h (see Makefile.global)
+echo >src/include/stamp-ext-h
;;
"src/interfaces/ecpg/include/ecpg_config.h":H) echo >src/interfaces/ecpg/include/stamp-h ;;
View
@@ -1580,13 +1580,19 @@ dnl 64-bit type. But we still handle the case of snprintf being broken.
PGAC_TYPE_64BIT_INT([long int])
-if test x"$HAVE_LONG_INT_64" = x"no" ; then
+if test x"$HAVE_LONG_INT_64" = x"yes" ; then
+ pg_int64_type="long int"
+else
PGAC_TYPE_64BIT_INT([long long int])
- if test x"$HAVE_LONG_LONG_INT_64" = x"no" ; then
+ if test x"$HAVE_LONG_LONG_INT_64" = x"yes" ; then
+ pg_int64_type="long long int"
+ else
AC_MSG_ERROR([Cannot find a working 64-bit integer type.])
fi
fi
+AC_DEFINE_UNQUOTED(PG_INT64_TYPE, $pg_int64_type,
+ [Define to the name of a signed 64-bit integer type.])
dnl If we need to use "long long int", figure out whether nnnLL notation works.
@@ -1935,6 +1941,12 @@ AC_CONFIG_HEADERS([src/include/pg_config.h],
echo >src/include/stamp-h
])
+AC_CONFIG_HEADERS([src/include/pg_config_ext.h],
+[
+# Update timestamp for pg_config_ext.h (see Makefile.global)
+echo >src/include/stamp-ext-h
+])
+
AC_CONFIG_HEADERS([src/interfaces/ecpg/include/ecpg_config.h],
[echo >src/interfaces/ecpg/include/stamp-h])
View
@@ -539,6 +539,12 @@ $(top_builddir)/src/include/pg_config.h: $(top_builddir)/src/include/stamp-h ;
$(top_builddir)/src/include/stamp-h: $(top_srcdir)/src/include/pg_config.h.in $(top_builddir)/config.status
cd $(top_builddir) && ./config.status src/include/pg_config.h
+# Also remake pg_config_ext.h from pg_config_ext.h.in, same logic as above.
+$(top_builddir)/src/include/pg_config_ext.h: $(top_builddir)/src/include/stamp-ext-h ;
+
+$(top_builddir)/src/include/stamp-ext-h: $(top_srcdir)/src/include/pg_config_ext.h.in $(top_builddir)/config.status
+ cd $(top_builddir) && ./config.status src/include/pg_config_ext.h
+
# Also remake ecpg_config.h from ecpg_config.h.in if the latter changed, same
# logic as above.
$(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h: $(top_builddir)/src/interfaces/ecpg/include/stamp-h ;
View
@@ -26,6 +26,7 @@ NULL=nul
ALL:
cd include
if not exist pg_config.h copy pg_config.h.win32 pg_config.h
+ if not exist pg_config_ext.h copy pg_config_ext.h.win32 pg_config_ext.h
if not exist pg_config_os.h copy port\win32.h pg_config_os.h
cd ..
cd interfaces\libpq
@@ -42,5 +43,5 @@ CLEAN:
DISTCLEAN: CLEAN
cd include
- del pg_config.h pg_config_os.h
+ del pg_config.h pg_config_ext.h pg_config_os.h
cd ..
View
@@ -1,5 +1,6 @@
/stamp-h
+/stamp-ext-h
/pg_config.h
+/pg_config_ext.h
/pg_config_os.h
/dynloader.h
-
View
@@ -13,7 +13,7 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global
-all: pg_config.h pg_config_os.h
+all: pg_config.h pg_config_ext.h pg_config_os.h
# Subdirectories containing headers for server-side dev
@@ -29,17 +29,19 @@ install: all installdirs
# These headers are needed by the public headers of the interfaces.
$(INSTALL_DATA) $(srcdir)/postgres_ext.h '$(DESTDIR)$(includedir)'
$(INSTALL_DATA) $(srcdir)/libpq/libpq-fs.h '$(DESTDIR)$(includedir)/libpq'
- $(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir)'
- $(INSTALL_DATA) pg_config_os.h '$(DESTDIR)$(includedir)'
+ $(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir)'
+ $(INSTALL_DATA) pg_config_ext.h '$(DESTDIR)$(includedir)'
+ $(INSTALL_DATA) pg_config_os.h '$(DESTDIR)$(includedir)'
$(INSTALL_DATA) $(srcdir)/pg_config_manual.h '$(DESTDIR)$(includedir)'
# These headers are needed by the not-so-public headers of the interfaces.
$(INSTALL_DATA) $(srcdir)/c.h '$(DESTDIR)$(includedir_internal)'
$(INSTALL_DATA) $(srcdir)/port.h '$(DESTDIR)$(includedir_internal)'
$(INSTALL_DATA) $(srcdir)/postgres_fe.h '$(DESTDIR)$(includedir_internal)'
$(INSTALL_DATA) $(srcdir)/libpq/pqcomm.h '$(DESTDIR)$(includedir_internal)/libpq'
# These headers are needed for server-side development
- $(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir_server)'
- $(INSTALL_DATA) pg_config_os.h '$(DESTDIR)$(includedir_server)'
+ $(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir_server)'
+ $(INSTALL_DATA) pg_config_ext.h '$(DESTDIR)$(includedir_server)'
+ $(INSTALL_DATA) pg_config_os.h '$(DESTDIR)$(includedir_server)'
$(INSTALL_DATA) utils/errcodes.h '$(DESTDIR)$(includedir_server)/utils'
$(INSTALL_DATA) utils/fmgroids.h '$(DESTDIR)$(includedir_server)/utils'
# We don't use INSTALL_DATA for performance reasons --- there are a lot of files
@@ -62,7 +64,7 @@ installdirs:
uninstall:
- rm -f $(addprefix '$(DESTDIR)$(includedir)'/, pg_config.h pg_config_os.h pg_config_manual.h postgres_ext.h libpq/libpq-fs.h)
+ rm -f $(addprefix '$(DESTDIR)$(includedir)'/, pg_config.h pg_config_ext.h pg_config_os.h pg_config_manual.h postgres_ext.h libpq/libpq-fs.h)
rm -f $(addprefix '$(DESTDIR)$(includedir_internal)'/, c.h port.h postgres_fe.h libpq/pqcomm.h)
# heuristic...
rm -rf $(addprefix '$(DESTDIR)$(includedir_server)'/, $(SUBDIRS) *.h)
@@ -72,7 +74,7 @@ clean:
rm -f utils/fmgroids.h utils/errcodes.h parser/gram.h utils/probes.h catalog/schemapg.h
distclean maintainer-clean: clean
- rm -f pg_config.h dynloader.h pg_config_os.h stamp-h
+ rm -f pg_config.h pg_config_ext.h pg_config_os.h dynloader.h stamp-h stamp-ext-h
maintainer-check:
cd catalog && ./duplicate_oids
View
@@ -44,26 +44,30 @@
#ifndef C_H
#define C_H
-/*
- * We have to include stdlib.h here because it defines many of these macros
- * on some platforms, and we only want our definitions used if stdlib.h doesn't
- * have its own. The same goes for stddef and stdarg if present.
- */
+#include "postgres_ext.h"
+
+/* Must undef pg_config_ext.h symbols before including pg_config.h */
+#undef PG_INT64_TYPE
#include "pg_config.h"
#include "pg_config_manual.h" /* must be after pg_config.h */
-#if !defined(WIN32) && !defined(__CYGWIN__) /* win32 will include further
- * down */
+
+#if !defined(WIN32) && !defined(__CYGWIN__) /* win32 includes further down */
#include "pg_config_os.h" /* must be before any system header files */
#endif
-#include "postgres_ext.h"
#if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H)
#define errcode __msvc_errcode
#include <crtdefs.h>
#undef errcode
#endif
+/*
+ * We have to include stdlib.h here because it defines many of these macros
+ * on some platforms, and we only want our definitions used if stdlib.h doesn't
+ * have its own. The same goes for stddef and stdarg if present.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -671,6 +671,9 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION
+/* Define to the name of a signed 64-bit integer type. */
+#undef PG_INT64_TYPE
+
/* Define to the name of the default PostgreSQL service principal in Kerberos.
(--with-krb-srvnam=NAME) */
#undef PG_KRB_SRVNAM
@@ -562,6 +562,9 @@
/* Define to the version of this package. */
#define PACKAGE_VERSION "9.3devel"
+/* Define to the name of a signed 64-bit integer type. */
+#define PG_INT64_TYPE long long int
+
/* PostgreSQL version as a string */
#define PG_VERSION "9.3devel"
@@ -0,0 +1,7 @@
+/*
+ * src/include/pg_config_ext.h.in. This is generated manually, not by
+ * autoheader, since we want to limit which symbols get defined here.
+ */
+
+/* Define to the name of a signed 64-bit integer type. */
+#undef PG_INT64_TYPE
@@ -0,0 +1,7 @@
+/*
+ * src/include/pg_config_ext.h.win32. This is generated manually, not by
+ * autoheader, since we want to limit which symbols get defined here.
+ */
+
+/* Define to the name of a signed 64-bit integer type. */
+#define PG_INT64_TYPE long long int
View
@@ -23,6 +23,8 @@
#ifndef POSTGRES_EXT_H
#define POSTGRES_EXT_H
+#include "pg_config_ext.h"
+
/*
* Object ID is a fundamental type in Postgres.
*/
@@ -37,6 +39,9 @@ typedef unsigned int Oid;
#define OID_MAX UINT_MAX
/* you will need to include <limits.h> to use the above #define */
+/* Define a signed 64-bit integer type for use in client API declarations. */
+typedef PG_INT64_TYPE pg_int64;
+
/*
* Identifiers of error message fields. Kept here to keep common
@@ -56,9 +61,4 @@ typedef unsigned int Oid;
#define PG_DIAG_SOURCE_LINE 'L'
#define PG_DIAG_SOURCE_FUNCTION 'R'
-#ifndef NO_PG_INT64
-#define HAVE_PG_INT64 1
-typedef long long int pg_int64;
-#endif
-
-#endif
+#endif /* POSTGRES_EXT_H */
@@ -62,10 +62,13 @@ typedef struct LargeObjectDesc
* This avoids unnecessary tuple updates caused by partial-page writes.
*/
#define LOBLKSIZE (BLCKSZ / 4)
+
/*
- * Maximum byte length for each large object
-*/
-#define MAX_LARGE_OBJECT_SIZE ((int64)INT_MAX * LOBLKSIZE)
+ * Maximum length in bytes for a large object. To make this larger, we'd
+ * have to widen pg_largeobject.pageno as well as various internal variables.
+ */
+#define MAX_LARGE_OBJECT_SIZE ((int64) INT_MAX * LOBLKSIZE)
+
/*
* Function definitions...
@@ -77,8 +80,8 @@ extern Oid inv_create(Oid lobjId);
extern LargeObjectDesc *inv_open(Oid lobjId, int flags, MemoryContext mcxt);
extern void inv_close(LargeObjectDesc *obj_desc);
extern int inv_drop(Oid lobjId);
-extern int64 inv_seek(LargeObjectDesc *obj_desc, int64 offset, int whence);
-extern int64 inv_tell(LargeObjectDesc *obj_desc);
+extern int64 inv_seek(LargeObjectDesc *obj_desc, int64 offset, int whence);
+extern int64 inv_tell(LargeObjectDesc *obj_desc);
extern int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes);
extern int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes);
extern void inv_truncate(LargeObjectDesc *obj_desc, int64 len);
@@ -153,11 +153,14 @@ LIB32_OBJS= \
"$(INTDIR)\pthread-win32.obj"
-config: ..\..\include\pg_config.h ..\..\include\pg_config_os.h pg_config_paths.h
+config: ..\..\include\pg_config.h ..\..\include\pg_config_ext.h ..\..\include\pg_config_os.h pg_config_paths.h
..\..\include\pg_config.h: ..\..\include\pg_config.h.win32
copy ..\..\include\pg_config.h.win32 ..\..\include\pg_config.h
+..\..\include\pg_config_ext.h: ..\..\include\pg_config_ext.h.win32
+ copy ..\..\include\pg_config_ext.h.win32 ..\..\include\pg_config_ext.h
+
..\..\include\pg_config_os.h: ..\..\include\port\win32.h
copy ..\..\include\port\win32.h ..\..\include\pg_config_os.h
Oops, something went wrong.

0 comments on commit 95d035e

Please sign in to comment.