Fix iterators for containers of NULL pointers (or Python None) when using -builtin.

Previously iteration would stop at the first element that had a NULL pointer value.
This commit is contained in:
William S Fulton 2016-09-17 17:53:48 +01:00
commit 0769e9b727
5 changed files with 30 additions and 14 deletions

View file

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.11 (in progress)
============================
2016-09-17: wsfulton
[Python] Fix iterators for containers of NULL pointers (or Python None) when using
-builtin. Previously iteration would stop at the first element that was NULL.
2016-09-16: olly
[Javascript] Fix SWIG_exception() macro to return from the current
function. Fixes #789, reported by Julien Dutriaux.

View file

@ -36,3 +36,21 @@ try:
raise RuntimeError("missed exception")
except TypeError:
pass
b111 = makeB(111)
bNones = BPtrVector([None, b111, None])
bCount = 0
noneCount = 0
for b in bNones:
if b == None:
noneCount = noneCount + 1
else:
if b.val != 111:
raise RuntimeError("b.val is wrong")
bCount = bCount + 1
if bCount != 1:
raise RuntimeError("bCount wrong")
if noneCount != 2:
raise RuntimeError("noneCount wrong")

View file

@ -2,3 +2,9 @@ from li_std_vector import *
if typedef_test(101) != 101:
raise RuntimeError
try:
sv = StructVector([None, None])
raise RuntimeError("Using None should result in a TypeError")
except TypeError:
pass

View file

@ -199,18 +199,6 @@ wrapper##_closure(PyObject *a) { \
return result; \
}
#define SWIGPY_ITERNEXT_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
PyObject *result; \
result = wrapper(a, NULL); \
if (result && result == Py_None) { \
Py_DECREF(result); \
result = NULL; \
} \
return result; \
}
#ifdef __cplusplus
extern "C" {
#endif

View file

@ -200,7 +200,7 @@ static String *getClosure(String *functype, String *wrapper, int funpack = 0) {
"objobjargproc", "SWIGPY_OBJOBJARGPROC_CLOSURE",
"reprfunc", "SWIGPY_REPRFUNC_CLOSURE",
"hashfunc", "SWIGPY_HASHFUNC_CLOSURE",
"iternextfunc", "SWIGPY_ITERNEXT_CLOSURE",
"iternextfunc", "SWIGPY_UNARYFUNC_CLOSURE",
NULL
};
@ -219,7 +219,7 @@ static String *getClosure(String *functype, String *wrapper, int funpack = 0) {
"objobjargproc", "SWIGPY_OBJOBJARGPROC_CLOSURE",
"reprfunc", "SWIGPY_REPRFUNC_CLOSURE",
"hashfunc", "SWIGPY_HASHFUNC_CLOSURE",
"iternextfunc", "SWIGPY_ITERNEXT_CLOSURE",
"iternextfunc", "SWIGPY_UNARYFUNC_CLOSURE",
NULL
};