/**************************************** * Computer Algebra System SINGULAR * ****************************************/ /* $Id: mminit.cc,v 1.2 2009-03-17 09:01:46 Singular Exp $ */ /* * ABSTRACT: init of memory management */ #include #include #include "mod2.h" #include "mmalloc.h" #include "structs.h" // this prevents the definition of malloc/free and macros // by omalloc #define OMALLOC_C #include "omalloc.h" #include int mmIsInitialized=mmInit(); extern "C" { void omSingOutOfMemoryFunc() { fprintf(stderr, "\nerror: no more memory\n"); omPrintStats(stderr); m2_end(14); /* should never get here */ exit(1); } } int mmInit( void ) { if(mmIsInitialized==0) { #if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC) /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */ /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */ /* solution: correctly check OMALLOC_USES_MALLOC from omalloc.h, */ /* do not rely on the default in Singular as libsingular may be different */ mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc); #else mp_set_memory_functions(malloc,reallocSize,freeSize); #endif om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; #ifndef OM_NDEBUG om_Opts.ErrorHook = dErrorBreak; #endif omInitInfo(); #ifdef OM_SING_KEEP om_Opts.Keep = OM_SING_KEEP; #endif } mmIsInitialized=1; return 1; }