##// END OF EJS Templates
cext: define MIN macro only if it is not yet defined...
André Sintzoff -
r35793:440e8fce default
parent child Browse files
Show More
@@ -1,52 +1,54 b''
1 1 /*
2 2 util.h - utility functions for interfacing with the various python APIs.
3 3
4 4 This software may be used and distributed according to the terms of
5 5 the GNU General Public License, incorporated herein by reference.
6 6 */
7 7
8 8 #ifndef _HG_UTIL_H_
9 9 #define _HG_UTIL_H_
10 10
11 11 #include "compat.h"
12 12
13 13 #if PY_MAJOR_VERSION >= 3
14 14 #define IS_PY3K
15 15 #endif
16 16
17 17 /* clang-format off */
18 18 typedef struct {
19 19 PyObject_HEAD
20 20 char state;
21 21 int mode;
22 22 int size;
23 23 int mtime;
24 24 } dirstateTupleObject;
25 25 /* clang-format on */
26 26
27 27 extern PyTypeObject dirstateTupleType;
28 28 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
29 29
30 #ifndef MIN
30 31 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
32 #endif
31 33 /* VC9 doesn't include bool and lacks stdbool.h based on my searching */
32 34 #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
33 35 #define true 1
34 36 #define false 0
35 37 typedef unsigned char bool;
36 38 #else
37 39 #include <stdbool.h>
38 40 #endif
39 41
40 42 static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
41 43 {
42 44 /* _PyDict_NewPresized expects a minused parameter, but it actually
43 45 creates a dictionary that's the nearest power of two bigger than the
44 46 parameter. For example, with the initial minused = 1000, the
45 47 dictionary created has size 1024. Of course in a lot of cases that
46 48 can be greater than the maximum load factor Python's dict object
47 49 expects (= 2/3), so as soon as we cross the threshold we'll resize
48 50 anyway. So create a dictionary that's at least 3/2 the size. */
49 51 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
50 52 }
51 53
52 54 #endif /* _HG_UTIL_H_ */
General Comments 0
You need to be logged in to leave comments. Login now