diff options
Diffstat (limited to 'lv2/atom/forge.h')
-rw-r--r-- | lv2/atom/forge.h | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lv2/atom/forge.h b/lv2/atom/forge.h index 826b2d1..e992ff2 100644 --- a/lv2/atom/forge.h +++ b/lv2/atom/forge.h @@ -48,17 +48,16 @@ #ifndef LV2_ATOM_FORGE_H #define LV2_ATOM_FORGE_H -#include <assert.h> - #include "lv2/atom/atom.h" #include "lv2/atom/util.h" #include "lv2/core/attributes.h" #include "lv2/urid/urid.h" +#include <assert.h> +#include <stdbool.h> + #ifdef __cplusplus extern "C" { -#else -# include <stdbool.h> #endif // Disable deprecation warnings for Blank and Resource @@ -82,9 +81,9 @@ typedef LV2_Atom* LV2_Atom_Forge_Ref ref); /** A stack frame used for keeping track of nested Atom containers. */ -typedef struct _LV2_Atom_Forge_Frame { - struct _LV2_Atom_Forge_Frame* parent; - LV2_Atom_Forge_Ref ref; +typedef struct LV2_Atom_Forge_Frame { + struct LV2_Atom_Forge_Frame* parent; + LV2_Atom_Forge_Ref ref; } LV2_Atom_Forge_Frame; /** A "forge" for creating atoms by appending to a buffer. */ @@ -177,7 +176,11 @@ lv2_atom_forge_push(LV2_Atom_Forge* forge, { frame->parent = forge->stack; frame->ref = ref; - forge->stack = frame; + + if (ref) { + forge->stack = frame; // Don't push, so walking the stack is always safe + } + return ref; } @@ -185,8 +188,12 @@ lv2_atom_forge_push(LV2_Atom_Forge* forge, static inline void lv2_atom_forge_pop(LV2_Atom_Forge* forge, LV2_Atom_Forge_Frame* frame) { - assert(frame == forge->stack); - forge->stack = frame->parent; + if (frame->ref) { + // If frame has a valid ref, it must be the top of the stack + assert(frame == forge->stack); + forge->stack = frame->parent; + } + // Otherwise, frame was not pushed because of overflow, do nothing } /** Return true iff the top of the stack has the given type. */ |