Skip to content

Commit 9149544

Browse files
committed
improve doc of pntrLet
1 parent 0f3adf2 commit 9149544

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/mmdata.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,11 +2468,16 @@ long g_pntrStartTempAllocStack = 0; /* Where to start freeing temporary alloca
24682468
* \brief a \ref stack "stack" of \ref temp_pntrString.
24692469
*
24702470
* Holds pointers to temporarily allocated data of type \ref temp_pntrString. Such
2471-
* a \ref stack "stack" is primarily designed to function like a stack for
2472-
* temporary allocated ad hoc operands, as described in \ref stack. The stack top
2473-
* index is \ref g_pntrTempAllocStackTop, always refering to the next push
2474-
* position. The \ref g_pntrStartTempAllocStack supports nested operations by
2475-
* indicating where the operands for the upcoming operation start from.
2471+
* a \ref stack "stack" is primarily designed to operate like one for temporary
2472+
* allocated ad hoc operands, as described in \ref stack. The stack top index
2473+
* is \ref g_pntrTempAllocStackTop, always refering to the next push position.
2474+
* The \ref g_pntrStartTempAllocStack supports nested operations by indicating
2475+
* where the operands for the upcoming operation start from.
2476+
* \attention A \ref pntrString consists of an array of pointers. These
2477+
* pointers may themself refer data that needs a clean up, when the last
2478+
* reference to it disappears (such as deallocating memory for example).
2479+
* There is no automatic procedure handling such cases when pointers are
2480+
* popped off the stack to be freed.
24762481
* \bug The element type should be temp_pntrString, because a NULL_PNTRSTRING
24772482
* must not be pushed on the stack.
24782483
*/
@@ -2498,6 +2503,8 @@ pntrString *pntrTempAllocStack[M_MAX_ALLOC_STACK];
24982503
* "block's" header, but the data is still random.
24992504
* - updates \ref db2
25002505
* - Exits on out-of-memory
2506+
* \bug it is unfortunate that the same function is used for opposite
2507+
* operations like de-/allocation.
25012508
*/
25022509
temp_pntrString *pntrTempAlloc(long size) {
25032510
/* pntrString memory allocation/deallocation */

src/mmdata.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ typedef long nmbrString; /* String of numbers */
128128
* pointer. If this array is held in a \ref block, its size can also be
129129
* determined from its header's administrative data. Both values must be kept
130130
* synchronized. In early phases of memory allocation, when data wasn't
131-
* assigned yet, this need not hold.
131+
* assigned yet, this need not hold, though.
132132
*
133133
* To summarize the usages of this type:
134134
* - If you want to resize the array/stack you need a pointer to element 0.
@@ -728,21 +728,31 @@ temp_pntrString *pntrMakeTempAlloc(pntrString *s);
728728
* reallocated, and if it is, it gets twice the needed size to account for
729729
* future growing. If the \p target block is only partially used after copy it
730730
* is added to the \ref memUsedPool. If \p source is empty, the \p target is
731-
*
731+
* to \ref NULL_PNTRSTRING.
732+
* \n
733+
* It is assumed that the value persisted in \p target is in fact computed from
734+
* temporary operands in \ref pntrTempAllocStack. All blocks starting with
735+
* the element at \ref g_pntrTempAllocStackStart are returned to the
736+
* \ref memFreePool.
737+
* \attention freed \ref block "blocks" contain \ref pntrString instances.
738+
* See \ref pntrTempAllocStack to learn how this free process can be
739+
* dangerous if no precautions are taken.
732740
* \param[in,out] target (not null) the address of a pointer pointing to the
733741
* first byte of a \ref block receiving the copied elements of \p source.
734742
* \param[in] source (not null) a pointer to the first \ref pntrString element
735743
* in a \ref block, to be copied from.
736744
* \pre
737-
* - source does not contain NULL pointer, but is terminated by one. This
738-
* NULL pointer is not part of the array, but must be present.
745+
* - source does not contain NULL pointerelements , but is terminated by one.
746+
* This final NULL pointer is not part of the array, but must be present.
739747
* - the target \ref block does not contain any valuable data.
740748
* \post
741749
* - the \ref block \p target points to is filled with a copy of
742750
* \ref pntrString elements \p source points to, padded with a terminal
743751
* NULL.
744752
* - due to a possible reallocation the pointer \p target points to may
745753
* change.
754+
* - The stack pointer of \ref pntrTempAllocStack is reset to
755+
* \ref g_pntrTempAllocStackStart
746756
* - updates \ref db3 and \ref poolTotalFree.
747757
* - Exit on out-of-memory
748758
* \bug If the \p target block is full after the copy operation, it is not

0 commit comments

Comments
 (0)