Void ptr external application (#1121)

* #1119 allocate using memory manager

* #1119 replace void* vector with char* vector in external application

Co-authored-by: Fennell, Scott P 263712616 <scott.p.fennell@nasa.gov>
This commit is contained in:
Scott Fennell 2021-03-25 13:17:21 -05:00 committed by GitHub
parent 92ad2a8063
commit f439d95775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -300,7 +300,7 @@ namespace Trick {
/** alloc'd addresses to be deallocated during app destruction (currently only
used by command_c_str) */
std::vector<void*> allocations;
std::vector<char*> allocations;
private:

View File

@ -15,6 +15,8 @@
#include "trick/variable_server_proto.h"
#include "trick/env_proto.h"
#include "trick/command_line_protos.h"
#include "trick/MemoryManager.hh"
extern Trick::MemoryManager* trick_MM;
Trick::ExternalApplication::ExternalApplication() :
command(std::string(env_get_var("TRICK_HOME") + std::string("/bin/"))) {
@ -23,21 +25,23 @@ Trick::ExternalApplication::ExternalApplication() :
width_set = x_set = y_set = auto_reconnect_set = false;
// c_intf uses char *, we manage the memory here in external application
command_c_str = strdup(command.c_str());
allocations.push_back((void*)command_c_str);
command_c_str = (char*)trick_MM->declare_var("char", (command.size() + 1) );
strcpy(command_c_str, command.c_str());
allocations.push_back(command_c_str);
}
Trick::ExternalApplication::~ExternalApplication() {
for(std::vector<void*>::iterator it = allocations.begin(); it != allocations.end(); ++it) {
free(*it);
for(std::vector<char*>::iterator it = allocations.begin(); it != allocations.end(); ++it) {
trick_MM->delete_var(*it);
}
allocations.clear();
}
void Trick::ExternalApplication::set_startup_command(std::string in_command) {
command = in_command;
command_c_str = strdup(in_command.c_str());
allocations.push_back((void *) command_c_str);
command_c_str = (char*)trick_MM->declare_var("char", (command.size() + 1) );
strcpy(command_c_str, command.c_str());
allocations.push_back((command_c_str));
}
std::string Trick::ExternalApplication::get_startup_command() {