diff options
Diffstat (limited to 'upb')
-rw-r--r-- | upb/msg.h | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -24,6 +24,7 @@ #include <stdint.h> #include <string.h> #include "upb/upb.h" +#include "upb/structs.int.h" #ifdef __cplusplus @@ -217,6 +218,31 @@ bool upb_msg_clearfield(upb_msg *msg, * semantics are the same as upb_msg. A upb_array allocates dynamic * memory internally for the array elements. */ +UPB_INLINE const void *_upb_array_accessor(const upb_array *arr, size_t *size) { + if (size) *size = arr->size; + return arr->data; +} + +UPB_INLINE void *_upb_array_mutable_accessor(upb_array *arr, size_t *size) { + if (size) *size = arr->size; + return arr->data; +} + +UPB_INLINE void *_upb_array_resize_accessor(upb_array *arr, size_t size, + size_t elem_size) { + if (size > arr->size) { + size_t new_size = UPB_MAX(arr->size, 4); + size_t old_bytes = arr->size * elem_size; + size_t new_bytes; + upb_alloc *alloc = upb_arena_alloc(arr->arena); + while (new_size < size) new_size *= 2; + new_bytes = new_size * elem_size; + arr->data = upb_realloc(alloc, arr->data, old_bytes, new_bytes); + } + arr->len = size; + return arr->data; +} + upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a); upb_fieldtype_t upb_array_type(const upb_array *arr); |