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

nasa / trick / 14740747793

29 Apr 2025 08:30PM UTC coverage: 55.958% (-0.06%) from 56.017%
14740747793

push

github

web-flow
Fix several ICG class template bugs (#1871)

* Fix several bugs with processing templates in ICG

- Fixed an issue where io_src code for some templates was being placed in the
  wrong file.
- Fixed an issue with templates being instantiated with templates as parameters.
- Fixed an issue with templates that instantiate templates.

Added additional tests to cover these cases.

* Moved the list of template argument header dependencies from ClassValues to PrintFileContents10 so they can be printed to the io_ file regardless of the order in which class info is printed.

* Moved the list of template argument header dependencies from ClassValues to PrintFileContents10 so they can be printed to the io_ file regardless of the order in which class info is printed.

Moved the list of template argument header dependencies from ClassValues to PrintFileContents10 so they can be printed to the io_ file regardless of the order in which class info is printed.

* Added support to handle template enum class type argument and removed some commented code.

Added support to handle template enum class type argument and removed some commented code.

---------

Co-authored-by: Hong Chen <hchen99@users.noreply.github.com>

12332 of 22038 relevant lines covered (55.96%)

266375.59 hits per line

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

93.24
/trick_source/sim_services/MemoryManager/MemoryManager.cpp
1
#include <dlfcn.h>
2
#include <stdlib.h>
3
#include "trick/MemoryManager.hh"
4
#include "trick/ClassicCheckPointAgent.hh"
5
// Global pointer to the (singleton) MemoryManager for the C language interface.
6
Trick::MemoryManager * trick_MM = NULL;
7

8
// CLASS VARIABLE INITIALIZATION
9
int Trick::MemoryManager::instance_count = 0;
10
bool Trick::MemoryManager::restore_stls_default = true;
11

12
// CONSTRUCTOR
13
Trick::MemoryManager::MemoryManager()
636✔
14
{
15

16

17
    // The MemoryManager is a singleton. That is only one instance of it is allowed.
18
    if (instance_count != 0) {
627✔
19
        throw std::logic_error("Only one instance of the Memory Manager is allowed.");
1✔
20
    }
21
    instance_count ++;
626✔
22

23
    debug_level = 0;
626✔
24
    hexfloat_checkpoint = 0;
626✔
25
    reduced_checkpoint  = 1;
626✔
26
    resetting_memory = false;
626✔
27
    expanded_arrays  = 0;
626✔
28
    // start counter at 100mil.  This (hopefully) ensures all alloc'ed ids are after external variables.
29
    alloc_info_map_counter = 100000000 ;
626✔
30
    // start counter at 0.  This forces extern vars to appear in front of actual allocations in checkpoint.
31
    extern_alloc_info_map_counter = 0 ;
626✔
32
    pthread_mutex_init(&mm_mutex, NULL);
626✔
33

34
    defaultCheckPointAgent = new ClassicCheckPointAgent( this);
626✔
35
    defaultCheckPointAgent->set_reduced_checkpoint( reduced_checkpoint);
626✔
36
    defaultCheckPointAgent->set_hexfloat_checkpoint( hexfloat_checkpoint);
626✔
37
    defaultCheckPointAgent->set_debug_level( debug_level);
626✔
38

39
    currentCheckPointAgent = defaultCheckPointAgent;
626✔
40

41
    dlhandles.push_back(dlopen( NULL, RTLD_LAZY)) ;
626✔
42

43
    local_anon_var_prefix = "trick_anon_local_";
626✔
44
    extern_anon_var_prefix = "trick_anon_extern_";
626✔
45

46
    primitive_types.insert(std::string("char")) ;
626✔
47
    primitive_types.insert(std::string("unsigned char")) ;
626✔
48
    primitive_types.insert(std::string("short")) ;
626✔
49
    primitive_types.insert(std::string("unsigned short")) ;
626✔
50
    primitive_types.insert(std::string("int")) ;
626✔
51
    primitive_types.insert(std::string("unsigned int")) ;
626✔
52
    primitive_types.insert(std::string("long")) ;
626✔
53
    primitive_types.insert(std::string("unsigned long")) ;
626✔
54
    primitive_types.insert(std::string("long long")) ;
626✔
55
    primitive_types.insert(std::string("unsigned long long")) ;
626✔
56
    primitive_types.insert(std::string("double")) ;
626✔
57
    primitive_types.insert(std::string("float")) ;
626✔
58
    primitive_types.insert(std::string("bool")) ;
626✔
59
    // add stdint.h types
60
    primitive_types.insert(std::string("int8_t")) ;
626✔
61
    primitive_types.insert(std::string("uint8_t")) ;
626✔
62
    primitive_types.insert(std::string("int16_t")) ;
626✔
63
    primitive_types.insert(std::string("uint16_t")) ;
626✔
64
    primitive_types.insert(std::string("int32_t")) ;
626✔
65
    primitive_types.insert(std::string("uint32_t")) ;
626✔
66
    primitive_types.insert(std::string("int64_t")) ;
626✔
67
    primitive_types.insert(std::string("uint64_t")) ;
626✔
68

69
    trick_MM = this;
626✔
70
    return ;
626✔
71
}
72

73
Trick::MemoryManager::~MemoryManager() {
625✔
74

75
    ALLOC_INFO_MAP::iterator ait ;
625✔
76

77
    if (instance_count > 0) {
625✔
78
        instance_count --;
625✔
79
    }
80

81
    delete defaultCheckPointAgent ;
625✔
82

83
    for ( ait = alloc_info_map.begin() ; ait != alloc_info_map.end() ; ++ait ) {
7,750✔
84
        ALLOC_INFO * ai_ptr = (*ait).second ;
7,125✔
85
        if (ai_ptr->stcl == TRICK_LOCAL) {
7,125✔
86
            if ( ai_ptr->alloc_type == TRICK_ALLOC_MALLOC ) {
2,357✔
87
                free((char *)ai_ptr->start - ai_ptr->sentinel_bytes) ;
1,703✔
88
            } else if ( ai_ptr->alloc_type == TRICK_ALLOC_NEW ) {
654✔
89
                io_src_delete_class( ai_ptr );
33✔
90
            }
91
        }
92
        if (ai_ptr->name) { free(ai_ptr->name); }
7,125✔
93
        if (ai_ptr->user_type_name) { free(ai_ptr->user_type_name); }
7,125✔
94
        free(ai_ptr) ;
7,125✔
95
    }
96
    alloc_info_map.clear() ;
625✔
97
}
625✔
98

99
#include <sstream>
100
void Trick::MemoryManager::emitMessage( std::string message) {
8✔
101
    std::cerr << "MemoryManager:" << message << std::endl;
8✔
102
    std::cerr.flush();
8✔
103
}
8✔
104

105
void Trick::MemoryManager::emitError( std::string message) {
8✔
106
    std::stringstream ss;
8✔
107
    ss << "ERROR:" << message << std::endl;
8✔
108
    emitMessage( ss.str() );
8✔
109
}
8✔
110

111
void Trick::MemoryManager::emitWarning( std::string message) {
×
112
    std::stringstream ss;
×
113
    ss << "WARNING:" << message << std::endl;
×
114
    emitMessage( ss.str() );
×
115
}
×
116

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