Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.0 KiB

  1. /***
  2. *ehveccvb.cpp - EH c-tor iterator helper function for class w/ virtual bases
  3. *
  4. * Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * EH-aware version of constructor iterator helper function for class
  8. * with virtual bases
  9. *
  10. * These functions are called when constructing and destructing arrays of
  11. * objects. Their purpose is to assure that constructed elements get
  12. * destructed if the constructor for one of the elements throws.
  13. *
  14. * These functions are called when constructing and destructing arrays of
  15. * objects. Their purpose is to assure that constructed elements get
  16. * destructed if the constructor for one of the elements throws.
  17. *
  18. * Must be compiled using "-d1Binl" to be able to specify __thiscall
  19. * at the user level
  20. *
  21. *Revision History:
  22. * 10-11-93 JDR Module created
  23. * 05-09-94 BES Module adapted for CRT source conventions
  24. * 05-13-94 SKS Remove _CRTIMP modifier
  25. * 10-10-94 CFW Fix EH/SEH exception handling.
  26. * 10-17-94 BWT Disable code for PPC.
  27. * 11-09-94 CFW Back out 10-10-94 change.
  28. * 02-08-95 JWM Mac merge.
  29. * 04-14-95 JWM Re-fix EH/SEH exception handling.
  30. * 04-17-95 JWM Restore non-WIN32 behavior.
  31. * 06-22-95 JWM Remove bogus throw from __ehvec_ctor_vb()..
  32. * 05-17-99 PML Remove all Macintosh support.
  33. * 05-20-99 PML Turn off __thiscall for IA64.
  34. * 07-12-99 RDL Image relative fixes under CC_P7_SOFT25.
  35. * 03-15-00 PML Remove CC_P7_SOFT25, which is now on permanently.
  36. *
  37. ****/
  38. #include <cruntime.h>
  39. #include <eh.h>
  40. #if defined (_M_IX86)
  41. #define CALLTYPE __thiscall
  42. #else
  43. #define CALLTYPE __stdcall
  44. #endif
  45. #ifdef _WIN32
  46. void __stdcall __ArrayUnwind(
  47. void* ptr, // Pointer to array to destruct
  48. size_t size, // Size of each element (including padding)
  49. int count, // Number of elements in the array
  50. void(CALLTYPE *pDtor)(void*) // The destructor to call
  51. );
  52. void __stdcall __ehvec_ctor_vb(
  53. void* ptr, // Pointer to array to destruct
  54. size_t size, // Size of each element (including padding)
  55. int count, // Number of elements in the array
  56. void(CALLTYPE *pCtor)(void*), // Constructor to call
  57. void(CALLTYPE *pDtor)(void*) // Destructor to call should exception be thrown
  58. ){
  59. int i; // Count of elements constructed
  60. int success = 0;
  61. __try
  62. {
  63. // Construct the elements of the array
  64. for( i = 0; i < count; i++ )
  65. {
  66. #pragma warning(disable:4191)
  67. (*(void(CALLTYPE*)(void*,int))pCtor)( ptr, 1 );
  68. #pragma warning(default:4191)
  69. ptr = (char*)ptr + size;
  70. }
  71. success = 1;
  72. }
  73. __finally
  74. {
  75. if (!success)
  76. __ArrayUnwind(ptr, size, i, pDtor);
  77. }
  78. }
  79. #else
  80. void __stdcall __ehvec_ctor_vb(
  81. void* ptr, // Pointer to array to destruct
  82. unsigned size, // Size of each element (including padding)
  83. int count, // Number of elements in the array
  84. void(CALLTYPE *pCtor)(void*), // Constructor to call
  85. void(CALLTYPE *pDtor)(void*) // Destructor to call should exception be thrown
  86. ){
  87. int i; // Count of elements constructed
  88. try
  89. {
  90. // Construct the elements of the array
  91. for( i = 0; i < count; i++ )
  92. {
  93. (*(void(CALLTYPE*)(void*,int))pCtor)( ptr, 1 );
  94. ptr = (char*)ptr + size;
  95. }
  96. }
  97. catch(...)
  98. {
  99. // If a constructor throws, unwind the portion of the array thus
  100. // far constructed.
  101. for( i--; i >= 0; i-- )
  102. {
  103. ptr = (char*)ptr - size;
  104. try {
  105. (*pDtor)(ptr);
  106. }
  107. catch(...) {
  108. // If the destructor threw during the unwind, quit
  109. terminate();
  110. }
  111. }
  112. // Propagate the exception to surrounding frames
  113. throw;
  114. }
  115. }
  116. #endif