[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48723] trunk/blender: use gcc attrubutes to warn on unused return values and arguments which shouldnt be NULL .

Campbell Barton ideasman42 at gmail.com
Sun Jul 8 08:00:28 CEST 2012


Revision: 48723
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48723
Author:   campbellbarton
Date:     2012-07-08 06:00:27 +0000 (Sun, 08 Jul 2012)
Log Message:
-----------
use gcc attrubutes to warn on unused return values and arguments which shouldnt be NULL.

also remove IDP_AppendArray's return value which wasnt the new item in the array (which is odd/misleading), but wasnt used anywhere either.

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
    trunk/blender/intern/guardedalloc/intern/mallocn.c
    trunk/blender/source/blender/blenkernel/BKE_idprop.h
    trunk/blender/source/blender/blenkernel/BKE_lamp.h
    trunk/blender/source/blender/blenkernel/BKE_library.h
    trunk/blender/source/blender/blenkernel/intern/idprop.c
    trunk/blender/source/blender/blenkernel/intern/lamp.c
    trunk/blender/source/blender/blenlib/BLI_string.h
    trunk/blender/source/blender/compositor/intern/COM_CompositorContext.cpp
    trunk/blender/source/blender/makesrna/intern/rna_mesh_api.c
    trunk/blender/source/blender/modifiers/intern/MOD_multires.c
    trunk/blender/source/blender/python/intern/bpy_library.c

Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2012-07-08 05:00:16 UTC (rev 48722)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2012-07-08 06:00:27 UTC (rev 48723)
@@ -63,22 +63,6 @@
 #include <stdio.h> /* needed for FILE* */
 #include "MEM_sys_types.h" /* needed for uintptr_t */
 
-#ifndef WARN_UNUSED
-#  ifdef __GNUC__
-#    define WARN_UNUSED  __attribute__((warn_unused_result))
-#  else
-#    define WARN_UNUSED
-#  endif
-#endif
-
-#ifndef ALLOC_SIZE
-#  ifdef __GNUC__
-#    define ALLOC_SIZE(arg_pos)  __attribute__((alloc_size(arg_pos)))
-#  else
-#    define ALLOC_SIZE(arg_pos)
-#  endif
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -86,14 +70,22 @@
 	/** 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) WARN_UNUSED;
+	size_t MEM_allocN_len(void *vmemh)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+	__attribute__((nonnull))
+#endif
+	;
 
 	/**
 	 * Release memory previously allocatred by this module. 
 	 */
-	short MEM_freeN(void *vmemh);
+	short MEM_freeN(void *vmemh)
+#ifdef __GNUC__
+	__attribute__((nonnull))
+#endif
+	;
 
-
 	/**
 	 * Return zero if memory is not in allocated list
 	 */
@@ -102,30 +94,59 @@
 	/**
 	 * Duplicates a block of memory, and returns a pointer to the
 	 * newly allocated block.  */
-	void *MEM_dupallocN(void *vmemh) WARN_UNUSED;
+	void *MEM_dupallocN(void *vmemh)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+	__attribute__((nonnull))
+#endif
+	;
 
 	/**
 	 * Reallocates a block of memory, and returns pointer to the newly
 	 * allocated block, the old one is freed. this is not as optimized
 	 * as a system realloc but just makes a new allocation and copies
 	 * over from existing memory. */
-	void *MEM_reallocN(void *vmemh, size_t len) WARN_UNUSED ALLOC_SIZE(2);
+	void *MEM_reallocN(void *vmemh, size_t len)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+	__attribute__((nonnull))
+	__attribute__((alloc_size(2)))
+#endif
+	;
 
 	/**
 	 * 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) WARN_UNUSED ALLOC_SIZE(1);
+	void *MEM_callocN(size_t len, const char * str)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+	__attribute__((nonnull))
+	__attribute__((alloc_size(1)))
+#endif
+	;
 	
 	/** 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) WARN_UNUSED ALLOC_SIZE(1);
+	void *MEM_mallocN(size_t len, const char * str)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+	__attribute__((nonnull))
+	__attribute__((alloc_size(1)))
+#endif
+	;
 	
 	/** 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) WARN_UNUSED ALLOC_SIZE(1);
+	void *MEM_mapallocN(size_t len, const char * str)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+	__attribute__((nonnull))
+	__attribute__((alloc_size(1)))
+#endif
+	;
 
 	/** Print a list of the names and sizes of all allocated memory
 	 * blocks. as a python dict for easy investigation */ 
@@ -170,7 +191,11 @@
 	void MEM_reset_peak_memory(void);
 
 	/** Get the peak memory usage in bytes, including mmap allocations. */
-	uintptr_t MEM_get_peak_memory(void) WARN_UNUSED;
+	uintptr_t MEM_get_peak_memory(void)
+#ifdef __GNUC__
+	__attribute__((warn_unused_result))
+#endif
+	;
 
 #ifndef NDEBUG
 const char *MEM_name_ptr(void *vmemh);

Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c	2012-07-08 05:00:16 UTC (rev 48722)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c	2012-07-08 06:00:27 UTC (rev 48723)
@@ -163,6 +163,9 @@
 /* implementation                                                        */
 /* --------------------------------------------------------------------- */
 
+#ifdef __GNUC__
+__attribute__ ((format(printf, 1, 2)))
+#endif
 static void print_error(const char *str, ...)
 {
 	char buf[512];

Modified: trunk/blender/source/blender/blenkernel/BKE_idprop.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_idprop.h	2012-07-08 05:00:16 UTC (rev 48722)
+++ trunk/blender/source/blender/blenkernel/BKE_idprop.h	2012-07-08 06:00:27 UTC (rev 48723)
@@ -60,15 +60,30 @@
 
 /* note: as a start to move away from the stupid IDP_New function, this type
  * has it's own allocation function.*/
-IDProperty *IDP_NewIDPArray(const char *name);
-IDProperty *IDP_CopyIDPArray(IDProperty *array);
+IDProperty *IDP_NewIDPArray(const char *name)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull))
+#endif
+;
+IDProperty *IDP_CopyIDPArray(IDProperty *array)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull))
+#endif
+;
 
 void IDP_FreeIDPArray(IDProperty *prop);
 
 /* shallow copies item */
 void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item);
-struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index);
-struct IDProperty *IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
+struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull))
+#endif
+;
+void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
 void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
 
 /* ----------- Numeric Array Type ----------- */
@@ -77,12 +92,34 @@
 void IDP_FreeArray(struct IDProperty *prop);
 
 /* ---------- String Type ------------ */
-IDProperty *IDP_NewString(const char *st, const char *name, int maxlen); /* maxlen excludes '\0' */
-void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen); /* maxlen excludes '\0' */
-void IDP_ConcatStringC(struct IDProperty *prop, const char *st);
-void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append);
-void IDP_FreeString(struct IDProperty *prop);
+IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) /* maxlen excludes '\0' */
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull))
+#endif
+;
 
+void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) /* maxlen excludes '\0' */
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
+void IDP_ConcatStringC(struct IDProperty *prop, const char *st)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
+void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
+void IDP_FreeString(struct IDProperty *prop)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
+
 /*-------- ID Type -------*/
 void IDP_LinkID(struct IDProperty *prop, ID *id);
 void IDP_UnlinkID(struct IDProperty *prop);
@@ -90,17 +127,29 @@
 /*-------- Group Functions -------*/
 
 /** Sync values from one group to another, only where they match */
-void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src);
+void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 
 /**
  * replaces all properties with the same name in a destination group from a source group.
  */
-void IDP_ReplaceGroupInGroup(struct IDProperty *dest, struct IDProperty *src);
+void IDP_ReplaceGroupInGroup(struct IDProperty *dest, struct IDProperty *src)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 
 /**
  * Checks if a property with the same name as prop exists, and if so replaces it.
  * Use this to preserve order!*/
-void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop);
+void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 
 /**
  * This function has a sanity check to make sure ID properties with the same name don't
@@ -117,12 +166,20 @@
  * struct.  In the future this will just be IDP_FreeProperty and the code will
  * be reorganized to work properly.
  */
-int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop);
+int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 
 /** this is the same as IDP_AddToGroup, only you pass an item
  * in the group list to be inserted after. */
 int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous, 
-                      struct IDProperty *pnew);
+                      struct IDProperty *pnew)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 
 /** \note this does not free the property!!
  *
@@ -130,18 +187,36 @@
  * IDP_FreeProperty(prop); //free all subdata
  * MEM_freeN(prop); //free property struct itself
  */
-void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop);
+void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 
-IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name);
+IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull))
+#endif
+;
 /** same as above but ensure type match */
-IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type);
+IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull))
+#endif
+;
 
 /**
  * Get an iterator to iterate over the members of an id property group.
  * Note that this will automatically free the iterator once iteration is complete;
  * if you stop the iteration before hitting the end, make sure to call
  * IDP_FreeIterBeforeEnd(). */
-void *IDP_GetGroupIterator(struct IDProperty *prop);
+void *IDP_GetGroupIterator(struct IDProperty *prop)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list