|
6 | 6 | The following calling convention macros are defined for frequently |
7 | 7 | called functions: |
8 | 8 |
|
9 | | - FASTCALL - Used for those internal functions that have a simple |
10 | | - body and a low number of arguments and local variables. |
11 | | -
|
12 | | - PTRCALL - Used for functions called though function pointers. |
13 | | -
|
14 | | - PTRFASTCALL - Like PTRCALL, but for low number of arguments. |
15 | | -
|
16 | 9 | inline - Used for selected internal functions for which inlining |
17 | 10 | may improve performance on some platforms. |
18 | 11 |
|
|
34 | 27 | Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> |
35 | 28 | Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> |
36 | 29 | Copyright (c) 2026 Matthew Wozniczka <mattheww@simba.com> |
| 30 | + Copyright (c) 2026 Braian Plaku <braianplaku@gmail.com> |
| 31 | + Copyright (c) 2026 Florian Schmaus <florian.schmaus@codasip.com> |
37 | 32 | Licensed under the MIT license: |
38 | 33 |
|
39 | 34 | Permission is hereby granted, free of charge, to any person obtaining |
|
58 | 53 | SPDX-License-Identifier: MIT |
59 | 54 | */ |
60 | 55 |
|
61 | | -#if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__) |
62 | | -/* We'll use this version by default only where we know it helps. |
63 | | -
|
64 | | - regparm() generates warnings on Solaris boxes. See SF bug #692878. |
65 | | -
|
66 | | - Instability reported with egcs on a RedHat Linux 7.3. |
67 | | - Let's comment out: |
68 | | - #define FASTCALL __attribute__((stdcall, regparm(3))) |
69 | | - and let's try this: |
70 | | -*/ |
71 | | -# define FASTCALL __attribute__((regparm(3))) |
72 | | -# define PTRFASTCALL __attribute__((regparm(3))) |
73 | | -#endif |
74 | | - |
75 | | -/* Using __fastcall seems to have an unexpected negative effect under |
76 | | - MS VC++, especially for function pointers, so we won't use it for |
77 | | - now on that platform. It may be reconsidered for a future release |
78 | | - if it can be made more effective. |
79 | | - Likely reason: __fastcall on Windows is like stdcall, therefore |
80 | | - the compiler cannot perform stack optimizations for call clusters. |
81 | | -*/ |
82 | | - |
83 | | -/* Make sure all of these are defined if they aren't already. */ |
84 | | - |
85 | | -#ifndef FASTCALL |
86 | | -# define FASTCALL |
87 | | -#endif |
| 56 | +#if ! defined(INTERNAL_H) |
| 57 | +# define INTERNAL_H 1 |
88 | 58 |
|
89 | | -#ifndef PTRCALL |
90 | | -# define PTRCALL |
91 | | -#endif |
92 | | - |
93 | | -#ifndef PTRFASTCALL |
94 | | -# define PTRFASTCALL |
95 | | -#endif |
96 | | - |
97 | | -#ifndef XML_MIN_SIZE |
98 | | -# if ! defined(__cplusplus) && ! defined(inline) |
99 | | -# ifdef __GNUC__ |
100 | | -# define inline __inline |
101 | | -# endif /* __GNUC__ */ |
102 | | -# endif |
103 | | -#endif /* XML_MIN_SIZE */ |
| 59 | +# ifndef XML_MIN_SIZE |
| 60 | +# if ! defined(inline) |
| 61 | +# ifdef __GNUC__ |
| 62 | +# define inline __inline |
| 63 | +# endif /* __GNUC__ */ |
| 64 | +# endif |
| 65 | +# endif /* XML_MIN_SIZE */ |
104 | 66 |
|
105 | | -#ifdef __cplusplus |
106 | | -# define inline inline |
107 | | -#else |
108 | 67 | # ifndef inline |
109 | 68 | # define inline |
110 | 69 | # endif |
111 | | -#endif |
112 | | - |
113 | | -#include <limits.h> // ULONG_MAX |
114 | | -#include <stddef.h> // size_t |
115 | | - |
116 | | -#if defined(_WIN32) \ |
117 | | - && (! defined(__USE_MINGW_ANSI_STDIO) \ |
118 | | - || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0)) |
119 | | -# define EXPAT_FMT_LLX(midpart) "%" midpart "I64x" |
120 | | -# define EXPAT_FMT_ULL(midpart) "%" midpart "I64u" |
121 | | -# if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW |
122 | | -# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d" |
123 | | -# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u" |
| 70 | + |
| 71 | +# if ! defined(XML_NONTESTING_STATIC) |
| 72 | +# if defined(XML_TESTING) |
| 73 | +# define XML_NONTESTING_STATIC // empty i.e. not static |
| 74 | +# else |
| 75 | +# define XML_NONTESTING_STATIC static |
| 76 | +# endif |
| 77 | +# endif |
| 78 | + |
| 79 | +# include <limits.h> // ULONG_MAX |
| 80 | +# include <stddef.h> // size_t |
| 81 | + |
| 82 | +# if defined(_WIN32) \ |
| 83 | + && (! defined(__USE_MINGW_ANSI_STDIO) \ |
| 84 | + || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0)) |
| 85 | +# define EXPAT_FMT_LLX(midpart) "%" midpart "I64x" |
| 86 | +# define EXPAT_FMT_ULL(midpart) "%" midpart "I64u" |
| 87 | +# if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW |
| 88 | +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d" |
| 89 | +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u" |
| 90 | +# else |
| 91 | +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" |
| 92 | +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" |
| 93 | +# endif |
124 | 94 | # else |
125 | | -# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" |
126 | | -# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" |
| 95 | +# include <inttypes.h> // PRIdPTR, PRIuPTR |
| 96 | +# define EXPAT_FMT_LLX(midpart) "%" midpart "llx" |
| 97 | +# define EXPAT_FMT_ULL(midpart) "%" midpart "llu" |
| 98 | +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart PRIdPTR |
| 99 | +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart PRIuPTR |
| 100 | +# endif |
| 101 | + |
| 102 | +# ifndef UNUSED_P |
| 103 | +# define UNUSED_P(p) (void)p |
127 | 104 | # endif |
128 | | -#else |
129 | | -# include <inttypes.h> // PRIdPTR, PRIuPTR |
130 | | -# define EXPAT_FMT_LLX(midpart) "%" midpart "llx" |
131 | | -# define EXPAT_FMT_ULL(midpart) "%" midpart "llu" |
132 | | -# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart PRIdPTR |
133 | | -# define EXPAT_FMT_SIZE_T(midpart) "%" midpart PRIuPTR |
134 | | -#endif |
135 | | - |
136 | | -#ifndef UNUSED_P |
137 | | -# define UNUSED_P(p) (void)p |
138 | | -#endif |
139 | 105 |
|
140 | 106 | /* NOTE BEGIN If you ever patch these defaults to greater values |
141 | 107 | for non-attack XML payload in your environment, |
142 | 108 | please file a bug report with libexpat. Thank you! |
143 | 109 | */ |
144 | | -#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \ |
145 | | - 100.0f |
146 | | -#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \ |
147 | | - 8388608 // 8 MiB, 2^23 |
| 110 | +# define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \ |
| 111 | + 100.0f |
| 112 | +# define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \ |
| 113 | + 8388608 // 8 MiB, 2^23 |
148 | 114 |
|
149 | | -#define EXPAT_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT 100.0f |
150 | | -#define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \ |
151 | | - 67108864 // 64 MiB, 2^26 |
| 115 | +# define EXPAT_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT 100.0f |
| 116 | +# define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \ |
| 117 | + 67108864 // 64 MiB, 2^26 |
152 | 118 |
|
153 | 119 | // NOTE: If function expat_alloc was user facing, EXPAT_MALLOC_ALIGNMENT would |
154 | 120 | // have to take sizeof(long double) into account |
155 | | -#define EXPAT_MALLOC_ALIGNMENT sizeof(long long) // largest parser (sub)member |
156 | | -#define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t)) |
| 121 | +union expat_align { |
| 122 | + long long l; |
| 123 | + void *p; |
| 124 | +}; |
| 125 | +# define EXPAT_MALLOC_ALIGNMENT sizeof(union expat_align) |
| 126 | +# define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t)) |
157 | 127 |
|
158 | 128 | /* NOTE END */ |
159 | 129 |
|
160 | | -#include "expat.h" // so we can use type XML_Parser below |
161 | | - |
162 | | -#ifdef __cplusplus |
163 | | -extern "C" { |
164 | | -#endif |
| 130 | +# include "expat.h" // so we can use type XML_Parser below |
165 | 131 |
|
166 | 132 | void _INTERNAL_trim_to_complete_utf8_characters(const char *from, |
167 | 133 | const char **fromLimRef); |
168 | 134 |
|
169 | | -#if defined(XML_GE) && XML_GE == 1 |
| 135 | +# if defined(XML_GE) && XML_GE == 1 |
170 | 136 | unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser); |
171 | 137 | unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); |
172 | 138 | const char *unsignedCharToPrintable(unsigned char c); |
173 | | -#endif |
| 139 | +# endif |
174 | 140 |
|
175 | 141 | extern |
176 | | -#if ! defined(XML_TESTING) |
| 142 | +# if ! defined(XML_TESTING) |
177 | 143 | const |
178 | | -#endif |
| 144 | +# endif |
179 | 145 | XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c |
180 | | -#if defined(XML_TESTING) |
| 146 | +# if defined(XML_TESTING) |
| 147 | + |
| 148 | +int xmlSetHashSalt(XML_Parser parser, unsigned long hash_salt); |
| 149 | + |
181 | 150 | void *expat_malloc(XML_Parser parser, size_t size, int sourceLine); |
182 | 151 | void expat_free(XML_Parser parser, void *ptr, int sourceLine); |
183 | 152 | void *expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine); |
184 | 153 | extern unsigned int g_bytesScanned; // used for testing only |
185 | | -#endif |
| 154 | +# endif |
186 | 155 |
|
187 | | -#ifdef __cplusplus |
188 | | -} |
189 | | -#endif |
| 156 | +#endif // not defined INTERNAL_H |
0 commit comments