internals: move the bitmanipulation routines into its own file
This is to allow more flexibility with the C sources -- now the
bitmanipulation routines can be safely imported without importing Python.h
--- a/mercurial/bdiff.c Fri Jun 24 16:12:05 2016 +0100
+++ b/mercurial/bdiff.c Mon Jun 06 13:08:13 2016 +0200
@@ -16,6 +16,7 @@
#include <limits.h>
#include "util.h"
+#include "bitmanipulation.h"
struct line {
int hash, n, e;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/bitmanipulation.h Mon Jun 06 13:08:13 2016 +0200
@@ -0,0 +1,53 @@
+#ifndef _HG_BITMANIPULATION_H_
+#define _HG_BITMANIPULATION_H_
+
+#include "compat.h"
+
+static inline uint32_t getbe32(const char *c)
+{
+ const unsigned char *d = (const unsigned char *)c;
+
+ return ((d[0] << 24) |
+ (d[1] << 16) |
+ (d[2] << 8) |
+ (d[3]));
+}
+
+static inline int16_t getbeint16(const char *c)
+{
+ const unsigned char *d = (const unsigned char *)c;
+
+ return ((d[0] << 8) |
+ (d[1]));
+}
+
+static inline uint16_t getbeuint16(const char *c)
+{
+ const unsigned char *d = (const unsigned char *)c;
+
+ return ((d[0] << 8) |
+ (d[1]));
+}
+
+static inline void putbe32(uint32_t x, char *c)
+{
+ c[0] = (x >> 24) & 0xff;
+ c[1] = (x >> 16) & 0xff;
+ c[2] = (x >> 8) & 0xff;
+ c[3] = (x) & 0xff;
+}
+
+static inline double getbefloat64(const char *c)
+{
+ const unsigned char *d = (const unsigned char *)c;
+ double ret;
+ int i;
+ uint64_t t = 0;
+ for (i = 0; i < 8; i++) {
+ t = (t<<8) + d[i];
+ }
+ memcpy(&ret, &t, sizeof(t));
+ return ret;
+}
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/compat.h Mon Jun 06 13:08:13 2016 +0200
@@ -0,0 +1,38 @@
+#ifndef _HG_COMPAT_H_
+#define _HG_COMPAT_H_
+
+#ifdef _WIN32
+#ifdef _MSC_VER
+/* msvc 6.0 has problems */
+#define inline __inline
+typedef signed char int8_t;
+typedef short int16_t;
+typedef long int32_t;
+typedef __int64 int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned long uint32_t;
+typedef unsigned __int64 uint64_t;
+#else
+#include <stdint.h>
+#endif
+#else
+/* not windows */
+#include <sys/types.h>
+#if defined __BEOS__ && !defined __HAIKU__
+#include <ByteOrder.h>
+#else
+#include <arpa/inet.h>
+#endif
+#include <inttypes.h>
+#endif
+
+#if defined __hpux || defined __SUNPRO_C || defined _AIX
+#define inline
+#endif
+
+#ifdef __linux
+#define inline __inline
+#endif
+
+#endif
--- a/mercurial/mpatch.c Fri Jun 24 16:12:05 2016 +0100
+++ b/mercurial/mpatch.c Mon Jun 06 13:08:13 2016 +0200
@@ -26,6 +26,7 @@
#include <string.h>
#include "util.h"
+#include "bitmanipulation.h"
static char mpatch_doc[] = "Efficient binary patching.";
static PyObject *mpatch_Error;
--- a/mercurial/parsers.c Fri Jun 24 16:12:05 2016 +0100
+++ b/mercurial/parsers.c Mon Jun 06 13:08:13 2016 +0200
@@ -13,6 +13,7 @@
#include <string.h>
#include "util.h"
+#include "bitmanipulation.h"
static char *versionerrortext = "Python minor version mismatch";
--- a/mercurial/util.h Fri Jun 24 16:12:05 2016 +0100
+++ b/mercurial/util.h Mon Jun 06 13:08:13 2016 +0200
@@ -8,6 +8,8 @@
#ifndef _HG_UTIL_H_
#define _HG_UTIL_H_
+#include "compat.h"
+
#if PY_MAJOR_VERSION >= 3
#define IS_PY3K
@@ -57,40 +59,6 @@
#endif /* PY_MAJOR_VERSION */
-#ifdef _WIN32
-#ifdef _MSC_VER
-/* msvc 6.0 has problems */
-#define inline __inline
-typedef signed char int8_t;
-typedef short int16_t;
-typedef long int32_t;
-typedef __int64 int64_t;
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned long uint32_t;
-typedef unsigned __int64 uint64_t;
-#else
-#include <stdint.h>
-#endif
-#else
-/* not windows */
-#include <sys/types.h>
-#if defined __BEOS__ && !defined __HAIKU__
-#include <ByteOrder.h>
-#else
-#include <arpa/inet.h>
-#endif
-#include <inttypes.h>
-#endif
-
-#if defined __hpux || defined __SUNPRO_C || defined _AIX
-#define inline
-#endif
-
-#ifdef __linux
-#define inline __inline
-#endif
-
typedef struct {
PyObject_HEAD
char state;
@@ -102,53 +70,6 @@
extern PyTypeObject dirstateTupleType;
#define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
-static inline uint32_t getbe32(const char *c)
-{
- const unsigned char *d = (const unsigned char *)c;
-
- return ((d[0] << 24) |
- (d[1] << 16) |
- (d[2] << 8) |
- (d[3]));
-}
-
-static inline int16_t getbeint16(const char *c)
-{
- const unsigned char *d = (const unsigned char *)c;
-
- return ((d[0] << 8) |
- (d[1]));
-}
-
-static inline uint16_t getbeuint16(const char *c)
-{
- const unsigned char *d = (const unsigned char *)c;
-
- return ((d[0] << 8) |
- (d[1]));
-}
-
-static inline void putbe32(uint32_t x, char *c)
-{
- c[0] = (x >> 24) & 0xff;
- c[1] = (x >> 16) & 0xff;
- c[2] = (x >> 8) & 0xff;
- c[3] = (x) & 0xff;
-}
-
-static inline double getbefloat64(const char *c)
-{
- const unsigned char *d = (const unsigned char *)c;
- double ret;
- int i;
- uint64_t t = 0;
- for (i = 0; i < 8; i++) {
- t = (t<<8) + d[i];
- }
- memcpy(&ret, &t, sizeof(t));
- return ret;
-}
-
/* This should be kept in sync with normcasespecs in encoding.py. */
enum normcase_spec {
NORMCASE_LOWER = -1,
--- a/setup.py Fri Jun 24 16:12:05 2016 +0100
+++ b/setup.py Mon Jun 06 13:08:13 2016 +0200
@@ -536,7 +536,9 @@
'hgext.fsmonitor.pywatchman', 'hgext.highlight',
'hgext.largefiles', 'hgext.zeroconf', 'hgext3rd']
-common_depends = ['mercurial/util.h']
+common_depends = ['mercurial/bitmanipulation.h',
+ 'mercurial/compat.h',
+ 'mercurial/util.h']
osutil_ldflags = []