diff --git a/CHANGES.current b/CHANGES.current index a72f31f31..3421669de 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.11 (in progress) ============================ +2016-12-18: wsfulton + Zero initialize arrays when using %array_class and %array_functions. + 2016-12-18: t-ikegami [Python] Fix https://github.com/swig/swig/issues/446 Python %array_class of carrays.i failed with -builtin option. diff --git a/Examples/test-suite/python/li_cpointer_cpp_runme.py b/Examples/test-suite/python/li_cpointer_cpp_runme.py index c49e9fc28..c763b85b8 100644 --- a/Examples/test-suite/python/li_cpointer_cpp_runme.py +++ b/Examples/test-suite/python/li_cpointer_cpp_runme.py @@ -2,6 +2,10 @@ from li_cpointer_cpp import * p = new_intp() + +if intp_value(p) != 0: + raise RuntimeError("not initialized") + intp_assign(p, 3) if intp_value(p) != 3: diff --git a/Examples/test-suite/python/li_cpointer_runme.py b/Examples/test-suite/python/li_cpointer_runme.py index 1565069cf..f0ec99060 100644 --- a/Examples/test-suite/python/li_cpointer_runme.py +++ b/Examples/test-suite/python/li_cpointer_runme.py @@ -2,6 +2,10 @@ from li_cpointer import * p = new_intp() + +if intp_value(p) != 0: + raise RuntimeError("not initialized") + intp_assign(p, 3) if intp_value(p) != 3: diff --git a/Lib/typemaps/swigmacros.swg b/Lib/typemaps/swigmacros.swg index 778502d43..3a63a256c 100644 --- a/Lib/typemaps/swigmacros.swg +++ b/Lib/typemaps/swigmacros.swg @@ -157,14 +157,14 @@ nocppval * ----------------------------------------------------------------------------- */ #if defined(__cplusplus) -# define %new_instance(Type...) (new Type) +# define %new_instance(Type...) (new Type()) # define %new_copy(val,Type...) (new Type(%static_cast(val, const Type&))) # define %new_array(size,Type...) (new Type[size]()) # define %new_copy_array(ptr,size,Type...) %reinterpret_cast(memcpy(new Type[size], ptr, sizeof(Type)*(size)), Type*) # define %delete(cptr) delete cptr # define %delete_array(cptr) delete[] cptr #else /* C case */ -# define %new_instance(Type...) (Type *)malloc(sizeof(Type)) +# define %new_instance(Type...) (Type *)calloc(1,sizeof(Type)) # define %new_copy(val,Type...) (Type *)memcpy(%new_instance(Type),&val,sizeof(Type)) # define %new_array(size,Type...) (Type *)calloc(size, sizeof(Type)) # define %new_copy_array(ptr,size,Type...) (Type *)memcpy(malloc((size)*sizeof(Type)), ptr, sizeof(Type)*(size))