# HG changeset patch # User Yuya Nishihara # Date 1495344202 -32400 # Node ID 0f4ac3b6dee4d58d9b46f0e6bb95a9d8b478d88d # Parent e9996bd7203f99494c4701b8218335b02798d36e cext: factor out header for charencode.c This merges a part of util.h with the header which should exist for charencode.c. diff -r e9996bd7203f -r 0f4ac3b6dee4 mercurial/cext/charencode.c --- a/mercurial/cext/charencode.c Mon Jul 31 22:28:27 2017 +0900 +++ b/mercurial/cext/charencode.c Sun May 21 14:23:22 2017 +0900 @@ -9,6 +9,7 @@ #include +#include "charencode.h" #include "util.h" static const char lowertable[128] = { diff -r e9996bd7203f -r 0f4ac3b6dee4 mercurial/cext/charencode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/cext/charencode.h Sun May 21 14:23:22 2017 +0900 @@ -0,0 +1,57 @@ +/* + charencode.h - miscellaneous character encoding + + This software may be used and distributed according to the terms of + the GNU General Public License, incorporated herein by reference. +*/ + +#ifndef _HG_CHARENCODE_H_ +#define _HG_CHARENCODE_H_ + +#include +#include "compat.h" + +/* This should be kept in sync with normcasespecs in encoding.py. */ +enum normcase_spec { + NORMCASE_LOWER = -1, + NORMCASE_UPPER = 1, + NORMCASE_OTHER = 0 +}; + +PyObject *unhexlify(const char *str, int len); +PyObject *asciilower(PyObject *self, PyObject *args); +PyObject *asciiupper(PyObject *self, PyObject *args); +PyObject *make_file_foldmap(PyObject *self, PyObject *args); + +static const int8_t hextable[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0-9 */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; + +static inline int hexdigit(const char *p, Py_ssize_t off) +{ + int8_t val = hextable[(unsigned char)p[off]]; + + if (val >= 0) { + return val; + } + + PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); + return 0; +} + +#endif /* _HG_CHARENCODE_H_ */ diff -r e9996bd7203f -r 0f4ac3b6dee4 mercurial/cext/manifest.c --- a/mercurial/cext/manifest.c Mon Jul 31 22:28:27 2017 +0900 +++ b/mercurial/cext/manifest.c Sun May 21 14:23:22 2017 +0900 @@ -12,6 +12,7 @@ #include #include +#include "charencode.h" #include "util.h" #define DEFAULT_LINES 100000 @@ -38,9 +39,6 @@ #define MANIFEST_NOT_SORTED -2 #define MANIFEST_MALFORMED -3 -/* defined in charencode.c */ -PyObject *unhexlify(const char *str, int len); - /* get the length of the path for a line */ static size_t pathlen(line *l) { return strlen(l->start); diff -r e9996bd7203f -r 0f4ac3b6dee4 mercurial/cext/parsers.c --- a/mercurial/cext/parsers.c Mon Jul 31 22:28:27 2017 +0900 +++ b/mercurial/cext/parsers.c Sun May 21 14:23:22 2017 +0900 @@ -12,6 +12,7 @@ #include #include +#include "charencode.h" #include "util.h" #include "bitmanipulation.h" @@ -29,12 +30,6 @@ static const char *const versionerrortext = "Python minor version mismatch"; -/* defined in charencode.c */ -PyObject *unhexlify(const char *str, int len); -PyObject *asciilower(PyObject *self, PyObject *args); -PyObject *asciiupper(PyObject *self, PyObject *args); -PyObject *make_file_foldmap(PyObject *self, PyObject *args); - static PyObject *dict_new_presized(PyObject *self, PyObject *args) { Py_ssize_t expected_size; diff -r e9996bd7203f -r 0f4ac3b6dee4 mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c Mon Jul 31 22:28:27 2017 +0900 +++ b/mercurial/cext/revlog.c Sun May 21 14:23:22 2017 +0900 @@ -13,6 +13,7 @@ #include #include +#include "charencode.h" #include "util.h" #include "bitmanipulation.h" diff -r e9996bd7203f -r 0f4ac3b6dee4 mercurial/cext/util.h --- a/mercurial/cext/util.h Mon Jul 31 22:28:27 2017 +0900 +++ b/mercurial/cext/util.h Sun May 21 14:23:22 2017 +0900 @@ -25,13 +25,6 @@ extern PyTypeObject dirstateTupleType; #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType) -/* This should be kept in sync with normcasespecs in encoding.py. */ -enum normcase_spec { - NORMCASE_LOWER = -1, - NORMCASE_UPPER = 1, - NORMCASE_OTHER = 0 -}; - #define MIN(a, b) (((a)<(b))?(a):(b)) /* VC9 doesn't include bool and lacks stdbool.h based on my searching */ #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L @@ -54,35 +47,4 @@ return _PyDict_NewPresized(((1 + expected_size) / 2) * 3); } -static const int8_t hextable[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0-9 */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; - -static inline int hexdigit(const char *p, Py_ssize_t off) -{ - int8_t val = hextable[(unsigned char)p[off]]; - - if (val >= 0) { - return val; - } - - PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); - return 0; -} - #endif /* _HG_UTIL_H_ */ diff -r e9996bd7203f -r 0f4ac3b6dee4 setup.py --- a/setup.py Mon Jul 31 22:28:27 2017 +0900 +++ b/setup.py Sun May 21 14:23:22 2017 +0900 @@ -767,7 +767,7 @@ 'mercurial/cext/pathencode.c', 'mercurial/cext/revlog.c'], include_dirs=common_include_dirs, - depends=common_depends), + depends=common_depends + ['mercurial/cext/charencode.h']), Extension('mercurial.cext.osutil', ['mercurial/cext/osutil.c'], include_dirs=common_include_dirs, extra_compile_args=osutil_cflags,