From 7b90f2dac53b7cd17fb9499c4cedf2b301d90129 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 9 Nov 2011 01:08:14 +0000 Subject: Define types as complete objects, not just atom bodies. Improve helper API. --- ext/atom.lv2/atom-buffer.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'ext/atom.lv2/atom-buffer.h') diff --git a/ext/atom.lv2/atom-buffer.h b/ext/atom.lv2/atom-buffer.h index 2ac71e3..f4b90dd 100644 --- a/ext/atom.lv2/atom-buffer.h +++ b/ext/atom.lv2/atom-buffer.h @@ -28,19 +28,9 @@ #include #include #include -#include #include "lv2/lv2plug.in/ns/ext/atom/atom.h" -/** - Pad a size to 64 bits. -*/ -static inline uint32_t -lv2_atom_pad_size(uint32_t size) -{ - return (size + 7) & (~7); -} - /** Initialize an existing atom buffer. All fields of @c buf are reset, except capacity which is unmodified. @@ -111,9 +101,10 @@ lv2_atom_buffer_is_valid(LV2_Atom_Buffer_Iterator i) static inline LV2_Atom_Buffer_Iterator lv2_atom_buffer_next(LV2_Atom_Buffer_Iterator i) { - assert(lv2_atom_buffer_is_valid(i)); - const LV2_Atom_Event* const ev = (LV2_Atom_Event*)( - i.buf->data + i.offset); + if (!lv2_atom_buffer_is_valid(i)) { + return i; + } + const LV2_Atom_Event* const ev = (LV2_Atom_Event*)(i.buf->data + i.offset); i.offset += lv2_atom_pad_size(sizeof(LV2_Atom_Event) + ev->body.size); return i; } @@ -124,7 +115,9 @@ lv2_atom_buffer_next(LV2_Atom_Buffer_Iterator i) static inline LV2_Atom_Event* lv2_atom_buffer_get(LV2_Atom_Buffer_Iterator i) { - assert(lv2_event_is_valid(i)); + if (!lv2_atom_buffer_is_valid(i)) { + return NULL; + } return (LV2_Atom_Event*)(i.buf->data + i.offset); } -- cgit v1.2.1