[PATCH 1 of 4] internals: move the bitmanipulation routines into its own file

Maciej Fijalkowski fijall at gmail.com
Wed Jun 8 07:59:36 UTC 2016


# HG changeset patch
# User Maciej Fijalkowski <fijall at gmail.com>
# Date 1465211293 -7200
#      Mon Jun 06 13:08:13 2016 +0200
# Node ID 9ede4f03703acd35cc0629367aed9c7318e1dfce
# Parent  bdba6a2015d0bc57c6e2beab25d138610dcbf360
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

diff -r bdba6a2015d0 -r 9ede4f03703a mercurial/bdiff.c
--- a/mercurial/bdiff.c	Mon May 16 04:31:20 2016 +0530
+++ 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;
diff -r bdba6a2015d0 -r 9ede4f03703a mercurial/bitmanipulation.h
--- /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,85 @@
+#ifndef _HG_BITMANIPULATION_H_
+#define _HG_BITMANIPULATION_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
+
+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
diff -r bdba6a2015d0 -r 9ede4f03703a mercurial/mpatch.c
--- a/mercurial/mpatch.c	Mon May 16 04:31:20 2016 +0530
+++ 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;
diff -r bdba6a2015d0 -r 9ede4f03703a mercurial/parsers.c
--- a/mercurial/parsers.c	Mon May 16 04:31:20 2016 +0530
+++ 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";
 
diff -r bdba6a2015d0 -r 9ede4f03703a mercurial/util.h
--- a/mercurial/util.h	Mon May 16 04:31:20 2016 +0530
+++ b/mercurial/util.h	Mon Jun 06 13:08:13 2016 +0200
@@ -57,40 +57,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 +68,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,


More information about the Mercurial-devel mailing list