#ifdef emacs
#include <config.h>
#include "lisp.h"
#endif
#ifndef emacs
#include <stddef.h>
typedef size_t SIZE;
typedef void *POINTER;
#define EXCEEDS_LISP_PTR(x) 0
#endif
#include "mem-limits.h"
static int warnlevel;
static void (*warn_function) ();
static void
check_memory_limits ()
{
#ifdef REL_ALLOC
extern POINTER (*real_morecore) ();
#endif
extern POINTER (*__morecore) ();
register POINTER cp;
unsigned long five_percent;
unsigned long data_size;
if (lim_data == 0)
get_lim_data ();
five_percent = lim_data / 20;
#ifdef REL_ALLOC
if (real_morecore)
cp = (char *) (*real_morecore) (0);
else
#endif
cp = (char *) (*__morecore) (0);
data_size = (char *) cp - (char *) data_space_start;
if (warn_function)
switch (warnlevel)
{
case 0:
if (data_size > five_percent * 15)
{
warnlevel++;
(*warn_function) ("Warning: past 75% of memory limit");
}
break;
case 1:
if (data_size > five_percent * 17)
{
warnlevel++;
(*warn_function) ("Warning: past 85% of memory limit");
}
break;
case 2:
if (data_size > five_percent * 19)
{
warnlevel++;
(*warn_function) ("Warning: past 95% of memory limit");
}
break;
default:
(*warn_function) ("Warning: past acceptable memory limits");
break;
}
if (data_size < five_percent * 14)
warnlevel = 0;
else if (warnlevel > 1 && data_size < five_percent * 16)
warnlevel = 1;
else if (warnlevel > 2 && data_size < five_percent * 18)
warnlevel = 2;
if (EXCEEDS_LISP_PTR (cp))
(*warn_function) ("Warning: memory in use exceeds lisp pointer size");
}
void
memory_warnings (start, warnfun)
POINTER start;
void (*warnfun) ();
{
extern void (* __after_morecore_hook) ();
if (start)
data_space_start = start;
else
data_space_start = start_of_data ();
warn_function = warnfun;
__after_morecore_hook = check_memory_limits;
#ifdef WINDOWSNT
lim_data = 0;
#endif
}