[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41102] branches/bmesh/blender/source/ blender/blenlib/BLI_array.h: formatting to BLI_array to make it easier to follow, also give line numbers with unfreed memory.
Campbell Barton
ideasman42 at gmail.com
Tue Oct 18 05:48:55 CEST 2011
Revision: 41102
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41102
Author: campbellbarton
Date: 2011-10-18 03:48:53 +0000 (Tue, 18 Oct 2011)
Log Message:
-----------
formatting to BLI_array to make it easier to follow, also give line numbers with unfreed memory.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenlib/BLI_array.h
Modified: branches/bmesh/blender/source/blender/blenlib/BLI_array.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_array.h 2011-10-18 02:58:05 UTC (rev 41101)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_array.h 2011-10-18 03:48:53 UTC (rev 41102)
@@ -56,47 +56,107 @@
behaviour, though it may not be the best in practice.
*/
-#define BLI_array_declare(arr) int _##arr##_count=0; void *_##arr##_tmp; void *_##arr##_static = NULL
+#define BLI_array_declare(arr) \
+ int _##arr##_count=0; \
+ void *_##arr##_tmp; \
+ void *_##arr##_static = NULL
-/*this will use stack space, up to maxstatic array elements, befoe
- switching to dynamic heap allocation*/
-#define BLI_array_staticdeclare(arr, maxstatic) int _##arr##_count=0; void *_##arr##_tmp; char _##arr##_static[maxstatic*sizeof(arr)]
+/* this will use stack space, up to maxstatic array elements, befoe
+ * switching to dynamic heap allocation */
+#define BLI_array_staticdeclare(arr, maxstatic) \
+ int _##arr##_count=0; \
+ void *_##arr##_tmp; \
+ char _##arr##_static[maxstatic*sizeof(arr)]
-/*this returns the entire size of the array, including any buffering.*/
-#define BLI_array_totalsize_dyn(arr) ((arr)==NULL ? 0 : MEM_allocN_len(arr) / sizeof(*arr))
-#define BLI_array_totalsize(arr) ((signed int)(((void *)(arr) == (void *)_##arr##_static && (void *)(arr) != NULL) ? (sizeof(_##arr##_static) / sizeof(*arr)) : BLI_array_totalsize_dyn(arr)))
-/*this returns the logical size of the array, not including buffering.*/
+/* this returns the entire size of the array, including any buffering. */
+#define BLI_array_totalsize_dyn(arr) ( \
+ ((arr)==NULL) ? \
+ 0 : \
+ MEM_allocN_len(arr) / sizeof(*arr) \
+)
+
+
+#define BLI_array_totalsize(arr) ( \
+ (signed int) \
+ (((void *)(arr) == (void *)_##arr##_static && (void *)(arr) != NULL) ? \
+ (sizeof(_##arr##_static) / sizeof(*arr)) : \
+ BLI_array_totalsize_dyn(arr)) \
+)
+
+
+/* this returns the logical size of the array, not including buffering. */
#define BLI_array_count(arr) _##arr##_count
-/*grow the array by one. zeroes the new elements.*/
-#define _BLI_array_growone(arr) \
- BLI_array_totalsize(arr) > _##arr##_count ? ++_##arr##_count : \
- ((_##arr##_tmp = MEM_callocN(sizeof(*arr)*(_##arr##_count*2+2), #arr " " __FILE__ " ")),\
- (arr && memcpy(_##arr##_tmp, arr, sizeof(*arr) * _##arr##_count)),\
- (arr && ((void *)(arr) != (void*)_##arr##_static ? (MEM_freeN(arr), arr) : arr)),\
- (arr = _##arr##_tmp),\
- _##arr##_count++)
+/* grow the array by one. zeroes the new elements. */
+#define _BLI_array_growone(arr) ( \
+ (BLI_array_totalsize(arr) > _##arr##_count) ? \
+ ++_##arr##_count : \
+ ((_##arr##_tmp = MEM_callocN( \
+ sizeof(*arr)*(_##arr##_count*2+2), \
+ #arr " " __FILE__ ":" STRINGIFY(__LINE__) \
+ ) \
+ ), \
+ (arr && memcpy(_##arr##_tmp, arr, sizeof(*arr) * _##arr##_count)), \
+ (arr && ((void *)(arr) != (void*)_##arr##_static ? \
+ (MEM_freeN(arr), arr) : \
+ arr)), \
+ (arr = _##arr##_tmp), \
+ _##arr##_count++) \
+)
-/*returns length of array*/
-#define BLI_array_growone(arr) ((void *)(arr)==NULL && (void *)(_##arr##_static) != NULL ? ((arr=(void*)_##arr##_static), ++_##arr##_count) : _BLI_array_growone(arr))
- /*appends an item to the array and returns a pointer to the item in the array.
- item is not a pointer, but actual data value.*/
-#define BLI_array_append(arr, item) (BLI_array_growone(arr), (arr[_##arr##_count-1] = item), (arr+(_##arr##_count-1)))
+/* returns length of array */
+#define BLI_array_growone(arr) ( \
+ ((void *)(arr)==NULL && (void *)(_##arr##_static) != NULL) ? \
+ ((arr=(void*)_##arr##_static), ++_##arr##_count) : \
+ _BLI_array_growone(arr) \
+)
-/*grow an array by a specified number of items.*/
-#define BLI_array_growitems(arr, num) {int _i; for (_i=0; _i<(num); _i++) {BLI_array_growone(arr);}}
-#define BLI_array_free(arr) if (arr && (char *)arr != _##arr##_static) { BLI_array_fake_user(arr); MEM_freeN(arr); }
-#define BLI_array_pop(arr) ((arr&&_##arr##_count) ? arr[--_##arr##_count] : 0)
-/*resets the logical size of an array to zero, but doesn't
- free the memory.*/
-#define BLI_array_empty(arr) _##arr##_count=0
+/* appends an item to the array and returns a pointer to the item in the array.
+ * item is not a pointer, but actual data value.*/
+#define BLI_array_append(arr, item) ( \
+ BLI_array_growone(arr), \
+ (arr[_##arr##_count-1] = item), \
+ (arr+(_##arr##_count-1)) \
+)
-/*set the count of the array, doesn't actually increase the allocated array
- size. don't use this unless you know what you're doing.*/
-#define BLI_array_set_length(arr, count) _##arr##_count = (count)
-/*only to prevent unused warnings*/
-#define BLI_array_fake_user(arr) (void)_##arr##_count, (void)_##arr##_tmp, (void)_##arr##_static
+/* grow an array by a specified number of items. */
+/* TODO, this could be done in a less crappy way by not looping - campbell */
+#define BLI_array_growitems(arr, num) \
+ { \
+ int _i; \
+ for (_i = 0; _i < (num); _i++) { \
+ BLI_array_growone(arr); \
+ } \
+ }
+
+#define BLI_array_free(arr) \
+ if (arr && (char *)arr != _##arr##_static) { \
+ BLI_array_fake_user(arr); \
+ MEM_freeN(arr); \
+ }
+
+#define BLI_array_pop(arr) ( \
+ (arr&&_##arr##_count) ? \
+ arr[--_##arr##_count] : \
+ 0 \
+)
+
+/* resets the logical size of an array to zero, but doesn't
+ * free the memory. */
+#define BLI_array_empty(arr) \
+ _##arr##_count=0
+
+/* set the count of the array, doesn't actually increase the allocated array
+ * size. don't use this unless you know what you're doing. */
+#define BLI_array_set_length(arr, count) \
+ _##arr##_count = (count)
+
+/* only to prevent unused warnings */
+#define BLI_array_fake_user(arr) \
+ (void)_##arr##_count, \
+ (void)_##arr##_tmp, \
+ (void)_##arr##_static
More information about the Bf-blender-cvs
mailing list