Destructable.C 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 libraries 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. void *Destructable::g_stack_start;
  27. unsigned short Destructable::g_size;
  28. #ifdef C_API
  29. NEW_AND_DELETE_BODIES_SIMPLE(Destructable)
  30. #endif
  31. #ifdef DEBUG
  32. #ifdef NOPE
  33. struct Init
  34. {
  35. Init() {}
  36. };
  37. static Init I;
  38. #endif
  39. #endif
  40. // /////////////////////////////////////////////////////////////////
  41. // in_stack - return true if ptr is in stack memory
  42. // /////////////////////////////////////////////////////////////////
  43. int
  44. Destructable::in_stack()
  45. {
  46. char stack_end;
  47. PRINTF (("In_stack : %p -- %p | %p ",
  48. g_stack_start, &stack_end, this));
  49. if (((void *) this > &stack_end && (void *) this < g_stack_start) ||
  50. ((void *) this < &stack_end && (void *) this > g_stack_start))
  51. {
  52. PRINTF (("(stack)\n"));
  53. return (1);
  54. }
  55. else
  56. {
  57. PRINTF (("(heap)\n"));
  58. return (0);
  59. }
  60. }
  61. // /////////////////////////////////////////////////////////////////
  62. // in_stack_set_size - return 1 if in the stack, set size as well
  63. // /////////////////////////////////////////////////////////////////
  64. int
  65. Destructable::in_stack_set_size()
  66. {
  67. char stack_end;
  68. PRINTF (("In_stack_size : %p -- %p | %p ",
  69. g_stack_start, &stack_end, this));
  70. // Handle stack grows down case.
  71. if ((void *) this > (void *) &stack_end &&
  72. (void *) this < (void *) g_stack_start)
  73. {
  74. PRINTF (("(stack)\n"));
  75. // Size unknown, also used to indicate stack grows down.
  76. Destructable::g_size = 0;
  77. return (1);
  78. }
  79. // Handle stack grows up case.
  80. else if ((void *) this > (void *) g_stack_start &&
  81. (void *) this < (void *) &stack_end)
  82. {
  83. // stack_end is just past this, so size is space between them.
  84. Destructable::g_size = (unsigned long) &stack_end - (unsigned long) this;
  85. #ifdef foobar
  86. g_size -=
  87. #endif
  88. PRINTF (("(stack)\n"));
  89. PRINTF ((" obj start = %p, end = %p, size = %d\n",
  90. this, &stack_end, g_size));
  91. return (1);
  92. }
  93. else
  94. {
  95. PRINTF (("(heap)\n"));
  96. return (0);
  97. }
  98. }
  99. #endif /* NATIVE_EXCEPTIONS */