[PATCH v2] store: rewrite fncache path mangling code in C
Adrian Buehlmann
adrian at cadifra.com
Thu Aug 30 07:58:22 CDT 2012
On 2012-08-28 19:43, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano at fb.com>
> # Date 1346175814 25200
> # Node ID 91f70954e9d681a35130aa24f66aaa7148d8ee1b
> # Parent 99a2a4ae35e2180b7f825ef2677c36d538eac4ba
> store: rewrite fncache path mangling code in C
>
> The Python path mangling code used by fncache
The closest I got this to compile with the MS C compiler is to apply:
diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -18,10 +18,18 @@
#include <Python.h>
#include <assert.h>
#include <ctype.h>
-#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#ifndef _MSC_VER
+#include <stdint.h>
+#else
+typedef unsigned char uint8_t;
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+#endif
+
+
/* state machine for the fast path */
enum path_state {
START, /* first byte of a path component */
@@ -54,12 +62,12 @@
DDEFAULT,
};
-static inline int isset(const uint32_t bitset[], char c)
+static int isset(const uint32_t bitset[], char c)
{
return bitset[c >> 5] & (1 << (c & 31));
}
-static inline void charcopy(char *dest, Py_ssize_t *destlen, size_t destsize,
+static void charcopy(char *dest, Py_ssize_t *destlen, size_t destsize,
char c)
{
if (dest) {
@@ -69,7 +77,7 @@
(*destlen)++;
}
-static inline void memcopy(char *dest, Py_ssize_t *destlen, size_t destsize,
+static void memcopy(char *dest, Py_ssize_t *destlen, size_t destsize,
const void *src, Py_ssize_t len)
{
if (dest) {
@@ -79,7 +87,7 @@
*destlen += len;
}
-static inline void hexencode(char *dest, Py_ssize_t *destlen, size_t destsize,
+static void hexencode(char *dest, Py_ssize_t *destlen, size_t destsize,
uint8_t c)
{
static const char hexdigit[] = "0123456789abcdef";
@@ -89,7 +97,7 @@
}
/* 3-byte escape: tilde followed by two hex digits */
-static inline void escape3(char *dest, Py_ssize_t *destlen, size_t destsize,
+static void escape3(char *dest, Py_ssize_t *destlen, size_t destsize,
char c)
{
charcopy(dest, destlen, destsize, '~');
on top of your patch, but then this
> diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
> new file mode 100644
> --- /dev/null
> +++ b/mercurial/pathencode.c
> @@ -0,0 +1,669 @@
[..]
> +static Py_ssize_t hashencode(char *dest, size_t destsize, const char *src,
> + Py_ssize_t len)
> +{
> + const Py_ssize_t baselen = (len - 5) * 3;
> + char dired[baselen];
> + char lowered[baselen];
> + char auxed[baselen];
> + char mangled[baselen];
still fails to compile with:
mercurial/pathencode.c(612) : error C2057: expected constant expression
mercurial/pathencode.c(612) : error C2466: cannot allocate an array of constant size 0
mercurial/pathencode.c(612) : error C2133: 'dired' : unknown size
mercurial/pathencode.c(613) : error C2057: expected constant expression
mercurial/pathencode.c(613) : error C2466: cannot allocate an array of constant size 0
mercurial/pathencode.c(613) : error C2133: 'lowered' : unknown size
mercurial/pathencode.c(614) : error C2057: expected constant expression
mercurial/pathencode.c(614) : error C2466: cannot allocate an array of constant size 0
mercurial/pathencode.c(614) : error C2133: 'auxed' : unknown size
mercurial/pathencode.c(615) : error C2057: expected constant expression
mercurial/pathencode.c(615) : error C2466: cannot allocate an array of constant size 0
mercurial/pathencode.c(615) : error C2133: 'mangled' : unknown size
More information about the Mercurial-devel
mailing list