unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 8794@debbugs.gnu.org
Subject: bug#8794: cons_to_long fixes; making 64-bit EMACS_INT the default
Date: Fri, 03 Jun 2011 10:53:55 -0700	[thread overview]
Message-ID: <4DE91FB3.80601@cs.ucla.edu> (raw)
In-Reply-To: <83oc2fdw59.fsf@gnu.org>

>> 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.





  reply	other threads:[~2011-06-03 17:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DE91FB3.80601@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=8794@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).