diff --git a/la_traits.h b/la_traits.h index 9c28a13..5c82ab7 100644 --- a/la_traits.h +++ b/la_traits.h @@ -69,7 +69,6 @@ extern "C" { namespace LA { -extern bool _LA_count_check; //forward declarations template class NRVec; diff --git a/laerror.cc b/laerror.cc index 94592c4..598cd47 100644 --- a/laerror.cc +++ b/laerror.cc @@ -44,7 +44,8 @@ namespace LA { GPU_START gpu_start_instant; #endif -bool _LA_count_check=true; +const bool _LA_count_check=true; +const bool _LA_warn_empty_copyonwrite=false; extern "C" void _findme(void) {}; //for autoconf test we need a function with C linkage diff --git a/laerror.h b/laerror.h index 632590e..ac9c962 100644 --- a/laerror.h +++ b/laerror.h @@ -28,6 +28,10 @@ extern int traceback(int flags); extern void sigtraceback(int sig,int flags); } +extern const bool _LA_warn_empty_copyonwrite; +extern const bool _LA_count_check; + + //exception class for laerror class LAerror { diff --git a/mat.h b/mat.h index 3f3c659..512843f 100644 --- a/mat.h +++ b/mat.h @@ -1089,7 +1089,13 @@ NRMat & NRMat::operator|=(const NRMat &rhs) { ******************************************************************************/ template void NRMat::copyonwrite(bool detachonly) { - if(!count) laerror("attempt to call copyonwrite() for a matrix with count == 0"); + if(!count) + { + if(nn||mm) laerror("nonempty matrix without reference count encountered"); + if(_LA_warn_empty_copyonwrite) std::cout <<"Warning: copyonwrite of empty matrix\n"; + return; + } + if(*count > 1){ (*count)--; count = new int; diff --git a/smat.h b/smat.h index c2c74e2..975e5b4 100644 --- a/smat.h +++ b/smat.h @@ -957,7 +957,12 @@ NRSMat & NRSMat::operator=(const NRSMat & rhs) { ******************************************************************************/ template void NRSMat::copyonwrite(bool detachonly) { - if(!count) laerror("calling NRSMat::copyonwrite() for undefined NRSMat object"); + if(!count) + { + if(nn) laerror("nonempty smat without reference count encountered"); + if(_LA_warn_empty_copyonwrite) std::cout <<"Warning: copyonwrite of empty smat\n"; + return; + } if(*count > 1){ (*count)--; count = new int; diff --git a/sparsemat.cc b/sparsemat.cc index 1685e85..6507ff6 100644 --- a/sparsemat.cc +++ b/sparsemat.cc @@ -145,7 +145,13 @@ while(l) template void SparseMat::copyonwrite(bool detachonly) { - if(!count) laerror("probably an assignment to undefined sparse matrix"); + if(!count) + { + if(nn||mm) laerror("nonempty sparsemat without reference count encountered"); + if(_LA_warn_empty_copyonwrite) std::cout <<"Warning: copyonwrite of empty sparsemat\n"; + return; + } + if(*count > 1) { (*count)--; diff --git a/vec.h b/vec.h index 1583bd6..84ca3cc 100644 --- a/vec.h +++ b/vec.h @@ -1011,7 +1011,12 @@ NRVec::~NRVec() { ******************************************************************************/ template void NRVec::copyonwrite(bool detachonly) { - if(!count) laerror("copyonwrite of an undefined vector"); + if(!count) + { + if(nn) laerror("nonempty vector without reference count encountered"); + if(_LA_warn_empty_copyonwrite) std::cout <<"Warning: copyonwrite of empty vector\n"; + return; + } if(*count > 1) { (*count)--; count = new int;