clipper-exceptions.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. diff --git a/thirdparty/misc/clipper.cpp b/thirdparty/misc/clipper.cpp
  2. index 8c3a59c4ca..c67045d113 100644
  3. --- a/thirdparty/misc/clipper.cpp
  4. +++ b/thirdparty/misc/clipper.cpp
  5. @@ -48,6 +48,38 @@
  6. #include <ostream>
  7. #include <functional>
  8. +//Explicitly disables exceptions handling for target platform
  9. +//#define CLIPPER_NOEXCEPTION
  10. +
  11. +#define CLIPPER_THROW(exception) std::abort()
  12. +#define CLIPPER_TRY if(true)
  13. +#define CLIPPER_CATCH(exception) if(false)
  14. +
  15. +#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
  16. + #ifndef CLIPPER_NOEXCEPTION
  17. + #undef CLIPPER_THROW
  18. + #define CLIPPER_THROW(exception) throw exception
  19. + #undef CLIPPER_TRY
  20. + #define CLIPPER_TRY try
  21. + #undef CLIPPER_CATCH
  22. + #define CLIPPER_CATCH(exception) catch(exception)
  23. + #endif
  24. +#endif
  25. +
  26. +//Optionally allows to override exception macros
  27. +#if defined(CLIPPER_THROW_USER)
  28. + #undef CLIPPER_THROW
  29. + #define CLIPPER_THROW CLIPPER_THROW_USER
  30. +#endif
  31. +#if defined(CLIPPER_TRY_USER)
  32. + #undef CLIPPER_TRY
  33. + #define CLIPPER_TRY CLIPPER_TRY_USER
  34. +#endif
  35. +#if defined(CLIPPER_CATCH_USER)
  36. + #undef CLIPPER_CATCH
  37. + #define CLIPPER_CATCH CLIPPER_CATCH_USER
  38. +#endif
  39. +
  40. namespace ClipperLib {
  41. static double const pi = 3.141592653589793238;
  42. @@ -898,7 +930,7 @@ void RangeTest(const IntPoint& Pt, bool& useFullRange)
  43. if (useFullRange)
  44. {
  45. if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange)
  46. - throw clipperException("Coordinate outside allowed range");
  47. + CLIPPER_THROW(clipperException("Coordinate outside allowed range"));
  48. }
  49. else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange)
  50. {
  51. @@ -1046,10 +1078,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed)
  52. {
  53. #ifdef use_lines
  54. if (!Closed && PolyTyp == ptClip)
  55. - throw clipperException("AddPath: Open paths must be subject.");
  56. + CLIPPER_THROW(clipperException("AddPath: Open paths must be subject."));
  57. #else
  58. if (!Closed)
  59. - throw clipperException("AddPath: Open paths have been disabled.");
  60. + CLIPPER_THROW(clipperException("AddPath: Open paths have been disabled."));
  61. #endif
  62. int highI = (int)pg.size() -1;
  63. @@ -1062,7 +1094,7 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed)
  64. bool IsFlat = true;
  65. //1. Basic (first) edge initialization ...
  66. - try
  67. + CLIPPER_TRY
  68. {
  69. edges[1].Curr = pg[1];
  70. RangeTest(pg[0], m_UseFullRange);
  71. @@ -1075,10 +1107,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed)
  72. InitEdge(&edges[i], &edges[i+1], &edges[i-1], pg[i]);
  73. }
  74. }
  75. - catch(...)
  76. + CLIPPER_CATCH(...)
  77. {
  78. delete [] edges;
  79. - throw; //range test fails
  80. + CLIPPER_THROW(); //range test fails
  81. }
  82. TEdge *eStart = &edges[0];
  83. @@ -1442,7 +1474,7 @@ void ClipperBase::SwapPositionsInAEL(TEdge *Edge1, TEdge *Edge2)
  84. void ClipperBase::UpdateEdgeIntoAEL(TEdge *&e)
  85. {
  86. if (!e->NextInLML)
  87. - throw clipperException("UpdateEdgeIntoAEL: invalid call");
  88. + CLIPPER_THROW(clipperException("UpdateEdgeIntoAEL: invalid call"));
  89. e->NextInLML->OutIdx = e->OutIdx;
  90. TEdge* AelPrev = e->PrevInAEL;
  91. @@ -1510,7 +1542,7 @@ bool Clipper::Execute(ClipType clipType, Paths &solution,
  92. {
  93. if( m_ExecuteLocked ) return false;
  94. if (m_HasOpenPaths)
  95. - throw clipperException("Error: PolyTree struct is needed for open path clipping.");
  96. + CLIPPER_THROW(clipperException("Error: PolyTree struct is needed for open path clipping."));
  97. m_ExecuteLocked = true;
  98. solution.resize(0);
  99. m_SubjFillType = subjFillType;
  100. @@ -1560,7 +1592,7 @@ void Clipper::FixHoleLinkage(OutRec &outrec)
  101. bool Clipper::ExecuteInternal()
  102. {
  103. bool succeeded = true;
  104. - try {
  105. + CLIPPER_TRY {
  106. Reset();
  107. m_Maxima = MaximaList();
  108. m_SortedEdges = 0;
  109. @@ -1583,7 +1615,7 @@ bool Clipper::ExecuteInternal()
  110. InsertLocalMinimaIntoAEL(botY);
  111. }
  112. }
  113. - catch(...)
  114. + CLIPPER_CATCH(...)
  115. {
  116. succeeded = false;
  117. }
  118. @@ -2827,18 +2859,18 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge)
  119. bool Clipper::ProcessIntersections(const cInt topY)
  120. {
  121. if( !m_ActiveEdges ) return true;
  122. - try {
  123. + CLIPPER_TRY {
  124. BuildIntersectList(topY);
  125. size_t IlSize = m_IntersectList.size();
  126. if (IlSize == 0) return true;
  127. if (IlSize == 1 || FixupIntersectionOrder()) ProcessIntersectList();
  128. else return false;
  129. }
  130. - catch(...)
  131. + CLIPPER_CATCH(...)
  132. {
  133. m_SortedEdges = 0;
  134. DisposeIntersectNodes();
  135. - throw clipperException("ProcessIntersections error");
  136. + CLIPPER_THROW(clipperException("ProcessIntersections error"));
  137. }
  138. m_SortedEdges = 0;
  139. return true;
  140. @@ -3002,7 +3034,7 @@ void Clipper::DoMaxima(TEdge *e)
  141. DeleteFromAEL(eMaxPair);
  142. }
  143. #endif
  144. - else throw clipperException("DoMaxima error");
  145. + else CLIPPER_THROW(clipperException("DoMaxima error"));
  146. }
  147. //------------------------------------------------------------------------------