[pypy-dev] Re: [pypy-svn] r22006 - in pypy/dist/pypy/translator/c: . src test
Ben.Young at risk.sungard.com
Ben.Young at risk.sungard.com
Thu Jan 12 10:41:52 CET 2006
Hi Eric,
Just to let you know that on Windows, alloca is spelt _alloca. In later
versions the preferred version is _malloca, which needs to be matched by a
_freea, as _malloca can allocate on the heap if the object is too large.
Cheers,
Ben
pypy-svn-bounces at codespeak.net wrote on 12/01/2006 09:31:21:
> Author: ericvrp
> Date: Thu Jan 12 10:31:20 2006
> New Revision: 22006
>
> Modified:
> pypy/dist/pypy/translator/c/funcgen.py
> pypy/dist/pypy/translator/c/src/address.h
> pypy/dist/pypy/translator/c/test/test_lladdresses.py
> Log:
> Added genc support of stack flavored_malloc
>
>
> Modified: pypy/dist/pypy/translator/c/funcgen.py
>
==============================================================================
> --- pypy/dist/pypy/translator/c/funcgen.py (original)
> +++ pypy/dist/pypy/translator/c/funcgen.py Thu Jan 12 10:31:20 2006
> @@ -568,6 +568,8 @@
> flavor = op.args[0].value
> if flavor == "raw":
> return "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, err)
> + elif flavor == "stack":
> + return "OP_STACK_MALLOC(%s, %s, %s);" % (esize, eresult,
err)
> else:
> raise NotImplementedError
>
>
> Modified: pypy/dist/pypy/translator/c/src/address.h
>
==============================================================================
> --- pypy/dist/pypy/translator/c/src/address.h (original)
> +++ pypy/dist/pypy/translator/c/src/address.h Thu Jan 12 10:31:20 2006
> @@ -20,5 +20,9 @@
> r = (void*) malloc(size); \
> if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of
memory");\
>
> +#define OP_STACK_MALLOC(size,r,err) \
> + r = (void*) alloca(size); \
> + if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of
memory");\
> +
> #define OP_RAW_FREE(x,r,err) free(x);
> #define OP_RAW_MEMCOPY(x,y,size,r,err) memcpy(y,x,size);
>
> Modified: pypy/dist/pypy/translator/c/test/test_lladdresses.py
>
==============================================================================
> --- pypy/dist/pypy/translator/c/test/test_lladdresses.py (original)
> +++ pypy/dist/pypy/translator/c/test/test_lladdresses.py Thu Jan
> 12 10:31:20 2006
> @@ -88,7 +88,7 @@
> res = fc()
> assert res == int('011100' * 2, 2)
>
> -def test_flavored_malloc():
> +def test_flavored_malloc_raw():
> class A(object):
> _alloc_flavor_ = "raw"
> def __init__(self, val):
> @@ -100,3 +100,15 @@
> return result
> fn = compile(f, [int])
> assert fn(1) == 2
> +
> +def test_flavored_malloc_stack():
> + class A(object):
> + _alloc_flavor_ = "stack"
> + def __init__(self, val):
> + self.val = val
> + def f(x):
> + a = A(x + 1)
> + result = a.val
> + return result
> + fn = compile(f, [int])
> + assert fn(1) == 2
> _______________________________________________
> pypy-svn mailing list
> pypy-svn at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-svn
>
More information about the Pypy-dev
mailing list