15bb6a25fSPoul-Henning Kamp /* internal.h 25bb6a25fSPoul-Henning Kamp 35bb6a25fSPoul-Henning Kamp Internal definitions used by Expat. This is not needed to compile 45bb6a25fSPoul-Henning Kamp client code. 55bb6a25fSPoul-Henning Kamp 6220ed979SColeman Kane The following calling convention macros are defined for frequently 7220ed979SColeman Kane called functions: 85bb6a25fSPoul-Henning Kamp 9220ed979SColeman Kane FASTCALL - Used for those internal functions that have a simple 10220ed979SColeman Kane body and a low number of arguments and local variables. 115bb6a25fSPoul-Henning Kamp 12220ed979SColeman Kane PTRCALL - Used for functions called though function pointers. 13220ed979SColeman Kane 14220ed979SColeman Kane PTRFASTCALL - Like PTRCALL, but for low number of arguments. 15220ed979SColeman Kane 16220ed979SColeman Kane inline - Used for selected internal functions for which inlining 175bb6a25fSPoul-Henning Kamp may improve performance on some platforms. 18220ed979SColeman Kane 19220ed979SColeman Kane Note: Use of these macros is based on judgement, not hard rules, 20220ed979SColeman Kane and therefore subject to change. 210a48773fSEric van Gyzen __ __ _ 220a48773fSEric van Gyzen ___\ \/ /_ __ __ _| |_ 230a48773fSEric van Gyzen / _ \\ /| '_ \ / _` | __| 240a48773fSEric van Gyzen | __// \| |_) | (_| | |_ 250a48773fSEric van Gyzen \___/_/\_\ .__/ \__,_|\__| 260a48773fSEric van Gyzen |_| XML parser 270a48773fSEric van Gyzen 28cc68614dSXin LI Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> 29cc68614dSXin LI Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net> 30cc68614dSXin LI Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> 31*fe927888SPhilip Paeps Copyright (c) 2016-2025 Sebastian Pipping <sebastian@pipping.org> 32cc68614dSXin LI Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com> 33cc68614dSXin LI Copyright (c) 2019 David Loffredo <loffredo@steptools.com> 34ffd294a1SEnji Cooper Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> 35ffd294a1SEnji Cooper Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> 360a48773fSEric van Gyzen Licensed under the MIT license: 370a48773fSEric van Gyzen 380a48773fSEric van Gyzen Permission is hereby granted, free of charge, to any person obtaining 390a48773fSEric van Gyzen a copy of this software and associated documentation files (the 400a48773fSEric van Gyzen "Software"), to deal in the Software without restriction, including 410a48773fSEric van Gyzen without limitation the rights to use, copy, modify, merge, publish, 420a48773fSEric van Gyzen distribute, sublicense, and/or sell copies of the Software, and to permit 430a48773fSEric van Gyzen persons to whom the Software is furnished to do so, subject to the 440a48773fSEric van Gyzen following conditions: 450a48773fSEric van Gyzen 460a48773fSEric van Gyzen The above copyright notice and this permission notice shall be included 470a48773fSEric van Gyzen in all copies or substantial portions of the Software. 480a48773fSEric van Gyzen 490a48773fSEric van Gyzen THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 500a48773fSEric van Gyzen EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 510a48773fSEric van Gyzen MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 520a48773fSEric van Gyzen NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 530a48773fSEric van Gyzen DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 540a48773fSEric van Gyzen OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 550a48773fSEric van Gyzen USE OR OTHER DEALINGS IN THE SOFTWARE. 565bb6a25fSPoul-Henning Kamp */ 575bb6a25fSPoul-Henning Kamp 58220ed979SColeman Kane #if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__) 59220ed979SColeman Kane /* We'll use this version by default only where we know it helps. 60220ed979SColeman Kane 61220ed979SColeman Kane regparm() generates warnings on Solaris boxes. See SF bug #692878. 62220ed979SColeman Kane 63220ed979SColeman Kane Instability reported with egcs on a RedHat Linux 7.3. 64220ed979SColeman Kane Let's comment out: 65220ed979SColeman Kane #define FASTCALL __attribute__((stdcall, regparm(3))) 66220ed979SColeman Kane and let's try this: 675bb6a25fSPoul-Henning Kamp */ 68220ed979SColeman Kane # define FASTCALL __attribute__((regparm(3))) 69220ed979SColeman Kane # define PTRFASTCALL __attribute__((regparm(3))) 705bb6a25fSPoul-Henning Kamp #endif 715bb6a25fSPoul-Henning Kamp 72220ed979SColeman Kane /* Using __fastcall seems to have an unexpected negative effect under 73220ed979SColeman Kane MS VC++, especially for function pointers, so we won't use it for 74220ed979SColeman Kane now on that platform. It may be reconsidered for a future release 75220ed979SColeman Kane if it can be made more effective. 76220ed979SColeman Kane Likely reason: __fastcall on Windows is like stdcall, therefore 77220ed979SColeman Kane the compiler cannot perform stack optimizations for call clusters. 78220ed979SColeman Kane */ 79220ed979SColeman Kane 80220ed979SColeman Kane /* Make sure all of these are defined if they aren't already. */ 81220ed979SColeman Kane 825bb6a25fSPoul-Henning Kamp #ifndef FASTCALL 835bb6a25fSPoul-Henning Kamp # define FASTCALL 845bb6a25fSPoul-Henning Kamp #endif 855bb6a25fSPoul-Henning Kamp 86220ed979SColeman Kane #ifndef PTRCALL 87220ed979SColeman Kane # define PTRCALL 88220ed979SColeman Kane #endif 89220ed979SColeman Kane 90220ed979SColeman Kane #ifndef PTRFASTCALL 91220ed979SColeman Kane # define PTRFASTCALL 92220ed979SColeman Kane #endif 93220ed979SColeman Kane 945bb6a25fSPoul-Henning Kamp #ifndef XML_MIN_SIZE 955bb6a25fSPoul-Henning Kamp # if ! defined(__cplusplus) && ! defined(inline) 965bb6a25fSPoul-Henning Kamp # ifdef __GNUC__ 975bb6a25fSPoul-Henning Kamp # define inline __inline 985bb6a25fSPoul-Henning Kamp # endif /* __GNUC__ */ 995bb6a25fSPoul-Henning Kamp # endif 1005bb6a25fSPoul-Henning Kamp #endif /* XML_MIN_SIZE */ 1015bb6a25fSPoul-Henning Kamp 1025bb6a25fSPoul-Henning Kamp #ifdef __cplusplus 1035bb6a25fSPoul-Henning Kamp # define inline inline 1045bb6a25fSPoul-Henning Kamp #else 1055bb6a25fSPoul-Henning Kamp # ifndef inline 1065bb6a25fSPoul-Henning Kamp # define inline 1075bb6a25fSPoul-Henning Kamp # endif 1085bb6a25fSPoul-Henning Kamp #endif 109be8aff81SXin LI 110cc68614dSXin LI #include <limits.h> // ULONG_MAX 111cc68614dSXin LI 11271f0c44aSXin LI #if defined(_WIN32) \ 11371f0c44aSXin LI && (! defined(__USE_MINGW_ANSI_STDIO) \ 11471f0c44aSXin LI || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0)) 115cc68614dSXin LI # define EXPAT_FMT_ULL(midpart) "%" midpart "I64u" 116cc68614dSXin LI # if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW 117cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d" 118cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u" 119cc68614dSXin LI # else 120cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" 121cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" 122cc68614dSXin LI # endif 123cc68614dSXin LI #else 124cc68614dSXin LI # define EXPAT_FMT_ULL(midpart) "%" midpart "llu" 125cc68614dSXin LI # if ! defined(ULONG_MAX) 126cc68614dSXin LI # error Compiler did not define ULONG_MAX for us 127cc68614dSXin LI # elif ULONG_MAX == 18446744073709551615u // 2^64-1 128cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld" 129cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu" 130*fe927888SPhilip Paeps # elif defined(EMSCRIPTEN) // 32bit mode Emscripten 131*fe927888SPhilip Paeps # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld" 132*fe927888SPhilip Paeps # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "zu" 133cc68614dSXin LI # else 134cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" 135cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" 136cc68614dSXin LI # endif 137cc68614dSXin LI #endif 138cc68614dSXin LI 139be8aff81SXin LI #ifndef UNUSED_P 1406b2c1e49SXin LI # define UNUSED_P(p) (void)p 141be8aff81SXin LI #endif 142be8aff81SXin LI 143cc68614dSXin LI /* NOTE BEGIN If you ever patch these defaults to greater values 144cc68614dSXin LI for non-attack XML payload in your environment, 145cc68614dSXin LI please file a bug report with libexpat. Thank you! 146cc68614dSXin LI */ 147cc68614dSXin LI #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \ 148cc68614dSXin LI 100.0f 149cc68614dSXin LI #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \ 150cc68614dSXin LI 8388608 // 8 MiB, 2^23 151cc68614dSXin LI /* NOTE END */ 152cc68614dSXin LI 153cc68614dSXin LI #include "expat.h" // so we can use type XML_Parser below 154cc68614dSXin LI 155be8aff81SXin LI #ifdef __cplusplus 156be8aff81SXin LI extern "C" { 157be8aff81SXin LI #endif 158be8aff81SXin LI 159cc68614dSXin LI void _INTERNAL_trim_to_complete_utf8_characters(const char *from, 1606b2c1e49SXin LI const char **fromLimRef); 161be8aff81SXin LI 162ffd294a1SEnji Cooper #if defined(XML_GE) && XML_GE == 1 163cc68614dSXin LI unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser); 164cc68614dSXin LI unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); 165cc68614dSXin LI const char *unsignedCharToPrintable(unsigned char c); 166cc68614dSXin LI #endif 167cc68614dSXin LI 168ffd294a1SEnji Cooper extern 169ffd294a1SEnji Cooper #if ! defined(XML_TESTING) 170ffd294a1SEnji Cooper const 171ffd294a1SEnji Cooper #endif 172ffd294a1SEnji Cooper XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c 173ffd294a1SEnji Cooper #if defined(XML_TESTING) 174ffd294a1SEnji Cooper extern unsigned int g_bytesScanned; // used for testing only 175ffd294a1SEnji Cooper #endif 1764543ef51SXin LI 177be8aff81SXin LI #ifdef __cplusplus 178be8aff81SXin LI } 179be8aff81SXin LI #endif 180