mercurial/cext/util.h
author Yuya Nishihara <yuya@tcha.org>
Sun, 21 May 2017 13:41:01 +0900
changeset 32386 7640584e697c
parent 32385 34bd3cd28dcb
child 33756 5866ba5e9c48
permissions -rw-r--r--
cext: mark constant variables
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     1
/*
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     2
 util.h - utility functions for interfacing with the various python APIs.
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     3
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     4
 This software may be used and distributed according to the terms of
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     5
 the GNU General Public License, incorporated herein by reference.
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     6
*/
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     7
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     8
#ifndef _HG_UTIL_H_
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     9
#define _HG_UTIL_H_
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    10
29444
284d742e5611 internals: move the bitmanipulation routines into its own file
Maciej Fijalkowski <fijall@gmail.com>
parents: 25076
diff changeset
    11
#include "compat.h"
284d742e5611 internals: move the bitmanipulation routines into its own file
Maciej Fijalkowski <fijall@gmail.com>
parents: 25076
diff changeset
    12
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    13
#if PY_MAJOR_VERSION >= 3
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    14
#define IS_PY3K
30112
9b6ff0f940ed parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30101
diff changeset
    15
#endif
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    16
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    17
typedef struct {
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    18
	PyObject_HEAD
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    19
	char state;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    20
	int mode;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    21
	int size;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    22
	int mtime;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    23
} dirstateTupleObject;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    24
21838
0022ee690446 util.h: declare dirstateTupleType variable instead of defining it
André Sintzoff <andre.sintzoff@gmail.com>
parents: 21809
diff changeset
    25
extern PyTypeObject dirstateTupleType;
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    26
#define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    27
24608
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    28
/* This should be kept in sync with normcasespecs in encoding.py. */
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    29
enum normcase_spec {
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    30
	NORMCASE_LOWER = -1,
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    31
	NORMCASE_UPPER = 1,
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    32
	NORMCASE_OTHER = 0
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    33
};
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    34
24443
539b3c7eea44 phase: compute phases in C
Laurent Charignon <lcharignon@fb.com>
parents: 24442
diff changeset
    35
#define MIN(a, b) (((a)<(b))?(a):(b))
24442
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    36
/* VC9 doesn't include bool and lacks stdbool.h based on my searching */
24829
8e9f8d2a2c0c util: fix the check for non-C99 compilers (issue4605)
Kevin Bullock <kbullock@ringworld.org>
parents: 24823
diff changeset
    37
#if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
24442
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    38
#define true 1
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    39
#define false 0
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    40
typedef unsigned char bool;
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    41
#else
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    42
#include <stdbool.h>
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    43
#endif
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    44
32386
7640584e697c cext: mark constant variables
Yuya Nishihara <yuya@tcha.org>
parents: 32385
diff changeset
    45
static const int8_t hextable[256] = {
32378
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    46
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    47
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    48
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    49
	 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, /* 0-9 */
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    50
	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    51
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    52
	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    53
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    54
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    55
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    56
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    57
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    58
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    59
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    60
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    61
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    62
};
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    63
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    64
static inline int hexdigit(const char *p, Py_ssize_t off)
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    65
{
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    66
	int8_t val = hextable[(unsigned char)p[off]];
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    67
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    68
	if (val >= 0) {
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    69
		return val;
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    70
	}
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    71
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    72
	PyErr_SetString(PyExc_ValueError, "input contains non-hex character");
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    73
	return 0;
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    74
}
7d0c69505a66 cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30112
diff changeset
    75
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    76
#endif /* _HG_UTIL_H_ */