Skip to content

Commit

Permalink
Merge pull request #3736 from MikeLing/issuefix-3700
Browse files Browse the repository at this point in the history
clean up memcpy in swig typemaps
  • Loading branch information
lambday committed Mar 22, 2017
2 parents d3c225e + 176feb6 commit 044780d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/interfaces/csharp_modular/swig_typemaps.i
Expand Up @@ -204,7 +204,7 @@ TYPEMAP_SGMATRIX(float64_t, double, double)

if (len >0) {
strings[i].string = SG_MALLOC(SGTYPE, len);
memcpy(strings[i].string, array, len * sizeof(SGTYPE));
sg_memcpy(strings[i].string, array, len * sizeof(SGTYPE));
}
array = array + len;
}
Expand All @@ -230,7 +230,7 @@ TYPEMAP_SGMATRIX(float64_t, double, double)
res = res + 2;

for (i = 0; i < rows; i++) {
memcpy(res, str[i].string, str[i].slen * sizeof(SGTYPE));
sg_memcpy(res, str[i].string, str[i].slen * sizeof(SGTYPE));
res = res + cols;
SG_FREE(str[i].string);
}
Expand Down Expand Up @@ -302,7 +302,7 @@ TYPEMAP_STRINGFEATURES(float64_t, double, double)

if (len > 0) {
strings[i].string = SG_MALLOC(char, len);
memcpy(strings[i].string, str, len);
sg_memcpy(strings[i].string, str, len);
}
}

Expand All @@ -325,7 +325,7 @@ TYPEMAP_STRINGFEATURES(float64_t, double, double)

for (i = 0; i < size; i++) {
res[i + 1] = SG_MALLOC(char, str[i].slen);
memcpy(res[i + 1], str[i].string, str[i].slen * sizeof(char));
sg_memcpy(res[i + 1], str[i].string, str[i].slen * sizeof(char));
}
$result = res;
}
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/java_modular/swig_typemaps.i
Expand Up @@ -664,7 +664,7 @@ TYPEMAP_SGMATRIX(float64_t, double, Double, jdouble, "toDoubleArray", "()[[D", "

if (len >0) {
strings[i].string = SG_MALLOC(SGTYPE, len);
memcpy(strings[i].string, jarr, len * sizeof(SGTYPE));
sg_memcpy(strings[i].string, jarr, len * sizeof(SGTYPE));
}
}

Expand All @@ -686,7 +686,7 @@ TYPEMAP_SGMATRIX(float64_t, double, Double, jdouble, "toDoubleArray", "()[[D", "

for (i = 0; i < num; i++) {
SGTYPE* data = SG_MALLOC(SGTYPE, str[i].slen);
memcpy(data, str[i].string, str[i].slen * sizeof(SGTYPE));
sg_memcpy(data, str[i].string, str[i].slen * sizeof(SGTYPE));

##JNITYPE##Array jarr = (##JNITYPE##Array)JCALL1(New##JAVATYPE##Array, jenv, str[i].slen);

Expand Down Expand Up @@ -756,7 +756,7 @@ TYPEMAP_STRINGFEATURES(float64_t, double, Double, jdouble, "Doulbe[][]", "[[D")

if (len > 0) {
strings[i].string = SG_MALLOC(char, len);
memcpy(strings[i].string, str, len);
sg_memcpy(strings[i].string, str, len);
}
JCALL2(ReleaseStringUTFChars, jenv, jstr, str);
}
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/lua_modular/swig_typemaps.i
Expand Up @@ -306,7 +306,7 @@ TYPEMAP_SGMATRIX(float64_t)

if (len > 0) {
strings[i].string = SG_MALLOC(SGTYPE, len+1);
memcpy(strings[i].string, str, len);
sg_memcpy(strings[i].string, str, len);
strings[i].string[len]='\0';
}
}
Expand All @@ -323,7 +323,7 @@ TYPEMAP_SGMATRIX(float64_t)

if (len > 0) {
strings[i].string = SG_MALLOC(SGTYPE, len);
memcpy(strings[i].string, arr, len * sizeof(SGTYPE));
sg_memcpy(strings[i].string, arr, len * sizeof(SGTYPE));
}

}
Expand All @@ -350,7 +350,7 @@ TYPEMAP_SGMATRIX(float64_t)
}
else {
SGTYPE* data = SG_MALLOC(SGTYPE, str[i].slen);
memcpy(data, str[i].string, str[i].slen * sizeof(SGTYPE));
sg_memcpy(data, str[i].string, str[i].slen * sizeof(SGTYPE));

lua_newtable(L);
for (j = 0; j < str[i].slen; j++) {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/modular/abstract_types_extension.i
Expand Up @@ -54,7 +54,7 @@
{
CHOGFeatures* hf = (CHOGFeatures*) m_features->get_sample(i);
CBoundingBox* bb = (CBoundingBox*) m_labels->get_latent_label(i);
memcpy(psi_m.matrix+i*dim, hf->hog[bb->x_pos][bb->y_pos], dim*sizeof(float64_t));
sg_memcpy(psi_m.matrix+i*dim, hf->hog[bb->x_pos][bb->y_pos], dim*sizeof(float64_t));
}
CDenseFeatures<float64_t>* psi_feats = new CDenseFeatures<float64_t>(psi_m);
return psi_feats;
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/perl_modular/swig_typemaps.i
Expand Up @@ -35,7 +35,7 @@
PDL->destroy(it);
return false;
}
memcpy((type *)data, sg_vec.vector, clen);
sg_memcpy((type *)data, sg_vec.vector, clen);
PDL->SetSV_PDL(rsv, it);
return true;
}
Expand Down Expand Up @@ -99,7 +99,7 @@
}
for(int32_t i = 0; i < sg_num; i++) {
//PTZ121012 really to check this with unicode types also...
memcpy((type*) data_pdl + (i * sg_slen_max), sg_str[i].string, sizeof(type) * sg_str[i].slen);
sg_memcpy((type*) data_pdl + (i * sg_slen_max), sg_str[i].string, sizeof(type) * sg_str[i].slen);
//PTZ121012 shall have calloced also...
}
PDL->SetSV_PDL(rsv, it);
Expand Down Expand Up @@ -303,7 +303,7 @@ fail:
//free(inds);
return false;
}
memcpy(l_ss[lind].string, el_str, el_len);
sg_memcpy(l_ss[lind].string, el_str, el_len);
if(el_len > sg_strings.max_string_length) {
sg_strings.max_string_length = el_len;
}
Expand Down Expand Up @@ -346,7 +346,7 @@ fail:
l_ss[i].string = NULL;
if (el_len > 0) {
l_ss[i].string = SG_MALLOC(type, el_len);
memcpy(l_ss[i].string, el_str, el_len);
sg_memcpy(l_ss[i].string, el_str, el_len);
if(el_len > sg_strings.max_string_length) {
sg_strings.max_string_length = el_len;
}
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/python_modular/swig_typemaps.i
Expand Up @@ -411,7 +411,7 @@ static bool string_from_strpy(SGStringList<type>& sg_strings, PyObject* obj, int
if (len>0)
{
strings[i].string=SG_MALLOC(type, len);
memcpy(strings[i].string, str, len);
sg_memcpy(strings[i].string, str, len);
}
}
else
Expand Down Expand Up @@ -443,7 +443,7 @@ static bool string_from_strpy(SGStringList<type>& sg_strings, PyObject* obj, int
if (len>0)
{
strings[i].string=SG_MALLOC(type, len);
memcpy(strings[i].string, str, len*sizeof(type));
sg_memcpy(strings[i].string, str, len*sizeof(type));
}

if (is_new_object)
Expand Down Expand Up @@ -505,7 +505,7 @@ static bool string_to_strpy(PyObject* &obj, SGStringList<type> sg_strings, int t
type* data = SG_MALLOC(type, str[i].slen);
if (descr && data)
{
memcpy(data, str[i].string, str[i].slen*sizeof(type));
sg_memcpy(data, str[i].string, str[i].slen*sizeof(type));
npy_intp dims = str[i].slen;

s = PyArray_NewFromDescr(&PyArray_Type,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/r_modular/swig_typemaps.i
Expand Up @@ -183,7 +183,7 @@ TYPEMAP_OUT_SGMATRIX(INTSXP, INTEGER, uint16_t, int, "Word")
{
sg_type* dst=SG_MALLOC(sg_type, len+1);
/*ASSERT(strs[i].string);*/
strs[i].string=(sg_type*) memcpy(dst, c, len*sizeof(sg_type));
strs[i].string=(sg_type*) sg_memcpy(dst, c, len*sizeof(sg_type));
strs[i].string[len]='\0'; /* zero terminate */
strs[i].slen=len;
max_len=CMath::max(max_len, len);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/ruby_modular/swig_typemaps.i
Expand Up @@ -193,7 +193,7 @@ TYPEMAP_SGMATRIX(float64_t, NUM2DBL, rb_float_new)

if (len > 0) {
strings[i].string = SG_MALLOC(SGTYPE, len + 1);
memcpy(strings[i].string, str, len + 1);
sg_memcpy(strings[i].string, str, len + 1);
}
}
else {
Expand Down Expand Up @@ -237,7 +237,7 @@ TYPEMAP_SGMATRIX(float64_t, NUM2DBL, rb_float_new)
}
else {
SGTYPE* data = SG_MALLOC(SGTYPE, str[i].slen);
memcpy(data, str[i].string, str[i].slen * sizeof(SGTYPE));
sg_memcpy(data, str[i].string, str[i].slen * sizeof(SGTYPE));

VALUE vec = rb_ary_new2(str[i].slen);
for (j = 0; j < str[i].slen; j++) {
Expand Down

0 comments on commit 044780d

Please sign in to comment.