Fix Python 3 inconsistency handling -ve numbers for unsigned C types.
An OverFlow error is now consistently thrown instead of a TypeError. Fixes primitive_types testcase for Python 3
This commit is contained in:
parent
3e188e508d
commit
5481270c2a
3 changed files with 56 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue