##// END OF EJS Templates
cext: factor out header for charencode.c...
Yuya Nishihara -
r33753:0f4ac3b6 default
parent child Browse files
Show More
@@ -9,6 +9,7 b''
9
9
10 #include <Python.h>
10 #include <Python.h>
11
11
12 #include "charencode.h"
12 #include "util.h"
13 #include "util.h"
13
14
14 static const char lowertable[128] = {
15 static const char lowertable[128] = {
@@ -1,29 +1,15 b''
1 /*
1 /*
2 util.h - utility functions for interfacing with the various python APIs.
2 charencode.h - miscellaneous character encoding
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_CHARENCODE_H_
9 #define _HG_UTIL_H_
9 #define _HG_CHARENCODE_H_
10
11 #include "compat.h"
12
13 #if PY_MAJOR_VERSION >= 3
14 #define IS_PY3K
15 #endif
16
10
17 typedef struct {
11 #include <Python.h>
18 PyObject_HEAD
12 #include "compat.h"
19 char state;
20 int mode;
21 int size;
22 int mtime;
23 } dirstateTupleObject;
24
25 extern PyTypeObject dirstateTupleType;
26 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
27
13
28 /* This should be kept in sync with normcasespecs in encoding.py. */
14 /* This should be kept in sync with normcasespecs in encoding.py. */
29 enum normcase_spec {
15 enum normcase_spec {
@@ -32,27 +18,10 b' enum normcase_spec {'
32 NORMCASE_OTHER = 0
18 NORMCASE_OTHER = 0
33 };
19 };
34
20
35 #define MIN(a, b) (((a)<(b))?(a):(b))
21 PyObject *unhexlify(const char *str, int len);
36 /* VC9 doesn't include bool and lacks stdbool.h based on my searching */
22 PyObject *asciilower(PyObject *self, PyObject *args);
37 #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
23 PyObject *asciiupper(PyObject *self, PyObject *args);
38 #define true 1
24 PyObject *make_file_foldmap(PyObject *self, PyObject *args);
39 #define false 0
40 typedef unsigned char bool;
41 #else
42 #include <stdbool.h>
43 #endif
44
45 static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
46 {
47 /* _PyDict_NewPresized expects a minused parameter, but it actually
48 creates a dictionary that's the nearest power of two bigger than the
49 parameter. For example, with the initial minused = 1000, the
50 dictionary created has size 1024. Of course in a lot of cases that
51 can be greater than the maximum load factor Python's dict object
52 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. */
54 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
55 }
56
25
57 static const int8_t hextable[256] = {
26 static const int8_t hextable[256] = {
58 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
27 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -85,4 +54,4 b' static inline int hexdigit(const char *p'
85 return 0;
54 return 0;
86 }
55 }
87
56
88 #endif /* _HG_UTIL_H_ */
57 #endif /* _HG_CHARENCODE_H_ */
@@ -12,6 +12,7 b''
12 #include <string.h>
12 #include <string.h>
13 #include <stdlib.h>
13 #include <stdlib.h>
14
14
15 #include "charencode.h"
15 #include "util.h"
16 #include "util.h"
16
17
17 #define DEFAULT_LINES 100000
18 #define DEFAULT_LINES 100000
@@ -38,9 +39,6 b' typedef struct {'
38 #define MANIFEST_NOT_SORTED -2
39 #define MANIFEST_NOT_SORTED -2
39 #define MANIFEST_MALFORMED -3
40 #define MANIFEST_MALFORMED -3
40
41
41 /* defined in charencode.c */
42 PyObject *unhexlify(const char *str, int len);
43
44 /* get the length of the path for a line */
42 /* get the length of the path for a line */
45 static size_t pathlen(line *l) {
43 static size_t pathlen(line *l) {
46 return strlen(l->start);
44 return strlen(l->start);
@@ -12,6 +12,7 b''
12 #include <stddef.h>
12 #include <stddef.h>
13 #include <string.h>
13 #include <string.h>
14
14
15 #include "charencode.h"
15 #include "util.h"
16 #include "util.h"
16 #include "bitmanipulation.h"
17 #include "bitmanipulation.h"
17
18
@@ -29,12 +30,6 b''
29
30
30 static const char *const versionerrortext = "Python minor version mismatch";
31 static const char *const versionerrortext = "Python minor version mismatch";
31
32
32 /* defined in charencode.c */
33 PyObject *unhexlify(const char *str, int len);
34 PyObject *asciilower(PyObject *self, PyObject *args);
35 PyObject *asciiupper(PyObject *self, PyObject *args);
36 PyObject *make_file_foldmap(PyObject *self, PyObject *args);
37
38 static PyObject *dict_new_presized(PyObject *self, PyObject *args)
33 static PyObject *dict_new_presized(PyObject *self, PyObject *args)
39 {
34 {
40 Py_ssize_t expected_size;
35 Py_ssize_t expected_size;
@@ -13,6 +13,7 b''
13 #include <stddef.h>
13 #include <stddef.h>
14 #include <string.h>
14 #include <string.h>
15
15
16 #include "charencode.h"
16 #include "util.h"
17 #include "util.h"
17 #include "bitmanipulation.h"
18 #include "bitmanipulation.h"
18
19
@@ -25,13 +25,6 b' typedef struct {'
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
@@ -54,35 +47,4 b' static inline PyObject *_dict_new_presiz'
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_ */
@@ -767,7 +767,7 b' extmodules = ['
767 'mercurial/cext/pathencode.c',
767 'mercurial/cext/pathencode.c',
768 'mercurial/cext/revlog.c'],
768 'mercurial/cext/revlog.c'],
769 include_dirs=common_include_dirs,
769 include_dirs=common_include_dirs,
770 depends=common_depends),
770 depends=common_depends + ['mercurial/cext/charencode.h']),
771 Extension('mercurial.cext.osutil', ['mercurial/cext/osutil.c'],
771 Extension('mercurial.cext.osutil', ['mercurial/cext/osutil.c'],
772 include_dirs=common_include_dirs,
772 include_dirs=common_include_dirs,
773 extra_compile_args=osutil_cflags,
773 extra_compile_args=osutil_cflags,
General Comments 0
You need to be logged in to leave comments. Login now