summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2012-01-02 13:31:46 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-02 15:08:19 +0100
commit16696ce49373d3ea2b4d12e28b85ca3275f73b82 (patch)
tree0db18bda1aade4adc4bb5fbaada6d4a6ea3149fa /src
parentfb7404e569b5c69dd9e1c6eab3157826442872e8 (diff)
downloadqtbase-16696ce49373d3ea2b4d12e28b85ca3275f73b82.tar.gz
corelib: Introduce Q_ALLOC_SIZE and use it on qMalloc and friends
GCC 4.3 introduced the alloc_size attribute to hint the compiler that allocated memory will be returned, inform the compiler which parameter holds the size of the allocation. Change-Id: I8734868f6bd19e201abdacd0a1b0fb80a27883c0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qglobal.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 785ee4a49a..ac721f19ba 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -487,6 +487,9 @@ namespace QT_NAMESPACE {}
# define QT_NO_ARM_EABI
# endif
# endif
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
+# define Q_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
+# endif
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
/* C++0x features supported in GCC 4.3: */
@@ -793,6 +796,10 @@ namespace QT_NAMESPACE {}
# define Q_UNLIKELY(x) (x)
#endif
+#ifndef Q_ALLOC_SIZE
+# define Q_ALLOC_SIZE(x)
+#endif
+
#ifndef Q_CONSTRUCTOR_FUNCTION
# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
namespace { \
@@ -2161,11 +2168,11 @@ Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE);
These functions make it possible to use standard C++ functions with
a similar name from Qt header files (especially template classes).
*/
-Q_CORE_EXPORT void *qMalloc(size_t size);
+Q_CORE_EXPORT void *qMalloc(size_t size) Q_ALLOC_SIZE(1);
Q_CORE_EXPORT void qFree(void *ptr);
-Q_CORE_EXPORT void *qRealloc(void *ptr, size_t size);
-Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment);
-Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment);
+Q_CORE_EXPORT void *qRealloc(void *ptr, size_t size) Q_ALLOC_SIZE(2);
+Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
+Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
Q_CORE_EXPORT void qFreeAligned(void *ptr);
Q_CORE_EXPORT void *qMemCopy(void *dest, const void *src, size_t n);
Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);