Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-03-16 04:12:14 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-03-16 04:12:14 +0400
commit1b994dbeb0e6ea7220e636d2b828eb427065772b (patch)
tree45213d655f9e9c8cd89a24d8d963f83a9d0fd1c9 /source/blender/blenlib/BLI_buffer.h
parent93836a24aaba3965232c6df3f525302bd9b924ce (diff)
changes to BLI_buffer
- assert if BLI_buffer_at() is called with an out of bounds value. - add BLI_buffer_resize_data() macro which resizes and returns a pointer to the new array. - warn if missing call to BLI_buffer_free().
Diffstat (limited to 'source/blender/blenlib/BLI_buffer.h')
-rw-r--r--source/blender/blenlib/BLI_buffer.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h
index 880a97acb80..fe835e7cadc 100644
--- a/source/blender/blenlib/BLI_buffer.h
+++ b/source/blender/blenlib/BLI_buffer.h
@@ -52,6 +52,7 @@ enum {
};
#define BLI_buffer_declare_static(type_, name_, flag_, static_count_) \
+ char name_ ## user; /* warn for free only */ \
type_ *name_ ## _static_[static_count_]; \
BLI_Buffer name_ = { \
/* clear the static memory if this is a calloc'd array */ \
@@ -66,15 +67,26 @@ enum {
/* never use static*/
#define BLI_buffer_declare(type_, name_, flag_) \
+ bool name_ ## user; /* warn for free only */ \
BLI_Buffer name_ = {NULL, \
sizeof(type_), \
0, \
0, \
flag_}
-
#define BLI_buffer_at(buffer_, type_, index_) ( \
- (((type_ *)(buffer_)->data)[(BLI_assert(sizeof(type_) == (buffer_)->elem_size)), index_]))
+ (((type_ *)(buffer_)->data)[ \
+ (BLI_assert(sizeof(type_) == (buffer_)->elem_size)), \
+ (BLI_assert(index_ >= 0 && index_ < (buffer_)->count)), \
+ index_]))
+
+#define BLI_buffer_array(buffer_, type_) ( \
+ &(BLI_buffer_at(buffer_, type_, 0)))
+
+#define BLI_buffer_resize_data(buffer_, type_, new_count_) ( \
+ (BLI_buffer_resize(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL))
+
+
#define BLI_buffer_append(buffer_, type_, val_) ( \
BLI_buffer_resize(buffer_, (buffer_)->count + 1), \
@@ -85,6 +97,10 @@ enum {
void BLI_buffer_resize(BLI_Buffer *buffer, int new_count);
/* Does not free the buffer structure itself */
-void BLI_buffer_free(BLI_Buffer *buffer);
+void _bli_buffer_free(BLI_Buffer *buffer);
+#define BLI_buffer_free(name_) { \
+ _bli_buffer_free(name_); \
+ (void)name_ ## user; /* ensure we free */ \
+} (void)0
#endif /* __BLI_BUFFER_H__ */