Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 07ae591

Browse files
committed
Attached is a patch that uses autoconf to determine whether there
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
1 parent 9cad9fe commit 07ae591

File tree

5 files changed

+94
-19
lines changed

5 files changed

+94
-19
lines changed

src/backend/parser/gram.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
*
220220
*
221221
* IDENTIFICATION
222-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/gram.c,v 2.27 1998/08/19 14:51:26 momjian Exp $
222+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/gram.c,v 2.28 1998/08/23 22:25:47 momjian Exp $
223223
*
224224
* HISTORY
225225
* AUTHOR DATE MAJOR EVENT

src/backend/parser/scan.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* A lexical scanner generated by flex */
22

33
/* Scanner skeleton version:
4-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.23 1998/08/17 03:50:15 scrappy Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.24 1998/08/23 22:25:51 momjian Exp $
55
*/
66

77
#define FLEX_SCANNER
@@ -555,7 +555,7 @@ char *yytext;
555555
*
556556
*
557557
* IDENTIFICATION
558-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.23 1998/08/17 03:50:15 scrappy Exp $
558+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.24 1998/08/23 22:25:51 momjian Exp $
559559
*
560560
*-------------------------------------------------------------------------
561561
*/

src/configure.in

+77-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,83 @@ AC_TRY_RUN([#include <stdlib.h>
522522
#endif
523523
main() { double d = DBL_MIN; if (d != DBL_MIN) exit(-1); else exit(0); }],
524524
AC_MSG_RESULT(yes),
525-
[AC_MSG_RESULT(no) AC_DEFINE(HAVE_DBL_MIN_PROBLEM)])
525+
[AC_MSG_RESULT(no) AC_DEFINE(HAVE_DBL_MIN_PROBLEM)],
526+
AC_MSG_RESULT(assuming ok on target machine))
527+
528+
dnl Check to see if we have a working 64-bit integer type.
529+
AC_MSG_CHECKING(whether 'long int' is 64 bits)
530+
AC_TRY_RUN([#include <stdio.h>
531+
typedef long int int64;
532+
#define INT64_FORMAT "%ld"
533+
534+
int64 a = 20000001;
535+
int64 b = 40000005;
536+
537+
int does_int64_work()
538+
{
539+
int64 c,d,e;
540+
char buf[100];
541+
542+
if (sizeof(int64) != 8)
543+
return 0; /* doesn't look like the right size */
544+
545+
/* we do perfunctory checks on multiply, divide, sprintf, sscanf */
546+
c = a * b;
547+
sprintf(buf, INT64_FORMAT, c);
548+
if (strcmp(buf, "800000140000005") != 0)
549+
return 0; /* either multiply or sprintf is busted */
550+
if (sscanf(buf, INT64_FORMAT, &d) != 1)
551+
return 0;
552+
if (d != c)
553+
return 0;
554+
e = d / b;
555+
if (e != a)
556+
return 0;
557+
return 1;
558+
}
559+
main() {
560+
exit(! does_int64_work());
561+
}],
562+
[AC_MSG_RESULT(yes) AC_DEFINE(HAVE_LONG_INT_64)],
563+
AC_MSG_RESULT(no),
564+
AC_MSG_RESULT(assuming not on target machine))
565+
566+
AC_MSG_CHECKING(whether 'long long int' is 64 bits)
567+
AC_TRY_RUN([#include <stdio.h>
568+
typedef long long int int64;
569+
#define INT64_FORMAT "%Ld"
570+
571+
int64 a = 20000001;
572+
int64 b = 40000005;
573+
574+
int does_int64_work()
575+
{
576+
int64 c,d,e;
577+
char buf[100];
578+
579+
if (sizeof(int64) != 8)
580+
return 0; /* doesn't look like the right size */
581+
582+
/* we do perfunctory checks on multiply, divide, sprintf, sscanf */
583+
c = a * b;
584+
sprintf(buf, INT64_FORMAT, c);
585+
if (strcmp(buf, "800000140000005") != 0)
586+
return 0; /* either multiply or sprintf is busted */
587+
if (sscanf(buf, INT64_FORMAT, &d) != 1)
588+
return 0;
589+
if (d != c)
590+
return 0;
591+
e = d / b;
592+
if (e != a)
593+
return 0;
594+
return 1;
595+
}
596+
main() {
597+
exit(! does_int64_work());
598+
}],
599+
[AC_MSG_RESULT(yes) AC_DEFINE(HAVE_LONG_LONG_INT_64)],
600+
AC_MSG_RESULT(no),
601+
AC_MSG_RESULT(assuming not on target machine))
526602

527603
dnl Checks for library functions.
528604
AC_PROG_GCC_TRADITIONAL

src/include/config.h.in

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ extern void srandom(int seed);
219219
/* Set to 1 if your DBL_MIN is problematic */
220220
#undef HAVE_DBL_MIN_PROBLEM
221221

222+
/* Set to 1 if type "long int" works and is 64 bits */
223+
#undef HAVE_LONG_INT_64
224+
225+
/* Set to 1 if type "long long int" works and is 64 bits */
226+
#undef HAVE_LONG_LONG_INT_64
227+
222228
/*
223229
* Code below this point should not require changes
224230
*/

src/include/utils/int8.h

+8-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: int8.h,v 1.1 1998/07/08 14:10:30 thomas Exp $
9+
* $Id: int8.h,v 1.2 1998/08/23 22:25:54 momjian Exp $
1010
*
1111
* NOTES
1212
* These data types are supported on all 64-bit architectures, and may
@@ -23,29 +23,22 @@
2323
#ifndef INT8_H
2424
#define INT8_H
2525

26-
#if defined(__alpha) || defined(PPC)
26+
#ifdef HAVE_LONG_INT_64
27+
/* Plain "long int" fits, use it */
2728
typedef long int int64;
28-
2929
#define INT64_FORMAT "%ld"
30-
31-
#elif defined(__GNUC__) && defined(i386)
30+
#else
31+
#ifdef HAVE_LONG_LONG_INT_64
32+
/* We have working support for "long long int", use that */
3233
typedef long long int int64;
33-
3434
#define INT64_FORMAT "%Ld"
35-
3635
#else
36+
/* Won't actually work, but fall back to long int so that int8.c compiles */
3737
typedef long int int64;
38-
3938
#define INT64_FORMAT "%ld"
39+
#define INT64_IS_BUSTED
4040
#endif
41-
42-
43-
/*
44-
#if sizeof(int64) == 8
45-
#define HAVE_64BIT_INTS 1
4641
#endif
47-
*/
48-
4942

5043
extern int64 *int8in(char *str);
5144
extern char *int8out(int64 * val);

0 commit comments

Comments
 (0)