Initialize C++ arrays created by array_functions' new_foo().

`array_functions(TYPE, NAME)' generates a `new_foo(size)' function that
allocates a new array of the given type.  When compiling in C, the array
is initialized with `calloc()', which shows that the intent was to have
the array be zero-initialized.  When in C++, however, the array was not
getting initialized, so it could contain random garbage after creation,
when the type was a POD type.

This change makes `new_foo(size)' create a value-initialized array when
in C++, as per the C++ standard's 5.3.4.15 that says that adding a pair
of parentheses at the end of a new-expression does that.
This commit is contained in:
Benoit Sigoure 2014-08-12 23:44:50 -07:00
commit 16549a36e3

View file

@ -22,7 +22,7 @@
%{
static TYPE *new_##NAME(int nelements) { %}
#ifdef __cplusplus
%{ return new TYPE[nelements]; %}
%{ return new TYPE[nelements](); %}
#else
%{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %}
#endif