internal.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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-2024 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-2024 Sony Corporation / Snild Dolkow <snild@sony.com>
  27. Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp>
  28. Licensed under the MIT license:
  29. Permission is hereby granted, free of charge, to any person obtaining
  30. a copy of this software and associated documentation files (the
  31. "Software"), to deal in the Software without restriction, including
  32. without limitation the rights to use, copy, modify, merge, publish,
  33. distribute, sublicense, and/or sell copies of the Software, and to permit
  34. persons to whom the Software is furnished to do so, subject to the
  35. following conditions:
  36. The above copyright notice and this permission notice shall be included
  37. in all copies or substantial portions of the Software.
  38. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  39. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  40. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  41. NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  42. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  43. OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  44. USE OR OTHER DEALINGS IN THE SOFTWARE.
  45. */
  46. #if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__)
  47. /* We'll use this version by default only where we know it helps.
  48. regparm() generates warnings on Solaris boxes. See SF bug #692878.
  49. Instability reported with egcs on a RedHat Linux 7.3.
  50. Let's comment out:
  51. #define FASTCALL __attribute__((stdcall, regparm(3)))
  52. and let's try this:
  53. */
  54. # define FASTCALL __attribute__((regparm(3)))
  55. # define PTRFASTCALL __attribute__((regparm(3)))
  56. #endif
  57. /* Using __fastcall seems to have an unexpected negative effect under
  58. MS VC++, especially for function pointers, so we won't use it for
  59. now on that platform. It may be reconsidered for a future release
  60. if it can be made more effective.
  61. Likely reason: __fastcall on Windows is like stdcall, therefore
  62. the compiler cannot perform stack optimizations for call clusters.
  63. */
  64. /* Make sure all of these are defined if they aren't already. */
  65. #ifndef FASTCALL
  66. # define FASTCALL
  67. #endif
  68. #ifndef PTRCALL
  69. # define PTRCALL
  70. #endif
  71. #ifndef PTRFASTCALL
  72. # define PTRFASTCALL
  73. #endif
  74. #ifndef XML_MIN_SIZE
  75. # if ! defined(__cplusplus) && ! defined(inline)
  76. # ifdef __GNUC__
  77. # define inline __inline
  78. # endif /* __GNUC__ */
  79. # endif
  80. #endif /* XML_MIN_SIZE */
  81. #ifdef __cplusplus
  82. # define inline inline
  83. #else
  84. # ifndef inline
  85. # define inline
  86. # endif
  87. #endif
  88. #include <limits.h> // ULONG_MAX
  89. #if defined(_WIN32) \
  90. && (! defined(__USE_MINGW_ANSI_STDIO) \
  91. || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0))
  92. # define EXPAT_FMT_ULL(midpart) "%" midpart "I64u"
  93. # if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW
  94. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d"
  95. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u"
  96. # else
  97. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
  98. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
  99. # endif
  100. #else
  101. # define EXPAT_FMT_ULL(midpart) "%" midpart "llu"
  102. # if ! defined(ULONG_MAX)
  103. # error Compiler did not define ULONG_MAX for us
  104. # elif ULONG_MAX == 18446744073709551615u // 2^64-1
  105. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld"
  106. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu"
  107. # else
  108. # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
  109. # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
  110. # endif
  111. #endif
  112. #ifndef UNUSED_P
  113. # define UNUSED_P(p) (void)p
  114. #endif
  115. /* NOTE BEGIN If you ever patch these defaults to greater values
  116. for non-attack XML payload in your environment,
  117. please file a bug report with libexpat. Thank you!
  118. */
  119. #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \
  120. 100.0f
  121. #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \
  122. 8388608 // 8 MiB, 2^23
  123. /* NOTE END */
  124. #include "expat.h" // so we can use type XML_Parser below
  125. #ifdef __cplusplus
  126. extern "C" {
  127. #endif
  128. void _INTERNAL_trim_to_complete_utf8_characters(const char *from,
  129. const char **fromLimRef);
  130. #if defined(XML_GE) && XML_GE == 1
  131. unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser);
  132. unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
  133. const char *unsignedCharToPrintable(unsigned char c);
  134. #endif
  135. extern
  136. #if ! defined(XML_TESTING)
  137. const
  138. #endif
  139. XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
  140. #if defined(XML_TESTING)
  141. extern unsigned int g_bytesScanned; // used for testing only
  142. #endif
  143. #ifdef __cplusplus
  144. }
  145. #endif