diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c --- a/mercurial/bdiff.c +++ b/mercurial/bdiff.c @@ -16,6 +16,7 @@ #include #include "util.h" +#include "bitmanipulation.h" struct line { int hash, n, e; diff --git a/mercurial/bitmanipulation.h b/mercurial/bitmanipulation.h new file mode 100644 --- /dev/null +++ b/mercurial/bitmanipulation.h @@ -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 diff --git a/mercurial/compat.h b/mercurial/compat.h new file mode 100644 --- /dev/null +++ b/mercurial/compat.h @@ -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 +#endif +#else +/* not windows */ +#include +#if defined __BEOS__ && !defined __HAIKU__ +#include +#else +#include +#endif +#include +#endif + +#if defined __hpux || defined __SUNPRO_C || defined _AIX +#define inline +#endif + +#ifdef __linux +#define inline __inline +#endif + +#endif diff --git a/mercurial/mpatch.c b/mercurial/mpatch.c --- a/mercurial/mpatch.c +++ b/mercurial/mpatch.c @@ -26,6 +26,7 @@ #include #include "util.h" +#include "bitmanipulation.h" static char mpatch_doc[] = "Efficient binary patching."; static PyObject *mpatch_Error; diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -13,6 +13,7 @@ #include #include "util.h" +#include "bitmanipulation.h" static char *versionerrortext = "Python minor version mismatch"; diff --git a/mercurial/util.h b/mercurial/util.h --- a/mercurial/util.h +++ b/mercurial/util.h @@ -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 -#endif -#else -/* not windows */ -#include -#if defined __BEOS__ && !defined __HAIKU__ -#include -#else -#include -#endif -#include -#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 @@ typedef struct { 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, diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -536,7 +536,9 @@ packages = ['mercurial', 'mercurial.hgwe '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 = []