[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58944] trunk/blender: use gcc malloc attribute for low level allocation functions, prevents gcc from checking if resulting pointers alias existing pointers, also use sentinel attribute for uiButGetStrInfo so incorrect usage gives a warning .

Campbell Barton ideasman42 at gmail.com
Mon Aug 5 22:57:13 CEST 2013


Revision: 58944
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58944
Author:   campbellbarton
Date:     2013-08-05 20:57:13 +0000 (Mon, 05 Aug 2013)
Log Message:
-----------
use gcc malloc attribute for low level allocation functions, prevents gcc from checking if resulting pointers alias existing pointers, also use sentinel attribute for uiButGetStrInfo so incorrect usage gives a warning.

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
    trunk/blender/source/blender/blenlib/BLI_memarena.h
    trunk/blender/source/blender/blenlib/BLI_mempool.h
    trunk/blender/source/blender/blenlib/BLI_string.h
    trunk/blender/source/blender/editors/include/UI_interface.h

Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2013-08-05 19:16:52 UTC (rev 58943)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2013-08-05 20:57:13 UTC (rev 58944)
@@ -98,6 +98,7 @@
 	 * newly allocated block.  */
 	void *MEM_dupallocN(const void *vmemh)
 #if MEM_GNU_ATTRIBUTES
+	__attribute__((malloc))
 	__attribute__((warn_unused_result))
 #endif
 	;
@@ -109,6 +110,7 @@
 	 * over from existing memory. */
 	void *MEM_reallocN_id(void *vmemh, size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
+	__attribute__((malloc))
 	__attribute__((warn_unused_result))
 	__attribute__((alloc_size(2)))
 #endif
@@ -119,6 +121,7 @@
 	 */
 	void *MEM_recallocN_id(void *vmemh, size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
+	__attribute__((malloc))
 	__attribute__((warn_unused_result))
 	__attribute__((alloc_size(2)))
 #endif
@@ -133,6 +136,7 @@
 	 * pointer to it is stored ! */
 	void *MEM_callocN(size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
+	__attribute__((malloc))
 	__attribute__((warn_unused_result))
 	__attribute__((nonnull(2)))
 	__attribute__((alloc_size(1)))
@@ -145,6 +149,7 @@
 	 * */
 	void *MEM_mallocN(size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
+	__attribute__((malloc))
 	__attribute__((warn_unused_result))
 	__attribute__((nonnull(2)))
 	__attribute__((alloc_size(1)))
@@ -157,6 +162,7 @@
 	 * */
 	void *MEM_mapallocN(size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
+	__attribute__((malloc))
 	__attribute__((warn_unused_result))
 	__attribute__((nonnull(2)))
 	__attribute__((alloc_size(1)))

Modified: trunk/blender/source/blender/blenlib/BLI_memarena.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_memarena.h	2013-08-05 19:16:52 UTC (rev 58943)
+++ trunk/blender/source/blender/blenlib/BLI_memarena.h	2013-08-05 20:57:13 UTC (rev 58944)
@@ -55,6 +55,7 @@
 
 struct MemArena    *BLI_memarena_new(const int bufsize, const char *name)
 #if MEM_GNU_ATTRIBUTES
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull(2)))
 #endif
@@ -85,6 +86,7 @@
 
 void               *BLI_memarena_alloc(struct MemArena *ma, int size)
 #if MEM_GNU_ATTRIBUTES
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull(1)))
 __attribute__((alloc_size(2)))

Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h	2013-08-05 19:16:52 UTC (rev 58943)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h	2013-08-05 20:57:13 UTC (rev 58944)
@@ -50,17 +50,20 @@
 
 BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 #endif
 ;
 void        *BLI_mempool_alloc(BLI_mempool *pool)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull(1)))
 #endif
 ;
 void        *BLI_mempool_calloc(BLI_mempool *pool)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull(1)))
 #endif
@@ -94,6 +97,7 @@
 
 void      **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull(1, 2)))
 #endif
@@ -107,6 +111,7 @@
 
 void       *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull(1, 2)))
 #endif

Modified: trunk/blender/source/blender/blenlib/BLI_string.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string.h	2013-08-05 19:16:52 UTC (rev 58943)
+++ trunk/blender/source/blender/blenlib/BLI_string.h	2013-08-05 20:57:13 UTC (rev 58944)
@@ -40,6 +40,7 @@
 
 char *BLI_strdupn(const char *str, const size_t len)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull))
 #endif
@@ -47,6 +48,7 @@
 
 char *BLI_strdup(const char *str)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull))
 #endif
@@ -54,6 +56,7 @@
 
 char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull))
 #endif
@@ -81,6 +84,7 @@
 
 char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull))
 #endif
@@ -88,6 +92,7 @@
 
 char *BLI_replacestrN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__((warn_unused_result))
 __attribute__((nonnull))
 #endif
@@ -108,6 +113,7 @@
 
 char *BLI_sprintfN(const char *__restrict format, ...)
 #ifdef __GNUC__
+__attribute__((malloc))
 __attribute__ ((format(printf, 1, 2)))
 __attribute__((warn_unused_result))
 __attribute__((nonnull))
@@ -183,4 +189,4 @@
 }
 #endif
 
-#endif
+#endif  /* __BLI_STRING_H__ */

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2013-08-05 19:16:52 UTC (rev 58943)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2013-08-05 20:57:13 UTC (rev 58944)
@@ -550,7 +550,11 @@
 /* Note: Expects pointers to uiStringInfo structs as parameters.
  *       Will fill them with translated strings, when possible.
  *       Strings in uiStringInfo must be MEM_freeN'ed by caller. */
-void uiButGetStrInfo(struct bContext *C, uiBut *but, ...);
+void uiButGetStrInfo(struct bContext *C, uiBut *but, ...)
+#ifdef __GNUC__
+__attribute__((sentinel))
+#endif
+;
 
 /* Edit i18n stuff. */
 /* Name of the main py op from i18n addon. */




More information about the Bf-blender-cvs mailing list