deep memory issues. so many issues.
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										36
									
								
								build_linux64/valgrind.supp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								build_linux64/valgrind.supp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					# Save this as valgrind.supp
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   glibc_tls_init
 | 
				
			||||||
 | 
					   Memcheck:Param
 | 
				
			||||||
 | 
					   set_robust_list(head)
 | 
				
			||||||
 | 
					   ...
 | 
				
			||||||
 | 
					   fun:__libc_setup_tls
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   glibc_malloc_init
 | 
				
			||||||
 | 
					   Memcheck:Cond
 | 
				
			||||||
 | 
					   ...
 | 
				
			||||||
 | 
					   fun:ptmalloc_init*
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   glibc_getrandom
 | 
				
			||||||
 | 
					   Memcheck:Cond
 | 
				
			||||||
 | 
					   fun:getrandom
 | 
				
			||||||
 | 
					   ...
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   glibc_dl_init
 | 
				
			||||||
 | 
					   Memcheck:Cond
 | 
				
			||||||
 | 
					   ...
 | 
				
			||||||
 | 
					   fun:_dl_*
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   glibc_tcache_init
 | 
				
			||||||
 | 
					   Memcheck:Cond
 | 
				
			||||||
 | 
					   ...
 | 
				
			||||||
 | 
					   fun:tcache_init*
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@ -12,6 +12,8 @@ namespace amsmathutil25
 | 
				
			|||||||
    void test_amsarray_select();
 | 
					    void test_amsarray_select();
 | 
				
			||||||
    void test_amsarray_sort1();
 | 
					    void test_amsarray_sort1();
 | 
				
			||||||
    void test_amsarray_insertdelete1();
 | 
					    void test_amsarray_insertdelete1();
 | 
				
			||||||
 | 
					    void test_amsarray_insertdelete2();
 | 
				
			||||||
 | 
					    void test_amsarray_minimal();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,13 @@ namespace ams
 | 
				
			|||||||
        amsarray_size_t lmin = 0;
 | 
					        amsarray_size_t lmin = 0;
 | 
				
			||||||
        T defval = T();
 | 
					        T defval = T();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void* test_ptr = malloc(16);
 | 
				
			||||||
 | 
					        if(test_ptr) free(test_ptr);
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            printf("HEAP CORRUPTED before reserve()!\n");
 | 
				
			||||||
 | 
					            return amsarray_failure;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(_newcap<=0)
 | 
					        if(_newcap<=0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            length = 0;
 | 
					            length = 0;
 | 
				
			||||||
@ -61,12 +68,14 @@ namespace ams
 | 
				
			|||||||
            return ret;
 | 
					            return ret;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //this shouldn't be necessary, but I'm getting weird memory bugs.
 | 
				
			||||||
 | 
					        ams::buffer_set<T>(newdata,0,_newcap,defval);
 | 
				
			||||||
        if(data!=NULL)
 | 
					        if(data!=NULL)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            lmin = (_newcap>=reserved) ? reserved : _newcap;
 | 
					            lmin = (_newcap>=reserved) ? reserved : _newcap;
 | 
				
			||||||
            ams::buffer_cast_copy<T,T>(newdata,data,lmin);
 | 
					            ams::buffer_cast_copy<T,T>(newdata,data,lmin);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ams::buffer_set<T>(newdata,reserved,_newcap,defval);
 | 
					        //ams::buffer_set<T>(newdata,reserved,_newcap,defval);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(data!=NULL) {delete[] data; data = NULL;}
 | 
					        if(data!=NULL) {delete[] data; data = NULL;}
 | 
				
			||||||
        data = newdata;
 | 
					        data = newdata;
 | 
				
			||||||
@ -132,7 +141,7 @@ namespace ams
 | 
				
			|||||||
                return ret;
 | 
					                return ret;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            q = (amsarray_size_t)((1.0/growfactor)*(double)_newlen);
 | 
					            q = (amsarray_size_t)((1.0/growfactor)*(double)reserved);
 | 
				
			||||||
            if(_newlen<q)
 | 
					            if(_newlen<q)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                res = this->reserve(_newlen);
 | 
					                res = this->reserve(_newlen);
 | 
				
			||||||
@ -237,6 +246,8 @@ namespace ams
 | 
				
			|||||||
            growfactor = other.growfactor;
 | 
					            growfactor = other.growfactor;
 | 
				
			||||||
            data = other.data;
 | 
					            data = other.data;
 | 
				
			||||||
            other.length = 0;
 | 
					            other.length = 0;
 | 
				
			||||||
 | 
					            other.reserved = 0;
 | 
				
			||||||
 | 
					            other.growfactor = 0;
 | 
				
			||||||
            other.data = NULL;
 | 
					            other.data = NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return *this;
 | 
					        return *this;
 | 
				
			||||||
@ -405,8 +416,8 @@ template<typename T> int amsarray<T>::insert(amsarray_size_t ind, const T& val)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    int ret = amsarray_success;
 | 
					    int ret = amsarray_success;
 | 
				
			||||||
    int res;
 | 
					    int res;
 | 
				
			||||||
    amsarray<T> narr;
 | 
					    amsarray_size_t I, oldlen;
 | 
				
			||||||
    amsarray_size_t I;
 | 
					    amsarray_size_t I0,I1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(ind<0)
 | 
					    if(ind<0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -415,61 +426,45 @@ template<typename T> int amsarray<T>::insert(amsarray_size_t ind, const T& val)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    else if(ind<=this->length)
 | 
					    else if(ind<=this->length)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        res = narr.resize_insert(this->length+1);
 | 
					        oldlen = this->length;
 | 
				
			||||||
        if(res!=amsarray_success)
 | 
					        res = this->resize_insert(this->length + 1);
 | 
				
			||||||
 | 
					        if(res==amsarray_success)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            //for now, do things single threaded.
 | 
				
			||||||
 | 
					            //to do things multithreaded, I'd need another buffer
 | 
				
			||||||
 | 
					            if(this->data!=NULL)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                for(I=oldlen;I>=ind+1;I--)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    this->data[I] = this->data[I-1];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                this->data[ind] = val;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            ret = amsarray_success;
 | 
				
			||||||
 | 
					            return ret;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ret = amsarray_failure;
 | 
					            ret = amsarray_failure;
 | 
				
			||||||
            return ret;
 | 
					            return ret;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if(this->data!=NULL)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            for(I=0;I<ind && I<this->length;I++)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                narr.data[I] = this->data[I];
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        narr.data[ind] = val;
 | 
					 | 
				
			||||||
        if(this->data!=NULL)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            for(I=ind+1;I<narr.length;I++)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                narr.data[I] = this->data[I-1];
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //steal data from narr
 | 
					 | 
				
			||||||
        if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
 | 
					 | 
				
			||||||
        this->length = narr.length;
 | 
					 | 
				
			||||||
        this->data = narr.data;
 | 
					 | 
				
			||||||
        narr.length = 0;
 | 
					 | 
				
			||||||
        narr.data = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        //inserting past the end of the array
 | 
					        //inserting past the end of the array
 | 
				
			||||||
        res = narr.resize_insert(ind+1);
 | 
					        res = this->resize_insert(ind+1);
 | 
				
			||||||
        if(res!=amsarray_success)
 | 
					        if(res!=amsarray_success)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ret = amsarray_failure;
 | 
					            ret = amsarray_failure;
 | 
				
			||||||
            return ret;
 | 
					            return ret;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
        if(this->data!=NULL)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for(I=0;I<this->length;I++)
 | 
					            this->data[ind] = val;
 | 
				
			||||||
            {
 | 
					            ret = amsarray_success;
 | 
				
			||||||
                narr.data[I] = this->data[I];
 | 
					            return ret;
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        narr.data[ind] = val;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //steal data from narr
 | 
					 | 
				
			||||||
        if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
 | 
					 | 
				
			||||||
        this->length = narr.length;
 | 
					 | 
				
			||||||
        this->data = narr.data;
 | 
					 | 
				
			||||||
        narr.length = 0;
 | 
					 | 
				
			||||||
        narr.data = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
@ -480,7 +475,6 @@ template<typename T> int amsarray<T>::erase(amsarray_size_t ind)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    int ret = amsarray_success;
 | 
					    int ret = amsarray_success;
 | 
				
			||||||
    int res;
 | 
					    int res;
 | 
				
			||||||
    amsarray<T> narr;
 | 
					 | 
				
			||||||
    amsarray_size_t I;
 | 
					    amsarray_size_t I;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(ind<0 || ind>=this->length)
 | 
					    if(ind<0 || ind>=this->length)
 | 
				
			||||||
@ -489,31 +483,16 @@ template<typename T> int amsarray<T>::erase(amsarray_size_t ind)
 | 
				
			|||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res = narr.resize_insert(this->length-1);
 | 
					 | 
				
			||||||
    if(res!=amsarray_success)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        ret = amsarray_failure;
 | 
					 | 
				
			||||||
        return ret;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(this->data!=NULL)
 | 
					    if(this->data!=NULL)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        for(I=0;I<ind && I<this->length && I<narr.length;I++)
 | 
					        for(I=ind;I<this->length-1;I++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            narr.data[I] = this->data[I];
 | 
					            this->data[I] = this->data[I+1];
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        for(I=ind+1;I<this->length && (I-1)<narr.length;I++)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            narr.data[I-1] = this->data[I];
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        this->data[this->length-1] = T();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    res = this->resize_insert(this->length-1);
 | 
				
			||||||
    //steal data from narr (should be similar to what std::move would do?)
 | 
					    ret = res;
 | 
				
			||||||
    if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
 | 
					 | 
				
			||||||
    this->length = narr.length;
 | 
					 | 
				
			||||||
    this->data = narr.data;
 | 
					 | 
				
			||||||
    narr.length = 0;
 | 
					 | 
				
			||||||
    narr.data = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -611,7 +590,7 @@ template<typename T> bool amsarray<T>::operator==(const amsarray<T>& other) cons
 | 
				
			|||||||
    amsarray_size_t I;
 | 
					    amsarray_size_t I;
 | 
				
			||||||
    int J;
 | 
					    int J;
 | 
				
			||||||
    int nthreads;
 | 
					    int nthreads;
 | 
				
			||||||
    std::vector<std::thread*> threads;
 | 
					    amsarray<std::thread*> threads;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(this->length != other.length)
 | 
					    if(this->length != other.length)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
@ -246,6 +246,53 @@ void test_amsarray_insertdelete1()
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct testing_amsarray_somelargestruct
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int q1[50];
 | 
				
			||||||
 | 
					    float q2[255];
 | 
				
			||||||
 | 
					    testing_amsarray_somelargestruct() {
 | 
				
			||||||
 | 
					        memset(q1, 0, sizeof(q1));
 | 
				
			||||||
 | 
					        memset(q2, 0, sizeof(q2));
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void test_amsarray_insertdelete2()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int I,J;
 | 
				
			||||||
 | 
					    //int K;
 | 
				
			||||||
 | 
					    amsarray<testing_amsarray_somelargestruct> la;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    la.resize(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(I=0;I<255;I++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        la.append(testing_amsarray_somelargestruct());
 | 
				
			||||||
 | 
					        printf("la length: %ld reserved: %ld\n", (long)la.length, (long)la.reserved);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for(I=0;I<255;I++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        J = la.length-1;
 | 
				
			||||||
 | 
					        la.erase(J);
 | 
				
			||||||
 | 
					        printf("la length: %ld reserved: %ld\n", (long)la.length, (long)la.reserved);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void test_amsarray_minimal()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    amsarray<int> simple_array;
 | 
				
			||||||
 | 
					    for(int i = 0; i < 10; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        simple_array.append(i);
 | 
				
			||||||
 | 
					        printf("Length: %ld\n", simple_array.length);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,8 @@
 | 
				
			|||||||
#include <amsmathutil25/amsmathutil25.hpp>
 | 
					#include <amsmathutil25/amsmathutil25.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace ams;
 | 
				
			||||||
 | 
					using namespace ams::amsmathutil25;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char* argv[])
 | 
					int main(int argc, char* argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret = 0;
 | 
					    int ret = 0;
 | 
				
			||||||
@ -9,7 +12,10 @@ int main(int argc, char* argv[])
 | 
				
			|||||||
    //ams::amsmathutil25::test_amsarray2();
 | 
					    //ams::amsmathutil25::test_amsarray2();
 | 
				
			||||||
    //ams::amsmathutil25::test_amsarray_select();
 | 
					    //ams::amsmathutil25::test_amsarray_select();
 | 
				
			||||||
    //ams::amsmathutil25::test_amsarray_sort1();
 | 
					    //ams::amsmathutil25::test_amsarray_sort1();
 | 
				
			||||||
    ams::amsmathutil25::test_amsarray_insertdelete1();
 | 
					    //test_amsarray_insertdelete1();
 | 
				
			||||||
 | 
					    //test_amsarray_insertdelete2();
 | 
				
			||||||
 | 
					    test_amsarray_minimal();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user