libfossil
fossil-config.h
Go to the documentation of this file.
1 #if !defined (NET_FOSSIL_SCM_FSL_CONFIG_H_INCLUDED)
2 #define NET_FOSSIL_SCM_FSL_CONFIG_H_INCLUDED
3 
4 #if defined(_MSC_VER) && ! defined(FSL_AMALGAMATION_BUILD)
5 #include "config-win32.h" /* manually generated */
6 #else
7 #include "autoconfig.h" /* auto-generated */
8 #endif
9 
10 #ifdef _WIN32
11 # if defined(BUILD_libfossil_static) || defined(FSL_AMALGAMATION_BUILD)
12 # define FSL_EXPORT extern
13 # elif defined(BUILD_libfossil)
14 # define FSL_EXPORT extern __declspec(dllexport)
15 # else
16 # define FSL_EXPORT extern __declspec(dllimport)
17 # endif
18 #else
19 # define FSL_EXPORT extern
20 #endif
21 
22 #if HAVE_C99_INT || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
23 /* C99 fixed integers... */
24 #if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
25 /* inttypes.h needs this for the PRI* and SCN* macros in C++ mode. */
26 # define __STDC_FORMAT_MACROS
27 #endif
28 #include <stdint.h>
29 #include <inttypes.h>
30 #define FSL_HAS_FIXED_INTEGERS 1
31 #else
32 #define FSL_HAS_FIXED_INTEGERS 0
33 #endif
34 /* /C99 */
35 
36 #if !defined(FSL_AUX_SCHEMA)
37 #error "Expecting FSL_AUX_SCHEMA to be defined by the configuration bits."
38 #endif
39 #if !defined(FSL_LIBRARY_VERSION)
40 #error "Expecting FSL_LIBRARY_VERSION to be defined by the configuration bits."
41 #endif
42 
43 /**
44  A workaround for late-2015 gcc versions adding __func__ warnings
45  to -pedantic mode.
46 */
47 #if !defined(__cplusplus)
48 # if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
49 # define __func__ "__func__"
50 # endif
51 #endif
52 
53 
54 #if FSL_HAS_FIXED_INTEGERS
55 /* C99 specifies fixed-size integers and their printf-compatible format specifiers,
56  so we'll use those...
57 */
58 typedef int16_t fsl_int16_t;
59 typedef uint16_t fsl_uint16_t;
60 typedef int32_t fsl_int32_t;
61 typedef uint32_t fsl_uint32_t;
62 typedef int64_t fsl_int64_t;
63 typedef uint64_t fsl_uint64_t;
64 #define FSL_INT32_T_PFMT PRIi32
65 #define FSL_INT32_T_SFMT SCNi32
66 #define FSL_UINT32_T_PFMT PRIu32
67 #define FSL_UINT32_T_SFMT SCNu32
68 #define FSL_INT64_T_PFMT PRIi64
69 #define FSL_INT64_T_SFMT SCNi64
70 #define FSL_UINT64_T_PFMT PRIu64
71 #define FSL_UINT64_T_SFMT SCNu64
72 #else
73 /*
74  Guess some reasonable defaults...
75 
76  See FSL_SIZE_T_PFMT for some important notes regarding formatting
77  strings, sizeof()s, and variadic arguments.
78 */
79 typedef short fsl_int16_t;
80 typedef unsigned short fsl_uint16_t;
81 typedef int fsl_int32_t;
82 typedef unsigned int fsl_uint32_t;
83 
84 #define FSL_INT32_T_PFMT "i"
85 #define FSL_INT32_T_SFMT "i"
86 #define FSL_UINT32_T_PFMT "u"
87 #define FSL_UINT32_T_SFMT "u"
88 
89 #if defined(HAVE_LONG_LONG) && HAVE_LONG_LONG
90 #if defined(_MSC_VER) || defined(__BORLANDC__)
91 typedef __int64 fsl_int64_t;
92 typedef unsigned __int64 fsl_uint64_t;
93 #else
94 typedef long long int fsl_int64_t;
95 typedef unsigned long long int fsl_uint64_t;
96 #endif
97 #define FSL_INT64_T_PFMT "lli"
98 #define FSL_INT64_T_SFMT "lli"
99 #define FSL_UINT64_T_PFMT "llu"
100 #define FSL_UINT64_T_SFMT "llu"
101 #else
102 /*
103  We have no long long...
104 */
105 #if defined(_MSC_VER) || defined(__BORLANDC__)
106 typedef __int64 fsl_int64_t;
107 typedef unsigned __int64 fsl_uint64_t;
108 #else
109 /*
110  Make up a 64-bit integer type...
111 
112  WARNING: on 32-bit platforms 'long' is very likely to be 4 bytes,
113  meaning that Fossil, while "generally functional and correct," and
114  certainly won't overrun any values on normal repos, could run into
115  overflow problems on some operations, e.g. the /stat page of the
116  fossil(1) repo needs to count above 2GB at times.
117 
118  We "could" use sqlite_int64, BUT that header isn't included yet and
119  we cannot, for portability reasons involving some of the lower-level
120  config macros, include that header first. We "could" include it not
121  first, though. Okay, let's try falling back to that one...
122 */
123 #include "sqlite3.h"
124 typedef sqlite3_int64 fsl_int64_t;
125 typedef sqlite3_uint64 fsl_uint64_t;
126 #endif
127 /* end MSC or BORLAND */
128 #define FSL_INT64_T_PFMT "lli"
129 #define FSL_INT64_T_SFMT "lli"
130 #define FSL_UINT64_T_PFMT "llu"
131 #define FSL_UINT64_T_SFMT "llu"
132 #endif
133 /* HAVE_LONG_LONG */
134 #endif
135 /* end configurable numeric bits.
136  Moving on to fixed and derived numeric bits...
137 */
138 
139 
140 /** @typedef some_int_type fsl_int_t
141 
142  fsl_int_t is a signed integer type used to denote "relative"
143  ranges and lengths, or to tell a routine that it should try to
144  figure out the length of some byte array itself (e.g. by using
145  fsl_strlen() on it). It is provided primarily for
146  documentation/readability purposes, to avoid confusion with the
147  widely varying integer semantics used by various APIs. This type
148  is never used as a return type for functions which use "error code
149  semantics." Those always use an unadorned integer type or some
150  API-specific enum type.
151 
152  The library typedefs this to a 64-bit type if possible, else
153  a 32-bit type.
154  */
156 /**
157  The unsigned counterpart of fsl_int_t.
158  */
160 /**
161  printf format specifier for fsl_int_t.
162  */
163 #define FSL_INT_T_PFMT FSL_INT64_T_PFMT
164 /**
165  scanf format specifier for fsl_int_t.
166  */
167 #define FSL_INT_T_SFMT FSL_INT64_T_SFMT
168 /**
169  printf format specifier for fsl_uint_t.
170  */
171 #define FSL_UINT_T_PFMT FSL_UINT64_T_PFMT
172 /**
173  scanf format specifier for fsl_uint_t.
174  */
175 #define FSL_UINT_T_SFMT FSL_UINT64_T_SFMT
176 
177 /** @def FSL_INT_T_PFMT
178 
179  Fossil's fsl_int_t equivalent of C99's PRIi32 and friends.
180  */
181 
182 /** @def FSL_INT_T_SFMT
183 
184  Fossil's fsl_int_t equivalent of C99's SCNi32 and friends.
185  */
186 
187 /** @def FSL_UINT_T_PFMT
188 
189  Fossil's fsl_uint_t equivalent of C99's PRIu32 and friends.
190  */
191 
192 /** @def FSL_UINT_T_SFMT
193 
194  Fossil's fsl_uint_t equivalent of C99's SCNu32 and friends.
195  */
196 
197 /**
198  fsl_double_t is the double type used by the library. It is
199  currently hard-coded to double but the API allows for it to
200  eventually be used with long double, or potentially even with
201  integers as a substitute (but note that Fossil generally stores
202  times in Julian Date format, which requires double precision).
203  */
204 typedef double fsl_double_t;
205 
206 /** @def FSL_DOUBLE_T_PFMT
207 
208  Fossil's fsl_double_t-equivalent of FSL_INT_T_PFMT and friends.
209  */
210 #define FSL_DOUBLE_T_PFMT "f"
211 
212 /** @def FSL_JULIAN_T_PFMT
213 
214  An output format specifier for Julian-format doubles.
215  */
216 #define FSL_JULIAN_T_PFMT ".17g"
217 
218 
219 /**
220  fsl_size_t is an unsigned integer type used to denote absolute
221  ranges and lengths. It is provided primarily for
222  documentation/readability purposes, to avoid confusion with the
223  widely varying integer semantics used by various APIs. While a
224  32-bit type is legal, a 64-bit type is required for "unusually
225  large" repos.
226  */
228 
229 /** @def FSL_SIZE_T_PFMT
230 
231  Fossil's fsl_size_t equivalent of C99's PRIu32 and friends.
232 
233  ACHTUNG: when passing arguments of this type of fsl_appendf(), or
234  any function which uses it for formatting purposes, it is very
235  important if if you pass _literal integers_ OR enum values, that
236  they be cast to fsl_size_t, or the va_list handling might extract
237  the wrong number of bytes from the argument list, leading to
238  really weird side-effects via what is effectively memory
239  corruption.
240 
241  That warning applies primarily to the following typedefs and their
242  format specifiers: fsl_size_t, fsl_int_t, fsl_uint_t, fsl_id_t.
243 
244  The warning does not apply to strongly-typed arguments,
245  e.g. variables of the proper type, so long as the format specifier
246  string matches the argument type.
247 
248  For example:
249 
250  @code
251  fsl_size_t sz = 3;
252  fsl_fprintf( stdout, "%"FSL_SIZE_T_PFMT" %"FSL_SIZE_T_PFMT\n",
253  sz, // OK!
254  3 // BAD! See below...
255  );
256  @endcode
257 
258  The "fix" is to cast the literal 3 to a fsl_size_t resp. the type
259  appropriate for the format specifier. That ensures that there is
260  no (or much less ;) confusion when va_arg() extracts arguments
261  from the variadic array.
262 
263  Reminders to self:
264 
265  @code
266  int i = 0;
267  f_out(("#%d: %"FSL_ID_T_PFMT" %"FSL_ID_T_PFMT" %"FSL_ID_T_PFMT"\n",
268  ++i, 1, 2, 3));
269  f_out(("#%d: %"FSL_SIZE_T_PFMT" %"FSL_ID_T_PFMT" %"FSL_SIZE_T_PFMT"\n",
270  ++i, (fsl_size_t)1, (fsl_id_t)2, (fsl_size_t)3));
271  // This one is the (generally) problematic case:
272  f_out(("#%d: %"FSL_SIZE_T_PFMT" %"FSL_ID_T_PFMT" %"FSL_SIZE_T_PFMT"\n",
273  ++i, 1, 2, 3));
274  @endcode
275 
276  The above was Tested with gcc, clang, tcc on a 32-bit linux
277  platform (it has not been problematic on 64-bit builds!). The
278  above problem was reproduced on all compiler combinations i
279  tried. Current code (20130824) seems to be behaving well as long
280  as callers always cast to help variadic arg handling DTRT.
281 
282  */
283 #define FSL_SIZE_T_PFMT FSL_UINT_T_PFMT
284 
285 /** @def FSL_SIZE_T_SFMT
286 
287  Fossil's fsl_int_t equivalent of C99's SCNu32 and friends.
288  */
289 #define FSL_SIZE_T_SFMT FSL_UINT_T_SFMT
290 
291 /**
292  fsl_id_t is a signed integer type used to store database record
293  IDs. It is provided primarily for documentation/readability purposes,
294  to avoid confusion with the widely varying integer semantics used
295  by various APIs.
296 
297  This type "could" be 32-bit (instead of 64) because the
298  oldest/largest Fossil repo (the TCL tree, with 15 years of
299  history) currently (August 2013) has only 131k RIDs. HOWEVER,
300  changing this type can have side-effects vis-a-vis va_arg() deep
301  in the fsl_appendf() implementation if FSL_ID_T_PFMT is not 100%
302  correct for this typedef. After changing this, _make sure_ to do a
303  full clean rebuild and test thoroughly because changing a sizeof
304  can produce weird side-effects (effectively memory corruption) on
305  unclean rebuilds.
306  */
308 
309 /** @def FSL_ID_T_PFMT
310 
311  Fossil's fsl_id_t equivalent of C99's PRIi32 and friends.
312 
313  ACHTUNG: see FSL_SIZE_T_PFMT for important details.
314  */
315 #define FSL_ID_T_PFMT FSL_INT32_T_PFMT
316 
317 /** @def FSL_ID_T_SFMT
318 
319  Fossil's fsl_id_t equivalent of C99's SCNi32 and friends.
320  */
321 #define FSL_ID_T_SFMT FSL_INT32_T_SFMT
322 
323 /**
324  The type used to represent type values. Unless noted otherwise,
325  the general convention is Unix Epoch. That said, Fossil internally
326  uses Julian Date for times, so this typedef is clearly the result
327  of over-specification/over-thinking the problem. THAT said,
328  application-level code more commonly works with Unix timestamps,
329  so... here it is. Over-specified, perhaps, but not 100%
330  unjustifiable.
331  */
333 
334 /** @def FSL_TIME_T_PFMT
335 
336  Fossil's fsl_time_t equivalent of C99's PRIi32 and friends.
337  */
338 #define FSL_TIME_T_PFMT FSL_INT64_T_PFMT
339 
340 /** @def FSL_TIME_T_SFMT
341 
342  Fossil's fsl_time_t equivalent of C99's SCNi32 and friends.
343  */
344 #define FSL_TIME_T_SFMT FSL_INT64_T_SFMT
345 
346 /**
347  If true, the fsl_timer_xxx() family of functions might do something useful,
348  otherwise they do not.
349  */
350 #define FSL_CONFIG_ENABLE_TIMER 1
351 
352 
353 #endif
354 /* NET_FOSSIL_SCM_FSL_CONFIG_H_INCLUDED */
fsl_uint_t fsl_size_t
fsl_size_t is an unsigned integer type used to denote absolute ranges and lengths.
int fsl_int32_t
Definition: fossil-config.h:81
fsl_int64_t fsl_time_t
The type used to represent type values.
fsl_int32_t fsl_id_t
fsl_id_t is a signed integer type used to store database record IDs.
long long int fsl_int64_t
Definition: fossil-config.h:94
short fsl_int16_t
A workaround for late-2015 gcc versions adding __func__ warnings to -pedantic mode.
Definition: fossil-config.h:79
fsl_uint64_t fsl_uint_t
The unsigned counterpart of fsl_int_t.
unsigned int fsl_uint32_t
Definition: fossil-config.h:82
unsigned short fsl_uint16_t
Definition: fossil-config.h:80
fsl_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...
double fsl_double_t
fsl_double_t is the double type used by the library.
unsigned long long int fsl_uint64_t
Definition: fossil-config.h:95