Skip to content

Commit d5c4c23

Browse files
committed
replace goto end with ClearUnitIfMemFailed
also set default calc function
1 parent aa61075 commit d5c4c23

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

source/DEINDUGens/JPverbRaw.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,16 +1526,18 @@ void Faust_next_clear(Faust* unit, int inNumSamples)
15261526

15271527
void Faust_Ctor(Faust* unit) // module constructor
15281528
{
1529-
// init such that we can use generic end goto
1529+
// init such that we can still free them in the destructor if
1530+
// allocation fails.
15301531
unit->mDSP = nullptr;
15311532
unit->mInBufCopy = nullptr;
15321533
unit->mInBufValue = nullptr;
15331534

1535+
// set a default calc function
1536+
SETCALC(Faust_next_clear);
1537+
15341538
// allocate dsp
15351539
void* mem = RTAlloc(unit->mWorld, sizeof(FAUSTCLASS));
1536-
if (mem == nullptr) {
1537-
goto end;
1538-
}
1540+
ClearUnitIfMemFailed(mem);
15391541
unit->mDSP = new (mem) FAUSTCLASS();
15401542
{
15411543
// init dsp
@@ -1566,21 +1568,15 @@ void Faust_Ctor(Faust* unit) // module constructor
15661568
SETCALC(Faust_next);
15671569
} else {
15681570
unit->mInBufCopy = (float**)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*sizeof(float*));
1569-
if (!unit->mInBufCopy) {
1570-
goto end;
1571-
}
1571+
ClearUnitIfMemFailed(unit->mInBufCopy);
15721572
// Allocate memory for input buffer copies (numInputs * bufLength)
15731573
// and linear interpolation state (numInputs)
15741574
// = numInputs * (bufLength + 1)
15751575
unit->mInBufValue = (float*)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*sizeof(float));
1576-
if (!unit->mInBufValue) {
1577-
goto end;
1578-
}
1576+
ClearUnitIfMemFailed(unit->mInBufValue);
15791577
// Aquire memory for interpolator state.
1580-
float* mem = (float*)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*BUFLENGTH*sizeof(float));
1581-
if (mem) {
1582-
goto end;
1583-
}
1578+
auto* mem = (float*)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*BUFLENGTH*sizeof(float));
1579+
ClearUnitIfMemFailed(mem);
15841580
for (int i = 0; i < unit->getNumAudioInputs(); ++i) {
15851581
// Initialize interpolator.
15861582
unit->mInBufValue[i] = IN0(i);
@@ -1610,11 +1606,6 @@ void Faust_Ctor(Faust* unit) // module constructor
16101606
}
16111607
}
16121608

1613-
end:
1614-
Print("Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n", g_unitName);
1615-
RTFree(unit->mWorld, unit->mDSP);
1616-
RTFree(unit->mWorld, unit->mInBufCopy);
1617-
RTFree(unit->mWorld, unit->mInBufValue);
16181609
// Fix for https://github.com/grame-cncm/faust/issues/13
16191610
ClearUnitOutputs(unit, 1);
16201611
}

0 commit comments

Comments
 (0)