From: <ar...@co...> - 2006-09-01 09:23:24
|
Author: arigo Date: Fri Sep 1 11:23:51 2006 New Revision: 31907 Modified: psyco/dist/c/Objects/pabstract.c psyco/dist/c/Python/pycompiler.c psyco/dist/c/Python/pyver.h psyco/dist/test/btrun.py psyco/dist/test/test5.py psyco/dist/test/test_misc.py Log: Update to the new definition of the 2.5 nb_index slot. More tests. Modified: psyco/dist/c/Objects/pabstract.c ============================================================================== --- psyco/dist/c/Objects/pabstract.c (original) +++ psyco/dist/c/Objects/pabstract.c Fri Sep 1 11:23:51 2006 @@ -138,15 +138,20 @@ vinfo_decref(key_value, po); return result; } - if (TYPE_HAS_INDEX(ktp)) { +#if HAVE_NB_INDEX + if (PsycoIndex_Check(ktp)) { vinfo_t* result; - vinfo_t* key_value = TYPE_VINDEX(po, ktp, key); + vinfo_t* key_value; + key_value = psyco_generic_call(po, PyNumber_AsSsize_t, + CfReturnNormal|CfPyErrCheckMinus1, + "vl", key, (long) PyExc_IndexError); if (key_value == NULL) return NULL; result = PsycoSequence_GetItem(po, o, key_value); vinfo_decref(key_value, po); return result; } +#endif type_error(po, "sequence index must be integer"); return false; } @@ -192,15 +197,20 @@ vinfo_decref(key_value, po); return result; } - if (TYPE_HAS_INDEX(ktp)) { +#if HAVE_NB_INDEX + if (PsycoIndex_Check(ktp)) { bool result; - vinfo_t* key_value = TYPE_VINDEX(po, ktp, key); + vinfo_t* key_value; + key_value = psyco_generic_call(po, PyNumber_AsSsize_t, + CfReturnNormal|CfPyErrCheckMinus1, + "vl", key, (long) PyExc_IndexError); if (key_value == NULL) return false; result = PsycoSequence_SetItem(po, o, key_value,value); vinfo_decref(key_value, po); return result; } +#endif if (tp->tp_as_sequence->sq_ass_item) { type_error(po, "sequence index must be integer"); return false; @@ -723,9 +733,14 @@ else if (PyType_TypeCheck(tp, &PyLong_Type)) { vcount = PsycoLong_AsLong(po, vn); } - else if (TYPE_HAS_INDEX(tp)) { - vcount = TYPE_VINDEX(po, tp, vn); +#if HAVE_NB_INDEX + else if (PsycoIndex_Check(tp)) { + vcount = psyco_generic_call(po, PyNumber_AsSsize_t, + CfReturnNormal|CfPyErrCheckMinus1, + "vl", vn, + (long) PyExc_OverflowError); } +#endif else { return type_error(po, "can't multiply sequence to non-int"); Modified: psyco/dist/c/Python/pycompiler.c ============================================================================== --- psyco/dist/c/Python/pycompiler.c (original) +++ psyco/dist/c/Python/pycompiler.c Fri Sep 1 11:23:51 2006 @@ -1315,9 +1315,13 @@ result = vinfo_new(CompileTime_New(x)); } } - else if (TYPE_HAS_INDEX(vtp)) { - result = TYPE_VINDEX(po, vtp, v); +#if HAVE_NB_INDEX + else if (PsycoIndex_Check(vtp)) { + result = psyco_generic_call(po, PyNumber_AsSsize_t, + CfReturnNormal|CfPyErrCheckMinus1, + "vl", v, (long) NULL); } +#endif else { /* no error set */ result = NULL; Modified: psyco/dist/c/Python/pyver.h ============================================================================== --- psyco/dist/c/Python/pyver.h (original) +++ psyco/dist/c/Python/pyver.h Fri Sep 1 11:23:51 2006 @@ -100,15 +100,14 @@ #endif #ifdef Py_TPFLAGS_HAVE_INDEX /* Python >= 2.5 */ -# define TYPE_HAS_INDEX(tp) ((tp)->tp_as_number && \ - PyType_HasFeature((tp), Py_TPFLAGS_HAVE_INDEX) \ - && (tp)->tp_as_number->nb_index) -# define TYPE_VINDEX(po, tp, v) Psyco_META1(po, (tp)->tp_as_number->nb_index, \ - CfReturnNormal|CfPyErrCheckMinus1,\ - "v", (v)) +# define HAVE_NB_INDEX 1 +# define PsycoIndex_Check(tp) \ + ((tp)->tp_as_number != NULL && \ + PyType_HasFeature((tp), Py_TPFLAGS_HAVE_INDEX) && \ + (tp)->tp_as_number->nb_index != NULL) + #else -# define TYPE_HAS_INDEX(tp) 0 -# define TYPE_VINDEX(po, tp, v) NULL +# define HAVE_NB_INDEX 0 #endif Modified: psyco/dist/test/btrun.py ============================================================================== --- psyco/dist/test/btrun.py (original) +++ psyco/dist/test/btrun.py Fri Sep 1 11:23:51 2006 @@ -693,6 +693,18 @@ 4 8 +>>> test5.variousslices() +slice(4, None, None) +slice(None, 7, None) +slice(9, 'hello', None) +slice('world', None, None) +slice(1, 10, 'hello') +4 2147483647 +0 7 +slice(9, 'hello', None) +slice('world', None, None) +slice(1, 10, 'hello') + ########################### #### COMPACTOBJECT #### ########################### Modified: psyco/dist/test/test5.py ============================================================================== --- psyco/dist/test/test5.py (original) +++ psyco/dist/test/test5.py Fri Sep 1 11:23:51 2006 @@ -418,6 +418,22 @@ a[0] = 8 print b[0] +def variousslices(): + class X(object): + def __getitem__(self, x): + print x + class Y(object): + def __getitem__(self, x): + print x + def __getslice__(self, i, j): + print i, j + for o in [X(), Y()]: + o[4:] + o[:7] + o[9:'hello'] + o['world':] + o[1:10:'hello'] + if __name__ == '__main__': from test1 import go, print_results import time Modified: psyco/dist/test/test_misc.py ============================================================================== --- psyco/dist/test/test_misc.py (original) +++ psyco/dist/test/test_misc.py Fri Sep 1 11:23:51 2006 @@ -37,3 +37,17 @@ res = psyco.proxy(f)(Observer(), X(), Y()) assert res == ("slice", 5, -2) + +def test_index_repeat(): + if sys.version_info < (2, 5): + py.test.skip("for Python 2.5") + + class X(object): + def __index__(self): + return 3 + + def f(x): + return (12, 23) * x + + res = psyco.proxy(f)(X()) + assert res == (12, 23, 12, 23, 12, 23) |