[PATCH 3 of 6] cext: factor out header for charencode.c
Yuya Nishihara
yuya at tcha.org
Tue Aug 8 14:30:22 UTC 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1495344202 -32400
# Sun May 21 14:23:22 2017 +0900
# Node ID bc781471fcea7c9f2e5dc9db0b6696ad31c681cc
# Parent ef7755af442bdbbbe95c0d75e9375ab17cdb970f
cext: factor out header for charencode.c
This merges a part of util.h with the header which should exist for
charencode.c.
diff --git a/mercurial/cext/charencode.c b/mercurial/cext/charencode.c
--- a/mercurial/cext/charencode.c
+++ b/mercurial/cext/charencode.c
@@ -9,6 +9,7 @@
#include <Python.h>
+#include "charencode.h"
#include "util.h"
static const char lowertable[128] = {
diff --git a/mercurial/cext/util.h b/mercurial/cext/charencode.h
copy from mercurial/cext/util.h
copy to mercurial/cext/charencode.h
--- a/mercurial/cext/util.h
+++ b/mercurial/cext/charencode.h
@@ -1,29 +1,15 @@
/*
- util.h - utility functions for interfacing with the various python APIs.
+ 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_UTIL_H_
-#define _HG_UTIL_H_
-
-#include "compat.h"
-
-#if PY_MAJOR_VERSION >= 3
-#define IS_PY3K
-#endif
+#ifndef _HG_CHARENCODE_H_
+#define _HG_CHARENCODE_H_
-typedef struct {
- PyObject_HEAD
- char state;
- int mode;
- int size;
- int mtime;
-} dirstateTupleObject;
-
-extern PyTypeObject dirstateTupleType;
-#define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
+#include <Python.h>
+#include "compat.h"
/* This should be kept in sync with normcasespecs in encoding.py. */
enum normcase_spec {
@@ -32,27 +18,10 @@ enum normcase_spec {
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
-#define true 1
-#define false 0
-typedef unsigned char bool;
-#else
-#include <stdbool.h>
-#endif
-
-static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
-{
- /* _PyDict_NewPresized expects a minused parameter, but it actually
- creates a dictionary that's the nearest power of two bigger than the
- parameter. For example, with the initial minused = 1000, the
- dictionary created has size 1024. Of course in a lot of cases that
- can be greater than the maximum load factor Python's dict object
- expects (= 2/3), so as soon as we cross the threshold we'll resize
- anyway. So create a dictionary that's at least 3/2 the size. */
- return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
-}
+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,
@@ -85,4 +54,4 @@ static inline int hexdigit(const char *p
return 0;
}
-#endif /* _HG_UTIL_H_ */
+#endif /* _HG_CHARENCODE_H_ */
diff --git a/mercurial/cext/manifest.c b/mercurial/cext/manifest.c
--- a/mercurial/cext/manifest.c
+++ b/mercurial/cext/manifest.c
@@ -12,6 +12,7 @@
#include <string.h>
#include <stdlib.h>
+#include "charencode.h"
#include "util.h"
#define DEFAULT_LINES 100000
@@ -38,9 +39,6 @@ typedef struct {
#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 --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -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;
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -13,6 +13,7 @@
#include <stddef.h>
#include <string.h>
+#include "charencode.h"
#include "util.h"
#include "bitmanipulation.h"
diff --git a/mercurial/cext/util.h b/mercurial/cext/util.h
--- a/mercurial/cext/util.h
+++ b/mercurial/cext/util.h
@@ -25,13 +25,6 @@ typedef struct {
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 @@ static inline PyObject *_dict_new_presiz
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 --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -767,7 +767,7 @@ extmodules = [
'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,
More information about the Mercurial-devel
mailing list