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 | *************************************************************************/ |
---|
22 | |
---|
23 | #include <ode/config.h> |
---|
24 | #include <ode/memory.h> |
---|
25 | #include <ode/error.h> |
---|
26 | |
---|
27 | |
---|
28 | static dAllocFunction *allocfn = 0; |
---|
29 | static dReallocFunction *reallocfn = 0; |
---|
30 | static dFreeFunction *freefn = 0; |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | void dSetAllocHandler (dAllocFunction *fn) |
---|
35 | { |
---|
36 | allocfn = fn; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | void dSetReallocHandler (dReallocFunction *fn) |
---|
41 | { |
---|
42 | reallocfn = fn; |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | void dSetFreeHandler (dFreeFunction *fn) |
---|
47 | { |
---|
48 | freefn = fn; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | dAllocFunction *dGetAllocHandler() |
---|
53 | { |
---|
54 | return allocfn; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | dReallocFunction *dGetReallocHandler() |
---|
59 | { |
---|
60 | return reallocfn; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | dFreeFunction *dGetFreeHandler() |
---|
65 | { |
---|
66 | return freefn; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | void * dAlloc (size_t size) |
---|
71 | { |
---|
72 | if (allocfn) return allocfn (size); else return malloc (size); |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | void * dRealloc (void *ptr, size_t oldsize, size_t newsize) |
---|
77 | { |
---|
78 | if (reallocfn) return reallocfn (ptr,oldsize,newsize); |
---|
79 | else return realloc (ptr,newsize); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | void dFree (void *ptr, size_t size) |
---|
84 | { |
---|
85 | if (!ptr) return; |
---|
86 | if (freefn) freefn (ptr,size); else free (ptr); |
---|
87 | } |
---|