• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoni56 / c-xrefactory / 1767

04 Apr 2026 07:37PM UTC coverage: 82.964% (+0.3%) from 82.708%
1767

push

travis-ci

thoni56
[tidy][unused] Remove more unused things after the full migration to memory-is-truth

15676 of 18895 relevant lines covered (82.96%)

15556225.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.67
src/stackmemory.c
1
#include "stackmemory.h"
2

3
#include <string.h>
4
#include <stdlib.h>
5

6
#include "commons.h"
7
#include "constants.h"
8
#include "log.h"
9
#include "proto.h"
10

11

12

13
CodeBlock *currentBlock;
14

15

16
static bool memoryTrace = false;
17
#define mem_trace(...)  { if (memoryTrace) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__); }
18

19

20
/* Stack memory - in this we allocate blocks which have separate free indices */
21
char stackMemory[StackMemorySize];   /* Allocation using stackMemoryAlloc() et.al */
22

23

24
static void frameDump(void) {
×
25
    log_debug("*** begin frameDump");
×
26
    for (FrameAllocation *f=currentBlock->frameAllocations; f!=NULL; f=f->next)
×
27
        log_debug("%p ", f);
×
28
    log_debug("*** end frameDump");
×
29
}
30

31

32
void addToFrame(void (*action)(void*), void *argument) {
9,905,102✔
33
    FrameAllocation *f;
34

35
    f = stackMemoryAlloc(sizeof(FrameAllocation));
9,905,102✔
36
    f->action = action;
9,905,102✔
37
    f->argument = (void **) argument;
9,905,102✔
38
    f->next = currentBlock->frameAllocations;
9,905,102✔
39
    currentBlock->frameAllocations = f;
9,905,102✔
40
    if (memoryTrace)
9,905,102✔
41
        frameDump();
×
42
}
9,905,102✔
43

44
void removeFromFrameUntil(FrameAllocation *untilP) {
2,614,510✔
45
    FrameAllocation *f;
46
    for (f=currentBlock->frameAllocations; untilP<f; f=f->next) {
3,775,710✔
47
        assert(f!=NULL);
1,161,200✔
48
        (*(f->action))(f->argument);
49
    }
2,614,510✔
50
    assert(f == untilP && "block structure mismatch");
2,614,510✔
51
    currentBlock->frameAllocations = f;
×
52
    if (memoryTrace)
2,614,510✔
53
        frameDump();
54
}
2,618,817✔
55

2,618,817✔
56
static void fillCodeBlock(CodeBlock *block, int firstFreeIndex, FrameAllocation *allocation, CodeBlock *outerBlock) {
2,618,817✔
57
    block->firstFreeIndex = firstFreeIndex;
2,618,817✔
58
    block->frameAllocations = allocation;
2,618,817✔
59
    block->outerBlock = outerBlock;
60
}
4,246✔
61

62
void initOuterCodeBlock(void) {
4,246✔
63
    /* Any use of stack memory will require that this is run first */
4,246✔
64
    currentBlock = (CodeBlock *) stackMemory;
4,246✔
65
    fillCodeBlock(currentBlock, sizeof(CodeBlock), NULL, NULL);
66
}
67

68
static int stackMemoryMax = 0;
120,485,113✔
69

70
void *stackMemoryAlloc(int size) {
71
    int i;
120,485,113✔
72

120,485,113✔
73
    assert(currentBlock);
120,485,112✔
74
    mem_trace("stackMemoryAlloc: allocating %d bytes", size);
120,485,112✔
75
    i = currentBlock->firstFreeIndex;
20,461,994✔
76
    if (i+size < StackMemorySize) {
120,485,112✔
77
        currentBlock->firstFreeIndex = i+size;
78
        if (currentBlock->firstFreeIndex > stackMemoryMax)
1✔
79
            stackMemoryMax = currentBlock->firstFreeIndex;
80
        return &stackMemory[i];
1✔
81
    } else {
82
        fatalError(ERR_ST,"i+size > SIZE_stackMemory,\n\tstack memory overflowed,\n\tread TROUBLES section of README file\n", EXIT_FAILURE, __FILE__, __LINE__);
83
        /* Should not return, but for testing and compilers sake return something */
84
        return NULL;
22,450,112✔
85
    }
22,450,112✔
86
}
22,450,112✔
87

22,450,112✔
88
static void *stackMemoryPush(void *pointer, int size) {
89
    void *new = stackMemoryAlloc(size);
90
    memcpy(new, pointer, size);
19,835,541✔
91
    return new;
19,835,541✔
92
}
19,835,541✔
93

94
char *stackMemoryPushString(char *string) {
95
    log_debug("Pushing string '%s'", string);
2,614,571✔
96
    return (char*)stackMemoryPush(string, strlen(string)+1);
97
}
2,614,571✔
98

2,614,571✔
99
void beginBlock(void) {
2,614,571✔
100
    CodeBlock *pushed, previous;
101
    log_debug("Begin block");
102
    previous = *currentBlock;
2,614,571✔
103
    pushed = stackMemoryPush(&previous, sizeof(CodeBlock));
2,614,571✔
104
    // allocation can't be reset to NULL, because in case of syntax errors
105
    // this would avoid balancing of } at the end of class
2,614,510✔
106
    fillCodeBlock(currentBlock, currentBlock->firstFreeIndex, currentBlock->frameAllocations, pushed);
2,614,510✔
107
}
108

2,614,510✔
109
void endBlock(void) {
2,614,510✔
110
    log_debug("End block");
2,614,510✔
111
    //&removeFromFrameUntil(NULL);
112
    assert(currentBlock && currentBlock->outerBlock);
14,514,899✔
113
    removeFromFrameUntil(currentBlock->outerBlock->frameAllocations);
14,514,899✔
114
    *currentBlock =  *currentBlock->outerBlock;
14,514,899✔
115
    assert(currentBlock != NULL);
17,813,658✔
116
}
3,298,759✔
117

3,298,759✔
118
int nestingLevel(void) {
119
    int level = 0;
14,514,899✔
120
    CodeBlock *block = currentBlock;
121
    while (block->outerBlock != NULL) {
122
        block = block->outerBlock;
818,268✔
123
        level++;
33,413✔
124
    }
851,681✔
125
    return level;
33,413✔
126
}
127

128
bool isMemoryFromPreviousBlock(void *address) {
8,504,899✔
129
    return currentBlock->outerBlock != NULL &&
16,769,918✔
130
        (char*)address > stackMemory &&
8,265,019✔
131
        (char*)address < stackMemory + currentBlock->outerBlock->firstFreeIndex;
132
}
133

×
134
bool isFreedStackMemory(void *ptr) {
×
135
    return ((char*)ptr >= stackMemory + currentBlock->firstFreeIndex &&
136
            (char*)ptr < stackMemory + StackMemorySize);
137
}
138

139
void stackMemoryStatistics(void) {
140
    printf("Max memory use for stack: %d\n", stackMemoryMax);
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc