[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48911] trunk/blender: use gcc attributes for BLI alloc functions

Campbell Barton ideasman42 at gmail.com
Sat Jul 14 14:47:50 CEST 2012


Revision: 48911
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48911
Author:   campbellbarton
Date:     2012-07-14 12:47:49 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------
use gcc attributes for BLI alloc functions

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
    trunk/blender/intern/guardedalloc/intern/mallocn.c
    trunk/blender/source/blender/blenlib/BLI_memarena.h
    trunk/blender/source/blender/blenlib/BLI_mempool.h

Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2012-07-14 05:28:17 UTC (rev 48910)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2012-07-14 12:47:49 UTC (rev 48911)
@@ -60,8 +60,8 @@
 #ifndef __MEM_GUARDEDALLOC_H__
 #define __MEM_GUARDEDALLOC_H__
 
-#include <stdio.h> /* needed for FILE* */
-#include "MEM_sys_types.h" /* needed for uintptr_t */
+#include <stdio.h>          /* needed for FILE* */
+#include "MEM_sys_types.h"  /* needed for uintptr_t */
 
 #ifdef __cplusplus
 extern "C" {
@@ -70,7 +70,7 @@
 	/** Returns the length of the allocated memory segment pointed at
 	 * by vmemh. If the pointer was not previously allocated by this
 	 * module, the result is undefined.*/
-	size_t MEM_allocN_len(void *vmemh)
+	size_t MEM_allocN_len(const void *vmemh)
 #ifdef __GNUC__
 	__attribute__((warn_unused_result))
 #endif
@@ -111,10 +111,10 @@
 	 * Allocate a block of memory of size len, with tag name str. The
 	 * memory is cleared. The name must be static, because only a
 	 * pointer to it is stored ! */
-	void *MEM_callocN(size_t len, const char * str)
+	void *MEM_callocN(size_t len, const char *str)
 #ifdef __GNUC__
 	__attribute__((warn_unused_result))
-	__attribute__((nonnull))
+	__attribute__((nonnull(2)))
 	__attribute__((alloc_size(1)))
 #endif
 	;
@@ -122,10 +122,10 @@
 	/** Allocate a block of memory of size len, with tag name str. The
 	 * name must be a static, because only a pointer to it is stored !
 	 * */
-	void *MEM_mallocN(size_t len, const char * str)
+	void *MEM_mallocN(size_t len, const char *str)
 #ifdef __GNUC__
 	__attribute__((warn_unused_result))
-	__attribute__((nonnull))
+	__attribute__((nonnull(2)))
 	__attribute__((alloc_size(1)))
 #endif
 	;
@@ -133,10 +133,10 @@
 	/** Same as callocN, clears memory and uses mmap (disk cached) if supported.
 	 * Can be free'd with MEM_freeN as usual.
 	 * */
-	void *MEM_mapallocN(size_t len, const char * str)
+	void *MEM_mapallocN(size_t len, const char *str)
 #ifdef __GNUC__
 	__attribute__((warn_unused_result))
-	__attribute__((nonnull))
+	__attribute__((nonnull(2)))
 	__attribute__((alloc_size(1)))
 #endif
 	;
@@ -213,11 +213,10 @@
 			MEM_freeN(mem);                                                   \
 	}                                                                         \
 
-#endif
+#endif  /* __cplusplus */
 
-
 #ifdef __cplusplus
 }
-#endif
+#endif  /* __cplusplus */
 
-#endif
+#endif  /* __MEM_GUARDEDALLOC_H__ */

Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c	2012-07-14 05:28:17 UTC (rev 48910)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c	2012-07-14 12:47:49 UTC (rev 48911)
@@ -222,10 +222,10 @@
 	malloc_debug_memset = 1;
 }
 
-size_t MEM_allocN_len(void *vmemh)
+size_t MEM_allocN_len(const void *vmemh)
 {
 	if (vmemh) {
-		MemHead *memh = vmemh;
+		const MemHead *memh = vmemh;
 	
 		memh--;
 		return memh->len;

Modified: trunk/blender/source/blender/blenlib/BLI_memarena.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_memarena.h	2012-07-14 05:28:17 UTC (rev 48910)
+++ trunk/blender/source/blender/blenlib/BLI_memarena.h	2012-07-14 12:47:49 UTC (rev 48911)
@@ -50,16 +50,43 @@
 struct MemArena;
 typedef struct MemArena MemArena;
 
+struct MemArena    *BLI_memarena_new(const int bufsize, const char *name)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(2)))
+#endif
+;
 
-struct MemArena    *BLI_memarena_new(int bufsize, const char *name);
-void                BLI_memarena_free(struct MemArena *ma);
+void                BLI_memarena_free(struct MemArena *ma)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
 
-void                BLI_memarena_use_malloc(struct MemArena *ma);
-void                BLI_memarena_use_calloc(struct MemArena *ma);
+void                BLI_memarena_use_malloc(struct MemArena *ma)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
+void                BLI_memarena_use_calloc(struct MemArena *ma)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
 
-void                BLI_memarena_use_align(struct MemArena *ma, int align);
+void                BLI_memarena_use_align(struct MemArena *ma, const int align)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
 
-void               *BLI_memarena_alloc(struct MemArena *ma, int size);
+void               *BLI_memarena_alloc(struct MemArena *ma, int size)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+__attribute__((alloc_size(2)))
+#endif
+;
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h	2012-07-14 05:28:17 UTC (rev 48910)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h	2012-07-14 12:47:49 UTC (rev 48911)
@@ -48,16 +48,47 @@
  * first four bytes of the elements never contain the character string
  * 'free'.  use with care.*/
 
-BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag);
-void *BLI_mempool_alloc(BLI_mempool *pool);
-void *BLI_mempool_calloc(BLI_mempool *pool);
-void  BLI_mempool_free(BLI_mempool *pool, void *addr);
-void  BLI_mempool_destroy(BLI_mempool *pool);
-int   BLI_mempool_count(BLI_mempool *pool);
-void *BLI_mempool_findelem(BLI_mempool *pool, int index);
+BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+#endif
+;
+void        *BLI_mempool_alloc(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
+void        *BLI_mempool_calloc(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
+void         BLI_mempool_free(BLI_mempool *pool, void *addr)
+#ifdef __GNUC__
+__attribute__((nonnull(1, 2)))
+#endif
+;
+void         BLI_mempool_destroy(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
+int          BLI_mempool_count(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
+void        *BLI_mempool_findelem(BLI_mempool *pool, int index)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
 
 /** iteration stuff.  note: this may easy to produce bugs with **/
-/*private structure*/
+/* private structure */
 typedef struct BLI_mempool_iter {
 	BLI_mempool *pool;
 	struct BLI_mempool_chunk *curchunk;
@@ -70,11 +101,20 @@
 	BLI_MEMPOOL_ALLOW_ITER = (1 << 1)
 };
 
-void  BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter);
-void *BLI_mempool_iterstep(BLI_mempool_iter *iter);
+void  BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
+#ifdef __GNUC__
+__attribute__((nonnull(1, 2)))
+#endif
+;
+void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif
+#endif  /* __BLI_MEMPOOL_H__ */




More information about the Bf-blender-cvs mailing list