diff --git a/scripts/astyle-all.sh b/scripts/astyle-all.sh old mode 100644 new mode 100755 diff --git a/scripts/astyle-rollback.sh b/scripts/astyle-rollback.sh old mode 100644 new mode 100755 diff --git a/scripts/astyle.sh b/scripts/astyle.sh old mode 100644 new mode 100755 diff --git a/src/core/qgis.cpp b/src/core/qgis.cpp index 1c6333b5e26..7a07cd81494 100644 --- a/src/core/qgis.cpp +++ b/src/core/qgis.cpp @@ -21,6 +21,7 @@ #endif #include #include "qgsconfig.h" +#include "qgslogger.h" #include @@ -104,3 +105,38 @@ QString QGis::tr( QGis::UnitType unit ) { return QCoreApplication::translate( "QGis::UnitType", qPrintable( toLiteral( unit ) ) ); } + +void *QgsMalloc( size_t size ) +{ + if ( size == 0 || long( size ) < 0 ) + { + QgsDebugMsg( QString( "Negative or zero size %1." ).arg( size ) ); + return NULL; + } + void *p = malloc( size ); + if ( p == NULL ) + { + QgsDebugMsg( QString( "Allocation of %1 bytes failed." ).arg( size ) ); + } + return p; +} + +void *QgsCalloc( size_t nmemb, size_t size ) +{ + if ( nmemb == 0 || long( nmemb ) < 0 || size == 0 || long( size ) < 0 ) + { + QgsDebugMsg( QString( "Negative or zero nmemb %1 or size %2." ).arg( nmemb ).arg( size ) ); + return NULL; + } + void *p = QgsMalloc( nmemb * size ); + if ( p != NULL ) + { + memset( p, 0, nmemb * size ); + } + return p; +} + +void QgsFree( void *ptr ) +{ + free( ptr ); +} diff --git a/src/core/qgis.h b/src/core/qgis.h index f2d51dd04dd..f2054a7faee 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -172,6 +173,25 @@ inline bool doubleNearSig( double a, double b, int significantDigits = 10 ) qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) ) ; } +/** Allocates size bytes and returns a pointer to the allocated memory. + Works like C malloc() but prints debug message by QgsLogger if allocation fails. + @param size size in bytes + */ +void *QgsMalloc( size_t size ); + +/** Allocates memory for an array of nmemb elements of size bytes each and returns + a pointer to the allocated memory. Works like C calloc() but prints debug message + by QgsLogger if allocation fails. + @param nmemb number of elements + @param size size of element in bytes + */ +void *QgsCalloc( size_t nmemb, size_t size ); + +/** Frees the memory space pointed to by ptr. Works like C free(). + @param ptr pointer to memory space + */ +void QgsFree( void *ptr ); + /** Wkt string that represents a geographic coord sys * @note added in 1.8 to replace GEOWkt */