Skip to content

Commit

Permalink
Fix C macro names reserved by C99 for _RND
Browse files Browse the repository at this point in the history
C99: All identifiers that begin with an underscore and either an
     uppercase letter or another underscore are always reserved for any
     use.
This replaces all _RND with PNETCDF_RND
  • Loading branch information
wkliao committed Oct 17, 2024
1 parent e9aad60 commit c920993
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/drivers/ncmpio/ncmpio_attr.m4
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ x_len_NC_attrV(nc_type xtype,
switch(xtype) {
case NC_BYTE:
case NC_CHAR:
case NC_UBYTE: return _RNDUP(nelems, 4);
case NC_UBYTE: return PNETCDF_RNDUP(nelems, 4);
case NC_SHORT:
case NC_USHORT: return ((nelems + nelems%2) * 2);
case NC_INT:
Expand Down Expand Up @@ -188,7 +188,7 @@ ncmpio_dup_NC_attrarray(NC_attrarray *ncap, const NC_attrarray *ref)
}

if (ref->ndefined > 0) {
size_t alloc_size = _RNDUP(ref->ndefined, PNC_ARRAY_GROWBY);
size_t alloc_size = PNETCDF_RNDUP(ref->ndefined, PNC_ARRAY_GROWBY);
ncap->value = (NC_attr **) NCI_Calloc(alloc_size, sizeof(NC_attr*));
if (ncap->value == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)
}
Expand Down Expand Up @@ -980,10 +980,10 @@ ncmpio_put_att(void *ncdp,

/* sanity checks for varid, name, xtype has been done in dispatcher */

/* If this is the _FillValue attribute, then let PnetCDF return the
/* If this is attribute _FillValue, then let PnetCDF return the
* same error codes as netCDF
*/
if (varid != NC_GLOBAL && !strcmp(name, _FillValue)) {
if (varid != NC_GLOBAL && !strcmp(name, NC_FillValue)) {
/* Fill value must be of the same data type */
if (xtype != ncp->vars.value[varid]->xtype) {
DEBUG_ASSIGN_ERROR(err, NC_EBADTYPE)
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ncmpio/ncmpio_dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ncmpio_dup_NC_dimarray(NC_dimarray *ncap, const NC_dimarray *ref)

/* allocate array of NC_dim objects */
if (ref->ndefined > 0) {
size_t alloc_size = _RNDUP(ref->ndefined, PNC_ARRAY_GROWBY);
size_t alloc_size = PNETCDF_RNDUP(ref->ndefined, PNC_ARRAY_GROWBY);
ncap->value = (NC_dim**) NCI_Calloc(alloc_size, sizeof(NC_dim*));
if (ncap->value == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ncmpio/ncmpio_enddef.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ write_NC(NC *ncp)
header_wlen = ncp->xsz;
#endif

header_wlen = _RNDUP(header_wlen, X_ALIGN);
header_wlen = PNETCDF_RNDUP(header_wlen, X_ALIGN);

/* if header_wlen is > NC_MAX_INT, then write the header in chunks.
* Note reading file header is already done in chunks. See
Expand Down
40 changes: 20 additions & 20 deletions src/drivers/ncmpio/ncmpio_header_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ hdr_len_NC_name(const NC_string *ncstrp, int sizeof_NON_NEG)
assert(ncstrp != NULL);

if (ncstrp->nchars != 0) /* namestring */
sz += _RNDUP(ncstrp->nchars, X_ALIGN);
sz += PNETCDF_RNDUP(ncstrp->nchars, X_ALIGN);

return sz;
}
Expand All @@ -133,8 +133,8 @@ hdr_len_NC_dim(const NC_dim *dimp, int sizeof_NON_NEG)

assert(dimp != NULL);

sz = sizeof_NON_NEG + _RNDUP(dimp->name_len, X_ALIGN); /* name */
sz += sizeof_NON_NEG; /* dim_length */
sz = sizeof_NON_NEG + PNETCDF_RNDUP(dimp->name_len, X_ALIGN); /* name */
sz += sizeof_NON_NEG; /* dim_length */

return sz;
}
Expand Down Expand Up @@ -195,10 +195,10 @@ hdr_len_NC_attr(const NC_attr *attrp, int sizeof_NON_NEG)

assert(attrp != NULL);

sz = sizeof_NON_NEG + _RNDUP(attrp->name_len, X_ALIGN); /* name */
sz += X_SIZEOF_NC_TYPE; /* nc_type */
sz += sizeof_NON_NEG; /* nelems */
sz += attrp->xsz; /* [values ...] */
sz = sizeof_NON_NEG + PNETCDF_RNDUP(attrp->name_len, X_ALIGN); /* name */
sz += X_SIZEOF_NC_TYPE; /* nc_type */
sz += sizeof_NON_NEG; /* nelems */
sz += attrp->xsz; /* [values ...] */

return sz;
}
Expand Down Expand Up @@ -264,13 +264,13 @@ hdr_len_NC_var(const NC_var *varp,
* for CDF-2, sizeof_off_t == 8 && sizeof_NON_NEG == 4
* for CDF-5, sizeof_off_t == 8 && sizeof_NON_NEG == 8
*/
sz = sizeof_NON_NEG + _RNDUP(varp->name_len, X_ALIGN); /* name */
sz += sizeof_NON_NEG; /* nelems */
sz += sizeof_NON_NEG * varp->ndims; /* [dimid ...] */
sz += hdr_len_NC_attrarray(&varp->attrs, sizeof_NON_NEG); /* vatt_list */
sz += X_SIZEOF_NC_TYPE; /* nc_type */
sz += sizeof_NON_NEG; /* vsize */
sz += sizeof_off_t; /* begin */
sz = sizeof_NON_NEG + PNETCDF_RNDUP(varp->name_len, X_ALIGN); /* name */
sz += sizeof_NON_NEG; /* nelems */
sz += sizeof_NON_NEG * varp->ndims; /* [dimid ...] */
sz += hdr_len_NC_attrarray(&varp->attrs, sizeof_NON_NEG); /* vatt_list */
sz += X_SIZEOF_NC_TYPE; /* nc_type */
sz += sizeof_NON_NEG; /* vsize */
sz += sizeof_off_t; /* begin */

return sz;
}
Expand Down Expand Up @@ -553,9 +553,9 @@ hdr_get_NC_name(bufferinfo *gbp, char **namep, size_t *name_len)
(*namep)[nchars] = '\0'; /* add terminal character */

/* X_SIZEOF_CHAR is defined as 1 in classical CDF formats
padding = _RNDUP(X_SIZEOF_CHAR * nchars, X_ALIGN) - X_SIZEOF_CHAR * nchars;
padding = PNETCDF_RNDUP(X_SIZEOF_CHAR * nchars, X_ALIGN) - X_SIZEOF_CHAR * nchars;
*/
padding = _RNDUP(nchars, X_ALIGN) - nchars;
padding = PNETCDF_RNDUP(nchars, X_ALIGN) - nchars;

bufremain = gbp->chunk - (gbp->pos - gbp->base);

Expand Down Expand Up @@ -759,7 +759,7 @@ hdr_get_NC_dimarray(bufferinfo *gbp, NC_dimarray *ncap)
DEBUG_RETURN_ERROR(NC_ENOTNC)
}

alloc_size = _RNDUP(ncap->ndefined, PNC_ARRAY_GROWBY);
alloc_size = PNETCDF_RNDUP(ncap->ndefined, PNC_ARRAY_GROWBY);
ncap->value = (NC_dim**) NCI_Calloc(alloc_size, sizeof(NC_dim*));
if (ncap->value == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)

Expand Down Expand Up @@ -1004,7 +1004,7 @@ hdr_get_NC_attrarray(bufferinfo *gbp, NC_attrarray *ncap)
DEBUG_RETURN_ERROR(NC_ENOTNC)
}

alloc_size = _RNDUP(ncap->ndefined, PNC_ARRAY_GROWBY);
alloc_size = PNETCDF_RNDUP(ncap->ndefined, PNC_ARRAY_GROWBY);
ncap->value = (NC_attr**) NCI_Calloc(alloc_size, sizeof(NC_attr*));
if (ncap->value == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)

Expand Down Expand Up @@ -1250,7 +1250,7 @@ hdr_get_NC_vararray(bufferinfo *gbp,
DEBUG_RETURN_ERROR(NC_ENOTNC)
}

alloc_size = _RNDUP(ncap->ndefined, PNC_ARRAY_GROWBY);
alloc_size = PNETCDF_RNDUP(ncap->ndefined, PNC_ARRAY_GROWBY);
ncap->value = (NC_var**) NCI_Calloc(alloc_size, sizeof(NC_var*));
if (ncap->value == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)

Expand Down Expand Up @@ -1343,7 +1343,7 @@ ncmpio_hdr_get_NC(NC *ncp)
getbuf.coll_mode = 0;

/* CDF-5's minimum header size is 4 bytes more than CDF-1 and CDF-2's */
getbuf.chunk = _RNDUP( MAX(MIN_NC_XSZ+4, ncp->chunk), X_ALIGN );
getbuf.chunk = PNETCDF_RNDUP( MAX(MIN_NC_XSZ+4, ncp->chunk), X_ALIGN );

getbuf.base = (char*) NCI_Malloc(getbuf.chunk);
getbuf.pos = getbuf.base;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ncmpio/ncmpio_header_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ int ncmpio_write_header(NC *ncp)
if (ncp->rank == 0) { /* only root writes to file header */
MPI_Offset offset;
size_t remain;
size_t bufLen = _RNDUP(ncp->xsz, X_ALIGN);
size_t bufLen = PNETCDF_RNDUP(ncp->xsz, X_ALIGN);
char *buf, *buf_ptr;

buf = NCI_Malloc(bufLen); /* header's write buffer */
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ncmpio/ncmpio_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ncmpio_dup_NC_vararray(NC_vararray *ncap,
return NC_NOERR;
}

alloc_size = _RNDUP(ref->ndefined, PNC_ARRAY_GROWBY);
alloc_size = PNETCDF_RNDUP(ref->ndefined, PNC_ARRAY_GROWBY);
ncap->value = (NC_var **) NCI_Calloc(alloc_size, sizeof(NC_var*));
if (ncap->value == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)

Expand Down
12 changes: 6 additions & 6 deletions src/utils/ncoffsets/ncoffsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ typedef enum {
#define X_ALIGN 4

/* useful for aligning memory */
#define _RNDUP(x, unit) ((((x) + (unit) - 1) / (unit)) * (unit))
#define PNETCDF_RNDUP(x, unit) ((((x) + (unit) - 1) / (unit)) * (unit))
#define M_RND_UNIT X_SIZEOF_DOUBLE
#define M_RNDUP(x) _RNDUP(x, M_RND_UNIT)
#define M_RNDUP(x) PNETCDF_RNDUP(x, M_RND_UNIT)

#define ncmpix_len_char(nelems) _RNDUP((nelems), X_ALIGN)
#define ncmpix_len_char(nelems) PNETCDF_RNDUP((nelems), X_ALIGN)
#define ncmpix_len_short(nelems) (((nelems) + (nelems)%2) * X_SIZEOF_SHORT)
#define ncmpix_len_int(nelems) ((nelems) * X_SIZEOF_INT)
#define ncmpix_len_long(nelems) ((nelems) * X_SIZEOF_LONG)
#define ncmpix_len_float(nelems) ((nelems) * X_SIZEOF_FLOAT)
#define ncmpix_len_double(nelems) ((nelems) * X_SIZEOF_DOUBLE)
#define ncmpix_len_ubyte(nelems) _RNDUP((nelems), X_ALIGN)
#define ncmpix_len_ubyte(nelems) PNETCDF_RNDUP((nelems), X_ALIGN)
#define ncmpix_len_ushort(nelems) (((nelems) + (nelems)%2) * X_SIZEOF_USHORT)
#define ncmpix_len_uint(nelems) ((nelems) * X_SIZEOF_UINT)
#define ncmpix_len_int64(nelems) ((nelems) * X_SIZEOF_INT64)
Expand Down Expand Up @@ -534,7 +534,7 @@ hdr_len_NC_name(const NC_string *ncstrp,
assert(ncstrp != NULL);

if (ncstrp->nchars != 0) /* namestring */
sz += _RNDUP(ncstrp->nchars, X_ALIGN);
sz += PNETCDF_RNDUP(ncstrp->nchars, X_ALIGN);

return sz;
}
Expand Down Expand Up @@ -919,7 +919,7 @@ hdr_get_NC_name(bufferinfo *gbp,
ncstrp = ncmpii_new_NC_string(nchars, NULL);

nbytes = nchars;
padding = _RNDUP(ncstrp->nchars, X_ALIGN) - ncstrp->nchars;
padding = PNETCDF_RNDUP(ncstrp->nchars, X_ALIGN) - ncstrp->nchars;
bufremain = gbp->size - ((char*)gbp->pos - (char*)gbp->base);
cpos = ncstrp->cp;

Expand Down
8 changes: 4 additions & 4 deletions src/utils/ncvalidator/ncvalidator.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static const char *off_limit = "https://docs.unidata.ucar.edu/nug/current/file_s
#endif

/* useful for aligning memory */
#define _RNDUP(x, unit) ((((x) + (unit) - 1) / (unit)) * (unit))
#define PNETCDF_RNDUP(x, unit) ((((x) + (unit) - 1) / (unit)) * (unit))

#define ERR_ADDR (((size_t)gbp->pos - (size_t)gbp->base) + (size_t)(gbp->offset - gbp->size))

Expand Down Expand Up @@ -368,7 +368,7 @@ hdr_len_NC_name(size_t nchars,
long long sz = sizeof_t; /* nelems */

if (nchars != 0) /* namestring */
sz += _RNDUP(nchars, X_ALIGN);
sz += PNETCDF_RNDUP(nchars, X_ALIGN);

return sz;
}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ hdr_get_name(int fd,
if (*namep == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM)
(*namep)[nchars] = '\0'; /* add terminal character */

padding = _RNDUP(nchars, X_ALIGN) - nchars;
padding = PNETCDF_RNDUP(nchars, X_ALIGN) - nchars;
pos_addr = (size_t) gbp->pos;
base_addr = (size_t) gbp->base;
bufremain = gbp->size - (pos_addr - base_addr);
Expand Down Expand Up @@ -1347,7 +1347,7 @@ x_len_NC_attrV(nc_type xtype,
switch(xtype) {
case NC_BYTE:
case NC_CHAR:
case NC_UBYTE: return _RNDUP(nelems, 4);
case NC_UBYTE: return PNETCDF_RNDUP(nelems, 4);
case NC_SHORT:
case NC_USHORT: return ((nelems + (nelems)%2) * 2);
case NC_INT: return (nelems * 4);
Expand Down
6 changes: 3 additions & 3 deletions test/testcases/tst_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include <testutils.h>

#define _RNDUP(x, unit) ((((x) + (unit) - 1) / (unit)) * (unit))
#define PNETCDF_RNDUP(x, unit) ((((x) + (unit) - 1) / (unit)) * (unit))

#define CHECK_HINT(hint) { \
MPI_Info_get(info_used, hint, len, value, &flag); \
Expand Down Expand Up @@ -156,7 +156,7 @@ int main(int argc, char** argv) {
MPI_Info_get_valuelen(info_used, "nc_header_align_size", &len, &flag);
if (flag) {
MPI_Info_get(info_used, "nc_header_align_size", len+1, value, &flag);
expect = _RNDUP(1, 4);
expect = PNETCDF_RNDUP(1, 4);
if (expect != strtoll(value,NULL,10)) {
printf("Error: nc_header_align_size expect %lld but got %lld\n",
expect, strtoll(value,NULL,10));
Expand All @@ -170,7 +170,7 @@ int main(int argc, char** argv) {
MPI_Info_get_valuelen(info_used, "nc_var_align_size", &len, &flag);
if (flag) {
MPI_Info_get(info_used, "nc_var_align_size", len+1, value, &flag);
expect = _RNDUP(197, 4);
expect = PNETCDF_RNDUP(197, 4);
if (expect != strtoll(value,NULL,10)) {
printf("Error: nc_var_align_size expect %lld but got %lld\n",
expect, strtoll(value,NULL,10));
Expand Down

0 comments on commit c920993

Please sign in to comment.