diff --git a/CHANGES.current b/CHANGES.current index 565a4ec0f..fe11a2952 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-05-25: wsfulton + [Python] Fix Python 3 inconsistency when negative numbers are passed + where a parameter expects an unsigned C type. An OverFlow error is + now consistently thrown instead of a TypeError. + 2013-05-25: Artem Serebriyskiy SVN Patch ticket #338 - fixes to %attribute macros for template usage with %arg. diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index 2495cd60d..be8d38bad 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -275,10 +275,22 @@ try: except TypeError: if a != t.var_char: error = 1 - pass + pass if error: raise RuntimeError, "bad char typemap" +try: + error = 0 + a = t.var_ushort + t.var_ushort = -1 + error = 1 +except OverflowError: + if a != t.var_ushort: + error = 1 + pass +if error: + raise RuntimeError, "bad ushort typemap" + try: error = 0 a = t.var_uint @@ -287,10 +299,34 @@ try: except OverflowError: if a != t.var_uint: error = 1 - pass + pass if error: raise RuntimeError, "bad uint typemap" +try: + error = 0 + a = t.var_sizet + t.var_sizet = -1 + error = 1 +except OverflowError: + if a != t.var_sizet: + error = 1 + pass +if error: + raise RuntimeError, "bad sizet typemap" + +try: + error = 0 + a = t.var_ulong + t.var_ulong = -1 + error = 1 +except OverflowError: + if a != t.var_ulong: + error = 1 + pass +if error: + raise RuntimeError, "bad ulong typemap" + # # try: @@ -301,7 +337,7 @@ try: except TypeError: if a != t.var_namet: error = 1 - pass + pass if error: raise RuntimeError, "bad namet typemap" diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 3fbd86a21..66ff104a6 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -127,6 +127,18 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) return SWIG_OK; } else { PyErr_Clear(); +%#if PY_VERSION_HEX >= 0x03000000 + { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (v < 0) { + return SWIG_OverflowError; + } + } else { + PyErr_Clear(); + } + } +%#endif } } %#ifdef SWIG_PYTHON_CAST_MODE