[PATCH v2] store: rewrite fncache path mangling code in C

Adrian Buehlmann adrian at cadifra.com
Thu Aug 30 17:02:17 UTC 2012


On 2012-08-30 16:21, Noel Grandin wrote:
> 
> On 2012-08-30 14:58, Adrian Buehlmann wrote:
>>> > +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
> 
> MS-Visual-C cannot handle runtime-sized arrays allocated on the stack.

Apparently, yes.

It compiles with the MS C compiler if I do:

<snip>
#ifdef _MSC_VER
#include <malloc.h>
#endif

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 = alloca(baselen);
	char* lowered = alloca(baselen);
	char* auxed = alloca(baselen);
	char* mangled = alloca(baselen);
  ...
</snip>

> You will need to use malloc/free for the arrays.

I guess alloca() is faster.



More information about the Mercurial-devel mailing list