internal.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* internal.h
  2. Internal definitions used by Expat. This is not needed to compile
  3. client code.
  4. The following calling convention macros are defined for frequently
  5. called functions:
  6. FASTCALL - Used for those internal functions that have a simple
  7. body and a low number of arguments and local variables.
  8. PTRCALL - Used for functions called though function pointers.
  9. PTRFASTCALL - Like PTRCALL, but for low number of arguments.
  10. inline - Used for selected internal functions for which inlining
  11. may improve performance on some platforms.
  12. Note: Use of these macros is based on judgement, not hard rules,
  13. and therefore subject to change.
  14. __ __ _
  15. ___\ \/ /_ __ __ _| |_
  16. / _ \\ /| '_ \ / _` | __|
  17. | __// \| |_) | (_| | |_
  18. \___/_/\_\ .__/ \__,_|\__|
  19. |_| XML parser
  20. Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  21. Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
  22. Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
  23. Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
  24. Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com>
  25. Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
  26. Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
  27. Licensed under the MIT license:
  28. Permission is hereby granted, free of charge, to any person obtaining
  29. a copy of this software and associated documentation files (the
  30. "Software"), to deal in the Software without restriction, including
  31. without limitation the rights to use, copy, modify, merge, publish,
  32. distribute, sublicense, and/or sell copies of the Software, and to permit
  33. persons to whom the Software is furnished to do so, subject to the
  34. following conditions:
  35. The above copyright notice and this permission notice shall be included
  36. in all copies or substantial portions of the Software.
  37. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  38. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  39. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  40. NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  41. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  42. OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  43. USE OR OTHER DEALINGS IN THE SOFTWARE.
  44. */
  45. #if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__)
  46. /* We'll use this version by default only where we know it helps.
  47. regparm() generates warnings on Solaris boxes. See SF bug #692878.
  48. Instability reported with egcs on a RedHat Linux 7.3.
  49. Let's comment out:
  50. #define FASTCALL __attribute__((stdcall, regparm(3)))
  51. and let's try this:
  52. */
  53. # define FASTCALL __attribute__((regparm(3)))
  54. # define PTRFASTCALL __attribute__((regparm(3)))
  55. #endif
  56. /* Using __fastcall seems to have an unexpected negative effect under
  57. MS VC++, especially for function pointers, so we won't use it for
  58. now on that platform. It may be reconsidered for a future release
  59. if it can be made more effective.
  60. Likely reason: __fastcall on Windows is like stdcall, therefore
  61. the compiler cannot perform stack optimizations for call clusters.
  62. */
  63. /* Make sure all of these are defined if they aren't already. */
  64. #ifndef FASTCALL
  65. # define FASTCALL
  66. #endif
  67. #ifndef PTRCALL
  68. # define PTRCALL
  69. #endif
  70. #ifndef PTRFASTCALL
  71. # define PTRFASTCALL
  72. #endif
  73. #ifndef XML_MIN_SIZE
  74. # if ! defined(__cplusplus) && ! defined(inline)
  75. # ifdef __GNUC__
  76. # define inline __inline
  77. # endif /* __GNUC__ */
  78. # endif
  79. #endif /* XML_MIN_SIZE */
  80. #ifdef __cplusplus
  81. # define inline inline
  82. #else
  83. # ifndef inline
  84. # define inline
  85. # endif
  86. #endif
  87. #include <limits.h> // ULONG_MAX
  88. #if defined(_WIN32) \
  89. && (! defined(__USE_MINGW_ANSI_STDIO) \
  90. || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0))
  91. # define EXPAT_FMT_ULL(midpart) "%" midpart "I64u"
  92. # if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW
  93. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d"
  94. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u"
  95. # else
  96. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
  97. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
  98. # endif
  99. #else
  100. # define EXPAT_FMT_ULL(midpart) "%" midpart "llu"
  101. # if ! defined(ULONG_MAX)
  102. # error Compiler did not define ULONG_MAX for us
  103. # elif ULONG_MAX == 18446744073709551615u // 2^64-1
  104. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld"
  105. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu"
  106. # else
  107. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
  108. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
  109. # endif
  110. #endif
  111. #ifndef UNUSED_P
  112. # define UNUSED_P(p) (void)p
  113. #endif
  114. /* NOTE BEGIN If you ever patch these defaults to greater values
  115. for non-attack XML payload in your environment,
  116. please file a bug report with libexpat. Thank you!
  117. */
  118. #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \
  119. 100.0f
  120. #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \
  121. 8388608 // 8 MiB, 2^23
  122. /* NOTE END */
  123. #include "expat.h" // so we can use type XML_Parser below
  124. #ifdef __cplusplus
  125. extern "C" {
  126. #endif
  127. void _INTERNAL_trim_to_complete_utf8_characters(const char *from,
  128. const char **fromLimRef);
  129. #if XML_GE == 1
  130. unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser);
  131. unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
  132. const char *unsignedCharToPrintable(unsigned char c);
  133. #endif
  134. extern XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
  135. extern unsigned int g_parseAttempts; // used for testing only
  136. #ifdef __cplusplus
  137. }
  138. #endif