Skip to content

Commit

Permalink
Consistent memory intiailization between C and C++ in typemaps
Browse files Browse the repository at this point in the history
Remove unnecessary initialization via calloc calls and replace with
malloc.
  • Loading branch information
wsfulton committed Jul 30, 2015
1 parent 00a9b8d commit cd04b37
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Lib/java/arrays_java.i
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **ca
#ifdef __cplusplus
%{ *carr = new CTYPE[sz]; %}
#else
%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %}
%{ *carr = (CTYPE*) malloc(sz * sizeof(CTYPE)); %}
#endif
%{ if (!*carr) {
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
Expand Down Expand Up @@ -259,7 +259,7 @@ JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] *
#ifdef __cplusplus
$1 = new $*1_ltype[sz];
#else
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
$1 = ($1_ltype) malloc(sz * sizeof($*1_ltype));
#endif
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
Expand Down Expand Up @@ -289,7 +289,7 @@ JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] *
#ifdef __cplusplus
$1 = new $*1_ltype[sz];
#else
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
$1 = ($1_ltype) malloc(sz * sizeof($*1_ltype));
#endif
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
Expand Down
4 changes: 2 additions & 2 deletions Lib/java/various.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
#ifdef __cplusplus
$1 = new char*[size+1];
#else
$1 = (char **)calloc(size+1, sizeof(char *));
$1 = (char **)malloc((size+1) * sizeof(char *));
#endif
for (i = 0; i<size; i++) {
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
#ifdef __cplusplus
$1[i] = new char [strlen(c_string)+1];
#else
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
$1[i] = (char *)malloc((strlen(c_string)+1) * sizeof(const char *));
#endif
strcpy($1[i], c_string);
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
Expand Down

0 comments on commit cd04b37

Please sign in to comment.