1 | /*
|
---|
2 | * tclCkalloc.c --
|
---|
3 | *
|
---|
4 | * Interface to malloc and free that provides support for debugging problems
|
---|
5 | * involving overwritten, double freeing memory and loss of memory.
|
---|
6 | *
|
---|
7 | * Copyright (c) 1991-1994 The Regents of the University of California.
|
---|
8 | * Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * See the file "license.terms" for information on usage and redistribution
|
---|
11 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
---|
12 | *
|
---|
13 | * This code contributed by Karl Lehenbauer and Mark Diekhans
|
---|
14 | *
|
---|
15 | * RCS: @(#) $Id: tclCkalloc.c,v 1.1 2008-06-04 13:58:04 demin Exp $
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "tclInt.h"
|
---|
19 | #include "tclPort.h"
|
---|
20 |
|
---|
21 | #define FALSE 0
|
---|
22 | #define TRUE 1
|
---|
23 |
|
---|
24 | /*
|
---|
25 | *----------------------------------------------------------------------
|
---|
26 | *
|
---|
27 | * Tcl_Alloc --
|
---|
28 | * Interface to TclpAlloc.
|
---|
29 | * It does check that memory was actually allocated.
|
---|
30 | *
|
---|
31 | *----------------------------------------------------------------------
|
---|
32 | */
|
---|
33 |
|
---|
34 | char *
|
---|
35 | Tcl_Alloc (size)
|
---|
36 | unsigned int size;
|
---|
37 | {
|
---|
38 | char *result;
|
---|
39 |
|
---|
40 | result = TclpAlloc(size);
|
---|
41 | if (result == NULL)
|
---|
42 | panic("unable to alloc %d bytes", size);
|
---|
43 | return result;
|
---|
44 | }
|
---|
45 |
|
---|
46 | char *
|
---|
47 | Tcl_DbCkalloc(size, file, line)
|
---|
48 | unsigned int size;
|
---|
49 | char *file;
|
---|
50 | int line;
|
---|
51 | {
|
---|
52 | char *result;
|
---|
53 |
|
---|
54 | result = (char *) TclpAlloc(size);
|
---|
55 |
|
---|
56 | if (result == NULL) {
|
---|
57 | fflush(stdout);
|
---|
58 | panic("unable to alloc %d bytes, %s line %d", size, file,
|
---|
59 | line);
|
---|
60 | }
|
---|
61 | return result;
|
---|
62 | }
|
---|
63 |
|
---|
64 | |
---|
65 |
|
---|
66 | /*
|
---|
67 | *----------------------------------------------------------------------
|
---|
68 | *
|
---|
69 | * Tcl_Realloc --
|
---|
70 | * Interface to TclpRealloc.
|
---|
71 | * It does check that memory was actually allocated.
|
---|
72 | *
|
---|
73 | *----------------------------------------------------------------------
|
---|
74 | */
|
---|
75 |
|
---|
76 | char *
|
---|
77 | Tcl_Realloc(ptr, size)
|
---|
78 | char *ptr;
|
---|
79 | unsigned int size;
|
---|
80 | {
|
---|
81 | char *result;
|
---|
82 |
|
---|
83 | result = TclpRealloc(ptr, size);
|
---|
84 | if (result == NULL)
|
---|
85 | panic("unable to realloc %d bytes", size);
|
---|
86 | return result;
|
---|
87 | }
|
---|
88 |
|
---|
89 | char *
|
---|
90 | Tcl_DbCkrealloc(ptr, size, file, line)
|
---|
91 | char *ptr;
|
---|
92 | unsigned int size;
|
---|
93 | char *file;
|
---|
94 | int line;
|
---|
95 | {
|
---|
96 | char *result;
|
---|
97 |
|
---|
98 | result = (char *) TclpRealloc(ptr, size);
|
---|
99 |
|
---|
100 | if (result == NULL) {
|
---|
101 | fflush(stdout);
|
---|
102 | panic("unable to realloc %d bytes, %s line %d", size, file,
|
---|
103 | line);
|
---|
104 | }
|
---|
105 | return result;
|
---|
106 | }
|
---|
107 | |
---|
108 |
|
---|
109 | /*
|
---|
110 | *----------------------------------------------------------------------
|
---|
111 | *
|
---|
112 | * Tcl_Free --
|
---|
113 | * Interface to TclpFree.
|
---|
114 | *
|
---|
115 | *----------------------------------------------------------------------
|
---|
116 | */
|
---|
117 |
|
---|
118 | void
|
---|
119 | Tcl_Free (ptr)
|
---|
120 | char *ptr;
|
---|
121 | {
|
---|
122 | TclpFree(ptr);
|
---|
123 | }
|
---|