• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

nasa / trick / 25456501308

06 May 2026 07:29PM UTC coverage: 55.935% (-0.8%) from 56.7%
25456501308

Pull #2011

github

web-flow
Merge 7ad262960 into 7054e405e
Pull Request #2011: Single-file CI and code style adoption

14612 of 26123 relevant lines covered (55.94%)

462107.16 hits per line

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

58.25
/trick_source/sim_services/MemoryManager/MemoryManager_io_src_intf.cpp
1

2
#include <sstream>
3
// Provides stringstream.
4
#include <dlfcn.h>
5
// Provides dlsym().
6
#include <string.h>
7
#include "trick/MemoryManager.hh"
8

9
// MEMBER FUNCTION: void* Trick::MemoryManager::io_src_allocate_class(const char* class_name, int num);
10

11
/**
12
 * For every class processed by ICG (Interface Code Generator),
13
 * the generated io_src code contains a function whose name is
14
 * of the form: io_src_allocate_<class_name>.
15
 *
16
 * The purpose of this io_src function is to allocate one or more instances of the class.
17
 * The purpose of Trick::MemoryManager::io_src_allocate_class() is to call the io_src function.
18
 * - This requires that the io_src code be linked into the executable.
19
 * - Then given the name of the class, we can prepend the string "io_src_allocate_"
20
 * to form the name of the function.
21
 * - Then we look up the address of the function by name, using dlsym().
22
 * - If we find it, then we call it and return the address of the allocation.
23
 * - Otherwise we whine that we couldn't find it and return NULL.
24
 */
25
void* Trick::MemoryManager::io_src_allocate_class(const char* class_name, int num) {
700✔
26

27
    char alloc_fn_name[512];
28
    void* (*construct)(int) = NULL ;
700✔
29
    void* addr = NULL;
700✔
30
    unsigned int ii;
31

32
    alloc_fn_name[0] = '\0';
700✔
33
    strcat(alloc_fn_name, "io_src_allocate_");
700✔
34
    strcat(alloc_fn_name, class_name);
700✔
35

36
    for (ii = 0; ii < strlen(alloc_fn_name); ii++) {
25,150✔
37
        if ( alloc_fn_name[ii] == ':') {
24,450✔
38
            alloc_fn_name[ii] = '_';
996✔
39
        }
40
    }
41

42
    for ( ii = 0 ; ii < dlhandles.size() && construct == NULL ; ii++ ) {
1,400✔
43
        construct = (void*(*)(int)) dlsym( dlhandles[ii], alloc_fn_name);
700✔
44
    }
45
    if ( construct != NULL) {
700✔
46
        addr = (*construct)(num) ;
700✔
47
    } else {
48
        const char* msg = dlerror();
×
49
        addr = NULL;
×
50
        std::stringstream message;
×
51
        message << "Couldn't find function \"" << alloc_fn_name << "()\". "
52
                << "dlerror= " << msg;
×
53
        emitError(message.str());
×
54
    }
×
55
    return (addr);
700✔
56
}
57

58
// MEMBER FUNCTION: void Trick::MemoryManager::io_src_destruct_class(ALLOC_INFO * alloc_info);
59
void Trick::MemoryManager::io_src_destruct_class(ALLOC_INFO * alloc_info) {
2,236✔
60

61
    char destruct_fn_name[512];
62
    void* (*destruct)(void*, int) = NULL ;
2,236✔
63

64
    if ( (alloc_info->type == TRICK_STRUCTURED) &&
2,236✔
65
        (alloc_info->language == Language_CPP) &&
312✔
66
        ((alloc_info->num_index == 0) || (alloc_info->index[alloc_info->num_index-1] != 0))) {
277✔
67

68
        destruct_fn_name[0] = '\0';
277✔
69
        strcat(destruct_fn_name, "io_src_destruct_");
277✔
70
        strcat(destruct_fn_name, alloc_info->user_type_name );
277✔
71

72
        for (size_t ii = 0; ii < strlen(destruct_fn_name); ii++) {
11,082✔
73
            if ( destruct_fn_name[ii] == ':') {
10,805✔
74
                destruct_fn_name[ii] = '_';
532✔
75
            }
76
        }
77

78
        for (size_t  ii = 0 ; ii < dlhandles.size() && destruct == NULL ; ii++ ) {
554✔
79
            destruct = (void*(*)(void*,int)) dlsym( dlhandles[ii], destruct_fn_name);
277✔
80
        }
81
        if ( destruct != NULL) {
277✔
82
            (*destruct)(alloc_info->start, alloc_info->num) ;
277✔
83
        } else {
84
            const char* msg = dlerror();
×
85
            std::stringstream message;
×
86
            message << "Couldn't find function \"" << destruct_fn_name << "()\". "
87
                    << "dlerror= " << msg;
×
88
            emitError(message.str());
×
89
        }
×
90
    }
91
}
2,236✔
92

93
// MEMBER FUNCTION: void Trick::MemoryManager::io_src_delete_class(ALLOC_INFO * alloc_info);
94
void Trick::MemoryManager::io_src_delete_class(ALLOC_INFO * alloc_info) {
59✔
95
    char delete_fn_name[512];
96
    void* (*delete_fn)(void*) = NULL ;
59✔
97

98
    if ( (alloc_info->type == TRICK_STRUCTURED) &&
59✔
99
        (alloc_info->language == Language_CPP) &&
53✔
100
        ((alloc_info->num_index == 0) || (alloc_info->index[alloc_info->num_index-1] != 0))) {
44✔
101

102
        delete_fn_name[0] = '\0';
44✔
103
        strcat(delete_fn_name, "io_src_delete_");
44✔
104
        strcat(delete_fn_name, alloc_info->user_type_name );
44✔
105

106
        for (size_t ii = 0; ii < strlen(delete_fn_name); ii++) {
1,292✔
107
            if ( delete_fn_name[ii] == ':') {
1,248✔
108
                delete_fn_name[ii] = '_';
88✔
109
            }
110
        }
111

112
        for (size_t  ii = 0 ; ii < dlhandles.size() && delete_fn == NULL ; ii++ ) {
88✔
113
            delete_fn = (void*(*)(void*)) dlsym( dlhandles[ii], delete_fn_name);
44✔
114
        }
115
        if ( delete_fn != NULL) {
44✔
116
            (*delete_fn)(alloc_info->start) ;
44✔
117
        } else {
118
            const char* msg = dlerror();
×
119
            std::stringstream message;
×
120
            message << "Couldn't find function \"" << delete_fn_name << "()\". "
121
                    << "dlerror= " << msg;
×
122
            emitError(message.str());
×
123
        }
×
124
    }
125
}
59✔
126

127
// MEMBER FUNCTION: size_t Trick::MemoryManager::io_src_sizeof_user_type( const char* user_type_name);
128
/**
129
 * There should be a function whose name is of the form:
130
 *      io_src_sizeof_<user_type>
131
 * linked into the simulation executable. We need to find
132
 * it and call it.
133
 */
134
size_t Trick::MemoryManager::io_src_sizeof_user_type( const char* user_type_name) {
5,634✔
135

136
    char size_fn_name[512];
137
    size_t (*size_fn)(void) = NULL ;
5,634✔
138
    size_t class_size = 0;
5,634✔
139
    unsigned int ii;
140

141
    size_fn_name[0] = '\0';
5,634✔
142
    strcat(size_fn_name, "io_src_sizeof_");
5,634✔
143
    strcat(size_fn_name, user_type_name);
5,634✔
144

145
    for (ii = 0; ii < strlen(size_fn_name); ii++) {
197,150✔
146
        if ( size_fn_name[ii] == ':') {
191,516✔
147
            size_fn_name[ii] = '_';
2,216✔
148
        }
149
    }
150

151
    for ( ii = 0 ; ii < dlhandles.size() && size_fn == NULL ; ii++ ) {
11,268✔
152
        size_fn = (size_t (*)(void)) dlsym( dlhandles[ii], size_fn_name);
5,634✔
153
    }
154
    if ( size_fn != NULL) {
5,634✔
155
        class_size = (*size_fn)() ;
5,634✔
156
    } else {
157
        const char* msg = dlerror();
×
158
        class_size = 0;
×
159
        std::stringstream message;
×
160
        message << "Couldn't find function \"" << size_fn_name << "()\". "
161
                << "dlerror= " << msg;
×
162
        emitError(message.str());
×
163
    }
×
164
    return (class_size);
5,634✔
165
}
166

167
// PRIVATE MEMBER FUNCTION
168
void Trick::MemoryManager::debug_write_alloc_info( ALLOC_INFO *alloc_info) {
×
169

170
    int ii;
171
    std::cout << "alloc_info->start = " << alloc_info->start << std::endl;
×
172
    std::cout << "alloc_info->end   = " << alloc_info->end << std::endl;
×
173
    std::cout << "alloc_info->num   = " << alloc_info->num << std::endl;
×
174
    std::cout << "alloc_info->size  = " << alloc_info->size << std::endl;
×
175
    std::cout << "alloc_info->type  = " << alloc_info->type << std::endl;
×
176
    std::cout << "alloc_info->stcl = " ;
×
177
    if (alloc_info->stcl == TRICK_LOCAL) { std::cout << "TRICK_LOCAL" << std::endl; }
×
178
    if (alloc_info->stcl == TRICK_EXTERN) { std::cout << "TRICK_EXTERN" << std::endl; }
×
179
    std::cout << "alloc_info->language = ";
×
180
    if (alloc_info->language == Language_C  ) { std::cout << "Language_C" << std::endl; }
×
181
    if (alloc_info->language == Language_CPP) { std::cout << "Language_CPP" << std::endl; }
×
182
    std::cout << std::endl;
×
183
    if (alloc_info->user_type_name) {
×
184
        std::cout << "alloc_info->user_type_name = " << alloc_info->user_type_name << std::endl;
×
185
    }
186
    std::cout << "alloc_info->index = " ;
×
187
    for (ii=0; ii<alloc_info->num_index; ii++) {
×
188
        std::cout << "[" << alloc_info->index[ii] << "]";
×
189
    }
190
    std::cout << std::endl;
×
191
    std::cout.flush();
×
192
}
×
193

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