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