Skip to content

Commit

Permalink
Merge pull request #66 from derobins/minor/HD_to_H5MM
Browse files Browse the repository at this point in the history
Replaces C standard library memory calls with H5MM equivalents
  • Loading branch information
lrknox authored Oct 30, 2020
2 parents 6c0f954 + 16eab69 commit 42d4cea
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/H5FDhdfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ H5Pget_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa_out)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")

/* Copy the hdfs fapl data out */
HDmemcpy(fa_out, fa, sizeof(H5FD_hdfs_fapl_t));
H5MM_memcpy(fa_out, fa, sizeof(H5FD_hdfs_fapl_t));

done:
FUNC_LEAVE_API(ret_value)
Expand Down Expand Up @@ -709,7 +709,7 @@ H5FD__hdfs_fapl_get(H5FD_t *_file)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "memory allocation failed")

/* Copy the fields of the structure */
HDmemcpy(fa, &(file->fa), sizeof(H5FD_hdfs_fapl_t));
H5MM_memcpy(fa, &(file->fa), sizeof(H5FD_hdfs_fapl_t));

ret_value = fa;

Expand Down Expand Up @@ -747,7 +747,7 @@ H5FD__hdfs_fapl_copy(const void *_old_fa)
if (new_fa == NULL)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "memory allocation failed")

HDmemcpy(new_fa, old_fa, sizeof(H5FD_hdfs_fapl_t));
H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_hdfs_fapl_t));
ret_value = new_fa;

done:
Expand Down Expand Up @@ -904,7 +904,7 @@ H5FD__hdfs_open(const char *path, unsigned flags, hid_t fapl_id, haddr_t maxaddr
if (file == NULL)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate file struct")
file->hdfs_handle = handle;
HDmemcpy(&(file->fa), &fa, sizeof(H5FD_hdfs_fapl_t));
H5MM_memcpy(&(file->fa), &fa, sizeof(H5FD_hdfs_fapl_t));

#if HDFS_STATS
if (FAIL == hdfs__reset_stats(file))
Expand Down
22 changes: 11 additions & 11 deletions src/H5FDmirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ H5FD__mirror_xmit_decode_uint16(uint16_t *out, const unsigned char *_buf)

HDassert(_buf && out);

HDmemcpy(&n, _buf, sizeof(n));
H5MM_memcpy(&n, _buf, sizeof(n));
*out = (uint16_t)HDntohs(n);

return 2; /* number of bytes eaten */
Expand Down Expand Up @@ -326,7 +326,7 @@ H5FD__mirror_xmit_decode_uint32(uint32_t *out, const unsigned char *_buf)

HDassert(_buf && out);

HDmemcpy(&n, _buf, sizeof(n));
H5MM_memcpy(&n, _buf, sizeof(n));
*out = (uint32_t)HDntohl(n);

return 4; /* number of bytes eaten */
Expand Down Expand Up @@ -385,7 +385,7 @@ H5FD__mirror_xmit_decode_uint64(uint64_t *out, const unsigned char *_buf)

HDassert(_buf && out);

HDmemcpy(&n, _buf, sizeof(n));
H5MM_memcpy(&n, _buf, sizeof(n));
if (TRUE == is_host_little_endian())
*out = BSWAP_64(n);
else
Expand All @@ -412,7 +412,7 @@ H5FD__mirror_xmit_decode_uint8(uint8_t *out, const unsigned char *_buf)

HDassert(_buf && out);

HDmemcpy(out, _buf, sizeof(uint8_t));
H5MM_memcpy(out, _buf, sizeof(uint8_t));

return 1; /* number of bytes eaten */
} /* end H5FD__mirror_xmit_decode_uint8() */
Expand All @@ -439,7 +439,7 @@ H5FD__mirror_xmit_encode_uint16(unsigned char *_dest, uint16_t v)
HDassert(_dest);

n = (uint16_t)HDhtons(v);
HDmemcpy(_dest, &n, sizeof(n));
H5MM_memcpy(_dest, &n, sizeof(n));

return 2;
} /* end H5FD__mirror_xmit_encode_uint16() */
Expand All @@ -466,7 +466,7 @@ H5FD__mirror_xmit_encode_uint32(unsigned char *_dest, uint32_t v)
HDassert(_dest);

n = (uint32_t)HDhtonl(v);
HDmemcpy(_dest, &n, sizeof(n));
H5MM_memcpy(_dest, &n, sizeof(n));

return 4;
} /* end H5FD__mirror_xmit_encode_uint32() */
Expand Down Expand Up @@ -494,7 +494,7 @@ H5FD__mirror_xmit_encode_uint64(unsigned char *_dest, uint64_t v)

if (TRUE == is_host_little_endian())
n = BSWAP_64(v);
HDmemcpy(_dest, &n, sizeof(n));
H5MM_memcpy(_dest, &n, sizeof(n));

return 8;
} /* H5FD__mirror_xmit_encode_uint64() */
Expand All @@ -519,7 +519,7 @@ H5FD__mirror_xmit_encode_uint8(unsigned char *dest, uint8_t v)

HDassert(dest);

HDmemcpy(dest, &v, sizeof(v));
H5MM_memcpy(dest, &v, sizeof(v));

return 1;
} /* end H5FD__mirror_xmit_encode_uint8() */
Expand Down Expand Up @@ -1188,7 +1188,7 @@ H5FD__mirror_fapl_get(H5FD_t *_file)
if (NULL == fa)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "calloc failed");

HDmemcpy(fa, &(file->fa), sizeof(H5FD_mirror_fapl_t));
H5MM_memcpy(fa, &(file->fa), sizeof(H5FD_mirror_fapl_t));

ret_value = fa;

Expand Down Expand Up @@ -1224,7 +1224,7 @@ H5FD__mirror_fapl_copy(const void *_old_fa)
if (new_fa == NULL)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "memory allocation failed");

HDmemcpy(new_fa, old_fa, sizeof(H5FD_mirror_fapl_t));
H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_mirror_fapl_t));
ret_value = new_fa;

done:
Expand Down Expand Up @@ -1298,7 +1298,7 @@ H5Pget_fapl_mirror(hid_t fapl_id, H5FD_mirror_fapl_t *fa_out)

HDassert(fa->magic == H5FD_MIRROR_FAPL_MAGIC); /* sanity check */

HDmemcpy(fa_out, fa, sizeof(H5FD_mirror_fapl_t));
H5MM_memcpy(fa_out, fa, sizeof(H5FD_mirror_fapl_t));

done:
FUNC_LEAVE_API(ret_value);
Expand Down
8 changes: 4 additions & 4 deletions src/H5FDros3.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ H5Pget_fapl_ros3(hid_t fapl_id, H5FD_ros3_fapl_t *fa_out)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")

/* Copy the ros3 fapl data out */
HDmemcpy(fa_out, fa, sizeof(H5FD_ros3_fapl_t));
H5MM_memcpy(fa_out, fa, sizeof(H5FD_ros3_fapl_t));

done:
FUNC_LEAVE_API(ret_value)
Expand Down Expand Up @@ -535,7 +535,7 @@ H5FD__ros3_fapl_get(H5FD_t *_file)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")

/* Copy the fields of the structure */
HDmemcpy(fa, &(file->fa), sizeof(H5FD_ros3_fapl_t));
H5MM_memcpy(fa, &(file->fa), sizeof(H5FD_ros3_fapl_t));

/* Set return value */
ret_value = fa;
Expand Down Expand Up @@ -575,7 +575,7 @@ H5FD__ros3_fapl_copy(const void *_old_fa)
if (new_fa == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");

HDmemcpy(new_fa, old_fa, sizeof(H5FD_ros3_fapl_t));
H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_ros3_fapl_t));
ret_value = new_fa;

done:
Expand Down Expand Up @@ -768,7 +768,7 @@ H5FD__ros3_open(const char *url, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct")

file->s3r_handle = handle;
HDmemcpy(&(file->fa), &fa, sizeof(H5FD_ros3_fapl_t));
H5MM_memcpy(&(file->fa), &fa, sizeof(H5FD_ros3_fapl_t));

#if ROS3_STATS
if (FAIL == ros3_reset_stats(file))
Expand Down
30 changes: 15 additions & 15 deletions src/H5FDs3comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ curlwritecallback(char *ptr, size_t size, size_t nmemb, void *userdata)
return written;

if (size > 0) {
HDmemcpy(&(sds->data[sds->size]), ptr, product);
H5MM_memcpy(&(sds->data[sds->size]), ptr, product);
sds->size += product;
written = product;
}
Expand Down Expand Up @@ -263,12 +263,12 @@ H5FD_s3comms_hrb_node_set(hrb_node_t **L, const char *name, const char *value)
namecpy = (char *)H5MM_malloc(sizeof(char) * (namelen + 1));
if (namecpy == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for name copy.");
HDmemcpy(namecpy, name, (namelen + 1));
H5MM_memcpy(namecpy, name, (namelen + 1));

valuecpy = (char *)H5MM_malloc(sizeof(char) * (valuelen + 1));
if (valuecpy == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for value copy.");
HDmemcpy(valuecpy, value, (valuelen + 1));
H5MM_memcpy(valuecpy, value, (valuelen + 1));

nvcat = (char *)H5MM_malloc(sizeof(char) * catwrite);
if (nvcat == NULL)
Expand Down Expand Up @@ -701,14 +701,14 @@ H5FD_s3comms_hrb_init_request(const char *_verb, const char *_resource, const ch
res = (char *)H5MM_malloc(sizeof(char) * (reslen + 1));
if (res == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "no space for resource string");
HDmemcpy(res, _resource, (reslen + 1));
H5MM_memcpy(res, _resource, (reslen + 1));
}
else {
res = (char *)H5MM_malloc(sizeof(char) * (reslen + 2));
if (res == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "no space for resource string");
*res = '/';
HDmemcpy((&res[1]), _resource, (reslen + 1));
H5MM_memcpy((&res[1]), _resource, (reslen + 1));
HDassert((reslen + 1) == HDstrlen(res));
} /* end if (else resource string not starting with '/') */

Expand Down Expand Up @@ -910,7 +910,7 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle)
handle->httpverb = (char *)H5MM_malloc(sizeof(char) * 16);
if (handle->httpverb == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "unable to allocate space for S3 request HTTP verb");
HDmemcpy(handle->httpverb, "HEAD", 5);
H5MM_memcpy(handle->httpverb, "HEAD", 5);

headerresponse = (char *)H5MM_malloc(sizeof(char) * CURL_MAX_HTTP_HEADER);
if (headerresponse == NULL)
Expand Down Expand Up @@ -1078,19 +1078,19 @@ H5FD_s3comms_s3r_open(const char *url, const char *region, const char *id, const
handle->region = (char *)H5MM_malloc(sizeof(char) * tmplen);
if (handle->region == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "could not malloc space for handle region copy.");
HDmemcpy(handle->region, region, tmplen);
H5MM_memcpy(handle->region, region, tmplen);

tmplen = HDstrlen(id) + 1;
handle->secret_id = (char *)H5MM_malloc(sizeof(char) * tmplen);
if (handle->secret_id == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "could not malloc space for handle ID copy.");
HDmemcpy(handle->secret_id, id, tmplen);
H5MM_memcpy(handle->secret_id, id, tmplen);

tmplen = SHA256_DIGEST_LENGTH;
handle->signing_key = (unsigned char *)H5MM_malloc(sizeof(unsigned char) * tmplen);
if (handle->signing_key == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "could not malloc space for handle key copy.");
HDmemcpy(handle->signing_key, signing_key, tmplen);
H5MM_memcpy(handle->signing_key, signing_key, tmplen);
} /* if authentication information provided */

/************************
Expand Down Expand Up @@ -1138,7 +1138,7 @@ H5FD_s3comms_s3r_open(const char *url, const char *region, const char *id, const
*********************/

HDassert(handle->httpverb != NULL);
HDmemcpy(handle->httpverb, "GET", 4);
H5MM_memcpy(handle->httpverb, "GET", 4);

ret_value = handle;

Expand Down Expand Up @@ -2150,7 +2150,7 @@ H5FD_s3comms_nlowercase(char *dest, const char *s, size_t len)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be null.");

if (len > 0) {
HDmemcpy(dest, s, len);
H5MM_memcpy(dest, s, len);
do {
len--;
dest[len] = (char)HDtolower((int)dest[len]);
Expand Down Expand Up @@ -2686,14 +2686,14 @@ H5FD_s3comms_tostringtosign(char *dest, const char *req, const char *now, const
if (ret <= 0 || ret >= 127)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem adding day and region to string")

HDmemcpy((dest + d), "AWS4-HMAC-SHA256\n", 17);
H5MM_memcpy((dest + d), "AWS4-HMAC-SHA256\n", 17);
d = 17;

HDmemcpy((dest + d), now, HDstrlen(now));
H5MM_memcpy((dest + d), now, HDstrlen(now));
d += HDstrlen(now);
dest[d++] = '\n';

HDmemcpy((dest + d), tmp, HDstrlen(tmp));
H5MM_memcpy((dest + d), tmp, HDstrlen(tmp));
d += HDstrlen(tmp);
dest[d++] = '\n';

Expand Down Expand Up @@ -2777,7 +2777,7 @@ H5FD_s3comms_trim(char *dest, char *s, size_t s_len, size_t *n_written)
s_len++;

/* write output into dest */
HDmemcpy(dest, s, s_len);
H5MM_memcpy(dest, s, s_len);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/H5FDsplitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ H5FD__splitter_fapl_copy(const void *_old_fa)
if (NULL == new_fa_ptr)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL")

HDmemcpy(new_fa_ptr, old_fa_ptr, sizeof(H5FD_splitter_fapl_t));
H5MM_memcpy(new_fa_ptr, old_fa_ptr, sizeof(H5FD_splitter_fapl_t));
HDstrncpy(new_fa_ptr->wo_path, old_fa_ptr->wo_path, H5FD_SPLITTER_PATH_MAX);
HDstrncpy(new_fa_ptr->log_file_path, old_fa_ptr->log_file_path, H5FD_SPLITTER_PATH_MAX);

Expand Down Expand Up @@ -1300,14 +1300,14 @@ H5FD__splitter_log_error(const H5FD_splitter_t *file, const char *atfunc, const
char * s;

size = HDstrlen(atfunc) + HDstrlen(msg) + 3; /* ':', ' ', '\n' */
s = (char *)HDmalloc(sizeof(char) * (size + 1));
s = (char *)H5MM_malloc(sizeof(char) * (size + 1));
if (NULL == s)
ret_value = FAIL;
else if (size < (size_t)HDsnprintf(s, size + 1, "%s: %s\n", atfunc, msg))
ret_value = FAIL;
else if (size != HDfwrite(s, 1, size, file->logfp))
ret_value = FAIL;
HDfree(s);
H5MM_free(s);
}

FUNC_LEAVE_NOAPI(ret_value)
Expand Down
4 changes: 2 additions & 2 deletions src/H5Tref.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, s

/* Memory-to-memory conversion to support vlen conversion */
if (NULL == dst_file) {
HDmemcpy(dst_buf, src_buf, dst_size);
H5MM_memcpy(dst_buf, src_buf, dst_size);
HGOTO_DONE(ret_value);
}

Expand Down Expand Up @@ -602,7 +602,7 @@ H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size

/* Memory-to-memory conversion to support vlen conversion */
if (NULL == src_file) {
HDmemcpy(dst_buf, src_buf, src_size);
H5MM_memcpy(dst_buf, src_buf, src_size);
HGOTO_DONE(ret_value);
}

Expand Down

0 comments on commit 42d4cea

Please sign in to comment.