summaryrefslogtreecommitdiffstats
path: root/src/H5Shyper.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2015-09-26 23:52:42 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2015-09-26 23:52:42 (GMT)
commit8186a5cee10c41e97ba24b6fe1de9f6ce0c3902d (patch)
treeff9e92097542b930801522e1ce6c0ed5de72cecc /src/H5Shyper.c
parentaec3e1242d0d0f5c0fcbe796f2c2801c828e7efb (diff)
downloadhdf5-8186a5cee10c41e97ba24b6fe1de9f6ce0c3902d.zip
hdf5-8186a5cee10c41e97ba24b6fe1de9f6ce0c3902d.tar.gz
hdf5-8186a5cee10c41e97ba24b6fe1de9f6ce0c3902d.tar.bz2
[svn-r27884] Description:
Update dataspace selection encode/decode routines to avoid type aliasing errors. Tested on: Linux/64 2.6.x (platypus) w/production (h5committest forthcoming)
Diffstat (limited to 'src/H5Shyper.c')
-rw-r--r--src/H5Shyper.c76
1 files changed, 45 insertions, 31 deletions
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index 6b943d3..5ed1722 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -1977,14 +1977,14 @@ H5S_hyper_serial_size(const H5S_t *space)
PURPOSE
Serialize the current selection into a user-provided buffer.
USAGE
- herr_t H5S_hyper_serialize_helper(spans, start, end, rank, buf)
+ void H5S_hyper_serialize_helper(spans, start, end, rank, buf)
H5S_hyper_span_info_t *spans; IN: Hyperslab span tree to serialize
hssize_t start[]; IN/OUT: Accumulated start points
hssize_t end[]; IN/OUT: Accumulated end points
hsize_t rank; IN: Current rank looking at
uint8 *buf; OUT: Buffer to put serialized selection into
RETURNS
- Non-negative on success/Negative on failure
+ <none>
DESCRIPTION
Serializes the current element selection into a buffer. (Primarily for
storing on disk).
@@ -1993,13 +1993,13 @@ H5S_hyper_serial_size(const H5S_t *space)
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
-static herr_t
-H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans,
+static void
+H5S_hyper_serialize_helper(const H5S_hyper_span_info_t *spans,
hsize_t *start, hsize_t *end, hsize_t rank, uint8_t **p)
{
H5S_hyper_span_t *curr; /* Pointer to current hyperslab span */
+ uint8_t *pp = (*p); /* Local pointer for decoding */
hsize_t u; /* Index variable */
- herr_t ret_value=SUCCEED; /* return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -2008,7 +2008,7 @@ H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans,
HDassert(start);
HDassert(end);
HDassert(rank < H5O_LAYOUT_NDIMS);
- HDassert(p && *p);
+ HDassert(p && pp);
/* Walk through the list of spans, recursing or outputing them */
curr=spans->head;
@@ -2020,33 +2020,35 @@ H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans,
end[rank]=curr->high;
/* Recurse down to the next dimension */
- if(H5S_hyper_serialize_helper(curr->down,start,end,rank+1,p)<0)
- HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans")
+ *p = pp;
+ H5S_hyper_serialize_helper(curr->down, start, end, rank = 1, p);
} /* end if */
else {
/* Encode all the previous dimensions starting & ending points */
/* Encode previous starting points */
for(u=0; u<rank; u++)
- UINT32ENCODE(*p, (uint32_t)start[u]);
+ UINT32ENCODE(pp, (uint32_t)start[u]);
/* Encode starting point for this span */
- UINT32ENCODE(*p, (uint32_t)curr->low);
+ UINT32ENCODE(pp, (uint32_t)curr->low);
/* Encode previous ending points */
for(u=0; u<rank; u++)
- UINT32ENCODE(*p, (uint32_t)end[u]);
+ UINT32ENCODE(pp, (uint32_t)end[u]);
/* Encode starting point for this span */
- UINT32ENCODE(*p, (uint32_t)curr->high);
+ UINT32ENCODE(pp, (uint32_t)curr->high);
} /* end else */
/* Advance to next node */
curr=curr->next;
} /* end while */
-done:
- FUNC_LEAVE_NOAPI(ret_value)
+ /* Update encoding pointer */
+ *p = pp;
+
+ FUNC_LEAVE_NOAPI_VOID
} /* H5S_hyper_serialize_helper() */
@@ -2072,14 +2074,15 @@ done:
REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
-H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
+H5S_hyper_serialize(const H5S_t *space, uint8_t **p)
{
const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */
+ uint8_t *pp = (*p); /* Local pointer for decoding */
hsize_t tmp_count[H5O_LAYOUT_NDIMS]; /* Temporary hyperslab counts */
- hsize_t offset[H5O_LAYOUT_NDIMS]; /* Offset of element in dataspace */
+ hsize_t offset[H5O_LAYOUT_NDIMS]; /* Offset of element in dataspace */
hsize_t start[H5O_LAYOUT_NDIMS]; /* Location of start of hyperslab */
hsize_t end[H5O_LAYOUT_NDIMS]; /* Location of end of hyperslab */
- hsize_t temp_off; /* Offset in a given dimension */
+ hsize_t temp_off; /* Offset in a given dimension */
uint8_t *lenp; /* pointer to length location for later storage */
uint32_t len = 0; /* number of bytes used */
hsize_t block_count; /* block counter for regular hyperslabs */
@@ -2089,17 +2092,20 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
FUNC_ENTER_NOAPI_NOINIT_NOERR
+ /* Check args */
HDassert(space);
+ HDassert(p);
+ HDassert(pp);
/* Store the preamble information */
- UINT32ENCODE(*p, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */
- UINT32ENCODE(*p, (uint32_t)1); /* Store the version number */
- UINT32ENCODE(*p, (uint32_t)0); /* Store the un-used padding */
- lenp = *p; /* keep the pointer to the length location for later */
- *p += 4; /* skip over space for length */
+ UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */
+ UINT32ENCODE(pp, (uint32_t)1); /* Store the version number */
+ UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */
+ lenp = pp; /* keep the pointer to the length location for later */
+ pp += 4; /* skip over space for length */
/* Encode number of dimensions */
- UINT32ENCODE(*p, (uint32_t)space->extent.rank);
+ UINT32ENCODE(pp, (uint32_t)space->extent.rank);
len += 4;
/* Check for a "regular" hyperslab selection */
@@ -2117,7 +2123,7 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
/* Encode number of hyperslabs */
H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t);
- UINT32ENCODE(*p, (uint32_t)block_count);
+ UINT32ENCODE(pp, (uint32_t)block_count);
len+=4;
/* Now serialize the information for the regular hyperslab */
@@ -2140,11 +2146,11 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
/* Encode hyperslab starting location */
for(u = 0; u < ndims; u++)
- UINT32ENCODE(*p, (uint32_t)offset[u]);
+ UINT32ENCODE(pp, (uint32_t)offset[u]);
/* Encode hyperslab ending location */
for(u = 0; u < ndims; u++)
- UINT32ENCODE(*p, (uint32_t)(offset[u] + (diminfo[u].block - 1)));
+ UINT32ENCODE(pp, (uint32_t)(offset[u] + (diminfo[u].block - 1)));
/* Move the offset to the next sequence to start */
offset[fast_dim]+=diminfo[fast_dim].stride;
@@ -2195,7 +2201,7 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
/* Encode number of hyperslabs */
block_count = H5S_hyper_span_nblocks(space->select.sel_info.hslab->span_lst);
H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t);
- UINT32ENCODE(*p, (uint32_t)block_count);
+ UINT32ENCODE(pp, (uint32_t)block_count);
len+=4;
/* Add 8 bytes times the rank for each hyperslab selected */
@@ -2203,12 +2209,16 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
len += (uint32_t)(8 * space->extent.rank * block_count);
/* Encode each hyperslab in selection */
+ *p = pp;
H5S_hyper_serialize_helper(space->select.sel_info.hslab->span_lst, start, end, (hsize_t)0, p);
} /* end else */
/* Encode length */
UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */
+ /* Update encoding pointer */
+ *p = pp;
+
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_hyper_serialize() */
@@ -2238,6 +2248,7 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t **p)
static herr_t
H5S_hyper_deserialize(H5S_t *space, const uint8_t **p)
{
+ const uint8_t *pp = (*p); /* Local pointer for decoding */
unsigned rank; /* rank of points */
size_t num_elem=0; /* number of elements in selection */
hsize_t start[H5O_LAYOUT_NDIMS]; /* hyperslab start information */
@@ -2258,12 +2269,12 @@ H5S_hyper_deserialize(H5S_t *space, const uint8_t **p)
/* Check args */
HDassert(space);
HDassert(p);
- HDassert(*p);
+ HDassert(pp);
/* Deserialize slabs to select */
/* (The header and rank have already beed decoded) */
rank = space->extent.rank; /* Retrieve rank from space */
- UINT32DECODE(*p,num_elem); /* decode the number of points */
+ UINT32DECODE(pp,num_elem); /* decode the number of points */
/* Set the count & stride for all blocks */
for(tcount=count,tstride=stride,j=0; j<rank; j++,tstride++,tcount++) {
@@ -2275,11 +2286,11 @@ H5S_hyper_deserialize(H5S_t *space, const uint8_t **p)
for(i=0; i<num_elem; i++) {
/* Decode the starting points */
for(tstart=start,j=0; j<rank; j++,tstart++)
- UINT32DECODE(*p, *tstart);
+ UINT32DECODE(pp, *tstart);
/* Decode the ending points */
for(tend=end,j=0; j<rank; j++,tend++)
- UINT32DECODE(*p, *tend);
+ UINT32DECODE(pp, *tend);
/* Change the ending points into blocks */
for(tblock=block,tstart=start,tend=end,j=0; j<rank; j++,tstart++,tend++,tblock++)
@@ -2290,6 +2301,9 @@ H5S_hyper_deserialize(H5S_t *space, const uint8_t **p)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection")
} /* end for */
+ /* Update decoding pointer */
+ *p = pp;
+
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_hyper_deserialize() */