Wild Life  2.29
 All Data Structures Files Functions Variables Typedefs Macros
Macros | Functions | Variables
memory.c File Reference

memory management More...

Go to the source code of this file.

Macros

#define LONELY   1
 
#define assert(N)
 
#define UNCHECKED(P)   (! *((GENERIC)(P)+delta))
 

Functions

char * GetStrOption (char *name, char *def)
 GetStrOption. More...
 
int GetBoolOption (char *name)
 GetBoolOption. More...
 
int GetIntOption (char *name, int def)
 GetIntOption. More...
 
void pchoices ()
 pchoices More...
 
void print_undo_stack ()
 print_undo_stack More...
 
long bounds_undo_stack ()
 bounds_undo_stack More...
 
static void check_psi_list ()
 
static void check_resid_list ()
 
static void check_choice ()
 
static void check_undo_stack ()
 
void fail_all ()
 fail_all More...
 
static void compress ()
 compress More...
 
static long unchecked (GENERIC *p, long len)
 unchecked More...
 
static void check_string (GENERIC *s)
 check_string More...
 
static void check_bytedata (GENERIC *s)
 check_bytedata More...
 
static void check_code (ptr_int_list *c)
 check_code More...
 
static void check_pair_list (ptr_pair_list *p)
 check_pair_list More...
 
static void check_triple_list (ptr_triple_list *p)
 check_triple_list More...
 
static void check_kids (ptr_int_list *c)
 check_kids More...
 
static void check_operator_data (ptr_operator_data *op)
 check_operator_data More...
 
static void check_module ()
 
static void check_keyword ()
 
static void check_module_list (ptr_int_list *c)
 check_module_list More...
 
static void check_module_tree (ptr_node *n)
 check_module_tree More...
 
static void check_module (ptr_module *m)
 check_module More...
 
void check_hash_table (ptr_hash_table table)
 check_hash_table More...
 
static void check_keyword (ptr_keyword *k)
 check_keyword More...
 
void check_definition (ptr_definition *d)
 check_definition More...
 
void check_definition_list ()
 check_definition_list More...
 
static void check_def_code (ptr_definition *d)
 check_def_code More...
 
static void check_def_rest (ptr_definition *d)
 check_def_rest More...
 
static void check_symbol (ptr_node *n)
 check_symbol More...
 
static void check_type_disj (ptr_int_list *p)
 check_type_disj More...
 
static void check_goal_stack (ptr_goal *g)
 check_goal_stack More...
 
static void check_resid (ptr_residuation *r)
 check_resid More...
 
void check_resid_block (ptr_resid_block *rb)
 check_resid_block More...
 
void check_psi_term (ptr_psi_term *t)
 check_psi_term More...
 
void check_attr (ptr_node *n)
 check_attr More...
 
void check_gamma_code ()
 check_gamma_code More...
 
static void check_gamma_rest ()
 check_gamma_rest More...
 
static void check_undo_stack (ptr_stack *s)
 check_undo_stack More...
 
static void check_choice_structs (ptr_choice_point *c)
 check_choice_structs More...
 
static void check_choice (ptr_choice_point *c)
 check_choice More...
 
static void check_special_addresses ()
 check_special_addresses More...
 
static void check_psi_list (ptr_int_list *l)
 check_psi_list More...
 
static void check_resid_list (ptr_resid_list *l)
 check_resid_list More...
 
static void check_var (ptr_node *n)
 
static void check ()
 check More...
 
void print_gc_info (long timeflag)
 print_gc_info More...
 
void garbage ()
 garbage More...
 
GENERIC heap_alloc (long s)
 heap_alloc More...
 
GENERIC stack_alloc (long s)
 stack_alloc More...
 
void init_memory ()
 init_memory () More...
 
long memory_check ()
 memory_check More...
 

Variables

static long delta
 
static long pass
 
static struct tms last_garbage_time
 
static float gc_time
 
static float life_time
 

Detailed Description

memory management

Definition in file memory.c.

Macro Definition Documentation

#define assert (   N)

Definition at line 113 of file memory.c.

#define LONELY   1

Definition at line 24 of file memory.c.

#define UNCHECKED (   P)    (! *((GENERIC)(P)+delta))

Definition at line 317 of file memory.c.

Function Documentation

long bounds_undo_stack ( )

bounds_undo_stack

Address field in undo_stack is within range The only valid address outside this range is that of xevent_state

Definition at line 142 of file memory.c.

References wl_stack::aaaa_3, FALSE, mem_base, mem_limit, wl_stack::next, TRUE, wl_stack::type, undo_action, undo_stack, and VALID_ADDRESS.

143 {
145 
146  while (u) {
147  if ( (GENERIC)u<mem_base
148  || (GENERIC)u>mem_limit
149  || (!VALID_ADDRESS(u->aaaa_3) && !(u->type & undo_action))
150  ) {
151  if ((GENERIC)u<mem_base || (GENERIC)u>mem_limit) {
152  printf("\nUNDO: u=%lx\n",(long)u);
153  }
154  else {
155  printf("\nUNDO: u:%lx type:%ld a:%lx b:%lx next:%lx\n",
156  (unsigned long)u,(unsigned long)u->type,(unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3,(unsigned long)u->next);
157  }
158  (void)fflush(stdout);
159  return FALSE;
160  }
161  u=u->next;
162  }
163 
164  return TRUE;
165 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:132
GENERIC mem_limit
Definition: def_glob.h:13
ptr_stack undo_stack
Definition: def_glob.h:53
type_ptr type
Definition: def_struct.h:216
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
GENERIC mem_base
Definition: def_glob.h:11
GENERIC * aaaa_3
Definition: def_struct.h:217
#define undo_action
Definition: def_const.h:188
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_stack next
Definition: def_struct.h:219
static void check ( )
static

check

CHECK This routine checks all pointers and psi_terms to find out which memory cells must be preserved and which can be discarded.

This routine explores all known structures. It is vital that it should visit them all exactly once. It thus creates a map of what is used in memory, which COMPRESS uses to compact the memory and recalculate the addresses. Exploration of these structures should be done in exactly the same order in both passes. If it is the second pass, pointers are assigned their new values.

A crucial property of this routine: In pass 2, a global variable (i.e. a root for GC) must be updated before it is accessed. E.g. don't use the variable goal_stack before updating it.

Definition at line 1299 of file memory.c.

References aborthooksym, abortsym, add_module1, add_module2, add_module3, aim, alist, and, apply, assert, bi_module, boolpredsym, bounds_undo_stack(), built_in, call_handlersym, check_choice(), check_choice_structs(), check_definition(), check_definition_list(), check_gamma_code(), check_gamma_rest(), check_goal_stack(), check_module(), check_module_tree(), check_psi_term(), check_resid_list(), check_special_addresses(), check_string(), check_sys_definitions(), check_undo_stack(), check_var(), choice_stack, colonsym, commasym, comment, constant, current_module, cut, day_attr, delay_checksym, disj_nil, disjunction, dynamicsym, encodesym, eof, eqsym, error_psi_term, eval_argsym, final_dot, final_question, funcsym, functor, fx_sym, fy_sym, goal_stack, hour_attr, iff, input_state, inputfilesym, integer, lf_false, lf_true, life_or, listingsym, loadsym, minus_symbol, minute_attr, module_table, month_attr, nil, no_module, nothing, null_psi_term, nullsym, old_saved_psi_term, old_state, one, opsym, pass, predsym, quote, quoted_string, real, resid_aim, resid_vars, saved_psi_term, second_attr, staticsym, stdin_state, stream, succeed, such_that, syntax_module, sys_module, three, timesym, top, tracesym, TRUE, two, typesym, undo_stack, user_module, var_tree, variable, weekday_attr, x_module, xbutton_event, xconfigure_event, xdestroy_event, xdisplay, xdisplaylist, xdrawable, xenter_event, xevent, xevent_existing, xevent_list, xexpose_event, xf_sym, xfx_sym, xfy_sym, xgc, xkeyboard_event, xleave_event, xmisc_event, xmotion_event, xpixmap, xwindow, year_attr, yf_sym, and yfx_sym.

1300 {
1301 #ifdef prlDEBUG
1302  amount_used=0;
1303 #endif
1304 
1305  /* First of all, get all the codes right so that data type-checking remains
1306  coherent.
1307 
1308  Kids and Parents cannot be checked because the built-in types have codes
1309  which might have been moved.
1310  */
1311  /* print_undo_stack(); */
1312 
1313 
1314  check_choice_structs(&choice_stack); /* RM: Oct 28 1993 */
1315 
1317  check_gamma_code();
1318 
1319  /* Now, check the rest of the definitions and all global roots */
1320 
1321  check_gamma_rest();
1322 
1324 
1325  check_definition(&abortsym); /* 26.1 */
1326  check_definition(&aborthooksym); /* 26.1 */
1327 
1328  check_definition(&add_module1); /* RM: Mar 12 1993 */
1331 
1334  check_definition(&boolean);
1340  /* check_definition(&conjunction); 19.8 */
1344  check_definition(&disj_nil); /* RM: Feb 16 1993 */
1353  check_definition(&life_or); /* RM: Apr 6 1993 */
1354  check_definition(&minus_symbol); /* RM: Jun 21 1993 */
1355  check_definition(&nil); /* RM: Dec 9 1992 */
1367  check_definition(&tracesym); /* 26.1 */
1376  /* check_definition(&provesym); */
1389 
1390  /* RM: Jul 7 1993 */
1393 
1395 
1396 #ifdef X11
1413 #endif
1414 
1415  /* check_psi_term(&empty_list); 5.8 */
1416 
1417  check_string((GENERIC *)&one); // added cast DJD 12/8/2016
1418  check_string((GENERIC *)&two); // added cast DJD 12/8/2016
1419  check_string((GENERIC *)&three); // added cast DJD 12/8/2016
1420  check_string((GENERIC *)&year_attr); // added cast DJD 12/8/2016
1421  check_string((GENERIC *)&month_attr); // added cast DJD 12/8/2016
1422  check_string((GENERIC *)&day_attr); // added cast DJD 12/8/2016
1423  check_string((GENERIC *)&hour_attr); // added cast DJD 12/8/2016
1424  check_string((GENERIC *)&minute_attr); // added cast DJD 12/8/2016
1425  check_string((GENERIC *)&second_attr); // added cast DJD 12/8/2016
1426  check_string((GENERIC *)&weekday_attr); // added cast DJD 12/8/2016
1427 
1434  check_psi_term(&old_state); /* RM: Feb 17 1993 */
1435 
1437 #ifdef X11
1440 #endif
1441 
1443  /* check_choice(&prompt_choice_stack); 12.7 */
1444 
1445 
1446  /* RM: Feb 3 1993 */
1447  /* check_symbol(&symbol_table); */
1448  /* check_definition(&first_definition); */
1449  check_definition_list(); /* RM: Feb 15 1993 */
1450 
1451 
1452  /*** MODULES ***/
1453  /* RM: Jan 13 1993 */
1454 
1458  check_module(&user_module); /* RM: Jan 27 1993 */
1463 
1464  /*** End ***/
1465 
1466 
1467 
1468  check_var(&var_tree);
1469 
1470  check_goal_stack((ptr_goal *)&goal_stack); // added cast DJD 12/8/2016
1471  check_goal_stack((ptr_goal *)&aim); /* 7.10 */ // added cast DJD 12/8/2016
1472 
1473  if (TRUE /*resid_aim 10.6 */) check_resid_list(&resid_vars); /* 21.9 */
1474 
1475  check_goal_stack((ptr_goal *)&resid_aim); // added cast DJD 12/8/2016
1476 
1479 
1482 
1484 }
ptr_definition encodesym
Definition: def_glob.h:116
ptr_definition such_that
Definition: def_glob.h:105
ptr_definition boolpredsym
Definition: def_glob.h:74
static void check_undo_stack()
ptr_definition abortsym
Definition: def_glob.h:64
ptr_definition timesym
Definition: def_glob.h:108
static void check_resid_list()
ptr_definition xfy_sym
Definition: def_glob.h:127
ptr_definition staticsym
Definition: def_glob.h:115
ptr_psi_term stdin_state
Definition: def_glob.h:200
ptr_definition loadsym
Definition: def_glob.h:113
ptr_goal goal_stack
Definition: def_glob.h:50
ptr_module current_module
Definition: def_glob.h:161
ptr_definition dynamicsym
Definition: def_glob.h:114
ptr_definition opsym
Definition: def_glob.h:112
ptr_definition comment
Definition: def_glob.h:80
ptr_definition xdisplaylist
Definition: def_glob.h:211
ptr_definition stream
Definition: def_glob.h:103
ptr_psi_term xevent_list
Definition: def_glob.h:208
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:800
ptr_definition xbutton_event
Definition: def_glob.h:211
ptr_definition listingsym
Definition: def_glob.h:117
ptr_psi_term old_state
Definition: def_glob.h:142
char * two
Definition: def_glob.h:251
ptr_definition commasym
Definition: def_glob.h:79
ptr_psi_term null_psi_term
Definition: def_glob.h:140
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
ptr_definition fy_sym
Definition: def_glob.h:125
static void check_special_addresses()
check_special_addresses
Definition: memory.c:1202
static long pass
Definition: memory.c:21
ptr_definition aborthooksym
Definition: def_glob.h:65
ptr_definition xexpose_event
Definition: def_glob.h:211
ptr_definition constant
Definition: def_glob.h:82
ptr_module user_module
Definition: def_glob.h:156
ptr_definition top
Definition: def_glob.h:106
ptr_node var_tree
Definition: def_glob.h:26
ptr_psi_term input_state
Definition: def_glob.h:199
ptr_definition quote
Definition: def_glob.h:100
static void check_module()
char * three
Definition: def_glob.h:252
ptr_definition apply
Definition: def_glob.h:72
ptr_definition xgc
Definition: def_glob.h:211
ptr_goal resid_aim
Definition: def_glob.h:220
ptr_definition xmotion_event
Definition: def_glob.h:211
ptr_resid_list resid_vars
Definition: def_glob.h:221
ptr_definition xmisc_event
Definition: def_glob.h:211
ptr_definition minus_symbol
Definition: def_glob.h:96
static void check_choice()
ptr_definition xfx_sym
Definition: def_glob.h:126
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
ptr_definition add_module3
Definition: def_glob.h:69
ptr_stack undo_stack
Definition: def_glob.h:53
ptr_definition yf_sym
Definition: def_glob.h:124
ptr_definition disj_nil
Definition: def_glob.h:85
ptr_definition nullsym
Definition: def_glob.h:129
ptr_definition real
Definition: def_glob.h:102
ptr_definition alist
Definition: def_glob.h:94
static void check_choice_structs(ptr_choice_point *c)
check_choice_structs
Definition: memory.c:1169
ptr_definition functor
Definition: def_glob.h:91
ptr_definition eqsym
Definition: def_glob.h:87
ptr_definition eof
Definition: def_glob.h:86
ptr_definition xkeyboard_event
Definition: def_glob.h:211
#define TRUE
Definition: def_const.h:127
ptr_definition xwindow
Definition: def_glob.h:211
ptr_psi_term error_psi_term
Definition: def_glob.h:23
ptr_definition built_in
Definition: def_glob.h:75
ptr_definition integer
Definition: def_glob.h:93
ptr_definition lf_true
Definition: def_glob.h:107
ptr_definition iff
Definition: def_glob.h:92
ptr_definition final_dot
Definition: def_glob.h:137
ptr_definition quoted_string
Definition: def_glob.h:101
ptr_definition succeed
Definition: def_glob.h:104
ptr_definition and
Definition: def_glob.h:71
ptr_node module_table
Definition: def_glob.h:160
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
ptr_definition lf_false
Definition: def_glob.h:89
ptr_module syntax_module
Definition: def_glob.h:159
ptr_goal aim
Definition: def_glob.h:49
char * weekday_attr
Definition: def_glob.h:259
ptr_definition disjunction
Definition: def_glob.h:84
ptr_definition xpixmap
Definition: def_glob.h:211
char * one
Definition: def_glob.h:250
ptr_definition xenter_event
Definition: def_glob.h:211
ptr_definition xevent
Definition: def_glob.h:211
ptr_definition add_module2
Definition: def_glob.h:68
ptr_definition life_or
Definition: def_glob.h:95
ptr_definition delay_checksym
Definition: def_glob.h:118
void check_definition_list()
check_definition_list
Definition: memory.c:699
ptr_definition yfx_sym
Definition: def_glob.h:128
ptr_definition final_question
Definition: def_glob.h:138
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
ptr_module sys_module
Definition: def_glob.h:162
ptr_definition add_module1
Definition: def_glob.h:67
ptr_definition tracesym
Definition: def_glob.h:109
ptr_definition xdisplay
Definition: def_glob.h:211
void check_gamma_code()
check_gamma_code
Definition: memory.c:1078
static void check_var(ptr_node *n)
Definition: memory.c:1270
ptr_definition fx_sym
Definition: def_glob.h:123
char * minute_attr
Definition: def_glob.h:257
ptr_definition cut
Definition: def_glob.h:83
ptr_module x_module
Definition: def_glob.h:158
ptr_definition xdestroy_event
Definition: def_glob.h:211
static void check_module_tree(ptr_node *n)
check_module_tree
Definition: memory.c:587
ptr_definition nothing
Definition: def_glob.h:98
ptr_definition nil
Definition: def_glob.h:97
char * year_attr
Definition: def_glob.h:253
ptr_module no_module
Definition: def_glob.h:157
char * second_attr
Definition: def_glob.h:258
ptr_definition xleave_event
Definition: def_glob.h:211
char * day_attr
Definition: def_glob.h:255
static void check_gamma_rest()
check_gamma_rest
Definition: memory.c:1095
ptr_module bi_module
Definition: def_glob.h:155
ptr_definition predsym
Definition: def_glob.h:99
char * hour_attr
Definition: def_glob.h:256
void check_sys_definitions()
check_sys_definitions
Definition: sys.c:2192
ptr_definition xconfigure_event
Definition: def_glob.h:211
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_psi_term xevent_existing
Definition: def_glob.h:208
ptr_definition xf_sym
Definition: def_glob.h:122
long bounds_undo_stack()
bounds_undo_stack
Definition: memory.c:142
ptr_definition colonsym
Definition: def_glob.h:78
ptr_definition inputfilesym
Definition: def_glob.h:120
ptr_definition variable
Definition: def_glob.h:111
ptr_definition call_handlersym
Definition: def_glob.h:121
ptr_choice_point choice_stack
Definition: def_glob.h:51
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195
ptr_definition eval_argsym
Definition: def_glob.h:119
ptr_definition funcsym
Definition: def_glob.h:90
char * month_attr
Definition: def_glob.h:254
ptr_definition typesym
Definition: def_glob.h:110
#define assert(N)
Definition: memory.c:113
ptr_definition xdrawable
Definition: def_glob.h:211
void check_attr ( ptr_node n)

check_attr

Parameters
ptr_node*n

CHECK_ATTR(attribute-tree) Check an attribute tree. (Could improve this by randomly picking left or right subtree for last call optimization. This would never overflow, even on very skewed attribute trees.)

Definition at line 1054 of file memory.c.

References check_psi_term(), check_string(), and unchecked().

1055 {
1056  while (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
1057  check_attr(&((*n)->left));
1058  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
1059  check_psi_term((struct wl_psi_term **)&((*n)->data));
1060 
1061  n = &((*n)->right);
1062  /* check_attr(&((*n)->right)); 9.6 */
1063  }
1064 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
unsigned long * GENERIC
Definition: def_struct.h:17
void check_attr(ptr_node *n)
check_attr
Definition: memory.c:1054
static void check_bytedata ( GENERIC s)
static

check_bytedata

Parameters
GENERIC*s

CHECK_BYTEDATA(s) Claim the memory used by a block of bytes

Definition at line 450 of file memory.c.

References delta, MAX_BUILT_INS, pass, and unchecked().

451 {
452  GENERIC addr;
453  long value;
454  if ((unsigned long) *s > MAX_BUILT_INS) {
455  unsigned long bytes = *((unsigned long *) *s);
456  unsigned long size = bytes + sizeof(bytes);
457  switch (pass) {
458  case 1:
459  (void)unchecked((GENERIC *)s,size);
460  break;
461  case 2:
462  addr=(*s+delta);
463  value= *addr;
464  if (value & 1) {
465  value--;
466  *s=(GENERIC) value;
467  *addr=value;
468 #ifdef prlDEBUG
469  amount_used+=size;
470 #endif
471  }
472  *s=(GENERIC)value;
473  break;
474  }
475  }
476 }
static long delta
Definition: memory.c:12
static long pass
Definition: memory.c:21
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
#define MAX_BUILT_INS
Definition: def_const.h:82
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_choice ( )
static
static void check_choice ( ptr_choice_point c)
static

check_choice

Parameters
ptr_choice_point*c

CHECK_CHOICE(c) This routine checks all choice points.

Definition at line 1184 of file memory.c.

References check_goal_stack(), and check_undo_stack().

1185 {
1186  while(*c) {
1187  check_undo_stack(&((*c)->undo_point)); /* 17.7 */
1188  check_goal_stack((ptr_goal *)&((*c)->goal_stack)); // added cast DJD 12/8/2016
1189  c= &((*c)->next);
1190  }
1191 }
static void check_undo_stack()
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:800
static void check_choice_structs ( ptr_choice_point c)
static

check_choice_structs

Parameters
ptr_choice_point*c

Definition at line 1169 of file memory.c.

References unchecked().

1170 {
1171  while(unchecked((GENERIC *)c,sizeof(choice_point))) { // added cast DJD 12/8/2016
1172  c= &((*c)->next);
1173  }
1174 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_code ( ptr_int_list c)
static

check_code

Parameters
ptr_int_list*c

CHECK_CODE(c) Claim the memory used by a type code (=list of integers).

Definition at line 486 of file memory.c.

References unchecked().

487 {
488  while (unchecked((GENERIC *)c,sizeof(int_list))) // added cast DJD 12/8/2016
489  c= &((*c)->next);
490 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_def_code ( ptr_definition d)
static

check_def_code

Parameters
ptr_definition*d

CHECK_DEF_CODE(d) This routine checks the CODE field in a definition. It may only be invoked by CHECK_GAMMA.

Definition at line 720 of file memory.c.

References check_code(), and unchecked().

721 {
722  if (unchecked((GENERIC *)d,sizeof(definition))) // added cast DJD 12/8/2016
723  check_code((ptr_int_list *)&((*d)->code)); // added cast DJD 12/8/2016
724  /* p = &((*d)->properties); */
725  /* check_def_prop(p); */
726 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:486
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_def_rest ( ptr_definition d)
static

check_def_rest

Parameters
ptr_definition*d

CHECK_DEF_REST(d) This routine checks the other fields in a definition. It may only be invoked by CHECK_GAMMA_REST.

Definition at line 737 of file memory.c.

References check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_triple_list(), and type_it.

738 {
739  if (*d) {
740  check_keyword((ptr_keyword *)&((*d)->keyword)); /* RM: Jan 12 1993 */ // added cast DJD 12/8/2016
741  check_pair_list((ptr_pair_list *)&((*d)->rule)); // added cast DJD 12/8/2016
742  check_triple_list(&((*d)->properties));
743 
744  if ((*d)->type_def==(def_type)type_it) {
745  check_kids(&((*d)->parents));
746  check_kids(&((*d)->children));
747  }
748  check_operator_data(&((*d)->op_data)); /* PVR 5.6 */
749 #ifdef CLIFE
750  check_block_def(&((*d)->block_def)); /*CB 25/01/93 */
751 #endif /* CLIFE */
752  }
753 }
static void check_operator_data(ptr_operator_data *op)
check_operator_data
Definition: memory.c:551
static void check_pair_list(ptr_pair_list *p)
check_pair_list
Definition: memory.c:500
#define type_it
Definition: def_const.h:363
static void check_kids(ptr_int_list *c)
check_kids
Definition: memory.c:535
static void check_triple_list(ptr_triple_list *p)
check_triple_list
Definition: memory.c:517
static void check_keyword()
void check_definition ( ptr_definition d)

check_definition

Parameters
ptr_definition*d

CHECK_DEFINITION This goes through the type tree which contains the parents and children lists for all types, and the attributed code. The code field is not checked as this has been done separately by CHECK_GAMMA.

Definition at line 662 of file memory.c.

References check_code(), check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_psi_term(), check_triple_list(), wl_definition::keyword, wl_keyword::symbol, type_it, and unchecked().

663 {
664  if(unchecked((GENERIC *)d,sizeof(definition))) { // added cast DJD 12/8/2016
665 
666  check_keyword((ptr_keyword *)&((*d)->keyword)); /* RM: Jan 12 1993 */ // added cast DJD 12/8/2016
667 
668 #ifdef prlDEBUG
669  printf("%lx %20s %ld\n",*d,(*d)->keyword->symbol,amount_used);
670 #endif
671 
672  check_code((ptr_int_list *)&((*d)->code)); // added cast DJD 12/8/2016
673  check_pair_list((ptr_pair_list *)&((*d)->rule)); // added cast DJD 12/8/2016
674  check_triple_list(&((*d)->properties));
675 
676  if ((*d)->type_def==(def_type)type_it) {
677  check_kids(&((*d)->parents));
678  check_kids(&((*d)->children));
679  }
680 
681  check_psi_term(&((*d)->global_value)); /* RM: Feb 9 1993 */
682  check_psi_term(&((*d)->init_value)); /* RM: Mar 23 1993 */
683 
684  check_operator_data(&((*d)->op_data)); /* PVR 5.6 */
685 
686 #ifdef CLIFE
687  check_block_def(&((*d)->block_def)); /* RM: Jan 27 1993 */
688 #endif /* CLIFE */
689  }
690 }
static void check_operator_data(ptr_operator_data *op)
check_operator_data
Definition: memory.c:551
ptr_keyword keyword
Definition: def_struct.h:124
static void check_pair_list(ptr_pair_list *p)
check_pair_list
Definition: memory.c:500
char * symbol
Definition: def_struct.h:91
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
#define type_it
Definition: def_const.h:363
static void check_kids(ptr_int_list *c)
check_kids
Definition: memory.c:535
static void check_triple_list(ptr_triple_list *p)
check_triple_list
Definition: memory.c:517
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:486
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_keyword()
void check_definition_list ( )

check_definition_list

CHECK_DEFINITION_LIST This checks the entire list of definitions.

Definition at line 699 of file memory.c.

References check_definition(), and first_definition.

700 {
701  ptr_definition *d;
702 
703  d= &first_definition;
704 
705  while(*d) {
706  check_definition(d);
707  d= &((*d)->next);
708  }
709 }
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
ptr_definition first_definition
Definition: def_glob.h:3
void check_gamma_code ( )

check_gamma_code

CHECK_GAMMA_CODE() Check and update the code reversing table. In this part, only the codes are checked in the definitions, this is vital because these codes are used later to distinguish between the various data types and to determine the type of the VALUE field in psi_terms. Misunderstanding this caused a lot of bugs in the GC.

Definition at line 1078 of file memory.c.

References check_def_code(), gamma_table, type_count, and unchecked().

1079 {
1080  long i;
1081 
1082  if (unchecked((GENERIC *)&gamma_table,type_count*sizeof(ptr_definition))) { // added cast DJD 12/8/2016
1083  for (i=0;i<type_count;i++)
1084  check_def_code(&(gamma_table[i]));
1085  }
1086 }
long type_count
Definition: def_glob.h:46
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
static void check_def_code(ptr_definition *d)
check_def_code
Definition: memory.c:720
ptr_definition * gamma_table
Definition: def_glob.h:309
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_gamma_rest ( )
static

check_gamma_rest

CHECK_GAMMA_REST() Check and update the code reversing table.

Definition at line 1095 of file memory.c.

References check_def_rest(), gamma_table, and type_count.

1096 {
1097  long i;
1098 
1099  for (i=0;i<type_count;i++)
1100  check_def_rest(&(gamma_table[i]));
1101 }
long type_count
Definition: def_glob.h:46
ptr_definition * gamma_table
Definition: def_glob.h:309
static void check_def_rest(ptr_definition *d)
check_def_rest
Definition: memory.c:737
static void check_goal_stack ( ptr_goal g)
static

check_goal_stack

Parameters
ptr_goal*g

CHECK_GOAL_STACK Check the goal_stack. This is quite complicated as each type of goal (prove, unify, eval, eval_cut etc...) gives its own meanings to the three other fields (A,B and C) present in each goal.

Definition at line 800 of file memory.c.

References check_pair_list(), check_psi_term(), check_resid_block(), check_string(), check_type_disj(), choice_stack, clause, DEFRULES, del_clause, disj, Errorline(), eval, eval_cut, fail, freeze_cut, general_cut, implies_cut, load, LONELY, match, pass, prove, retract, type_disj, unchecked(), unify, unify_noeval, and what_next.

801 {
802  while (unchecked((GENERIC *)g,sizeof(goal))) { // added cast DJD 12/8/2016
803 
804  switch ((*g)->type) {
805 
806  case fail:
807  break;
808 
809  case unify:
810  case unify_noeval: /* PVR 5.6 */
811  check_psi_term(&((*g)->aaaa_1));
812  check_psi_term(&((*g)->bbbb_1));
813  break;
814 
815  case prove:
816  check_psi_term(&((*g)->aaaa_1));
817  if ((unsigned long)(*g)->bbbb_1!=DEFRULES) check_pair_list((ptr_pair_list *)&((*g)->bbbb_1)); // added cast DJD 12/8/2016
818  check_pair_list((ptr_pair_list *)&((*g)->cccc_1)); // added cast DJD 12/8/2016
819  break;
820 
821  case disj:
822  check_psi_term(&((*g)->aaaa_1));
823  check_psi_term(&((*g)->bbbb_1));
824  break;
825 
826  case what_next:
827  /* check_choice(&((*g)->bbbb_1)); */
828  break;
829 
830  case eval:
831  check_psi_term(&((*g)->aaaa_1));
832  check_psi_term(&((*g)->bbbb_1));
833  check_pair_list((ptr_pair_list *)&((*g)->cccc_1)); // added cast DJD 12/8/2016
834  break;
835 
836  case load:
837  check_psi_term(&((*g)->aaaa_1));
838  check_string((GENERIC *)&((*g)->cccc_1)); // added cast DJD 12/8/2016
839  break;
840 
841  case match:
842  check_psi_term(&((*g)->aaaa_1));
843  check_psi_term(&((*g)->bbbb_1));
844  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
845  break;
846 
847  case general_cut:
848  /* assert((GENERIC)(*g)->aaaa_3 <= (GENERIC)choice_stack); 12.7 17.7 */
849  if (pass==1 && (ptr_choice_point)(*g)->aaaa_1>choice_stack)
850  (*g)->aaaa_1=(ptr_psi_term)choice_stack;
851  (void)unchecked((GENERIC *)&((*g)->aaaa_1),LONELY); // added cast DJD 12/8/2016
852  break;
853 
854  case eval_cut:
855  check_psi_term(&((*g)->aaaa_1));
856  /* assert((GENERIC)(*g)->bbbb_1 <= (GENERIC)choice_stack); 12.7 17.7 */
857  if (pass==1 && (ptr_choice_point)(*g)->bbbb_1>choice_stack)
858  (*g)->bbbb_1=(ptr_psi_term)choice_stack;
859  (void)unchecked((GENERIC *)&((*g)->bbbb_1),LONELY); // added cast DJD 12/8/2016
860  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
861  break;
862 
863  case freeze_cut:
864  case implies_cut:
865  check_psi_term(&((*g)->aaaa_1));
866  /* assert((GENERIC)(*g)->bbbb_1 <= (GENERIC)choice_stack); 12.7 17.7 */
867  if (pass==1 && (ptr_choice_point)(*g)->bbbb_1>choice_stack)
868  (*g)->bbbb_1=(ptr_psi_term)choice_stack;
869  (void)unchecked((GENERIC *)&((*g)->bbbb_1),LONELY); // added cast DJD 12/8/2016
870  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
871  break;
872 
873  case type_disj:
874  check_psi_term(&((*g)->aaaa_1));
875  check_type_disj((ptr_int_list *)&((*g)->bbbb_1)); // added cast DJD 12/8/2016
876  break;
877 
878  case clause:
879  check_psi_term(&((*g)->aaaa_1));
880  check_psi_term(&((*g)->bbbb_1));
881  (void)unchecked((GENERIC *)&((*g)->cccc_1),LONELY); // added cast DJD 12/8/2016
882  /* check_pair_list((*g)->cccc_1); */ /* 6.8 */
883  break;
884 
885  case del_clause:
886  check_psi_term(&((*g)->aaaa_1));
887  check_psi_term(&((*g)->bbbb_1));
888  (void)unchecked((GENERIC *)&((*g)->cccc_1),LONELY); // added cast DJD 12/8/2016
889  /* check_pair_list((*g)->cccc_1); */ /* 6.8 */
890  break;
891 
892  case retract:
893  (void)unchecked((GENERIC *)&((*g)->aaaa_1),LONELY); // added cast DJD 12/8/2016
894  /* check_pair_list((*g)->aaaa_1); */ /* 6.8 */
895  /*PVR*/ /* check_choice(&((*g)->bbbb_1)); 9.6 */
896  break;
897 
898  default:
899  Errorline("in garbage collection, bad goal on stack.\n");
900  }
901 
902  g= &((*g)->next);
903  }
904 }
#define prove
Definition: def_const.h:273
static void check_type_disj(ptr_int_list *p)
check_type_disj
Definition: memory.c:782
#define general_cut
Definition: def_const.h:282
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
#define implies_cut
Definition: def_const.h:281
#define DEFRULES
Definition: def_const.h:138
static long pass
Definition: memory.c:21
static void check_pair_list(ptr_pair_list *p)
check_pair_list
Definition: memory.c:500
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
#define eval
Definition: def_const.h:278
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
void check_resid_block(ptr_resid_block *rb)
check_resid_block
Definition: memory.c:965
#define freeze_cut
Definition: def_const.h:280
#define what_next
Definition: def_const.h:277
#define match
Definition: def_const.h:283
#define clause
Definition: def_const.h:285
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
#define fail
Definition: def_const.h:272
#define retract
Definition: def_const.h:287
#define unify
Definition: def_const.h:274
#define load
Definition: def_const.h:288
#define unify_noeval
Definition: def_const.h:275
#define del_clause
Definition: def_const.h:286
#define eval_cut
Definition: def_const.h:279
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
#define disj
Definition: def_const.h:276
#define type_disj
Definition: def_const.h:284
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_choice_point choice_stack
Definition: def_glob.h:51
void check_hash_table ( ptr_hash_table  table)

check_hash_table

Parameters
ptr_hash_tabletable

CHECK_HASH_TABLE(table) Check a hash table of keywords. The actual table is not stored within LIFE memory.

Definition at line 625 of file memory.c.

References check_keyword(), wl_hash_table::data, and wl_hash_table::size.

626 {
627  long i;
628 
629  for(i=0;i<table->size;i++)
630  if(table->data[i])
631  check_keyword((ptr_keyword *)&(table->data[i]));
632 }
ptr_keyword * data
Definition: def_struct.h:114
static void check_keyword()
static void check_keyword ( )
static
check_keyword ( ptr_keyword k)
static

check_keyword

Parameters
ptr_keyword*k

CHECK_KEYWORD(k) Checks a keyword.

Definition at line 642 of file memory.c.

References check_definition(), check_module(), check_string(), and unchecked().

643 {
644  if(unchecked((GENERIC *)k,sizeof(struct wl_keyword))) { // added cast DJD 12/8/2016
645  check_module(&((*k)->module));
646  check_string((GENERIC *)&((*k)->symbol)); // added cast DJD 12/8/2016
647  check_string((GENERIC *)&((*k)->combined_name)); // added cast DJD 12/8/2016
648  check_definition(&((*k)->definition));
649  }
650 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static void check_module()
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_kids ( ptr_int_list c)
static

check_kids

Parameters
ptr_int_list*c

CHECK_KIDS(c) Check a list of parents or children of a given type.

Definition at line 535 of file memory.c.

References check_definition(), and unchecked().

536 {
537  while (unchecked((GENERIC *) c,sizeof(int_list))) { // added cast DJD 12/8/2016
538  check_definition((ptr_definition *)&((*c)->value_1));
539  c= &((*c)->next);
540  }
541 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_module ( )
static
static void check_module ( ptr_module m)
static

check_module

Parameters
ptr_module*m

CHECK_MODULE(m) Checks a module.

Definition at line 605 of file memory.c.

References check_hash_table(), check_module_list(), check_string(), and unchecked().

606 {
607  if(unchecked((GENERIC *)m,sizeof(struct wl_module))) { // added cast DJD 12/8/2016
608  check_string((GENERIC *)&((*m)->module_name)); // added cast DJD 12/8/2016
609  check_string((GENERIC *)&((*m)->source_file)); // added cast DJD 12/8/2016
610  check_module_list(&((*m)->open_modules));
611  check_module_list(&((*m)->inherited_modules));
612  check_hash_table((*m)->symbol_table);
613  }
614 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
static void check_module_list(ptr_int_list *c)
check_module_list
Definition: memory.c:570
void check_hash_table(ptr_hash_table table)
check_hash_table
Definition: memory.c:625
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_module_list ( ptr_int_list c)
static

check_module_list

Parameters
ptr_int_list*c

CHECK_MODULE_LIST(c) Check a list of modules.

Definition at line 570 of file memory.c.

References check_module(), and unchecked().

571 {
572  while (unchecked((GENERIC *)c,sizeof(int_list))) { // added cast DJD 12/8/2016
573  check_module(&((*c)->value_1));
574  c= &((*c)->next);
575  }
576 }
static void check_module()
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_module_tree ( ptr_node n)
static

check_module_tree

Parameters
ptr_node*n

CHECK_MODULE_TREE This goes through the module table, checking all nodes.

Definition at line 587 of file memory.c.

References check_module(), check_string(), and unchecked().

588 {
589  if (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
590  check_module_tree(&((*n)->left));
591  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
592  check_module(&((*n)->data));
593  check_module_tree(&((*n)->right));
594  }
595 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static void check_module()
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
static void check_module_tree(ptr_node *n)
check_module_tree
Definition: memory.c:587
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_operator_data ( ptr_operator_data op)
static

check_operator_data

Parameters
ptr_operator_data*op

CHECK_OPERATOR_DATA(op) Explore a list of operator declarations.

Definition at line 551 of file memory.c.

References unchecked().

552 {
553  while (unchecked((GENERIC *) op,sizeof(operator_data))) { // added cast DJD 12/8/2016
554  op = &((*op)->next);
555  }
556 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_pair_list ( ptr_pair_list p)
static

check_pair_list

ptr_pair_list *p

CHECK_PAIR_LIST Checks a list of <GOAL,BODY> pairs.

Definition at line 500 of file memory.c.

References check_psi_term(), and unchecked().

501 {
502  while (unchecked((GENERIC *)p,sizeof(pair_list))) { // added cast DJD 12/8/2016
503  check_psi_term(&((*p)->aaaa_2));
504  check_psi_term(&((*p)->bbbb_2));
505  p= &((*p)->next);
506  }
507 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_psi_list ( )
static
static void check_psi_list ( ptr_int_list l)
static

check_psi_list

Parameters
ptr_int_list*l

CHECK_PSI_LIST Update all the values in the list of residuation variables, which is a list of psi_terms.

Definition at line 1235 of file memory.c.

References check_psi_term(), and unchecked().

1236 {
1237  while(unchecked((GENERIC *)l,sizeof(int_list))) { // added cast DJD 12/8/2016
1238  check_psi_term((struct wl_psi_term **)&((*l)->value_1));
1239  l= &((*l)->next);
1240  }
1241 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
unsigned long * GENERIC
Definition: def_struct.h:17
void check_psi_term ( ptr_psi_term t)

check_psi_term

Parameters
ptr_psi_term*t

CHECK_PSI_TERM(t) Explore a psi_term.

Definition at line 987 of file memory.c.

References alist, assert, check_attr(), check_bytedata(), check_definition(), check_resid(), check_string(), choice_stack, cut, Errorline(), heap_pointer, LONELY, mem_limit, NULL, pass, quoted_string, REAL, real, stream, sub_type(), sys_bytedata, unchecked(), and variable.

988 {
989  ptr_list *l;
990 
991  while (unchecked((GENERIC *)t,sizeof(psi_term))) { // added cast DJD 12/8/2016
992 
993  /* A psi-term on the heap has no residuation list. */
994  if (pass==1 && (GENERIC)(*t)>=heap_pointer && (GENERIC)(*t)<mem_limit) {
995  assert((*t)->resid==NULL);
996  }
997  check_definition(&((*t)->type));
998  check_attr(&((*t)->attr_list));
999 
1000  if ((*t)->value_3) {
1001 
1002  if ((*t)->type==alist) { /* RM: Dec 15 1992 Should be removed */
1003  l=(ptr_list *) &((*t)->value_3);
1004  if (l)
1005  printf("Found an old list!\n");
1006  }
1007  else
1008 
1009  if (sub_type((*t)->type,real))
1010  (void)unchecked((GENERIC *)&((*t)->value_3),sizeof(REAL)); // added cast DJD 12/8/2016
1011  else if (sub_type((*t)->type,quoted_string))
1012  check_string((GENERIC *)&((*t)->value_3)); // added cast DJD 12/8/2016
1013  /* DENYS: BYTEDATA */
1014  else if (sub_type((*t)->type,sys_bytedata))
1015  check_bytedata(&((*t)->value_3));
1016 #ifdef CLIFE
1017  else if ((*t)->type->type==block) { /* RM: Jan 27 1993 */
1018  check_block_value(&((*t)->value_3));
1019  }
1020 #endif /* CLIFE */
1021  else if ((*t)->type==cut) { /* RM: Oct 28 1993 */
1022  /* assert((*t)->value_3 <= (GENERIC)choice_stack); 12.7 17.7 */
1023  if (pass==1 && (*t)->value_3>(GENERIC)choice_stack)
1024  (*t)->value_3=(GENERIC)choice_stack;
1025  (void)unchecked((GENERIC *)&((*t)->value_3),LONELY); // added cast DJD 12/8/2016
1026  }
1027  else if (sub_type((*t)->type,variable)) /* 8.8 */
1028  check_string((GENERIC *)&((*t)->value_3)); // added cast DJD 12/8/2016
1029  else if ((*t)->type!=stream)
1030  Errorline("non-NULL value field in garbage collector, type='%s', value=%d.\n",
1031  (*t)->type->keyword->combined_name,
1032  (*t)->value_3);
1033  }
1034 
1035  /* check_psi_term(&((*t)->coref)); 9.6 */
1036  if ((*t)->resid)
1037  check_resid((ptr_residuation *)&((*t)->resid)); // added cast DJD 12/8/2016
1038 
1039  t = &((*t)->coref);
1040  }
1041 }
static void check_bytedata(GENERIC *s)
check_bytedata
Definition: memory.c:450
static void check_resid(ptr_residuation *r)
check_resid
Definition: memory.c:914
GENERIC mem_limit
Definition: def_glob.h:13
ptr_definition stream
Definition: def_glob.h:103
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static long pass
Definition: memory.c:21
#define NULL
Definition: def_const.h:203
#define REAL
Definition: def_const.h:72
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
struct wl_list * ptr_list
Definition: def_struct.h:38
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
ptr_definition real
Definition: def_glob.h:102
ptr_definition alist
Definition: def_glob.h:94
ptr_definition quoted_string
Definition: def_glob.h:101
GENERIC heap_pointer
Definition: def_glob.h:12
ptr_definition sys_bytedata
Definition: def_glob.h:336
ptr_definition cut
Definition: def_glob.h:83
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
void check_attr(ptr_node *n)
check_attr
Definition: memory.c:1054
ptr_definition variable
Definition: def_glob.h:111
ptr_choice_point choice_stack
Definition: def_glob.h:51
#define assert(N)
Definition: memory.c:113
static void check_resid ( ptr_residuation r)
static

check_resid

Parameters
ptr_residuation*r

CHECK_RESID(r) Explore a list of residuations.

Definition at line 914 of file memory.c.

References alist, check_bytedata(), check_code(), check_definition(), check_goal_stack(), check_string(), choice_stack, wl_definition::code, cut, LONELY, pass, quoted_string, REAL, real, sub_CodeType(), sys_bytedata, unchecked(), and variable.

915 {
916  ptr_int_list code;
917  ptr_list *l;
918 
919  while (unchecked((GENERIC *)r,sizeof(residuation))) { // added cast DJD 12/8/2016
920 
921  if ((*r)->sortflag) /* 22.9 */
922  check_definition((struct wl_definition **)&((*r)->bestsort));
923  else
924  check_code((ptr_int_list *)&((*r)->bestsort)); /* 21.9 */ // added cast DJD 12/8/2016
925 
926  /* Handling of the value field (6.10) */
927  code = (*r)->sortflag ? ((ptr_definition)((*r)->bestsort))->code
928  : (ptr_int_list)(*r)->bestsort;
929  /* Copied (almost) verbatim from check_psi_term: */
930  if ((*r)->value_2) {
931  if (code==alist->code) { /* RM: Dec 15 1992 Will be removed */
932  l=(ptr_list *) &((*r)->value_2);
933  if (l)
934  printf("Found an old list!!\n");
935  }
936  else if (sub_CodeType(code,real->code))
937  (void)unchecked((GENERIC *)&((*r)->value_2),sizeof(REAL)); // added cast DJD 12/8/2016
938  else if (sub_CodeType(code,quoted_string->code))
939  check_string((GENERIC *)&((*r)->value_2)); // added cast DJD 12/8/2016
940  /* DENYS: BYTEDATA */
941  else if (sub_CodeType(code,sys_bytedata->code))
942  check_bytedata(&((*r)->value_2));
943  else if (sub_CodeType(code,cut->code)) {
944  if (pass==1 && (*r)->value_2>(GENERIC)choice_stack)
945  (*r)->value_2=(GENERIC)choice_stack;
946  (void)unchecked((GENERIC *)&((*r)->value_2),LONELY); // added cast DJD 12/8/2016
947  }
948  else if (sub_CodeType(code,variable->code)) /* 8.8 */
949  check_string((GENERIC *)&((*r)->value_2)); // added cast DJD 12/8/2016
950  }
951 
952  check_goal_stack((ptr_goal *)&((*r)->goal)); // added cast DJD 12/8/2016
953  r= &((*r)->next);
954  }
955 }
static void check_bytedata(GENERIC *s)
check_bytedata
Definition: memory.c:450
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:800
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static long pass
Definition: memory.c:21
#define REAL
Definition: def_const.h:72
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
struct wl_list * ptr_list
Definition: def_struct.h:38
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
ptr_definition real
Definition: def_glob.h:102
ptr_definition alist
Definition: def_glob.h:94
ptr_definition quoted_string
Definition: def_glob.h:101
struct wl_definition * ptr_definition
Definition: def_struct.h:31
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:486
ptr_definition sys_bytedata
Definition: def_glob.h:336
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
ptr_definition cut
Definition: def_glob.h:83
ptr_int_list code
Definition: def_struct.h:129
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_definition variable
Definition: def_glob.h:111
ptr_choice_point choice_stack
Definition: def_glob.h:51
void check_resid_block ( ptr_resid_block rb)

check_resid_block

Parameters
ptr_resid_block*rb

CHECK_RESID_BLOCK(rb) Explore a residuation block.

Definition at line 965 of file memory.c.

References check_goal_stack(), check_resid_list(), LONELY, and unchecked().

966 {
967  if (*rb) {
968  if (unchecked((GENERIC *)rb,sizeof(resid_block))) { // added cast DJD 12/8/2016
969  check_goal_stack((ptr_goal *)&((*rb)->ra)); // added cast DJD 12/8/2016
970  check_resid_list(&((*rb)->rv)); /* 21.9 */
971  /* unchecked(&((*rb)->rl),LONELY); 12.6 */ /* 10.6 */
972  (void)unchecked((GENERIC *)&((*rb)->md),LONELY); /* 10.6 */ // added cast DJD 12/8/2016
973  /* check_goal_stack(&((*rb)->rl)); 10.6 */
974  /* check_psi_term(&((*rb)->md)); 10.6 */
975  }
976  }
977 }
static void check_resid_list()
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:800
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_resid_list ( )
static
static void check_resid_list ( ptr_resid_list l)
static

check_resid_list

Parameters
ptr_resid_list*l

CHECK_RESID_LIST Update all the values in the list of residuation variables, which is a list of pairs of psi_terms.

Definition at line 1252 of file memory.c.

References check_psi_term(), and unchecked().

1253 {
1254  while(unchecked((GENERIC *)l,sizeof(resid_list))) { // added cast DJD 12/8/2016
1255  check_psi_term(&((*l)->var));
1256  check_psi_term(&((*l)->othervar));
1257  l= &((*l)->next);
1258  }
1259 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_special_addresses ( )
static

check_special_addresses

CHECK_SPECIAL_ADDRESSES Here we check all the addresses which do not point to a whole data structure, but to something within, for example a field such as VALUE which might have been modified in a PSI_TERM structure. These are the LONELY addresses.

Definition at line 1202 of file memory.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, choice_stack, cut_ptr, LONELY, wl_stack::next, wl_choice_point::next, wl_choice_point::stack_top, wl_stack::type, unchecked(), undo_action, undo_stack, and VALID_RANGE.

1203 {
1204  ptr_choice_point c;
1205  ptr_stack p;
1206  // ptr_goal g;
1207 
1208  c=choice_stack;
1209  while(c) {
1210  /* unchecked(&(c->undo_point),LONELY); 17.7 */
1211  (void)unchecked((GENERIC *)&(c->stack_top),LONELY); // added cast DJD 12/8/2016
1212  c=c->next;
1213  }
1214 
1215  p=undo_stack;
1216  while (p) {
1217  if (!(p->type & undo_action)) {
1218  /* Only update an address if it's within the Life data space! */
1219  if (VALID_RANGE(p->aaaa_3)) (void)unchecked((GENERIC *)&(p->aaaa_3),LONELY); // added cast DJD 12/8/2016
1220  if (p->type==cut_ptr) (void)unchecked((GENERIC *)&(p->bbbb_3),LONELY); /* 22.9 */ // added cast DJD 12/8/2016
1221  }
1222  p=p->next;
1223  }
1224 }
#define VALID_RANGE(A)
Definition: def_macro.h:122
GENERIC * bbbb_3
Definition: def_struct.h:218
GENERIC stack_top
Definition: def_struct.h:236
#define cut_ptr
Definition: def_const.h:176
ptr_choice_point next
Definition: def_struct.h:235
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
ptr_stack undo_stack
Definition: def_glob.h:53
type_ptr type
Definition: def_struct.h:216
GENERIC * aaaa_3
Definition: def_struct.h:217
#define undo_action
Definition: def_const.h:188
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_stack next
Definition: def_struct.h:219
ptr_choice_point choice_stack
Definition: def_glob.h:51
static void check_string ( GENERIC s)
static

check_string

Parameters
GENERIC*s

CHECK_STRING(s) Claim the memory used by the string S.

Definition at line 405 of file memory.c.

References delta, LONELY, MAX_BUILT_INS, pass, and unchecked().

406 {
407  GENERIC addr;
408  long value;
409  long bytes;
410 
411  if ((unsigned long) *s > MAX_BUILT_INS) {
412  switch (pass) {
413  case 1:
414  bytes=strlen((char *)*s)+1;
415  /* if (bytes==LONELY) {
416  fprintf(stderr,"Caught an empty string!\n");
417  fflush(stderr);
418  } */
419  /* Make sure there's no conflict with LONELY (this occurs for an */
420  /* empty string, which still needs a single byte of storage). */
421  /* This does occasionally happen. */
422  (void)unchecked((GENERIC *)s, (bytes==LONELY)?bytes+1:bytes); // added cast DJD 12/8/2016
423  break;
424  case 2:
425  addr=(*s+delta);
426  value= *addr;
427  if (value & 1) { /* If low bit set */
428  value--;
429  *s=(GENERIC)value;
430  *addr=value;
431 #ifdef prlDEBUG
432  amount_used+=strlen(*s)+1;
433 #endif
434  }
435  *s=(GENERIC)value;
436  break;
437  }
438  }
439 }
static long delta
Definition: memory.c:12
static long pass
Definition: memory.c:21
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
#define MAX_BUILT_INS
Definition: def_const.h:82
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_symbol ( ptr_node n)
static

check_symbol

Parameters
ptr_node*n

CHECK_SYMBOL This goes through the symbol table, checking all nodes, symbols, strings and definitions not contained in the type table.

Definition at line 764 of file memory.c.

References check_keyword(), check_string(), and unchecked().

765 {
766  if (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
767  check_symbol(&((*n)->left));
768  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
769  check_keyword((ptr_keyword *)&((*n)->data)); /* RM: Jan 12 1993 */ // added cast DJD 12/8/2016
770  check_symbol(&((*n)->right));
771  }
772 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
static void check_symbol(ptr_node *n)
check_symbol
Definition: memory.c:764
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_keyword()
static void check_triple_list ( ptr_triple_list p)
static

check_triple_list

Parameters
ptr_triple_list*p

CHECK_TRIPLE_LIST Checks a list of <GOAL,BODY,DEF> triples.

Definition at line 517 of file memory.c.

References check_definition(), check_psi_term(), and unchecked().

518 {
519  while (unchecked((GENERIC *)p,sizeof(triple_list))) { // added cast DJD 12/8/2016
520  check_psi_term(&((*p)->aaaa_4));
521  check_psi_term(&((*p)->bbbb_4));
522  check_definition(&((*p)->cccc_4));
523  p= &((*p)->next);
524  }
525 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_type_disj ( ptr_int_list p)
static

check_type_disj

Parameters
ptr_int_list*p

CHECK_TYPE_DISJ Checks the list of definitions appearing in a type disjunction.

Definition at line 782 of file memory.c.

References check_definition(), and unchecked().

783 {
784  while (unchecked((GENERIC *)p,sizeof(int_list))) { // added cast DJD 12/8/2016
785  check_definition((struct wl_definition **)&((*p)->value_1));
786  p= &((*p)->next);
787  }
788 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_undo_stack ( )
static
static void check_undo_stack ( ptr_stack s)
static

check_undo_stack

Parameters
ptr_stack*s

CHECK_UNDO_STACK() This looks after checking the addresses of objects pointed to in the trail. The type of the pointer to be restored on backtracking is known, which allows the structure it is referring to to be accordingly checked.

Definition at line 1113 of file memory.c.

References check_code(), check_definition(), check_goal_stack(), check_psi_term(), check_resid(), code_ptr, cut_ptr, def_ptr, destroy_window, goal_ptr, hide_window, int_ptr, psi_term_ptr, resid_ptr, show_window, and unchecked().

1114 {
1115  while (unchecked((GENERIC *)s,sizeof(stack))) { // added cast DJD 12/8/2016
1116 
1117  switch((*s)->type) {
1118 
1119  case psi_term_ptr:
1120  check_psi_term((struct wl_psi_term **)&((*s)->bbbb_3));
1121  break;
1122 
1123  case resid_ptr:
1124  check_resid((ptr_residuation *)&((*s)->bbbb_3)); // added cast DJD 12/8/2016
1125  break;
1126 
1127  case int_ptr:
1128  /* int_ptr's are used to trail time_stamps, so they can get large. */
1129  break;
1130 
1131  case def_ptr:
1132  check_definition((struct wl_definition **)&((*s)->bbbb_3));
1133  break;
1134 
1135  case code_ptr:
1136  check_code((ptr_int_list *)&((*s)->bbbb_3)); // added cast DJD 12/8/2016
1137  break;
1138 
1139  case goal_ptr:
1140  check_goal_stack((ptr_goal *)&((*s)->bbbb_3)); // added cast DJD 12/8/2016
1141  break;
1142 
1143  case cut_ptr: /* 22.9 */
1144  break;
1145 #ifdef CLIFE
1146  case block_ptr: /* CB: Jan 28 1993 */
1147  check_block_value(&((*s)->bbbb_3));
1148  break;
1149 
1150 #endif /* CLIFE */
1151  /* All undo actions here */
1152  case destroy_window:
1153  case show_window:
1154  case hide_window:
1155  /* No pointers to follow */
1156  break;
1157  }
1158 
1159  s= &((*s)->next);
1160  }
1161 }
static void check_resid(ptr_residuation *r)
check_resid
Definition: memory.c:914
#define show_window
Definition: def_const.h:184
#define def_ptr
Definition: def_const.h:173
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:800
#define destroy_window
Definition: def_const.h:183
#define cut_ptr
Definition: def_const.h:176
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:662
#define hide_window
Definition: def_const.h:185
#define code_ptr
Definition: def_const.h:174
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:486
unsigned long * GENERIC
Definition: def_struct.h:17
#define resid_ptr
Definition: def_const.h:171
#define goal_ptr
Definition: def_const.h:175
#define psi_term_ptr
Definition: def_const.h:170
#define int_ptr
Definition: def_const.h:172
static void check_var ( ptr_node n)
static
Parameters
check_var
ptr_node*n

CHECK_VAR(t) Go through the VARiable tree. (This could be made tail recursive.)

Definition at line 1270 of file memory.c.

References check_psi_term(), check_string(), and unchecked().

1271 {
1272  if (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
1273  check_var(&((*n)->left));
1274  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
1275  check_psi_term((struct wl_psi_term **)&((*n)->data));
1276  check_var(&((*n)->right));
1277  }
1278 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:405
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:338
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:987
static void check_var(ptr_node *n)
Definition: memory.c:1270
unsigned long * GENERIC
Definition: def_struct.h:17
static void compress ( )
static

compress

COMPRESS() This routine compresses the memory contents and calculates the new addresses. First the Stack is compressed, bottom up. Secondly the Heap is compressed, top down.

Definition at line 222 of file memory.c.

References ALIGN, assert, delta, heap_pointer, LONELY, mem_base, mem_limit, other_pointer, stack_pointer, TRUE, and VALID_ADDRESS.

223 {
224  GENERIC addr, new_addr;
225  long len, i;
226 
227  /* Compressing the stack: */
228 
229  addr=new_addr=mem_base;
230  while (addr<=stack_pointer) {
231  len = *(addr+delta);
232  if (len) {
233  /* There are lots of these: */
234  /* if (len==LONELY) printf("Isolated LONELY at %lx\n",addr); */
235  if (len==LONELY) len=ALIGN;
236  else if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
237  /* if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN; 12.6 */
238  assert((len & (ALIGN-1))==0);
239  len /= sizeof(*addr);
240  assert(len>0);
241 
242  for (i=0; i<len; i++) {
243  *new_addr = *addr;
244  if (i>0) {
245  if (*(addr+delta)>=len)
246  assert(i>0 ? *(addr+delta)<len : TRUE);
247  }
248  assert(VALID_ADDRESS(new_addr));
249  *(addr+delta) = (long)new_addr + 1; /* Set low bit */
250 #ifdef prlDEBUG
251  if (*(addr+delta) & 1 == 0)
252  printf ("compress: could be a bug ...\n");
253 #endif
254  addr++;
255  new_addr++;
256  }
257  }
258  else
259  addr++;
260  }
261  other_pointer=stack_pointer; /* 10.6 this var. is unused */
262  stack_pointer=new_addr;
263 
264  /* Compressing the heap: */
265 
266  addr=new_addr=mem_limit;
267  addr--; /* PVR fix: adding this statement avoids accessing beyond */
268  /* the memory's edge, which causes a segmentation fault on*/
269  /* SPARC. */
270  while (addr>=heap_pointer) {
271  skip_addr:
272  len= *(addr+delta);
273  if (len) {
274  if (len!=LONELY) {
275 
276  if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
277  assert((len & (ALIGN-1))==0);
278  len /= sizeof (*addr);
279  assert(len>0);
280 
281  } else { /* len==LONELY */
282  GENERIC a;
283 
284  if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
285  assert((len & (ALIGN-1))==0);
286  len /= sizeof (*addr);
287  assert(len==1);
288 
289  /* Check if the LONELY field is actually part of a block. */
290  /* If so, skip to the beginning of the block. */
291  a=addr;
292  do {
293  a--;
294  } while (a>=heap_pointer &&
295  (*(a+delta)==0 || *(a+delta)==LONELY));
296  if (a>=heap_pointer && *(a+delta)/sizeof(*a)+a>addr) {
297  addr=a;
298  goto skip_addr;
299  }
300  }
301 
302  /* Move a block or an isolated LONELY field. */
303  addr += len;
304  for (i=0; i<len; i++) {
305  addr--;
306  new_addr--;
307  *new_addr = *addr;
308  assert(VALID_ADDRESS(new_addr));
309  *(addr+delta) = (long)new_addr + 1;
310  }
311  }
312  addr--;
313  }
314  heap_pointer=new_addr;
315 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:132
GENERIC mem_limit
Definition: def_glob.h:13
static long delta
Definition: memory.c:12
GENERIC other_pointer
Definition: def_glob.h:21
#define TRUE
Definition: def_const.h:127
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
#define ALIGN
Definition: def_const.h:31
#define assert(N)
Definition: memory.c:113
void fail_all ( )

fail_all

FAIL_ALL() This routines provokes a total failure, in case of a bad error (out of memory, abort, etc...). All goals are abandoned.

Definition at line 188 of file memory.c.

References abort_life(), choice_stack, goal_stack, NULL, open_input_file(), output_stream, stdin_cleareof(), TRUE, and undo_stack.

189 {
190  output_stream=stdout;
194  (void)abort_life(TRUE);
195  /* printf("\n*** Abort\n"); */
196  stdin_cleareof();
197  (void)open_input_file("stdin");
198 }
ptr_goal goal_stack
Definition: def_glob.h:50
#define NULL
Definition: def_const.h:203
long abort_life(int nlflag)
abort_life
Definition: built_ins.c:2260
ptr_stack undo_stack
Definition: def_glob.h:53
#define TRUE
Definition: def_const.h:127
FILE * output_stream
Definition: def_glob.h:41
void stdin_cleareof()
stdin_cleareof
Definition: token.c:51
long open_input_file(char *file)
open_input_file
Definition: token.c:594
ptr_choice_point choice_stack
Definition: def_glob.h:51
void garbage ( )

garbage

GARBAGE() The garbage collector. This routine is called whenever memory is getting low. It returns TRUE if insufficient memory was freed to allow the interpreter to carry on working.

This is a half-space GC, it first explores all known structures, then compresses the heap and the stack, then during the second pass assigns all the new addresses.

Bugs will appear if the collector is called during parsing or other such routines which are 'unsafe'. In order to avoid this problem, before one of these routines is invoked the program will check to see whether there is enough memory available to work, and will call the GC if not (this is a fix, because it is not possible to determine in advance what the size of a psi_term read by the parser will be).

Definition at line 1529 of file memory.c.

References assert, bounds_undo_stack(), check(), clear_copy(), compress(), FALSE, garbage_time, gc_time, heap_pointer, ignore_eff, last_garbage_time, life_time, mem_base, mem_limit, NULL, other_base, other_limit, pass, pointer_names, print_gc_info(), printed_pointers, stack_info(), stack_pointer, TRUE, and verbose.

1530 {
1531  GENERIC addr;
1532  struct tms garbage_start_time,garbage_end_time;
1533  long start_number_cells, end_number_cells;
1534 
1535  start_number_cells = (stack_pointer-mem_base) + (mem_limit-heap_pointer);
1536 
1537  (void)times(&garbage_start_time);
1538 
1539  /* Time elapsed since last garbage collection */
1540  life_time=(garbage_start_time.tms_utime - last_garbage_time.tms_utime)/60.0;
1541 
1542 
1543  if (verbose) {
1544  fprintf(stderr,"*** Garbage Collect "); /* RM: Jan 26 1993 */
1545  fprintf(stderr,"\n*** Begin");
1547  (void)fflush(stderr);
1548  }
1549 
1550 
1551  /* reset the other base */
1552  for (addr = other_base; addr < other_limit; addr ++)
1553  *addr = 0;
1554 
1555  pass=1;
1556 
1557  check();
1558 #ifdef GCVERBOSE
1559  fprintf(stderr,"- Done pass 1 ");
1560 #endif
1561 
1563  compress();
1564 #ifdef GCVERBOSE
1565  fprintf(stderr,"- Done compress ");
1566 #endif
1567 
1568  pass=2;
1569 
1570  check();
1572 #ifdef GCVERBOSE
1573  fprintf(stderr,"- Done pass 2\n");
1574 #endif
1575 
1576  clear_copy();
1577 
1580 
1581  (void)times(&garbage_end_time);
1582  gc_time=(garbage_end_time.tms_utime - garbage_start_time.tms_utime)/60.0;
1584 
1585  if (verbose) {
1586  fprintf(stderr,"*** End ");
1587  print_gc_info(TRUE); /* RM: Jan 26 1993 */
1588  stack_info(stderr);
1589  (void)fflush(stderr);
1590  }
1591 
1592  last_garbage_time=garbage_end_time;
1593 
1594  end_number_cells = (stack_pointer-mem_base) + (mem_limit-heap_pointer);
1595  assert(end_number_cells<=start_number_cells);
1596 
1597  ignore_eff=FALSE;
1598 
1599 }
ptr_node printed_pointers
Definition: def_glob.h:28
static void check()
check
Definition: memory.c:1299
void clear_copy()
clear_copy
Definition: copy.c:53
GENERIC mem_limit
Definition: def_glob.h:13
static float gc_time
Definition: memory.c:27
long verbose
Definition: def_glob.h:273
static long pass
Definition: memory.c:21
GENERIC other_base
Definition: def_glob.h:19
#define NULL
Definition: def_const.h:203
long ignore_eff
Definition: def_glob.h:151
ptr_node pointer_names
Definition: def_glob.h:29
void print_gc_info(long timeflag)
print_gc_info
Definition: memory.c:1492
#define TRUE
Definition: def_const.h:127
static float life_time
Definition: memory.c:27
#define FALSE
Definition: def_const.h:128
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
static void compress()
compress
Definition: memory.c:222
void stack_info(FILE *outfile)
stack_info
Definition: error.c:77
GENERIC other_limit
Definition: def_glob.h:20
GENERIC stack_pointer
Definition: def_glob.h:14
float garbage_time
Definition: def_glob.h:16
unsigned long * GENERIC
Definition: def_struct.h:17
long bounds_undo_stack()
bounds_undo_stack
Definition: memory.c:142
static struct tms last_garbage_time
Definition: memory.c:26
#define assert(N)
Definition: memory.c:113
int GetBoolOption ( char *  name)

GetBoolOption.

Parameters
char*name

Definition at line 64 of file memory.c.

References GetStrOption().

65 {
66  char *s;
67  s=GetStrOption(name,"off");
68  return strcmp(s,"off");
69 }
char * name
Definition: def_glob.h:325
char * GetStrOption(char *name, char *def)
GetStrOption.
Definition: memory.c:41
int GetIntOption ( char *  name,
int  def 
)

GetIntOption.

Parameters
char*name
intdef

Definition at line 78 of file memory.c.

References GetStrOption().

79 {
80  char *s;
81  char buffer_loc[40];
82  (void)snprintf(buffer_loc,40,"%d",def);
83  s=GetStrOption(name,buffer_loc);
84  return atof(s);
85 }
char * name
Definition: def_glob.h:325
char * GetStrOption(char *name, char *def)
GetStrOption.
Definition: memory.c:41
char* GetStrOption ( char *  name,
char *  def 
)

GetStrOption.

Parameters
char*name
char*def

STUFF FOR PARSING COMMAND LINE ARGS

Definition at line 41 of file memory.c.

References arg_c, and arg_v.

42 {
43  int i;
44  char *result=def;
45  int l=strlen(name);
46 
47  for(i=1;i<arg_c;i++)
48  if(arg_v[i][0]=='-' && (int)strlen(arg_v[i])>=l+1)
49  if(!strncmp(arg_v[i]+1,name,l))
50  if(arg_v[i][l+1]=='=')
51  result=arg_v[i]+l+2;
52  else
53  result=arg_v[i]+l+1;
54 
55  return result;
56 }
char * name
Definition: def_glob.h:325
int arg_c
Definition: def_glob.h:5
char * arg_v[10]
Definition: def_glob.h:6
GENERIC heap_alloc ( long  s)

heap_alloc

Parameters
longs

HEAP_ALLOC(s) This returns a pointer to S bytes of memory in the heap. Alignment is taken into account in the following manner: the macro ALIGN is supposed to be a power of 2 and the pointer returned is a multiple of ALIGN.

Definition at line 1616 of file memory.c.

References ALIGN, Errorline(), heap_pointer, and stack_pointer.

1617 {
1618  if (s & (ALIGN-1))
1619  s = s - (s & (ALIGN-1))+ALIGN;
1620  /* assert(s % sizeof(*heap_pointer) == 0); */
1621  s /= sizeof (*heap_pointer);
1622 
1623  heap_pointer -= s;
1624 
1626  Errorline("the heap overflowed into the stack.\n");
1627 
1628  return heap_pointer;
1629 }
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
#define ALIGN
Definition: def_const.h:31
void init_memory ( )

init_memory ()

INIT_MEMORY() Get two big blocks of memory to work in. The second is only used for the half-space garbage collector. The start and end addresses of the blocks are re-aligned correctly. to allocate.

Definition at line 1671 of file memory.c.

References ALIGNUP, alloc_words, ALLOC_WORDS, buffer, delta, Errorline(), GetIntOption(), heap_pointer, mem_base, mem_limit, mem_size, other_base, other_limit, other_pointer, PRINT_BUFFER, and stack_pointer.

1672 {
1674  mem_size=alloc_words*sizeof(long);
1675 
1676  mem_base = (GENERIC) malloc(mem_size);
1677  other_base = (GENERIC) malloc(mem_size);
1678 
1679  if (mem_base && other_base) {
1680  /* Rewrote some rather poor code... RM: Mar 1 1994 */
1681  ALIGNUP(mem_base);
1683 
1684  mem_limit=mem_base+alloc_words-2;
1685  ALIGNUP(mem_limit);
1687 
1690 
1691  other_limit=other_base+alloc_words-2;
1693 
1695  buffer = (char *) malloc (PRINT_BUFFER); /* The printing buffer */
1696 
1697  /* RM: Oct 22 1993 */
1698  /* Fill the memory with rubbish data */
1699  /*
1700  {
1701  int i;
1702 
1703  for(i=0;i<alloc_words;i++) {
1704  mem_base[i]= -1234;
1705  other_base[i]= -1234;
1706  }
1707  }
1708  */
1709  }
1710  else
1711  Errorline("Wild_life could not allocate sufficient memory to run.\n\n");
1712 }
#define ALLOC_WORDS
Definition: def_config.h:10
GENERIC mem_limit
Definition: def_glob.h:13
int alloc_words
Definition: def_glob.h:10
static long delta
Definition: memory.c:12
int mem_size
Definition: def_glob.h:9
GENERIC other_base
Definition: def_glob.h:19
GENERIC other_pointer
Definition: def_glob.h:21
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
char * buffer
Definition: def_glob.h:175
#define ALIGNUP(X)
Definition: def_macro.h:294
#define PRINT_BUFFER
Definition: def_const.h:106
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC other_limit
Definition: def_glob.h:20
GENERIC stack_pointer
Definition: def_glob.h:14
int GetIntOption(char *name, int def)
GetIntOption.
Definition: memory.c:78
unsigned long * GENERIC
Definition: def_struct.h:17
long memory_check ( )

memory_check

MEMORY_CHECK() This function tests to see whether enough memory is available to allow execution to continue. It causes a garbage collection if not, and if that fails to release enough memory it returns FALSE.

Definition at line 1723 of file memory.c.

References fail_all(), FALSE, garbage(), GC_THRESHOLD, heap_pointer, stack_pointer, TRUE, and verbose.

1724 {
1725  long success=TRUE;
1726 
1728  if(verbose) fprintf(stderr,"\n"); /* RM: Feb 1 1993 */
1729  garbage();
1730  /* Abort if didn't recover at least GC_THRESHOLD/10 of memory */
1732  fprintf(stderr,"*********************\n");
1733  fprintf(stderr,"*** OUT OF MEMORY ***\n");
1734  fprintf(stderr,"*********************\n");
1735  fail_all();
1736  success=FALSE;
1737  }
1738  }
1739  return success;
1740 }
void fail_all()
fail_all
Definition: memory.c:188
long verbose
Definition: def_glob.h:273
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
GENERIC heap_pointer
Definition: def_glob.h:12
void garbage()
garbage
Definition: memory.c:1529
#define GC_THRESHOLD
Definition: def_const.h:65
GENERIC stack_pointer
Definition: def_glob.h:14
void pchoices ( )

pchoices

for debugging

Definition at line 93 of file memory.c.

References choice_stack, wl_choice_point::next, stack_pointer, and wl_choice_point::stack_top.

94 {
96  printf("stack pointer is: %lx\n",(unsigned long)stack_pointer);
97  for(c=choice_stack;c;c=c->next)
98  printf("\tc=%lx\ts=%lx\tg=%lx\tu=%lx\n",(unsigned long)c,(unsigned long)c->stack_top,(unsigned long)c->goal_stack,(unsigned long)c->undo_point);
99 }
GENERIC stack_top
Definition: def_struct.h:236
ptr_choice_point next
Definition: def_struct.h:235
GENERIC stack_pointer
Definition: def_glob.h:14
ptr_choice_point choice_stack
Definition: def_glob.h:51
void print_gc_info ( long  timeflag)

print_gc_info

Parameters
longtimeflag

Definition at line 1492 of file memory.c.

References gc_time, heap_pointer, life_time, mem_base, mem_limit, mem_size, and stack_pointer.

1493 {
1494  fprintf(stderr," [%ld%% free (%ldK), %ld%% heap, %ld%% stack",
1495  (100*((unsigned long)heap_pointer-(unsigned long)stack_pointer)+mem_size/2)/mem_size,
1496  ((unsigned long)heap_pointer-(unsigned long)stack_pointer+512)/1024,
1497  (100*((unsigned long)mem_limit-(unsigned long)heap_pointer)+mem_size/2)/mem_size,
1498  (100*((unsigned long)stack_pointer-(unsigned long)mem_base)+mem_size/2)/mem_size);
1499  if (timeflag) {
1500  fprintf(stderr,", %1.3fs cpu (%ld%%)",
1501  gc_time,
1502  (unsigned long)(0.5+100*gc_time/(life_time+gc_time)));
1503  }
1504  fprintf(stderr,"]\n");
1505 }
GENERIC mem_limit
Definition: def_glob.h:13
static float gc_time
Definition: memory.c:27
int mem_size
Definition: def_glob.h:9
static float life_time
Definition: memory.c:27
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
void print_undo_stack ( )

print_undo_stack

Definition at line 121 of file memory.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, mem_base, mem_limit, wl_stack::next, wl_stack::type, and undo_stack.

122 {
124 
125  while (u) {
126  if ((GENERIC)u->aaaa_3<mem_base || (GENERIC)u->aaaa_3>mem_limit ||
127  (GENERIC)u->next<mem_base || (GENERIC)u->next>mem_limit) {
128  printf("UNDO: type:%ld a:%lx b:%lx next:%lx\n",u->type,(unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3,(unsigned long)u->next);
129  (void)fflush(stdout);
130  }
131  u=u->next;
132  }
133 }
GENERIC mem_limit
Definition: def_glob.h:13
GENERIC * bbbb_3
Definition: def_struct.h:218
ptr_stack undo_stack
Definition: def_glob.h:53
type_ptr type
Definition: def_struct.h:216
GENERIC mem_base
Definition: def_glob.h:11
GENERIC * aaaa_3
Definition: def_struct.h:217
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_stack next
Definition: def_struct.h:219
GENERIC stack_alloc ( long  s)

stack_alloc

Parameters
longs

STACK_ALLOC(s) This returns a pointer to S bytes of memory in the stack. Alignment is taken into account in the following manner: the macro ALIGN is supposed to be a power of 2 and the pointer returned is a multiple of ALIGN.

Definition at line 1642 of file memory.c.

References ALIGN, Errorline(), heap_pointer, and stack_pointer.

1643 {
1644  GENERIC r;
1645 
1646  r = stack_pointer;
1647 
1648  if (s & (ALIGN-1))
1649  s = s - (s & (ALIGN-1)) + ALIGN;
1650  /* assert(s % sizeof(*stack_pointer) == 0); */
1651  s /= sizeof (*stack_pointer);
1652 
1653  stack_pointer += s;
1654 
1656  Errorline("the stack overflowed into the heap.\n");
1657 
1658  return r;
1659 }
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
unsigned long * GENERIC
Definition: def_struct.h:17
#define ALIGN
Definition: def_const.h:31
static long unchecked ( GENERIC p,
long  len 
)
static

unchecked

Parameters
GENERIC*p
longlen

UNCHECKED(p,l) P is a pointer to a structure L bytes in length. If L=LONELY then that means that P is a pointer to a sub-field of a structure. The function returns TRUE if the structure has not been yet thoroughly explored, otherwise FALSE. If this is the second pass then it translates P to its new value (as calculated by COMPRESS).

Definition at line 338 of file memory.c.

References assert, delta, Errorline(), FALSE, LONELY, MAX_BUILT_INS, pass, TRUE, and VALID_ADDRESS.

340 {
341  GENERIC addr;
342  long result=FALSE, value;
343 
344  assert(len>0);
345  if ((unsigned long)*p>MAX_BUILT_INS) {
346 #ifdef GCTEST
347  if (!VALID_ADDRESS(*p)) {
348  printf("p=%lx,*p=%lx\n",p,*p);
349  }
350 #endif
351  assert(VALID_ADDRESS(*p));
352  addr = *p + delta;
353  value = *addr;
354  switch (pass) {
355  case 1:
356 #ifdef GCTEST
357  if (FALSE /* len>100 || value>100 13.8 */) {
358  /* This does in fact happen */
359  printf("len=%ld,value=%ld\n",len,value);
360  fflush(stdout);
361  }
362 #endif
363  /* if (!value) */
364  if (!value || value==LONELY) {
365  /* Pointer not yet explored */
366  result=TRUE;
367  *addr=len;
368 #ifdef prlDEBUG
369  amount_used+=len;
370 #endif
371  }
372  else if (value < len && len != LONELY) {
373  Errorline("in garbage collection, %d < %d.\n", value, len);
374  }
375  else if (value > len && len != LONELY) {
376  Errorline("in garbage collection, %d > %d.\n", value, len);
377  }
378  break;
379  case 2:
380  if (value & 1) { /* If low bit set */
381  value--; /* Reset low bit */
382  *addr=value;
383 #ifdef prlDEBUG
384  amount_used+=len;
385 #endif
386  result=TRUE;
387  }
388  if (!VALID_ADDRESS(value))
389  assert(VALID_ADDRESS(value));
390  *p = (GENERIC) value;
391  break;
392  }
393  }
394  return result;
395 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:132
static long delta
Definition: memory.c:12
static long pass
Definition: memory.c:21
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
#define MAX_BUILT_INS
Definition: def_const.h:82
#define LONELY
Definition: memory.c:24
unsigned long * GENERIC
Definition: def_struct.h:17
#define assert(N)
Definition: memory.c:113

Variable Documentation

long delta
static

Definition at line 12 of file memory.c.

float gc_time
static

Definition at line 27 of file memory.c.

struct tms last_garbage_time
static

Definition at line 26 of file memory.c.

float life_time
static

Definition at line 27 of file memory.c.

long pass
static

Definition at line 21 of file memory.c.