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

thoni56 / c-xrefactory / 1598

08 Oct 2025 10:56AM UTC coverage: 25.401% (-54.8%) from 80.177%
1598

push

travis-ci

thoni56
Add llvm-cov to gcov conversion for Emacs cov-mode support

- Create llvm2gcov.sh script to convert Apple coverage to traditional format
- Parse llvm-cov show output and transform to gcov-compatible format
- Handle count formats including 'k' suffix (4.18k -> 4180)
- Generate proper gcov headers for Emacs compatibility
- Integrate conversion into Darwin gcov target
- Preserve full Emacs fringe coverage display functionality

Now Darwin users get both:
- Superior Apple coverage accuracy
- Full Emacs cov-mode integration

4019 of 15822 relevant lines covered (25.4%)

3416.81 hits per line

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

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

3
#include <string.h>
4

5
#include "commons.h"
6
#include "constants.h"
7
#include "head.h"
8
#include "log.h"
9
#include "memory.h"
10
#include "proto.h"
11

12

13

14
CodeBlock *currentBlock;
15

16

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

20
/* Inject the function to call for error() */
21
static void (*error)(int code, char *message);
22
void setErrorHandlerForStackMemory(void (*function)(int code, char *message)) {
×
23
    error = function;
×
24
}
25

26
/* Stack memory - in this we allocate blocks which have separate free indices */
27
char stackMemory[SIZE_stackMemory];   /* Allocation using stackMemoryAlloc() et.al */
28

29

30
static void frameDump(void) {
×
31
    log_trace("*** begin frameDump");
×
32
    for (FrameAllocation *f=currentBlock->frameAllocations; f!=NULL; f=f->next)
×
33
        log_trace("%p ", f);
×
34
    log_trace("*** end frameDump");
×
35
}
36

37

38
void addToFrame(void (*action)(void*), void *argument) {
×
39
    FrameAllocation *f;
40

41
    f = stackMemoryAlloc(sizeof(FrameAllocation));
×
42
    f->action = action;
×
43
    f->argument = (void **) argument;
×
44
    f->next = currentBlock->frameAllocations;
×
45
    currentBlock->frameAllocations = f;
×
46
    if (memoryTrace)
×
47
        frameDump();
×
48
}
49

50
void removeFromFrameUntil(FrameAllocation *untilP) {
1✔
51
    FrameAllocation *f;
52
    for (f=currentBlock->frameAllocations; untilP<f; f=f->next) {
×
53
        assert(f!=NULL);
×
54
        (*(f->action))(f->argument);
55
    }
1✔
56
    if (f!=untilP) {
×
57
        error(ERR_INTERNAL, "block structure mismatch?");
58
    }
1✔
59
    currentBlock->frameAllocations = f;
1✔
60
    if (memoryTrace)
×
61
        frameDump();
1✔
62
}
63

26✔
64
static void fillCodeBlock(CodeBlock *block, int firstFreeIndex, FrameAllocation *allocation, CodeBlock *outerBlock) {
26✔
65
    block->firstFreeIndex = firstFreeIndex;
26✔
66
    block->frameAllocations = allocation;
26✔
67
    block->outerBlock = outerBlock;
26✔
68
}
69

24✔
70
void initOuterCodeBlock(void) {
71
    /* Any use of stack memory will require that this is run first */
24✔
72
    currentBlock = (CodeBlock *) stackMemory;
24✔
73
    fillCodeBlock(currentBlock, sizeof(CodeBlock), NULL, NULL);
24✔
74
}
75

76
static int stackMemoryMax = 0;
77

6,000,018✔
78
void *stackMemoryAlloc(int size) {
79
    int i;
80

6,000,018✔
81
    assert(currentBlock);
6,000,018✔
82
    mem_trace("stackMemoryAlloc: allocating %d bytes", size);
6,000,017✔
83
    i = currentBlock->firstFreeIndex;
6,000,017✔
84
    if (i+size < SIZE_stackMemory) {
6,000,017✔
85
        currentBlock->firstFreeIndex = i+size;
6,000,017✔
86
        if (currentBlock->firstFreeIndex > stackMemoryMax)
87
            stackMemoryMax = currentBlock->firstFreeIndex;
1✔
88
        return &stackMemory[i];
89
    } else {
1✔
90
        fatalError(ERR_ST,"i+size > SIZE_stackMemory,\n\tstack memory overflowed,\n\tread TROUBLES section of README file\n", XREF_EXIT_ERR, __FILE__, __LINE__);
91
        /* Should not return, but for testing and compilers sake return something */
92
        return NULL;
93
    }
2✔
94
}
2✔
95

2✔
96
static void *stackMemoryPush(void *pointer, int size) {
2✔
97
    void *new = stackMemoryAlloc(size);
98
    memcpy(new, pointer, size);
99
    return new;
×
100
}
×
101

×
102
char *stackMemoryPushString(char *string) {
103
    log_trace("Pushing string '%s'", string);
104
    return (char*)stackMemoryPush(string, strlen(string)+1);
2✔
105
}
106

2✔
107
void beginBlock(void) {
2✔
108
    CodeBlock *pushed, previous;
2✔
109
    log_trace("Begin block");
110
    previous = *currentBlock;
111
    pushed = stackMemoryPush(&previous, sizeof(CodeBlock));
2✔
112
    // allocation can't be reset to NULL, because in case of syntax errors
2✔
113
    // this would avoid balancing of } at the end of class
114
    fillCodeBlock(currentBlock, currentBlock->firstFreeIndex, currentBlock->frameAllocations, pushed);
1✔
115
}
1✔
116

117
void endBlock(void) {
1✔
118
    log_trace("End block");
1✔
119
    //&removeFromFrameUntil(NULL);
1✔
120
    assert(currentBlock && currentBlock->outerBlock);
121
    removeFromFrameUntil(currentBlock->outerBlock->frameAllocations);
2✔
122
    *currentBlock =  *currentBlock->outerBlock;
2✔
123
    assert(currentBlock != NULL);
2✔
124
}
3✔
125

1✔
126
int nestingLevel(void) {
1✔
127
    int level = 0;
128
    CodeBlock *block = currentBlock;
2✔
129
    while (block->outerBlock != NULL) {
130
        block = block->outerBlock;
131
        level++;
×
132
    }
×
133
    return level;
×
134
}
×
135

136
bool isMemoryFromPreviousBlock(void *address) {
137
    return currentBlock->outerBlock != NULL &&
×
138
        (char*)address > stackMemory &&
×
139
        (char*)address < stackMemory + currentBlock->outerBlock->firstFreeIndex;
×
140
}
141

142
bool isFreedStackMemory(void *ptr) {
×
143
    return ((char*)ptr >= stackMemory + currentBlock->firstFreeIndex &&
×
144
            (char*)ptr < stackMemory + SIZE_stackMemory);
145
}
146

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

© 2026 Coveralls, Inc