Skip to content
Snippets Groups Projects
Commit 991e2a0d authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Fixing SE CLASS2 compilation

parent 5c270972
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ std::string col_stop("\e[0m");
// Print a message when allocation with id==msg_on_alloc is performed
long int msg_on_alloc = -1;
long int msg_on_dealloc = -1;
// throw when allocation with id==throw_on_alloc is performed
long int thr_on_alloc = -1;
......@@ -32,6 +32,7 @@ typedef unsigned char * byte_ptr;
#define MEM_ERROR 1300lu
extern long int msg_on_alloc;
extern long int msg_on_dealloc;
extern long int thr_on_alloc;
extern std::string col_stop;
extern long int new_data;
......@@ -64,8 +65,11 @@ static bool remove_ptr(const void * ptr)
return false;
}
it->second.ref_id--;
// erase the pointer
active_ptr.erase((byte_ptr)ptr);
if (it->second.ref_id == 0)
active_ptr.erase((byte_ptr)ptr);
return true;
}
......@@ -228,6 +232,16 @@ inline static void message_on_alloc(long int break_id)
msg_on_alloc = break_id;
}
/* \brief When the de-allocation id==break_id is performed, print a message
*
* \param break_id
*
*/
inline static void message_on_dealloc(long int break_id)
{
msg_on_dealloc = break_id;
}
/* \brief When the allocation id==break_id is performed, throw
*
* \param throw_id
......@@ -251,14 +265,20 @@ inline static bool check_new(const void * data, size_t sz, size_t struct_id, siz
// Add a new pointer
new_data++;
ptr_info & ptr = active_ptr[(byte_ptr)data];
ptr.size = sz;
if (ptr.ref_id >= 1)
{
if (sz > ptr.size) ptr.size = sz;
}
else
ptr.size = sz;
ptr.id = new_data;
ptr.struct_id = struct_id;
ptr.project_id = project_id;
ptr.ref_id++;
#ifdef SE_CLASS2_VERBOSE
if (process_to_print < 0 || process_to_print == process_v_cl)
std::cout << "New data: " << new_data << " " << data << "\n";
std::cout << "New data: " << new_data << " " << data << " " << ptr.size << "\n";
#endif
if (msg_on_alloc == new_data)
......@@ -283,6 +303,10 @@ inline static bool check_delete(const void * data)
if (data == NULL) return true;
// Delete the pointer
delete_data++;
if (msg_on_dealloc == (long int)delete_data)
std::cout << "Detected destruction: " << __FILE__ << ":" << __LINE__ << " id=" << msg_on_alloc << "\n";
bool result = remove_ptr(data);
#ifdef SE_CLASS2_VERBOSE
......@@ -347,12 +371,28 @@ inline static bool check_valid(const void * ptr, size_t size_access)
if (((unsigned char *)l_b->first) + sz < ((unsigned char *)ptr) + size_access)
{
if (process_to_print < 0 || process_to_print == process_v_cl)
bool found = false;
// Here we do a full search across all the registered pointers
std::map<byte_ptr, ptr_info>::iterator fit = active_ptr.begin();
for(; fit != active_ptr.end(); fit++)
{
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << " base allocation id=" << l_b->second.id << "\n";
ACTION_ON_ERROR(MEM_ERROR);
if (ptr >= fit->first && (((unsigned char *)ptr) + size_access) <= (((unsigned char *)fit->first) + fit->second.size) )
{
found = true;
break;
}
}
if (found == false)
{
if (process_to_print < 0 || process_to_print == process_v_cl)
{
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << "base allocation id=" << l_b->second.id << "\n";
ACTION_ON_ERROR(MEM_ERROR);
}
}
return false;
}
return true;
......
......@@ -48,6 +48,18 @@ public:
{
if (ref_cnt != 0)
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " destroying a live object" << "\n";
#ifdef SE_CLASS2
// Eliminate all the old pointers
// Eliminate all the old pointers (only if has been used)
if (a_seq != 0)
{
for (size_t i = 0 ; i < sequence.size() ; i++)
check_delete(getPointer(i));
}
#endif
}
//! Default constructor
......@@ -133,7 +145,6 @@ public:
*/
virtual bool allocate(size_t sz)
{
// Zero sized allocation are ignored
if (sz == 0)
return true;
......@@ -150,6 +161,12 @@ public:
a_seq++;
#ifdef SE_CLASS2
check_new(getPointer(),sz,HEAPMEMORY_EVENT,0);
#endif
return true;
}
......@@ -239,6 +256,17 @@ public:
void destroy()
{
mem->destroy();
#ifdef SE_CLASS2
// Eliminate all the old pointers (only if has been used)
if (a_seq != 0)
{
for (size_t i = 0 ; i < sequence.size() ; i++)
check_delete(getPointer(i));
}
#endif
}
/*! \brief Copy memory
......
......@@ -11,10 +11,11 @@
struct ptr_info
{
size_t id;
size_t struct_id;
size_t project_id;
size_t size;
size_t id = 0;
size_t struct_id = 0;
size_t project_id = 0;
size_t size = 0;
size_t ref_id = 0;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment