14
14
#include "mmvstr.h"
15
15
16
16
/* debugging flags & variables */
17
- /*E*/ extern long db ,db0 ,db1 ,db2 ;
18
17
/*!
18
+ * \var db
19
+ * \brief bytes held by vstring instances outside of the stack of temporaries
20
+ *
21
+ * monitors the number of bytes (including the terminal NUL) currently used in
22
+ * all \a vstring pointer variables OUTSIDE of the \a tempAllocStack. Note:
23
+ * This is NOT the number of bytes allocated, but the portion actually used! A
24
+ * few memory allocations are also included:
25
+ * - command line buffers used to hold user input from a console;
26
+ * - buffers used to read file contents in.
27
+ *
28
+ * If the user has turned MEMORY_STATUS on, metamath will print out this value
29
+ * after each command in a message like "Memory: string < db >".
30
+ */
31
+ /*E*/ extern long db ;
32
+ /*E*/ extern long db0 ;
33
+ /*!
34
+ * \var db1
35
+ * \brief bytes held by vstring instances inside of the stack of temporaries
36
+ *
37
+ * monitors the number of bytes currently pointed to by \a vstring pointers
38
+ * INSIDE the \a tempAllocStack. Note: This is NOT their capacity, but the
39
+ * portion actually used!
40
+ *
41
+ * Not updated if NDEBUG (usually deactivates asserts in C code) is defined.
42
+ *
43
+ * \bug Seems never be displayed.
44
+ */
45
+ /*E*/ extern long db1 ;
46
+ /*E*/ extern long db2 ;
47
+ /*!
48
+ * \var db3
19
49
* \brief monitors the de/allocations of nmbrString and pntrString outside of
20
50
* temporary arrays.
21
51
*
22
- * The number of bytes held in blocks dedicated to global data. There exists
52
+ * The number of bytes held in blocks dedicated to global data. There exist
23
53
* also temporary stacks, but they are not considered here. Useful to see
24
54
* whether a process looses memory due to imbalanced calls to allocation/free
25
55
* functions.
30
60
/*E*/ extern long db3 ;
31
61
/*E*/ extern long db4 ,db5 ,db6 ,db7 ,db8 ;
32
62
/*!
63
+ * \var db9
33
64
* \brief log memory pool usage for debugging purpose.
34
65
*
35
66
* If set to a non-zero value, the state of the memory pool is
54
85
typedef char flag ;
55
86
56
87
/*!
88
+ * \var g_listMode
57
89
* \deprecated
58
- * \var flag g_listMode.
59
90
* Obsolete. Now fixed to 0. Historically the metamath sources were also used
60
91
* for other purposes than maintaining Metamath files. One such application, a
61
92
* standalone text processor, was LIST.EXE. The sources still query this
@@ -64,7 +95,7 @@ typedef char flag;
64
95
*/
65
96
extern flag g_listMode ; /* 0 = metamath, 1 = list utility */
66
97
/*!
67
- * \var flag g_toolsMode.
98
+ * \var g_toolsMode
68
99
* Metamath has two modes of operation: In its primary mode it handles
69
100
* mathematical contents like proofs. In this mode \a g_toolsMode is set to
70
101
* 0. This is the value assigned on startup. A second mode is enabled after
@@ -76,7 +107,7 @@ extern flag g_toolsMode; /* In metamath mode: 0 = metamath, 1 = tools */
76
107
typedef long nmbrString ; /* String of numbers */
77
108
/*!
78
109
* \typedef pntrString
79
- * \brief an array of untyped pointers (void*)
110
+ * \brief an array (maybe of size 1) of untyped pointers (void*)
80
111
*
81
112
* In general this array is organized like a stack: the number of elements in
82
113
* the pntrString grows and shrinks during program flow, values are pushed and
@@ -90,9 +121,8 @@ typedef long nmbrString; /* String of numbers */
90
121
*
91
122
* To summarize the usages of this type:
92
123
* - If you want to resize the array/stack you need a pointer to element 0.
93
- * - Given an arbitrary pointer from the array allows you to iterate to the
94
- * end.
95
- *
124
+ * - You can iterate from an arbitrary pointer to the end.
125
+ * - Sometimes it denotes an isolated element, not embedded in a greater array.
96
126
*/
97
127
typedef void * pntrString ; /* String of pointers */
98
128
@@ -104,6 +134,15 @@ typedef nmbrString temp_nmbrString;
104
134
/* A pntrString allocated in temporary storage. These strings will be deallocated
105
135
after the next call to `pntrLet`.
106
136
See also `temp_vstring` for information on how temporaries are handled. */
137
+
138
+ /*!
139
+ * \typedef temp_pntrString
140
+ * \brief a single \a pntrString element for use in a \ref stack "stack".
141
+ *
142
+ * These elements are pushed onto and popped off a \ref stack
143
+ * "stack of temporary data". Special commands can free all pointers on and
144
+ * after a particular one in such a stack.
145
+ */
107
146
typedef pntrString temp_pntrString ;
108
147
109
148
enum mTokenType { var_ , con_ };
@@ -260,6 +299,7 @@ void addToUsedPool(void *ptr);
260
299
void memFreePoolPurge (flag untilOK );
261
300
/* Statistics */
262
301
/*!
302
+ * \fn getPoolStats
263
303
* \brief Provide information about memory in pools at the instant of call.
264
304
*
265
305
* Return the overall statistics about the pools \ref memFreePool
@@ -292,9 +332,27 @@ void initBigArrays(void);
292
332
long getFreeSpace (long max );
293
333
294
334
/* Fatal memory allocation error */
335
+ /*!
336
+ * \fn outOfMemory
337
+ * \brief fatal memory allocation error.
338
+ *
339
+ * called when memory cannot be allocated, either because memory/address space
340
+ * is physically exhausted, or because administrative structures would overflow.
341
+ * Stops execution and wait for the user to confirm having read the message,
342
+ * before exiting the program raising an error condition.
343
+ *
344
+ * \param msg error message displayed to the user.
345
+ * \returns never, but exits the program instead.
346
+ * \bug calls functions like print2, that in turn may call outOfMemory again
347
+ * under restricted memory conditions, so finally memory error messages are
348
+ * stacked up endlessly.
349
+ */
295
350
void outOfMemory (const char * msg );
296
351
297
352
/* Bug check error */
353
+ /*!
354
+ * \fn bug
355
+ */
298
356
void bug (int bugNum );
299
357
300
358
@@ -312,8 +370,8 @@ extern struct nullNmbrStruct g_NmbrNull;
312
370
/*!
313
371
* \struct nullPntrStruct
314
372
* describing a \ref block of \a pntrString containing only the null
315
- * pointer. Besides this pointer it is accompanied with a header matching
316
- * the hidden administrative values of a usual pntrString managed as a stack .
373
+ * pointer. Besides this pointer it is accompanied with a header containing
374
+ * the hidden administrative values of such \ref block "block" .
317
375
*
318
376
* The values in this administrative header are such that it is never subject to
319
377
* memory allocation or deallocation.
@@ -348,7 +406,8 @@ struct nullPntrStruct {
348
406
*/
349
407
pntrString nullElement ; };
350
408
/*!
351
- * \var g_PntrNull. Global instance of a memory block structured like a
409
+ * \var g_PntrNull
410
+ * Global instance of a memory block structured like a
352
411
* \a pntrString, fixed in size and containing always exactly one null pointer
353
412
* element, the terminating NULL. This setup is recognized as an empty
354
413
* \a pntrString.
@@ -530,6 +589,14 @@ long compressedProofSize(const nmbrString *proof, long statemNum);
530
589
/******* Special purpose routines for better
531
590
memory allocation (use with caution) *******/
532
591
592
+ /*!
593
+ * \var g_pntrTempAllocStackTop
594
+ *
595
+ * Index of the current top af the \ref stack "stack" \a pntrTempAlloc.
596
+ * New data is pushed from this location on if space available.
597
+ *
598
+ * \invariant always refers the null pointer element behind the valid data.
599
+ */
533
600
extern long g_pntrTempAllocStackTop ; /* Top of stack for pntrTempAlloc function */
534
601
extern long g_pntrStartTempAllocStack ; /* Where to start freeing temporary
535
602
allocation when pntrLet() is called (normally 0, except for nested
@@ -569,6 +636,7 @@ temp_pntrString *pntrNSpace(long n);
569
636
temp_pntrString * pntrPSpace (long n );
570
637
571
638
/*!
639
+ * \fn pntrLen
572
640
* \brief Determine the length of a pntrString held in a \ref block "block"
573
641
* dedicated to it.
574
642
*
@@ -582,6 +650,7 @@ temp_pntrString *pntrPSpace(long n);
582
650
*/
583
651
long pntrLen (const pntrString * s );
584
652
/*!
653
+ * \fn pntrAllocLen
585
654
* \brief Determine the capacity of a pntrString embedded in a dedicated block
586
655
*
587
656
* returns the capacity of pointers in the array pointed to by \p s,
0 commit comments