[Scummvm-git-logs] scummvm master -> a035334cbdec8b618506156f13f274f81004fd8d

sev- sev at scummvm.org
Sun Sep 11 18:06:52 CEST 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a035334cbd IMAGE: Indeo: Replace memory-related functions with standard ones


Commit: a035334cbdec8b618506156f13f274f81004fd8d
    https://github.com/scummvm/scummvm/commit/a035334cbdec8b618506156f13f274f81004fd8d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-09-11T18:04:49+02:00

Commit Message:
IMAGE: Indeo: Replace memory-related functions with standard ones

Changed paths:
    image/codecs/indeo/indeo.cpp
    image/codecs/indeo/mem.cpp
    image/codecs/indeo/mem.h
    image/codecs/indeo/vlc.cpp



diff --git a/image/codecs/indeo/indeo.cpp b/image/codecs/indeo/indeo.cpp
index e54d6d4..44cfdf9 100644
--- a/image/codecs/indeo/indeo.cpp
+++ b/image/codecs/indeo/indeo.cpp
@@ -225,7 +225,7 @@ int IVIBandDesc::initTiles(IVITile *refTile, int p, int b, int tHeight, int tWid
 				_mbSize);
 
 			avFreeP(&tile->_mbs);
-			tile->_mbs = (IVIMbInfo *)avMallocZArray(tile->_numMBs, sizeof(IVIMbInfo));
+			tile->_mbs = (IVIMbInfo *)calloc(tile->_numMBs, sizeof(IVIMbInfo));
 			if (!tile->_mbs)
 				return -2;
 
@@ -284,7 +284,7 @@ int IVIPlaneDesc::initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool
 	planes[1]._numBands = planes[2]._numBands = cfg->_chromaBands;
 
 	for (int p = 0; p < 3; p++) {
-		planes[p]._bands = (IVIBandDesc *)avMallocZArray(planes[p]._numBands, sizeof(IVIBandDesc));
+		planes[p]._bands = (IVIBandDesc *)calloc(planes[p]._numBands, sizeof(IVIBandDesc));
 		if (!planes[p]._bands)
 			return -2;
 
@@ -311,20 +311,20 @@ int IVIPlaneDesc::initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool
 			band->_height = b_height;
 			band->_pitch = width_aligned;
 			band->_aHeight = height_aligned;
-			band->_bufs[0] = (int16 *)avMallocZ(bufSize);
-			band->_bufs[1] = (int16 *)avMallocZ(bufSize);
+			band->_bufs[0] = (int16 *)calloc(bufSize, 1);
+			band->_bufs[1] = (int16 *)calloc(bufSize, 1);
 			band->_bufSize = bufSize / 2;
 			if (!band->_bufs[0] || !band->_bufs[1])
 				return -2;
 
 			// allocate the 3rd band buffer for scalability mode
 			if (cfg->_lumaBands > 1) {
-				band->_bufs[2] = (int16 *)avMallocZ(bufSize);
+				band->_bufs[2] = (int16 *)calloc(bufSize, 1);
 				if (!band->_bufs[2])
 					return -2;
 			}
 			if (isIndeo4) {
-				band->_bufs[3] = (int16 *)avMallocZ(bufSize);
+				band->_bufs[3] = (int16 *)calloc(bufSize, 1);
 				if (!band->_bufs[3])
 					return -2;
 			}
@@ -358,7 +358,7 @@ int IVIPlaneDesc::initTiles(IVIPlaneDesc *planes, int tileWidth, int tileHeight)
 			band->_numTiles = xTiles * yTiles;
 
 			avFreeP(&band->_tiles);
-			band->_tiles = (IVITile *)avMallocZArray(band->_numTiles, sizeof(IVITile));
+			band->_tiles = (IVITile *)calloc(band->_numTiles, sizeof(IVITile));
 			if (!band->_tiles)
 				return -2;
 
@@ -420,7 +420,7 @@ int AVFrame::getBuffer(int flags) {
 	freeFrame();
 
 	// Luminance channel
-	_data[0] = (uint8 *)avMallocZ(_width * _height);
+	_data[0] = (uint8 *)calloc(_width * _height, 1);
 
 	// UV Chroma Channels
 	_data[1] = (uint8 *)malloc(_width * _height);
@@ -1072,7 +1072,7 @@ int IndeoDecoderBase::decodeBlocks(GetBits *_gb, IVIBandDesc *band, IVITile *til
 		if (_ctx._isIndeo4)
 			quant = avClipUintp2(quant, 5);
 		else
-			quant = av_clip((int)quant, 0, 23);
+			quant = CLIP((int)quant, 0, 23);
 
 		const uint8 *scaleTab = isIntra ? band->_intraScale : band->_interScale;
 		if (scaleTab)
diff --git a/image/codecs/indeo/mem.cpp b/image/codecs/indeo/mem.cpp
index ab28c34..736b3b4 100644
--- a/image/codecs/indeo/mem.cpp
+++ b/image/codecs/indeo/mem.cpp
@@ -83,34 +83,12 @@ static inline int avSizeMult(size_t a, size_t b, size_t *r) {
 
 /*------------------------------------------------------------------------*/
 
-void *avMallocZ(size_t size) {
-	void *ptr = malloc(size);
-	if (ptr)
-		memset(ptr, 0, size);
-
-	return ptr;
-}
-
-void *avMallocArray(size_t nmemb, size_t size) {
-	assert(size && nmemb < MAX_INTEGER / size);
-	return malloc(nmemb * size);
-}
-
-void *avMallocZArray(size_t nmemb, size_t size) {
-	assert(size && nmemb < MAX_INTEGER / size);
-	return avMallocZ(nmemb * size);
-}
-
 void avFreeP(void *arg) {
 	void **ptr = (void **)arg;
 	free(*ptr);
 	*ptr = nullptr;
 }
 
-static void *avRealloc(void *ptr, size_t size) {
-	return realloc(ptr, size + !size);
-}
-
 void *avReallocF(void *ptr, size_t nelem, size_t elsize) {
 	size_t size;
 	void *r;
@@ -119,7 +97,7 @@ void *avReallocF(void *ptr, size_t nelem, size_t elsize) {
 		free(ptr);
 		return nullptr;
 	}
-	r = avRealloc(ptr, size);
+	r = realloc(ptr, size);
 	if (!r)
 		free(ptr);
 
diff --git a/image/codecs/indeo/mem.h b/image/codecs/indeo/mem.h
index 8e889e5..c4001bd 100644
--- a/image/codecs/indeo/mem.h
+++ b/image/codecs/indeo/mem.h
@@ -40,45 +40,6 @@ namespace Indeo {
 #define MAX_INTEGER 0x7ffffff
 
 /**
- * Allocate a memory block with alignment suitable for all memory accesses
- * (including vectors if available on the CPU) and zero all the bytes of the
- * block.
- *
- * @param size Size in bytes for the memory block to be allocated
- * @return Pointer to the allocated block, or `NULL` if it cannot be allocated
- * @see av_malloc()
- */
-extern void *avMallocZ(size_t size);
-
-/**
- * Allocate a memory block for an array with av_malloc().
- *
- * The allocated memory will have size `size * nmemb` bytes.
- *
- * @param nmemb Number of element
- * @param size  Size of a single element
- * @return Pointer to the allocated block, or `NULL` if the block cannot
- *         be allocated
- * @see av_malloc()
- */
-extern void *avMallocArray(size_t nmemb, size_t size);
-
-/**
- * Allocate a memory block for an array with av_mallocz().
- *
- * The allocated memory will have size `size * nmemb` bytes.
- *
- * @param nmemb Number of elements
- * @param size  Size of the single element
- * @return Pointer to the allocated block, or `NULL` if the block cannot
- *         be allocated
- *
- * @see av_mallocz()
- * @see av_malloc_array()
- */
-extern void *avMallocZArray(size_t nmemb, size_t size);
-
-/**
  * Free a memory block which has been allocated with a function of av_malloc()
  * or av_realloc() family, and set the pointer pointing to it to `NULL`.
  *
@@ -131,15 +92,6 @@ extern uint8 avClipUint8(int a);
  */
 extern unsigned avClipUintp2(int a, int p);
 
-/**
-* Clip a signed integer value into the amin-amax range.
-* @param a value to clip
-* @param amin minimum value of the clip range
-* @param amax maximum value of the clip range
-* @return clipped value
-*/
-#define av_clip CLIP
-
 extern const uint8 ffZigZagDirect[64];
 
 } // End of namespace Indeo
diff --git a/image/codecs/indeo/vlc.cpp b/image/codecs/indeo/vlc.cpp
index baf3984..1793952 100644
--- a/image/codecs/indeo/vlc.cpp
+++ b/image/codecs/indeo/vlc.cpp
@@ -165,7 +165,7 @@ int VLC::init_vlc(int nbBits, int nbCodes, const void *p_bits, int bitsWrap,
 		vlc->_tableAllocated = 0;
 		vlc->_tableSize = 0;
 
-		buf = (VLCcode *)avMallocArray((nbCodes + 1), sizeof(VLCcode));
+		buf = (VLCcode *)malloc((nbCodes + 1) * sizeof(VLCcode));
 		assert(buf);
 	}
 





More information about the Scummvm-git-logs mailing list