mercurial/cext/util.h
changeset 33758 0f4ac3b6dee4
parent 33756 5866ba5e9c48
child 34635 3455e2e2ce9b
equal deleted inserted replaced
33757:e9996bd7203f 33758:0f4ac3b6dee4
    23 } dirstateTupleObject;
    23 } dirstateTupleObject;
    24 
    24 
    25 extern PyTypeObject dirstateTupleType;
    25 extern PyTypeObject dirstateTupleType;
    26 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
    26 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
    27 
    27 
    28 /* This should be kept in sync with normcasespecs in encoding.py. */
       
    29 enum normcase_spec {
       
    30 	NORMCASE_LOWER = -1,
       
    31 	NORMCASE_UPPER = 1,
       
    32 	NORMCASE_OTHER = 0
       
    33 };
       
    34 
       
    35 #define MIN(a, b) (((a)<(b))?(a):(b))
    28 #define MIN(a, b) (((a)<(b))?(a):(b))
    36 /* VC9 doesn't include bool and lacks stdbool.h based on my searching */
    29 /* VC9 doesn't include bool and lacks stdbool.h based on my searching */
    37 #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
    30 #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
    38 #define true 1
    31 #define true 1
    39 #define false 0
    32 #define false 0
    52 	   expects (= 2/3), so as soon as we cross the threshold we'll resize
    45 	   expects (= 2/3), so as soon as we cross the threshold we'll resize
    53 	   anyway. So create a dictionary that's at least 3/2 the size. */
    46 	   anyway. So create a dictionary that's at least 3/2 the size. */
    54 	return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
    47 	return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
    55 }
    48 }
    56 
    49 
    57 static const int8_t hextable[256] = {
       
    58 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    59 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    60 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    61 	 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, /* 0-9 */
       
    62 	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */
       
    63 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    64 	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */
       
    65 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    66 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    67 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    68 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    69 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    70 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    71 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    72 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       
    73 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
       
    74 };
       
    75 
       
    76 static inline int hexdigit(const char *p, Py_ssize_t off)
       
    77 {
       
    78 	int8_t val = hextable[(unsigned char)p[off]];
       
    79 
       
    80 	if (val >= 0) {
       
    81 		return val;
       
    82 	}
       
    83 
       
    84 	PyErr_SetString(PyExc_ValueError, "input contains non-hex character");
       
    85 	return 0;
       
    86 }
       
    87 
       
    88 #endif /* _HG_UTIL_H_ */
    50 #endif /* _HG_UTIL_H_ */