Changed: Header inclusion order corrected
[ode.git] / ode / src / memory.cpp
blobdca074cca52901f3a9fe03d5f0dbb6b0b876003a
1 /*************************************************************************
2 * *
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of EITHER: *
8 * (1) The GNU Lesser General Public License as published by the Free *
9 * Software Foundation; either version 2.1 of the License, or (at *
10 * your option) any later version. The text of the GNU Lesser *
11 * General Public License is included with this library in the *
12 * file LICENSE.TXT. *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
15 * *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 * *
21 *************************************************************************/
23 #include <ode/odeconfig.h>
24 #include <ode/memory.h>
25 #include <ode/error.h>
26 #include "config.h"
29 static dAllocFunction *allocfn = 0;
30 static dReallocFunction *reallocfn = 0;
31 static dFreeFunction *freefn = 0;
33 #ifdef __MINGW32__
34 /*
35 this is a guard against AC_FUNC_MALLOC and AC_FUNC_REALLOC
36 which break cross compilation, no issues in native MSYS.
38 #undef malloc
39 #undef realloc
40 #endif
42 void dSetAllocHandler (dAllocFunction *fn)
44 allocfn = fn;
48 void dSetReallocHandler (dReallocFunction *fn)
50 reallocfn = fn;
54 void dSetFreeHandler (dFreeFunction *fn)
56 freefn = fn;
60 dAllocFunction *dGetAllocHandler()
62 return allocfn;
66 dReallocFunction *dGetReallocHandler()
68 return reallocfn;
72 dFreeFunction *dGetFreeHandler()
74 return freefn;
78 void * dAlloc (size_t size)
80 if (allocfn) return allocfn (size); else return malloc (size);
84 void * dRealloc (void *ptr, size_t oldsize, size_t newsize)
86 if (reallocfn) return reallocfn (ptr,oldsize,newsize);
87 else return realloc (ptr,newsize);
91 void dFree (void *ptr, size_t size)
93 if (!ptr) return;
94 if (freefn) freefn (ptr,size); else free (ptr);