Leaked source code of windows server 2003
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.

119 lines
3.4 KiB

  1. /***
  2. *ehvcccvb.cpp - EH copy-ctor iterator helper function for class w/ virtual bases
  3. *
  4. * Copyright (c) 2000-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * These functions are called when constructing and destructing arrays of
  8. * objects. Their purpose is to assure that constructed elements get
  9. * destructed if the constructor for one of the elements throws.
  10. *
  11. * Must be compiled using "-d1Binl" to be able to specify __thiscall
  12. * at the user level
  13. *
  14. *Revision History:
  15. * 04-27-00 JJS File created
  16. *
  17. ****/
  18. #include <cruntime.h>
  19. #include <eh.h>
  20. #if defined (_M_IX86)
  21. #define CALLTYPE __thiscall
  22. #else
  23. #define CALLTYPE __stdcall
  24. #endif
  25. #ifdef _WIN32
  26. void __stdcall __ArrayUnwind(
  27. void* ptr, // Pointer to array to destruct
  28. size_t size, // Size of each element (including padding)
  29. int count, // Number of elements in the array
  30. void(CALLTYPE *pDtor)(void*) // The destructor to call
  31. );
  32. void __stdcall __ehvec_copy_ctor_vb(
  33. void* dst, // Pointer to destination array
  34. void* src, // Pointer to source array
  35. size_t size, // Size of each element (including padding)
  36. int count, // Number of elements in the array
  37. void(CALLTYPE *pCopyCtor)(void*,void*), // Constructor to call
  38. void(CALLTYPE *pDtor)(void*) // Destructor to call should exception be thrown
  39. ){
  40. int i; // Count of elements constructed
  41. int success = 0;
  42. __try
  43. {
  44. // Construct the elements of the array
  45. for( i = 0; i < count; i++ )
  46. {
  47. #pragma warning(disable:4191)
  48. (*(void(CALLTYPE*)(void*,void*,int))pCopyCtor)( dst, src, 1 );
  49. #pragma warning(default:4191)
  50. dst = (char*)dst + size;
  51. src = (char*)src + size;
  52. }
  53. success = 1;
  54. }
  55. __finally
  56. {
  57. if (!success)
  58. __ArrayUnwind(dst, size, i, pDtor);
  59. }
  60. }
  61. #else
  62. void __stdcall __ehvec_copy_ctor_vb(
  63. void* dst, // Pointer to destination array
  64. void* src, // Pointer to source array
  65. size_t size, // Size of each element (including padding)
  66. int count, // Number of elements in the array
  67. void(CALLTYPE *pCopyCtor)(void*, void*), // Constructor to call
  68. void(CALLTYPE *pDtor)(void*) // Destructor to call should exception be thrown
  69. ){
  70. int i; // Count of elements constructed
  71. try
  72. {
  73. // Construct the elements of the array
  74. for( i = 0; i < count; i++ )
  75. {
  76. (*pCopyCtor)( dst, src );
  77. dst = (char*)dst + size;
  78. src = (char*)src + size;
  79. }
  80. }
  81. catch(...)
  82. {
  83. // If a constructor throws, unwind the portion of the array thus
  84. // far constructed.
  85. for( i--; i >= 0; i-- )
  86. {
  87. dst = (char*)dst - size;
  88. try {
  89. #pragma warning(disable:4191)
  90. (*(void(CALLTYPE*)(void*,void*,int))pCopyCtor)( dst, src, 1 );
  91. #pragma warning(default:4191)
  92. }
  93. catch(...) {
  94. // If the destructor threw during the unwind, quit
  95. terminate();
  96. }
  97. }
  98. // Propagate the exception to surrounding frames
  99. throw;
  100. }
  101. }
  102. #endif