[pypy-commit] extradoc extradoc: Add new topics
Author: Romain Guillebert Branch: extradoc Changeset: r5477:b636f7bce759 Date: 2014-12-04 14:18 +0530 http://bitbucket.org/pypy/extradoc/changeset/b636f7bce759/ Log:Add new topics diff --git a/talk/scipyindia2014/talk.rst b/talk/scipyindia2014/talk.rst --- a/talk/scipyindia2014/talk.rst +++ b/talk/scipyindia2014/talk.rst @@ -96,4 +96,15 @@ * ~80% of the numpy tests are passing -* XXX +* Most of numpy is there + +* XXX is missing + +NumPyPy performance +--- + +PyMetabiosis + + +JitPy +- ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: type definitions
Author: Armin Rigo Branch: Changeset: r146:910d0436c9ff Date: 2014-12-04 13:18 +0100 http://bitbucket.org/cffi/creflect/changeset/910d0436c9ff/ Log:type definitions diff --git a/zeffir/builder.c b/zeffir/builder.c --- a/zeffir/builder.c +++ b/zeffir/builder.c @@ -20,9 +20,6 @@ PyObject *result; char *p; -if (PyErr_Occurred()) -return NULL; - base_name_len = (ct != NULL ? strlen(ct->ct_name) : 0); extra_name_len = strlen(extra_text); result = PyString_FromStringAndSize(NULL, base_name_len + extra_name_len); @@ -72,6 +69,9 @@ static _crx_type_t *_zef_primitive(_crx_builder_t *cb, Py_ssize_t size, const char *name, int flags) { +if (PyErr_Occurred()) +return NULL; + PyObject *name_obj; CTypeDescrObject *ct; @@ -165,6 +165,9 @@ static _crx_type_t *zef_get_pointer_type(_crx_builder_t *cb, _crx_type_t *totype, int toquals) { +if (PyErr_Occurred()) +return NULL; + const char *extra; PyObject *name_obj; CTypeDescrObject *ct; @@ -205,6 +208,9 @@ static _crx_type_t *zef_get_array_type(_crx_builder_t *cb, _crx_type_t *ctitem, size_t len) { +if (PyErr_Occurred()) +return NULL; + CTypeDescrObject *ct; PyObject *name_obj; char extra_text[32]; @@ -304,7 +310,11 @@ static void zef_define_type(_crx_builder_t *cb, const char *name, _crx_type_t *type, int quals) { -abort(); +if (PyErr_Occurred()) +return; + +PyObject *types_dict = ((zeffir_builder_t *)cb)->types_dict; +PyDict_SetItemString(types_dict, name, (PyObject *)type); } static void zef_define_var(_crx_builder_t *cb, const char *name, @@ -317,6 +327,9 @@ _crx_type_t *ret, _crx_qual_type args[], int nargs, _crx_trampoline0_fn trampl, void *directcall) { +if (PyErr_Occurred()) +return; + PyObject *l_dict = ((zeffir_builder_t *)cb)->l_dict; PyObject *l_libname_obj = ((zeffir_builder_t *)cb)->lib->l_libname_obj; @@ -333,6 +346,9 @@ static void zef_define_num_const(_crx_builder_t *cb, const char *name, _crx_type_t *ct, _crx_num_const_t *value) { +if (PyErr_Occurred()) +return; + PyObject *l_dict = ((zeffir_builder_t *)cb)->l_dict; assert(ct->ct_flags & CT_PRIMITIVE_ANY); diff --git a/zeffir/test/ctype.crx b/zeffir/test/ctype.crx new file mode 100644 --- /dev/null +++ b/zeffir/test/ctype.crx @@ -0,0 +1,9 @@ +typedef long long foo_t; + + + +// CREFLECT: start + +typedef int foo_t; + +// CREFLECT: end diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py --- a/zeffir/test/test_ctype.py +++ b/zeffir/test/test_ctype.py @@ -65,3 +65,11 @@ assert repr(ffi.typeof("int [ ]")) == "" assert repr(ffi.typeof("int * [ ]")) == "" assert repr(ffi.typeof("int ( * ) [ ]")) == "" + +def test_simple_typedef(): +ffi, lib = support.compile_and_open('ctype') +assert ffi.sizeof("foo_t") == ffi.sizeof("long long") +if ffi.sizeof("long") == ffi.sizeof("long long"): +assert repr(ffi.typeof("foo_t")) == "" +else: +assert repr(ffi.typeof("foo_t")) == "" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: Finding the closest integer type matching the size: move that logic out
Author: Armin Rigo Branch: Changeset: r145:e7243eb19cf3 Date: 2014-12-04 13:15 +0100 http://bitbucket.org/cffi/creflect/changeset/e7243eb19cf3/ Log:Finding the closest integer type matching the size: move that logic out of creflect_debug_print.c, because it is generally useful diff --git a/creflect/creflect.h b/creflect/creflect.h --- a/creflect/creflect.h +++ b/creflect/creflect.h @@ -77,8 +77,16 @@ #undef _CRX_SELF -#define _CRX_INT_TYPE(cb, expr, guessname) \ -_crx_int_type(cb, expr > 0, sizeof(expr), expr == 1, guessname) +enum { +_crx_sc_char = 1, +_crx_sc_short = 2, +_crx_sc_int = 3, +_crx_sc_long = 4, +_crx_sc_long_long = 5, +}; + +#define _CRX_INT_TYPE(cb, expr, sizeclass) \ +_crx_int_type(cb, expr > 0, sizeof(expr), expr == 1, sizeclass) #define _CRX_INT_CONST(cb, expr, vp, pn) \ _crx_int_const(cb, vp, pn,\ @@ -102,14 +110,28 @@ __attribute__((unused)) static _crx_type_t *_crx_int_type(_crx_builder_t *cb, int expr_positive, size_t size_of_expr, int expr_equal_one, - const char *guessname) + int sizeclass) { +if (size_of_expr == 1 && expr_equal_one) +return cb->get_bool_type(cb); + +static size_t all_sizes[] = { 0, sizeof(char), sizeof(short), sizeof(int), + sizeof(long), sizeof(long long), (size_t)-1 }; +while (all_sizes[sizeclass] != size_of_expr) { +if (all_sizes[sizeclass] > size_of_expr) +sizeclass--; +else +sizeclass++; +} +if (sizeclass < 1) sizeclass = 1; +if (sizeclass > 5) sizeclass = 5; + +static const char *all_names[] = { NULL, "char", "short", "int", + "long", "long long" }; if (!expr_positive) -return cb->get_signed_type(cb, size_of_expr, guessname); -else if (size_of_expr == 1 && expr_equal_one) -return cb->get_bool_type(cb); +return cb->get_signed_type(cb, size_of_expr, all_names[sizeclass]); else -return cb->get_unsigned_type(cb, size_of_expr, guessname); +return cb->get_unsigned_type(cb, size_of_expr, all_names[sizeclass]); } __attribute__((unused)) diff --git a/creflect/creflect_debug_print.c b/creflect/creflect_debug_print.c --- a/creflect/creflect_debug_print.c +++ b/creflect/creflect_debug_print.c @@ -67,63 +67,52 @@ return newtype("_Bool"); } +static void badsize(const char *g, size_t sz) +{ +printf("type '%s' has incorrect size specification: %zd\n", g, sz); +abort(); +} + static _crx_type_t *tst_get_signed_type(_crx_builder_t *cb, size_t sz, const char *g) { -int skip = 0; -if (sizeof(long) == sizeof(long long)) -if (strcmp(g, "long long") == 0) -skip = 4; -if (sizeof(int) == sizeof(long)) -if (strcmp(g, "long") == 0 || strcmp(g, "long long") == 0) -skip = 3; +#define TT(in_name, out_name) \ +if (strcmp(g, #in_name) == 0) { \ +if (sz != sizeof(out_name)) badsize(g, sz); \ +return newtype(#out_name); \ +} -#define TT(name) if (--skip && sz == sizeof(name)) { return newtype(#name); } -TT(signed char); -TT(short); -TT(int); -TT(long); -TT(long long); +TT(char, signed char) +TT(short, short) +TT(int, int) +TT(long, long) +TT(long long, long long) -printf("cannot find signed type with %zd bytes\n", sz); +printf("cannot find signed type '%s'\n", g); abort(); } static _crx_type_t *tst_get_unsigned_type(_crx_builder_t *cb, size_t sz, const char *g) { -int skip = 0; -if (sizeof(long) == sizeof(long long)) -if (strcmp(g, "long long") == 0) -skip = 4; -if (sizeof(int) == sizeof(long)) -if (strcmp(g, "long") == 0 || strcmp(g, "long long") == 0) -skip = 3; +TT(char, unsigned char) +TT(short, unsigned short) +TT(int, unsigned int) +TT(long, unsigned long) +TT(long long, unsigned long long) -TT(unsigned char); -TT(unsigned short); -TT(unsigned int); -TT(unsigned long); -TT(unsigned long long); - -printf("cannot find unsigned type with %zd bytes\n", sz); +printf("cannot find unsigned type '%s'\n", g); abort(); } static _crx_type_t *tst_get_float_type(_crx_builder_t *cb, size_t sz, const char *g) { -int skip = 0; -if (sizeof(double) == sizeof(long double)) -if (strcmp(g, "long double") == 0) -skip = 2; +TT(float, float) +TT(double, double) +TT(long double, long double) -TT(float); -TT(double); -TT(long doubl
[pypy-commit] creflect default: clean-ups, small stuff
Author: Armin Rigo Branch: Changeset: r144:aab3d6122236 Date: 2014-12-04 12:15 +0100 http://bitbucket.org/cffi/creflect/changeset/aab3d6122236/ Log:clean-ups, small stuff diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -4,7 +4,6 @@ setup( ext_modules=[ Extension(name = 'zeffir', - sources=['zeffir/zeffir.c', - 'creflect/creflect_cdecl.c'], + sources=['zeffir/zeffir.c'] ) ]) diff --git a/zeffir/builder.c b/zeffir/builder.c --- a/zeffir/builder.c +++ b/zeffir/builder.c @@ -99,7 +99,7 @@ static _crx_type_t *zef_get_void_type(_crx_builder_t *cb) { -return _zef_primitive(cb, -1, "void", CT_VOID | CT_IS_OPAQUE); +return _zef_primitive(cb, -1, "void", CT_VOID); } static _crx_type_t *zef_get_char_type(_crx_builder_t *cb) @@ -285,7 +285,7 @@ static _crx_type_t *zef_get_unknown_type(_crx_builder_t *cb, const char *name) { -abort(); +return _zef_primitive(cb, -1, name, CT_UNKNOWN); } static void zef_complete(_crx_builder_t *cb, _crx_type_t *t, diff --git a/zeffir/ctype.c b/zeffir/ctype.c --- a/zeffir/ctype.c +++ b/zeffir/ctype.c @@ -8,13 +8,13 @@ #define CT_ARRAY 32/* array */ #define CT_STRUCT64/* struct */ #define CT_UNION128/* union */ -#define CT_FUNCTIONPTR 256/* pointer to function */ +#define CT_UNKNOWN 256/* unknown type */ #define CT_VOID 512/* void */ /* other flags that may also be set in addition to the base flag: */ #define CT_CAST_ANYTHING 1024/* 'char *' and 'void *' only */ #define CT_PRIMITIVE_FITS_LONG 2048 -#define CT_IS_OPAQUE 4096 +//#define CT_IS_OPAQUE 4096/* == (ct_size < 0) */ #define CT_IS_ENUM 8192 #define CT_IS_PTR_TO_OWNED 16384 #define CT_IS_LONGDOUBLE65536 diff --git a/zeffir/ffi_obj.c b/zeffir/ffi_obj.c --- a/zeffir/ffi_obj.c +++ b/zeffir/ffi_obj.c @@ -86,6 +86,8 @@ lib = lib_create(path); Py_DECREF(path); +if (lib == NULL) +return NULL; if (load_creflect_main(self, lib) < 0) { Py_DECREF(lib); @@ -108,22 +110,53 @@ return Py_None; } +static CTypeDescrObject *_ffi_type(ZefFFIObject *ffi, PyObject *arg) +{ +/* Returns the CTypeDescrObject from the user-supplied 'arg'. + Does not return a new reference! +*/ +if (PyString_Check(arg)) { +PyObject *x = PyDict_GetItem(ffi->types_dict, arg); +if (x != NULL && CTypeDescr_Check(x)) +return (CTypeDescrObject *)x; + +CTypeDescrObject *ct = parse_c_decl(ffi, PyString_AS_STRING(arg)); +if (ct == NULL) +return NULL; + +x = (PyObject *)ct; +if (PyDict_SetItem(ffi->types_dict, arg, x) < 0) +ct = NULL; +Py_DECREF(x); +return ct; +} +else if (CTypeDescr_Check(arg)) { +return (CTypeDescrObject *)arg; +} +else { +PyErr_SetString(PyExc_TypeError, "expected a string or a CType object"); +return NULL; +} +} + +static PyObject *ffi_sizeof(ZefFFIObject *self, PyObject *arg) +{ +CTypeDescrObject *ct = _ffi_type(self, arg); +if (ct == NULL) +return NULL; + +return PyInt_FromSsize_t(ct->ct_size); +} + static PyObject *ffi_typeof(ZefFFIObject *self, PyObject *arg) { if (!PyString_Check(arg)) { -PyErr_SetString(PyExc_TypeError, "XXX"); +PyErr_SetString(PyExc_TypeError, "expected a string"); return NULL; } -PyObject *x = PyDict_GetItem(self->types_dict, arg); -if (x != NULL) { -Py_INCREF(x); -return x; -} - -x = (PyObject *)parse_c_decl(self, PyString_AS_STRING(arg)); -if (x != NULL) -PyDict_SetItem(self->types_dict, arg, x); +PyObject *x = (PyObject *)_ffi_type(self, arg); +Py_XINCREF(x); return x; } @@ -131,6 +164,7 @@ {"close_library", ffi_close_library, METH_VARARGS | METH_STATIC}, {"load_library", (PyCFunction)ffi_load_library, METH_VARARGS | METH_KEYWORDS}, +{"sizeof",(PyCFunction)ffi_sizeof, METH_O}, {"typeof",(PyCFunction)ffi_typeof, METH_O}, {NULL} }; diff --git a/zeffir/test/function.crx b/zeffir/test/function.crx --- a/zeffir/test/function.crx +++ b/zeffir/test/function.crx @@ -1,11 +1,11 @@ +int simple_function(int x) +{ +return x + 1; +} + + // CREFLECT: start int simple_function(int); // CREFLECT: end - - -int simple_function(int x) -{ -return x + 1; -} diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py --- a/zeffir/test/test_ctype.py +++ b/zeffir/test/test_ctype.py @@ -10,6 +10,8 @@ def test_typeof_char(): ffi = support.new_ffi() assert repr(ffi.typeof("char")) == "" +assert ffi.sizeof("char") == 1 +assert ffi.sizeof(ffi.typeof("char")) == 1 def test_typeof_bool():
[pypy-commit] creflect default: a test
Author: Armin Rigo Branch: Changeset: r147:6b080d10e199 Date: 2014-12-04 13:22 +0100 http://bitbucket.org/cffi/creflect/changeset/6b080d10e199/ Log:a test diff --git a/creflect/test/codegen/003j.c b/creflect/test/codegen/003j.c new file mode 100644 --- /dev/null +++ b/creflect/test/codegen/003j.c @@ -0,0 +1,18 @@ +typedef _Bool num_t; + +# + +void test003j(_crx_builder_t *cb) +{ +_crx_type_t *t1; +{ +num_t *p1; +char b[sizeof(*p1)]; +p1 = (void *)b; +(void)(*p1 << 1); /* check that 'num_t' is an integer type */ +*p1 = -1; /* check that 'num_t' is not declared 'const' */ +t1 = _CRX_INT_TYPE(cb, *p1, _crx_sc_char); +cb->define_type(cb, "num_t", t1, 0); +#expect TYPEDEF num_t = _Bool +} +} ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: guess the float types, like we do the integer types
Author: Armin Rigo Branch: Changeset: r148:3471b7c2e683 Date: 2014-12-04 13:28 +0100 http://bitbucket.org/cffi/creflect/changeset/3471b7c2e683/ Log:guess the float types, like we do the integer types diff --git a/creflect/creflect.h b/creflect/creflect.h --- a/creflect/creflect.h +++ b/creflect/creflect.h @@ -83,13 +83,20 @@ _crx_sc_int = 3, _crx_sc_long = 4, _crx_sc_long_long = 5, + +_crx_sc_float = 1, +_crx_sc_double = 2, +_crx_sc_long_double = 3, }; #define _CRX_INT_TYPE(cb, expr, sizeclass) \ _crx_int_type(cb, expr > 0, sizeof(expr), expr == 1, sizeclass) -#define _CRX_INT_CONST(cb, expr, vp, pn) \ -_crx_int_const(cb, vp, pn,\ +#define _CRX_FLOAT_TYPE(cb, expr, sizeclass)\ +_crx_float_type(cb, sizeof(expr), sizeclass) + +#define _CRX_INT_CONST(cb, expr, vp, pn)\ +_crx_int_const(cb, vp, pn, \ "integer constant '" #expr "' is too large",\ !(((expr) * 0 + 4) << (sizeof(int)*8-2)), \ !(((expr) * 0L + 4L) << (sizeof(long)*8-2)),\ @@ -98,9 +105,9 @@ (expr) == (long long)(expr),\ (unsigned long long)(expr)) -#define _CRX_CHAR_CONST(cb, expr, vp)\ -_crx_char_const(cb, vp, \ -"char constant '" #expr "' is too large", \ +#define _CRX_CHAR_CONST(cb, expr, vp) \ +_crx_char_const(cb, vp, \ +"char constant '" #expr "' is too large", \ (expr) == (signed char)(expr) || (expr) == (unsigned char)(expr), \ (char)(expr)) @@ -135,6 +142,25 @@ } __attribute__((unused)) +static _crx_type_t *_crx_float_type(_crx_builder_t *cb, size_t size_of_expr, +int sizeclass) +{ +static size_t all_sizes[] = { 0, sizeof(float), sizeof(double), + sizeof(long double), (size_t)-1 }; +while (all_sizes[sizeclass] != size_of_expr) { +if (all_sizes[sizeclass] > size_of_expr) +sizeclass--; +else +sizeclass++; +} +if (sizeclass < 1) sizeclass = 1; +if (sizeclass > 3) sizeclass = 3; + +static const char *all_names[] = { NULL, "float", "double", "long double" }; +return cb->get_float_type(cb, size_of_expr, all_names[sizeclass]); +} + +__attribute__((unused)) static _crx_type_t *_crx_int_const(_crx_builder_t *cb, _crx_num_const_t *vp, int preference_number, const char *toobig, diff --git a/creflect/model.py b/creflect/model.py --- a/creflect/model.py +++ b/creflect/model.py @@ -186,8 +186,8 @@ block.writeline('cb->error(cb, "%s");' % (errmsg,)) block.writeline("return;") block.writeline("}") -expr = 'cb->get_float_type(cb, sizeof(%s), "%s")' % ( -star_p1, self.name) +hint = self.name.replace(' ', '_') +expr = '_CRX_FLOAT_TYPE(cb, %s, _crx_sc_%s)' % (star_p1, hint) else: raise AssertionError else: diff --git a/creflect/test/codegen/003g.c b/creflect/test/codegen/003g.c --- a/creflect/test/codegen/003g.c +++ b/creflect/test/codegen/003g.c @@ -16,7 +16,7 @@ cb->error(cb, "numeric type 'num_t' is an integer, not a float"); return; } -t1 = cb->get_float_type(cb, sizeof(*p1), "double"); +t1 = _CRX_FLOAT_TYPE(cb, *p1, _crx_sc_double); cb->define_type(cb, "num_t", t1, 0); #expect TYPEDEF num_t = double } diff --git a/creflect/test/codegen/003k.c b/creflect/test/codegen/003k.c new file mode 100644 --- /dev/null +++ b/creflect/test/codegen/003k.c @@ -0,0 +1,27 @@ +typedef double num_t; + +# + +#define num_t float + +# + +void test003k(_crx_builder_t *cb) +{ +_crx_type_t *t1; +{ +num_t *p1; +char b[sizeof(*p1)]; +memset(b, 0, sizeof(b)); +p1 = (void *)b; +(void)(*p1 / 2.0); /* check that 'num_t' is a numeric type */ +*p1 = -1; /* check that 'num_t' is not declared 'const' */ +if ((1 + *p1 * 0) / 2 == 0) { +cb->error(cb, "numeric type 'num_t' is an integer, not a float"); +return; +} +t1 = _CRX_FLOAT_TYPE(cb, *p1, _crx_sc_double); +cb->define_type(cb, "num_t", t1, 0); +#expect TYPEDEF num_t = float +} +} ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: add passing tests
Author: Armin Rigo Branch: Changeset: r149:bee544ef3a06 Date: 2014-12-04 13:31 +0100 http://bitbucket.org/cffi/creflect/changeset/bee544ef3a06/ Log:add passing tests diff --git a/zeffir/test/ctype.crx b/zeffir/test/ctype.crx --- a/zeffir/test/ctype.crx +++ b/zeffir/test/ctype.crx @@ -1,9 +1,14 @@ typedef long long foo_t; - +typedef char rfoo_t; +typedef long double bar_t; +typedef float rbar_t; // CREFLECT: start typedef int foo_t; +typedef long long rfoo_t; +typedef float bar_t; +typedef long double rbar_t; // CREFLECT: end diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py --- a/zeffir/test/test_ctype.py +++ b/zeffir/test/test_ctype.py @@ -73,3 +73,15 @@ assert repr(ffi.typeof("foo_t")) == "" else: assert repr(ffi.typeof("foo_t")) == "" +# +assert ffi.sizeof("rfoo_t") == ffi.sizeof("char") +assert repr(ffi.typeof("rfoo_t")) == "" +# +assert ffi.sizeof("bar_t") == ffi.sizeof("long double") +if ffi.sizeof("long double") == ffi.sizeof("double"): +assert repr(ffi.typeof("bar_t")) == "" +else: +assert repr(ffi.typeof("bar_t")) == "" +# +assert ffi.sizeof("rbar_t") == ffi.sizeof("float") +assert repr(ffi.typeof("rbar_t")) == "" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: unknown types
Author: Armin Rigo Branch: Changeset: r150:121223620cdd Date: 2014-12-04 16:08 +0100 http://bitbucket.org/cffi/creflect/changeset/121223620cdd/ Log:unknown types diff --git a/zeffir/ffi_obj.c b/zeffir/ffi_obj.c --- a/zeffir/ffi_obj.c +++ b/zeffir/ffi_obj.c @@ -134,7 +134,7 @@ return (CTypeDescrObject *)arg; } else { -PyErr_SetString(PyExc_TypeError, "expected a string or a CType object"); +PyErr_SetString(PyExc_TypeError, "expected a string or a ctype object"); return NULL; } } @@ -145,6 +145,11 @@ if (ct == NULL) return NULL; +if (ct->ct_size < 0) { +PyErr_Format(PyExc_ValueError, "don't know the size of ctype '%s': " + "incomplete type", ct->ct_name); +return NULL; +} return PyInt_FromSsize_t(ct->ct_size); } diff --git a/zeffir/test/ctype.crx b/zeffir/test/ctype.crx --- a/zeffir/test/ctype.crx +++ b/zeffir/test/ctype.crx @@ -11,4 +11,6 @@ typedef float bar_t; typedef long double rbar_t; +typedef ... unknown_t; + // CREFLECT: end diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py --- a/zeffir/test/test_ctype.py +++ b/zeffir/test/test_ctype.py @@ -1,3 +1,4 @@ +import py import support @@ -85,3 +86,8 @@ # assert ffi.sizeof("rbar_t") == ffi.sizeof("float") assert repr(ffi.typeof("rbar_t")) == "" + +def test_unknown_type(): +ffi, lib = support.compile_and_open('ctype') +assert repr(ffi.typeof("unknown_t")) == "" +py.test.raises(ValueError, ffi.sizeof, "unknown_t") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: progress
Author: Armin Rigo Branch: Changeset: r151:558efbc52db3 Date: 2014-12-04 17:49 +0100 http://bitbucket.org/cffi/creflect/changeset/558efbc52db3/ Log:progress diff --git a/zeffir/builder.c b/zeffir/builder.c --- a/zeffir/builder.c +++ b/zeffir/builder.c @@ -286,7 +286,20 @@ static _crx_qual_type zef_get_user_type(_crx_builder_t *cb, const char *name) { -abort(); +PyObject *name_obj; +_crx_qual_type result = { NULL, 0 }; + +if (PyErr_Occurred()) +return result; + +name_obj = combine_type_name(cb, NULL, name); +if (name_obj == NULL) +return result; + +result.type = get_cached_type(cb, name_obj); +if (result.type == NULL) +PyErr_Format(ZefError, "undefined type: '%s'", name); +return result; } static _crx_type_t *zef_get_unknown_type(_crx_builder_t *cb, const char *name) @@ -363,7 +376,8 @@ static void zef_error(_crx_builder_t *cb, const char *msg) { -abort(); +if (!PyErr_Occurred()) +PyErr_SetString(ZefError, msg); } static int load_creflect_main(ZefFFIObject *ffi, ZefLibObject *lib) @@ -463,6 +477,25 @@ _crx_qual_type result; const char *err = creflect_decl_parser(&builder.cb, str, &result); +if (PyErr_Occurred()) { +if (PyErr_ExceptionMatches(ZefError)) { +PyObject *exc, *val, *tb, *ps; +PyErr_Fetch(&exc, &val, &tb); +ps = PyObject_Str(val); +if (ps != NULL && PyString_Check(ps)) { +PyErr_Format(exc, "at pos %zd: %s", + (size_t)(err - str), PyString_AS_STRING(ps)); +Py_XDECREF(tb); +Py_XDECREF(val); +Py_XDECREF(exc); +} +else { +PyErr_Restore(exc, val, tb); +} +Py_XDECREF(ps); +} +return NULL; +} if (err != NULL) abort(); diff --git a/zeffir/ffi_obj.c b/zeffir/ffi_obj.c --- a/zeffir/ffi_obj.c +++ b/zeffir/ffi_obj.c @@ -146,7 +146,7 @@ return NULL; if (ct->ct_size < 0) { -PyErr_Format(PyExc_ValueError, "don't know the size of ctype '%s': " +PyErr_Format(ZefError, "don't know the size of ctype '%s': " "incomplete type", ct->ct_name); return NULL; } diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py --- a/zeffir/test/test_ctype.py +++ b/zeffir/test/test_ctype.py @@ -90,4 +90,15 @@ def test_unknown_type(): ffi, lib = support.compile_and_open('ctype') assert repr(ffi.typeof("unknown_t")) == "" -py.test.raises(ValueError, ffi.sizeof, "unknown_t") +py.test.raises(ffi.error, ffi.sizeof, "unknown_t") +py.test.raises(ffi.error, ffi.sizeof, " unknown_t ") +assert ffi.sizeof("unknown_t*") == ffi.sizeof("void *") + +def test_undefined_type(): +ffi = support.new_ffi() +py.test.raises(ffi.error, ffi.typeof, "abcdef_missing_t") + +def test_parse_error(): +ffi = support.new_ffi() +e = py.test.raises(ffi.error, ffi.typeof, "int int") +assert str(e.value) == "at pos 4: unexpected symbol" diff --git a/zeffir/zeffir.c b/zeffir/zeffir.c --- a/zeffir/zeffir.c +++ b/zeffir/zeffir.c @@ -53,4 +53,7 @@ Py_INCREF(ZefError); if (PyModule_AddObject(m, "error", ZefError) < 0) return; + +if (PyDict_SetItemString(ZefFFI_Type.tp_dict, "error", ZefError) < 0) +return; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: enable sum/prod test_zjits
Author: Brian Kearns Branch: Changeset: r74813:624d6b4b60ce Date: 2014-12-04 12:31 -0500 http://bitbucket.org/pypy/pypy/changeset/624d6b4b60ce/ Log:enable sum/prod test_zjits diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -166,17 +166,22 @@ def define_sum(): return """ a = |30| -b = a + a -sum(b) +sum(a) """ def test_sum(self): result = self.run("sum") -assert result == 2 * sum(range(30)) -py.test.skip("don't run for now") -self.check_simple_loop({"raw_load": 2, "float_add": 2, -"int_add": 1, "int_ge": 1, "guard_false": 1, -"jump": 1, 'arraylen_gc': 1}) +assert result == sum(range(30)) +self.check_trace_count(1) +self.check_simple_loop({ +'float_add': 1, +'guard_false': 1, +'guard_not_invalidated': 1, +'int_add': 2, +'int_ge': 1, +'jump': 1, +'raw_load': 1, +}) def define_axissum(): return """ @@ -260,8 +265,7 @@ def define_prod(): return """ a = |30| -b = a + a -prod(b) +prod(a) """ def test_prod(self): @@ -270,11 +274,16 @@ for i in range(30): expected *= i * 2 assert result == expected -py.test.skip("don't run for now") -self.check_simple_loop({"raw_load": 2, "float_add": 1, -"float_mul": 1, "int_add": 1, -"int_ge": 1, "guard_false": 1, "jump": 1, -'arraylen_gc': 1}) +self.check_trace_count(1) +self.check_simple_loop({ +'float_mul': 1, +'guard_false': 1, +'guard_not_invalidated': 1, +'int_add': 2, +'int_ge': 1, +'jump': 1, +'raw_load': 1, +}) def define_max(): return """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: enable axissum test_zjit
Author: Brian Kearns Branch: Changeset: r74811:39760476cedc Date: 2014-12-04 12:16 -0500 http://bitbucket.org/pypy/pypy/changeset/39760476cedc/ Log:enable axissum test_zjit diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -188,18 +188,48 @@ def test_axissum(self): result = self.run("axissum") assert result == 30 -py.test.skip("don't run for now") # XXX note - the bridge here is fairly crucial and yet it's pretty #bogus. We need to improve the situation somehow. -self.check_simple_loop({'raw_load': 2, -'raw_store': 1, -'arraylen_gc': 2, -'guard_true': 1, -'int_lt': 1, -'jump': 1, -'float_add': 1, -'int_add': 3, -}) +self.check_trace_count(2) +self.check_simple_loop({ +'float_add': 1, +'getarrayitem_gc': 2, +'guard_false': 2, +'guard_not_invalidated': 1, +'guard_true': 1, +'int_add': 5, +'int_ge': 1, +'int_is_zero': 1, +'int_lt': 1, +'jump': 1, +'raw_load': 2, +'raw_store': 1, +'setarrayitem_gc': 1, +}) +self.check_resops({ +'float_add': 2, +'getarrayitem_gc': 5, +'getarrayitem_gc_pure': 7, +'getfield_gc_pure': 56, +'guard_class': 3, +'guard_false': 11, +'guard_nonnull': 8, +'guard_nonnull_class': 3, +'guard_not_invalidated': 2, +'guard_true': 12, +'guard_value': 4, +'int_add': 17, +'int_ge': 4, +'int_is_true': 4, +'int_is_zero': 4, +'int_le': 2, +'int_lt': 3, +'int_sub': 1, +'jump': 2, +'raw_load': 4, +'raw_store': 2, +'setarrayitem_gc': 4, +}) def define_reduce(): return """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: enable min/max in test_zjit
Author: Brian Kearns Branch: Changeset: r74814:ac1f001ff1c0 Date: 2014-12-04 13:13 -0500 http://bitbucket.org/pypy/pypy/changeset/ac1f001ff1c0/ Log:enable min/max in test_zjit diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -289,30 +289,62 @@ return """ a = |30| a[13] = 128 -b = a + a -max(b) +max(a) """ def test_max(self): result = self.run("max") -assert result == 256 -py.test.skip("not there yet, getting though") -self.check_simple_loop({"raw_load": 2, "float_add": 1, -"float_mul": 1, "int_add": 1, -"int_lt": 1, "guard_true": 1, "jump": 1}) +assert result == 128 +self.check_trace_count(3) +self.check_simple_loop({ +'float_ge': 1, +'float_ne': 1, +'guard_false': 3, +'guard_not_invalidated': 1, +'int_add': 2, +'int_ge': 1, +'jump': 1, +'raw_load': 1, +}) +self.check_resops({ +'float_ge': 2, +'float_ne': 2, +'getfield_gc_pure': 34, +'guard_class': 1, +'guard_false': 8, +'guard_nonnull': 2, +'guard_nonnull_class': 2, +'guard_not_invalidated': 2, +'guard_true': 7, +'guard_value': 2, +'int_add': 8, +'int_ge': 4, +'int_is_true': 3, +'jump': 3, +'raw_load': 2, +}) + +def define_min(): +return """ +a = |30| +a[13] = -128 +min(a) +""" def test_min(self): -py.test.skip("broken, investigate") -result = self.run(""" -a = |30| -a[15] = -12 -b = a + a -min(b) -""") -assert result == -24 -self.check_simple_loop({"raw_load": 2, "float_add": 1, -"float_mul": 1, "int_add": 1, -"int_lt": 1, "guard_true": 1, "jump": 1}) +result = self.run("min") +assert result == -128 +self.check_trace_count(1) +self.check_simple_loop({ +'float_le': 1, +'guard_false': 1, +'guard_not_invalidated': 1, +'guard_true': 1, +'int_add': 2, +'int_ge': 1, +'jump': 1, +'raw_load': 1, +}) def define_any(): return """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: avoid tracking an iterator index in axis_reduce
Author: Brian Kearns Branch: Changeset: r74812:e9c67f6fba33 Date: 2014-12-04 12:23 -0500 http://bitbucket.org/pypy/pypy/changeset/e9c67f6fba33/ Log:avoid tracking an iterator index in axis_reduce diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py --- a/pypy/module/micronumpy/loop.py +++ b/pypy/module/micronumpy/loop.py @@ -239,10 +239,9 @@ state = x_state return out -axis_reduce__driver = jit.JitDriver(name='numpy_axis_reduce', -greens=['shapelen', -'func', 'dtype'], -reds='auto') +axis_reduce_driver = jit.JitDriver(name='numpy_axis_reduce', + greens=['shapelen', 'func', 'dtype'], + reds='auto') def do_axis_reduce(space, shape, func, arr, dtype, axis, out, identity, cumulative, temp): @@ -255,14 +254,16 @@ temp_iter = out_iter # hack temp_state = out_state arr_iter, arr_state = arr.create_iter() +arr_iter.track_index = False if identity is not None: identity = identity.convert_to(space, dtype) shapelen = len(shape) while not out_iter.done(out_state): -axis_reduce__driver.jit_merge_point(shapelen=shapelen, func=func, -dtype=dtype) -assert not arr_iter.done(arr_state) +axis_reduce_driver.jit_merge_point(shapelen=shapelen, func=func, + dtype=dtype) w_val = arr_iter.getitem(arr_state).convert_to(space, dtype) +arr_state = arr_iter.next(arr_state) + out_indices = out_iter.indices(out_state) if out_indices[axis] == 0: if identity is not None: @@ -270,6 +271,7 @@ else: cur = temp_iter.getitem(temp_state) w_val = func(dtype, cur, w_val) + out_iter.setitem(out_state, w_val) out_state = out_iter.next(out_state) if cumulative: @@ -277,7 +279,6 @@ temp_state = temp_iter.next(temp_state) else: temp_state = out_state -arr_state = arr_iter.next(arr_state) return out diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -197,7 +197,7 @@ 'guard_false': 2, 'guard_not_invalidated': 1, 'guard_true': 1, -'int_add': 5, +'int_add': 4, 'int_ge': 1, 'int_is_zero': 1, 'int_lt': 1, @@ -212,13 +212,13 @@ 'getarrayitem_gc_pure': 7, 'getfield_gc_pure': 56, 'guard_class': 3, -'guard_false': 11, -'guard_nonnull': 8, +'guard_false': 12, +'guard_nonnull': 11, 'guard_nonnull_class': 3, 'guard_not_invalidated': 2, -'guard_true': 12, -'guard_value': 4, -'int_add': 17, +'guard_true': 10, +'guard_value': 5, +'int_add': 13, 'int_ge': 4, 'int_is_true': 4, 'int_is_zero': 4, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi podshumok/add-source_extnsion-param-to-verifier-1417477338819: add source_extnsion param to Verifier
Author: podshumok Branch: podshumok/add-source_extnsion-param-to-verifier-1417477338819 Changeset: r1583:d82365905c32 Date: 2014-12-01 23:42 + http://bitbucket.org/cffi/cffi/changeset/d82365905c32/ Log:add source_extnsion param to Verifier diff --git a/cffi/verifier.py b/cffi/verifier.py --- a/cffi/verifier.py +++ b/cffi/verifier.py @@ -16,7 +16,8 @@ class Verifier(object): def __init__(self, ffi, preamble, tmpdir=None, modulename=None, - ext_package=None, tag='', force_generic_engine=False, **kwds): + ext_package=None, tag='', force_generic_engine=False, + source_extension='.c', **kwds): self.ffi = ffi self.preamble = preamble if not modulename: @@ -43,7 +44,7 @@ k1, k2) suffix = _get_so_suffixes()[0] self.tmpdir = tmpdir or os.environ.get('CFFI_TMPDIR') or _caller_dir_pycache() -self.sourcefilename = os.path.join(self.tmpdir, modulename + '.c') +self.sourcefilename = os.path.join(self.tmpdir, modulename + source_extension) self.modulefilename = os.path.join(self.tmpdir, modulename + suffix) self.ext_package = ext_package self._has_source = False ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: Merged in podshumok/cffi/podshumok/add-source_extnsion-param-to-verifier-1417477338819 (pull request #54)
Author: Armin Rigo Branch: Changeset: r1584:c5c87b3b1c00 Date: 2014-12-04 19:22 +0100 http://bitbucket.org/cffi/cffi/changeset/c5c87b3b1c00/ Log:Merged in podshumok/cffi/podshumok/add-source_extnsion-param-to- verifier-1417477338819 (pull request #54) add source_extnsion param to Verifier diff --git a/cffi/verifier.py b/cffi/verifier.py --- a/cffi/verifier.py +++ b/cffi/verifier.py @@ -16,7 +16,8 @@ class Verifier(object): def __init__(self, ffi, preamble, tmpdir=None, modulename=None, - ext_package=None, tag='', force_generic_engine=False, **kwds): + ext_package=None, tag='', force_generic_engine=False, + source_extension='.c', **kwds): self.ffi = ffi self.preamble = preamble if not modulename: @@ -43,7 +44,7 @@ k1, k2) suffix = _get_so_suffixes()[0] self.tmpdir = tmpdir or os.environ.get('CFFI_TMPDIR') or _caller_dir_pycache() -self.sourcefilename = os.path.join(self.tmpdir, modulename + '.c') +self.sourcefilename = os.path.join(self.tmpdir, modulename + source_extension) self.modulefilename = os.path.join(self.tmpdir, modulename + suffix) self.ext_package = ext_package self._has_source = False ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: Document c5c87b3b1c00
Author: Armin Rigo Branch: Changeset: r1585:2b86c5dc1331 Date: 2014-12-04 19:27 +0100 http://bitbucket.org/cffi/cffi/changeset/2b86c5dc1331/ Log:Document c5c87b3b1c00 diff --git a/doc/source/index.rst b/doc/source/index.rst --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -667,6 +667,15 @@ check. Be sure to have other means of clearing the ``tmpdir`` whenever you change your sources. +.. versionadded:: 0.8.7 + You can give C++ source code in ``ffi.verify()``:: + + ext = ffi.verify(r''' + extern "C" { + int somefunc(int somearg) { return real_cpp_func(somearg); } + } + ''', source_extension='.cpp', extra_compile_args=['-std=c++11']) + This function returns a "library" object that gets closed when it goes out of scope. Make sure you keep the library object around as long as needed. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: add test_pypy_c for flatiter next
Author: Brian Kearns Branch: Changeset: r74815:d62d6a8c4809 Date: 2014-12-04 15:00 -0500 http://bitbucket.org/pypy/pypy/changeset/d62d6a8c4809/ Log:add test_pypy_c for flatiter next diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -78,6 +78,46 @@ jump(p0, p1, p3, p6, p7, p12, p14, f86, p18, i87, i62, p41, i58, p47, i40, i64, i70, descr=...) """) +def test_array_flatiter_next(self): +def main(): +import _numpypy.multiarray as np +arr = np.zeros((1024, 16)) + 42 +ai = arr.flat +i = 0 +while i < arr.size: +a = next(ai) +i += 1 +return a +log = self.run(main, []) +assert log.result == 42.0 +loop, = log.loops_by_filename(self.filepath) +assert loop.match(""" +i86 = int_lt(i79, i45) +guard_true(i86, descr=...) +guard_not_invalidated(descr=...) +i87 = getfield_gc_pure(p85, descr=) +i88 = int_ge(i87, i59) +guard_false(i88, descr=...) +i89 = getfield_gc_pure(p85, descr=) +f90 = raw_load(i67, i89, descr=) +i91 = int_add(i87, 1) +p92 = getfield_gc_pure(p85, descr=) +i93 = int_add(i89, i76) +i94 = int_add(i79, 1) +i95 = getfield_raw(#, descr=) +i96 = int_lt(i95, 0) +guard_false(i96, descr=...) +p97 = new_with_vtable(#) +{{{ +setfield_gc(p97, p56, descr=) +setfield_gc(p97, p92, descr=) +setfield_gc(p97, i91, descr=) +setfield_gc(p97, i93, descr=) +setfield_gc(p16, p97, descr=) +}}} +jump(p0, p1, p3, p6, p12, p14, p16, i94, f90, p26, i45, p97, i59, p56, i67, i76, descr=...) +""") + def test_array_flatiter_getitem_single(self): def main(): import _numpypy.multiarray as np ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: use mutating iterator state in flatiter
Author: Brian Kearns Branch: Changeset: r74817:cdcc29b5a5eb Date: 2014-12-04 15:00 -0500 http://bitbucket.org/pypy/pypy/changeset/cdcc29b5a5eb/ Log:use mutating iterator state in flatiter diff --git a/pypy/module/micronumpy/flatiter.py b/pypy/module/micronumpy/flatiter.py --- a/pypy/module/micronumpy/flatiter.py +++ b/pypy/module/micronumpy/flatiter.py @@ -57,7 +57,7 @@ if self.iter.done(self.state): raise OperationError(space.w_StopIteration, space.w_None) w_res = self.iter.getitem(self.state) -self.state = self.iter.next(self.state) +self.iter.next(self.state, mutate=True) return w_res def descr_getitem(self, space, w_idx): @@ -74,7 +74,7 @@ base.get_order(), w_instance=base) return loop.flatiter_getitem(res, self.iter, state, step) finally: -self.state = self.iter.reset(self.state) +self.iter.reset(self.state, mutate=True) def descr_setitem(self, space, w_idx, w_value): if not (space.isinstance_w(w_idx, space.w_int) or @@ -94,7 +94,7 @@ arr = convert_to_array(space, w_value) loop.flatiter_setitem(space, dtype, arr, self.iter, state, step, length) finally: -self.state = self.iter.reset(self.state) +self.iter.reset(self.state, mutate=True) W_FlatIterator.typedef = TypeDef("numpy.flatiter", diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -95,27 +95,18 @@ i86 = int_lt(i79, i45) guard_true(i86, descr=...) guard_not_invalidated(descr=...) -i87 = getfield_gc_pure(p85, descr=) i88 = int_ge(i87, i59) guard_false(i88, descr=...) -i89 = getfield_gc_pure(p85, descr=) f90 = raw_load(i67, i89, descr=) i91 = int_add(i87, 1) -p92 = getfield_gc_pure(p85, descr=) i93 = int_add(i89, i76) i94 = int_add(i79, 1) i95 = getfield_raw(#, descr=) +setfield_gc(p97, i91, descr=) +setfield_gc(p97, i93, descr=) i96 = int_lt(i95, 0) guard_false(i96, descr=...) -p97 = new_with_vtable(#) -{{{ -setfield_gc(p97, p56, descr=) -setfield_gc(p97, p92, descr=) -setfield_gc(p97, i91, descr=) -setfield_gc(p97, i93, descr=) -setfield_gc(p16, p97, descr=) -}}} -jump(p0, p1, p3, p6, p12, p14, p16, i94, f90, p26, i45, p97, i59, p56, i67, i76, descr=...) +jump(p0, p1, p3, p6, p12, p14, p16, i94, f90, p26, i45, i91, i59, p97, p96, i67, i93, i76, descr=...) """) def test_array_flatiter_getitem_single(self): @@ -139,23 +130,15 @@ i128 = int_mul(i117, i59) i129 = int_add(i55, i128) f149 = raw_load(i100, i129, descr=) -p150 = getfield_gc_pure(p123, descr=) i151 = int_add(i117, 1) setarrayitem_gc(p150, 1, 0, descr=) setarrayitem_gc(p150, 0, 0, descr=) +setfield_gc(p156, i55, descr=) guard_not_invalidated(descr=...) i154 = getfield_raw(#, descr=) i155 = int_lt(i154, 0) guard_false(i155, descr=...) -p156 = new_with_vtable(...) -{{{ -setfield_gc(p156, p49, descr=) -setfield_gc(p156, i55, descr=) -setfield_gc(p156, 0, descr=) -setfield_gc(p156, p150, descr=) -setfield_gc(p16, p156, descr=) -}}} -jump(p0, p1, p3, p6, p7, p12, p14, p16, i151, f149, p26, i44, i50, i59, i55, i100, p156, p49, descr=...) +jump(p0, p1, p3, p6, p7, p12, p14, p16, i151, f149, p26, i44, i50, i59, i55, i100, p150, p156, descr=...) """) def test_array_flatiter_setitem_single(self): @@ -180,20 +163,12 @@ i132 = int_add(i53, i131) guard_not_invalidated(descr=...) raw_store(i103, i132, 42.00, descr=) -p152 = getfield_gc_pure(p126, descr=) i153 = int_add(i120, 1) i154 = getfield_raw(#, descr=) setarrayitem_gc(p152, 1, 0, descr=) setarrayitem_gc(p152, 0, 0, descr=) +setfield_gc(p158, i53, descr=) i157 = int_lt(i154, 0) guard_false(i157, descr=...) -p158 = new_with_vtable(...) -{{{ -setfield_gc(p158, p47, descr=) -setfield_gc(p158, i53, descr=) -setfield_gc(p158, 0, descr=) -setfield_gc(p158, p152, descr=) -setfield_gc(p16, p158, descr=) -}}} -jump(p0, p1, p3, p6, p7, p12, p14, p16, i153, i42,
[pypy-commit] pypy default: support mutate flag to iterator next/reset
Author: Brian Kearns Branch: Changeset: r74816:e920a686f245 Date: 2014-12-04 14:32 -0500 http://bitbucket.org/pypy/pypy/changeset/e920a686f245/ Log:support mutate flag to iterator next/reset diff --git a/pypy/module/micronumpy/iterators.py b/pypy/module/micronumpy/iterators.py --- a/pypy/module/micronumpy/iterators.py +++ b/pypy/module/micronumpy/iterators.py @@ -77,7 +77,7 @@ class IterState(object): -_immutable_fields_ = ['iterator', 'index', '_indices', 'offset'] +_immutable_fields_ = ['iterator', '_indices'] def __init__(self, iterator, index, indices, offset): self.iterator = iterator @@ -117,7 +117,8 @@ self.factors = factors @jit.unroll_safe -def reset(self, state=None): +def reset(self, state=None, mutate=False): +index = 0 if state is None: indices = [0] * len(self.shape_m1) else: @@ -125,10 +126,14 @@ indices = state._indices for i in xrange(self.ndim_m1, -1, -1): indices[i] = 0 -return IterState(self, 0, indices, self.array.start) +offset = self.array.start +if not mutate: +return IterState(self, index, indices, offset) +state.index = index +state.offset = offset @jit.unroll_safe -def next(self, state): +def next(self, state, mutate=False): assert state.iterator is self index = state.index if self.track_index: @@ -149,7 +154,10 @@ else: indices[i] = 0 offset -= self.backstrides[i] -return IterState(self, index, indices, offset) +if not mutate: +return IterState(self, index, indices, offset) +state.index = index +state.offset = offset @jit.unroll_safe def goto(self, index): diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -215,7 +215,8 @@ 'float_add': 2, 'getarrayitem_gc': 5, 'getarrayitem_gc_pure': 7, -'getfield_gc_pure': 56, +'getfield_gc': 5, +'getfield_gc_pure': 51, 'guard_class': 3, 'guard_false': 12, 'guard_nonnull': 11, @@ -309,7 +310,8 @@ self.check_resops({ 'float_ge': 2, 'float_ne': 2, -'getfield_gc_pure': 34, +'getfield_gc': 4, +'getfield_gc_pure': 30, 'guard_class': 1, 'guard_false': 8, 'guard_nonnull': 2, @@ -561,7 +563,8 @@ 'float_add': 3, 'getarrayitem_gc': 7, 'getarrayitem_gc_pure': 14, -'getfield_gc_pure': 69, +'getfield_gc': 6, +'getfield_gc_pure': 63, 'guard_class': 5, 'guard_false': 20, 'guard_nonnull': 6, @@ -612,7 +615,8 @@ 'float_add': 2, 'getarrayitem_gc': 2, 'getarrayitem_gc_pure': 2, -'getfield_gc_pure': 36, +'getfield_gc': 6, +'getfield_gc_pure': 30, 'guard_class': 3, 'guard_false': 7, 'guard_nonnull': 2, @@ -769,7 +773,8 @@ 'float_mul': 2, 'getarrayitem_gc': 4, 'getarrayitem_gc_pure': 9, -'getfield_gc_pure': 49, +'getfield_gc': 7, +'getfield_gc_pure': 42, 'guard_class': 4, 'guard_false': 15, 'guard_not_invalidated': 2, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: function types
Author: Armin Rigo Branch: Changeset: r153:bfdb3cb4b9b4 Date: 2014-12-04 22:45 +0100 http://bitbucket.org/cffi/creflect/changeset/bfdb3cb4b9b4/ Log:function types diff --git a/zeffir/builder.c b/zeffir/builder.c --- a/zeffir/builder.c +++ b/zeffir/builder.c @@ -10,32 +10,38 @@ PyObject *types_dict; } zeffir_builder_t; -static PyObject *combine_type_name(_crx_builder_t *cb, CTypeDescrObject *ct, - const char *extra_text) +static PyObject *combine_type_name_l(CTypeDescrObject *ct, + size_t extra_text_len) { -/* Build a PyString with the name given by combining 'ct' and 'extra_text'. - 'ct' can be NULL. If an error occurs (or has already occurred), - returns NULL. */ -size_t base_name_len, extra_name_len; +size_t base_name_len; PyObject *result; char *p; -base_name_len = (ct != NULL ? strlen(ct->ct_name) : 0); -extra_name_len = strlen(extra_text); -result = PyString_FromStringAndSize(NULL, base_name_len + extra_name_len); +base_name_len = strlen(ct->ct_name); +result = PyString_FromStringAndSize(NULL, base_name_len + extra_text_len); if (result == NULL) return NULL; p = PyString_AS_STRING(result); -if (ct != NULL) { -memcpy(p, ct->ct_name, ct->ct_name_position); +memcpy(p, ct->ct_name, ct->ct_name_position); +p += ct->ct_name_position; +p += extra_text_len; +memcpy(p, ct->ct_name + ct->ct_name_position, + base_name_len - ct->ct_name_position); +return result; +} + +static PyObject *combine_type_name(CTypeDescrObject *ct, const char *extra_text) +{ +/* Build a PyString with the name given by combining 'ct' and 'extra_text'. + 'ct' can be NULL. If an error occurs returns NULL. */ +size_t extra_text_len = strlen(extra_text); +PyObject *result = combine_type_name_l(ct, extra_text_len); + +if (result != NULL) { +char *p = PyString_AS_STRING(result); p += ct->ct_name_position; -} -memcpy(p, extra_text, extra_name_len); -if (ct != NULL) { -p += extra_name_len; -memcpy(p, ct->ct_name + ct->ct_name_position, - base_name_len - ct->ct_name_position); +memcpy(p, extra_text, extra_text_len); } return result; } @@ -75,7 +81,7 @@ PyObject *name_obj; CTypeDescrObject *ct; -name_obj = combine_type_name(cb, NULL, name); +name_obj = PyString_FromString(name); if (name_obj == NULL) return NULL; @@ -151,7 +157,63 @@ _crx_qual_type args[], int nargs, _crx_trampoline1_fn trampl) { -abort(); +if (PyErr_Occurred()) +return NULL; + +PyObject *name_obj; +CTypeDescrObject *ct; +size_t extra_len; + +if (nargs == 0) { +name_obj = combine_type_name(ret, "(void)"); +if (name_obj == NULL) +return NULL; +} +else { +char *p; +int i; +extra_len = 1 + 1; /* "(" ")" */ +extra_len += (nargs - 1) * 2; /* ", " */ +for (i = 0; i < nargs; i++) { +extra_len += strlen(args[i].type->ct_name); +} +name_obj = combine_type_name_l(ret, extra_len); +if (name_obj == NULL) +return NULL; +p = PyString_AS_STRING(name_obj); +p += ret->ct_name_position; +*p++ = '('; +for (i = 0; i < nargs; i++) { +size_t len = strlen(args[i].type->ct_name); +if (i > 0) { +*p++ = ','; +*p++ = ' '; +} +memcpy(p, args[i].type->ct_name, len); +p += len; +} +*p++ = ')'; +assert(p - PyString_AS_STRING(name_obj) - ret->ct_name_position + == extra_len); +} + +ct = get_cached_type(cb, name_obj); +if (ct && (ct->ct_flags == CT_FUNCTION)) +goto done; + +ct = ctypedescr_new(name_obj, ret->ct_name_position); +if (ct == NULL) +goto done; + +ct->ct_size = -1; +ct->ct_flags = CT_FUNCTION; +/* XXX more... */ + +put_cached_type(cb, name_obj, ct); + + done: +Py_DECREF(name_obj); +return ct; } static _crx_type_t *zef_get_ellipsis_function_type(_crx_builder_t *cb, @@ -172,12 +234,12 @@ PyObject *name_obj; CTypeDescrObject *ct; -if (totype->ct_flags & CT_ARRAY) +if (totype->ct_flags & (CT_ARRAY | CT_FUNCTION)) extra = "(*)"; else extra = " *"; -name_obj = combine_type_name(cb, totype, extra); +name_obj = combine_type_name(totype, extra); if (name_obj == NULL) return NULL; @@ -228,7 +290,7 @@ else sprintf(extra_text, "[%zd]", length); -name_obj = combine_type_name(cb, ctitem, extra_text); +name_obj = combine_type_name(ctitem, extra_text); if (name_obj == NULL) return NULL; @@ -292,7 +354,7 @@
[pypy-commit] creflect default: Accept (and ignore) variable names after "long" (they were already
Author: Armin Rigo Branch: Changeset: r152:f9f839119f6e Date: 2014-12-04 22:42 +0100 http://bitbucket.org/cffi/creflect/changeset/f9f839119f6e/ Log:Accept (and ignore) variable names after "long" (they were already accepted after "int") diff --git a/creflect/creflect_cdecl.c b/creflect/creflect_cdecl.c --- a/creflect/creflect_cdecl.c +++ b/creflect/creflect_cdecl.c @@ -444,7 +444,6 @@ case TOK_VOID: case TOK__BOOL: case TOK_FLOAT: -case TOK_IDENTIFIER: case TOK_STRUCT: case TOK_UNION: parse_error(tok, "invalid combination of types"); diff --git a/creflect/test/test_c_decl_parser.py b/creflect/test/test_c_decl_parser.py --- a/creflect/test/test_c_decl_parser.py +++ b/creflect/test/test_c_decl_parser.py @@ -43,6 +43,8 @@ parse("unsigned int", "unsigned int") parse("long", "long") parse("long int", "long") +parse("long int a", "long") +parse("long a", "long") parse("short int", "short") parse("long long int", "long long") parse("unsigned long long *", "PTR unsigned long long") @@ -82,7 +84,7 @@ parse_error("long char", "invalid combination of types", 5) parse_error("short char", "invalid combination of types", 6) parse_error("signed void", "invalid combination of types", 7) -parse_error("unsigned foobar_t", "invalid combination of types", 9) +parse_error("unsigned struct", "invalid combination of types", 9) # parse_error("", "identifier expected", 0) parse_error("]", "identifier expected", 0) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: functions with '...'
Author: Armin Rigo Branch: Changeset: r154:47c327664396 Date: 2014-12-04 22:49 +0100 http://bitbucket.org/cffi/creflect/changeset/47c327664396/ Log:functions with '...' diff --git a/zeffir/builder.c b/zeffir/builder.c --- a/zeffir/builder.c +++ b/zeffir/builder.c @@ -153,9 +153,9 @@ return _zef_primitive(cb, sz, name, flags); } -static _crx_type_t *zef_get_function_type(_crx_builder_t *cb, _crx_type_t *ret, - _crx_qual_type args[], int nargs, - _crx_trampoline1_fn trampl) +static _crx_type_t *_zef_function(_crx_builder_t *cb, _crx_type_t *ret, + _crx_qual_type args[], int nargs, + int dotdotdot) { if (PyErr_Occurred()) return NULL; @@ -163,8 +163,9 @@ PyObject *name_obj; CTypeDescrObject *ct; size_t extra_len; +int nargsall = nargs + dotdotdot; -if (nargs == 0) { +if (nargsall == 0) { name_obj = combine_type_name(ret, "(void)"); if (name_obj == NULL) return NULL; @@ -173,10 +174,12 @@ char *p; int i; extra_len = 1 + 1; /* "(" ")" */ -extra_len += (nargs - 1) * 2; /* ", " */ +extra_len += (nargsall - 1) * 2; /* ", " */ for (i = 0; i < nargs; i++) { extra_len += strlen(args[i].type->ct_name); } +if (dotdotdot) +extra_len += 3; /* "..." */ name_obj = combine_type_name_l(ret, extra_len); if (name_obj == NULL) return NULL; @@ -192,6 +195,14 @@ memcpy(p, args[i].type->ct_name, len); p += len; } +if (dotdotdot) { +if (nargs > 0) { +*p++ = ','; +*p++ = ' '; +} +memcpy(p, "...", 3); +p += 3; +} *p++ = ')'; assert(p - PyString_AS_STRING(name_obj) - ret->ct_name_position == extra_len); @@ -216,12 +227,19 @@ return ct; } +static _crx_type_t *zef_get_function_type(_crx_builder_t *cb, _crx_type_t *ret, + _crx_qual_type args[], int nargs, + _crx_trampoline1_fn trampl) +{ +return _zef_function(cb, ret, args, nargs, 0); +} + static _crx_type_t *zef_get_ellipsis_function_type(_crx_builder_t *cb, _crx_type_t *ret, _crx_qual_type args[], int nargs) { -abort(); +return _zef_function(cb, ret, args, nargs, 1); } static _crx_type_t *zef_get_pointer_type(_crx_builder_t *cb, diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py --- a/zeffir/test/test_ctype.py +++ b/zeffir/test/test_ctype.py @@ -74,6 +74,11 @@ assert repr(ffi.typeof("int(long a,short b)"))=="" assert repr(ffi.typeof("int(*)(long)"))=="" +def test_typedef_function_dotdotdot(): +ffi = support.new_ffi() +assert repr(ffi.typeof("int(...)")) == "" +assert repr(ffi.typeof("int*(void*,...)")) == "" + def test_simple_typedef(): ffi, lib = support.compile_and_open('ctype') assert ffi.sizeof("foo_t") == ffi.sizeof("long long") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: add a test_pypy_c for array.any()
Author: Brian Kearns Branch: Changeset: r74818:ff4204895657 Date: 2014-12-04 17:00 -0500 http://bitbucket.org/pypy/pypy/changeset/ff4204895657/ Log:add a test_pypy_c for array.any() diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -3,6 +3,30 @@ class TestMicroNumPy(BaseTestPyPyC): +def test_array_any(self): +def main(): +import _numpypy.multiarray as np +arr = np.array([False] * 1500) +return arr.any() +log = self.run(main, []) +assert log.result == False +assert len(log.loops) == 1 +loop = log._filter(log.loops[0]) +assert loop.match(""" +i33 = raw_load(i9, i29, descr=) +guard_false(i33, descr=...) +guard_not_invalidated(descr=...) +i34 = getarrayitem_raw(#, 1, descr=) +guard_value(i34, 0, descr=...) +i35 = getarrayitem_raw(#, 0, descr=) +i36 = int_add(i24, 1) +i37 = int_add(i29, i28) +i38 = int_ge(i36, i30) +guard_false(i38, descr=...) +guard_value(i35, 1, descr=...) +jump(p0, p25, i36, i37, i9, i28, i30, descr=...) +""") + def test_array_getitem_basic(self): def main(): import _numpypy.multiarray as np ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] creflect default: tweaks
Author: Armin Rigo Branch: Changeset: r155:7c6a10d45a9d Date: 2014-12-04 22:59 +0100 http://bitbucket.org/cffi/creflect/changeset/7c6a10d45a9d/ Log:tweaks diff --git a/zeffir/builder.c b/zeffir/builder.c --- a/zeffir/builder.c +++ b/zeffir/builder.c @@ -563,11 +563,11 @@ PyErr_Fetch(&exc, &val, &tb); ps = PyObject_Str(val); if (ps != NULL && PyString_Check(ps)) { -PyErr_Format(exc, "at pos %zd: %s", - (size_t)(err - str), PyString_AS_STRING(ps)); Py_XDECREF(tb); Py_XDECREF(val); Py_XDECREF(exc); +PyErr_Format(exc, "at pos %zd: %s", + (size_t)(err - str), PyString_AS_STRING(ps)); } else { PyErr_Restore(exc, val, tb); @@ -576,8 +576,7 @@ } return NULL; } -if (err != NULL) -abort(); +assert(err == NULL); /* else, zef_error() must have been called */ Py_INCREF(result.type); return result.type; diff --git a/zeffir/lib_obj.c b/zeffir/lib_obj.c --- a/zeffir/lib_obj.c +++ b/zeffir/lib_obj.c @@ -43,6 +43,12 @@ return x; } +static int lib_setattr(ZefLibObject *lib, PyObject *name, PyObject *val) +{ +PyErr_SetString(PyExc_AttributeError, "Lib object is read-only"); +return -1; +} + static PyObject *lib_dir(PyObject *lib, PyObject *noarg) { return PyDict_Keys(((ZefLibObject *)lib)->l_dict); @@ -71,7 +77,7 @@ 0, /* tp_call */ 0, /* tp_str */ (getattrofunc)lib_getattr, /* tp_getattro */ -0, /* tp_setattro */ +(setattrofunc)lib_setattr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ @@ -88,7 +94,7 @@ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ -offsetof(ZefLibObject, l_dict), /* tp_dictoffset */ +offsetof(ZefLibObject, l_dict), /* tp_dictoffset */ }; static void lib_dlerror(ZefLibObject *lib) diff --git a/zeffir/test/test_basic.py b/zeffir/test/test_basic.py --- a/zeffir/test/test_basic.py +++ b/zeffir/test/test_basic.py @@ -14,6 +14,8 @@ ffi, lib = support.compile_and_open('basic') assert lib.forty_two == 42 assert type(lib.forty_two) is int +py.test.raises(AttributeError, setattr, lib, 'forty_two', 43) +py.test.raises(AttributeError, delattr, lib, 'forty_two') def test_dir(): ffi, lib = support.compile_and_open('basic') @@ -21,7 +23,10 @@ def test_no_special_attribute(): ffi, lib = support.compile_and_open('basic') -py.test.raises(AttributeError, getattr, lib, '__class__') +for name in dir(object()): # '__class__', '__str__', etc. +py.test.raises(AttributeError, getattr, lib, name) +py.test.raises(AttributeError, setattr, lib, name, '?') +py.test.raises(AttributeError, delattr, lib, name) def test_types(): ffi = support.new_ffi() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: cleanups
Author: Brian Kearns Branch: Changeset: r74819:a0e9ee8c4971 Date: 2014-12-04 17:57 -0500 http://bitbucket.org/pypy/pypy/changeset/a0e9ee8c4971/ Log:cleanups diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -287,8 +287,9 @@ def logical_xor(self, v1, v2): return bool(v1) ^ bool(v2) +@raw_unary_op def bool(self, v): -return bool(self.for_computation(self.unbox(v))) +return bool(v) @simple_binary_op def max(self, v1, v2): diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py --- a/pypy/module/micronumpy/ufuncs.py +++ b/pypy/module/micronumpy/ufuncs.py @@ -18,6 +18,7 @@ def done_if_false(dtype, val): return not dtype.itemtype.bool(val) + def _get_dtype(space, w_npyobj): if isinstance(w_npyobj, boxes.W_GenericBox): return w_npyobj.get_dtype(space) diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -16,14 +16,14 @@ i33 = raw_load(i9, i29, descr=) guard_false(i33, descr=...) guard_not_invalidated(descr=...) -i34 = getarrayitem_raw(#, 1, descr=) -guard_value(i34, 0, descr=...) -i35 = getarrayitem_raw(#, 0, descr=) +i34 = getarrayitem_raw(#, 1, descr=) # XXX what are these? +guard_value(i34, 0, descr=...) # XXX +i35 = getarrayitem_raw(#, 0, descr=) # XXX i36 = int_add(i24, 1) i37 = int_add(i29, i28) i38 = int_ge(i36, i30) guard_false(i38, descr=...) -guard_value(i35, 1, descr=...) +guard_value(i35, 1, descr=...) # XXX jump(p0, p25, i36, i37, i9, i28, i30, descr=...) """) @@ -130,7 +130,7 @@ setfield_gc(p97, i93, descr=) i96 = int_lt(i95, 0) guard_false(i96, descr=...) -jump(p0, p1, p3, p6, p12, p14, p16, i94, f90, p26, i45, i91, i59, p97, p96, i67, i93, i76, descr=...) +jump(p0, p1, p3, p6, p12, p14, p16, i94, f90, p26, i45, i91, i59, p96, p97, i67, i93, i76, descr=...) """) def test_array_flatiter_getitem_single(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: cleanup some numpy test_pypy_c tests
Author: Brian Kearns Branch: Changeset: r74820:e99e8fe69789 Date: 2014-12-04 20:35 -0500 http://bitbucket.org/pypy/pypy/changeset/e99e8fe69789/ Log:cleanup some numpy test_pypy_c tests diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -58,9 +58,8 @@ """ + alignment_check + """ f80 = raw_load(i67, i79, descr=) i81 = int_add(i71, 1) -guard_not_invalidated(descr=...) --TICK-- -jump(p0, p1, p3, p6, p7, p12, p14, p16, i81, f80, i59, p38, i55, p40, i37, i61, i67, descr=...) +jump(..., descr=...) """) def test_array_getitem_accumulate(self): @@ -130,7 +129,7 @@ setfield_gc(p97, i93, descr=) i96 = int_lt(i95, 0) guard_false(i96, descr=...) -jump(p0, p1, p3, p6, p12, p14, p16, i94, f90, p26, i45, i91, i59, p96, p97, i67, i93, i76, descr=...) +jump(..., descr=...) """) def test_array_flatiter_getitem_single(self): @@ -158,11 +157,8 @@ setarrayitem_gc(p150, 1, 0, descr=) setarrayitem_gc(p150, 0, 0, descr=) setfield_gc(p156, i55, descr=) -guard_not_invalidated(descr=...) -i154 = getfield_raw(#, descr=) -i155 = int_lt(i154, 0) -guard_false(i155, descr=...) -jump(p0, p1, p3, p6, p7, p12, p14, p16, i151, f149, p26, i44, i50, i59, i55, i100, p150, p156, descr=...) +--TICK-- +jump(..., descr=...) """) def test_array_flatiter_setitem_single(self): @@ -194,5 +190,5 @@ setfield_gc(p158, i53, descr=) i157 = int_lt(i154, 0) guard_false(i157, descr=...) -jump(p0, p1, p3, p6, p7, p12, p14, p16, i153, i42, i48, i57, i53, p47, i103, p152, p158, descr=...) +jump(..., descr=...) """) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: add test_pypy_c for logical_xor.reduce
Author: Brian Kearns Branch: Changeset: r74822:81a86598865d Date: 2014-12-04 20:25 -0500 http://bitbucket.org/pypy/pypy/changeset/81a86598865d/ Log:add test_pypy_c for logical_xor.reduce diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -3,6 +3,59 @@ class TestMicroNumPy(BaseTestPyPyC): +def test_reduce_logical_xor(self): +def main(): +import _numpypy.multiarray as np +import _numpypy.umath as um +arr = np.array([1.0] * 1500) +return um.logical_xor.reduce(arr) +log = self.run(main, []) +assert log.result is False +assert len(log.loops) == 1 +loop = log._filter(log.loops[0]) +assert loop.match(""" +guard_class(p0, #, descr=...) +p4 = getfield_gc_pure(p0, descr=) +i5 = getfield_gc(p2, descr=) +p6 = getfield_gc_pure(p4, descr=) +p7 = getfield_gc_pure(p6, descr=) +guard_class(p7, ConstClass(Float64), descr=...) +i9 = getfield_gc_pure(p4, descr=) +f10 = raw_load(i9, i5, descr=) +i11 = getfield_gc_pure(p7, descr=) +guard_true(i11, descr=...) +guard_not_invalidated(descr=...) +i12 = cast_float_to_int(f10) +i14 = int_and(i12, 255) +guard_true(i14, descr=...) +i15 = getfield_gc_pure(p1, descr=) +i16 = int_is_true(i15) +i18 = int_xor(i16, 1) +i19 = int_is_true(i18) +guard_true(i19, descr=...) +i20 = getfield_gc(p2, descr=) +i21 = getfield_gc_pure(p0, descr=) +guard_true(i21, descr=...) +i23 = int_add(i20, 1) +p24 = getfield_gc_pure(p2, descr=) +i25 = getfield_gc_pure(p0, descr=) +i26 = int_is_true(i25) +guard_true(i26, descr=...) +i27 = getfield_gc_pure(p6, descr=) +i28 = int_add(i5, i27) +i29 = getfield_gc_pure(p0, descr=) +i30 = int_ge(i23, i29) +guard_false(i30, descr=...) +p32 = new_with_vtable(#) +{{{ +setfield_gc(p32, i23, descr=) +setfield_gc(p32, p24, descr=) +setfield_gc(p32, i28, descr=) +setfield_gc(p32, p0, descr=) +}}} +jump(..., descr=...) +""") + def test_reduce_logical_and(self): def main(): import _numpypy.multiarray as np ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: simplify array.any test_pypy_c to use reduce directly
Author: Brian Kearns Branch: Changeset: r74821:e301f280ff33 Date: 2014-12-04 20:24 -0500 http://bitbucket.org/pypy/pypy/changeset/e301f280ff33/ Log:simplify array.any test_pypy_c to use reduce directly diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -3,28 +3,31 @@ class TestMicroNumPy(BaseTestPyPyC): -def test_array_any(self): +def test_reduce_logical_and(self): def main(): import _numpypy.multiarray as np -arr = np.array([False] * 1500) -return arr.any() +import _numpypy.umath as um +arr = np.array([1.0] * 1500) +return um.logical_and.reduce(arr) log = self.run(main, []) -assert log.result == False +assert log.result is True assert len(log.loops) == 1 loop = log._filter(log.loops[0]) assert loop.match(""" -i33 = raw_load(i9, i29, descr=) -guard_false(i33, descr=...) +f31 = raw_load(i9, i29, descr=) guard_not_invalidated(descr=...) -i34 = getarrayitem_raw(#, 1, descr=) # XXX what are these? -guard_value(i34, 0, descr=...) # XXX -i35 = getarrayitem_raw(#, 0, descr=) # XXX +i32 = cast_float_to_int(f31) +i33 = int_and(i32, 255) +guard_true(i33, descr=...) +i34 = getarrayitem_raw(#, 2, descr=) # XXX what are these? +guard_value(i34, 1, descr=...) # XXX don't appear in +i35 = getarrayitem_raw(#, 1, descr=) # XXX equiv test_zjit i36 = int_add(i24, 1) i37 = int_add(i29, i28) i38 = int_ge(i36, i30) guard_false(i38, descr=...) -guard_value(i35, 1, descr=...) # XXX -jump(p0, p25, i36, i37, i9, i28, i30, descr=...) +guard_value(i35, 2, descr=...) # XXX +jump(..., descr=...) """) def test_array_getitem_basic(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix this test_pypy_c, these numbers can vary
Author: Brian Kearns Branch: Changeset: r74823:e27f4fbd7134 Date: 2014-12-04 21:57 -0500 http://bitbucket.org/pypy/pypy/changeset/e27f4fbd7134/ Log:fix this test_pypy_c, these numbers can vary diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py --- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py +++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py @@ -72,14 +72,14 @@ i32 = cast_float_to_int(f31) i33 = int_and(i32, 255) guard_true(i33, descr=...) -i34 = getarrayitem_raw(#, 2, descr=) # XXX what are these? -guard_value(i34, 1, descr=...) # XXX don't appear in -i35 = getarrayitem_raw(#, 1, descr=) # XXX equiv test_zjit +i34 = getarrayitem_raw(#, #, descr=) # XXX what are these? +guard_value(i34, #, descr=...) # XXX don't appear in +i35 = getarrayitem_raw(#, #, descr=) # XXX equiv test_zjit i36 = int_add(i24, 1) i37 = int_add(i29, i28) i38 = int_ge(i36, i30) guard_false(i38, descr=...) -guard_value(i35, 2, descr=...) # XXX +guard_value(i35, #, descr=...) # XXX jump(..., descr=...) """) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test/fix ufunc reduce with comparison func when dtype specified
Author: Brian Kearns Branch: Changeset: r74824:4213885db36d Date: 2014-12-05 00:23 -0500 http://bitbucket.org/pypy/pypy/changeset/4213885db36d/ Log:test/fix ufunc reduce with comparison func when dtype specified diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py --- a/pypy/module/micronumpy/test/test_ufuncs.py +++ b/pypy/module/micronumpy/test/test_ufuncs.py @@ -785,6 +785,7 @@ assert exc.value[0] == "'axis' entry is out of bounds" def test_reduce_1d(self): +import numpy as np from numpypy import array, add, maximum, less, float16, complex64 assert less.reduce([5, 4, 3, 2, 1]) @@ -799,6 +800,10 @@ assert type(add.reduce(array([True, False] * 200, dtype='float16'))) is float16 assert type(add.reduce(array([True, False] * 200, dtype='complex64'))) is complex64 +for dtype in ['bool', 'int']: +assert np.equal.reduce([1, 2], dtype=dtype) == True +assert np.equal.reduce([1, 2, 0], dtype=dtype) == False + def test_reduceND(self): from numpypy import add, arange a = arange(12).reshape(3, 4) diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py --- a/pypy/module/micronumpy/ufuncs.py +++ b/pypy/module/micronumpy/ufuncs.py @@ -196,16 +196,15 @@ axis += shapelen assert axis >= 0 dtype = descriptor.decode_w_dtype(space, dtype) -if dtype is None: -if self.comparison_func: -dtype = descriptor.get_dtype_cache(space).w_booldtype -else: -dtype = find_unaryop_result_dtype( -space, obj.get_dtype(), -promote_to_float=self.promote_to_float, -promote_to_largest=self.promote_to_largest, -promote_bools=self.promote_bools, -) +if self.comparison_func: +dtype = descriptor.get_dtype_cache(space).w_booldtype +elif dtype is None: +dtype = find_unaryop_result_dtype( +space, obj.get_dtype(), +promote_to_float=self.promote_to_float, +promote_to_largest=self.promote_to_largest, +promote_bools=self.promote_bools, +) if self.identity is None: for i in range(shapelen): if space.is_none(w_axis) or i == axis: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit