internal.h 5.8 KB

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