changeset 33758:0f4ac3b6dee4

cext: factor out header for charencode.c This merges a part of util.h with the header which should exist for charencode.c.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 21 May 2017 14:23:22 +0900
parents e9996bd7203f
children a22339d389d4
files mercurial/cext/charencode.c mercurial/cext/charencode.h mercurial/cext/manifest.c mercurial/cext/parsers.c mercurial/cext/revlog.c mercurial/cext/util.h setup.py
diffstat 7 files changed, 62 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- 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 <Python.h>
 
+#include "charencode.h"
 #include "util.h"
 
 static const char lowertable[128] = {
--- /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 <Python.h>
+#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_ */
--- 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 <string.h>
 #include <stdlib.h>
 
+#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);
--- 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 <stddef.h>
 #include <string.h>
 
+#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;
--- 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 <stddef.h>
 #include <string.h>
 
+#include "charencode.h"
 #include "util.h"
 #include "bitmanipulation.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_ */
--- 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,