Attached is a patch that uses autoconf to determine whether there
authorBruce Momjian
Sun, 23 Aug 1998 22:25:54 +0000 (22:25 +0000)
committerBruce Momjian
Sun, 23 Aug 1998 22:25:54 +0000 (22:25 +0000)
is a working 64-bit-int type available.

In playing around with it on my machine, I found that gcc provides
perfectly fine support for "long long" arithmetic ... but sprintf()
and sscanf(), which are system-supplied, don't work :-(.  So the
autoconf test program does a cursory test on them too.

If we find that a lot of systems are like this, it might be worth
the trouble to implement binary<->ASCII conversion of int64 ourselves
rather than relying on sprintf/sscanf to handle the data type.

regards, tom lane

src/backend/parser/gram.c
src/backend/parser/scan.c
src/configure.in
src/include/config.h.in
src/include/utils/int8.h

index fe45472fea0ecccf36a4e8baa771c53c3dab98e4..d18687dc73f4ff21a8af702feb9ae1f711dd17ce 100644 (file)
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/Attic/gram.c,v 2.27 1998/08/19 14:51:26 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/Attic/gram.c,v 2.28 1998/08/23 22:25:47 momjian Exp $
  *
  * HISTORY
  *   AUTHOR            DATE            MAJOR EVENT
index cede710c44ebe811d8b16e07e6efad18a0266787..0b9e8b41542e784df90ee1822a3ed92b097f5807 100644 (file)
@@ -1,7 +1,7 @@
 /* A lexical scanner generated by flex */
 
 /* Scanner skeleton version:
- * $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.23 1998/08/17 03:50:15 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.24 1998/08/23 22:25:51 momjian Exp $
  */
 
 #define FLEX_SCANNER
@@ -555,7 +555,7 @@ char *yytext;
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.23 1998/08/17 03:50:15 scrappy Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.24 1998/08/23 22:25:51 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
index 423faada999f333c5cb22f3ea57f18cd4cee2e95..b81d129ef331fa916615f2f38fe210819b7f8cc4 100644 (file)
@@ -522,7 +522,83 @@ AC_TRY_RUN([#include 
 #endif
 main() { double d = DBL_MIN; if (d != DBL_MIN) exit(-1); else exit(0); }],
    AC_MSG_RESULT(yes),
-   [AC_MSG_RESULT(no) AC_DEFINE(HAVE_DBL_MIN_PROBLEM)])
+   [AC_MSG_RESULT(no) AC_DEFINE(HAVE_DBL_MIN_PROBLEM)],
+   AC_MSG_RESULT(assuming ok on target machine))
+
+dnl Check to see if we have a working 64-bit integer type.
+AC_MSG_CHECKING(whether 'long int' is 64 bits)
+AC_TRY_RUN([#include 
+typedef long int int64;
+#define INT64_FORMAT "%ld"
+
+int64 a = 20000001;
+int64 b = 40000005;
+
+int does_int64_work()
+{
+  int64 c,d,e;
+  char buf[100];
+
+  if (sizeof(int64) != 8)
+    return 0;          /* doesn't look like the right size */
+
+  /* we do perfunctory checks on multiply, divide, sprintf, sscanf */
+  c = a * b;
+  sprintf(buf, INT64_FORMAT, c);
+  if (strcmp(buf, "800000140000005") != 0)
+    return 0;          /* either multiply or sprintf is busted */
+  if (sscanf(buf, INT64_FORMAT, &d) != 1)
+    return 0;
+  if (d != c)
+    return 0;
+  e = d / b;
+  if (e != a)
+    return 0;
+  return 1;
+}
+main() {
+  exit(! does_int64_work());
+}],
+   [AC_MSG_RESULT(yes) AC_DEFINE(HAVE_LONG_INT_64)],
+   AC_MSG_RESULT(no),
+   AC_MSG_RESULT(assuming not on target machine))
+
+AC_MSG_CHECKING(whether 'long long int' is 64 bits)
+AC_TRY_RUN([#include 
+typedef long long int int64;
+#define INT64_FORMAT "%Ld"
+
+int64 a = 20000001;
+int64 b = 40000005;
+
+int does_int64_work()
+{
+  int64 c,d,e;
+  char buf[100];
+
+  if (sizeof(int64) != 8)
+    return 0;          /* doesn't look like the right size */
+
+  /* we do perfunctory checks on multiply, divide, sprintf, sscanf */
+  c = a * b;
+  sprintf(buf, INT64_FORMAT, c);
+  if (strcmp(buf, "800000140000005") != 0)
+    return 0;          /* either multiply or sprintf is busted */
+  if (sscanf(buf, INT64_FORMAT, &d) != 1)
+    return 0;
+  if (d != c)
+    return 0;
+  e = d / b;
+  if (e != a)
+    return 0;
+  return 1;
+}
+main() {
+  exit(! does_int64_work());
+}],
+   [AC_MSG_RESULT(yes) AC_DEFINE(HAVE_LONG_LONG_INT_64)],
+   AC_MSG_RESULT(no),
+   AC_MSG_RESULT(assuming not on target machine))
 
 dnl Checks for library functions.
 AC_PROG_GCC_TRADITIONAL
index c849b078325439882b5197e19f81a26a44fa1da5..f8836576cfecbedc693703a34c93f590c772f3e4 100644 (file)
@@ -219,6 +219,12 @@ extern void srandom(int seed);
 /* Set to 1 if your DBL_MIN is problematic */
 #undef HAVE_DBL_MIN_PROBLEM
 
+/* Set to 1 if type "long int" works and is 64 bits */
+#undef HAVE_LONG_INT_64
+
+/* Set to 1 if type "long long int" works and is 64 bits */
+#undef HAVE_LONG_LONG_INT_64
+
 /*
  * Code below this point should not require changes
  */
index e285754d2ee5eee437a77489005a1c81d9694f68..dff02b71206bfb1851d566d1b37191d86016c32e 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: int8.h,v 1.1 1998/07/08 14:10:30 thomas Exp $
+ * $Id: int8.h,v 1.2 1998/08/23 22:25:54 momjian Exp $
  *
  * NOTES
  * These data types are supported on all 64-bit architectures, and may
 #ifndef INT8_H
 #define INT8_H
 
-#if defined(__alpha) || defined(PPC)
+#ifdef HAVE_LONG_INT_64
+/* Plain "long int" fits, use it */
 typedef long int int64;
-
 #define INT64_FORMAT "%ld"
-
-#elif defined(__GNUC__) && defined(i386)
+#else
+#ifdef HAVE_LONG_LONG_INT_64
+/* We have working support for "long long int", use that */
 typedef long long int int64;
-
 #define INT64_FORMAT "%Ld"
-
 #else
+/* Won't actually work, but fall back to long int so that int8.c compiles */
 typedef long int int64;
-
 #define INT64_FORMAT "%ld"
+#define INT64_IS_BUSTED
 #endif
-
-
-/*
-#if sizeof(int64) == 8
-#define HAVE_64BIT_INTS 1
 #endif
-*/
-
 
 extern int64 *int8in(char *str);
 extern char *int8out(int64 * val);