From 3d61d66388d94e52e7977a98e431d3ecf5169dcd Mon Sep 17 00:00:00 2001 From: Doyle Thai Date: Fri, 23 Jun 2017 19:05:51 +1000 Subject: [PATCH] Fix destructor premature call in memstack cpp api --- dqn.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dqn.h b/dqn.h index aa78db4..aa6e3f0 100644 --- a/dqn.h +++ b/dqn.h @@ -66,7 +66,7 @@ #define DQN_UNIX_PLATFORM #endif -#ifdef __cplusplus +#if defined(__cplusplus) #define DQN_CPP_MODE #endif @@ -233,7 +233,7 @@ typedef struct DqnMemStack void TempRegionEnd (DqnMemStackTempRegion region); // Scoped Temporary Regions API - struct DqnMemStackTempRegionScoped TempRegionScoped(bool *const succeeded); + struct DqnMemStackTempRegionScoped TempRegionScoped(); // Advanced API DqnMemStackBlock *AllocateCompatibleBlock(size_t size); @@ -1733,8 +1733,10 @@ DqnMemStackTempRegion DqnMemStack::TempRegionBegin() DQN_ASSERT_HARD(succeeded); return result; } -void DqnMemStack::TempRegionEnd(DqnMemStackTempRegion region) { DqnMemStackTempRegion_End(region); } -DqnMemStackTempRegionScoped DqnMemStack::TempRegionScoped(bool *const succeeded) { return DqnMemStackTempRegionScoped(this, succeeded); } +void DqnMemStack::TempRegionEnd(DqnMemStackTempRegion region) { DqnMemStackTempRegion_End(region); } + +// NOTE: Guaranteed to always succeed. Fails when arguments are invalid, like a NULL ptr which is impossible here. +DqnMemStackTempRegionScoped DqnMemStack::TempRegionScoped() { return DqnMemStackTempRegionScoped(this, NULL); } DqnMemStackBlock *DqnMemStack::AllocateCompatibleBlock(size_t size) { return DqnMemStack_AllocateCompatibleBlock(this, size); } bool DqnMemStack::AttachBlock (DqnMemStackBlock *const newBlock) { return DqnMemStack_AttachBlock (this, newBlock); }