1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
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 *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
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. *
21 *************************************************************************/
23 #include <ode/odeconfig.h>
24 #include <ode/memory.h>
25 #include <ode/error.h>
29 static dAllocFunction
*allocfn
= 0;
30 static dReallocFunction
*reallocfn
= 0;
31 static dFreeFunction
*freefn
= 0;
35 this is a guard against AC_FUNC_MALLOC and AC_FUNC_REALLOC
36 which break cross compilation, no issues in native MSYS.
42 void dSetAllocHandler (dAllocFunction
*fn
)
48 void dSetReallocHandler (dReallocFunction
*fn
)
54 void dSetFreeHandler (dFreeFunction
*fn
)
60 dAllocFunction
*dGetAllocHandler()
66 dReallocFunction
*dGetReallocHandler()
72 dFreeFunction
*dGetFreeHandler()
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
)
94 if (freefn
) freefn (ptr
,size
); else free (ptr
);