FSF: Original version; a long time ago.
Mly: Significantly rewritten to use new 3-bit tags and
- nicely abstracted object definitions, for 19.8.
+ nicely abstracted object definitions, for 19.8.
JWZ: Improved code to keep track of purespace usage and
- issue nice purespace and GC stats.
+ issue nice purespace and GC stats.
Ben Wing: Cleaned up frob-block lrecord code, added error-checking
- and various changes for Mule, for 19.12.
- Added bit vectors for 19.13.
+ and various changes for Mule, for 19.12.
+ Added bit vectors for 19.13.
Added lcrecord lists for 19.14.
slb: Lots of work on the purification and dump time code.
- Synched Doug Lea malloc support from Emacs 20.2.
+ Synched Doug Lea malloc support from Emacs 20.2.
og: Killed the purespace. Portable dumper (moved to dumper.c)
*/
#include "ui/window.h"
#include "ui/console-stream.h"
-#ifdef DOUG_LEA_MALLOC
+#include <ent/ent.h>
+#include <ent/ent-float.h>
+
+#ifdef HAVE_GLIBC
#include <malloc.h>
#endif
/* Non-zero means ignore malloc warnings. Set during initialization. */
int ignore_malloc_warnings;
\f
-static void *breathing_space;
+static void *breathing_space = NULL;
void release_breathing_space(void)
{
if (breathing_space) {
void *tmp = breathing_space;
- breathing_space = 0;
+ breathing_space = NULL;
free(tmp);
}
}
#endif /* ERROR_CHECK_MALLOC */
if ( str ) {
int len = strlen(str)+1; /* for stupid terminating 0 */
-
+
void *val = xmalloc(len);
if (val == 0)
return 0;
}
#endif /* !BDWGC */
-#if !defined HAVE_STRDUP
+#if !defined HAVE_STRDUP
/* will be a problem I think */
char *strdup(const char *s)
{
an object of that type is allocated. */
#ifndef MALLOC_OVERHEAD
-#ifdef GNU_MALLOC
+#ifdef HAVE_GLIBC
#define MALLOC_OVERHEAD 0
#elif defined (rcheck)
#define MALLOC_OVERHEAD 20
#endif
#endif /* MALLOC_OVERHEAD */
-#if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC)
+#if !defined(HAVE_MMAP) || defined(HAVE_GLIBC)
/* If we released our reserve (due to running out of memory),
and we have a fair amount free once again,
try to set aside another reserve in case we run out once more.
void refill_memory_reserve(void);
void refill_memory_reserve(void)
{
- if (breathing_space == 0)
- breathing_space = (char *)malloc(4096 - MALLOC_OVERHEAD);
+ if (breathing_space == NULL) {
+ breathing_space = malloc(0xFFFF - MALLOC_OVERHEAD);
+ }
}
-#endif /* !HAVE_MMAP || DOUG_LEA_MALLOC */
+#endif /* !HAVE_MMAP || HAVE_GLIBC */
#ifdef ALLOC_NO_POOLS
# define TYPE_ALLOC_SIZE(type, structtype) 1
#define ALLOCATE_FIXED_TYPE(type, structtype, result) \
do { \
result = xnew(structtype); \
+ assert(result != NULL); \
INCREMENT_CONS_COUNTER(sizeof(structtype), #type); \
} while (0)
#define ALLOCATE_ATOMIC_FIXED_TYPE(type, structtype, result) \
do { \
result = xnew_atomic(structtype); \
+ assert(result != NULL); \
INCREMENT_CONS_COUNTER(sizeof(structtype), #type); \
} while (0)
/************************************************************************/
/* Float allocation */
/************************************************************************/
+/* used by many of the allocators below */
+#include "ent/ent.h"
#ifdef HAVE_FPFLOAT
#include <math.h>
return make_indef(POS_INFINITY);
else if (ENT_FLOAT_NINF_P(float_value))
return make_indef(NEG_INFINITY);
- else if (ENT_FLOAT_NAN_P(float_value))
+ else if (ENT_FLOAT_NAN_P(float_value))
return make_indef(NOT_A_NUMBER);
ALLOCATE_FIXED_TYPE(float, Lisp_Float, f);
make_bigz (long bigz_value)
{
Lisp_Bigz *b;
-
+
ALLOCATE_FIXED_TYPE(bigz, Lisp_Bigz, b);
bigz_register_finaliser(b);
/*** Big complex numbers with correct rounding ***/
#if defined HAVE_MPC && defined WITH_MPC || \
defined HAVE_PSEUC && defined WITH_PSEUC
+#include <ent/ent-mpc.h>
DECLARE_FIXED_TYPE_ALLOC(bigc, Lisp_Bigc);
#define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigc 250
Lisp_Object make_uninit_string(Bytecount length)
{
- Lisp_String *s;
+ Lisp_String *s = NULL;
#if !defined HAVE_BDWGC || !defined EF_USE_BDWGC
EMACS_INT fullsize = STRING_FULLSIZE(length);
#endif /* !BDWGC */
set_lheader_implementation(&s->lheader, &lrecord_string);
string_register_finaliser(s);
-#if defined HAVE_BDWGC && defined EF_USE_BDWGC
{
- Bufbyte *foo = xnew_atomic_array(Bufbyte, length+1);
- set_string_data(s, foo);
- }
+ Bufbyte *foo = NULL;
+#if defined HAVE_BDWGC && defined EF_USE_BDWGC
+ foo = xnew_atomic_array(Bufbyte, length+1);
+ assert(foo != NULL);
#else
- set_string_data(s, BIG_STRING_FULLSIZE_P(fullsize)
- ? xnew_atomic_array(Bufbyte, length + 1)
- : allocate_string_chars_struct(s, fullsize)->chars);
+ if (BIG_STRING_FULLSIZE_P(fullsize)) {
+ foo = xnew_atomic_array(Bufbyte, length + 1);
+ assert(foo != NULL);
+ } else {
+ foo = allocate_string_chars_struct(s, fullsize)->chars;
+ assert(foo != NULL);
+ }
#endif
-
+ set_string_data(s, foo);
+ }
set_string_length(s, length);
s->plist = Qnil;
#ifdef EF_USE_COMPRE
Lisp_Object build_string(const char *str)
{
/* Some strlen's crash and burn if passed null. */
- return make_string((const Bufbyte*)str, (str ? strlen(str) : 0));
+ if( str )
+ return make_string((const Bufbyte*)str, strlen(str));
+ else
+ abort();
+ return Qnil;
}
Lisp_Object build_ext_string(const char *str, Lisp_Object coding_system)
#ifdef EF_USE_COMPRE
s->compre = Qnil;
#endif
- set_string_data(s, (Bufbyte*)contents);
+ set_string_data(s, contents);
set_string_length(s, length);
XSETSTRING(val, s);
4) Calling free_managed_lcrecord() is just like kissing the
lcrecord goodbye as if it were garbage-collected. This means:
-- the contents of the freed lcrecord are undefined, and the
- contents of something produced by allocate_managed_lcrecord()
+ contents of something produced by allocate_managed_lcrecord()
are undefined, just like for alloc_lcrecord().
-- the mark method for the lcrecord's type will *NEVER* be called
- on freed lcrecords.
+ on freed lcrecords.
-- the finalize method for the lcrecord's type will be called
- at the time that free_managed_lcrecord() is called.
+ at the time that free_managed_lcrecord() is called.
lcrecord lists do not work in bdwgc mode. -hrop
\f
/* Free all unmarked records */
#if !defined HAVE_BDWGC || !defined EF_USE_BDWGC
-static void
+static void
sweep_lcrecords_1(struct lcrecord_header *volatile*prev, int *used)
{
int num_used = 0;
{
#define UNMARK_bigq(ptr) UNMARK_RECORD_HEADER(&((ptr)->lheader))
#define ADDITIONAL_FREE_bigq(ptr) bigq_fini(ptr->data)
-
+
SWEEP_FIXED_TYPE_BLOCK(bigq, Lisp_Bigq);
}
#endif /* HAVE_MPQ */
{
#define UNMARK_bigf(ptr) UNMARK_RECORD_HEADER(&((ptr)->lheader))
#define ADDITIONAL_FREE_bigf(ptr) bigf_fini(ptr->data)
-
+
SWEEP_FIXED_TYPE_BLOCK(bigf, Lisp_Bigf);
}
#endif /* HAVE_MPF */
{
#define UNMARK_bigfr(ptr) UNMARK_RECORD_HEADER(&((ptr)->lheader))
#define ADDITIONAL_FREE_bigfr(ptr) bigfr_fini(ptr->data)
-
+
SWEEP_FIXED_TYPE_BLOCK(bigfr, Lisp_Bigfr);
}
#endif /* HAVE_MPFR */
{
#define UNMARK_bigg(ptr) UNMARK_RECORD_HEADER(&((ptr)->lheader))
#define ADDITIONAL_FREE_bigg(ptr) bigg_fini(ptr->data)
-
+
SWEEP_FIXED_TYPE_BLOCK(bigg, Lisp_Bigg);
}
#endif /* HAVE_PSEUG */
{
#define UNMARK_bigc(ptr) UNMARK_RECORD_HEADER(&((ptr)->lheader))
#define ADDITIONAL_FREE_bigc(ptr) bigc_fini(ptr->data)
-
+
SWEEP_FIXED_TYPE_BLOCK(bigc, Lisp_Bigc);
}
#endif /* HAVE_MPC */
{
#define UNMARK_quatern(ptr) UNMARK_RECORD_HEADER(&((ptr)->lheader))
#define ADDITIONAL_FREE_quatern(ptr) quatern_fini(ptr->data)
-
+
SWEEP_FIXED_TYPE_BLOCK(quatern, Lisp_Quatern);
}
#endif /* HAVE_QUATERN */
/* Put all unmarked bignums on free list */
sweep_bigzs();
#endif /* HAVE_MPZ */
-
+
#if defined HAVE_MPQ && defined WITH_GMP
/* Put all unmarked ratios on free list */
sweep_bigqs();
#endif /* HAVE_MPQ */
-
+
#if defined HAVE_MPF && defined WITH_GMP
/* Put all unmarked bigfloats on free list */
sweep_bigfs();
unbind_to(speccount, Qnil);
if (!breathing_space) {
- breathing_space = malloc(4096 - MALLOC_OVERHEAD);
+ breathing_space = malloc(0xFFFF - MALLOC_OVERHEAD);
}
UNGCPRO;
/* Okay, simple pluralization check for
`symbol-value-varalias' */
if (name[len - 1] == 's')
- sz = snprintf(buf, sizeof(buf), "%ses-freed", name);
+ sz = snprintf(buf, sizeof(buf), "%ses-freed", name);
else
sz = snprintf(buf, sizeof(buf), "%ss-freed", name);
assert(sz >=0 && (size_t)sz < sizeof(buf));
2. When using the new allocator (gmalloc.c):
-- blocks are always allocated in chunks of powers of two up
- to 4096 bytes. Larger blocks are allocated in chunks of
+ to 4096 bytes. Larger blocks are allocated in chunks of
an integral multiple of 4096 bytes. The minimum block
- size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
+ size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
is defined. There is no per-block overhead, but there
is an overhead of 3*sizeof (size_t) for each 4096 bytes
allocated.
{
size_t orig_claimed_size = claimed_size;
-#ifdef GNU_MALLOC
+#ifdef HAVE_GLIBC
if (claimed_size < 2 * sizeof(void *))
claimed_size = 2 * sizeof(void *);
claimed_size += (claimed_size / 4096) * 3 * sizeof(size_t);
}
-#elif defined (SYSTEM_MALLOC)
+#else
if (claimed_size < 16)
claimed_size = 16;
claimed_size += 2 * sizeof(void *);
-#else /* old GNU allocator */
-
-# ifdef rcheck /* #### may not be defined here */
- claimed_size += 20;
-# else
- claimed_size += 8;
-# endif
- {
- int _log_ = 1;
-
- /* compute the log base two, more or less, then use it to compute
- the block size needed. */
- claimed_size--;
- /* It's big, it's heavy, it's wood! */
- while ((claimed_size /= 2) != 0)
- ++_log_;
- claimed_size = 1;
- /* It's better than bad, it's good! */
- while (_log_ > 0) {
- claimed_size *= 2;
- _log_--;
- }
- }
-
-#endif /* old GNU allocator */
+#endif /* HAVE_GLIBC */
if (stats) {
stats->was_requested += orig_claimed_size;
void reinit_alloc_once_early(void)
{
gc_generation_number[0] = 0;
- breathing_space = 0;
+ breathing_space = NULL;
XSETINT(all_bit_vectors, 0); /* Qzero may not be set yet. */
XSETINT(Vgc_message, 0);
#if !defined HAVE_BDWGC || !defined EF_USE_BDWGC
all_lcrecords = 0;
#endif /* !BDWGC */
ignore_malloc_warnings = 1;
-#ifdef DOUG_LEA_MALLOC
+#ifdef HAVE_GLIBC
mallopt(M_TRIM_THRESHOLD, 128 * 1024); /* trim threshold */
mallopt(M_MMAP_THRESHOLD, 64 * 1024); /* mmap threshold */
#if 1 /* Moved to emacs.c */