unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
@ 2011-06-03  8:43 Paul Eggert
  2011-06-03 10:52 ` Eli Zaretskii
  2011-06-03 15:54 ` Stefan Monnier
  0 siblings, 2 replies; 21+ messages in thread
From: Paul Eggert @ 2011-06-03  8:43 UTC (permalink / raw)
  To: 8794

I found several problems in the Emacs code that converts
large C integers to Emacs conses-of-integers and back again.
I wrote some code to fix them systematically, and found that
it was simpler and more reliable if I could assume that EMACS_INT
was 64-bit even on 32-bit hosts.  So here's a patch to do all that.
I plan to test this a bit more before committing.

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: eggert@cs.ucla.edu-20110603052422-jleodvo6pg0bsrpk
# target_branch: bzr+ssh://eggert@bzr.savannah.gnu.org/emacs/trunk
# testament_sha1: 76b360c210c60c75ddc564f61f5ead41553b62f4
# timestamp: 2011-06-03 01:33:08 -0700
# base_revision_id: monnier@iro.umontreal.ca-20110602180444-\
#   lbjc3q55bwdn2fs5
# 
# Begin patch
=== modified file 'doc/emacs/ChangeLog'
--- doc/emacs/ChangeLog	2011-05-28 18:22:08 +0000
+++ doc/emacs/ChangeLog	2011-06-03 05:24:22 +0000
@@ -1,3 +1,9 @@
+2011-06-02  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Document wide integers better.
+	* buffers.texi (Buffers):
+	* files.texi (Visiting): Default buffer maximum is now 2 EiB typically.
+
 2011-05-28  Chong Yidong  <cyd@stupidchicken.com>
 
 	* custom.texi (Hooks): Reorganize.  Mention Prog mode.

=== modified file 'doc/emacs/buffers.texi'
--- doc/emacs/buffers.texi	2011-01-25 04:08:28 +0000
+++ doc/emacs/buffers.texi	2011-06-03 05:24:22 +0000
@@ -43,8 +43,11 @@
   A buffer's size cannot be larger than some maximum, which is defined
 by the largest buffer position representable by the @dfn{Emacs
 integer} data type.  This is because Emacs tracks buffer positions
-using that data type.  For 32-bit machines, the largest buffer size is
-512 megabytes.
+using that data type.  For most machines, the maximum buffer size
+enforced by the data types is @math{2^61 - 2} bytes, or about 2 EiB.
+For some older machines, the maximum is @math{2^29 - 2} bytes, or
+about 512 MiB.  Buffer sizes are also limited by the size of Emacs's
+virtual memory.
 
 @menu
 * Select Buffer::       Creating a new buffer or reselecting an old one.

=== modified file 'doc/emacs/files.texi'
--- doc/emacs/files.texi	2011-01-31 23:54:50 +0000
+++ doc/emacs/files.texi	2011-06-03 05:24:22 +0000
@@ -209,7 +209,7 @@
 about 10 megabytes), Emacs asks you for confirmation first.  You can
 answer @kbd{y} to proceed with visiting the file.  Note, however, that
 Emacs cannot visit files that are larger than the maximum Emacs buffer
-size, which is around 512 megabytes on 32-bit machines
+size, which is around 512 MiB on 32-bit machines and 2 EiB on 64-bit machines
 (@pxref{Buffers}).  If you try, Emacs will display an error message
 saying that the maximum buffer size has been exceeded.
 

=== modified file 'doc/lispref/ChangeLog'
--- doc/lispref/ChangeLog	2011-05-31 18:40:00 +0000
+++ doc/lispref/ChangeLog	2011-06-03 05:24:22 +0000
@@ -1,3 +1,12 @@
+2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Document wide integers better.
+	* files.texi (File Attributes): Document ino_t values better.
+	* numbers.texi (Integer Basics, Integer Basics, Arithmetic Operations):
+	(Bitwise Operations):
+	* objects.texi (Integer Type): Integers are typically 62 bits now.
+	* os.texi (Time Conversion): Document time_t values better.
+
 2011-05-31  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* processes.texi (Process Information): Document

=== modified file 'doc/lispref/files.texi'
--- doc/lispref/files.texi	2011-05-12 07:07:06 +0000
+++ doc/lispref/files.texi	2011-06-03 05:24:22 +0000
@@ -1236,12 +1236,13 @@
 
 @item
 The file's inode number.  If possible, this is an integer.  If the
-inode number is too large to be represented as an integer in Emacs
-Lisp, but still fits into a 32-bit integer, then the value has the
-form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16
-bits.  If the inode is wider than 32 bits, the value is of the form
+inode number @math{N} is too large to be represented as an integer in
+Emacs Lisp, but @math{N / 2^16} is representable, then the value has
+the form @code{(@var{high} . @var{low})}, where @var{high} holds the
+high bits (i.e., excluding the low-order bits) and @var{low} the low
+16 bits.  If the inode number is even larger, the value is of the form
 @code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds
-the high 24 bits, @var{middle} the next 24 bits, and @var{low} the low
+the high bits, @var{middle} the next 24 bits, and @var{low} the low
 16 bits.
 
 @item

=== modified file 'doc/lispref/numbers.texi'
--- doc/lispref/numbers.texi	2011-05-05 06:31:14 +0000
+++ doc/lispref/numbers.texi	2011-06-03 05:24:22 +0000
@@ -36,22 +36,24 @@
 @section Integer Basics
 
   The range of values for an integer depends on the machine.  The
-minimum range is @minus{}536870912 to 536870911 (30 bits; i.e.,
+typical range is @minus{}2305843009213693952 to 2305843009213693951
+(62 bits; i.e.,
 @ifnottex
--2**29
+-2**61
 @end ifnottex
 @tex
-@math{-2^{29}}
+@math{-2^{61}}
 @end tex
 to
 @ifnottex
-2**29 - 1),
+2**61 - 1)
 @end ifnottex
 @tex
-@math{2^{29}-1}),
+@math{2^{61}-1})
 @end tex
-but some machines may provide a wider range.  Many examples in this
-chapter assume an integer has 30 bits.
+but some older machines provide only 30 bits.  Many examples in this
+chapter assume that an integer has 62 bits and that floating point
+numbers are IEEE double precision.
 @cindex overflow
 
   The Lisp reader reads an integer as a sequence of digits with optional
@@ -63,7 +65,8 @@
  1.              ; @r{The integer 1.}
 +1               ; @r{Also the integer 1.}
 -1               ; @r{The integer @minus{}1.}
- 1073741825      ; @r{The floating point number 1073741825.0.}
+ 4611686018427387904
+                 ; @r{The floating point number 4.611686018427388e+18.}
  0               ; @r{The integer 0.}
 -0               ; @r{The integer 0.}
 @end example
@@ -94,25 +97,21 @@
 bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
 view the numbers in their binary form.
 
-  In 30-bit binary, the decimal integer 5 looks like this:
+  In 62-bit binary, the decimal integer 5 looks like this:
 
 @example
-00 0000  0000 0000  0000 0000  0000 0101
+0000...000101 (62 bits total)
 @end example
 
-@noindent
-(We have inserted spaces between groups of 4 bits, and two spaces
-between groups of 8 bits, to make the binary integer easier to read.)
-
   The integer @minus{}1 looks like this:
 
 @example
-11 1111  1111 1111  1111 1111  1111 1111
+1111...111111 (62 bits total)
 @end example
 
 @noindent
 @cindex two's complement
-@minus{}1 is represented as 30 ones.  (This is called @dfn{two's
+@minus{}1 is represented as 62 ones.  (This is called @dfn{two's
 complement} notation.)
 
   The negative integer, @minus{}5, is creating by subtracting 4 from
@@ -120,24 +119,24 @@
 @minus{}5 looks like this:
 
 @example
-11 1111  1111 1111  1111 1111  1111 1011
+1111...111011 (62 bits total)
 @end example
 
-  In this implementation, the largest 30-bit binary integer value is
-536,870,911 in decimal.  In binary, it looks like this:
+  In this implementation, the largest 62-bit binary integer value is
+2,305,843,009,213,693,951 in decimal.  In binary, it looks like this:
 
 @example
-01 1111  1111 1111  1111 1111  1111 1111
+0111...111111 (62 bits total)
 @end example
 
   Since the arithmetic functions do not check whether integers go
-outside their range, when you add 1 to 536,870,911, the value is the
-negative integer @minus{}536,870,912:
+outside their range, when you add 1 to 2,305,843,009,213,693,951, the value is the
+negative integer @minus{}2,305,843,009,213,693,952:
 
 @example
-(+ 1 536870911)
-     @result{} -536870912
-     @result{} 10 0000  0000 0000  0000 0000  0000 0000
+(+ 1 2305843009213693951)
+     @result{} -2305843009213693952
+     @result{} 1000...000000 (62 bits total)
 @end example
 
   Many of the functions described in this chapter accept markers for
@@ -508,8 +507,8 @@
 if any argument is floating.
 
   It is important to note that in Emacs Lisp, arithmetic functions
-do not check for overflow.  Thus @code{(1+ 268435455)} may evaluate to
-@minus{}268435456, depending on your hardware.
+do not check for overflow.  Thus @code{(1+ 2305843009213693951)} may
+evaluate to @minus{}2305843009213693952, depending on your hardware.
 
 @defun 1+ number-or-marker
 This function returns @var{number-or-marker} plus 1.
@@ -829,19 +828,19 @@
 The function @code{lsh}, like all Emacs Lisp arithmetic functions, does
 not check for overflow, so shifting left can discard significant bits
 and change the sign of the number.  For example, left shifting
-536,870,911 produces @minus{}2 on a 30-bit machine:
+2,305,843,009,213,693,951 produces @minus{}2 on a typical machine:
 
 @example
-(lsh 536870911 1)          ; @r{left shift}
+(lsh 2305843009213693951 1)  ; @r{left shift}
      @result{} -2
 @end example
 
-In binary, in the 30-bit implementation, the argument looks like this:
+In binary, in the 62-bit implementation, the argument looks like this:
 
 @example
 @group
-;; @r{Decimal 536,870,911}
-01 1111  1111 1111  1111 1111  1111 1111
+;; @r{Decimal 2,305,843,009,213,693,951}
+0111...111111 (62 bits total)
 @end group
 @end example
 
@@ -851,7 +850,7 @@
 @example
 @group
 ;; @r{Decimal @minus{}2}
-11 1111  1111 1111  1111 1111  1111 1110
+1111...111110 (62 bits total)
 @end group
 @end example
 @end defun
@@ -874,9 +873,9 @@
 @group
 (ash -6 -1) @result{} -3
 ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
-11 1111  1111 1111  1111 1111  1111 1010
+1111...111010 (62 bits total)
      @result{}
-11 1111  1111 1111  1111 1111  1111 1101
+1111...111101 (62 bits total)
 @end group
 @end example
 
@@ -885,11 +884,11 @@
 
 @example
 @group
-(lsh -6 -1) @result{} 536870909
-;; @r{Decimal @minus{}6 becomes decimal 536,870,909.}
-11 1111  1111 1111  1111 1111  1111 1010
+(lsh -6 -1) @result{} 2305843009213693949
+;; @r{Decimal @minus{}6 becomes decimal 2,305,843,009,213,693,949.}
+1111...111010 (62 bits total)
      @result{}
-01 1111  1111 1111  1111 1111  1111 1101
+0111...111101 (62 bits total)
 @end group
 @end example
 
@@ -899,34 +898,35 @@
 @c     with smallbook but not with regular book! --rjc 16mar92
 @smallexample
 @group
-                   ;  @r{             30-bit binary values}
+                   ;  @r{       62-bit binary values}
 
-(lsh 5 2)          ;   5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 20         ;      =  @r{00 0000  0000 0000  0000 0000  0001 0100}
+(lsh 5 2)          ;   5  =  @r{0000...000101}
+     @result{} 20         ;      =  @r{0000...010100}
 @end group
 @group
 (ash 5 2)
      @result{} 20
-(lsh -5 2)         ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
-     @result{} -20        ;      =  @r{11 1111  1111 1111  1111 1111  1110 1100}
+(lsh -5 2)         ;  -5  =  @r{1111...111011}
+     @result{} -20        ;      =  @r{1111...101100}
 (ash -5 2)
      @result{} -20
 @end group
 @group
-(lsh 5 -2)         ;   5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 1          ;      =  @r{00 0000  0000 0000  0000 0000  0000 0001}
+(lsh 5 -2)         ;   5  =  @r{0000...000101}
+     @result{} 1          ;      =  @r{0000...000001}
 @end group
 @group
 (ash 5 -2)
      @result{} 1
 @end group
 @group
-(lsh -5 -2)        ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
-     @result{} 268435454  ;      =  @r{00 0111  1111 1111  1111 1111  1111 1110}
+(lsh -5 -2)        ;  -5  =  @r{1111...111011}
+     @result{} 1152921504606846974
+                   ;      =  @r{0011...111110}
 @end group
 @group
-(ash -5 -2)        ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
-     @result{} -2         ;      =  @r{11 1111  1111 1111  1111 1111  1111 1110}
+(ash -5 -2)        ;  -5  =  @r{1111...111011}
+     @result{} -2         ;      =  @r{1111...111110}
 @end group
 @end smallexample
 @end defun
@@ -961,23 +961,23 @@
 
 @smallexample
 @group
-                   ; @r{               30-bit binary values}
+                   ; @r{       62-bit binary values}
 
-(logand 14 13)     ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
-                   ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
-     @result{} 12         ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
+(logand 14 13)     ; 14  =  @r{0000...001110}
+                   ; 13  =  @r{0000...001101}
+     @result{} 12         ; 12  =  @r{0000...001100}
 @end group
 
 @group
-(logand 14 13 4)   ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
-                   ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
-                   ;  4  =  @r{00 0000  0000 0000  0000 0000  0000 0100}
-     @result{} 4          ;  4  =  @r{00 0000  0000 0000  0000 0000  0000 0100}
+(logand 14 13 4)   ; 14  =  @r{0000...001110}
+                   ; 13  =  @r{0000...001101}
+                   ;  4  =  @r{0000...000100}
+     @result{} 4          ;  4  =  @r{0000...000100}
 @end group
 
 @group
 (logand)
-     @result{} -1         ; -1  =  @r{11 1111  1111 1111  1111 1111  1111 1111}
+     @result{} -1         ; -1  =  @r{1111...111111}
 @end group
 @end smallexample
 @end defun
@@ -991,18 +991,18 @@
 
 @smallexample
 @group
-                   ; @r{              30-bit binary values}
+                   ; @r{       62-bit binary values}
 
-(logior 12 5)      ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 13         ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
+(logior 12 5)      ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+     @result{} 13         ; 13  =  @r{0000...001101}
 @end group
 
 @group
-(logior 12 5 7)    ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-                   ;  7  =  @r{00 0000  0000 0000  0000 0000  0000 0111}
-     @result{} 15         ; 15  =  @r{00 0000  0000 0000  0000 0000  0000 1111}
+(logior 12 5 7)    ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+                   ;  7  =  @r{0000...000111}
+     @result{} 15         ; 15  =  @r{0000...001111}
 @end group
 @end smallexample
 @end defun
@@ -1016,18 +1016,18 @@
 
 @smallexample
 @group
-                   ; @r{              30-bit binary values}
+                   ; @r{       62-bit binary values}
 
-(logxor 12 5)      ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 9          ;  9  =  @r{00 0000  0000 0000  0000 0000  0000 1001}
+(logxor 12 5)      ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+     @result{} 9          ;  9  =  @r{0000...001001}
 @end group
 
 @group
-(logxor 12 5 7)    ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-                   ;  7  =  @r{00 0000  0000 0000  0000 0000  0000 0111}
-     @result{} 14         ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
+(logxor 12 5 7)    ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+                   ;  7  =  @r{0000...000111}
+     @result{} 14         ; 14  =  @r{0000...001110}
 @end group
 @end smallexample
 @end defun
@@ -1040,9 +1040,9 @@
 @example
 (lognot 5)
      @result{} -6
-;;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
+;;  5  =  @r{0000...000101} (62 bits total)
 ;; @r{becomes}
-;; -6  =  @r{11 1111  1111 1111  1111 1111  1111 1010}
+;; -6  =  @r{1111...111010} (62 bits total)
 @end example
 @end defun
 

=== modified file 'doc/lispref/objects.texi'
--- doc/lispref/objects.texi	2011-05-05 06:31:14 +0000
+++ doc/lispref/objects.texi	2011-06-03 05:24:22 +0000
@@ -164,25 +164,25 @@
 @node Integer Type
 @subsection Integer Type
 
-  The range of values for integers in Emacs Lisp is @minus{}536870912 to
-536870911 (30 bits; i.e.,
+  The range of values for integers in Emacs Lisp is
+@minus{}2305843009213693952 to 2305843009213693951 (62 bits; i.e.,
 @ifnottex
--2**29
+-2**61
 @end ifnottex
 @tex
-@math{-2^{29}}
+@math{-2^{61}}
 @end tex
 to
 @ifnottex
-2**29 - 1)
+2**61 - 1)
 @end ifnottex
 @tex
-@math{2^{29}-1})
+@math{2^{61}-1})
 @end tex
-on most machines.  (Some machines may provide a wider range.)  It is
-important to note that the Emacs Lisp arithmetic functions do not check
-for overflow.  Thus @code{(1+ 536870911)} is @minus{}536870912 on most
-machines.
+on most machines.  Some older machines may provide a narrower or wider
+range; all machines provide at least 30 bits.  Emacs Lisp arithmetic
+functions do not check for overflow.  Thus @code{(1+
+2305843009213693951)} is @minus{}2305843009213693952 on most machines.
 
   The read syntax for integers is a sequence of (base ten) digits with an
 optional sign at the beginning and an optional period at the end.  The
@@ -195,7 +195,6 @@
 1                ; @r{The integer 1.}
 1.               ; @r{Also the integer 1.}
 +1               ; @r{Also the integer 1.}
-1073741825       ; @r{Also the integer 1 on a 30-bit implementation.}
 @end group
 @end example
 
@@ -203,8 +202,8 @@
 As a special exception, if a sequence of digits specifies an integer
 too large or too small to be a valid integer object, the Lisp reader
 reads it as a floating-point number (@pxref{Floating Point Type}).
-For instance, on most machines @code{536870912} is read as the
-floating-point number @code{536870912.0}.
+For instance, on most machines @code{2305843009213693952} is read as the
+floating-point number @code{2.305843009213694e+18}.
 
   @xref{Numbers}, for more information.
 

=== modified file 'doc/lispref/os.texi'
--- doc/lispref/os.texi	2011-02-01 07:23:48 +0000
+++ doc/lispref/os.texi	2011-06-03 05:24:22 +0000
@@ -1193,11 +1193,11 @@
 from the functions @code{current-time} (@pxref{Time of Day}) and
 @code{file-attributes} (@pxref{Definition of file-attributes}).
 
-  Many operating systems are limited to time values that contain 32 bits
+  Many 32-bit operating systems are limited to time values that contain 32 bits
 of information; these systems typically handle only the times from
-1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.  However, some
-operating systems have larger time values, and can represent times far
-in the past or future.
+1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.  However, 64-bit
+and some 32-bit operating systems have larger time values, and can
+represent times far in the past or future.
 
   Time conversion functions always use the Gregorian calendar, even
 for dates before the Gregorian calendar was introduced.  Year numbers

=== modified file 'etc/ChangeLog'
--- etc/ChangeLog	2011-05-24 14:22:44 +0000
+++ etc/ChangeLog	2011-06-03 05:24:22 +0000
@@ -1,3 +1,7 @@
+2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* NEWS: 62-bit integers are typical now.
+
 2011-05-24  Leo Liu  <sdl.web@gmail.com>
 
 	* NEWS: Mention the new primitive sha1 and the removal of sha1.el.

=== modified file 'etc/NEWS'
--- etc/NEWS	2011-06-01 15:34:41 +0000
+++ etc/NEWS	2011-06-03 05:24:22 +0000
@@ -902,6 +902,13 @@
 *** New function `special-variable-p' to check whether a variable is
 declared as dynamically bound.
 
+** Emacs integers have a wider range on typical 32-bit hosts.
+Previously, they were limited to a 30-bit range (-2**29 .. 2**29-1).
+Now, they are limited to a 62-bit range (-2**61 .. 2**61-1), the
+same as on 64-bit hosts.  This increased range comes from the Emacs
+interpreter using 64-bit native integer types that are available
+on typical modern 32-bit platforms.
+
 ** pre/post-command-hook are not reset to nil upon error.
 Instead, the offending function is removed.
 

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-02 08:40:41 +0000
+++ src/ChangeLog	2011-06-03 05:24:22 +0000
@@ -1,5 +1,71 @@
 2011-06-02  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Check for overflow when converting integer to cons and back.
+	* charset.c (Fdefine_charset_internal, Fdecode_char):
+	Use cons_to_unsigned to catch overflow.
+	(Fencode_char): Use INTEGER_TO_CONS.
+	* composite.h (LGLYPH_CODE): Use cons_to_unsigned.
+	(LGLYPH_SET_CODE): Use INTEGER_TO_CONS.
+	* data.c (long_to_cons, cons_to_long): Remove.
+	(cons_to_unsigned, cons_to_signed): New functions.  These signal an
+	error for invalid or out-of-range values.
+	* dired.c (Ffile_attributes): Use INTEGER_TO_CONS.
+	(Ffile_attributes): Document inode number handling more accurately.
+	* termhooks.h: Fix comment for inode number handling.
+
+	* fileio.c (Fset_visited_file_modtime): Use CONS_TO_INTEGER.
+	* font.c (Ffont_variation_glyphs):
+	* fontset.c (Finternal_char_font): Use INTEGER_TO_CONS.
+	* lisp.h (INTEGER_TO_CONS, CONS_TO_INTEGER): New macros.
+	(cons_to_signed, cons_to_unsigned): New decls.
+	(long_to_cons, cons_to_long): Remove decls.
+	* undo.c (record_first_change): Use INTEGER_TO_CONS.
+	(Fprimitive_undo): Use CONS_TO_INTEGER.
+	* xfns.c (Fx_window_property): Likewise.
+	* xselect.c (x_own_selection, selection_data_to_lisp_data):
+	Use INTEGER_TO_CONS.
+	(x_handle_selection_request, x_handle_selection_clear)
+	(x_get_foreign_selection, Fx_disown_selection_internal)
+	(Fx_get_atom_name, x_send_client_event): Use CONS_TO_INTEGER.
+	(lisp_data_to_selection_data): Use cons_to_unsigned.
+	(x_fill_property_data): Use cons_to_signed.  Report values out of range.
+
+	* xselect.c (selection_data_to_lisp_data): Use 'unsigned' consistently
+	when computing sizes of unsigned objects.
+	(lisp_data_to_selection_data): Likewise.
+
+	* lisp.h (WIDE_EMACS_INT): Now defaults to 1.
+
+	* fileio.c (Fverify_visited_file_modtime): Avoid time overflow
+	if b->modtime has its maximal value.
+
+	* dired.c (Ffile_attributes): Don't assume EMACS_INT has >32 bits.
+
+	* lisp.h: Include <intprops.h>, as it'll useful in later changes.
+	* character.c, data.c, editfns.c, insdel.c, intervals.c:
+	Don't include <intprops.h>, since lisp.h does.
+
+	Don't assume time_t can fit into int.
+	* buffer.h (struct buffer.modtime): Now time_t, not int.
+	* fileio.c (Fvisited_file_modtime): No need for time_t cast now.
+	* undo.c (Fprimitive_undo): Use time_t, not int, for time_t value.
+
+	Minor fixes for signed vs unsigned integers.
+	* character.h (MAYBE_UNIFY_CHAR):
+	* charset.c (maybe_unify_char):
+	* keyboard.c (read_char, reorder_modifiers):
+	XINT -> XFASTINT, since the integer must be nonnegative.
+	* ftfont.c (ftfont_spec_pattern):
+	* keymap.c (access_keymap, silly_event_symbol_error):
+	XUINT -> XFASTINT, since the integer must be nonnegative.
+	(Fsingle_key_description, preferred_sequence_p): XUINT -> XINT,
+	since it makes no difference and we prefer signed.
+	* keyboard.c (record_char): Use XUINT when all the neighbors do.
+	(access_keymap): NATNUMP -> INTEGERP, since the integer must be
+	nonnegative.
+
+2011-06-02  Paul Eggert  <eggert@cs.ucla.edu>
+
 	Malloc failure behavior now depends on size of allocation.
 	* alloc.c (buffer_memory_full, memory_full): New arg NBYTES.
 	* lisp.h: Change signatures accordingly.

=== modified file 'src/buffer.h'
--- src/buffer.h	2011-05-12 07:07:06 +0000
+++ src/buffer.h	2011-06-02 06:15:15 +0000
@@ -545,7 +545,7 @@
      -1 means visited file was nonexistent.
      0 means visited file modtime unknown; in no case complain
      about any mismatch on next save attempt.  */
-  int modtime;
+  time_t modtime;
   /* Size of the file when modtime was set.  This is used to detect the
      case where the file grew while we were reading it, so the modtime
      is still the same (since it's rounded up to seconds) but we're actually

=== modified file 'src/character.c'
--- src/character.c	2011-05-21 04:33:23 +0000
+++ src/character.c	2011-06-02 06:17:35 +0000
@@ -35,7 +35,7 @@
 
 #include <sys/types.h>
 #include <setjmp.h>
-#include <intprops.h>
+
 #include "lisp.h"
 #include "character.h"
 #include "buffer.h"

=== modified file 'src/character.h'
--- src/character.h	2011-05-21 04:33:23 +0000
+++ src/character.h	2011-06-01 02:49:12 +0000
@@ -544,7 +544,7 @@
 	Lisp_Object val;				\
 	val = CHAR_TABLE_REF (Vchar_unify_table, c);	\
 	if (INTEGERP (val))				\
-	  c = XINT (val);				\
+	  c = XFASTINT (val);				\
 	else if (! NILP (val))				\
 	  c = maybe_unify_char (c, val);		\
       }							\

=== modified file 'src/charset.c'
--- src/charset.c	2011-05-31 06:05:00 +0000
+++ src/charset.c	2011-06-02 18:35:30 +0000
@@ -932,17 +932,8 @@
   val = args[charset_arg_min_code];
   if (! NILP (val))
     {
-      unsigned code;
+      unsigned code = cons_to_unsigned (val, UINT_MAX);
 
-      if (INTEGERP (val))
-	code = XINT (val);
-      else
-	{
-	  CHECK_CONS (val);
-	  CHECK_NUMBER_CAR (val);
-	  CHECK_NUMBER_CDR (val);
-	  code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
-	}
       if (code < charset.min_code
 	  || code > charset.max_code)
 	args_out_of_range_3 (make_number (charset.min_code),
@@ -954,17 +945,8 @@
   val = args[charset_arg_max_code];
   if (! NILP (val))
     {
-      unsigned code;
+      unsigned code = cons_to_unsigned (val, UINT_MAX);
 
-      if (INTEGERP (val))
-	code = XINT (val);
-      else
-	{
-	  CHECK_CONS (val);
-	  CHECK_NUMBER_CAR (val);
-	  CHECK_NUMBER_CDR (val);
-	  code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
-	}
       if (code < charset.min_code
 	  || code > charset.max_code)
 	args_out_of_range_3 (make_number (charset.min_code),
@@ -1637,7 +1619,7 @@
   struct charset *charset;
 
   if (INTEGERP (val))
-    return XINT (val);
+    return XFASTINT (val);
   if (NILP (val))
     return c;
 
@@ -1647,7 +1629,7 @@
     {
       val = CHAR_TABLE_REF (Vchar_unify_table, c);
       if (! NILP (val))
-	c = XINT (val);
+	c = XFASTINT (val);
     }
   else
     {
@@ -1865,17 +1847,7 @@
   struct charset *charsetp;
 
   CHECK_CHARSET_GET_ID (charset, id);
-  if (CONSP (code_point))
-    {
-      CHECK_NATNUM_CAR (code_point);
-      CHECK_NATNUM_CDR (code_point);
-      code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
-    }
-  else
-    {
-      CHECK_NATNUM (code_point);
-      code = XINT (code_point);
-    }
+  code = cons_to_unsigned (code_point, UINT_MAX);
   charsetp = CHARSET_FROM_ID (id);
   c = DECODE_CHAR (charsetp, code);
   return (c >= 0 ? make_number (c) : Qnil);
@@ -1900,9 +1872,7 @@
   code = ENCODE_CHAR (charsetp, XINT (ch));
   if (code == CHARSET_INVALID_CODE (charsetp))
     return Qnil;
-  if (code > 0x7FFFFFF)
-    return Fcons (make_number (code >> 16), make_number (code & 0xFFFF));
-  return make_number (code);
+  return INTEGER_TO_CONS (code);
 }
 
 

=== modified file 'src/composite.h'
--- src/composite.h	2011-05-31 06:05:00 +0000
+++ src/composite.h	2011-06-02 18:54:35 +0000
@@ -265,10 +265,7 @@
 #define LGLYPH_CODE(g)						\
   (NILP (AREF ((g), LGLYPH_IX_CODE))				\
    ? FONT_INVALID_CODE						\
-   : CONSP (AREF ((g), LGLYPH_IX_CODE))				\
-   ? ((XFASTINT (XCAR (AREF ((g), LGLYPH_IX_CODE))) << 16)	\
-      | (XFASTINT (XCDR (AREF ((g), LGLYPH_IX_CODE)))))		\
-   : XFASTINT (AREF ((g), LGLYPH_IX_CODE)))
+   : cons_to_unsigned (AREF (g, LGLYPH_IX_CODE), TYPE_MAXIMUM (unsigned)))
 #define LGLYPH_WIDTH(g) XINT (AREF ((g), LGLYPH_IX_WIDTH))
 #define LGLYPH_LBEARING(g) XINT (AREF ((g), LGLYPH_IX_LBEARING))
 #define LGLYPH_RBEARING(g) XINT (AREF ((g), LGLYPH_IX_RBEARING))
@@ -280,15 +277,8 @@
 #define LGLYPH_SET_CHAR(g, val) ASET ((g), LGLYPH_IX_CHAR, make_number (val))
 /* Callers must assure that VAL is not negative!  */
 #define LGLYPH_SET_CODE(g, val)						\
-  do {									\
-    if (val == FONT_INVALID_CODE)					\
-      ASET ((g), LGLYPH_IX_CODE, Qnil);					\
-    else if ((EMACS_INT)val > MOST_POSITIVE_FIXNUM)			\
-      ASET ((g), LGLYPH_IX_CODE, Fcons (make_number ((val) >> 16),	\
-					make_number ((val) & 0xFFFF)));	\
-    else								\
-      ASET ((g), LGLYPH_IX_CODE, make_number (val));			\
-  } while (0)
+  ASET (g, LGLYPH_IX_CODE,						\
+	val == FONT_INVALID_CODE ? Qnil : INTEGER_TO_CONS (val))
 
 #define LGLYPH_SET_WIDTH(g, val) ASET ((g), LGLYPH_IX_WIDTH, make_number (val))
 #define LGLYPH_SET_LBEARING(g, val) ASET ((g), LGLYPH_IX_LBEARING, make_number (val))

=== modified file 'src/data.c'
--- src/data.c	2011-05-31 14:57:53 +0000
+++ src/data.c	2011-06-02 07:38:44 +0000
@@ -23,8 +23,6 @@
 #include <stdio.h>
 #include <setjmp.h>
 
-#include <intprops.h>
-
 #include "lisp.h"
 #include "puresize.h"
 #include "character.h"
@@ -2326,33 +2324,89 @@
   return Qnil;
 }
 \f
-/* Convert between long values and pairs of Lisp integers.
-   Note that long_to_cons returns a single Lisp integer
-   when the value fits in one.  */
+/* Convert the cons-of-integers, integer, or float value C to an
+   unsigned value with maximum value MAX.  Signal an error if C does not
+   have a valid format or is out of range.  */
+uintmax_t
+cons_to_unsigned (Lisp_Object c, uintmax_t max)
+{
+  int valid = 0;
+  uintmax_t val IF_LINT (= 0);
+  if (INTEGERP (c))
+    {
+      valid = 0 <= XINT (c);
+      val = XINT (c);
+    }
+  else if (FLOATP (c))
+    {
+      double d = XFLOAT_DATA (c);
+      if (0 <= d
+	  && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
+	{
+	  val = d;
+	  valid = 1;
+	}
+    }
+  else if (CONSP (c))
+    {
+      Lisp_Object top = XCAR (c);
+      Lisp_Object bot = XCDR (c);
+      if (CONSP (bot))
+	bot = XCAR (bot);
+      if (NATNUMP (top) && XFASTINT (top) <= UINTMAX_MAX >> 16 && NATNUMP (bot))
+	{
+	  uintmax_t utop = XFASTINT (top);
+	  val = (utop << 16) | XFASTINT (bot);
+	  valid = 1;
+	}
+    }
 
-Lisp_Object
-long_to_cons (long unsigned int i)
-{
-  unsigned long top = i >> 16;
-  unsigned int bot = i & 0xFFFF;
-  if (top == 0)
-    return make_number (bot);
-  if (top == (unsigned long)-1 >> 16)
-    return Fcons (make_number (-1), make_number (bot));
-  return Fcons (make_number (top), make_number (bot));
+  if (! (valid && val <= max))
+    error ("Not an in-range integer, float, or cons of integers");
+  return val;
 }
 
-unsigned long
-cons_to_long (Lisp_Object c)
+/* Convert the cons-of-integers, integer, or float value C to a signed
+   value with extrema MIN and MAX.  Signal an error if C does not have
+   a valid format or is out of range.  */
+intmax_t
+cons_to_signed (Lisp_Object c, intmax_t min, intmax_t max)
 {
-  Lisp_Object top, bot;
+  int valid = 0;
+  intmax_t val IF_LINT (= 0);
   if (INTEGERP (c))
-    return XINT (c);
-  top = XCAR (c);
-  bot = XCDR (c);
-  if (CONSP (bot))
-    bot = XCAR (bot);
-  return ((XINT (top) << 16) | XINT (bot));
+    {
+      val = XINT (c);
+      valid = 1;
+    }
+  else if (FLOATP (c))
+    {
+      double d = XFLOAT_DATA (c);
+      if (min <= d
+	  && d < (max == INTMAX_MAX ? (double) INTMAX_MAX + 1 : max + 1))
+	{
+	  val = d;
+	  valid = 1;
+	}
+    }
+  else if (CONSP (c))
+    {
+      Lisp_Object top = XCAR (c);
+      Lisp_Object bot = XCDR (c);
+      if (CONSP (bot))
+	bot = XCAR (bot);
+      if (INTEGERP (top) && INTMAX_MIN >> 16 <= XINT (top)
+	  && XINT (top) <= INTMAX_MAX >> 16 && INTEGERP (bot))
+	{
+	  intmax_t itop = XINT (top);
+	  val = (itop << 16) | XINT (bot);
+	  valid = 1;
+	}
+    }
+
+  if (! (valid && min <= val && val <= max))
+    error ("Not an in-range integer, float, or cons of integers");
+  return val;
 }
 \f
 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,

=== modified file 'src/dired.c'
--- src/dired.c	2011-04-14 19:34:42 +0000
+++ src/dired.c	2011-06-03 05:24:22 +0000
@@ -901,10 +901,10 @@
  8. File modes, as a string of ten letters or dashes as in ls -l.
  9. t if file's gid would change if file were deleted and recreated.
 10. inode number.  If inode number is larger than what Emacs integer
-  can hold, but still fits into a 32-bit number, this is a cons cell
+  can hold, but all but the bottom 16 bits still fits, this is a cons cell
   containing two integers: first the high part, then the low 16 bits.
-  If the inode number is wider than 32 bits, this is of the form
-  (HIGH MIDDLE . LOW): first the high 24 bits, then middle 24 bits,
+  If the inode number is still wider, this is of the form
+  (HIGH MIDDLE . LOW): first the high bits, then the middle 24 bits,
   and finally the low 16 bits.
 11. Filesystem device number.  If it is larger than what the Emacs
   integer can hold, this is a cons cell, similar to the inode number.
@@ -998,35 +998,24 @@
 #else					/* file gid will be egid */
   values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
 #endif	/* not BSD4_2 */
-  if (!FIXNUM_OVERFLOW_P (s.st_ino))
-    /* Keep the most common cases as integers.  */
-    values[10] = make_number (s.st_ino);
-  else if (!FIXNUM_OVERFLOW_P (s.st_ino >> 16))
-    /* To allow inode numbers larger than VALBITS, separate the bottom
-       16 bits.  */
-    values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)),
-			make_number ((EMACS_INT)(s.st_ino & 0xffff)));
+  if (! FIXNUM_OVERFLOW_P ((s.st_ino) >> 16))
+    values[10] = INTEGER_TO_CONS (s.st_ino);
   else
     {
-      /* To allow inode numbers beyond 32 bits, separate into 2 24-bit
-	 high parts and a 16-bit bottom part.
+      /* To allow inode numbers beyond what INTEGER_TO_CONS can handle,
+	 separate into 2 24-bit high parts and a 16-bit bottom part.
 	 The code on the next line avoids a compiler warning on
 	 systems where st_ino is 32 bit wide. (bug#766).  */
       EMACS_INT high_ino = s.st_ino >> 31 >> 1;
-      EMACS_INT low_ino  = s.st_ino & 0xffffffff;
 
       values[10] = Fcons (make_number (high_ino >> 8),
 			  Fcons (make_number (((high_ino & 0xff) << 16)
-					      + (low_ino >> 16)),
-				 make_number (low_ino & 0xffff)));
+					      + (s.st_ino >> 16 & 0xffff)),
+				 make_number (s.st_ino & 0xffff)));
     }
 
   /* Likewise for device.  */
-  if (FIXNUM_OVERFLOW_P (s.st_dev))
-    values[11] = Fcons (make_number (s.st_dev >> 16),
-			make_number (s.st_dev & 0xffff));
-  else
-    values[11] = make_number (s.st_dev);
+  values[11] = INTEGER_TO_CONS (s.st_dev);
 
   return Flist (sizeof(values) / sizeof(values[0]), values);
 }

=== modified file 'src/editfns.c'
--- src/editfns.c	2011-05-30 16:47:35 +0000
+++ src/editfns.c	2011-06-02 18:35:30 +0000
@@ -47,7 +47,6 @@
 #include <ctype.h>
 #include <float.h>
 #include <limits.h>
-#include <intprops.h>
 #include <strftime.h>
 #include <verify.h>
 

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-04-29 19:47:29 +0000
+++ src/fileio.c	2011-06-02 07:38:44 +0000
@@ -4960,7 +4960,7 @@
   if ((st.st_mtime == b->modtime
        /* If both are positive, accept them if they are off by one second.  */
        || (st.st_mtime > 0 && b->modtime > 0
-	   && (st.st_mtime == b->modtime + 1
+	   && (st.st_mtime - 1 == b->modtime
 	       || st.st_mtime == b->modtime - 1)))
       && (st.st_size == b->modtime_size
           || b->modtime_size < 0))
@@ -4990,7 +4990,7 @@
 {
   if (! current_buffer->modtime)
     return make_number (0);
-  return make_time ((time_t) current_buffer->modtime);
+  return make_time (current_buffer->modtime);
 }
 
 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime,
@@ -5005,7 +5005,7 @@
 {
   if (!NILP (time_list))
     {
-      current_buffer->modtime = cons_to_long (time_list);
+      CONS_TO_INTEGER (time_list, time_t, current_buffer->modtime);
       current_buffer->modtime_size = -1;
     }
   else

=== modified file 'src/font.c'
--- src/font.c	2011-05-29 19:04:01 +0000
+++ src/font.c	2011-06-02 07:38:44 +0000
@@ -4388,16 +4388,8 @@
   for (i = 0; i < 255; i++)
     if (variations[i])
       {
-	Lisp_Object code;
 	int vs = (i < 16 ? 0xFE00 + i : 0xE0100 + (i - 16));
-	/* Stops GCC whining about limited range of data type.	*/
-	EMACS_INT var = variations[i];
-
-	if (var > MOST_POSITIVE_FIXNUM)
-	  code = Fcons (make_number ((variations[i]) >> 16),
-			make_number ((variations[i]) & 0xFFFF));
-	else
-	  code = make_number (variations[i]);
+	Lisp_Object code = INTEGER_TO_CONS (variations[i]);
 	val = Fcons (Fcons (make_number (vs), code), val);
       }
   return val;

=== modified file 'src/fontset.c'
--- src/fontset.c	2011-05-28 22:39:39 +0000
+++ src/fontset.c	2011-06-02 07:38:44 +0000
@@ -1859,17 +1859,11 @@
     {
       unsigned code = face->font->driver->encode_char (face->font, c);
       Lisp_Object font_object;
-      /* Assignment to EMACS_INT stops GCC whining about limited range
-	 of data type.  */
-      EMACS_INT cod = code;
 
       if (code == FONT_INVALID_CODE)
 	return Qnil;
       XSETFONT (font_object, face->font);
-      if (cod <= MOST_POSITIVE_FIXNUM)
-	return Fcons (font_object, make_number (code));
-      return Fcons (font_object, Fcons (make_number (code >> 16),
-				     make_number (code & 0xFFFF)));
+      return Fcons (font_object, INTEGER_TO_CONS (code));
     }
   return Qnil;
 }

=== modified file 'src/ftfont.c'
--- src/ftfont.c	2011-04-11 03:39:45 +0000
+++ src/ftfont.c	2011-06-01 02:49:12 +0000
@@ -815,7 +815,7 @@
 	    goto err;
 	  for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars))
 	    if (CHARACTERP (XCAR (chars))
-		&& ! FcCharSetAddChar (charset, XUINT (XCAR (chars))))
+		&& ! FcCharSetAddChar (charset, XFASTINT (XCAR (chars))))
 	      goto err;
 	}
     }

=== modified file 'src/insdel.c'
--- src/insdel.c	2011-05-21 04:33:23 +0000
+++ src/insdel.c	2011-06-02 06:17:35 +0000
@@ -21,8 +21,6 @@
 #include <config.h>
 #include <setjmp.h>
 
-#include <intprops.h>
-
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"

=== modified file 'src/intervals.c'
--- src/intervals.c	2011-05-28 22:39:39 +0000
+++ src/intervals.c	2011-06-02 06:17:35 +0000
@@ -39,7 +39,7 @@
 
 #include <config.h>
 #include <setjmp.h>
-#include <intprops.h>
+
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2011-05-28 22:39:39 +0000
+++ src/keyboard.c	2011-06-01 02:49:12 +0000
@@ -2395,8 +2395,8 @@
 
       c = Faref (Vexecuting_kbd_macro, make_number (executing_kbd_macro_index));
       if (STRINGP (Vexecuting_kbd_macro)
-	  && (XINT (c) & 0x80) && (XUINT (c) <= 0xff))
-	XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80));
+	  && (XFASTINT (c) & 0x80) && (XFASTINT (c) <= 0xff))
+	XSETFASTINT (c, CHAR_META | (XFASTINT (c) & ~0x80));
 
       executing_kbd_macro_index++;
 
@@ -3321,7 +3321,7 @@
       if (INTEGERP (c))
 	{
 	  if (XUINT (c) < 0x100)
-	    putc (XINT (c), dribble);
+	    putc (XUINT (c), dribble);
 	  else
 	    fprintf (dribble, " 0x%"pI"x", XUINT (c));
 	}
@@ -6370,7 +6370,7 @@
   Lisp_Object parsed;
 
   parsed = parse_modifiers (symbol);
-  return apply_modifiers ((int) XINT (XCAR (XCDR (parsed))),
+  return apply_modifiers (XFASTINT (XCAR (XCDR (parsed))),
 			  XCAR (parsed));
 }
 

=== modified file 'src/keymap.c'
--- src/keymap.c	2011-05-12 07:07:06 +0000
+++ src/keymap.c	2011-06-01 02:49:12 +0000
@@ -462,7 +462,7 @@
     XSETFASTINT (idx, XINT (idx) & (CHAR_META | (CHAR_META - 1)));
 
   /* Handle the special meta -> esc mapping. */
-  if (INTEGERP (idx) && XUINT (idx) & meta_modifier)
+  if (INTEGERP (idx) && XFASTINT (idx) & meta_modifier)
     {
       /* See if there is a meta-map.  If there's none, there is
          no binding for IDX, unless a default binding exists in MAP.  */
@@ -480,7 +480,7 @@
       if (CONSP (event_meta_map))
 	{
 	  map = event_meta_map;
-	  idx = make_number (XUINT (idx) & ~meta_modifier);
+	  idx = make_number (XFASTINT (idx) & ~meta_modifier);
 	}
       else if (t_ok)
 	/* Set IDX to t, so that we only find a default binding.  */
@@ -529,7 +529,7 @@
 	  }
 	else if (VECTORP (binding))
 	  {
-	    if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (binding))
+	    if (INTEGERP (idx) && XFASTINT (idx) < ASIZE (binding))
 	      val = AREF (binding, XFASTINT (idx));
 	  }
 	else if (CHAR_TABLE_P (binding))
@@ -537,7 +537,7 @@
 	    /* Character codes with modifiers
 	       are not included in a char-table.
 	       All character codes without modifiers are included.  */
-	    if (NATNUMP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0)
+	    if (INTEGERP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0)
 	      {
 		val = Faref (binding, idx);
 		/* `nil' has a special meaning for char-tables, so
@@ -1357,7 +1357,7 @@
   int modifiers;
 
   parsed = parse_modifiers (c);
-  modifiers = (int) XUINT (XCAR (XCDR (parsed)));
+  modifiers = XFASTINT (XCAR (XCDR (parsed)));
   base = XCAR (parsed);
   name = Fsymbol_name (base);
   /* This alist includes elements such as ("RET" . "\\r").  */
@@ -2416,7 +2416,7 @@
     {
       char tem[KEY_DESCRIPTION_SIZE];
 
-      *push_key_description (XUINT (key), tem, 1) = 0;
+      *push_key_description (XINT (key), tem, 1) = 0;
       return build_string (tem);
     }
   else if (SYMBOLP (key))	/* Function key or event-symbol */
@@ -2515,7 +2515,7 @@
 	return 0;
       else
 	{
-	  int modifiers = XUINT (elt) & (CHAR_MODIFIER_MASK & ~CHAR_META);
+	  int modifiers = XINT (elt) & (CHAR_MODIFIER_MASK & ~CHAR_META);
 	  if (modifiers == where_is_preferred_modifier)
 	    result = 2;
 	  else if (modifiers)

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-02 08:25:28 +0000
+++ src/lisp.h	2011-06-02 18:35:30 +0000
@@ -24,6 +24,8 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+#include <intprops.h>
+
 /* Use the configure flag --enable-checking[=LIST] to enable various
    types of run time checks for Lisp objects.  */
 
@@ -34,13 +36,14 @@
 #define CHECK_CONS_LIST() ((void) 0)
 #endif
 
-/* Temporarily disable wider-than-pointer integers until they're tested more.
-   Build with CFLAGS='-DWIDE_EMACS_INT' to try them out.  */
-/* #undef WIDE_EMACS_INT */
+/* To disable wider-than-pointer integers, build with -DWIDE_EMACS_INT=0.  */
+#ifndef WIDE_EMACS_INT
+#define WIDE_EMACS_INT 1
+#endif
 
 /* These are default choices for the types to use.  */
 #ifndef EMACS_INT
-# if BITS_PER_LONG < BITS_PER_LONG_LONG && defined WIDE_EMACS_INT
+# if BITS_PER_LONG < BITS_PER_LONG_LONG && WIDE_EMACS_INT
 #  define EMACS_INT long long
 #  define BITS_PER_EMACS_INT BITS_PER_LONG_LONG
 #  define pI "ll"
@@ -2402,9 +2405,33 @@
 EXFUN (Fsub1, 1);
 EXFUN (Fmake_variable_buffer_local, 1);
 
+/* Convert the integer I to an Emacs representation, either the integer
+   itself, or a cons of two integers, or if all else fails a float.
+   The float might lose information; this happens only in extreme cases
+   such as 32-bit EMACS_INT and 64-bit time_t with outlandish time values,
+   and these aren't worth complicating the interface.
+
+   I should not have side effects.  */
+#define INTEGER_TO_CONS(i)					    \
+  (! FIXNUM_OVERFLOW_P (i)					    \
+   ? make_number (i)						    \
+   : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16)			    \
+	 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16))		    \
+	&& FIXNUM_OVERFLOW_P ((i) >> 16))			    \
+   ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff))    \
+   : make_float (i))
+
+/* Convert the Emacs representation CONS back to an integer of type
+   TYPE, storing the result the variable VAR.  Signal an error if CONS
+   is not a valid representation or is out of range for TYPE.  */
+#define CONS_TO_INTEGER(cons, type, var)				\
+  (TYPE_SIGNED (type)							\
+   ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
+   : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
+extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
+extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
+
 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
-extern Lisp_Object long_to_cons (unsigned long);
-extern unsigned long cons_to_long (Lisp_Object);
 extern void args_out_of_range (Lisp_Object, Lisp_Object) NO_RETURN;
 extern void args_out_of_range_3 (Lisp_Object, Lisp_Object,
                                  Lisp_Object) NO_RETURN;

=== modified file 'src/termhooks.h'
--- src/termhooks.h	2011-05-27 16:17:59 +0000
+++ src/termhooks.h	2011-06-03 05:24:22 +0000
@@ -342,8 +342,8 @@
      SELECTION-VALUE is the value that emacs owns for that selection.
       It may be any kind of Lisp object.
      SELECTION-TIMESTAMP is the time at which emacs began owning this
-      selection, as a cons of two 16-bit numbers (making a 32 bit
-      time.)
+      selection, as an Emacs integer; or if that doesn't fit, as a
+      cons of two 16-bit integers (making a 32 bit time.)
      FRAME is the frame for which we made the selection.  If there is
       an entry in this alist, then it can be assumed that Emacs owns
       that selection.

=== modified file 'src/undo.c'
--- src/undo.c	2011-04-14 05:04:02 +0000
+++ src/undo.c	2011-06-02 07:38:44 +0000
@@ -212,7 +212,6 @@
 void
 record_first_change (void)
 {
-  Lisp_Object high, low;
   struct buffer *base_buffer = current_buffer;
 
   if (EQ (BVAR (current_buffer, undo_list), Qt))
@@ -225,9 +224,9 @@
   if (base_buffer->base_buffer)
     base_buffer = base_buffer->base_buffer;
 
-  XSETFASTINT (high, (base_buffer->modtime >> 16) & 0xffff);
-  XSETFASTINT (low, base_buffer->modtime & 0xffff);
-  BVAR (current_buffer, undo_list) = Fcons (Fcons (Qt, Fcons (high, low)), BVAR (current_buffer, undo_list));
+  BVAR (current_buffer, undo_list) =
+    Fcons (Fcons (Qt, INTEGER_TO_CONS (base_buffer->modtime)),
+	   BVAR (current_buffer, undo_list));
 }
 
 /* Record a change in property PROP (whose old value was VAL)
@@ -499,13 +498,9 @@
 	      if (EQ (car, Qt))
 		{
 		  /* Element (t high . low) records previous modtime.  */
-		  Lisp_Object high, low;
-		  int mod_time;
 		  struct buffer *base_buffer = current_buffer;
-
-		  high = Fcar (cdr);
-		  low = Fcdr (cdr);
-		  mod_time = (XFASTINT (high) << 16) + XFASTINT (low);
+		  time_t mod_time;
+		  CONS_TO_INTEGER (cdr, time_t, mod_time);
 
 		  if (current_buffer->base_buffer)
 		    base_buffer = current_buffer->base_buffer;

=== modified file 'src/xfns.c'
--- src/xfns.c	2011-04-19 06:34:43 +0000
+++ src/xfns.c	2011-06-02 07:38:44 +0000
@@ -4295,18 +4295,9 @@
 
   if (! NILP (source))
     {
-      if (NUMBERP (source))
-        {
-          if (FLOATP (source))
-            target_window = (Window) XFLOAT (source);
-          else
-            target_window = XFASTINT (source);
-
-          if (target_window == 0)
-            target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
-        }
-      else if (CONSP (source))
-        target_window = cons_to_long (source);
+      CONS_TO_INTEGER (source, Window, target_window);
+      if (! target_window)
+	target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
     }
 
   BLOCK_INPUT;

=== modified file 'src/xselect.c'
--- src/xselect.c	2011-05-29 05:23:24 +0000
+++ src/xselect.c	2011-06-02 07:38:44 +0000
@@ -335,7 +335,7 @@
     Lisp_Object prev_value;
 
     selection_data = list4 (selection_name, selection_value,
-			    long_to_cons (timestamp), frame);
+			    INTEGER_TO_CONS (timestamp), frame);
     prev_value = LOCAL_SELECTION (selection_name, dpyinfo);
 
     dpyinfo->terminal->Vselection_alist
@@ -419,7 +419,7 @@
       || INTEGERP (check)
       || NILP (value))
     return value;
-  /* Check for a value that cons_to_long could handle.  */
+  /* Check for a value that CONS_TO_INTEGER could handle.  */
   else if (CONSP (check)
 	   && INTEGERP (XCAR (check))
 	   && (INTEGERP (XCDR (check))
@@ -782,8 +782,8 @@
   if (NILP (local_selection_data)) goto DONE;
 
   /* Decline requests issued prior to our acquiring the selection.  */
-  local_selection_time
-    = (Time) cons_to_long (XCAR (XCDR (XCDR (local_selection_data))));
+  CONS_TO_INTEGER (XCAR (XCDR (XCDR (local_selection_data))),
+		   Time, local_selection_time);
   if (SELECTION_EVENT_TIME (event) != CurrentTime
       && local_selection_time > SELECTION_EVENT_TIME (event))
     goto DONE;
@@ -950,8 +950,8 @@
   /* Well, we already believe that we don't own it, so that's just fine.  */
   if (NILP (local_selection_data)) return;
 
-  local_selection_time = (Time)
-    cons_to_long (XCAR (XCDR (XCDR (local_selection_data))));
+  CONS_TO_INTEGER (XCAR (XCDR (XCDR (local_selection_data))),
+		   Time, local_selection_time);
 
   /* We have reasserted the selection since this SelectionClear was
      generated, so we can disregard it.  */
@@ -1213,16 +1213,7 @@
     return Qnil;
 
   if (! NILP (time_stamp))
-    {
-      if (CONSP (time_stamp))
-        requestor_time = (Time) cons_to_long (time_stamp);
-      else if (INTEGERP (time_stamp))
-        requestor_time = (Time) XUINT (time_stamp);
-      else if (FLOATP (time_stamp))
-        requestor_time = (Time) XFLOAT_DATA (time_stamp);
-      else
-        error ("TIME_STAMP must be cons or number");
-    }
+    CONS_TO_INTEGER (time_stamp, Time, requestor_time);
 
   BLOCK_INPUT;
 
@@ -1651,9 +1642,9 @@
      If the number is 32 bits and won't fit in a Lisp_Int,
      convert it to a cons of integers, 16 bits in each half.
    */
-  else if (format == 32 && size == sizeof (int))
-    return long_to_cons (((unsigned int *) data) [0]);
-  else if (format == 16 && size == sizeof (short))
+  else if (format == 32 && size == sizeof (unsigned int))
+    return INTEGER_TO_CONS (((unsigned int *) data) [0]);
+  else if (format == 16 && size == sizeof (unsigned short))
     return make_number ((int) (((unsigned short *) data) [0]));
 
   /* Convert any other kind of data to a vector of numbers, represented
@@ -1678,7 +1669,7 @@
       for (i = 0; i < size / 4; i++)
 	{
 	  unsigned int j = ((unsigned int *) data) [i];
-	  Faset (v, make_number (i), long_to_cons (j));
+	  Faset (v, make_number (i), INTEGER_TO_CONS (j));
 	}
       return v;
     }
@@ -1753,9 +1744,9 @@
     {
       *format_ret = 32;
       *size_ret = 1;
-      *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
-      (*data_ret) [sizeof (long)] = 0;
-      (*(unsigned long **) data_ret) [0] = cons_to_long (obj);
+      *data_ret = (unsigned char *) xmalloc (sizeof (unsigned long) + 1);
+      (*data_ret) [sizeof (unsigned long)] = 0;
+      (*(unsigned long **) data_ret) [0] = cons_to_unsigned (obj, ULONG_MAX);
       if (NILP (type)) type = QINTEGER;
     }
   else if (VECTORP (obj))
@@ -1803,11 +1794,11 @@
 	  *data_ret = (unsigned char *) xmalloc (*size_ret * data_size);
 	  for (i = 0; i < *size_ret; i++)
 	    if (*format_ret == 32)
-	      (*((unsigned long **) data_ret)) [i]
-		= cons_to_long (XVECTOR (obj)->contents [i]);
+	      (*((unsigned long **) data_ret)) [i] =
+		cons_to_unsigned (XVECTOR (obj)->contents [i], ULONG_MAX);
 	    else
-	      (*((unsigned short **) data_ret)) [i]
-		= (unsigned short) cons_to_long (XVECTOR (obj)->contents [i]);
+	      (*((unsigned short **) data_ret)) [i] =
+		cons_to_unsigned (XVECTOR (obj)->contents [i], USHRT_MAX);
 	}
     }
   else
@@ -2025,8 +2016,10 @@
   selection_atom = symbol_to_x_atom (dpyinfo, selection);
 
   BLOCK_INPUT;
-  timestamp = (NILP (time_object) ? last_event_timestamp
-	       : cons_to_long (time_object));
+  if (NILP (time_object))
+    timestamp = last_event_timestamp;
+  else
+    CONS_TO_INTEGER (time_object, Time, timestamp);
   XSetSelectionOwner (dpyinfo->display, selection_atom, None, timestamp);
   UNBLOCK_INPUT;
 
@@ -2232,12 +2225,8 @@
     {
       Lisp_Object o = XCAR (iter);
 
-      if (INTEGERP (o))
-        val = (long) XFASTINT (o);
-      else if (FLOATP (o))
-        val = (long) XFLOAT_DATA (o);
-      else if (CONSP (o))
-        val = (long) cons_to_long (o);
+      if (INTEGERP (o) || FLOATP (o) || CONSP (o))
+	val = cons_to_signed (o, LONG_MIN, LONG_MAX);
       else if (STRINGP (o))
         {
           BLOCK_INPUT;
@@ -2248,9 +2237,19 @@
         error ("Wrong type, must be string, number or cons");
 
       if (format == 8)
-        *d08++ = (char) val;
+	{
+	  if (CHAR_MIN <= val && val <= CHAR_MAX)
+	    *d08++ = val;
+	  else
+	    error ("Out of 'char' range");
+	}
       else if (format == 16)
-        *d16++ = (short) val;
+	{
+	  if (SHRT_MIN <= val && val <= SHRT_MAX)
+	    *d16++ = val;
+	  else
+	    error ("Out of 'short' range");
+	}
       else
         *d32++ = val;
     }
@@ -2334,14 +2333,7 @@
   Atom atom;
   int had_errors;
 
-  if (INTEGERP (value))
-    atom = (Atom) XUINT (value);
-  else if (FLOATP (value))
-    atom = (Atom) XFLOAT_DATA (value);
-  else if (CONSP (value))
-    atom = (Atom) cons_to_long (value);
-  else
-    error ("Wrong type, value must be number or cons");
+  CONS_TO_INTEGER (value, Atom, atom);
 
   BLOCK_INPUT;
   x_catch_errors (dpy);
@@ -2531,17 +2523,8 @@
       else
         error ("DEST as a string must be one of PointerWindow or InputFocus");
     }
-  else if (INTEGERP (dest))
-    wdest = (Window) XFASTINT (dest);
-  else if (FLOATP (dest))
-    wdest =  (Window) XFLOAT_DATA (dest);
-  else if (CONSP (dest))
-    {
-      if (! NUMBERP (XCAR (dest)) || ! NUMBERP (XCDR (dest)))
-        error ("Both car and cdr for DEST must be numbers");
-      else
-        wdest = (Window) cons_to_long (dest);
-    }
+  else if (INTEGERP (dest) || FLOATP (dest) || CONSP (dest))
+    CONS_TO_INTEGER (dest, Window, wdest);
   else
     error ("DEST must be a frame, nil, string, number or cons");
 

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWUXr/vgAQi1fgH8y+f/////v
//+/////YEve8PDpvoybBuuvdxbivPXy3Yct309aq99d609O7t275Z9xnUzPPOld77u7eu1zK7tc
9XrXyO3D5fee3xk9u4oXDzzz21FsvO47YAOGwDdncPs4Ae8dlwDcYAEgH07j3AUvU+UEF9m6bSuu
bV92er4X2XvN614DHdwfbvPrtvhxRr533NO3feK+rG1Xbu0Pvg3JHo0otj6AFAd9j0pXQ28uacqa
b1L7vcam89e89Gt9ht3A07a6EkQQEZMg0aIaGpggnoRqnqMn6UaND0jQD1DQ0NNAlBAAIhE0jRGI
hmgp6h6EA0AANAAAGEpoEEgg0JoQymo2o9QeoekHqaaDQAA00Gg9QNAk0oiaApkTEwmyqPxqnhU3
hUPU0ep5I0AGTRoaDTQ0NBEogIATITAAJqYmaATISbQn6phqNqDJoyAaCRIEATRqZNTJqaemp6Kn
6bSp+qNDINPUPUD0nqeobUAAA2GH4uc5RONR5FeixC6JIIVi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mD8INm1b3DrDMHgfUQoVNpFOX3DJpgxkiPkSkg71rhoOSCEes2vO
987cRUAc3H5h0OMUOAw+il8bPIEFYg7KPvEGcOHXAmLxgeI+NFNiIJikU6x+mG+kNEA9EGhOEp6x
7RPB9KIpndz4FCUjISBlHOIntaWAfAsA7RKhZyxUHQXEPh5hX6zB2Ps92ImwzHnIlSEJCBRGAEB4
zkRryNi8+IhzKFr6tOfrYYd3mpfZM+er1cFEzQDfHIawqHzeQTKGhEUubfLz8mJwO8iKdonkOR2u
d0F0OchRYejf7/X7RM7lNyPUdxCG4gQyiUD4hicMX1LlztCs+H2NrjSJLppS6dCrYCCk9fnoRtTM
52OZFAwzAhdyGec0LqegWstt6yoXHWUboLCQgvi72ne5i8wcGpmPc5i1c70O3dNBodekuhtvwR9o
w2GIt5JB8jE6EH5kL0BBTWdwFwyOo3avJCJ7O1C2J4iDmb3dFYYA6K0IB3Gt8A4sM4tUdghodsDf
8POPiPo7ArWA4gHHD/gIDjAbuSS5Adn70MlWQ5c/26TS/Pfu1NyVPruNgYGUQRNgu5x9gdGQ8A/+
L8P0Q+RsqHg521AOYL/8XckU4UJBF6/74A==





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03  8:43 bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default Paul Eggert
@ 2011-06-03 10:52 ` Eli Zaretskii
  2011-06-03 17:53   ` Paul Eggert
  2011-06-03 15:54 ` Stefan Monnier
  1 sibling, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2011-06-03 10:52 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

> Date: Fri, 03 Jun 2011 01:43:36 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> 
> I found several problems in the Emacs code that converts
> large C integers to Emacs conses-of-integers and back again.
> I wrote some code to fix them systematically, and found that
> it was simpler and more reliable if I could assume that EMACS_INT
> was 64-bit even on 32-bit hosts.  So here's a patch to do all that.

I don't think we agreed to make that the only configurations on 32-bit
machines.  Did we?

> +using that data type.  For most machines, the maximum buffer size
> +enforced by the data types is @math{2^61 - 2} bytes, or about 2 EiB.
> +For some older machines, the maximum is @math{2^29 - 2} bytes, or
> +about 512 MiB.  Buffer sizes are also limited by the size of Emacs's
> +virtual memory.

Can 32-bit hosts really support buffers and strings larger than 2GB,
even if EMACS_INT is a 64-bit type?  I thought the largest object on a
32-but machine cannot exceed 2GB due to pointer arithmetics, which
will wrap around after that.  What am I missing?

>  Emacs cannot visit files that are larger than the maximum Emacs buffer
> -size, which is around 512 megabytes on 32-bit machines
> +size, which is around 512 MiB on 32-bit machines and 2 EiB on 64-bit machines
>  (@pxref{Buffers}).  If you try, Emacs will display an error message
>  saying that the maximum buffer size has been exceeded.

This seems to contradict what you said about buffers, doesn't it?

> === modified file 'src/data.c'
> --- src/data.c	2011-05-31 14:57:53 +0000
> +++ src/data.c	2011-06-02 07:38:44 +0000
> @@ -23,8 +23,6 @@
> [...]
> +  else if (FLOATP (c))
> +    {
> +      double d = XFLOAT_DATA (c);
> +      if (0 <= d
> +	  && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
> +	{
> +	  val = d;
> +	  valid = 1;
> +	}
> +    }
> +  else if (CONSP (c))
> +    {
> +      Lisp_Object top = XCAR (c);
> +      Lisp_Object bot = XCDR (c);
> +      if (CONSP (bot))
> +	bot = XCAR (bot);
> +      if (NATNUMP (top) && XFASTINT (top) <= UINTMAX_MAX >> 16 && NATNUMP (bot))
> +	{
> +	  uintmax_t utop = XFASTINT (top);
> +	  val = (utop << 16) | XFASTINT (bot);
> +	  valid = 1;
> +	}
> +    }

The *_MAX macros need limits.h, but I don't see it being included by
data.c.  Did I miss something?

> +#define INTEGER_TO_CONS(i)					    \
> +  (! FIXNUM_OVERFLOW_P (i)					    \
> +   ? make_number (i)						    \
> +   : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16)			    \
> +	 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16))		    \
> +	&& FIXNUM_OVERFLOW_P ((i) >> 16))			    \
> +   ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff))    \
> +   : make_float (i))

Same here (this is from lisp.h).  But since every C file includes
lisp.h, it looks like we need to include limits.h in lisp.h.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03  8:43 bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default Paul Eggert
  2011-06-03 10:52 ` Eli Zaretskii
@ 2011-06-03 15:54 ` Stefan Monnier
  2011-06-03 19:28   ` Paul Eggert
                     ` (3 more replies)
  1 sibling, 4 replies; 21+ messages in thread
From: Stefan Monnier @ 2011-06-03 15:54 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

> I found several problems in the Emacs code that converts
> large C integers to Emacs conses-of-integers and back again.
> I wrote some code to fix them systematically, and found that
> it was simpler and more reliable if I could assume that EMACS_INT
> was 64-bit even on 32-bit hosts.  So here's a patch to do all that.
> I plan to test this a bit more before committing.

So, there are 3 parts:
- fix the cons<->int conversions.
- add a 64bit-on-32bit compilation option.
- make that option the default.
Please split it into those three parts.  I'd rather keep the "change the
default" for later, after we've gotten some experience with it.


        Stefan





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03 10:52 ` Eli Zaretskii
@ 2011-06-03 17:53   ` Paul Eggert
  2011-06-03 19:43     ` Eli Zaretskii
  0 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-03 17:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 8794

>> I wrote some code to fix them systematically, and found that
>> it was simpler and more reliable if I could assume that EMACS_INT
>> was 64-bit even on 32-bit hosts.
> 
> I don't think we agreed to make that the only configurations on 32-bit
> machines.

Sorry, I should have explained more clearly.  If there is a system
integer type (such as ino_t or time_t) that is 64 bits, it's cleaner
if EMACS_INT is also 64 bits.  And in practice this requirement is not
a problem, as any 32-bit host where some standard system types are 64 bits
supports 64-bit integers quite well.  On an old-fashioned host where
all the system types are 32 bits, EMACS_INT can still be 32 bits.

> Can 32-bit hosts really support buffers and strings larger than 2GB,
> even if EMACS_INT is a 64-bit type?

Yes, absolutely.  For example:

  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  int
  main (void)
  {
    int big = 536870913;
    int *p = malloc (big * sizeof *p);
    if (!p)
      return 1;
    memset (p, 0xef, big * sizeof *p);
    printf ("%x %x\n", p[0], p[big - 1]);
    return 0;
  }

On my RHEL 5.6 host, built as a 32-bit executable, this outputs:

  $ gcc -m32 t.c
  $ ./a.out
  efefefef efefefef

even though the array's size does not fit in 'int' or 'long'.
The same behavior can be observed on pure 32-bit systems;
it's quite common and has been for years.

> I thought the largest object on a
> 32-but machine cannot exceed 2GB due to pointer arithmetics,

No, but as shown above one can often allocate objects larger than 2 GiB
on such machines.

Perhaps you're thinking of pointer subtraction?  That often stops working on
arrays larger than 2 GiB.  But this is easy to program around.  And
anyway, even if we assume buffers and strings are all smaller than 2
GiB, an EMACS_INT wider than 32 bits is still needed for large buffers
and strings, due to the tag bits.

>>  Emacs cannot visit files that are larger than the maximum Emacs buffer
>> -size, which is around 512 megabytes on 32-bit machines
>> +size, which is around 512 MiB on 32-bit machines and 2 EiB on 64-bit machines
>>  (@pxref{Buffers}).  If you try, Emacs will display an error message
>>  saying that the maximum buffer size has been exceeded.
> 
> This seems to contradict what you said about buffers, doesn't it?

Yes, thanks, I messed that up; I'll fix that part of the documentation.

>> +      if (NATNUMP (top) && XFASTINT (top) <= UINTMAX_MAX >> 16 && NATNUMP (bo> 
> The *_MAX macros need limits.h, but I don't see it being included by
> data.c.  Did I miss something?

Those are OK because lisp.h includes inttypes.h.  INTMAX_MAX and
UINTMAX_MAX are defined by inttypes.h (actually, stdint.h, but
inttypes.h includes stdint.h).  Like you, I would have put all the
_MIN and _MAX macros into limits.h, but I wasn't part of that
design decision.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03 15:54 ` Stefan Monnier
@ 2011-06-03 19:28   ` Paul Eggert
  2011-06-05 12:00     ` Stefan Monnier
  2011-06-03 19:29   ` bug#8794: (a) straightforward prerequisite fixes Paul Eggert
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-03 19:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

On 06/03/11 08:54, Stefan Monnier wrote:
> So, there are 3 parts:
> - fix the cons<->int conversions.
> - add a 64bit-on-32bit compilation option.
> - make that option the default.
> Please split it into those three parts.

OK.  The 2nd part is already done: just compile the Emacs trunk
with -DWIDE_EMACS_INT.  But I see the need for another part,
containing some prerequisite fixes.  So I'll send three followup emails:

(a) straightforward fixes that I assume are uncontroversial
(b) make 64bit-on-32bit the default (on 32bit systems that support it)
(c) fix the cons<->int conversions

Each part is a prerequisite for the next.  Some of the fixes in
(a) are not actually prerequisites, so if you want me to explode (a)
into the dozen or so patches that it contains, then I can do that,
but I'd rather not bother unless it's needed.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (a) straightforward prerequisite fixes
  2011-06-03 15:54 ` Stefan Monnier
  2011-06-03 19:28   ` Paul Eggert
@ 2011-06-03 19:29   ` Paul Eggert
  2011-06-03 19:29   ` bug#8794: (b) make the 64bit-on-32bit the default (if supported) Paul Eggert
  2011-06-03 19:30   ` bug#8794: (c) fix the cons<->int conversions Paul Eggert
  3 siblings, 0 replies; 21+ messages in thread
From: Paul Eggert @ 2011-06-03 19:29 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-02 08:40:41 +0000
+++ src/ChangeLog	2011-06-03 18:22:12 +0000
@@ -1,3 +1,37 @@
+2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* xselect.c: Use 'unsigned' more consistently.
+	(selection_data_to_lisp_data, lisp_data_to_selection_data):
+	Use 'unsigned' consistently when computing sizes of unsigned objects.
+
+	* fileio.c (Fverify_visited_file_modtime): Avoid time overflow
+	if b->modtime has its maximal value.
+
+	* dired.c (Ffile_attributes): Don't assume EMACS_INT has >32 bits.
+
+	* lisp.h: Include <intprops.h>, as it'll useful in later changes.
+	* character.c, data.c, editfns.c, insdel.c, intervals.c:
+	Don't include <intprops.h>, since lisp.h does.
+
+	Don't assume time_t can fit into int.
+	* buffer.h (struct buffer.modtime): Now time_t, not int.
+	* fileio.c (Fvisited_file_modtime): No need for time_t cast now.
+	* undo.c (Fprimitive_undo): Use time_t, not int, for time_t value.
+
+	Minor fixes for signed vs unsigned integers.
+	* character.h (MAYBE_UNIFY_CHAR):
+	* charset.c (maybe_unify_char):
+	* keyboard.c (read_char, reorder_modifiers):
+	XINT -> XFASTINT, since the integer must be nonnegative.
+	* ftfont.c (ftfont_spec_pattern):
+	* keymap.c (access_keymap, silly_event_symbol_error):
+	XUINT -> XFASTINT, since the integer must be nonnegative.
+	(Fsingle_key_description, preferred_sequence_p): XUINT -> XINT,
+	since it makes no difference and we prefer signed.
+	* keyboard.c (record_char): Use XUINT when all the neighbors do.
+	(access_keymap): NATNUMP -> INTEGERP, since the integer must be
+	nonnegative.
+
 2011-06-02  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Malloc failure behavior now depends on size of allocation.

=== modified file 'src/buffer.h'
--- src/buffer.h	2011-05-12 07:07:06 +0000
+++ src/buffer.h	2011-06-02 06:15:15 +0000
@@ -545,7 +545,7 @@
      -1 means visited file was nonexistent.
      0 means visited file modtime unknown; in no case complain
      about any mismatch on next save attempt.  */
-  int modtime;
+  time_t modtime;
   /* Size of the file when modtime was set.  This is used to detect the
      case where the file grew while we were reading it, so the modtime
      is still the same (since it's rounded up to seconds) but we're actually

=== modified file 'src/character.c'
--- src/character.c	2011-05-21 04:33:23 +0000
+++ src/character.c	2011-06-02 06:17:35 +0000
@@ -35,7 +35,7 @@
 
 #include <sys/types.h>
 #include <setjmp.h>
-#include <intprops.h>
+
 #include "lisp.h"
 #include "character.h"
 #include "buffer.h"

=== modified file 'src/character.h'
--- src/character.h	2011-05-21 04:33:23 +0000
+++ src/character.h	2011-06-01 02:49:12 +0000
@@ -544,7 +544,7 @@
 	Lisp_Object val;				\
 	val = CHAR_TABLE_REF (Vchar_unify_table, c);	\
 	if (INTEGERP (val))				\
-	  c = XINT (val);				\
+	  c = XFASTINT (val);				\
 	else if (! NILP (val))				\
 	  c = maybe_unify_char (c, val);		\
       }							\

=== modified file 'src/charset.c'
--- src/charset.c	2011-05-31 06:05:00 +0000
+++ src/charset.c	2011-06-03 18:11:17 +0000
@@ -1637,7 +1637,7 @@
   struct charset *charset;
 
   if (INTEGERP (val))
-    return XINT (val);
+    return XFASTINT (val);
   if (NILP (val))
     return c;
 
@@ -1647,7 +1647,7 @@
     {
       val = CHAR_TABLE_REF (Vchar_unify_table, c);
       if (! NILP (val))
-	c = XINT (val);
+	c = XFASTINT (val);
     }
   else
     {

=== modified file 'src/data.c'
--- src/data.c	2011-05-31 14:57:53 +0000
+++ src/data.c	2011-06-02 06:17:35 +0000
@@ -23,8 +23,6 @@
 #include <stdio.h>
 #include <setjmp.h>
 
-#include <intprops.h>
-
 #include "lisp.h"
 #include "puresize.h"
 #include "character.h"

=== modified file 'src/dired.c'
--- src/dired.c	2011-04-14 19:34:42 +0000
+++ src/dired.c	2011-06-02 06:21:13 +0000
@@ -1013,12 +1013,11 @@
 	 The code on the next line avoids a compiler warning on
 	 systems where st_ino is 32 bit wide. (bug#766).  */
       EMACS_INT high_ino = s.st_ino >> 31 >> 1;
-      EMACS_INT low_ino  = s.st_ino & 0xffffffff;
 
       values[10] = Fcons (make_number (high_ino >> 8),
 			  Fcons (make_number (((high_ino & 0xff) << 16)
-					      + (low_ino >> 16)),
-				 make_number (low_ino & 0xffff)));
+					      + (s.st_ino >> 16 & 0xffff)),
+				 make_number (s.st_ino & 0xffff)));
     }
 
   /* Likewise for device.  */

=== modified file 'src/editfns.c'
--- src/editfns.c	2011-05-30 16:47:35 +0000
+++ src/editfns.c	2011-06-03 18:14:49 +0000
@@ -47,7 +47,6 @@
 #include <ctype.h>
 #include <float.h>
 #include <limits.h>
-#include <intprops.h>
 #include <strftime.h>
 #include <verify.h>
 

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-04-29 19:47:29 +0000
+++ src/fileio.c	2011-06-02 06:23:20 +0000
@@ -4960,7 +4960,7 @@
   if ((st.st_mtime == b->modtime
        /* If both are positive, accept them if they are off by one second.  */
        || (st.st_mtime > 0 && b->modtime > 0
-	   && (st.st_mtime == b->modtime + 1
+	   && (st.st_mtime - 1 == b->modtime
 	       || st.st_mtime == b->modtime - 1)))
       && (st.st_size == b->modtime_size
           || b->modtime_size < 0))
@@ -4990,7 +4990,7 @@
 {
   if (! current_buffer->modtime)
     return make_number (0);
-  return make_time ((time_t) current_buffer->modtime);
+  return make_time (current_buffer->modtime);
 }
 
 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime,

=== modified file 'src/ftfont.c'
--- src/ftfont.c	2011-04-11 03:39:45 +0000
+++ src/ftfont.c	2011-06-01 02:49:12 +0000
@@ -815,7 +815,7 @@
 	    goto err;
 	  for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars))
 	    if (CHARACTERP (XCAR (chars))
-		&& ! FcCharSetAddChar (charset, XUINT (XCAR (chars))))
+		&& ! FcCharSetAddChar (charset, XFASTINT (XCAR (chars))))
 	      goto err;
 	}
     }

=== modified file 'src/insdel.c'
--- src/insdel.c	2011-05-21 04:33:23 +0000
+++ src/insdel.c	2011-06-02 06:17:35 +0000
@@ -21,8 +21,6 @@
 #include <config.h>
 #include <setjmp.h>
 
-#include <intprops.h>
-
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"

=== modified file 'src/intervals.c'
--- src/intervals.c	2011-05-28 22:39:39 +0000
+++ src/intervals.c	2011-06-02 06:17:35 +0000
@@ -39,7 +39,7 @@
 
 #include <config.h>
 #include <setjmp.h>
-#include <intprops.h>
+
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2011-05-28 22:39:39 +0000
+++ src/keyboard.c	2011-06-01 02:49:12 +0000
@@ -2395,8 +2395,8 @@
 
       c = Faref (Vexecuting_kbd_macro, make_number (executing_kbd_macro_index));
       if (STRINGP (Vexecuting_kbd_macro)
-	  && (XINT (c) & 0x80) && (XUINT (c) <= 0xff))
-	XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80));
+	  && (XFASTINT (c) & 0x80) && (XFASTINT (c) <= 0xff))
+	XSETFASTINT (c, CHAR_META | (XFASTINT (c) & ~0x80));
 
       executing_kbd_macro_index++;
 
@@ -3321,7 +3321,7 @@
       if (INTEGERP (c))
 	{
 	  if (XUINT (c) < 0x100)
-	    putc (XINT (c), dribble);
+	    putc (XUINT (c), dribble);
 	  else
 	    fprintf (dribble, " 0x%"pI"x", XUINT (c));
 	}
@@ -6370,7 +6370,7 @@
   Lisp_Object parsed;
 
   parsed = parse_modifiers (symbol);
-  return apply_modifiers ((int) XINT (XCAR (XCDR (parsed))),
+  return apply_modifiers (XFASTINT (XCAR (XCDR (parsed))),
 			  XCAR (parsed));
 }
 

=== modified file 'src/keymap.c'
--- src/keymap.c	2011-05-12 07:07:06 +0000
+++ src/keymap.c	2011-06-01 02:49:12 +0000
@@ -462,7 +462,7 @@
     XSETFASTINT (idx, XINT (idx) & (CHAR_META | (CHAR_META - 1)));
 
   /* Handle the special meta -> esc mapping. */
-  if (INTEGERP (idx) && XUINT (idx) & meta_modifier)
+  if (INTEGERP (idx) && XFASTINT (idx) & meta_modifier)
     {
       /* See if there is a meta-map.  If there's none, there is
          no binding for IDX, unless a default binding exists in MAP.  */
@@ -480,7 +480,7 @@
       if (CONSP (event_meta_map))
 	{
 	  map = event_meta_map;
-	  idx = make_number (XUINT (idx) & ~meta_modifier);
+	  idx = make_number (XFASTINT (idx) & ~meta_modifier);
 	}
       else if (t_ok)
 	/* Set IDX to t, so that we only find a default binding.  */
@@ -529,7 +529,7 @@
 	  }
 	else if (VECTORP (binding))
 	  {
-	    if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (binding))
+	    if (INTEGERP (idx) && XFASTINT (idx) < ASIZE (binding))
 	      val = AREF (binding, XFASTINT (idx));
 	  }
 	else if (CHAR_TABLE_P (binding))
@@ -537,7 +537,7 @@
 	    /* Character codes with modifiers
 	       are not included in a char-table.
 	       All character codes without modifiers are included.  */
-	    if (NATNUMP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0)
+	    if (INTEGERP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0)
 	      {
 		val = Faref (binding, idx);
 		/* `nil' has a special meaning for char-tables, so
@@ -1357,7 +1357,7 @@
   int modifiers;
 
   parsed = parse_modifiers (c);
-  modifiers = (int) XUINT (XCAR (XCDR (parsed)));
+  modifiers = XFASTINT (XCAR (XCDR (parsed)));
   base = XCAR (parsed);
   name = Fsymbol_name (base);
   /* This alist includes elements such as ("RET" . "\\r").  */
@@ -2416,7 +2416,7 @@
     {
       char tem[KEY_DESCRIPTION_SIZE];
 
-      *push_key_description (XUINT (key), tem, 1) = 0;
+      *push_key_description (XINT (key), tem, 1) = 0;
       return build_string (tem);
     }
   else if (SYMBOLP (key))	/* Function key or event-symbol */
@@ -2515,7 +2515,7 @@
 	return 0;
       else
 	{
-	  int modifiers = XUINT (elt) & (CHAR_MODIFIER_MASK & ~CHAR_META);
+	  int modifiers = XINT (elt) & (CHAR_MODIFIER_MASK & ~CHAR_META);
 	  if (modifiers == where_is_preferred_modifier)
 	    result = 2;
 	  else if (modifiers)

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-02 08:25:28 +0000
+++ src/lisp.h	2011-06-03 18:14:49 +0000
@@ -24,6 +24,8 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+#include <intprops.h>
+
 /* Use the configure flag --enable-checking[=LIST] to enable various
    types of run time checks for Lisp objects.  */
 

=== modified file 'src/undo.c'
--- src/undo.c	2011-04-14 05:04:02 +0000
+++ src/undo.c	2011-06-02 06:15:15 +0000
@@ -500,7 +500,7 @@
 		{
 		  /* Element (t high . low) records previous modtime.  */
 		  Lisp_Object high, low;
-		  int mod_time;
+		  time_t mod_time;
 		  struct buffer *base_buffer = current_buffer;
 
 		  high = Fcar (cdr);

=== modified file 'src/xselect.c'
--- src/xselect.c	2011-05-29 05:23:24 +0000
+++ src/xselect.c	2011-06-03 18:22:12 +0000
@@ -1651,9 +1651,9 @@
      If the number is 32 bits and won't fit in a Lisp_Int,
      convert it to a cons of integers, 16 bits in each half.
    */
-  else if (format == 32 && size == sizeof (int))
+  else if (format == 32 && size == sizeof (unsigned int))
     return long_to_cons (((unsigned int *) data) [0]);
-  else if (format == 16 && size == sizeof (short))
+  else if (format == 16 && size == sizeof (unsigned short))
     return make_number ((int) (((unsigned short *) data) [0]));
 
   /* Convert any other kind of data to a vector of numbers, represented
@@ -1753,8 +1753,8 @@
     {
       *format_ret = 32;
       *size_ret = 1;
-      *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
-      (*data_ret) [sizeof (long)] = 0;
+      *data_ret = (unsigned char *) xmalloc (sizeof (unsigned long) + 1);
+      (*data_ret) [sizeof (unsigned long)] = 0;
       (*(unsigned long **) data_ret) [0] = cons_to_long (obj);
       if (NILP (type)) type = QINTEGER;
     }






^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (b) make the 64bit-on-32bit the default (if supported)
  2011-06-03 15:54 ` Stefan Monnier
  2011-06-03 19:28   ` Paul Eggert
  2011-06-03 19:29   ` bug#8794: (a) straightforward prerequisite fixes Paul Eggert
@ 2011-06-03 19:29   ` Paul Eggert
  2011-06-06 14:52     ` Stefan Monnier
  2011-06-03 19:30   ` bug#8794: (c) fix the cons<->int conversions Paul Eggert
  3 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-03 19:29 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

Almost all of this is documentation change.  The only code change
is the lisp.h change to the default.


=== modified file 'doc/emacs/ChangeLog'
--- doc/emacs/ChangeLog	2011-05-28 18:22:08 +0000
+++ doc/emacs/ChangeLog	2011-06-03 18:47:14 +0000
@@ -1,3 +1,9 @@
+2011-06-02  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Document wide integers better.
+	* buffers.texi (Buffers):
+	* files.texi (Visiting): Default buffer maximum is now 2 EiB typically.
+
 2011-05-28  Chong Yidong  <cyd@stupidchicken.com>
 
 	* custom.texi (Hooks): Reorganize.  Mention Prog mode.

=== modified file 'doc/emacs/buffers.texi'
--- doc/emacs/buffers.texi	2011-01-25 04:08:28 +0000
+++ doc/emacs/buffers.texi	2011-06-03 18:47:14 +0000
@@ -43,8 +43,11 @@
   A buffer's size cannot be larger than some maximum, which is defined
 by the largest buffer position representable by the @dfn{Emacs
 integer} data type.  This is because Emacs tracks buffer positions
-using that data type.  For 32-bit machines, the largest buffer size is
-512 megabytes.
+using that data type.  For most machines, the maximum buffer size
+enforced by the data types is @math{2^61 - 2} bytes, or about 2 EiB.
+For some older machines, the maximum is @math{2^29 - 2} bytes, or
+about 512 MiB.  Buffer sizes are also limited by the size of Emacs's
+virtual memory.
 
 @menu
 * Select Buffer::       Creating a new buffer or reselecting an old one.

=== modified file 'doc/emacs/files.texi'
--- doc/emacs/files.texi	2011-01-31 23:54:50 +0000
+++ doc/emacs/files.texi	2011-06-03 18:47:14 +0000
@@ -209,7 +209,8 @@
 about 10 megabytes), Emacs asks you for confirmation first.  You can
 answer @kbd{y} to proceed with visiting the file.  Note, however, that
 Emacs cannot visit files that are larger than the maximum Emacs buffer
-size, which is around 512 megabytes on 32-bit machines
+size, which is limited by the amount of memory Emacs can allocate
+and by the integers that Emacs can represent
 (@pxref{Buffers}).  If you try, Emacs will display an error message
 saying that the maximum buffer size has been exceeded.
 

=== modified file 'doc/lispref/ChangeLog'
--- doc/lispref/ChangeLog	2011-05-31 18:40:00 +0000
+++ doc/lispref/ChangeLog	2011-06-03 18:49:33 +0000
@@ -1,3 +1,12 @@
+2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Document wide integers better.
+	* files.texi (File Attributes): Document ino_t values better.
+	* numbers.texi (Integer Basics, Integer Basics, Arithmetic Operations):
+	(Bitwise Operations):
+	* objects.texi (Integer Type): Integers are typically 62 bits now.
+	* os.texi (Time Conversion): Document time_t values better.
+
 2011-05-31  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* processes.texi (Process Information): Document

=== modified file 'doc/lispref/files.texi'
--- doc/lispref/files.texi	2011-05-12 07:07:06 +0000
+++ doc/lispref/files.texi	2011-06-03 18:49:33 +0000
@@ -1236,12 +1236,13 @@
 
 @item
 The file's inode number.  If possible, this is an integer.  If the
-inode number is too large to be represented as an integer in Emacs
-Lisp, but still fits into a 32-bit integer, then the value has the
-form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16
-bits.  If the inode is wider than 32 bits, the value is of the form
+inode number @math{N} is too large to be represented as an integer in
+Emacs Lisp, but @math{N / 2^16} is representable, then the value has
+the form @code{(@var{high} . @var{low})}, where @var{high} holds the
+high bits (i.e., excluding the low-order bits) and @var{low} the low
+16 bits.  If the inode number is even larger, the value is of the form
 @code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds
-the high 24 bits, @var{middle} the next 24 bits, and @var{low} the low
+the high bits, @var{middle} the next 24 bits, and @var{low} the low
 16 bits.
 
 @item

=== modified file 'doc/lispref/numbers.texi'
--- doc/lispref/numbers.texi	2011-05-05 06:31:14 +0000
+++ doc/lispref/numbers.texi	2011-06-03 18:49:33 +0000
@@ -36,22 +36,24 @@
 @section Integer Basics
 
   The range of values for an integer depends on the machine.  The
-minimum range is @minus{}536870912 to 536870911 (30 bits; i.e.,
+typical range is @minus{}2305843009213693952 to 2305843009213693951
+(62 bits; i.e.,
 @ifnottex
--2**29
+-2**61
 @end ifnottex
 @tex
-@math{-2^{29}}
+@math{-2^{61}}
 @end tex
 to
 @ifnottex
-2**29 - 1),
+2**61 - 1)
 @end ifnottex
 @tex
-@math{2^{29}-1}),
+@math{2^{61}-1})
 @end tex
-but some machines may provide a wider range.  Many examples in this
-chapter assume an integer has 30 bits.
+but some older machines provide only 30 bits.  Many examples in this
+chapter assume that an integer has 62 bits and that floating point
+numbers are IEEE double precision.
 @cindex overflow
 
   The Lisp reader reads an integer as a sequence of digits with optional
@@ -63,7 +65,8 @@
  1.              ; @r{The integer 1.}
 +1               ; @r{Also the integer 1.}
 -1               ; @r{The integer @minus{}1.}
- 1073741825      ; @r{The floating point number 1073741825.0.}
+ 4611686018427387904
+                 ; @r{The floating point number 4.611686018427388e+18.}
  0               ; @r{The integer 0.}
 -0               ; @r{The integer 0.}
 @end example
@@ -94,25 +97,21 @@
 bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
 view the numbers in their binary form.
 
-  In 30-bit binary, the decimal integer 5 looks like this:
+  In 62-bit binary, the decimal integer 5 looks like this:
 
 @example
-00 0000  0000 0000  0000 0000  0000 0101
+0000...000101 (62 bits total)
 @end example
 
-@noindent
-(We have inserted spaces between groups of 4 bits, and two spaces
-between groups of 8 bits, to make the binary integer easier to read.)
-
   The integer @minus{}1 looks like this:
 
 @example
-11 1111  1111 1111  1111 1111  1111 1111
+1111...111111 (62 bits total)
 @end example
 
 @noindent
 @cindex two's complement
-@minus{}1 is represented as 30 ones.  (This is called @dfn{two's
+@minus{}1 is represented as 62 ones.  (This is called @dfn{two's
 complement} notation.)
 
   The negative integer, @minus{}5, is creating by subtracting 4 from
@@ -120,24 +119,24 @@
 @minus{}5 looks like this:
 
 @example
-11 1111  1111 1111  1111 1111  1111 1011
+1111...111011 (62 bits total)
 @end example
 
-  In this implementation, the largest 30-bit binary integer value is
-536,870,911 in decimal.  In binary, it looks like this:
+  In this implementation, the largest 62-bit binary integer value is
+2,305,843,009,213,693,951 in decimal.  In binary, it looks like this:
 
 @example
-01 1111  1111 1111  1111 1111  1111 1111
+0111...111111 (62 bits total)
 @end example
 
   Since the arithmetic functions do not check whether integers go
-outside their range, when you add 1 to 536,870,911, the value is the
-negative integer @minus{}536,870,912:
+outside their range, when you add 1 to 2,305,843,009,213,693,951, the value is the
+negative integer @minus{}2,305,843,009,213,693,952:
 
 @example
-(+ 1 536870911)
-     @result{} -536870912
-     @result{} 10 0000  0000 0000  0000 0000  0000 0000
+(+ 1 2305843009213693951)
+     @result{} -2305843009213693952
+     @result{} 1000...000000 (62 bits total)
 @end example
 
   Many of the functions described in this chapter accept markers for
@@ -508,8 +507,8 @@
 if any argument is floating.
 
   It is important to note that in Emacs Lisp, arithmetic functions
-do not check for overflow.  Thus @code{(1+ 268435455)} may evaluate to
-@minus{}268435456, depending on your hardware.
+do not check for overflow.  Thus @code{(1+ 2305843009213693951)} may
+evaluate to @minus{}2305843009213693952, depending on your hardware.
 
 @defun 1+ number-or-marker
 This function returns @var{number-or-marker} plus 1.
@@ -829,19 +828,19 @@
 The function @code{lsh}, like all Emacs Lisp arithmetic functions, does
 not check for overflow, so shifting left can discard significant bits
 and change the sign of the number.  For example, left shifting
-536,870,911 produces @minus{}2 on a 30-bit machine:
+2,305,843,009,213,693,951 produces @minus{}2 on a typical machine:
 
 @example
-(lsh 536870911 1)          ; @r{left shift}
+(lsh 2305843009213693951 1)  ; @r{left shift}
      @result{} -2
 @end example
 
-In binary, in the 30-bit implementation, the argument looks like this:
+In binary, in the 62-bit implementation, the argument looks like this:
 
 @example
 @group
-;; @r{Decimal 536,870,911}
-01 1111  1111 1111  1111 1111  1111 1111
+;; @r{Decimal 2,305,843,009,213,693,951}
+0111...111111 (62 bits total)
 @end group
 @end example
 
@@ -851,7 +850,7 @@
 @example
 @group
 ;; @r{Decimal @minus{}2}
-11 1111  1111 1111  1111 1111  1111 1110
+1111...111110 (62 bits total)
 @end group
 @end example
 @end defun
@@ -874,9 +873,9 @@
 @group
 (ash -6 -1) @result{} -3
 ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
-11 1111  1111 1111  1111 1111  1111 1010
+1111...111010 (62 bits total)
      @result{}
-11 1111  1111 1111  1111 1111  1111 1101
+1111...111101 (62 bits total)
 @end group
 @end example
 
@@ -885,11 +884,11 @@
 
 @example
 @group
-(lsh -6 -1) @result{} 536870909
-;; @r{Decimal @minus{}6 becomes decimal 536,870,909.}
-11 1111  1111 1111  1111 1111  1111 1010
+(lsh -6 -1) @result{} 2305843009213693949
+;; @r{Decimal @minus{}6 becomes decimal 2,305,843,009,213,693,949.}
+1111...111010 (62 bits total)
      @result{}
-01 1111  1111 1111  1111 1111  1111 1101
+0111...111101 (62 bits total)
 @end group
 @end example
 
@@ -899,34 +898,35 @@
 @c     with smallbook but not with regular book! --rjc 16mar92
 @smallexample
 @group
-                   ;  @r{             30-bit binary values}
+                   ;  @r{       62-bit binary values}
 
-(lsh 5 2)          ;   5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 20         ;      =  @r{00 0000  0000 0000  0000 0000  0001 0100}
+(lsh 5 2)          ;   5  =  @r{0000...000101}
+     @result{} 20         ;      =  @r{0000...010100}
 @end group
 @group
 (ash 5 2)
      @result{} 20
-(lsh -5 2)         ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
-     @result{} -20        ;      =  @r{11 1111  1111 1111  1111 1111  1110 1100}
+(lsh -5 2)         ;  -5  =  @r{1111...111011}
+     @result{} -20        ;      =  @r{1111...101100}
 (ash -5 2)
      @result{} -20
 @end group
 @group
-(lsh 5 -2)         ;   5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 1          ;      =  @r{00 0000  0000 0000  0000 0000  0000 0001}
+(lsh 5 -2)         ;   5  =  @r{0000...000101}
+     @result{} 1          ;      =  @r{0000...000001}
 @end group
 @group
 (ash 5 -2)
      @result{} 1
 @end group
 @group
-(lsh -5 -2)        ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
-     @result{} 268435454  ;      =  @r{00 0111  1111 1111  1111 1111  1111 1110}
+(lsh -5 -2)        ;  -5  =  @r{1111...111011}
+     @result{} 1152921504606846974
+                   ;      =  @r{0011...111110}
 @end group
 @group
-(ash -5 -2)        ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
-     @result{} -2         ;      =  @r{11 1111  1111 1111  1111 1111  1111 1110}
+(ash -5 -2)        ;  -5  =  @r{1111...111011}
+     @result{} -2         ;      =  @r{1111...111110}
 @end group
 @end smallexample
 @end defun
@@ -961,23 +961,23 @@
 
 @smallexample
 @group
-                   ; @r{               30-bit binary values}
+                   ; @r{       62-bit binary values}
 
-(logand 14 13)     ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
-                   ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
-     @result{} 12         ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
+(logand 14 13)     ; 14  =  @r{0000...001110}
+                   ; 13  =  @r{0000...001101}
+     @result{} 12         ; 12  =  @r{0000...001100}
 @end group
 
 @group
-(logand 14 13 4)   ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
-                   ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
-                   ;  4  =  @r{00 0000  0000 0000  0000 0000  0000 0100}
-     @result{} 4          ;  4  =  @r{00 0000  0000 0000  0000 0000  0000 0100}
+(logand 14 13 4)   ; 14  =  @r{0000...001110}
+                   ; 13  =  @r{0000...001101}
+                   ;  4  =  @r{0000...000100}
+     @result{} 4          ;  4  =  @r{0000...000100}
 @end group
 
 @group
 (logand)
-     @result{} -1         ; -1  =  @r{11 1111  1111 1111  1111 1111  1111 1111}
+     @result{} -1         ; -1  =  @r{1111...111111}
 @end group
 @end smallexample
 @end defun
@@ -991,18 +991,18 @@
 
 @smallexample
 @group
-                   ; @r{              30-bit binary values}
+                   ; @r{       62-bit binary values}
 
-(logior 12 5)      ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 13         ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
+(logior 12 5)      ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+     @result{} 13         ; 13  =  @r{0000...001101}
 @end group
 
 @group
-(logior 12 5 7)    ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-                   ;  7  =  @r{00 0000  0000 0000  0000 0000  0000 0111}
-     @result{} 15         ; 15  =  @r{00 0000  0000 0000  0000 0000  0000 1111}
+(logior 12 5 7)    ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+                   ;  7  =  @r{0000...000111}
+     @result{} 15         ; 15  =  @r{0000...001111}
 @end group
 @end smallexample
 @end defun
@@ -1016,18 +1016,18 @@
 
 @smallexample
 @group
-                   ; @r{              30-bit binary values}
+                   ; @r{       62-bit binary values}
 
-(logxor 12 5)      ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-     @result{} 9          ;  9  =  @r{00 0000  0000 0000  0000 0000  0000 1001}
+(logxor 12 5)      ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+     @result{} 9          ;  9  =  @r{0000...001001}
 @end group
 
 @group
-(logxor 12 5 7)    ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
-                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
-                   ;  7  =  @r{00 0000  0000 0000  0000 0000  0000 0111}
-     @result{} 14         ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
+(logxor 12 5 7)    ; 12  =  @r{0000...001100}
+                   ;  5  =  @r{0000...000101}
+                   ;  7  =  @r{0000...000111}
+     @result{} 14         ; 14  =  @r{0000...001110}
 @end group
 @end smallexample
 @end defun
@@ -1040,9 +1040,9 @@
 @example
 (lognot 5)
      @result{} -6
-;;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
+;;  5  =  @r{0000...000101} (62 bits total)
 ;; @r{becomes}
-;; -6  =  @r{11 1111  1111 1111  1111 1111  1111 1010}
+;; -6  =  @r{1111...111010} (62 bits total)
 @end example
 @end defun
 

=== modified file 'doc/lispref/objects.texi'
--- doc/lispref/objects.texi	2011-05-05 06:31:14 +0000
+++ doc/lispref/objects.texi	2011-06-03 18:49:33 +0000
@@ -164,25 +164,25 @@
 @node Integer Type
 @subsection Integer Type
 
-  The range of values for integers in Emacs Lisp is @minus{}536870912 to
-536870911 (30 bits; i.e.,
+  The range of values for integers in Emacs Lisp is
+@minus{}2305843009213693952 to 2305843009213693951 (62 bits; i.e.,
 @ifnottex
--2**29
+-2**61
 @end ifnottex
 @tex
-@math{-2^{29}}
+@math{-2^{61}}
 @end tex
 to
 @ifnottex
-2**29 - 1)
+2**61 - 1)
 @end ifnottex
 @tex
-@math{2^{29}-1})
+@math{2^{61}-1})
 @end tex
-on most machines.  (Some machines may provide a wider range.)  It is
-important to note that the Emacs Lisp arithmetic functions do not check
-for overflow.  Thus @code{(1+ 536870911)} is @minus{}536870912 on most
-machines.
+on most machines.  Some machines may provide a narrower or wider
+range; all machines provide at least 30 bits.  Emacs Lisp arithmetic
+functions do not check for overflow.  Thus @code{(1+
+2305843009213693951)} is @minus{}2305843009213693952 on most machines.
 
   The read syntax for integers is a sequence of (base ten) digits with an
 optional sign at the beginning and an optional period at the end.  The
@@ -195,7 +195,6 @@
 1                ; @r{The integer 1.}
 1.               ; @r{Also the integer 1.}
 +1               ; @r{Also the integer 1.}
-1073741825       ; @r{Also the integer 1 on a 30-bit implementation.}
 @end group
 @end example
 
@@ -203,8 +202,8 @@
 As a special exception, if a sequence of digits specifies an integer
 too large or too small to be a valid integer object, the Lisp reader
 reads it as a floating-point number (@pxref{Floating Point Type}).
-For instance, on most machines @code{536870912} is read as the
-floating-point number @code{536870912.0}.
+For instance, on most machines @code{2305843009213693952} is read as the
+floating-point number @code{2.305843009213694e+18}.
 
   @xref{Numbers}, for more information.
 

=== modified file 'doc/lispref/os.texi'
--- doc/lispref/os.texi	2011-02-01 07:23:48 +0000
+++ doc/lispref/os.texi	2011-06-03 18:49:33 +0000
@@ -1193,11 +1193,11 @@
 from the functions @code{current-time} (@pxref{Time of Day}) and
 @code{file-attributes} (@pxref{Definition of file-attributes}).
 
-  Many operating systems are limited to time values that contain 32 bits
+  Many 32-bit operating systems are limited to time values that contain 32 bits
 of information; these systems typically handle only the times from
-1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.  However, some
-operating systems have larger time values, and can represent times far
-in the past or future.
+1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.  However, 64-bit
+and some 32-bit operating systems have larger time values, and can
+represent times far in the past or future.
 
   Time conversion functions always use the Gregorian calendar, even
 for dates before the Gregorian calendar was introduced.  Year numbers

=== modified file 'etc/ChangeLog'
--- etc/ChangeLog	2011-05-24 14:22:44 +0000
+++ etc/ChangeLog	2011-06-03 18:42:04 +0000
@@ -1,3 +1,7 @@
+2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* NEWS: 62-bit integers are typical now.
+
 2011-05-24  Leo Liu  <sdl.web@gmail.com>
 
 	* NEWS: Mention the new primitive sha1 and the removal of sha1.el.

=== modified file 'etc/NEWS'
--- etc/NEWS	2011-06-01 15:34:41 +0000
+++ etc/NEWS	2011-06-03 18:42:04 +0000
@@ -902,6 +902,14 @@
 *** New function `special-variable-p' to check whether a variable is
 declared as dynamically bound.
 
+** Emacs integers have a wider range on typical 32-bit hosts.
+Previously, they were limited to a 30-bit range (-2**29 .. 2**29-1).
+Now, they are limited to a 62-bit range (-2**61 .. 2**61-1), the
+same as on 64-bit hosts.  This increased range comes from the Emacs
+interpreter using 64-bit native integer types that are available
+on typical modern 32-bit platforms.  Older 32-bit hosts that lack
+64-bit integers have the same 30-bit range as before.
+
 ** pre/post-command-hook are not reset to nil upon error.
 Instead, the offending function is removed.
 

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-03 18:22:12 +0000
+++ src/ChangeLog	2011-06-03 18:42:59 +0000
@@ -1,5 +1,14 @@
 2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Fix doc for machines with wider system times such as time_t.
+	On such machines, it's now safe to assume that EMACS_INT is as
+	wide as the system times, so that shifting right by 16 will
+	result in an integer that always fits in EMACS_INT.
+	* dired.c (Ffile_attributes): Document large inode number handling.
+	* termhooks.h: Fix comment for large time stamp handling.
+
+	* lisp.h (WIDE_EMACS_INT): Now defaults to 1.
+
 	* xselect.c: Use 'unsigned' more consistently.
 	(selection_data_to_lisp_data, lisp_data_to_selection_data):
 	Use 'unsigned' consistently when computing sizes of unsigned objects.

=== modified file 'src/dired.c'
--- src/dired.c	2011-06-02 06:21:13 +0000
+++ src/dired.c	2011-06-03 18:42:59 +0000
@@ -901,10 +901,10 @@
  8. File modes, as a string of ten letters or dashes as in ls -l.
  9. t if file's gid would change if file were deleted and recreated.
 10. inode number.  If inode number is larger than what Emacs integer
-  can hold, but still fits into a 32-bit number, this is a cons cell
+  can hold, but all but the bottom 16 bits still fits, this is a cons cell
   containing two integers: first the high part, then the low 16 bits.
-  If the inode number is wider than 32 bits, this is of the form
-  (HIGH MIDDLE . LOW): first the high 24 bits, then middle 24 bits,
+  If the inode number is still wider, this is of the form
+  (HIGH MIDDLE . LOW): first the high bits, then the middle 24 bits,
   and finally the low 16 bits.
 11. Filesystem device number.  If it is larger than what the Emacs
   integer can hold, this is a cons cell, similar to the inode number.
@@ -1008,8 +1008,8 @@
 			make_number ((EMACS_INT)(s.st_ino & 0xffff)));
   else
     {
-      /* To allow inode numbers beyond 32 bits, separate into 2 24-bit
-	 high parts and a 16-bit bottom part.
+      /* To allow inode numbers beyond what INTEGER_TO_CONS can handle,
+	 separate into 2 24-bit high parts and a 16-bit bottom part.
 	 The code on the next line avoids a compiler warning on
 	 systems where st_ino is 32 bit wide. (bug#766).  */
       EMACS_INT high_ino = s.st_ino >> 31 >> 1;

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-03 18:14:49 +0000
+++ src/lisp.h	2011-06-03 18:28:20 +0000
@@ -36,13 +36,14 @@
 #define CHECK_CONS_LIST() ((void) 0)
 #endif
 
-/* Temporarily disable wider-than-pointer integers until they're tested more.
-   Build with CFLAGS='-DWIDE_EMACS_INT' to try them out.  */
-/* #undef WIDE_EMACS_INT */
+/* To disable wider-than-pointer integers, build with -DWIDE_EMACS_INT=0.  */
+#ifndef WIDE_EMACS_INT
+#define WIDE_EMACS_INT 1
+#endif
 
 /* These are default choices for the types to use.  */
 #ifndef EMACS_INT
-# if BITS_PER_LONG < BITS_PER_LONG_LONG && defined WIDE_EMACS_INT
+# if BITS_PER_LONG < BITS_PER_LONG_LONG && WIDE_EMACS_INT
 #  define EMACS_INT long long
 #  define BITS_PER_EMACS_INT BITS_PER_LONG_LONG
 #  define pI "ll"

=== modified file 'src/termhooks.h'
--- src/termhooks.h	2011-05-27 16:17:59 +0000
+++ src/termhooks.h	2011-06-03 18:42:59 +0000
@@ -342,8 +342,8 @@
      SELECTION-VALUE is the value that emacs owns for that selection.
       It may be any kind of Lisp object.
      SELECTION-TIMESTAMP is the time at which emacs began owning this
-      selection, as a cons of two 16-bit numbers (making a 32 bit
-      time.)
+      selection, as an Emacs integer; or if that doesn't fit, as a
+      cons of two 16-bit integers (making a 32 bit time.)
      FRAME is the frame for which we made the selection.  If there is
       an entry in this alist, then it can be assumed that Emacs owns
       that selection.






^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (c) fix the cons<->int conversions
  2011-06-03 15:54 ` Stefan Monnier
                     ` (2 preceding siblings ...)
  2011-06-03 19:29   ` bug#8794: (b) make the 64bit-on-32bit the default (if supported) Paul Eggert
@ 2011-06-03 19:30   ` Paul Eggert
  2016-02-25  6:49     ` Lars Ingebrigtsen
  3 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-03 19:30 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

=== modified file 'doc/lispref/ChangeLog'
--- doc/lispref/ChangeLog	2011-06-03 18:49:33 +0000
+++ doc/lispref/ChangeLog	2011-06-03 19:04:41 +0000
@@ -2,6 +2,8 @@
 
 	Document wide integers better.
 	* files.texi (File Attributes): Document ino_t values better.
+	ino_t values no longer map to anything larger than a single cons.
+
 	* numbers.texi (Integer Basics, Integer Basics, Arithmetic Operations):
 	(Bitwise Operations):
 	* objects.texi (Integer Type): Integers are typically 62 bits now.

=== modified file 'doc/lispref/files.texi'
--- doc/lispref/files.texi	2011-06-03 18:49:33 +0000
+++ doc/lispref/files.texi	2011-06-03 19:04:41 +0000
@@ -1237,13 +1237,9 @@
 @item
 The file's inode number.  If possible, this is an integer.  If the
 inode number @math{N} is too large to be represented as an integer in
-Emacs Lisp, but @math{N / 2^16} is representable, then the value has
-the form @code{(@var{high} . @var{low})}, where @var{high} holds the
-high bits (i.e., excluding the low-order bits) and @var{low} the low
-16 bits.  If the inode number is even larger, the value is of the form
-@code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds
-the high bits, @var{middle} the next 24 bits, and @var{low} the low
-16 bits.
+Emacs Lisp, then the value has the form @code{(@var{high}
+. @var{low})}, where @var{high} holds the high bits (i.e., all but the
+low 16 bits) and @var{low} the low 16 bits.
 
 @item
 The filesystem number of the device that the file is on.  Depending on

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-03 18:42:59 +0000
+++ src/ChangeLog	2011-06-03 19:02:25 +0000
@@ -1,5 +1,32 @@
 2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Check for overflow when converting integer to cons and back.
+	* charset.c (Fdefine_charset_internal, Fdecode_char):
+	Use cons_to_unsigned to catch overflow.
+	(Fencode_char): Use INTEGER_TO_CONS.
+	* composite.h (LGLYPH_CODE): Use cons_to_unsigned.
+	(LGLYPH_SET_CODE): Use INTEGER_TO_CONS.
+	* data.c (long_to_cons, cons_to_long): Remove.
+	(cons_to_unsigned, cons_to_signed): New functions.
+	These signal an error for invalid or out-of-range values.
+	* dired.c (Ffile_attributes): Use INTEGER_TO_CONS.
+	* fileio.c (Fset_visited_file_modtime): Use CONS_TO_INTEGER.
+	* font.c (Ffont_variation_glyphs):
+	* fontset.c (Finternal_char_font): Use INTEGER_TO_CONS.
+	* lisp.h (INTEGER_TO_CONS, CONS_TO_INTEGER): New macros.
+	(cons_to_signed, cons_to_unsigned): New decls.
+	(long_to_cons, cons_to_long): Remove decls.
+	* undo.c (record_first_change): Use INTEGER_TO_CONS.
+	(Fprimitive_undo): Use CONS_TO_INTEGER.
+	* xfns.c (Fx_window_property): Likewise.
+	* xselect.c (x_own_selection, selection_data_to_lisp_data):
+	Use INTEGER_TO_CONS.
+	(x_handle_selection_request, x_handle_selection_clear)
+	(x_get_foreign_selection, Fx_disown_selection_internal)
+	(Fx_get_atom_name, x_send_client_event): Use CONS_TO_INTEGER.
+	(lisp_data_to_selection_data): Use cons_to_unsigned.
+	(x_fill_property_data): Use cons_to_signed.  Report values out of range.
+
 	Fix doc for machines with wider system times such as time_t.
 	On such machines, it's now safe to assume that EMACS_INT is as
 	wide as the system times, so that shifting right by 16 will

=== modified file 'src/charset.c'
--- src/charset.c	2011-06-03 18:11:17 +0000
+++ src/charset.c	2011-06-03 19:02:25 +0000
@@ -932,17 +932,8 @@
   val = args[charset_arg_min_code];
   if (! NILP (val))
     {
-      unsigned code;
+      unsigned code = cons_to_unsigned (val, UINT_MAX);
 
-      if (INTEGERP (val))
-	code = XINT (val);
-      else
-	{
-	  CHECK_CONS (val);
-	  CHECK_NUMBER_CAR (val);
-	  CHECK_NUMBER_CDR (val);
-	  code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
-	}
       if (code < charset.min_code
 	  || code > charset.max_code)
 	args_out_of_range_3 (make_number (charset.min_code),
@@ -954,17 +945,8 @@
   val = args[charset_arg_max_code];
   if (! NILP (val))
     {
-      unsigned code;
+      unsigned code = cons_to_unsigned (val, UINT_MAX);
 
-      if (INTEGERP (val))
-	code = XINT (val);
-      else
-	{
-	  CHECK_CONS (val);
-	  CHECK_NUMBER_CAR (val);
-	  CHECK_NUMBER_CDR (val);
-	  code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
-	}
       if (code < charset.min_code
 	  || code > charset.max_code)
 	args_out_of_range_3 (make_number (charset.min_code),
@@ -1865,17 +1847,7 @@
   struct charset *charsetp;
 
   CHECK_CHARSET_GET_ID (charset, id);
-  if (CONSP (code_point))
-    {
-      CHECK_NATNUM_CAR (code_point);
-      CHECK_NATNUM_CDR (code_point);
-      code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
-    }
-  else
-    {
-      CHECK_NATNUM (code_point);
-      code = XINT (code_point);
-    }
+  code = cons_to_unsigned (code_point, UINT_MAX);
   charsetp = CHARSET_FROM_ID (id);
   c = DECODE_CHAR (charsetp, code);
   return (c >= 0 ? make_number (c) : Qnil);
@@ -1900,9 +1872,7 @@
   code = ENCODE_CHAR (charsetp, XINT (ch));
   if (code == CHARSET_INVALID_CODE (charsetp))
     return Qnil;
-  if (code > 0x7FFFFFF)
-    return Fcons (make_number (code >> 16), make_number (code & 0xFFFF));
-  return make_number (code);
+  return INTEGER_TO_CONS (code);
 }
 
 

=== modified file 'src/composite.h'
--- src/composite.h	2011-05-31 06:05:00 +0000
+++ src/composite.h	2011-06-03 19:02:25 +0000
@@ -265,10 +265,7 @@
 #define LGLYPH_CODE(g)						\
   (NILP (AREF ((g), LGLYPH_IX_CODE))				\
    ? FONT_INVALID_CODE						\
-   : CONSP (AREF ((g), LGLYPH_IX_CODE))				\
-   ? ((XFASTINT (XCAR (AREF ((g), LGLYPH_IX_CODE))) << 16)	\
-      | (XFASTINT (XCDR (AREF ((g), LGLYPH_IX_CODE)))))		\
-   : XFASTINT (AREF ((g), LGLYPH_IX_CODE)))
+   : cons_to_unsigned (AREF (g, LGLYPH_IX_CODE), TYPE_MAXIMUM (unsigned)))
 #define LGLYPH_WIDTH(g) XINT (AREF ((g), LGLYPH_IX_WIDTH))
 #define LGLYPH_LBEARING(g) XINT (AREF ((g), LGLYPH_IX_LBEARING))
 #define LGLYPH_RBEARING(g) XINT (AREF ((g), LGLYPH_IX_RBEARING))
@@ -280,15 +277,8 @@
 #define LGLYPH_SET_CHAR(g, val) ASET ((g), LGLYPH_IX_CHAR, make_number (val))
 /* Callers must assure that VAL is not negative!  */
 #define LGLYPH_SET_CODE(g, val)						\
-  do {									\
-    if (val == FONT_INVALID_CODE)					\
-      ASET ((g), LGLYPH_IX_CODE, Qnil);					\
-    else if ((EMACS_INT)val > MOST_POSITIVE_FIXNUM)			\
-      ASET ((g), LGLYPH_IX_CODE, Fcons (make_number ((val) >> 16),	\
-					make_number ((val) & 0xFFFF)));	\
-    else								\
-      ASET ((g), LGLYPH_IX_CODE, make_number (val));			\
-  } while (0)
+  ASET (g, LGLYPH_IX_CODE,						\
+	val == FONT_INVALID_CODE ? Qnil : INTEGER_TO_CONS (val))
 
 #define LGLYPH_SET_WIDTH(g, val) ASET ((g), LGLYPH_IX_WIDTH, make_number (val))
 #define LGLYPH_SET_LBEARING(g, val) ASET ((g), LGLYPH_IX_LBEARING, make_number (val))

=== modified file 'src/data.c'
--- src/data.c	2011-06-02 06:17:35 +0000
+++ src/data.c	2011-06-03 19:02:25 +0000
@@ -2324,33 +2324,89 @@
   return Qnil;
 }
 \f
-/* Convert between long values and pairs of Lisp integers.
-   Note that long_to_cons returns a single Lisp integer
-   when the value fits in one.  */
+/* Convert the cons-of-integers, integer, or float value C to an
+   unsigned value with maximum value MAX.  Signal an error if C does not
+   have a valid format or is out of range.  */
+uintmax_t
+cons_to_unsigned (Lisp_Object c, uintmax_t max)
+{
+  int valid = 0;
+  uintmax_t val IF_LINT (= 0);
+  if (INTEGERP (c))
+    {
+      valid = 0 <= XINT (c);
+      val = XINT (c);
+    }
+  else if (FLOATP (c))
+    {
+      double d = XFLOAT_DATA (c);
+      if (0 <= d
+	  && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
+	{
+	  val = d;
+	  valid = 1;
+	}
+    }
+  else if (CONSP (c))
+    {
+      Lisp_Object top = XCAR (c);
+      Lisp_Object bot = XCDR (c);
+      if (CONSP (bot))
+	bot = XCAR (bot);
+      if (NATNUMP (top) && XFASTINT (top) <= UINTMAX_MAX >> 16 && NATNUMP (bot))
+	{
+	  uintmax_t utop = XFASTINT (top);
+	  val = (utop << 16) | XFASTINT (bot);
+	  valid = 1;
+	}
+    }
 
-Lisp_Object
-long_to_cons (long unsigned int i)
-{
-  unsigned long top = i >> 16;
-  unsigned int bot = i & 0xFFFF;
-  if (top == 0)
-    return make_number (bot);
-  if (top == (unsigned long)-1 >> 16)
-    return Fcons (make_number (-1), make_number (bot));
-  return Fcons (make_number (top), make_number (bot));
+  if (! (valid && val <= max))
+    error ("Not an in-range integer, float, or cons of integers");
+  return val;
 }
 
-unsigned long
-cons_to_long (Lisp_Object c)
+/* Convert the cons-of-integers, integer, or float value C to a signed
+   value with extrema MIN and MAX.  Signal an error if C does not have
+   a valid format or is out of range.  */
+intmax_t
+cons_to_signed (Lisp_Object c, intmax_t min, intmax_t max)
 {
-  Lisp_Object top, bot;
+  int valid = 0;
+  intmax_t val IF_LINT (= 0);
   if (INTEGERP (c))
-    return XINT (c);
-  top = XCAR (c);
-  bot = XCDR (c);
-  if (CONSP (bot))
-    bot = XCAR (bot);
-  return ((XINT (top) << 16) | XINT (bot));
+    {
+      val = XINT (c);
+      valid = 1;
+    }
+  else if (FLOATP (c))
+    {
+      double d = XFLOAT_DATA (c);
+      if (min <= d
+	  && d < (max == INTMAX_MAX ? (double) INTMAX_MAX + 1 : max + 1))
+	{
+	  val = d;
+	  valid = 1;
+	}
+    }
+  else if (CONSP (c))
+    {
+      Lisp_Object top = XCAR (c);
+      Lisp_Object bot = XCDR (c);
+      if (CONSP (bot))
+	bot = XCAR (bot);
+      if (INTEGERP (top) && INTMAX_MIN >> 16 <= XINT (top)
+	  && XINT (top) <= INTMAX_MAX >> 16 && INTEGERP (bot))
+	{
+	  intmax_t itop = XINT (top);
+	  val = (itop << 16) | XINT (bot);
+	  valid = 1;
+	}
+    }
+
+  if (! (valid && min <= val && val <= max))
+    error ("Not an in-range integer, float, or cons of integers");
+  return val;
 }
 \f
 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,

=== modified file 'src/dired.c'
--- src/dired.c	2011-06-03 18:42:59 +0000
+++ src/dired.c	2011-06-03 19:02:25 +0000
@@ -900,12 +900,9 @@
   This is a floating point number if the size is too large for an integer.
  8. File modes, as a string of ten letters or dashes as in ls -l.
  9. t if file's gid would change if file were deleted and recreated.
-10. inode number.  If inode number is larger than what Emacs integer
-  can hold, but all but the bottom 16 bits still fits, this is a cons cell
-  containing two integers: first the high part, then the low 16 bits.
-  If the inode number is still wider, this is of the form
-  (HIGH MIDDLE . LOW): first the high bits, then the middle 24 bits,
-  and finally the low 16 bits.
+10. inode number.  If it is larger than what the Emacs integer
+  can hold, this is a cons cell containing two integers: first the
+  high part, then the low 16 bits.
 11. Filesystem device number.  If it is larger than what the Emacs
   integer can hold, this is a cons cell, similar to the inode number.
 
@@ -998,34 +995,8 @@
 #else					/* file gid will be egid */
   values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
 #endif	/* not BSD4_2 */
-  if (!FIXNUM_OVERFLOW_P (s.st_ino))
-    /* Keep the most common cases as integers.  */
-    values[10] = make_number (s.st_ino);
-  else if (!FIXNUM_OVERFLOW_P (s.st_ino >> 16))
-    /* To allow inode numbers larger than VALBITS, separate the bottom
-       16 bits.  */
-    values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)),
-			make_number ((EMACS_INT)(s.st_ino & 0xffff)));
-  else
-    {
-      /* To allow inode numbers beyond what INTEGER_TO_CONS can handle,
-	 separate into 2 24-bit high parts and a 16-bit bottom part.
-	 The code on the next line avoids a compiler warning on
-	 systems where st_ino is 32 bit wide. (bug#766).  */
-      EMACS_INT high_ino = s.st_ino >> 31 >> 1;
-
-      values[10] = Fcons (make_number (high_ino >> 8),
-			  Fcons (make_number (((high_ino & 0xff) << 16)
-					      + (s.st_ino >> 16 & 0xffff)),
-				 make_number (s.st_ino & 0xffff)));
-    }
-
-  /* Likewise for device.  */
-  if (FIXNUM_OVERFLOW_P (s.st_dev))
-    values[11] = Fcons (make_number (s.st_dev >> 16),
-			make_number (s.st_dev & 0xffff));
-  else
-    values[11] = make_number (s.st_dev);
+  values[10] = INTEGER_TO_CONS (s.st_ino);
+  values[11] = INTEGER_TO_CONS (s.st_dev);
 
   return Flist (sizeof(values) / sizeof(values[0]), values);
 }

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-06-02 06:23:20 +0000
+++ src/fileio.c	2011-06-03 19:02:25 +0000
@@ -5005,7 +5005,7 @@
 {
   if (!NILP (time_list))
     {
-      current_buffer->modtime = cons_to_long (time_list);
+      CONS_TO_INTEGER (time_list, time_t, current_buffer->modtime);
       current_buffer->modtime_size = -1;
     }
   else

=== modified file 'src/font.c'
--- src/font.c	2011-05-29 19:04:01 +0000
+++ src/font.c	2011-06-03 19:02:25 +0000
@@ -4388,16 +4388,8 @@
   for (i = 0; i < 255; i++)
     if (variations[i])
       {
-	Lisp_Object code;
 	int vs = (i < 16 ? 0xFE00 + i : 0xE0100 + (i - 16));
-	/* Stops GCC whining about limited range of data type.	*/
-	EMACS_INT var = variations[i];
-
-	if (var > MOST_POSITIVE_FIXNUM)
-	  code = Fcons (make_number ((variations[i]) >> 16),
-			make_number ((variations[i]) & 0xFFFF));
-	else
-	  code = make_number (variations[i]);
+	Lisp_Object code = INTEGER_TO_CONS (variations[i]);
 	val = Fcons (Fcons (make_number (vs), code), val);
       }
   return val;

=== modified file 'src/fontset.c'
--- src/fontset.c	2011-05-28 22:39:39 +0000
+++ src/fontset.c	2011-06-03 19:02:25 +0000
@@ -1859,17 +1859,11 @@
     {
       unsigned code = face->font->driver->encode_char (face->font, c);
       Lisp_Object font_object;
-      /* Assignment to EMACS_INT stops GCC whining about limited range
-	 of data type.  */
-      EMACS_INT cod = code;
 
       if (code == FONT_INVALID_CODE)
 	return Qnil;
       XSETFONT (font_object, face->font);
-      if (cod <= MOST_POSITIVE_FIXNUM)
-	return Fcons (font_object, make_number (code));
-      return Fcons (font_object, Fcons (make_number (code >> 16),
-				     make_number (code & 0xFFFF)));
+      return Fcons (font_object, INTEGER_TO_CONS (code));
     }
   return Qnil;
 }

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-03 18:28:20 +0000
+++ src/lisp.h	2011-06-03 19:02:25 +0000
@@ -2405,9 +2405,33 @@
 EXFUN (Fsub1, 1);
 EXFUN (Fmake_variable_buffer_local, 1);
 
+/* Convert the integer I to an Emacs representation, either the integer
+   itself, or a cons of two integers, or if all else fails a float.
+   The float might lose information; this happens only in extreme cases
+   such as 32-bit EMACS_INT and 64-bit time_t with outlandish time values,
+   and these aren't worth complicating the interface.
+
+   I should not have side effects.  */
+#define INTEGER_TO_CONS(i)					    \
+  (! FIXNUM_OVERFLOW_P (i)					    \
+   ? make_number (i)						    \
+   : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16)			    \
+	 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16))		    \
+	&& FIXNUM_OVERFLOW_P ((i) >> 16))			    \
+   ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff))    \
+   : make_float (i))
+
+/* Convert the Emacs representation CONS back to an integer of type
+   TYPE, storing the result the variable VAR.  Signal an error if CONS
+   is not a valid representation or is out of range for TYPE.  */
+#define CONS_TO_INTEGER(cons, type, var)				\
+  (TYPE_SIGNED (type)							\
+   ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
+   : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
+extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
+extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
+
 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
-extern Lisp_Object long_to_cons (unsigned long);
-extern unsigned long cons_to_long (Lisp_Object);
 extern void args_out_of_range (Lisp_Object, Lisp_Object) NO_RETURN;
 extern void args_out_of_range_3 (Lisp_Object, Lisp_Object,
                                  Lisp_Object) NO_RETURN;

=== modified file 'src/undo.c'
--- src/undo.c	2011-06-02 06:15:15 +0000
+++ src/undo.c	2011-06-03 19:02:25 +0000
@@ -212,7 +212,6 @@
 void
 record_first_change (void)
 {
-  Lisp_Object high, low;
   struct buffer *base_buffer = current_buffer;
 
   if (EQ (BVAR (current_buffer, undo_list), Qt))
@@ -225,9 +224,9 @@
   if (base_buffer->base_buffer)
     base_buffer = base_buffer->base_buffer;
 
-  XSETFASTINT (high, (base_buffer->modtime >> 16) & 0xffff);
-  XSETFASTINT (low, base_buffer->modtime & 0xffff);
-  BVAR (current_buffer, undo_list) = Fcons (Fcons (Qt, Fcons (high, low)), BVAR (current_buffer, undo_list));
+  BVAR (current_buffer, undo_list) =
+    Fcons (Fcons (Qt, INTEGER_TO_CONS (base_buffer->modtime)),
+	   BVAR (current_buffer, undo_list));
 }
 
 /* Record a change in property PROP (whose old value was VAL)
@@ -499,13 +498,9 @@
 	      if (EQ (car, Qt))
 		{
 		  /* Element (t high . low) records previous modtime.  */
-		  Lisp_Object high, low;
+		  struct buffer *base_buffer = current_buffer;
 		  time_t mod_time;
-		  struct buffer *base_buffer = current_buffer;
-
-		  high = Fcar (cdr);
-		  low = Fcdr (cdr);
-		  mod_time = (XFASTINT (high) << 16) + XFASTINT (low);
+		  CONS_TO_INTEGER (cdr, time_t, mod_time);
 
 		  if (current_buffer->base_buffer)
 		    base_buffer = current_buffer->base_buffer;

=== modified file 'src/xfns.c'
--- src/xfns.c	2011-04-19 06:34:43 +0000
+++ src/xfns.c	2011-06-03 19:02:25 +0000
@@ -4295,18 +4295,9 @@
 
   if (! NILP (source))
     {
-      if (NUMBERP (source))
-        {
-          if (FLOATP (source))
-            target_window = (Window) XFLOAT (source);
-          else
-            target_window = XFASTINT (source);
-
-          if (target_window == 0)
-            target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
-        }
-      else if (CONSP (source))
-        target_window = cons_to_long (source);
+      CONS_TO_INTEGER (source, Window, target_window);
+      if (! target_window)
+	target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
     }
 
   BLOCK_INPUT;

=== modified file 'src/xselect.c'
--- src/xselect.c	2011-06-03 18:22:12 +0000
+++ src/xselect.c	2011-06-03 19:02:25 +0000
@@ -335,7 +335,7 @@
     Lisp_Object prev_value;
 
     selection_data = list4 (selection_name, selection_value,
-			    long_to_cons (timestamp), frame);
+			    INTEGER_TO_CONS (timestamp), frame);
     prev_value = LOCAL_SELECTION (selection_name, dpyinfo);
 
     dpyinfo->terminal->Vselection_alist
@@ -419,7 +419,7 @@
       || INTEGERP (check)
       || NILP (value))
     return value;
-  /* Check for a value that cons_to_long could handle.  */
+  /* Check for a value that CONS_TO_INTEGER could handle.  */
   else if (CONSP (check)
 	   && INTEGERP (XCAR (check))
 	   && (INTEGERP (XCDR (check))
@@ -782,8 +782,8 @@
   if (NILP (local_selection_data)) goto DONE;
 
   /* Decline requests issued prior to our acquiring the selection.  */
-  local_selection_time
-    = (Time) cons_to_long (XCAR (XCDR (XCDR (local_selection_data))));
+  CONS_TO_INTEGER (XCAR (XCDR (XCDR (local_selection_data))),
+		   Time, local_selection_time);
   if (SELECTION_EVENT_TIME (event) != CurrentTime
       && local_selection_time > SELECTION_EVENT_TIME (event))
     goto DONE;
@@ -950,8 +950,8 @@
   /* Well, we already believe that we don't own it, so that's just fine.  */
   if (NILP (local_selection_data)) return;
 
-  local_selection_time = (Time)
-    cons_to_long (XCAR (XCDR (XCDR (local_selection_data))));
+  CONS_TO_INTEGER (XCAR (XCDR (XCDR (local_selection_data))),
+		   Time, local_selection_time);
 
   /* We have reasserted the selection since this SelectionClear was
      generated, so we can disregard it.  */
@@ -1213,16 +1213,7 @@
     return Qnil;
 
   if (! NILP (time_stamp))
-    {
-      if (CONSP (time_stamp))
-        requestor_time = (Time) cons_to_long (time_stamp);
-      else if (INTEGERP (time_stamp))
-        requestor_time = (Time) XUINT (time_stamp);
-      else if (FLOATP (time_stamp))
-        requestor_time = (Time) XFLOAT_DATA (time_stamp);
-      else
-        error ("TIME_STAMP must be cons or number");
-    }
+    CONS_TO_INTEGER (time_stamp, Time, requestor_time);
 
   BLOCK_INPUT;
 
@@ -1652,7 +1643,7 @@
      convert it to a cons of integers, 16 bits in each half.
    */
   else if (format == 32 && size == sizeof (unsigned int))
-    return long_to_cons (((unsigned int *) data) [0]);
+    return INTEGER_TO_CONS (((unsigned int *) data) [0]);
   else if (format == 16 && size == sizeof (unsigned short))
     return make_number ((int) (((unsigned short *) data) [0]));
 
@@ -1678,7 +1669,7 @@
       for (i = 0; i < size / 4; i++)
 	{
 	  unsigned int j = ((unsigned int *) data) [i];
-	  Faset (v, make_number (i), long_to_cons (j));
+	  Faset (v, make_number (i), INTEGER_TO_CONS (j));
 	}
       return v;
     }
@@ -1755,7 +1746,7 @@
       *size_ret = 1;
       *data_ret = (unsigned char *) xmalloc (sizeof (unsigned long) + 1);
       (*data_ret) [sizeof (unsigned long)] = 0;
-      (*(unsigned long **) data_ret) [0] = cons_to_long (obj);
+      (*(unsigned long **) data_ret) [0] = cons_to_unsigned (obj, ULONG_MAX);
       if (NILP (type)) type = QINTEGER;
     }
   else if (VECTORP (obj))
@@ -1803,11 +1794,11 @@
 	  *data_ret = (unsigned char *) xmalloc (*size_ret * data_size);
 	  for (i = 0; i < *size_ret; i++)
 	    if (*format_ret == 32)
-	      (*((unsigned long **) data_ret)) [i]
-		= cons_to_long (XVECTOR (obj)->contents [i]);
+	      (*((unsigned long **) data_ret)) [i] =
+		cons_to_unsigned (XVECTOR (obj)->contents [i], ULONG_MAX);
 	    else
-	      (*((unsigned short **) data_ret)) [i]
-		= (unsigned short) cons_to_long (XVECTOR (obj)->contents [i]);
+	      (*((unsigned short **) data_ret)) [i] =
+		cons_to_unsigned (XVECTOR (obj)->contents [i], USHRT_MAX);
 	}
     }
   else
@@ -2025,8 +2016,10 @@
   selection_atom = symbol_to_x_atom (dpyinfo, selection);
 
   BLOCK_INPUT;
-  timestamp = (NILP (time_object) ? last_event_timestamp
-	       : cons_to_long (time_object));
+  if (NILP (time_object))
+    timestamp = last_event_timestamp;
+  else
+    CONS_TO_INTEGER (time_object, Time, timestamp);
   XSetSelectionOwner (dpyinfo->display, selection_atom, None, timestamp);
   UNBLOCK_INPUT;
 
@@ -2232,12 +2225,8 @@
     {
       Lisp_Object o = XCAR (iter);
 
-      if (INTEGERP (o))
-        val = (long) XFASTINT (o);
-      else if (FLOATP (o))
-        val = (long) XFLOAT_DATA (o);
-      else if (CONSP (o))
-        val = (long) cons_to_long (o);
+      if (INTEGERP (o) || FLOATP (o) || CONSP (o))
+	val = cons_to_signed (o, LONG_MIN, LONG_MAX);
       else if (STRINGP (o))
         {
           BLOCK_INPUT;
@@ -2248,9 +2237,19 @@
         error ("Wrong type, must be string, number or cons");
 
       if (format == 8)
-        *d08++ = (char) val;
+	{
+	  if (CHAR_MIN <= val && val <= CHAR_MAX)
+	    *d08++ = val;
+	  else
+	    error ("Out of 'char' range");
+	}
       else if (format == 16)
-        *d16++ = (short) val;
+	{
+	  if (SHRT_MIN <= val && val <= SHRT_MAX)
+	    *d16++ = val;
+	  else
+	    error ("Out of 'short' range");
+	}
       else
         *d32++ = val;
     }
@@ -2334,14 +2333,7 @@
   Atom atom;
   int had_errors;
 
-  if (INTEGERP (value))
-    atom = (Atom) XUINT (value);
-  else if (FLOATP (value))
-    atom = (Atom) XFLOAT_DATA (value);
-  else if (CONSP (value))
-    atom = (Atom) cons_to_long (value);
-  else
-    error ("Wrong type, value must be number or cons");
+  CONS_TO_INTEGER (value, Atom, atom);
 
   BLOCK_INPUT;
   x_catch_errors (dpy);
@@ -2531,17 +2523,8 @@
       else
         error ("DEST as a string must be one of PointerWindow or InputFocus");
     }
-  else if (INTEGERP (dest))
-    wdest = (Window) XFASTINT (dest);
-  else if (FLOATP (dest))
-    wdest =  (Window) XFLOAT_DATA (dest);
-  else if (CONSP (dest))
-    {
-      if (! NUMBERP (XCAR (dest)) || ! NUMBERP (XCDR (dest)))
-        error ("Both car and cdr for DEST must be numbers");
-      else
-        wdest = (Window) cons_to_long (dest);
-    }
+  else if (INTEGERP (dest) || FLOATP (dest) || CONSP (dest))
+    CONS_TO_INTEGER (dest, Window, wdest);
   else
     error ("DEST must be a frame, nil, string, number or cons");
 







^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03 17:53   ` Paul Eggert
@ 2011-06-03 19:43     ` Eli Zaretskii
  2011-06-04  3:05       ` Paul Eggert
  0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2011-06-03 19:43 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

> Date: Fri, 03 Jun 2011 10:53:55 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: 8794@debbugs.gnu.org
> 
>   int
>   main (void)
>   {
>     int big = 536870913;
>     int *p = malloc (big * sizeof *p);
>     if (!p)
>       return 1;
>     memset (p, 0xef, big * sizeof *p);
>     printf ("%x %x\n", p[0], p[big - 1]);
>     return 0;
>   }
> 
> On my RHEL 5.6 host, built as a 32-bit executable, this outputs:
> 
>   $ gcc -m32 t.c
>   $ ./a.out
>   efefefef efefefef

How does this work on the machine code level?  Doesn't the code need
to load a pointer to p into a 32-bit register, in order to reference
the array?  On Windows, I see that the GCC-produced code does this:

  movl   $0x20000001,0xfffffffc(%ebp)
  ...
  mov    0xfffffffc(%ebp),%eax
  shl    $0x2,%eax

and then uses EAX to reference the array elements.

That last left shift by 2 bits will surely overflow for values of
`big' that are larger that 0x3fffffff (not 0x20000001, the value you
used).  So maybe 2GB is not the limit, but 4GB surely is.  You promise
much more.

> Perhaps you're thinking of pointer subtraction?  That often stops working on
> arrays larger than 2 GiB.  But this is easy to program around.

Well, then we need to program around that, _before_ we promise buffers
larger than 2GB on 32-bit hosts.  E.g., look how we address characters
in buffers:

  /* Address of beginning of buffer.  */
  #define BUF_BEG_ADDR(buf) ((buf)->text->beg)

  /* Return character code of multi-byte form at byte position POS in BUF.
     If POS doesn't point the head of valid multi-byte form, only the byte at
     POS is returned.  No range checking.  */

  #define BUF_FETCH_MULTIBYTE_CHAR(buf, pos)				\
    (_fetch_multibyte_char_p						\
       = (((pos) >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)	\
	  + (pos) + BUF_BEG_ADDR (buf) - BEG_BYTE),			\
     STRING_CHAR (_fetch_multibyte_char_p))

The pointer arithmetics will wrap around on 32-bit hosts here, because
a pointer is loaded into a 32-bit register before it's dereferenced.
Am I missing something?

> And anyway, even if we assume buffers and strings are all smaller
> than 2 GiB, an EMACS_INT wider than 32 bits is still needed for
> large buffers and strings, due to the tag bits.

I wasn't saying a 64-bit EMACS_INT wasn't an advantage.  It is.  But I
very much doubt that we could have buffers and strings larger than 4GB
on 32-bit hosts.  Your changes to the docs seem to promise much larger
buffers, which I don't think is feasible.

> > The *_MAX macros need limits.h, but I don't see it being included by
> > data.c.  Did I miss something?
> 
> Those are OK because lisp.h includes inttypes.h.  INTMAX_MAX and
> UINTMAX_MAX are defined by inttypes.h (actually, stdint.h, but
> inttypes.h includes stdint.h).

What about ULONG_MAX in this patch to xselect.c:

> -      *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
> -      (*data_ret) [sizeof (long)] = 0;
> -      (*(unsigned long **) data_ret) [0] = cons_to_long (obj);
> +      *data_ret = (unsigned char *) xmalloc (sizeof (unsigned long) + 1);
> +      (*data_ret) [sizeof (unsigned long)] = 0;
> +      (*(unsigned long **) data_ret) [0] = cons_to_unsigned (obj, ULONG_MAX);

?  There are also USHRT_MAX, LONG_MAX, CHAR_MAX, and SHRT_MAX there,
but I see no limits.h being included.  How did that compile for you?





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03 19:43     ` Eli Zaretskii
@ 2011-06-04  3:05       ` Paul Eggert
  0 siblings, 0 replies; 21+ messages in thread
From: Paul Eggert @ 2011-06-04  3:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 8794

On 06/03/11 12:43, Eli Zaretskii wrote:

> maybe 2GB is not the limit, but 4GB surely is.

Yes, that's right.  A host with 32-bit addresses can address at most 4 GiB.

>> Perhaps you're thinking of pointer subtraction?  That often stops working on
>> arrays larger than 2 GiB.  But this is easy to program around.
>
> Well, then we need to program around that, _before_ we promise buffers
> larger than 2GB on 32-bit hosts.

OK, good point.  Rather than embark on that further fix, let's just
get this one done.  The further patches below fix the documentation so
that it talks about the 2 GiB limit on typical 32-bit hosts, and fix
the code to enforce this limit.

> What about ULONG_MAX in this patch to xselect.c:
> ...
> ?  There are also USHRT_MAX, LONG_MAX, CHAR_MAX, and SHRT_MAX there,
> but I see no limits.h being included.  How did that compile for you?

Thanks for catching that.  It worked for me because my platform needed
a replacement inttypes.h, which in turn included limits.h.  More
up-to-date platforms would use the system inttypes.h, which wouldn't
do that.  The patches below fix that too.

One more patch (also below) catches a similar problem with 32-bit
integer overflow that I noticed in image.c while I was fixing the
other problems.  It has no dependencies on the other patches.

Thanks for the review.

::::::::::::::
diff1
::::::::::::::
=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-03 19:02:25 +0000
+++ src/ChangeLog	2011-06-03 20:14:12 +0000
@@ -19,7 +19,8 @@
 	* undo.c (record_first_change): Use INTEGER_TO_CONS.
 	(Fprimitive_undo): Use CONS_TO_INTEGER.
 	* xfns.c (Fx_window_property): Likewise.
-	* xselect.c (x_own_selection, selection_data_to_lisp_data):
+	* xselect.c: Include <limits.h>.
+	(x_own_selection, selection_data_to_lisp_data):
 	Use INTEGER_TO_CONS.
 	(x_handle_selection_request, x_handle_selection_clear)
 	(x_get_foreign_selection, Fx_disown_selection_internal)

=== modified file 'src/xselect.c'
--- src/xselect.c	2011-06-03 19:02:25 +0000
+++ src/xselect.c	2011-06-03 20:14:12 +0000
@@ -20,6 +20,7 @@
 /* Rewritten by jwz */
 
 #include <config.h>
+#include <limits.h>
 #include <stdio.h>      /* termhooks.h needs this */
 #include <setjmp.h>
 

::::::::::::::
diff2
::::::::::::::
=== modified file 'doc/emacs/buffers.texi'
--- doc/emacs/buffers.texi	2011-06-03 18:47:14 +0000
+++ doc/emacs/buffers.texi	2011-06-03 23:21:13 +0000
@@ -43,8 +43,9 @@
   A buffer's size cannot be larger than some maximum, which is defined
 by the largest buffer position representable by the @dfn{Emacs
 integer} data type.  This is because Emacs tracks buffer positions
-using that data type.  For most machines, the maximum buffer size
+using that data type.  For 64-bit machines, the maximum buffer size
 enforced by the data types is @math{2^61 - 2} bytes, or about 2 EiB.
+For most 32-bit machines, the maximum is @math{2^31 - 1} bytes, or about 2 GiB.
 For some older machines, the maximum is @math{2^29 - 2} bytes, or
 about 512 MiB.  Buffer sizes are also limited by the size of Emacs's
 virtual memory.

::::::::::::::
diff3
::::::::::::::
=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-03 20:14:12 +0000
+++ src/ChangeLog	2011-06-04 02:02:36 +0000
@@ -1,3 +1,11 @@
+2011-06-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Use ptrdiff_t, not int, for sizes.
+	* image.c (slurp_file): Switch from int to ptrdiff_t.
+	All uses changed.
+	(slurp_file, svg_load): Check that file size fits in both
+	size_t (for malloc) and ptrdiff_t (for sanity and safety).
+
 2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Check for overflow when converting integer to cons and back.

=== modified file 'src/image.c'
--- src/image.c	2011-05-31 06:05:00 +0000
+++ src/image.c	2011-06-04 02:02:36 +0000
@@ -2112,9 +2112,6 @@
 			      File Handling
  ***********************************************************************/
 
-static unsigned char *slurp_file (char *, int *);
-
-
 /* Find image file FILE.  Look in data-directory/images, then
    x-bitmap-file-path.  Value is the encoded full name of the file
    found, or nil if not found.  */
@@ -2151,7 +2148,7 @@
    occurred.  *SIZE is set to the size of the file.  */
 
 static unsigned char *
-slurp_file (char *file, int *size)
+slurp_file (char *file, ptrdiff_t *size)
 {
   FILE *fp = NULL;
   unsigned char *buf = NULL;
@@ -2159,6 +2156,7 @@
 
   if (stat (file, &st) == 0
       && (fp = fopen (file, "rb")) != NULL
+      && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
       && (buf = (unsigned char *) xmalloc (st.st_size),
 	  fread (buf, 1, st.st_size, fp) == st.st_size))
     {
@@ -2814,7 +2812,7 @@
     {
       Lisp_Object file;
       unsigned char *contents;
-      int size;
+      ptrdiff_t size;
 
       file = x_find_image_file (file_name);
       if (!STRINGP (file))
@@ -4039,7 +4037,7 @@
     {
       Lisp_Object file;
       unsigned char *contents;
-      int size;
+      ptrdiff_t size;
 
       file = x_find_image_file (file_name);
       if (!STRINGP (file))
@@ -5021,6 +5019,7 @@
 
   if (stat (SDATA (file), &st) == 0
       && (fp = fopen (SDATA (file), "rb")) != NULL
+      && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
       && (buf = (char *) xmalloc (st.st_size),
 	  fread (buf, 1, st.st_size, fp) == st.st_size))
     {
@@ -5055,7 +5054,7 @@
   enum {PBM_MONO, PBM_GRAY, PBM_COLOR} type;
   unsigned char *contents = NULL;
   unsigned char *end, *p;
-  int size;
+  ptrdiff_t size;
 
   specified_file = image_spec_value (img->spec, QCfile, NULL);
 
@@ -7869,7 +7868,7 @@
 static int svg_load (struct frame *f, struct image *img);
 
 static int svg_load_image (struct frame *, struct image *,
-                           unsigned char *, unsigned int);
+                           unsigned char *, ptrdiff_t);
 
 /* The symbol `svg' identifying images of this type. */
 
@@ -8047,7 +8046,7 @@
     {
       Lisp_Object file;
       unsigned char *contents;
-      int size;
+      ptrdiff_t size;
 
       file = x_find_image_file (file_name);
       if (!STRINGP (file))
@@ -8074,7 +8073,7 @@
       Lisp_Object data;
 
       data = image_spec_value (img->spec, QCdata, NULL);
-      if (!STRINGP (data))
+      if (! (STRINGP (data) && SBYTES (data) <= min (PTRDIFF_MAX, SIZE_MAX)))
 	{
 	  image_error ("Invalid image data `%s'", data, Qnil);
 	  return 0;
@@ -8096,7 +8095,7 @@
 svg_load_image (struct frame *f,         /* Pointer to emacs frame structure.  */
 		struct image *img,       /* Pointer to emacs image structure.  */
 		unsigned char *contents, /* String containing the SVG XML data to be parsed.  */
-		unsigned int size)       /* Size of data in bytes.  */
+		ptrdiff_t size)          /* Size of data in bytes.  */
 {
   RsvgHandle *rsvg_handle;
   RsvgDimensionData dimension_data;

::::::::::::::
diff4
::::::::::::::
=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-04 02:02:36 +0000
+++ src/ChangeLog	2011-06-04 02:49:51 +0000
@@ -1,5 +1,20 @@
 2011-06-04  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Check for buffer and string overflow more precisely.
+	* buffer.h (BUF_BYTES_MAX): New macro.
+	* lisp.h (STRING_BYTES_MAX): New macro.
+	* alloc.c (Fmake_string):
+	* character.c (string_escape_byte8):
+	* coding.c (coding_alloc_by_realloc):
+	* doprnt.c (doprnt):
+	* editfns.c (Fformat):
+	* eval.c (verror):
+	Use STRING_BYTES_MAX, not MOST_POSITIVE_FIXNUM,
+	since they may not be the same number.
+	* editfns.c (Finsert_char):
+	* fileio.c (Finsert_file_contents):
+	Likewise for BUF_BYTES_MAX.
+
 	Use ptrdiff_t, not int, for sizes.
 	* image.c (slurp_file): Switch from int to ptrdiff_t.
 	All uses changed.

=== modified file 'src/alloc.c'
--- src/alloc.c	2011-06-02 08:35:28 +0000
+++ src/alloc.c	2011-06-04 02:49:51 +0000
@@ -2205,7 +2205,7 @@
       int len = CHAR_STRING (c, str);
       EMACS_INT string_len = XINT (length);
 
-      if (string_len > MOST_POSITIVE_FIXNUM / len)
+      if (string_len > STRING_BYTES_MAX / len)
 	string_overflow ();
       nbytes = len * string_len;
       val = make_uninit_multibyte_string (string_len, nbytes);

=== modified file 'src/buffer.h'
--- src/buffer.h	2011-06-02 06:15:15 +0000
+++ src/buffer.h	2011-06-04 02:49:51 +0000
@@ -306,6 +306,11 @@
   }								\
 while (0)
 
+/* Maximum number of bytes in a buffer.
+   A buffer cannot contain more bytes than a 1-origin fixnum can represent,
+   nor can it be so large that C pointer arithmetic stops working.  */
+#define BUF_BYTES_MAX min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
+
 /* Return the address of byte position N in current buffer.  */
 
 #define BYTE_POS_ADDR(n) \

=== modified file 'src/character.c'
--- src/character.c	2011-06-02 06:17:35 +0000
+++ src/character.c	2011-06-04 02:49:51 +0000
@@ -838,7 +838,7 @@
   if (multibyte)
     {
       if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count
-	  || (MOST_POSITIVE_FIXNUM - nbytes) / 2 < byte8_count)
+	  || (STRING_BYTES_MAX - nbytes) / 2 < byte8_count)
 	string_overflow ();
 
       /* Convert 2-byte sequence of byte8 chars to 4-byte octal.  */
@@ -847,7 +847,7 @@
     }
   else
     {
-      if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count)
+      if ((STRING_BYTES_MAX - nchars) / 3 < byte8_count)
 	string_overflow ();
 
       /* Convert 1-byte sequence of byte8 chars to 4-byte octal.  */

=== modified file 'src/coding.c'
--- src/coding.c	2011-05-30 01:12:12 +0000
+++ src/coding.c	2011-06-04 02:49:51 +0000
@@ -1071,8 +1071,8 @@
 static void
 coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes)
 {
-  if (coding->dst_bytes >= MOST_POSITIVE_FIXNUM - bytes)
-    error ("Maximum size of buffer or string exceeded");
+  if (STRING_BYTES_MAX - coding->dst_bytes < bytes)
+    string_overflow ();
   coding->destination = (unsigned char *) xrealloc (coding->destination,
 						    coding->dst_bytes + bytes);
   coding->dst_bytes += bytes;

=== modified file 'src/doprnt.c'
--- src/doprnt.c	2011-04-30 20:05:43 +0000
+++ src/doprnt.c	2011-06-04 02:49:51 +0000
@@ -329,7 +329,7 @@
 		minlen = atoi (&fmtcpy[1]);
 	      string = va_arg (ap, char *);
 	      tem = strlen (string);
-	      if (tem > MOST_POSITIVE_FIXNUM)
+	      if (tem > STRING_BYTES_MAX)
 		error ("String for %%s or %%S format is too long");
 	      width = strwidth (string, tem);
 	      goto doit1;
@@ -338,7 +338,7 @@
 	    doit:
 	      /* Coming here means STRING contains ASCII only.  */
 	      tem = strlen (string);
-	      if (tem > MOST_POSITIVE_FIXNUM)
+	      if (tem > STRING_BYTES_MAX)
 		error ("Format width or precision too large");
 	      width = tem;
 	    doit1:

=== modified file 'src/editfns.c'
--- src/editfns.c	2011-06-03 18:14:49 +0000
+++ src/editfns.c	2011-06-04 02:49:51 +0000
@@ -2341,7 +2341,7 @@
     len = CHAR_STRING (XFASTINT (character), str);
   else
     str[0] = XFASTINT (character), len = 1;
-  if (MOST_POSITIVE_FIXNUM / len < XINT (count))
+  if (BUF_BYTES_MAX / len < XINT (count))
     error ("Maximum buffer size would be exceeded");
   n = XINT (count) * len;
   if (n <= 0)
@@ -3588,7 +3588,7 @@
   char initial_buffer[4000];
   char *buf = initial_buffer;
   EMACS_INT bufsize = sizeof initial_buffer;
-  EMACS_INT max_bufsize = min (MOST_POSITIVE_FIXNUM + 1, SIZE_MAX);
+  EMACS_INT max_bufsize = STRING_BYTES_MAX + 1;
   char *p;
   Lisp_Object buf_save_value IF_LINT (= {0});
   register char *format, *end, *format_start;

=== modified file 'src/eval.c'
--- src/eval.c	2011-05-30 05:39:59 +0000
+++ src/eval.c	2011-06-04 02:49:51 +0000
@@ -1994,7 +1994,7 @@
 {
   char buf[4000];
   size_t size = sizeof buf;
-  size_t size_max = min (MOST_POSITIVE_FIXNUM + 1, SIZE_MAX);
+  size_t size_max = STRING_BYTES_MAX + 1;
   size_t mlen = strlen (m);
   char *buffer = buf;
   size_t used;

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-06-03 19:02:25 +0000
+++ src/fileio.c	2011-06-04 02:49:51 +0000
@@ -3248,7 +3248,7 @@
   /* Check whether the size is too large or negative, which can happen on a
      platform that allows file sizes greater than the maximum off_t value.  */
   if (! not_regular
-      && ! (0 <= st.st_size && st.st_size <= MOST_POSITIVE_FIXNUM))
+      && ! (0 <= st.st_size && st.st_size <= BUF_BYTES_MAX))
     error ("Maximum buffer size exceeded");
 
   /* Prevent redisplay optimizations.  */

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-03 19:02:25 +0000
+++ src/lisp.h	2011-06-04 02:49:51 +0000
@@ -766,6 +766,12 @@
 
 #endif /* not GC_CHECK_STRING_BYTES */
 
+/* A string cannot contain more bytes than a fixnum can represent,
+   nor can it be so long that C pointer arithmetic stops working on
+   the string plus a terminating null.  */
+#define STRING_BYTES_MAX  \
+  min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1)
+
 /* Mark STR as a unibyte string.  */
 #define STRING_SET_UNIBYTE(STR)  \
   do { if (EQ (STR, empty_multibyte_string))  \







^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-03 19:28   ` Paul Eggert
@ 2011-06-05 12:00     ` Stefan Monnier
  2011-06-06  8:39       ` Paul Eggert
                         ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Stefan Monnier @ 2011-06-05 12:00 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

> (a) straightforward fixes that I assume are uncontroversial
> (b) make 64bit-on-32bit the default (on 32bit systems that support it)
> (c) fix the cons<->int conversions

> Each part is a prerequisite for the next.

That's a problem for (c) because I don't want to install (b) for now.


        Stefan





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-05 12:00     ` Stefan Monnier
@ 2011-06-06  8:39       ` Paul Eggert
  2011-06-06 16:01         ` Stefan Monnier
  2011-06-06  8:39       ` bug#8794: (a) uncontroversial fixes (2011-06-06 version) Paul Eggert
  2011-06-06  8:39       ` bug#8794: (c) fix the cons<->int conversions " Paul Eggert
  2 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-06  8:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

On 06/05/11 05:00, Stefan Monnier wrote:
>> (a) straightforward fixes that I assume are uncontroversial
>> (b) make 64bit-on-32bit the default (on 32bit systems that support it)
>> (c) fix the cons<->int conversions
> 
>> Each part is a prerequisite for the next.
> 
> That's a problem for (c) because I don't want to install (b) for now.

OK, I have revamped (c) so that it does two conses
for large integers on 32-bit hosts; this removes its
dependency on (b).  I'll send the revised (c) in a followup email.
The uncontroversial changes (a) have some changes too, based on
later discussion with Eli, so I'll send a revised (a) too.

What else needs to be done before it's reasonable to install
something like (b)?





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (a) uncontroversial fixes (2011-06-06 version)
  2011-06-05 12:00     ` Stefan Monnier
  2011-06-06  8:39       ` Paul Eggert
@ 2011-06-06  8:39       ` Paul Eggert
  2011-06-06 17:17         ` Stefan Monnier
  2011-06-06  8:39       ` bug#8794: (c) fix the cons<->int conversions " Paul Eggert
  2 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-06  8:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: eggert@cs.ucla.edu-20110606061612-wzv4dvdtnh828yk3
# target_branch: bzr+ssh://eggert@bzr.savannah.gnu.org/emacs/trunk
# testament_sha1: c8b36cc2ea7b3f5a15360443ec4a0832655a629c
# timestamp: 2011-06-06 01:28:12 -0700
# base_revision_id: eggert@cs.ucla.edu-20110606045423-zu70kvdqb6987ptx
# 
# Begin patch
=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-06-06 04:54:23 +0000
+++ src/ChangeLog	2011-06-06 06:16:12 +0000
@@ -1,5 +1,52 @@
 2011-06-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Check for buffer and string overflow more precisely.
+	* buffer.h (BUF_BYTES_MAX): New macro.
+	* lisp.h (STRING_BYTES_MAX): New macro.
+	* alloc.c (Fmake_string):
+	* character.c (string_escape_byte8):
+	* coding.c (coding_alloc_by_realloc):
+	* doprnt.c (doprnt):
+	* editfns.c (Fformat):
+	* eval.c (verror):
+	Use STRING_BYTES_MAX, not MOST_POSITIVE_FIXNUM,
+	since they may not be the same number.
+	* editfns.c (Finsert_char):
+	* fileio.c (Finsert_file_contents):
+	Likewise for BUF_BYTES_MAX.
+
+	* image.c: Use ptrdiff_t, not int, for sizes.
+	(slurp_file): Switch from int to ptrdiff_t.
+	All uses changed.
+	(slurp_file): Check that file size fits in both size_t (for
+	malloc) and ptrdiff_t (for sanity and safety).
+
+	* fileio.c (Fverify_visited_file_modtime): Avoid time overflow
+	if b->modtime has its maximal value.
+
+	* dired.c (Ffile_attributes): Don't assume EMACS_INT has >32 bits.
+
+	Don't assume time_t can fit into int.
+	* buffer.h (struct buffer.modtime): Now time_t, not int.
+	* fileio.c (Fvisited_file_modtime): No need for time_t cast now.
+	* undo.c (Fprimitive_undo): Use time_t, not int, for time_t value.
+
+	Minor fixes for signed vs unsigned integers.
+	* character.h (MAYBE_UNIFY_CHAR):
+	* charset.c (maybe_unify_char):
+	* keyboard.c (read_char, reorder_modifiers):
+	XINT -> XFASTINT, since the integer must be nonnegative.
+	* ftfont.c (ftfont_spec_pattern):
+	* keymap.c (access_keymap, silly_event_symbol_error):
+	XUINT -> XFASTINT, since the integer must be nonnegative.
+	(Fsingle_key_description, preferred_sequence_p): XUINT -> XINT,
+	since it makes no difference and we prefer signed.
+	* keyboard.c (record_char): Use XUINT when all the neighbors do.
+	(access_keymap): NATNUMP -> INTEGERP, since the integer must be
+	nonnegative.
+
+2011-06-06  Paul Eggert  <eggert@cs.ucla.edu>
+
 	* alloc.c (memory_full) [SYSTEM_MALLOC]: Port to MacOS (Bug#8800).
 	Do not assume that spare memory exists; that assumption is valid
 	only if SYSTEM_MALLOC.

=== modified file 'src/alloc.c'
--- src/alloc.c	2011-06-06 04:54:23 +0000
+++ src/alloc.c	2011-06-06 06:16:12 +0000
@@ -2211,7 +2211,7 @@
       int len = CHAR_STRING (c, str);
       EMACS_INT string_len = XINT (length);
 
-      if (string_len > MOST_POSITIVE_FIXNUM / len)
+      if (string_len > STRING_BYTES_MAX / len)
 	string_overflow ();
       nbytes = len * string_len;
       val = make_uninit_multibyte_string (string_len, nbytes);

=== modified file 'src/buffer.h'
--- src/buffer.h	2011-05-12 07:07:06 +0000
+++ src/buffer.h	2011-06-06 06:16:12 +0000
@@ -306,6 +306,11 @@
   }								\
 while (0)
 
+/* Maximum number of bytes in a buffer.
+   A buffer cannot contain more bytes than a 1-origin fixnum can represent,
+   nor can it be so large that C pointer arithmetic stops working.  */
+#define BUF_BYTES_MAX min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
+
 /* Return the address of byte position N in current buffer.  */
 
 #define BYTE_POS_ADDR(n) \
@@ -545,7 +550,7 @@
      -1 means visited file was nonexistent.
      0 means visited file modtime unknown; in no case complain
      about any mismatch on next save attempt.  */
-  int modtime;
+  time_t modtime;
   /* Size of the file when modtime was set.  This is used to detect the
      case where the file grew while we were reading it, so the modtime
      is still the same (since it's rounded up to seconds) but we're actually

=== modified file 'src/character.c'
--- src/character.c	2011-05-21 04:33:23 +0000
+++ src/character.c	2011-06-06 06:16:12 +0000
@@ -838,7 +838,7 @@
   if (multibyte)
     {
       if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count
-	  || (MOST_POSITIVE_FIXNUM - nbytes) / 2 < byte8_count)
+	  || (STRING_BYTES_MAX - nbytes) / 2 < byte8_count)
 	string_overflow ();
 
       /* Convert 2-byte sequence of byte8 chars to 4-byte octal.  */
@@ -847,7 +847,7 @@
     }
   else
     {
-      if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count)
+      if ((STRING_BYTES_MAX - nchars) / 3 < byte8_count)
 	string_overflow ();
 
       /* Convert 1-byte sequence of byte8 chars to 4-byte octal.  */

=== modified file 'src/character.h'
--- src/character.h	2011-05-21 04:33:23 +0000
+++ src/character.h	2011-06-01 02:49:12 +0000
@@ -544,7 +544,7 @@
 	Lisp_Object val;				\
 	val = CHAR_TABLE_REF (Vchar_unify_table, c);	\
 	if (INTEGERP (val))				\
-	  c = XINT (val);				\
+	  c = XFASTINT (val);				\
 	else if (! NILP (val))				\
 	  c = maybe_unify_char (c, val);		\
       }							\

=== modified file 'src/charset.c'
--- src/charset.c	2011-05-31 06:05:00 +0000
+++ src/charset.c	2011-06-03 18:11:17 +0000
@@ -1637,7 +1637,7 @@
   struct charset *charset;
 
   if (INTEGERP (val))
-    return XINT (val);
+    return XFASTINT (val);
   if (NILP (val))
     return c;
 
@@ -1647,7 +1647,7 @@
     {
       val = CHAR_TABLE_REF (Vchar_unify_table, c);
       if (! NILP (val))
-	c = XINT (val);
+	c = XFASTINT (val);
     }
   else
     {

=== modified file 'src/coding.c'
--- src/coding.c	2011-05-30 01:12:12 +0000
+++ src/coding.c	2011-06-06 06:16:12 +0000
@@ -1071,8 +1071,8 @@
 static void
 coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes)
 {
-  if (coding->dst_bytes >= MOST_POSITIVE_FIXNUM - bytes)
-    error ("Maximum size of buffer or string exceeded");
+  if (STRING_BYTES_MAX - coding->dst_bytes < bytes)
+    string_overflow ();
   coding->destination = (unsigned char *) xrealloc (coding->destination,
 						    coding->dst_bytes + bytes);
   coding->dst_bytes += bytes;

=== modified file 'src/dired.c'
--- src/dired.c	2011-04-14 19:34:42 +0000
+++ src/dired.c	2011-06-06 05:55:38 +0000
@@ -1013,12 +1013,11 @@
 	 The code on the next line avoids a compiler warning on
 	 systems where st_ino is 32 bit wide. (bug#766).  */
       EMACS_INT high_ino = s.st_ino >> 31 >> 1;
-      EMACS_INT low_ino  = s.st_ino & 0xffffffff;
 
       values[10] = Fcons (make_number (high_ino >> 8),
 			  Fcons (make_number (((high_ino & 0xff) << 16)
-					      + (low_ino >> 16)),
-				 make_number (low_ino & 0xffff)));
+					      + (s.st_ino >> 16 & 0xffff)),
+				 make_number (s.st_ino & 0xffff)));
     }
 
   /* Likewise for device.  */

=== modified file 'src/doprnt.c'
--- src/doprnt.c	2011-04-30 20:05:43 +0000
+++ src/doprnt.c	2011-06-06 06:16:12 +0000
@@ -329,7 +329,7 @@
 		minlen = atoi (&fmtcpy[1]);
 	      string = va_arg (ap, char *);
 	      tem = strlen (string);
-	      if (tem > MOST_POSITIVE_FIXNUM)
+	      if (tem > STRING_BYTES_MAX)
 		error ("String for %%s or %%S format is too long");
 	      width = strwidth (string, tem);
 	      goto doit1;
@@ -338,7 +338,7 @@
 	    doit:
 	      /* Coming here means STRING contains ASCII only.  */
 	      tem = strlen (string);
-	      if (tem > MOST_POSITIVE_FIXNUM)
+	      if (tem > STRING_BYTES_MAX)
 		error ("Format width or precision too large");
 	      width = tem;
 	    doit1:

=== modified file 'src/editfns.c'
--- src/editfns.c	2011-06-05 22:46:26 +0000
+++ src/editfns.c	2011-06-06 06:16:12 +0000
@@ -2342,7 +2342,7 @@
     len = CHAR_STRING (XFASTINT (character), str);
   else
     str[0] = XFASTINT (character), len = 1;
-  if (MOST_POSITIVE_FIXNUM / len < XINT (count))
+  if (BUF_BYTES_MAX / len < XINT (count))
     error ("Maximum buffer size would be exceeded");
   n = XINT (count) * len;
   if (n <= 0)
@@ -3589,7 +3589,7 @@
   char initial_buffer[4000];
   char *buf = initial_buffer;
   EMACS_INT bufsize = sizeof initial_buffer;
-  EMACS_INT max_bufsize = min (MOST_POSITIVE_FIXNUM + 1, SIZE_MAX);
+  EMACS_INT max_bufsize = STRING_BYTES_MAX + 1;
   char *p;
   Lisp_Object buf_save_value IF_LINT (= {0});
   register char *format, *end, *format_start;

=== modified file 'src/eval.c'
--- src/eval.c	2011-05-30 05:39:59 +0000
+++ src/eval.c	2011-06-06 06:16:12 +0000
@@ -1994,7 +1994,7 @@
 {
   char buf[4000];
   size_t size = sizeof buf;
-  size_t size_max = min (MOST_POSITIVE_FIXNUM + 1, SIZE_MAX);
+  size_t size_max = STRING_BYTES_MAX + 1;
   size_t mlen = strlen (m);
   char *buffer = buf;
   size_t used;

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-04-29 19:47:29 +0000
+++ src/fileio.c	2011-06-06 06:16:12 +0000
@@ -3248,7 +3248,7 @@
   /* Check whether the size is too large or negative, which can happen on a
      platform that allows file sizes greater than the maximum off_t value.  */
   if (! not_regular
-      && ! (0 <= st.st_size && st.st_size <= MOST_POSITIVE_FIXNUM))
+      && ! (0 <= st.st_size && st.st_size <= BUF_BYTES_MAX))
     error ("Maximum buffer size exceeded");
 
   /* Prevent redisplay optimizations.  */
@@ -4960,7 +4960,7 @@
   if ((st.st_mtime == b->modtime
        /* If both are positive, accept them if they are off by one second.  */
        || (st.st_mtime > 0 && b->modtime > 0
-	   && (st.st_mtime == b->modtime + 1
+	   && (st.st_mtime - 1 == b->modtime
 	       || st.st_mtime == b->modtime - 1)))
       && (st.st_size == b->modtime_size
           || b->modtime_size < 0))
@@ -4990,7 +4990,7 @@
 {
   if (! current_buffer->modtime)
     return make_number (0);
-  return make_time ((time_t) current_buffer->modtime);
+  return make_time (current_buffer->modtime);
 }
 
 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime,

=== modified file 'src/ftfont.c'
--- src/ftfont.c	2011-04-11 03:39:45 +0000
+++ src/ftfont.c	2011-06-01 02:49:12 +0000
@@ -815,7 +815,7 @@
 	    goto err;
 	  for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars))
 	    if (CHARACTERP (XCAR (chars))
-		&& ! FcCharSetAddChar (charset, XUINT (XCAR (chars))))
+		&& ! FcCharSetAddChar (charset, XFASTINT (XCAR (chars))))
 	      goto err;
 	}
     }

=== modified file 'src/image.c'
--- src/image.c	2011-05-31 06:05:00 +0000
+++ src/image.c	2011-06-06 06:10:06 +0000
@@ -2112,9 +2112,6 @@
 			      File Handling
  ***********************************************************************/
 
-static unsigned char *slurp_file (char *, int *);
-
-
 /* Find image file FILE.  Look in data-directory/images, then
    x-bitmap-file-path.  Value is the encoded full name of the file
    found, or nil if not found.  */
@@ -2151,7 +2148,7 @@
    occurred.  *SIZE is set to the size of the file.  */
 
 static unsigned char *
-slurp_file (char *file, int *size)
+slurp_file (char *file, ptrdiff_t *size)
 {
   FILE *fp = NULL;
   unsigned char *buf = NULL;
@@ -2159,6 +2156,7 @@
 
   if (stat (file, &st) == 0
       && (fp = fopen (file, "rb")) != NULL
+      && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
       && (buf = (unsigned char *) xmalloc (st.st_size),
 	  fread (buf, 1, st.st_size, fp) == st.st_size))
     {
@@ -2814,7 +2812,7 @@
     {
       Lisp_Object file;
       unsigned char *contents;
-      int size;
+      ptrdiff_t size;
 
       file = x_find_image_file (file_name);
       if (!STRINGP (file))
@@ -4039,7 +4037,7 @@
     {
       Lisp_Object file;
       unsigned char *contents;
-      int size;
+      ptrdiff_t size;
 
       file = x_find_image_file (file_name);
       if (!STRINGP (file))
@@ -5021,6 +5019,7 @@
 
   if (stat (SDATA (file), &st) == 0
       && (fp = fopen (SDATA (file), "rb")) != NULL
+      && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
       && (buf = (char *) xmalloc (st.st_size),
 	  fread (buf, 1, st.st_size, fp) == st.st_size))
     {
@@ -5055,7 +5054,7 @@
   enum {PBM_MONO, PBM_GRAY, PBM_COLOR} type;
   unsigned char *contents = NULL;
   unsigned char *end, *p;
-  int size;
+  ptrdiff_t size;
 
   specified_file = image_spec_value (img->spec, QCfile, NULL);
 
@@ -7869,7 +7868,7 @@
 static int svg_load (struct frame *f, struct image *img);
 
 static int svg_load_image (struct frame *, struct image *,
-                           unsigned char *, unsigned int);
+                           unsigned char *, ptrdiff_t);
 
 /* The symbol `svg' identifying images of this type. */
 
@@ -8047,7 +8046,7 @@
     {
       Lisp_Object file;
       unsigned char *contents;
-      int size;
+      ptrdiff_t size;
 
       file = x_find_image_file (file_name);
       if (!STRINGP (file))
@@ -8096,7 +8095,7 @@
 svg_load_image (struct frame *f,         /* Pointer to emacs frame structure.  */
 		struct image *img,       /* Pointer to emacs image structure.  */
 		unsigned char *contents, /* String containing the SVG XML data to be parsed.  */
-		unsigned int size)       /* Size of data in bytes.  */
+		ptrdiff_t size)          /* Size of data in bytes.  */
 {
   RsvgHandle *rsvg_handle;
   RsvgDimensionData dimension_data;

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2011-06-04 07:41:44 +0000
+++ src/keyboard.c	2011-06-06 05:48:28 +0000
@@ -2395,8 +2395,8 @@
 
       c = Faref (Vexecuting_kbd_macro, make_number (executing_kbd_macro_index));
       if (STRINGP (Vexecuting_kbd_macro)
-	  && (XINT (c) & 0x80) && (XUINT (c) <= 0xff))
-	XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80));
+	  && (XFASTINT (c) & 0x80) && (XFASTINT (c) <= 0xff))
+	XSETFASTINT (c, CHAR_META | (XFASTINT (c) & ~0x80));
 
       executing_kbd_macro_index++;
 
@@ -3321,7 +3321,7 @@
       if (INTEGERP (c))
 	{
 	  if (XUINT (c) < 0x100)
-	    putc (XINT (c), dribble);
+	    putc (XUINT (c), dribble);
 	  else
 	    fprintf (dribble, " 0x%"pI"x", XUINT (c));
 	}
@@ -6370,7 +6370,7 @@
   Lisp_Object parsed;
 
   parsed = parse_modifiers (symbol);
-  return apply_modifiers ((int) XINT (XCAR (XCDR (parsed))),
+  return apply_modifiers (XFASTINT (XCAR (XCDR (parsed))),
 			  XCAR (parsed));
 }
 

=== modified file 'src/keymap.c'
--- src/keymap.c	2011-05-12 07:07:06 +0000
+++ src/keymap.c	2011-06-01 02:49:12 +0000
@@ -462,7 +462,7 @@
     XSETFASTINT (idx, XINT (idx) & (CHAR_META | (CHAR_META - 1)));
 
   /* Handle the special meta -> esc mapping. */
-  if (INTEGERP (idx) && XUINT (idx) & meta_modifier)
+  if (INTEGERP (idx) && XFASTINT (idx) & meta_modifier)
     {
       /* See if there is a meta-map.  If there's none, there is
          no binding for IDX, unless a default binding exists in MAP.  */
@@ -480,7 +480,7 @@
       if (CONSP (event_meta_map))
 	{
 	  map = event_meta_map;
-	  idx = make_number (XUINT (idx) & ~meta_modifier);
+	  idx = make_number (XFASTINT (idx) & ~meta_modifier);
 	}
       else if (t_ok)
 	/* Set IDX to t, so that we only find a default binding.  */
@@ -529,7 +529,7 @@
 	  }
 	else if (VECTORP (binding))
 	  {
-	    if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (binding))
+	    if (INTEGERP (idx) && XFASTINT (idx) < ASIZE (binding))
 	      val = AREF (binding, XFASTINT (idx));
 	  }
 	else if (CHAR_TABLE_P (binding))
@@ -537,7 +537,7 @@
 	    /* Character codes with modifiers
 	       are not included in a char-table.
 	       All character codes without modifiers are included.  */
-	    if (NATNUMP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0)
+	    if (INTEGERP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0)
 	      {
 		val = Faref (binding, idx);
 		/* `nil' has a special meaning for char-tables, so
@@ -1357,7 +1357,7 @@
   int modifiers;
 
   parsed = parse_modifiers (c);
-  modifiers = (int) XUINT (XCAR (XCDR (parsed)));
+  modifiers = XFASTINT (XCAR (XCDR (parsed)));
   base = XCAR (parsed);
   name = Fsymbol_name (base);
   /* This alist includes elements such as ("RET" . "\\r").  */
@@ -2416,7 +2416,7 @@
     {
       char tem[KEY_DESCRIPTION_SIZE];
 
-      *push_key_description (XUINT (key), tem, 1) = 0;
+      *push_key_description (XINT (key), tem, 1) = 0;
       return build_string (tem);
     }
   else if (SYMBOLP (key))	/* Function key or event-symbol */
@@ -2515,7 +2515,7 @@
 	return 0;
       else
 	{
-	  int modifiers = XUINT (elt) & (CHAR_MODIFIER_MASK & ~CHAR_META);
+	  int modifiers = XINT (elt) & (CHAR_MODIFIER_MASK & ~CHAR_META);
 	  if (modifiers == where_is_preferred_modifier)
 	    result = 2;
 	  else if (modifiers)

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-02 08:25:28 +0000
+++ src/lisp.h	2011-06-06 06:16:12 +0000
@@ -763,6 +763,12 @@
 
 #endif /* not GC_CHECK_STRING_BYTES */
 
+/* A string cannot contain more bytes than a fixnum can represent,
+   nor can it be so long that C pointer arithmetic stops working on
+   the string plus a terminating null.  */
+#define STRING_BYTES_MAX  \
+  min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1)
+
 /* Mark STR as a unibyte string.  */
 #define STRING_SET_UNIBYTE(STR)  \
   do { if (EQ (STR, empty_multibyte_string))  \

=== modified file 'src/undo.c'
--- src/undo.c	2011-04-14 05:04:02 +0000
+++ src/undo.c	2011-06-02 06:15:15 +0000
@@ -500,7 +500,7 @@
 		{
 		  /* Element (t high . low) records previous modtime.  */
 		  Lisp_Object high, low;
-		  int mod_time;
+		  time_t mod_time;
 		  struct buffer *base_buffer = current_buffer;
 
 		  high = Fcar (cdr);

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWZWt1eoAJRF/gHEwAIB5////
f+/fdL////VgKT73XpSXbud2Q999AbvW+33n3k9533fL75zZRqzCtdHt3AAvY0OgOmugOtsAAd2A
LsCPuI+4Drrd4uHriIQg7ue96b3j2572j3DPQpQ6y1kqqAN5gqqXYDtgMJKJknojJ6mJimI1N6TS
ntNUP1TAA9UBkBkwjZNBKEAAgRAIIxGihp6g0AA9QAABoNMgJJNI8iGKNNMQGmmgAAAaNAAAEmpB
BEGRKbaepppIND0jQ0BoD9U0BoNAACJJI00Uep6TEj09JmiMo/ST9TypjUMTTJoANAA0CpIhGQTI
DRGE00aI0yVPxHqNU9IDTE0BkMJnxfUcQvHbMkiMQy80FqSKhIcOnShIHhJ76lkpN6N7Us9hWqdT
r/n+v7O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urYgwniJMIITMhJ8SbkF0lx6xM1io0+y
x6GKejzXOMbzLAbjYTCiSO9MHss8ifUlkkao5hWqsVct7fdloYI+ca1uOLtndaRNfpKOM0k0OdNP
0zm7InQmkUTsRsL0n7EqbjgtColESS2yPmSxDXhTFquuUmTAlE+GG5RgurKjVVKr2SW8DlCEJ6sE
Ok5Shr7ViUeaMXdUH9ydik2rLusx3nOzINp9NiqRVIKCyCrFFcEAwmkT5eEsS1vmbCQyThk9ai6C
k4oeSCgsixQWLFBYsUdfQFzWGQ+PkSvug5TpI9ifOdRLGzYm76w1Eu65ElG5lPhR6pHtTKpidxUb
LEp5P9UxJ0ljkGgFGRIXAt0cgkoQT0JlbUdiNCQWQZBoJCMCGJedoE6HxA+TIE3kRNeWu5ZBaYoK
SkFhjisMCde19DUSyYwdDqscSe0l6NSa1XIOJLNcngToYyJd9kOYmHM4E7uroszVIvVkjsE1/GKJ
sMROcydUSSxDKJSc66ON7GOouptsiSxM0+W+ckbIxXXENsQSkk1H12JGPPG526w5utFu+IicDJN/
1PxSOUTZPXpDjgSnKo4ptTkFwYedkgR7no1KGdVo5mPLKQTKwT8rhBYAeJV3+FB1PdTMPGLyOwUG
JpAevUDUC83kPV1x+La8UXySD2MT16ydqP3a+eNaM5RSO5XTN3b90Pf6bpofL2WNr+j9nek1JCfI
Mmf5E4E8Z0I9qQn80mM6mAmzEcfD8MYm7tP2RtfIm1s6vRq84xMZ23ceQR7dTQl2pV1ydCies/hz
mUYx2rvT8poZJOCOL+HkSwnQGMk3HQ2yPk5Ps1o3+CRqRs9i6HJwonJUSNj5uOPAl+9DmHsEoMXZ
zo+ou5IpwoSErW6vUA==





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (c) fix the cons<->int conversions (2011-06-06 version)
  2011-06-05 12:00     ` Stefan Monnier
  2011-06-06  8:39       ` Paul Eggert
  2011-06-06  8:39       ` bug#8794: (a) uncontroversial fixes (2011-06-06 version) Paul Eggert
@ 2011-06-06  8:39       ` Paul Eggert
  2011-06-06 17:18         ` Stefan Monnier
  2 siblings, 1 reply; 21+ messages in thread
From: Paul Eggert @ 2011-06-06  8:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

Check for overflow when converting integer to cons and back.
* charset.c (Fdefine_charset_internal, Fdecode_char):
Use cons_to_unsigned to catch overflow.
(Fencode_char): Use INTEGER_TO_CONS.
* composite.h (LGLYPH_CODE): Use cons_to_unsigned.
(LGLYPH_SET_CODE): Use INTEGER_TO_CONS.
* data.c (long_to_cons, cons_to_long): Remove.
(cons_to_unsigned, cons_to_signed): New functions.
These signal an error for invalid or out-of-range values.
* dired.c (Ffile_attributes): Use INTEGER_TO_CONS.
* fileio.c (Fset_visited_file_modtime): Use CONS_TO_INTEGER.
* font.c (Ffont_variation_glyphs):
* fontset.c (Finternal_char_font): Use INTEGER_TO_CONS.
* lisp.h: Include <intprops.h>.
(INTEGER_TO_CONS, CONS_TO_INTEGER): New macros.
(cons_to_signed, cons_to_unsigned): New decls.
(long_to_cons, cons_to_long): Remove decls.
* undo.c (record_first_change): Use INTEGER_TO_CONS.
(Fprimitive_undo): Use CONS_TO_INTEGER.
* xfns.c (Fx_window_property): Likewise.
* xselect.c: Include <limits.h>.
(x_own_selection, selection_data_to_lisp_data):
Use INTEGER_TO_CONS.
(x_handle_selection_request, x_handle_selection_clear)
(x_get_foreign_selection, Fx_disown_selection_internal)
(Fx_get_atom_name, x_send_client_event): Use CONS_TO_INTEGER.
(lisp_data_to_selection_data): Use cons_to_unsigned.
(x_fill_property_data): Use cons_to_signed.
Report values out of range.
=== modified file 'src/charset.c'
--- src/charset.c	2011-06-03 18:11:17 +0000
+++ src/charset.c	2011-06-06 06:19:52 +0000
@@ -932,17 +932,8 @@
   val = args[charset_arg_min_code];
   if (! NILP (val))
     {
-      unsigned code;
+      unsigned code = cons_to_unsigned (val, UINT_MAX);

-      if (INTEGERP (val))
-	code = XINT (val);
-      else
-	{
-	  CHECK_CONS (val);
-	  CHECK_NUMBER_CAR (val);
-	  CHECK_NUMBER_CDR (val);
-	  code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
-	}
       if (code < charset.min_code
 	  || code > charset.max_code)
 	args_out_of_range_3 (make_number (charset.min_code),
@@ -954,17 +945,8 @@
   val = args[charset_arg_max_code];
   if (! NILP (val))
     {
-      unsigned code;
+      unsigned code = cons_to_unsigned (val, UINT_MAX);

-      if (INTEGERP (val))
-	code = XINT (val);
-      else
-	{
-	  CHECK_CONS (val);
-	  CHECK_NUMBER_CAR (val);
-	  CHECK_NUMBER_CDR (val);
-	  code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
-	}
       if (code < charset.min_code
 	  || code > charset.max_code)
 	args_out_of_range_3 (make_number (charset.min_code),
@@ -1865,17 +1847,7 @@
   struct charset *charsetp;

   CHECK_CHARSET_GET_ID (charset, id);
-  if (CONSP (code_point))
-    {
-      CHECK_NATNUM_CAR (code_point);
-      CHECK_NATNUM_CDR (code_point);
-      code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
-    }
-  else
-    {
-      CHECK_NATNUM (code_point);
-      code = XINT (code_point);
-    }
+  code = cons_to_unsigned (code_point, UINT_MAX);
   charsetp = CHARSET_FROM_ID (id);
   c = DECODE_CHAR (charsetp, code);
   return (c >= 0 ? make_number (c) : Qnil);
@@ -1900,9 +1872,7 @@
   code = ENCODE_CHAR (charsetp, XINT (ch));
   if (code == CHARSET_INVALID_CODE (charsetp))
     return Qnil;
-  if (code > 0x7FFFFFF)
-    return Fcons (make_number (code >> 16), make_number (code & 0xFFFF));
-  return make_number (code);
+  return INTEGER_TO_CONS (code);
 }



=== modified file 'src/composite.h'
--- src/composite.h	2011-05-31 06:05:00 +0000
+++ src/composite.h	2011-06-06 06:19:52 +0000
@@ -265,10 +265,7 @@
 #define LGLYPH_CODE(g)						\
   (NILP (AREF ((g), LGLYPH_IX_CODE))				\
    ? FONT_INVALID_CODE						\
-   : CONSP (AREF ((g), LGLYPH_IX_CODE))				\
-   ? ((XFASTINT (XCAR (AREF ((g), LGLYPH_IX_CODE))) << 16)	\
-      | (XFASTINT (XCDR (AREF ((g), LGLYPH_IX_CODE)))))		\
-   : XFASTINT (AREF ((g), LGLYPH_IX_CODE)))
+   : cons_to_unsigned (AREF (g, LGLYPH_IX_CODE), TYPE_MAXIMUM (unsigned)))
 #define LGLYPH_WIDTH(g) XINT (AREF ((g), LGLYPH_IX_WIDTH))
 #define LGLYPH_LBEARING(g) XINT (AREF ((g), LGLYPH_IX_LBEARING))
 #define LGLYPH_RBEARING(g) XINT (AREF ((g), LGLYPH_IX_RBEARING))
@@ -280,15 +277,8 @@
 #define LGLYPH_SET_CHAR(g, val) ASET ((g), LGLYPH_IX_CHAR, make_number (val))
 /* Callers must assure that VAL is not negative!  */
 #define LGLYPH_SET_CODE(g, val)						\
-  do {									\
-    if (val == FONT_INVALID_CODE)					\
-      ASET ((g), LGLYPH_IX_CODE, Qnil);					\
-    else if ((EMACS_INT)val > MOST_POSITIVE_FIXNUM)			\
-      ASET ((g), LGLYPH_IX_CODE, Fcons (make_number ((val) >> 16),	\
-					make_number ((val) & 0xFFFF)));	\
-    else								\
-      ASET ((g), LGLYPH_IX_CODE, make_number (val));			\
-  } while (0)
+  ASET (g, LGLYPH_IX_CODE,						\
+	val == FONT_INVALID_CODE ? Qnil : INTEGER_TO_CONS (val))

 #define LGLYPH_SET_WIDTH(g, val) ASET ((g), LGLYPH_IX_WIDTH, make_number (val))
 #define LGLYPH_SET_LBEARING(g, val) ASET ((g), LGLYPH_IX_LBEARING, make_number (val))

=== modified file 'src/data.c'
--- src/data.c	2011-05-31 14:57:53 +0000
+++ src/data.c	2011-06-06 08:16:15 +0000
@@ -2326,33 +2326,110 @@
   return Qnil;
 }
 \f
-/* Convert between long values and pairs of Lisp integers.
-   Note that long_to_cons returns a single Lisp integer
-   when the value fits in one.  */
+/* Convert the cons-of-integers, integer, or float value C to an
+   unsigned value with maximum value MAX.  Signal an error if C does not
+   have a valid format or is out of range.  */
+uintmax_t
+cons_to_unsigned (Lisp_Object c, uintmax_t max)
+{
+  int valid = 0;
+  uintmax_t val IF_LINT (= 0);
+  if (INTEGERP (c))
+    {
+      valid = 0 <= XINT (c);
+      val = XINT (c);
+    }
+  else if (FLOATP (c))
+    {
+      double d = XFLOAT_DATA (c);
+      if (0 <= d
+	  && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
+	{
+	  val = d;
+	  valid = 1;
+	}
+    }
+  else if (CONSP (c) && NATNUMP (XCAR (c)))
+    {
+      uintmax_t top = XFASTINT (XCAR (c));
+      Lisp_Object rest = XCDR (c);
+      if (top <= UINTMAX_MAX >> 24 >> 16
+	  && CONSP (rest)
+	  && NATNUMP (XCAR (rest)) && XFASTINT (XCAR (rest)) < 1 << 24
+	  && NATNUMP (XCDR (rest)) && XFASTINT (XCDR (rest)) < 1 << 16)
+	{
+	  uintmax_t mid = XFASTINT (XCAR (rest));
+	  val = top << 24 << 16 | mid << 16 | XFASTINT (XCDR (rest));
+	  valid = 1;
+	}
+      else if (top <= UINTMAX_MAX >> 16)
+	{
+	  if (CONSP (rest))
+	    rest = XCAR (rest);
+	  if (NATNUMP (rest) && XFASTINT (rest) < 1 << 16)
+	    {
+	      val = top << 16 | XFASTINT (rest);
+	      valid = 1;
+	    }
+	}
+    }

-Lisp_Object
-long_to_cons (long unsigned int i)
-{
-  unsigned long top = i >> 16;
-  unsigned int bot = i & 0xFFFF;
-  if (top == 0)
-    return make_number (bot);
-  if (top == (unsigned long)-1 >> 16)
-    return Fcons (make_number (-1), make_number (bot));
-  return Fcons (make_number (top), make_number (bot));
+  if (! (valid && val <= max))
+    error ("Not an in-range integer, float, or cons of integers");
+  return val;
 }

-unsigned long
-cons_to_long (Lisp_Object c)
+/* Convert the cons-of-integers, integer, or float value C to a signed
+   value with extrema MIN and MAX.  Signal an error if C does not have
+   a valid format or is out of range.  */
+intmax_t
+cons_to_signed (Lisp_Object c, intmax_t min, intmax_t max)
 {
-  Lisp_Object top, bot;
+  int valid = 0;
+  intmax_t val IF_LINT (= 0);
   if (INTEGERP (c))
-    return XINT (c);
-  top = XCAR (c);
-  bot = XCDR (c);
-  if (CONSP (bot))
-    bot = XCAR (bot);
-  return ((XINT (top) << 16) | XINT (bot));
+    {
+      val = XINT (c);
+      valid = 1;
+    }
+  else if (FLOATP (c))
+    {
+      double d = XFLOAT_DATA (c);
+      if (min <= d
+	  && d < (max == INTMAX_MAX ? (double) INTMAX_MAX + 1 : max + 1))
+	{
+	  val = d;
+	  valid = 1;
+	}
+    }
+  else if (CONSP (c) && INTEGERP (XCAR (c)))
+    {
+      intmax_t top = XINT (XCAR (c));
+      Lisp_Object rest = XCDR (c);
+      if (INTMAX_MIN >> 24 >> 16 <= top && top <= INTMAX_MAX >> 24 >> 16
+	  && CONSP (rest)
+	  && NATNUMP (XCAR (rest)) && XFASTINT (XCAR (rest)) < 1 << 24
+	  && NATNUMP (XCDR (rest)) && XFASTINT (XCDR (rest)) < 1 << 16)
+	{
+	  intmax_t mid = XFASTINT (XCAR (rest));
+	  val = top << 24 << 16 | mid << 16 | XFASTINT (XCDR (rest));
+	  valid = 1;
+	}
+      else if (INTMAX_MIN >> 16 <= top && top <= INTMAX_MAX >> 16)
+	{
+	  if (CONSP (rest))
+	    rest = XCAR (rest);
+	  if (NATNUMP (rest) && XFASTINT (rest) < 1 << 16)
+	    {
+	      val = top << 16 | XFASTINT (rest);
+	      valid = 1;
+	    }
+	}
+    }
+
+  if (! (valid && min <= val && val <= max))
+    error ("Not an in-range integer, float, or cons of integers");
+  return val;
 }
 \f
 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,

=== modified file 'src/dired.c'
--- src/dired.c	2011-06-06 05:55:38 +0000
+++ src/dired.c	2011-06-06 06:26:32 +0000
@@ -900,11 +900,10 @@
   This is a floating point number if the size is too large for an integer.
  8. File modes, as a string of ten letters or dashes as in ls -l.
  9. t if file's gid would change if file were deleted and recreated.
-10. inode number.  If inode number is larger than what Emacs integer
-  can hold, but still fits into a 32-bit number, this is a cons cell
-  containing two integers: first the high part, then the low 16 bits.
-  If the inode number is wider than 32 bits, this is of the form
-  (HIGH MIDDLE . LOW): first the high 24 bits, then middle 24 bits,
+10. inode number.  If it is larger than what an Emacs integer can hold,
+  this is of the form (HIGH . LOW): first the high bits, then the low 16 bits.
+  If even HIGH is too large for an Emacs integer, this is instead of the form
+  (HIGH MIDDLE . LOW): first the high bits, then the middle 24 bits,
   and finally the low 16 bits.
 11. Filesystem device number.  If it is larger than what the Emacs
   integer can hold, this is a cons cell, similar to the inode number.
@@ -998,34 +997,8 @@
 #else					/* file gid will be egid */
   values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
 #endif	/* not BSD4_2 */
-  if (!FIXNUM_OVERFLOW_P (s.st_ino))
-    /* Keep the most common cases as integers.  */
-    values[10] = make_number (s.st_ino);
-  else if (!FIXNUM_OVERFLOW_P (s.st_ino >> 16))
-    /* To allow inode numbers larger than VALBITS, separate the bottom
-       16 bits.  */
-    values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)),
-			make_number ((EMACS_INT)(s.st_ino & 0xffff)));
-  else
-    {
-      /* To allow inode numbers beyond 32 bits, separate into 2 24-bit
-	 high parts and a 16-bit bottom part.
-	 The code on the next line avoids a compiler warning on
-	 systems where st_ino is 32 bit wide. (bug#766).  */
-      EMACS_INT high_ino = s.st_ino >> 31 >> 1;
-
-      values[10] = Fcons (make_number (high_ino >> 8),
-			  Fcons (make_number (((high_ino & 0xff) << 16)
-					      + (s.st_ino >> 16 & 0xffff)),
-				 make_number (s.st_ino & 0xffff)));
-    }
-
-  /* Likewise for device.  */
-  if (FIXNUM_OVERFLOW_P (s.st_dev))
-    values[11] = Fcons (make_number (s.st_dev >> 16),
-			make_number (s.st_dev & 0xffff));
-  else
-    values[11] = make_number (s.st_dev);
+  values[10] = INTEGER_TO_CONS (s.st_ino);
+  values[11] = INTEGER_TO_CONS (s.st_dev);

   return Flist (sizeof(values) / sizeof(values[0]), values);
 }

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-06-06 06:16:12 +0000
+++ src/fileio.c	2011-06-06 06:19:52 +0000
@@ -5005,7 +5005,7 @@
 {
   if (!NILP (time_list))
     {
-      current_buffer->modtime = cons_to_long (time_list);
+      CONS_TO_INTEGER (time_list, time_t, current_buffer->modtime);
       current_buffer->modtime_size = -1;
     }
   else

=== modified file 'src/font.c'
--- src/font.c	2011-05-29 19:04:01 +0000
+++ src/font.c	2011-06-06 06:19:52 +0000
@@ -4388,16 +4388,8 @@
   for (i = 0; i < 255; i++)
     if (variations[i])
       {
-	Lisp_Object code;
 	int vs = (i < 16 ? 0xFE00 + i : 0xE0100 + (i - 16));
-	/* Stops GCC whining about limited range of data type.	*/
-	EMACS_INT var = variations[i];
-
-	if (var > MOST_POSITIVE_FIXNUM)
-	  code = Fcons (make_number ((variations[i]) >> 16),
-			make_number ((variations[i]) & 0xFFFF));
-	else
-	  code = make_number (variations[i]);
+	Lisp_Object code = INTEGER_TO_CONS (variations[i]);
 	val = Fcons (Fcons (make_number (vs), code), val);
       }
   return val;

=== modified file 'src/fontset.c'
--- src/fontset.c	2011-05-28 22:39:39 +0000
+++ src/fontset.c	2011-06-06 06:19:52 +0000
@@ -1859,17 +1859,11 @@
     {
       unsigned code = face->font->driver->encode_char (face->font, c);
       Lisp_Object font_object;
-      /* Assignment to EMACS_INT stops GCC whining about limited range
-	 of data type.  */
-      EMACS_INT cod = code;

       if (code == FONT_INVALID_CODE)
 	return Qnil;
       XSETFONT (font_object, face->font);
-      if (cod <= MOST_POSITIVE_FIXNUM)
-	return Fcons (font_object, make_number (code));
-      return Fcons (font_object, Fcons (make_number (code >> 16),
-				     make_number (code & 0xFFFF)));
+      return Fcons (font_object, INTEGER_TO_CONS (code));
     }
   return Qnil;
 }

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-06-06 06:16:12 +0000
+++ src/lisp.h	2011-06-06 07:44:04 +0000
@@ -24,6 +24,8 @@
 #include <stddef.h>
 #include <inttypes.h>

+#include <intprops.h>
+
 /* Use the configure flag --enable-checking[=LIST] to enable various
    types of run time checks for Lisp objects.  */

@@ -2408,9 +2410,35 @@
 EXFUN (Fsub1, 1);
 EXFUN (Fmake_variable_buffer_local, 1);

+/* Convert the integer I to an Emacs representation, either the integer
+   itself, or a cons of two or three integers, or if all else fails a float.
+   I should not have side effects.  */
+#define INTEGER_TO_CONS(i)					    \
+  (! FIXNUM_OVERFLOW_P (i)					    \
+   ? make_number (i)						    \
+   : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16)			    \
+	 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16))		    \
+	&& FIXNUM_OVERFLOW_P ((i) >> 16))			    \
+   ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff))    \
+   : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16 >> 24)		    \
+	 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16 >> 24))	    \
+	&& FIXNUM_OVERFLOW_P ((i) >> 16 >> 24))			    \
+   ? Fcons (make_number ((i) >> 16 >> 24),			    \
+	    Fcons (make_number ((i) >> 16 & 0xffffff),		    \
+		   make_number ((i) & 0xffff)))			    \
+   : make_float (i))
+
+/* Convert the Emacs representation CONS back to an integer of type
+   TYPE, storing the result the variable VAR.  Signal an error if CONS
+   is not a valid representation or is out of range for TYPE.  */
+#define CONS_TO_INTEGER(cons, type, var)				\
+ (TYPE_SIGNED (type)							\
+  ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
+  : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
+extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
+extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
+
 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
-extern Lisp_Object long_to_cons (unsigned long);
-extern unsigned long cons_to_long (Lisp_Object);
 extern void args_out_of_range (Lisp_Object, Lisp_Object) NO_RETURN;
 extern void args_out_of_range_3 (Lisp_Object, Lisp_Object,
                                  Lisp_Object) NO_RETURN;

=== modified file 'src/undo.c'
--- src/undo.c	2011-06-02 06:15:15 +0000
+++ src/undo.c	2011-06-06 06:19:52 +0000
@@ -212,7 +212,6 @@
 void
 record_first_change (void)
 {
-  Lisp_Object high, low;
   struct buffer *base_buffer = current_buffer;

   if (EQ (BVAR (current_buffer, undo_list), Qt))
@@ -225,9 +224,9 @@
   if (base_buffer->base_buffer)
     base_buffer = base_buffer->base_buffer;

-  XSETFASTINT (high, (base_buffer->modtime >> 16) & 0xffff);
-  XSETFASTINT (low, base_buffer->modtime & 0xffff);
-  BVAR (current_buffer, undo_list) = Fcons (Fcons (Qt, Fcons (high, low)), BVAR (current_buffer, undo_list));
+  BVAR (current_buffer, undo_list) =
+    Fcons (Fcons (Qt, INTEGER_TO_CONS (base_buffer->modtime)),
+	   BVAR (current_buffer, undo_list));
 }

 /* Record a change in property PROP (whose old value was VAL)
@@ -499,13 +498,9 @@
 	      if (EQ (car, Qt))
 		{
 		  /* Element (t high . low) records previous modtime.  */
-		  Lisp_Object high, low;
+		  struct buffer *base_buffer = current_buffer;
 		  time_t mod_time;
-		  struct buffer *base_buffer = current_buffer;
-
-		  high = Fcar (cdr);
-		  low = Fcdr (cdr);
-		  mod_time = (XFASTINT (high) << 16) + XFASTINT (low);
+		  CONS_TO_INTEGER (cdr, time_t, mod_time);

 		  if (current_buffer->base_buffer)
 		    base_buffer = current_buffer->base_buffer;

=== modified file 'src/xfns.c'
--- src/xfns.c	2011-06-05 22:20:42 +0000
+++ src/xfns.c	2011-06-06 06:19:52 +0000
@@ -4299,18 +4299,9 @@

   if (! NILP (source))
     {
-      if (NUMBERP (source))
-        {
-          if (FLOATP (source))
-            target_window = (Window) XFLOAT (source);
-          else
-            target_window = XFASTINT (source);
-
-          if (target_window == 0)
-            target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
-        }
-      else if (CONSP (source))
-        target_window = cons_to_long (source);
+      CONS_TO_INTEGER (source, Window, target_window);
+      if (! target_window)
+	target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
     }

   BLOCK_INPUT;

=== modified file 'src/xselect.c'
--- src/xselect.c	2011-06-04 22:08:32 +0000
+++ src/xselect.c	2011-06-06 06:27:37 +0000
@@ -20,6 +20,7 @@
 /* Rewritten by jwz */

 #include <config.h>
+#include <limits.h>
 #include <stdio.h>      /* termhooks.h needs this */
 #include <setjmp.h>

@@ -335,7 +336,7 @@
     Lisp_Object prev_value;

     selection_data = list4 (selection_name, selection_value,
-			    long_to_cons (timestamp), frame);
+			    INTEGER_TO_CONS (timestamp), frame);
     prev_value = LOCAL_SELECTION (selection_name, dpyinfo);

     dpyinfo->terminal->Vselection_alist
@@ -419,7 +420,7 @@
       || INTEGERP (check)
       || NILP (value))
     return value;
-  /* Check for a value that cons_to_long could handle.  */
+  /* Check for a value that CONS_TO_INTEGER could handle.  */
   else if (CONSP (check)
 	   && INTEGERP (XCAR (check))
 	   && (INTEGERP (XCDR (check))
@@ -782,8 +783,8 @@
   if (NILP (local_selection_data)) goto DONE;

   /* Decline requests issued prior to our acquiring the selection.  */
-  local_selection_time
-    = (Time) cons_to_long (XCAR (XCDR (XCDR (local_selection_data))));
+  CONS_TO_INTEGER (XCAR (XCDR (XCDR (local_selection_data))),
+		   Time, local_selection_time);
   if (SELECTION_EVENT_TIME (event) != CurrentTime
       && local_selection_time > SELECTION_EVENT_TIME (event))
     goto DONE;
@@ -950,8 +951,8 @@
   /* Well, we already believe that we don't own it, so that's just fine.  */
   if (NILP (local_selection_data)) return;

-  local_selection_time = (Time)
-    cons_to_long (XCAR (XCDR (XCDR (local_selection_data))));
+  CONS_TO_INTEGER (XCAR (XCDR (XCDR (local_selection_data))),
+		   Time, local_selection_time);

   /* We have reasserted the selection since this SelectionClear was
      generated, so we can disregard it.  */
@@ -1212,16 +1213,7 @@
     return Qnil;

   if (! NILP (time_stamp))
-    {
-      if (CONSP (time_stamp))
-        requestor_time = (Time) cons_to_long (time_stamp);
-      else if (INTEGERP (time_stamp))
-        requestor_time = (Time) XUINT (time_stamp);
-      else if (FLOATP (time_stamp))
-        requestor_time = (Time) XFLOAT_DATA (time_stamp);
-      else
-        error ("TIME_STAMP must be cons or number");
-    }
+    CONS_TO_INTEGER (time_stamp, Time, requestor_time);

   BLOCK_INPUT;
   TRACE2 ("Get selection %s, type %s",
@@ -1639,7 +1631,7 @@
      convert it to a cons of integers, 16 bits in each half.
    */
   else if (format == 32 && size == sizeof (int))
-    return long_to_cons (((unsigned int *) data) [0]);
+    return INTEGER_TO_CONS (((unsigned int *) data) [0]);
   else if (format == 16 && size == sizeof (short))
     return make_number ((int) (((unsigned short *) data) [0]));

@@ -1665,7 +1657,7 @@
       for (i = 0; i < size / 4; i++)
 	{
 	  unsigned int j = ((unsigned int *) data) [i];
-	  Faset (v, make_number (i), long_to_cons (j));
+	  Faset (v, make_number (i), INTEGER_TO_CONS (j));
 	}
       return v;
     }
@@ -1742,7 +1734,7 @@
       *size_ret = 1;
       *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
       (*data_ret) [sizeof (long)] = 0;
-      (*(unsigned long **) data_ret) [0] = cons_to_long (obj);
+      (*(unsigned long **) data_ret) [0] = cons_to_unsigned (obj, ULONG_MAX);
       if (NILP (type)) type = QINTEGER;
     }
   else if (VECTORP (obj))
@@ -1790,11 +1782,11 @@
 	  *data_ret = (unsigned char *) xmalloc (*size_ret * data_size);
 	  for (i = 0; i < *size_ret; i++)
 	    if (*format_ret == 32)
-	      (*((unsigned long **) data_ret)) [i]
-		= cons_to_long (XVECTOR (obj)->contents [i]);
+	      (*((unsigned long **) data_ret)) [i] =
+		cons_to_unsigned (XVECTOR (obj)->contents [i], ULONG_MAX);
 	    else
-	      (*((unsigned short **) data_ret)) [i]
-		= (unsigned short) cons_to_long (XVECTOR (obj)->contents [i]);
+	      (*((unsigned short **) data_ret)) [i] =
+		cons_to_unsigned (XVECTOR (obj)->contents [i], USHRT_MAX);
 	}
     }
   else
@@ -2012,8 +2004,10 @@
   selection_atom = symbol_to_x_atom (dpyinfo, selection);

   BLOCK_INPUT;
-  timestamp = (NILP (time_object) ? last_event_timestamp
-	       : cons_to_long (time_object));
+  if (NILP (time_object))
+    timestamp = last_event_timestamp;
+  else
+    CONS_TO_INTEGER (time_object, Time, timestamp);
   XSetSelectionOwner (dpyinfo->display, selection_atom, None, timestamp);
   UNBLOCK_INPUT;

@@ -2250,12 +2244,8 @@
     {
       Lisp_Object o = XCAR (iter);

-      if (INTEGERP (o))
-        val = (long) XFASTINT (o);
-      else if (FLOATP (o))
-        val = (long) XFLOAT_DATA (o);
-      else if (CONSP (o))
-        val = (long) cons_to_long (o);
+      if (INTEGERP (o) || FLOATP (o) || CONSP (o))
+	val = cons_to_signed (o, LONG_MIN, LONG_MAX);
       else if (STRINGP (o))
         {
           BLOCK_INPUT;
@@ -2266,9 +2256,19 @@
         error ("Wrong type, must be string, number or cons");

       if (format == 8)
-        *d08++ = (char) val;
+	{
+	  if (CHAR_MIN <= val && val <= CHAR_MAX)
+	    *d08++ = val;
+	  else
+	    error ("Out of 'char' range");
+	}
       else if (format == 16)
-        *d16++ = (short) val;
+	{
+	  if (SHRT_MIN <= val && val <= SHRT_MAX)
+	    *d16++ = val;
+	  else
+	    error ("Out of 'short' range");
+	}
       else
         *d32++ = val;
     }
@@ -2352,14 +2352,7 @@
   Atom atom;
   int had_errors;

-  if (INTEGERP (value))
-    atom = (Atom) XUINT (value);
-  else if (FLOATP (value))
-    atom = (Atom) XFLOAT_DATA (value);
-  else if (CONSP (value))
-    atom = (Atom) cons_to_long (value);
-  else
-    error ("Wrong type, value must be number or cons");
+  CONS_TO_INTEGER (value, Atom, atom);

   BLOCK_INPUT;
   x_catch_errors (dpy);
@@ -2549,17 +2542,8 @@
       else
         error ("DEST as a string must be one of PointerWindow or InputFocus");
     }
-  else if (INTEGERP (dest))
-    wdest = (Window) XFASTINT (dest);
-  else if (FLOATP (dest))
-    wdest =  (Window) XFLOAT_DATA (dest);
-  else if (CONSP (dest))
-    {
-      if (! NUMBERP (XCAR (dest)) || ! NUMBERP (XCDR (dest)))
-        error ("Both car and cdr for DEST must be numbers");
-      else
-        wdest = (Window) cons_to_long (dest);
-    }
+  else if (INTEGERP (dest) || FLOATP (dest) || CONSP (dest))
+    CONS_TO_INTEGER (dest, Window, wdest);
   else
     error ("DEST must be a frame, nil, string, number or cons");








^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (b) make the 64bit-on-32bit the default (if supported)
  2011-06-03 19:29   ` bug#8794: (b) make the 64bit-on-32bit the default (if supported) Paul Eggert
@ 2011-06-06 14:52     ` Stefan Monnier
  2011-06-06 17:54       ` Paul Eggert
  2011-06-07  4:21       ` Paul Eggert
  0 siblings, 2 replies; 21+ messages in thread
From: Stefan Monnier @ 2011-06-06 14:52 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

severity 8794 wishlist
tags 8794 +patch
thanks

As mentioned earlier, I don't think we want to install this right now,
so let's keep it as an option for now and reconsider this choice for
Emacs-24.2.  We should make a --with-wide-int option for ./configure, tho.


        Stefan


>>>>> "Paul" == Paul Eggert <eggert@cs.ucla.edu> writes:

> Almost all of this is documentation change.  The only code change
> is the lisp.h change to the default.


> === modified file 'doc/emacs/ChangeLog'
> --- doc/emacs/ChangeLog	2011-05-28 18:22:08 +0000
> +++ doc/emacs/ChangeLog	2011-06-03 18:47:14 +0000
> @@ -1,3 +1,9 @@
> +2011-06-02  Paul Eggert  <eggert@cs.ucla.edu>
> +
> +	Document wide integers better.
> +	* buffers.texi (Buffers):
> +	* files.texi (Visiting): Default buffer maximum is now 2 EiB typically.
> +
>  2011-05-28  Chong Yidong  <cyd@stupidchicken.com>
 
>  	* custom.texi (Hooks): Reorganize.  Mention Prog mode.

> === modified file 'doc/emacs/buffers.texi'
> --- doc/emacs/buffers.texi	2011-01-25 04:08:28 +0000
> +++ doc/emacs/buffers.texi	2011-06-03 18:47:14 +0000
> @@ -43,8 +43,11 @@
>    A buffer's size cannot be larger than some maximum, which is defined
>  by the largest buffer position representable by the @dfn{Emacs
>  integer} data type.  This is because Emacs tracks buffer positions
> -using that data type.  For 32-bit machines, the largest buffer size is
> -512 megabytes.
> +using that data type.  For most machines, the maximum buffer size
> +enforced by the data types is @math{2^61 - 2} bytes, or about 2 EiB.
> +For some older machines, the maximum is @math{2^29 - 2} bytes, or
> +about 512 MiB.  Buffer sizes are also limited by the size of Emacs's
> +virtual memory.
 
>  @menu
>  * Select Buffer::       Creating a new buffer or reselecting an old one.

> === modified file 'doc/emacs/files.texi'
> --- doc/emacs/files.texi	2011-01-31 23:54:50 +0000
> +++ doc/emacs/files.texi	2011-06-03 18:47:14 +0000
> @@ -209,7 +209,8 @@
>  about 10 megabytes), Emacs asks you for confirmation first.  You can
>  answer @kbd{y} to proceed with visiting the file.  Note, however, that
>  Emacs cannot visit files that are larger than the maximum Emacs buffer
> -size, which is around 512 megabytes on 32-bit machines
> +size, which is limited by the amount of memory Emacs can allocate
> +and by the integers that Emacs can represent
>  (@pxref{Buffers}).  If you try, Emacs will display an error message
>  saying that the maximum buffer size has been exceeded.
 

> === modified file 'doc/lispref/ChangeLog'
> --- doc/lispref/ChangeLog	2011-05-31 18:40:00 +0000
> +++ doc/lispref/ChangeLog	2011-06-03 18:49:33 +0000
> @@ -1,3 +1,12 @@
> +2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
> +
> +	Document wide integers better.
> +	* files.texi (File Attributes): Document ino_t values better.
> +	* numbers.texi (Integer Basics, Integer Basics, Arithmetic Operations):
> +	(Bitwise Operations):
> +	* objects.texi (Integer Type): Integers are typically 62 bits now.
> +	* os.texi (Time Conversion): Document time_t values better.
> +
>  2011-05-31  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
>  	* processes.texi (Process Information): Document

> === modified file 'doc/lispref/files.texi'
> --- doc/lispref/files.texi	2011-05-12 07:07:06 +0000
> +++ doc/lispref/files.texi	2011-06-03 18:49:33 +0000
> @@ -1236,12 +1236,13 @@
 
>  @item
>  The file's inode number.  If possible, this is an integer.  If the
> -inode number is too large to be represented as an integer in Emacs
> -Lisp, but still fits into a 32-bit integer, then the value has the
> -form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16
> -bits.  If the inode is wider than 32 bits, the value is of the form
> +inode number @math{N} is too large to be represented as an integer in
> +Emacs Lisp, but @math{N / 2^16} is representable, then the value has
> +the form @code{(@var{high} . @var{low})}, where @var{high} holds the
> +high bits (i.e., excluding the low-order bits) and @var{low} the low
> +16 bits.  If the inode number is even larger, the value is of the form
>  @code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds
> -the high 24 bits, @var{middle} the next 24 bits, and @var{low} the low
> +the high bits, @var{middle} the next 24 bits, and @var{low} the low
>  16 bits.
 
>  @item

> === modified file 'doc/lispref/numbers.texi'
> --- doc/lispref/numbers.texi	2011-05-05 06:31:14 +0000
> +++ doc/lispref/numbers.texi	2011-06-03 18:49:33 +0000
> @@ -36,22 +36,24 @@
>  @section Integer Basics
 
>    The range of values for an integer depends on the machine.  The
> -minimum range is @minus{}536870912 to 536870911 (30 bits; i.e.,
> +typical range is @minus{}2305843009213693952 to 2305843009213693951
> +(62 bits; i.e.,
>  @ifnottex
> --2**29
> +-2**61
>  @end ifnottex
>  @tex
> -@math{-2^{29}}
> +@math{-2^{61}}
>  @end tex
>  to
>  @ifnottex
> -2**29 - 1),
> +2**61 - 1)
>  @end ifnottex
>  @tex
> -@math{2^{29}-1}),
> +@math{2^{61}-1})
>  @end tex
> -but some machines may provide a wider range.  Many examples in this
> -chapter assume an integer has 30 bits.
> +but some older machines provide only 30 bits.  Many examples in this
> +chapter assume that an integer has 62 bits and that floating point
> +numbers are IEEE double precision.
>  @cindex overflow
 
>    The Lisp reader reads an integer as a sequence of digits with optional
> @@ -63,7 +65,8 @@
>   1.              ; @r{The integer 1.}
>  +1               ; @r{Also the integer 1.}
>  -1               ; @r{The integer @minus{}1.}
> - 1073741825      ; @r{The floating point number 1073741825.0.}
> + 4611686018427387904
> +                 ; @r{The floating point number 4.611686018427388e+18.}
>   0               ; @r{The integer 0.}
>  -0               ; @r{The integer 0.}
>  @end example
> @@ -94,25 +97,21 @@
>  bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
>  view the numbers in their binary form.
 
> -  In 30-bit binary, the decimal integer 5 looks like this:
> +  In 62-bit binary, the decimal integer 5 looks like this:
 
>  @example
> -00 0000  0000 0000  0000 0000  0000 0101
> +0000...000101 (62 bits total)
>  @end example
 
> -@noindent
> -(We have inserted spaces between groups of 4 bits, and two spaces
> -between groups of 8 bits, to make the binary integer easier to read.)
> -
>    The integer @minus{}1 looks like this:
 
>  @example
> -11 1111  1111 1111  1111 1111  1111 1111
> +1111...111111 (62 bits total)
>  @end example
 
>  @noindent
>  @cindex two's complement
> -@minus{}1 is represented as 30 ones.  (This is called @dfn{two's
> +@minus{}1 is represented as 62 ones.  (This is called @dfn{two's
>  complement} notation.)
 
>    The negative integer, @minus{}5, is creating by subtracting 4 from
> @@ -120,24 +119,24 @@
>  @minus{}5 looks like this:
 
>  @example
> -11 1111  1111 1111  1111 1111  1111 1011
> +1111...111011 (62 bits total)
>  @end example
 
> -  In this implementation, the largest 30-bit binary integer value is
> -536,870,911 in decimal.  In binary, it looks like this:
> +  In this implementation, the largest 62-bit binary integer value is
> +2,305,843,009,213,693,951 in decimal.  In binary, it looks like this:
 
>  @example
> -01 1111  1111 1111  1111 1111  1111 1111
> +0111...111111 (62 bits total)
>  @end example
 
>    Since the arithmetic functions do not check whether integers go
> -outside their range, when you add 1 to 536,870,911, the value is the
> -negative integer @minus{}536,870,912:
> +outside their range, when you add 1 to 2,305,843,009,213,693,951, the value is the
> +negative integer @minus{}2,305,843,009,213,693,952:
 
>  @example
> -(+ 1 536870911)
> -     @result{} -536870912
> -     @result{} 10 0000  0000 0000  0000 0000  0000 0000
> +(+ 1 2305843009213693951)
> +     @result{} -2305843009213693952
> +     @result{} 1000...000000 (62 bits total)
>  @end example
 
>    Many of the functions described in this chapter accept markers for
> @@ -508,8 +507,8 @@
>  if any argument is floating.
 
>    It is important to note that in Emacs Lisp, arithmetic functions
> -do not check for overflow.  Thus @code{(1+ 268435455)} may evaluate to
> -@minus{}268435456, depending on your hardware.
> +do not check for overflow.  Thus @code{(1+ 2305843009213693951)} may
> +evaluate to @minus{}2305843009213693952, depending on your hardware.
 
>  @defun 1+ number-or-marker
>  This function returns @var{number-or-marker} plus 1.
> @@ -829,19 +828,19 @@
>  The function @code{lsh}, like all Emacs Lisp arithmetic functions, does
>  not check for overflow, so shifting left can discard significant bits
>  and change the sign of the number.  For example, left shifting
> -536,870,911 produces @minus{}2 on a 30-bit machine:
> +2,305,843,009,213,693,951 produces @minus{}2 on a typical machine:
 
>  @example
> -(lsh 536870911 1)          ; @r{left shift}
> +(lsh 2305843009213693951 1)  ; @r{left shift}
>       @result{} -2
>  @end example
 
> -In binary, in the 30-bit implementation, the argument looks like this:
> +In binary, in the 62-bit implementation, the argument looks like this:
 
>  @example
>  @group
> -;; @r{Decimal 536,870,911}
> -01 1111  1111 1111  1111 1111  1111 1111
> +;; @r{Decimal 2,305,843,009,213,693,951}
> +0111...111111 (62 bits total)
>  @end group
>  @end example
 
> @@ -851,7 +850,7 @@
>  @example
>  @group
>  ;; @r{Decimal @minus{}2}
> -11 1111  1111 1111  1111 1111  1111 1110
> +1111...111110 (62 bits total)
>  @end group
>  @end example
>  @end defun
> @@ -874,9 +873,9 @@
>  @group
>  (ash -6 -1) @result{} -3
>  ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
> -11 1111  1111 1111  1111 1111  1111 1010
> +1111...111010 (62 bits total)
>       @result{}
> -11 1111  1111 1111  1111 1111  1111 1101
> +1111...111101 (62 bits total)
>  @end group
>  @end example
 
> @@ -885,11 +884,11 @@
 
>  @example
>  @group
> -(lsh -6 -1) @result{} 536870909
> -;; @r{Decimal @minus{}6 becomes decimal 536,870,909.}
> -11 1111  1111 1111  1111 1111  1111 1010
> +(lsh -6 -1) @result{} 2305843009213693949
> +;; @r{Decimal @minus{}6 becomes decimal 2,305,843,009,213,693,949.}
> +1111...111010 (62 bits total)
>       @result{}
> -01 1111  1111 1111  1111 1111  1111 1101
> +0111...111101 (62 bits total)
>  @end group
>  @end example
 
> @@ -899,34 +898,35 @@
>  @c     with smallbook but not with regular book! --rjc 16mar92
>  @smallexample
>  @group
> -                   ;  @r{             30-bit binary values}
> +                   ;  @r{       62-bit binary values}
 
> -(lsh 5 2)          ;   5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> -     @result{} 20         ;      =  @r{00 0000  0000 0000  0000 0000  0001 0100}
> +(lsh 5 2)          ;   5  =  @r{0000...000101}
> +     @result{} 20         ;      =  @r{0000...010100}
>  @end group
>  @group
>  (ash 5 2)
>       @result{} 20
> -(lsh -5 2)         ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
> -     @result{} -20        ;      =  @r{11 1111  1111 1111  1111 1111  1110 1100}
> +(lsh -5 2)         ;  -5  =  @r{1111...111011}
> +     @result{} -20        ;      =  @r{1111...101100}
>  (ash -5 2)
>       @result{} -20
>  @end group
>  @group
> -(lsh 5 -2)         ;   5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> -     @result{} 1          ;      =  @r{00 0000  0000 0000  0000 0000  0000 0001}
> +(lsh 5 -2)         ;   5  =  @r{0000...000101}
> +     @result{} 1          ;      =  @r{0000...000001}
>  @end group
>  @group
>  (ash 5 -2)
>       @result{} 1
>  @end group
>  @group
> -(lsh -5 -2)        ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
> -     @result{} 268435454  ;      =  @r{00 0111  1111 1111  1111 1111  1111 1110}
> +(lsh -5 -2)        ;  -5  =  @r{1111...111011}
> +     @result{} 1152921504606846974
> +                   ;      =  @r{0011...111110}
>  @end group
>  @group
> -(ash -5 -2)        ;  -5  =  @r{11 1111  1111 1111  1111 1111  1111 1011}
> -     @result{} -2         ;      =  @r{11 1111  1111 1111  1111 1111  1111 1110}
> +(ash -5 -2)        ;  -5  =  @r{1111...111011}
> +     @result{} -2         ;      =  @r{1111...111110}
>  @end group
>  @end smallexample
>  @end defun
> @@ -961,23 +961,23 @@
 
>  @smallexample
>  @group
> -                   ; @r{               30-bit binary values}
> +                   ; @r{       62-bit binary values}
 
> -(logand 14 13)     ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
> -                   ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
> -     @result{} 12         ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
> +(logand 14 13)     ; 14  =  @r{0000...001110}
> +                   ; 13  =  @r{0000...001101}
> +     @result{} 12         ; 12  =  @r{0000...001100}
>  @end group
 
>  @group
> -(logand 14 13 4)   ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
> -                   ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
> -                   ;  4  =  @r{00 0000  0000 0000  0000 0000  0000 0100}
> -     @result{} 4          ;  4  =  @r{00 0000  0000 0000  0000 0000  0000 0100}
> +(logand 14 13 4)   ; 14  =  @r{0000...001110}
> +                   ; 13  =  @r{0000...001101}
> +                   ;  4  =  @r{0000...000100}
> +     @result{} 4          ;  4  =  @r{0000...000100}
>  @end group
 
>  @group
>  (logand)
> -     @result{} -1         ; -1  =  @r{11 1111  1111 1111  1111 1111  1111 1111}
> +     @result{} -1         ; -1  =  @r{1111...111111}
>  @end group
>  @end smallexample
>  @end defun
> @@ -991,18 +991,18 @@
 
>  @smallexample
>  @group
> -                   ; @r{              30-bit binary values}
> +                   ; @r{       62-bit binary values}
 
> -(logior 12 5)      ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
> -                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> -     @result{} 13         ; 13  =  @r{00 0000  0000 0000  0000 0000  0000 1101}
> +(logior 12 5)      ; 12  =  @r{0000...001100}
> +                   ;  5  =  @r{0000...000101}
> +     @result{} 13         ; 13  =  @r{0000...001101}
>  @end group
 
>  @group
> -(logior 12 5 7)    ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
> -                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> -                   ;  7  =  @r{00 0000  0000 0000  0000 0000  0000 0111}
> -     @result{} 15         ; 15  =  @r{00 0000  0000 0000  0000 0000  0000 1111}
> +(logior 12 5 7)    ; 12  =  @r{0000...001100}
> +                   ;  5  =  @r{0000...000101}
> +                   ;  7  =  @r{0000...000111}
> +     @result{} 15         ; 15  =  @r{0000...001111}
>  @end group
>  @end smallexample
>  @end defun
> @@ -1016,18 +1016,18 @@
 
>  @smallexample
>  @group
> -                   ; @r{              30-bit binary values}
> +                   ; @r{       62-bit binary values}
 
> -(logxor 12 5)      ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
> -                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> -     @result{} 9          ;  9  =  @r{00 0000  0000 0000  0000 0000  0000 1001}
> +(logxor 12 5)      ; 12  =  @r{0000...001100}
> +                   ;  5  =  @r{0000...000101}
> +     @result{} 9          ;  9  =  @r{0000...001001}
>  @end group
 
>  @group
> -(logxor 12 5 7)    ; 12  =  @r{00 0000  0000 0000  0000 0000  0000 1100}
> -                   ;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> -                   ;  7  =  @r{00 0000  0000 0000  0000 0000  0000 0111}
> -     @result{} 14         ; 14  =  @r{00 0000  0000 0000  0000 0000  0000 1110}
> +(logxor 12 5 7)    ; 12  =  @r{0000...001100}
> +                   ;  5  =  @r{0000...000101}
> +                   ;  7  =  @r{0000...000111}
> +     @result{} 14         ; 14  =  @r{0000...001110}
>  @end group
>  @end smallexample
>  @end defun
> @@ -1040,9 +1040,9 @@
>  @example
>  (lognot 5)
>       @result{} -6
> -;;  5  =  @r{00 0000  0000 0000  0000 0000  0000 0101}
> +;;  5  =  @r{0000...000101} (62 bits total)
>  ;; @r{becomes}
> -;; -6  =  @r{11 1111  1111 1111  1111 1111  1111 1010}
> +;; -6  =  @r{1111...111010} (62 bits total)
>  @end example
>  @end defun
 

> === modified file 'doc/lispref/objects.texi'
> --- doc/lispref/objects.texi	2011-05-05 06:31:14 +0000
> +++ doc/lispref/objects.texi	2011-06-03 18:49:33 +0000
> @@ -164,25 +164,25 @@
>  @node Integer Type
>  @subsection Integer Type
 
> -  The range of values for integers in Emacs Lisp is @minus{}536870912 to
> -536870911 (30 bits; i.e.,
> +  The range of values for integers in Emacs Lisp is
> +@minus{}2305843009213693952 to 2305843009213693951 (62 bits; i.e.,
>  @ifnottex
> --2**29
> +-2**61
>  @end ifnottex
>  @tex
> -@math{-2^{29}}
> +@math{-2^{61}}
>  @end tex
>  to
>  @ifnottex
> -2**29 - 1)
> +2**61 - 1)
>  @end ifnottex
>  @tex
> -@math{2^{29}-1})
> +@math{2^{61}-1})
>  @end tex
> -on most machines.  (Some machines may provide a wider range.)  It is
> -important to note that the Emacs Lisp arithmetic functions do not check
> -for overflow.  Thus @code{(1+ 536870911)} is @minus{}536870912 on most
> -machines.
> +on most machines.  Some machines may provide a narrower or wider
> +range; all machines provide at least 30 bits.  Emacs Lisp arithmetic
> +functions do not check for overflow.  Thus @code{(1+
> +2305843009213693951)} is @minus{}2305843009213693952 on most machines.
 
>    The read syntax for integers is a sequence of (base ten) digits with an
>  optional sign at the beginning and an optional period at the end.  The
> @@ -195,7 +195,6 @@
>  1                ; @r{The integer 1.}
>  1.               ; @r{Also the integer 1.}
>  +1               ; @r{Also the integer 1.}
> -1073741825       ; @r{Also the integer 1 on a 30-bit implementation.}
>  @end group
>  @end example
 
> @@ -203,8 +202,8 @@
>  As a special exception, if a sequence of digits specifies an integer
>  too large or too small to be a valid integer object, the Lisp reader
>  reads it as a floating-point number (@pxref{Floating Point Type}).
> -For instance, on most machines @code{536870912} is read as the
> -floating-point number @code{536870912.0}.
> +For instance, on most machines @code{2305843009213693952} is read as the
> +floating-point number @code{2.305843009213694e+18}.
 
>    @xref{Numbers}, for more information.
 

> === modified file 'doc/lispref/os.texi'
> --- doc/lispref/os.texi	2011-02-01 07:23:48 +0000
> +++ doc/lispref/os.texi	2011-06-03 18:49:33 +0000
> @@ -1193,11 +1193,11 @@
>  from the functions @code{current-time} (@pxref{Time of Day}) and
>  @code{file-attributes} (@pxref{Definition of file-attributes}).
 
> -  Many operating systems are limited to time values that contain 32 bits
> +  Many 32-bit operating systems are limited to time values that contain 32 bits
>  of information; these systems typically handle only the times from
> -1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.  However, some
> -operating systems have larger time values, and can represent times far
> -in the past or future.
> +1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.  However, 64-bit
> +and some 32-bit operating systems have larger time values, and can
> +represent times far in the past or future.
 
>    Time conversion functions always use the Gregorian calendar, even
>  for dates before the Gregorian calendar was introduced.  Year numbers

> === modified file 'etc/ChangeLog'
> --- etc/ChangeLog	2011-05-24 14:22:44 +0000
> +++ etc/ChangeLog	2011-06-03 18:42:04 +0000
> @@ -1,3 +1,7 @@
> +2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
> +
> +	* NEWS: 62-bit integers are typical now.
> +
>  2011-05-24  Leo Liu  <sdl.web@gmail.com>
 
>  	* NEWS: Mention the new primitive sha1 and the removal of sha1.el.

> === modified file 'etc/NEWS'
> --- etc/NEWS	2011-06-01 15:34:41 +0000
> +++ etc/NEWS	2011-06-03 18:42:04 +0000
> @@ -902,6 +902,14 @@
>  *** New function `special-variable-p' to check whether a variable is
>  declared as dynamically bound.
 
> +** Emacs integers have a wider range on typical 32-bit hosts.
> +Previously, they were limited to a 30-bit range (-2**29 .. 2**29-1).
> +Now, they are limited to a 62-bit range (-2**61 .. 2**61-1), the
> +same as on 64-bit hosts.  This increased range comes from the Emacs
> +interpreter using 64-bit native integer types that are available
> +on typical modern 32-bit platforms.  Older 32-bit hosts that lack
> +64-bit integers have the same 30-bit range as before.
> +
>  ** pre/post-command-hook are not reset to nil upon error.
>  Instead, the offending function is removed.
 

> === modified file 'src/ChangeLog'
> --- src/ChangeLog	2011-06-03 18:22:12 +0000
> +++ src/ChangeLog	2011-06-03 18:42:59 +0000
> @@ -1,5 +1,14 @@
>  2011-06-03  Paul Eggert  <eggert@cs.ucla.edu>
 
> +	Fix doc for machines with wider system times such as time_t.
> +	On such machines, it's now safe to assume that EMACS_INT is as
> +	wide as the system times, so that shifting right by 16 will
> +	result in an integer that always fits in EMACS_INT.
> +	* dired.c (Ffile_attributes): Document large inode number handling.
> +	* termhooks.h: Fix comment for large time stamp handling.
> +
> +	* lisp.h (WIDE_EMACS_INT): Now defaults to 1.
> +
>  	* xselect.c: Use 'unsigned' more consistently.
>  	(selection_data_to_lisp_data, lisp_data_to_selection_data):
>  	Use 'unsigned' consistently when computing sizes of unsigned objects.

> === modified file 'src/dired.c'
> --- src/dired.c	2011-06-02 06:21:13 +0000
> +++ src/dired.c	2011-06-03 18:42:59 +0000
> @@ -901,10 +901,10 @@
>   8. File modes, as a string of ten letters or dashes as in ls -l.
>   9. t if file's gid would change if file were deleted and recreated.
>  10. inode number.  If inode number is larger than what Emacs integer
> -  can hold, but still fits into a 32-bit number, this is a cons cell
> +  can hold, but all but the bottom 16 bits still fits, this is a cons cell
>    containing two integers: first the high part, then the low 16 bits.
> -  If the inode number is wider than 32 bits, this is of the form
> -  (HIGH MIDDLE . LOW): first the high 24 bits, then middle 24 bits,
> +  If the inode number is still wider, this is of the form
> +  (HIGH MIDDLE . LOW): first the high bits, then the middle 24 bits,
>    and finally the low 16 bits.
>  11. Filesystem device number.  If it is larger than what the Emacs
>    integer can hold, this is a cons cell, similar to the inode number.
> @@ -1008,8 +1008,8 @@
>  			make_number ((EMACS_INT)(s.st_ino & 0xffff)));
>    else
>      {
> -      /* To allow inode numbers beyond 32 bits, separate into 2 24-bit
> -	 high parts and a 16-bit bottom part.
> +      /* To allow inode numbers beyond what INTEGER_TO_CONS can handle,
> +	 separate into 2 24-bit high parts and a 16-bit bottom part.
>  	 The code on the next line avoids a compiler warning on
>  	 systems where st_ino is 32 bit wide. (bug#766).  */
>        EMACS_INT high_ino = s.st_ino >> 31 >> 1;

> === modified file 'src/lisp.h'
> --- src/lisp.h	2011-06-03 18:14:49 +0000
> +++ src/lisp.h	2011-06-03 18:28:20 +0000
> @@ -36,13 +36,14 @@
>  #define CHECK_CONS_LIST() ((void) 0)
>  #endif
 
> -/* Temporarily disable wider-than-pointer integers until they're tested more.
> -   Build with CFLAGS='-DWIDE_EMACS_INT' to try them out.  */
> -/* #undef WIDE_EMACS_INT */
> +/* To disable wider-than-pointer integers, build with -DWIDE_EMACS_INT=0.  */
> +#ifndef WIDE_EMACS_INT
> +#define WIDE_EMACS_INT 1
> +#endif
 
>  /* These are default choices for the types to use.  */
>  #ifndef EMACS_INT
> -# if BITS_PER_LONG < BITS_PER_LONG_LONG && defined WIDE_EMACS_INT
> +# if BITS_PER_LONG < BITS_PER_LONG_LONG && WIDE_EMACS_INT
>  #  define EMACS_INT long long
>  #  define BITS_PER_EMACS_INT BITS_PER_LONG_LONG
>  #  define pI "ll"

> === modified file 'src/termhooks.h'
> --- src/termhooks.h	2011-05-27 16:17:59 +0000
> +++ src/termhooks.h	2011-06-03 18:42:59 +0000
> @@ -342,8 +342,8 @@
>       SELECTION-VALUE is the value that emacs owns for that selection.
>        It may be any kind of Lisp object.
>       SELECTION-TIMESTAMP is the time at which emacs began owning this
> -      selection, as a cons of two 16-bit numbers (making a 32 bit
> -      time.)
> +      selection, as an Emacs integer; or if that doesn't fit, as a
> +      cons of two 16-bit integers (making a 32 bit time.)
>       FRAME is the frame for which we made the selection.  If there is
>        an entry in this alist, then it can be assumed that Emacs owns
>        that selection.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
  2011-06-06  8:39       ` Paul Eggert
@ 2011-06-06 16:01         ` Stefan Monnier
  0 siblings, 0 replies; 21+ messages in thread
From: Stefan Monnier @ 2011-06-06 16:01 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

> What else needs to be done before it's reasonable to install
> something like (b)?

Experience with it.  AFAIK a non-negligible fraction of users would be
happy to see such a feature because they need to access large files that
don't grow too fast (i.e. large but still within the 32bit limit) but:
- this category of files is fairly small: only files between 512MB and
  2GB, basically.  So a non-negligible fraction of those users may end
  up finding out that it only covers some percentage of their needs
  because the other files go beyond the 2GB limit.
- some other percentage of those users won't be satisfied either because
  such large files may prove too slow to access.
- so given the limited benefits, I want to make sure the drawbacks
  are negligible.  How is the memory use impacted by your change in
  "typical" sessions?  How is the CPU use impacted in typical sessions?
Benchmarks running the byte-compiler, Gnus, and any other intensive
Elisp code would be welcome.  Benchmarks testing the impact on
redisplay performance wold also be welcome.
I'd hope most of those benchmarks to show very little difference, but so
far I haven't seen any reports to make confident that this is the case.


        Stefan





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (a) uncontroversial fixes (2011-06-06 version)
  2011-06-06  8:39       ` bug#8794: (a) uncontroversial fixes (2011-06-06 version) Paul Eggert
@ 2011-06-06 17:17         ` Stefan Monnier
  0 siblings, 0 replies; 21+ messages in thread
From: Stefan Monnier @ 2011-06-06 17:17 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794


Feel free to install it.


        Stefan





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (c) fix the cons<->int conversions (2011-06-06 version)
  2011-06-06  8:39       ` bug#8794: (c) fix the cons<->int conversions " Paul Eggert
@ 2011-06-06 17:18         ` Stefan Monnier
  0 siblings, 0 replies; 21+ messages in thread
From: Stefan Monnier @ 2011-06-06 17:18 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8794

> Check for overflow when converting integer to cons and back.

Now that it doesn't depend on (b), feel free to install it.


        Stefan





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (b) make the 64bit-on-32bit the default (if supported)
  2011-06-06 14:52     ` Stefan Monnier
@ 2011-06-06 17:54       ` Paul Eggert
  2011-06-07  4:21       ` Paul Eggert
  1 sibling, 0 replies; 21+ messages in thread
From: Paul Eggert @ 2011-06-06 17:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794, Emacs Development

[CC'ing to emacs-devel as this may be of more-general interest.
 This is about a plan to widen Emacs integers to 64 bits
 (62 bits after tagging) on typical 32-bit hosts.
 The original thread is in <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8794>.]

On 06/06/11 07:52, Stefan Monnier wrote:
> let's keep it as an option for now and reconsider this choice for
> Emacs-24.2.  We should make a --with-wide-int option for ./configure, tho.

OK, thanks, I'll add that option.

> I want to make sure the drawbacks
>   are negligible.  How is the memory use impacted by your change in
>   "typical" sessions?  How is the CPU use impacted in typical sessions?
> Benchmarks running the byte-compiler, Gnus, and any other intensive
> Elisp code would be welcome.  Benchmarks testing the impact on
> redisplay performance wold also be welcome.
> I'd hope most of those benchmarks to show very little difference, but so
> far I haven't seen any reports to make confident that this is the case.

This all sounds reasonable.  I haven't noticed much difference in
ordinary interactive use, but I haven't done quantitative benchmarks.
Thanks for reviewing it and for taking the time to make these suggestions.

One thing I plan to do while benchmarking is to replace EMACS_INT
with ptrdiff_t whenever the value is known to fit in a 32-bit quantity
on a 32-bit host.  This won't make any difference unless --with-wide-int
is used, since EMACS_INT and ptrdiff_t are normally the same (on both
32-bit and 64-bit hosts).  But in the --with-wide-int case it should
decrease both memory footprint and register pressure and should be a
measurable win.

I've started an effort to do that, and (as usual) I'm finding more
int-overflow bugs as a side effect.  For example, on a 64-bit host,
(copy-sequence (make-bool-vector 17179869184 nil)) crashes Emacs,
due to integer overflow.  I plan to fix those bugs independently of
the EMACS_INT->ptrdiff_t change.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (b) make the 64bit-on-32bit the default (if supported)
  2011-06-06 14:52     ` Stefan Monnier
  2011-06-06 17:54       ` Paul Eggert
@ 2011-06-07  4:21       ` Paul Eggert
  1 sibling, 0 replies; 21+ messages in thread
From: Paul Eggert @ 2011-06-07  4:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8794

On 06/06/11 07:52, Stefan Monnier wrote:
> We should make a --with-wide-int option for ./configure, tho.

I did that in the trunk as bzr 104521, with this patch:

[ChangeLog]
* configure.in: Add --with-wide-int.
* INSTALL: Mention this.
[etc/ChangeLog]
* NEWS: Mention new configure option --with-wide-int.
=== modified file 'INSTALL'
--- INSTALL	2011-05-18 03:39:45 +0000
+++ INSTALL	2011-06-07 04:13:43 +0000
@@ -309,6 +309,10 @@

 Use --without-sound to disable sound support.

+Use --with-wide-int to implement Emacs values with the type 'long long',
+even on hosts where a narrower type would do.  With this option, on a
+typical 32-bit host, Emacs integers have 62 bits instead of 30.
+
 The `--prefix=PREFIXDIR' option specifies where the installation process
 should put emacs and its data files.  This defaults to `/usr/local'.
 - Emacs (and the other utilities users run) go in PREFIXDIR/bin

=== modified file 'configure.in'
--- configure.in	2011-05-28 22:39:39 +0000
+++ configure.in	2011-06-07 04:13:43 +0000
@@ -144,6 +144,11 @@
 	  with_x_toolkit=$val
 ])

+OPTION_DEFAULT_OFF([wide-int], [prefer wide Emacs integers (typically 62-bit)])
+if test "$with_wide_int" = yes; then
+  AC_DEFINE([WIDE_EMACS_INT], 1, [Use long long for EMACS_INT if available.])
+fi
+
 dnl _ON results in a '--without' option in the --help output, so
 dnl the help text should refer to "don't compile", etc.
 OPTION_DEFAULT_ON([xpm],[don't compile with XPM image support])

=== modified file 'etc/NEWS'
--- etc/NEWS	2011-06-06 19:43:39 +0000
+++ etc/NEWS	2011-06-07 04:13:43 +0000
@@ -47,6 +47,9 @@
 This is only useful for Emacs developers to debug certain types of bugs.
 This is not a new feature; only the configure flag is new.

+** There is a new configure option --with-wide-int.
+With it, Emacs integers typically have 62 bits, even on 32-bit machines.
+
 ---
 ** New translation of the Emacs Tutorial in Hebrew is available.
 Type `C-u C-h t' to choose it in case your language setup doesn't






^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#8794: (c) fix the cons<->int conversions
  2011-06-03 19:30   ` bug#8794: (c) fix the cons<->int conversions Paul Eggert
@ 2016-02-25  6:49     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 21+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-25  6:49 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Stefan Monnier, 8794

This was a quite long thread, and some parts were supposed to be applied
later.  I've looked at a couple of those parts, and they seem to be
applied now:

grep --color -nH -e cons_to_unsigned *.c
charset.c:918:      unsigned code = cons_to_unsigned (val, UINT_MAX);
charset.c:931:      unsigned code = cons_to_unsigned (val, UINT_MAX);
charset.c:956:    charset.invalid_code = cons_to_unsigned (val, UINT_MAX);
charset.c:1853:  code = cons_to_unsigned (code_point, UINT_MAX);
data.c:2458:cons_to_unsigned (Lisp_Object c, uintmax_t max)
xselect.c:1663:    return cons_to_unsigned (obj, X_ULONG_MAX);

So I'm closing this bug report now.  If there were bits that were still
left dangling, please reopen.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no






^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-02-25  6:49 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-03  8:43 bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default Paul Eggert
2011-06-03 10:52 ` Eli Zaretskii
2011-06-03 17:53   ` Paul Eggert
2011-06-03 19:43     ` Eli Zaretskii
2011-06-04  3:05       ` Paul Eggert
2011-06-03 15:54 ` Stefan Monnier
2011-06-03 19:28   ` Paul Eggert
2011-06-05 12:00     ` Stefan Monnier
2011-06-06  8:39       ` Paul Eggert
2011-06-06 16:01         ` Stefan Monnier
2011-06-06  8:39       ` bug#8794: (a) uncontroversial fixes (2011-06-06 version) Paul Eggert
2011-06-06 17:17         ` Stefan Monnier
2011-06-06  8:39       ` bug#8794: (c) fix the cons<->int conversions " Paul Eggert
2011-06-06 17:18         ` Stefan Monnier
2011-06-03 19:29   ` bug#8794: (a) straightforward prerequisite fixes Paul Eggert
2011-06-03 19:29   ` bug#8794: (b) make the 64bit-on-32bit the default (if supported) Paul Eggert
2011-06-06 14:52     ` Stefan Monnier
2011-06-06 17:54       ` Paul Eggert
2011-06-07  4:21       ` Paul Eggert
2011-06-03 19:30   ` bug#8794: (c) fix the cons<->int conversions Paul Eggert
2016-02-25  6:49     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).