Fixed the allocation of mobile arrays of mobile things so that the pointers in the new array are set to 0

This commit is contained in:
Neil Brown 2009-04-16 17:19:40 +00:00
parent 19cd8085d2
commit cdab6af65a
2 changed files with 25 additions and 5 deletions

View File

@ -2178,11 +2178,20 @@ cgenAllocMobile :: Meta -> A.Type -> Maybe A.Expression -> CGen()
cgenAllocMobile m (A.Mobile t@(A.Array ds innerT)) Nothing
| A.UnknownDimension `elem` ds = dieP m "Cannot allocate mobile array with unknown dimension"
| otherwise =
do tell ["MTAllocDataArray(wptr,"]
call genBytesIn m innerT (Left False)
tell [",", show $ length ds]
prefixComma $ [call genExpression e | A.Dimension e <- ds]
tell [")"]
do let elemSize = call genBytesIn m innerT (Left False)
numDims = show $ length ds
wrap alloc = do tell ["TockZeroMobileArray("]
alloc
tell [","]
elemSize
tell [",", numDims, ")"]
mobInner <- isMobileType innerT
(if mobInner then wrap else id) $ do
tell ["MTAllocDataArray(wptr,"]
elemSize
tell [",", numDims]
prefixComma $ [call genExpression e | A.Dimension e <- ds]
tell [")"]
cgenAllocMobile m (A.Mobile t) Nothing
= do tell ["MTAlloc(wptr,"]
mobileElemType False t

View File

@ -86,10 +86,21 @@ static inline void occam_RESIZE_MOBILE_ARRAY_1D (Workspace wptr, const int eleme
//}}}
//{{{ other mobile stuff
static inline void* TockMTLock(Workspace wptr, void* ptr, int lock) occam_unused;
static inline void* TockMTLock(Workspace wptr, void* ptr, int lock) {
MTLock(wptr, ptr, lock);
return ptr;
}
static inline mt_array_t* TockZeroMobileArray(mt_array_t* arr, int elem_size, int num_dims) occam_unused;
static inline mt_array_t* TockZeroMobileArray(mt_array_t* arr, int elem_size, int num_dims) {
int total_size = elem_size;
for (int i = 0; i < num_dims; i++) {
total_size *= arr->dimensions[i];
}
memset(arr->data, 0, total_size);
return arr;
}
//}}}
//{{{ top-level process interface