diff options
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_buffer.h | 21 | ||||
-rw-r--r-- | source/blender/blenlib/intern/buffer.c | 33 |
3 files changed, 33 insertions, 23 deletions
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index cf4c49a9244..cef570a54f5 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -97,7 +97,7 @@ UvVertMap *BKE_mesh_uv_vert_map_create( float (*tf_uv)[2] = NULL; if (use_winding) { - tf_uv = (float (*)[2])BLI_buffer_resize_data(&tf_uv_buf, vec2f, mp->totloop); + tf_uv = (float (*)[2])BLI_buffer_resize_data(&tf_uv_buf, vec2f, (size_t)mp->totloop); } nverts = mp->totloop; diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index 4e5b61da532..941c1c93ae9 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -23,27 +23,12 @@ /** \file BLI_buffer.h * \ingroup bli - * - * \note this more or less fills same purpose as BLI_array, but makes - * it much easier to resize the array outside of the function it was - * declared in since. - * - * Usage examples: - * \code{.c} - * BLI_buffer_declare_static(int, my_int_array, BLI_BUFFER_NOP, 32); - * - * BLI_buffer_append(my_int_array, int, 42); - * assert(my_int_array.count == 1); - * assert(BLI_buffer_at(my_int_array, int, 0) == 42); - * - * BLI_buffer_free(&my_int_array); - * \endcode */ typedef struct { void *data; - const int elem_size; - int count, alloc_count; + const size_t elem_size; + size_t count, alloc_count; int flag; } BLI_Buffer; @@ -98,7 +83,7 @@ enum { } (void)0 /* Never decreases the amount of memory allocated */ -void BLI_buffer_resize(BLI_Buffer *buffer, int new_count); +void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); /* Does not free the buffer structure itself */ void _bli_buffer_free(BLI_Buffer *buffer); diff --git a/source/blender/blenlib/intern/buffer.c b/source/blender/blenlib/intern/buffer.c index ed47efd93eb..7588a6ec14d 100644 --- a/source/blender/blenlib/intern/buffer.c +++ b/source/blender/blenlib/intern/buffer.c @@ -20,30 +20,55 @@ /** \file blender/blenlib/intern/buffer.c * \ingroup bli + * + * Primitive generic buffer library. + * + * - Automatically grow as needed. + * (currently never shrinks). + * - Can be passed between functions. + * - Supports using stack memory by default, + * falling back to heap as needed. + * + * Usage examples: + * \code{.c} + * BLI_buffer_declare_static(int, my_int_array, BLI_BUFFER_NOP, 32); + * + * BLI_buffer_append(my_int_array, int, 42); + * assert(my_int_array.count == 1); + * assert(BLI_buffer_at(my_int_array, int, 0) == 42); + * + * BLI_buffer_free(&my_int_array); + * \endcode + * + * \note this more or less fills same purpose as #BLI_array, + * but supports resizing the array outside of the function + * it was declared in. */ +#include <string.h> + #include "MEM_guardedalloc.h" #include "BLI_buffer.h" #include "BLI_utildefines.h" -#include <string.h> +#include "BLI_strict_flags.h" -static void *buffer_alloc(BLI_Buffer *buffer, int len) +static void *buffer_alloc(BLI_Buffer *buffer, const size_t len) { return ((buffer->flag & BLI_BUFFER_USE_CALLOC) ? MEM_callocN : MEM_mallocN) (buffer->elem_size * len, "BLI_Buffer.data"); } -static void *buffer_realloc(BLI_Buffer *buffer, int len) +static void *buffer_realloc(BLI_Buffer *buffer, const size_t len) { return ((buffer->flag & BLI_BUFFER_USE_CALLOC) ? MEM_recallocN_id : MEM_reallocN_id) (buffer->data, buffer->elem_size * len, "BLI_Buffer.data"); } -void BLI_buffer_resize(BLI_Buffer *buffer, int new_count) +void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count) { if (UNLIKELY(new_count > buffer->alloc_count)) { if (buffer->flag & BLI_BUFFER_USE_STATIC) { |