libfossil
config.h
Go to the documentation of this file.
1#if !defined (ORG_FOSSIL_SCM_FSL_CONFIG_H_INCLUDED)
2#define ORG_FOSSIL_SCM_FSL_CONFIG_H_INCLUDED
3/*
4 Copyright 2013-2021 The Libfossil Authors, see LICENSES/BSD-2-Clause.txt
5
6 SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7 SPDX-FileCopyrightText: 2021 The Libfossil Authors
8 SPDX-FileType: Code
9
10 Heavily indebted to the Fossil SCM project (https://fossil-scm.org).
11
12*/
13
14#include "autoconfig.h" /* auto-generated and filtered out of amalgamation */
15
16#if !defined(_ISOC99_SOURCE)
17/* glibc apparently guards snprintf() on this #define, even though
18 snprintf() is part of C99 and we're building in C99 mode. */
19# define _ISOC99_SOURCE
20#endif
21#if !defined(_C99_SOURCE)
22/* Some Mac enviorments guard snprintf() on this #define but do not
23 #define it when building in C99 mode. */
24# define _C99_SOURCE
25#endif
26
27#if !defined(FSL_AUX_SCHEMA)
28# error "Expecting FSL_AUX_SCHEMA to be defined by the configuration bits."
29#endif
30#if !defined(FSL_LIBRARY_VERSION)
31# error "Expecting FSL_LIBRARY_VERSION to be defined by the configuration bits."
32#endif
33
34#undef FSL_SHA1_HARDENED
35/**
36 If true, the library uses the "hardnened" SHA1 algorithm rather
37 than the original. See:
38
39 https://crypto.stackexchange.com/questions/44141/what-is-hardened-sha-1-how-does-it-work-and-how-much-protection-does-it-offer
40
41 https://shattered.io/
42*/
43#define FSL_SHA1_HARDENED 1
44
45/**
46 FSL_API_ARMOR is a not-yet-widely-implemented feature adopted from
47 SQLite, in which many APIs will perform more argument validation
48 against NULL pointers or values which might, if unchecked, lead to
49 illegal memory access. Without this flag, such APIs have undefined
50 behavior with such illegal arguments but use fewer CPU cycles.
51*/
52#if !defined(FSL_API_ARMOR)
53# define FSL_API_ARMOR 1
54#endif
55
56
57#ifdef _WIN32
58# if defined(BUILD_libfossil_static) || defined(FSL_AMALGAMATION_BUILD)
59# define FSL_EXPORT extern
60# elif defined(BUILD_libfossil)
61# define FSL_EXPORT extern __declspec(dllexport)
62# else
63# define FSL_EXPORT extern __declspec(dllimport)
64# endif
65#else
66# define FSL_EXPORT extern
67#endif
68
69#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
70# if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
71/* inttypes.h needs this for the PRI* and SCN* macros in C++ mode. */
72# define __STDC_FORMAT_MACROS
73# else
74# error "This tree requires a standards-compliant C99-capable compiler."
75# endif
76#endif
77
78#if defined(_MSC_VER)
79# define FSL_PLATFORM_IS_WINDOWS 1
80# define FSL_PLATFORM_IS_UNIX 0
81# define FSL_PLATFORM_PLATFORM "windows"
82/* define a __func__ compatibility macro */
83# if _MSC_VER < 1500 /* (vc9.0; dev studio 2008) */
84/* sorry; cant do much better than nothing at all on those earlier ones */
85# define __func__ "(func)"
86# else
87# define __func__ __FUNCTION__
88# endif
89/* for the time being at least, don't complain about there being secure crt alternatives: */
90# ifndef _CRT_SECURE_NO_WARNINGS
91# define _CRT_SECURE_NO_WARNINGS
92# endif
93/* for the time being at least, don't complain about using POSIX names instead of ISO C++: */
94# pragma warning ( disable : 4996 )
95/* for the time being at least, suppresss some int conversion warnings */
96# pragma warning ( disable : 4244 ) /*'fsl_size_t' to 'int'; this masks other problems that should be fixed*/
97# pragma warning ( disable : 4761 ) /*'integral size mismatch in argument'; more size_t problems*/
98# pragma warning ( disable : 4267 ) /*'size_t' to 'int'; crops up especially in 64-bit builds*/
99/* these were extracted from fossil's unistd.h */
100# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
101# include <io.h>
102#elif defined(__MINGW32__)
103# define FSL_PLATFORM_IS_WINDOWS 1
104# define FSL_PLATFORM_IS_UNIX 0
105# define FSL_PLATFORM_PLATFORM "windows"
106#elif defined(__CYGWIN__)
107# define FSL_PLATFORM_IS_WINDOWS 0
108# define FSL_PLATFORM_IS_UNIX 1
109# define FSL_PLATFORM_PLATFORM "unix"
110#else
111# define FSL_PLATFORM_IS_WINDOWS 0
112# define FSL_PLATFORM_IS_UNIX 1
113# define FSL_PLATFORM_PLATFORM "unix"
114#endif
115
116#if !defined(HAVE_SIGACTION)
117# if defined(FSL_PLATFORM_IS_UNIX)
118# define HAVE_SIGACTION 1
119# else
120# define HAVE_SIGACTION 0
121# endif
122#endif
123
124#include <stdint.h>
125#include <inttypes.h>
126
127
128/** @typedef some_int_type fsl_int_t
129
130 fsl_int_t is a signed integer type used to denote "relative"
131 ranges and lengths, or to tell a routine that it should try to
132 figure out the length of some byte array itself (e.g. by using
133 fsl_strlen() on it). It is provided primarily for
134 documentation/readability purposes, to avoid confusion with the
135 widely varying integer semantics used by various APIs. This type
136 is never used as a return type for functions which use "result
137 code semantics". Those always use an unadorned integer type or
138 some API-specific enum type.
139
140 The library typedefs this to a 64-bit type if possible, else
141 a 32-bit type.
142*/
143typedef int64_t fsl_int_t;
144/**
145 The unsigned counterpart of fsl_int_t.
146*/
147typedef uint64_t fsl_uint_t;
148
149/**
150 A 32-bit unsigned int type. This typedef is primarily to
151 improve documentation of the intent of function arguments
152 and struct members.
153*/
154typedef uint32_t fsl_flag32_t;
155typedef uint16_t fsl_flag16_t;
156
157/** @def FSL_INT_T_PFMT
158 Fossil's fsl_int_t equivalent of C99's PRIi32 and friends.
159 */
160#define FSL_INT_T_PFMT PRIi64
161/** @def FSL_INT_T_SFMT
162
163 Fossil's fsl_int_t equivalent of C99's SCNi32 and friends.
164 */
165#define FSL_INT_T_SFMT SCNi64
166/** @def FSL_UINT_T_PFMT
167
168 Fossil's fsl_uint_t equivalent of C99's PRIu32 and friends.
169 */
170#define FSL_UINT_T_PFMT PRIu64
171/** @def FSL_UINT_T_SFMT
172
173 Fossil's fsl_uint_t equivalent of C99's SCNu32 and friends.
174 */
175#define FSL_UINT_T_SFMT SCNu64
176
177/** @def FSL_JULIAN_T_PFMT
178
179 An output format specifier for Julian-format doubles.
180 */
181#define FSL_JULIAN_T_PFMT ".17g"
182
183/**
184 fsl_size_t is an unsigned integer type used to denote absolute
185 ranges and lengths. It is provided primarily for
186 documentation/readability purposes, to avoid confusion with the
187 widely varying integer semantics used by various APIs. While a
188 32-bit type is legal, a 64-bit type is required for "unusually
189 large" repos and for some metrics reporting even for mid-sized
190 repos.
191 */
192typedef uint64_t fsl_size_t;
193
194/** @def FSL_SIZE_T_PFMT
195
196 Fossil's fsl_size_t equivalent of C99's PRIu32 and friends.
197
198 ACHTUNG: when passing arguments of this type of fsl_appendf(), or
199 any function which uses it for formatting purposes, it is very
200 important if if you pass _literal integers_ OR enum values, that
201 they be cast to fsl_size_t, or the va_list handling might extract
202 the wrong number of bytes from the argument list, leading to
203 really weird side-effects via what is effectively memory
204 corruption.
205
206 That warning applies primarily to the following typedefs and their
207 format specifiers: fsl_size_t, fsl_int_t, fsl_uint_t, fsl_id_t.
208
209 The warning does not apply to strongly-typed arguments,
210 e.g. variables of the proper type, so long as the format specifier
211 string matches the argument type.
212
213 For example:
214
215 ```
216 fsl_size_t sz = 3;
217 fsl_fprintf( stdout, "%"FSL_SIZE_T_PFMT" %"FSL_SIZE_T_PFMT\n",
218 sz, // OK!
219 3 // BAD! See below...
220 );
221 ```
222
223 The "fix" is to cast the literal 3 to a fsl_size_t resp. the type
224 appropriate for the format specifier. That ensures that there is
225 no (or much less ;) confusion when va_arg() extracts arguments
226 from the variadic array.
227
228 Reminders to self:
229
230 ```
231 int i = 0;
232 f_out(("#%d: %"FSL_ID_T_PFMT" %"FSL_ID_T_PFMT" %"FSL_ID_T_PFMT"\n",
233 ++i, 1, 2, 3));
234 f_out(("#%d: %"FSL_SIZE_T_PFMT" %"FSL_ID_T_PFMT" %"FSL_SIZE_T_PFMT"\n",
235 ++i, (fsl_size_t)1, (fsl_id_t)2, (fsl_size_t)3));
236 // This one is the (generally) problematic case:
237 f_out(("#%d: %"FSL_SIZE_T_PFMT" %"FSL_ID_T_PFMT" %"FSL_SIZE_T_PFMT"\n",
238 ++i, 1, 2, 3));
239 ```
240
241 The above was Tested with gcc, clang, tcc on a 32-bit linux
242 platform (it has not been problematic on 64-bit builds!). The
243 above problem was reproduced on all compiler combinations i
244 tricored. Current code (20130824) seems to be behaving well as long
245 as callers always cast to help variadic arg handling DTRT.
246 */
247#define FSL_SIZE_T_PFMT FSL_UINT_T_PFMT
248
249/** @def FSL_SIZE_T_SFMT
250
251 Fossil's fsl_int_t equivalent of C99's SCNu32 and friends.
252 */
253#define FSL_SIZE_T_SFMT FSL_UINT_T_SFMT
254
255/**
256 fsl_id_t is a signed integer type used to store database record
257 IDs. It is provided primarily for documentation/readability purposes,
258 to avoid confusion with the widely varying integer semantics used
259 by various APIs.
260
261 This type "could" be 32-bit (instead of 64) because the
262 oldest/largest Fossil repo (the TCL tree, with 15 years of
263 history) currently (August 2013) has only 131k RIDs. HOWEVER,
264 changing this type can have side-effects vis-a-vis va_arg() deep
265 in the fsl_appendf() implementation if FSL_ID_T_PFMT is not 100%
266 correct for this typedef. After changing this, _make sure_ to do a
267 full clean rebuild and test thoroughly because changing a sizeof
268 can produce weird side-effects (effectively memory corruption) on
269 unclean rebuilds.
270 */
271typedef int32_t fsl_id_t;
272
273/** @def FSL_ID_T_PFMT
274
275 Fossil's fsl_id_t equivalent of C99's PRIi32 and friends.
276
277 ACHTUNG: see FSL_SIZE_T_PFMT for important details.
278 */
279#define FSL_ID_T_PFMT PRIi32
280
281/** @def FSL_ID_T_SFMT
282
283 Fossil's fsl_id_t equivalent of C99's SCNi32 and friends.
284 */
285#define FSL_ID_T_SFMT SCNi32
286
287/**
288 The type used to represent type values. Unless noted otherwise,
289 the general convention is Unix Epoch. That said, Fossil internally
290 uses Julian Date for times, so this typedef is clearly the result
291 of over-specification/over-thinking the problem. THAT said,
292 application-level code more commonly works with Unix timestamps,
293 so... here it is. Over-specified, perhaps, but not 100%
294 unjustifiable.
295 */
296typedef int64_t fsl_time_t;
297
298/** @def FSL_TIME_T_PFMT
299
300 Fossil's fsl_time_t equivalent of C99's PRIi32 and friends.
301 */
302#define FSL_TIME_T_PFMT PRIi64
303
304/** @def FSL_TIME_T_SFMT
305
306 Fossil's fsl_time_t equivalent of C99's SCNi32 and friends.
307 */
308#define FSL_TIME_T_SFMT SCNi64
309
310/**
311 If true, the fsl_timer_xxx() family of functions might do something useful,
312 otherwise they do not.
313 */
314#define FSL_CONFIG_ENABLE_TIMER 1
315
316#if !defined(FSL_ENABLE_SQLITE_REGEXP)
317# define FSL_ENABLE_SQLITE_REGEXP 0
318#endif
319
320/**
321 fossil(1)'s internal buffer size upper limit, which is also its
322 blob.content size limit. Changing this has no magic ability to push
323 past this limit, as pushing past them would create content
324 incompatible with fossil(1), and going past just shy of 2gb would
325 exceed sqlite3's limits.
326*/
327#define FSL_BLOB_MAX_SIZE 0x7fff0000
328
329#if !defined(FSL_SWITCH_FALL_THROUGH)
330# if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 7)
331/*
332 #define FSL_USING_GCC
333
334 gcc v7+ treats implicit 'switch' fallthrough as a warning
335 (i.e. error because we always build with -Wall -Werror -Wextra
336 -pedantic).
337
338 Similarly braindead, clang #defines __GNUC__.
339
340 _Sigh_.
341*/
342# define FSL_SWITCH_FALL_THROUGH __attribute__ ((fallthrough))
343# else
344# define FSL_SWITCH_FALL_THROUGH
345# endif
346#endif
347/* /FSL_SWITCH_FALL_THROUGH
348
349 TODO: add support for the C++ attributes for doing this.
350*/
351
352#if !defined(fsl__unused)
353#define fsl__unused
354#endif
355
356
357#endif
358/* ORG_FOSSIL_SCM_FSL_CONFIG_H_INCLUDED */
uint16_t fsl_flag16_t
Definition config.h:155
int32_t fsl_id_t
fsl_id_t is a signed integer type used to store database record IDs.
Definition config.h:271
uint64_t fsl_size_t
fsl_size_t is an unsigned integer type used to denote absolute ranges and lengths.
Definition config.h:192
int64_t fsl_time_t
The type used to represent type values.
Definition config.h:296
uint32_t fsl_flag32_t
A 32-bit unsigned int type.
Definition config.h:154
int64_t fsl_int_t
fsl_int_t is a signed integer type used to denote "relative" ranges and lengths, or to tell a routine...
Definition config.h:143
uint64_t fsl_uint_t
The unsigned counterpart of fsl_int_t.
Definition config.h:147