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> 314543ef51SXin LI Copyright (c) 2016-2023 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> 344543ef51SXin LI Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> 350a48773fSEric van Gyzen Licensed under the MIT license: 360a48773fSEric van Gyzen 370a48773fSEric van Gyzen Permission is hereby granted, free of charge, to any person obtaining 380a48773fSEric van Gyzen a copy of this software and associated documentation files (the 390a48773fSEric van Gyzen "Software"), to deal in the Software without restriction, including 400a48773fSEric van Gyzen without limitation the rights to use, copy, modify, merge, publish, 410a48773fSEric van Gyzen distribute, sublicense, and/or sell copies of the Software, and to permit 420a48773fSEric van Gyzen persons to whom the Software is furnished to do so, subject to the 430a48773fSEric van Gyzen following conditions: 440a48773fSEric van Gyzen 450a48773fSEric van Gyzen The above copyright notice and this permission notice shall be included 460a48773fSEric van Gyzen in all copies or substantial portions of the Software. 470a48773fSEric van Gyzen 480a48773fSEric van Gyzen THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 490a48773fSEric van Gyzen EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 500a48773fSEric van Gyzen MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 510a48773fSEric van Gyzen NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 520a48773fSEric van Gyzen DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 530a48773fSEric van Gyzen OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 540a48773fSEric van Gyzen USE OR OTHER DEALINGS IN THE SOFTWARE. 555bb6a25fSPoul-Henning Kamp */ 565bb6a25fSPoul-Henning Kamp 57220ed979SColeman Kane #if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__) 58220ed979SColeman Kane /* We'll use this version by default only where we know it helps. 59220ed979SColeman Kane 60220ed979SColeman Kane regparm() generates warnings on Solaris boxes. See SF bug #692878. 61220ed979SColeman Kane 62220ed979SColeman Kane Instability reported with egcs on a RedHat Linux 7.3. 63220ed979SColeman Kane Let's comment out: 64220ed979SColeman Kane #define FASTCALL __attribute__((stdcall, regparm(3))) 65220ed979SColeman Kane and let's try this: 665bb6a25fSPoul-Henning Kamp */ 67220ed979SColeman Kane # define FASTCALL __attribute__((regparm(3))) 68220ed979SColeman Kane # define PTRFASTCALL __attribute__((regparm(3))) 695bb6a25fSPoul-Henning Kamp #endif 705bb6a25fSPoul-Henning Kamp 71220ed979SColeman Kane /* Using __fastcall seems to have an unexpected negative effect under 72220ed979SColeman Kane MS VC++, especially for function pointers, so we won't use it for 73220ed979SColeman Kane now on that platform. It may be reconsidered for a future release 74220ed979SColeman Kane if it can be made more effective. 75220ed979SColeman Kane Likely reason: __fastcall on Windows is like stdcall, therefore 76220ed979SColeman Kane the compiler cannot perform stack optimizations for call clusters. 77220ed979SColeman Kane */ 78220ed979SColeman Kane 79220ed979SColeman Kane /* Make sure all of these are defined if they aren't already. */ 80220ed979SColeman Kane 815bb6a25fSPoul-Henning Kamp #ifndef FASTCALL 825bb6a25fSPoul-Henning Kamp # define FASTCALL 835bb6a25fSPoul-Henning Kamp #endif 845bb6a25fSPoul-Henning Kamp 85220ed979SColeman Kane #ifndef PTRCALL 86220ed979SColeman Kane # define PTRCALL 87220ed979SColeman Kane #endif 88220ed979SColeman Kane 89220ed979SColeman Kane #ifndef PTRFASTCALL 90220ed979SColeman Kane # define PTRFASTCALL 91220ed979SColeman Kane #endif 92220ed979SColeman Kane 935bb6a25fSPoul-Henning Kamp #ifndef XML_MIN_SIZE 945bb6a25fSPoul-Henning Kamp # if ! defined(__cplusplus) && ! defined(inline) 955bb6a25fSPoul-Henning Kamp # ifdef __GNUC__ 965bb6a25fSPoul-Henning Kamp # define inline __inline 975bb6a25fSPoul-Henning Kamp # endif /* __GNUC__ */ 985bb6a25fSPoul-Henning Kamp # endif 995bb6a25fSPoul-Henning Kamp #endif /* XML_MIN_SIZE */ 1005bb6a25fSPoul-Henning Kamp 1015bb6a25fSPoul-Henning Kamp #ifdef __cplusplus 1025bb6a25fSPoul-Henning Kamp # define inline inline 1035bb6a25fSPoul-Henning Kamp #else 1045bb6a25fSPoul-Henning Kamp # ifndef inline 1055bb6a25fSPoul-Henning Kamp # define inline 1065bb6a25fSPoul-Henning Kamp # endif 1075bb6a25fSPoul-Henning Kamp #endif 108be8aff81SXin LI 109cc68614dSXin LI #include <limits.h> // ULONG_MAX 110cc68614dSXin LI 11171f0c44aSXin LI #if defined(_WIN32) \ 11271f0c44aSXin LI && (! defined(__USE_MINGW_ANSI_STDIO) \ 11371f0c44aSXin LI || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0)) 114cc68614dSXin LI # define EXPAT_FMT_ULL(midpart) "%" midpart "I64u" 115cc68614dSXin LI # if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW 116cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d" 117cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u" 118cc68614dSXin LI # else 119cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" 120cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" 121cc68614dSXin LI # endif 122cc68614dSXin LI #else 123cc68614dSXin LI # define EXPAT_FMT_ULL(midpart) "%" midpart "llu" 124cc68614dSXin LI # if ! defined(ULONG_MAX) 125cc68614dSXin LI # error Compiler did not define ULONG_MAX for us 126cc68614dSXin LI # elif ULONG_MAX == 18446744073709551615u // 2^64-1 127cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld" 128cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu" 129cc68614dSXin LI # else 130cc68614dSXin LI # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" 131cc68614dSXin LI # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" 132cc68614dSXin LI # endif 133cc68614dSXin LI #endif 134cc68614dSXin LI 135be8aff81SXin LI #ifndef UNUSED_P 1366b2c1e49SXin LI # define UNUSED_P(p) (void)p 137be8aff81SXin LI #endif 138be8aff81SXin LI 139cc68614dSXin LI /* NOTE BEGIN If you ever patch these defaults to greater values 140cc68614dSXin LI for non-attack XML payload in your environment, 141cc68614dSXin LI please file a bug report with libexpat. Thank you! 142cc68614dSXin LI */ 143cc68614dSXin LI #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \ 144cc68614dSXin LI 100.0f 145cc68614dSXin LI #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \ 146cc68614dSXin LI 8388608 // 8 MiB, 2^23 147cc68614dSXin LI /* NOTE END */ 148cc68614dSXin LI 149cc68614dSXin LI #include "expat.h" // so we can use type XML_Parser below 150cc68614dSXin LI 151be8aff81SXin LI #ifdef __cplusplus 152be8aff81SXin LI extern "C" { 153be8aff81SXin LI #endif 154be8aff81SXin LI 155cc68614dSXin LI void _INTERNAL_trim_to_complete_utf8_characters(const char *from, 1566b2c1e49SXin LI const char **fromLimRef); 157be8aff81SXin LI 1584543ef51SXin LI #if XML_GE == 1 159cc68614dSXin LI unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser); 160cc68614dSXin LI unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); 161cc68614dSXin LI const char *unsignedCharToPrintable(unsigned char c); 162cc68614dSXin LI #endif 163cc68614dSXin LI 1644543ef51SXin LI extern XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c 1654543ef51SXin LI extern unsigned int g_parseAttempts; // used for testing only 1664543ef51SXin LI 167be8aff81SXin LI #ifdef __cplusplus 168be8aff81SXin LI } 169be8aff81SXin LI #endif 170