Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dti_excs / Destructable.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: Destructable.C /main/8 1996/10/04 12:48:45 cde-hal $
24 #ifndef NATIVE_EXCEPTIONS
25 #include "Exceptions.hh"
26
27
28 void *Destructable::g_stack_start;
29 unsigned short Destructable::g_size;
30
31 #ifdef C_API
32 NEW_AND_DELETE_BODIES_SIMPLE(Destructable)
33 #endif
34
35 #ifdef DEBUG
36 #ifdef NOPE
37 struct Init
38 {
39   Init() {}
40 };
41
42 static Init I;
43 #endif
44 #endif
45
46
47 // /////////////////////////////////////////////////////////////////
48 // in_stack - return true if ptr is in stack memory
49 // /////////////////////////////////////////////////////////////////
50
51 int
52 Destructable::in_stack()
53 {
54   char stack_end;
55   PRINTF (("In_stack : %p -- %p  |  %p  ",
56            g_stack_start, &stack_end, this));
57   
58   if (((void *) this > &stack_end && (void *) this < g_stack_start) ||
59       ((void *) this < &stack_end && (void *) this > g_stack_start))
60     {
61       PRINTF (("(stack)\n"));
62       return (1);
63     }
64   else
65     {
66       PRINTF (("(heap)\n"));
67       return (0);
68     }
69 }
70
71
72 // /////////////////////////////////////////////////////////////////
73 // in_stack_set_size - return 1 if in the stack, set size as well
74 // /////////////////////////////////////////////////////////////////
75
76 int
77 Destructable::in_stack_set_size()
78 {
79   char stack_end;
80   PRINTF (("In_stack_size : %p -- %p  |  %p  ",
81            g_stack_start, &stack_end, this));
82
83   // Handle stack grows down case.
84   if ((void *) this > (void *) &stack_end &&
85       (void *) this < (void *) g_stack_start)
86     {
87       PRINTF (("(stack)\n"));
88       // Size unknown, also used to indicate stack grows down.
89       Destructable::g_size = 0;
90       return (1);
91     }
92   // Handle stack grows up case. 
93   else if ((void *) this > (void *) g_stack_start &&
94            (void *) this < (void *) &stack_end)
95     {
96       // stack_end is just past this, so size is space between them. 
97       Destructable::g_size = (unsigned long) &stack_end - (unsigned long) this;
98 #ifdef foobar
99       g_size -=
100 #endif
101       PRINTF (("(stack)\n"));
102       PRINTF (("  obj start = %p, end = %p, size = %d\n",
103                this, &stack_end, g_size));
104
105       return (1);
106     }
107   else
108     {
109       PRINTF (("(heap)\n"));
110       return (0);
111     }
112 }
113
114 #endif /* NATIVE_EXCEPTIONS */