puresize.h 3.35 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* How much read-only Lisp storage a dumped Emacs needs.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 1993, 2001-2019 Free Software Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
3 4 5

This file is part of GNU Emacs.

6
GNU Emacs is free software: you can redistribute it and/or modify
Jim Blandy's avatar
Jim Blandy committed
7
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Jim Blandy's avatar
Jim Blandy committed
10 11 12 13 14 15 16

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Jim Blandy's avatar
Jim Blandy committed
18

19 20 21 22 23
#ifndef EMACS_PURESIZE_H
#define EMACS_PURESIZE_H

#include "lisp.h"

24 25
INLINE_HEADER_BEGIN

26
/* Define PURESIZE, the number of bytes of pure Lisp code to leave space for.
Jim Blandy's avatar
Jim Blandy committed
27 28 29

   At one point, this was defined in config.h, meaning that changing
   PURESIZE would make Make recompile all of Emacs.  But only a few
Jim Blandy's avatar
Jim Blandy committed
30
   files actually use PURESIZE, so we split it out to its own .h file.
Jim Blandy's avatar
Jim Blandy committed
31

Jim Blandy's avatar
Jim Blandy committed
32 33 34 35
   Make sure to include this file after config.h, since that tells us
   whether we are running X windows, which tells us how much pure
   storage to allocate.  */

36 37
/* First define a measure of the amount of data we have.  */

Morten Welinder's avatar
Morten Welinder committed
38 39 40 41 42 43 44
/* A system configuration file may set this to request a certain extra
   amount of storage.  This is a lot more update-robust that defining
   BASE_PURESIZE or even PURESIZE directly.  */
#ifndef SYSTEM_PURESIZE_EXTRA
#define SYSTEM_PURESIZE_EXTRA 0
#endif

45 46 47 48
#ifndef SITELOAD_PURESIZE_EXTRA
#define SITELOAD_PURESIZE_EXTRA 0
#endif

49
#ifndef BASE_PURESIZE
50
#define BASE_PURESIZE (2000000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA)
Jim Blandy's avatar
Jim Blandy committed
51
#endif
52 53 54

/* Increase BASE_PURESIZE by a ratio depending on the machine's word size.  */
#ifndef PURESIZE_RATIO
Paul Eggert's avatar
Paul Eggert committed
55
#if EMACS_INT_MAX >> 31 != 0
56
#if PTRDIFF_MAX >> 31 != 0
57
#define PURESIZE_RATIO 10 / 6	/* Don't surround with `()'.  */
58
#else
59
#define PURESIZE_RATIO 8 / 6	/* Don't surround with `()'.  */
60 61
#endif
#else
62 63 64 65
#define PURESIZE_RATIO 1
#endif
#endif

66 67 68 69
#ifdef ENABLE_CHECKING
/* ENABLE_CHECKING somehow increases the purespace used, probably because
   it tends to cause some macro arguments to be evaluated twice.  This is
   a bug, but it's difficult to track it down.  */
70
#define PURESIZE_CHECKING_RATIO 12 / 10	/* Don't surround with `()'.  */
71 72 73 74
#else
#define PURESIZE_CHECKING_RATIO 1
#endif

75 76
/* This is the actual size in bytes to allocate.  */
#ifndef PURESIZE
77
#define PURESIZE  (BASE_PURESIZE * PURESIZE_RATIO * PURESIZE_CHECKING_RATIO)
Jim Blandy's avatar
Jim Blandy committed
78
#endif
Jim Blandy's avatar
Jim Blandy committed
79

80
extern AVOID pure_write_error (Lisp_Object);
Jim Blandy's avatar
Jim Blandy committed
81

82 83
extern EMACS_INT pure[];

84 85
/* The puresize_h_* macros are private to this include file.  */

Paul Eggert's avatar
Paul Eggert committed
86
/* True if PTR is pure.  */
87 88 89 90

#define puresize_h_PURE_P(ptr) \
  ((uintptr_t) (ptr) - (uintptr_t) pure <= PURESIZE)

Paul Eggert's avatar
Paul Eggert committed
91 92 93
INLINE bool
PURE_P (void *ptr)
{
94
  return puresize_h_PURE_P (ptr);
Paul Eggert's avatar
Paul Eggert committed
95 96 97
}

/* Signal an error if OBJ is pure.  PTR is OBJ untagged.  */
98 99 100 101

#define puresize_h_CHECK_IMPURE(obj, ptr) \
  (PURE_P (ptr) ? pure_write_error (obj) : (void) 0)

Paul Eggert's avatar
Paul Eggert committed
102 103 104
INLINE void
CHECK_IMPURE (Lisp_Object obj, void *ptr)
{
105
  puresize_h_CHECK_IMPURE (obj, ptr);
Paul Eggert's avatar
Paul Eggert committed
106
}
107

108 109 110 111 112
#if DEFINE_KEY_OPS_AS_MACROS
# define PURE_P(ptr) puresize_h_PURE_P (ptr)
# define CHECK_IMPURE(obj, ptr) puresize_h_CHECK_IMPURE (obj, ptr)
#endif

113
INLINE_HEADER_END
114 115

#endif /* EMACS_PURESIZE_H */