Skip to content

Commit c46a765

Browse files
Use new (nothrow) everywhere
We jump through various hoops in order to get new to be recognised as having nothrow behaviour but it is fragile and doesn't work when the engine is hosted inside another process (if that process uses its own implementation of new, as it is entitled to do). Instead of dealing with this, just bite the bullet and add the (std::nothrow) argument to every invocation of new in the engine and externals.
1 parent f835682 commit c46a765

File tree

255 files changed

+1169
-1273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+1169
-1273
lines changed

engine/src/aclip.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ MCAudioClip::MCAudioClip()
123123
disposable = False;
124124
loudness = 100;
125125
#ifdef TARGET_PLATFORM_LINUX
126-
x11audio = new X11Audio ;
126+
x11audio = new (nothrow) X11Audio ;
127127
#endif
128128
}
129129

@@ -133,7 +133,7 @@ MCAudioClip::MCAudioClip(const MCAudioClip &aref) : MCObject(aref)
133133
samples = osamples = NULL;
134134
if (size != 0)
135135
{
136-
samples = new int1[size];
136+
samples = new (nothrow) int1[size];
137137
memcpy(samples, aref.samples, size);
138138
}
139139
format = aref.format;
@@ -143,7 +143,7 @@ MCAudioClip::MCAudioClip(const MCAudioClip &aref) : MCObject(aref)
143143
disposable = False;
144144
loudness = aref.loudness;
145145
#ifdef TARGET_PLATFORM_LINUX
146-
x11audio = new X11Audio ;
146+
x11audio = new (nothrow) X11Audio ;
147147
#endif
148148
}
149149

@@ -240,7 +240,7 @@ void MCAudioClip::init()
240240

241241
void MCAudioClip::convert_mulawtolin16()
242242
{
243-
int2 *newsamples = new int2[size];
243+
int2 *newsamples = new (nothrow) int2[size];
244244
uint1 *sptr = (uint1 *)samples;
245245
int2 *dptr = newsamples;
246246
uint4 count = size;
@@ -260,7 +260,7 @@ void MCAudioClip::convert_mulawtolin16()
260260

261261
void MCAudioClip::convert_mulawtoulin8()
262262
{
263-
int1 *newsamples = new int1[size];
263+
int1 *newsamples = new (nothrow) int1[size];
264264
uint1 *sptr = (uint1 *)samples;
265265
int1 *dptr = newsamples;
266266
uint4 count = size;
@@ -287,7 +287,7 @@ void MCAudioClip::convert_slin8toslin16()
287287
uint4 count = size;
288288
size <<= 1;
289289
swidth = 2;
290-
int1 *newsamples = new int1[size];
290+
int1 *newsamples = new (nothrow) int1[size];
291291
int1 *sptr = samples;
292292
int2 *dptr = (int2 *)newsamples;
293293
while(count--)
@@ -359,7 +359,7 @@ Boolean MCAudioClip::import(MCStringRef fname, IO_handle stream)
359359
size = (uint4)MCS_fsize(stream);
360360
if (size == 0)
361361
return False;
362-
samples = new int1[size];
362+
samples = new (nothrow) int1[size];
363363
if (IO_read(samples, size, stream) != IO_NORMAL)
364364
return False;
365365
if (strnequal((char*)samples, ".snd", 4))
@@ -687,7 +687,7 @@ Boolean MCAudioClip::play()
687687
if (!open_audio())
688688
{
689689
real8 delay = MCS_time() + (real8)size / (real8)(rate*nchannels*swidth);
690-
MCParameter *newparam = new MCParameter;
690+
MCParameter *newparam = new (nothrow) MCParameter;
691691
newparam->setvalueref_argument(getname());
692692
MCscreen->addmessage(MCdefaultstackptr->getcurcard(), MCM_play_stopped, delay, newparam);
693693
return False;
@@ -910,7 +910,7 @@ IO_stat MCAudioClip::load(IO_handle stream, uint32_t version)
910910
return checkloadstat(stat);
911911
if (size != 0)
912912
{
913-
samples = new int1[size];
913+
samples = new (nothrow) int1[size];
914914
if ((stat = IO_read(samples, size, stream)) != IO_NORMAL)
915915
return checkloadstat(stat);
916916
}
@@ -965,7 +965,7 @@ uint2 MCS_getplayloudness()
965965
t_loudness = (HiWord(volume) + LoWord(volume)) * 50 / 255;
966966
#elif defined TARGET_PLATFORM_LINUX
967967
X11Audio *t_x11audio = nil;
968-
t_x11audio = new X11Audio ;
968+
t_x11audio = new (nothrow) X11Audio ;
969969
if ( t_x11audio != nil)
970970
{
971971
t_loudness = t_x11audio -> getloudness() ;
@@ -1008,7 +1008,7 @@ void MCS_setplayloudness(uint2 p_loudness)
10081008
SetDefaultOutputVolume(volume | volume << 16);
10091009
#elif defined TARGET_PLATFORM_LINUX
10101010
X11Audio *t_x11audio = nil;
1011-
t_x11audio = new X11Audio ;
1011+
t_x11audio = new (nothrow) X11Audio ;
10121012
if (t_x11audio != nil)
10131013
{
10141014
t_x11audio -> setloudness(p_loudness);

engine/src/bitmapeffect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool MCBitmapEffectsAssign(MCBitmapEffectsRef& self, MCBitmapEffectsRef src)
160160
if (src != NULL)
161161
{
162162
// Allocate, returning false if it fails.
163-
t_new_self = new MCBitmapEffects;
163+
t_new_self = new (nothrow) MCBitmapEffects;
164164
if (t_new_self == NULL)
165165
return false;
166166

@@ -437,7 +437,7 @@ IO_stat MCBitmapEffectsUnpickle(MCBitmapEffectsRef& self, MCObjectInputStream& p
437437
{
438438
// Create a new instance
439439
MCBitmapEffects *t_new_self;
440-
t_new_self = new MCBitmapEffects;
440+
t_new_self = new (nothrow) MCBitmapEffects;
441441
if (t_new_self == NULL)
442442
return IO_ERROR;
443443

@@ -1041,7 +1041,7 @@ bool MCBitmapEffectsSetProperty(MCExecContext& ctxt, MCBitmapEffectsRef& self, M
10411041
// If we are currently empty, then allocate a new object
10421042
if (self == nil)
10431043
{
1044-
self = new MCBitmapEffects;
1044+
self = new (nothrow) MCBitmapEffects;
10451045
if (self == nil)
10461046
return false;
10471047

@@ -1252,7 +1252,7 @@ static void MCBitmapEffectRender(MCBitmapEffectRenderState& state, MCBitmapEffec
12521252

12531253
// Allocate a run of mask pixels
12541254
uint8_t *t_mask_pixels;
1255-
t_mask_pixels = new uint8_t[dst . bounds . width];
1255+
t_mask_pixels = new (nothrow) uint8_t[dst . bounds . width];
12561256

12571257
// Calculate the attenuation bounds
12581258
int32_t t_left, t_top, t_right, t_bottom, t_count;

engine/src/bitmapeffectblur.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static float *MCBitmapEffectComputeGaussianKernel(uint4 r)
139139
t_width = r * 2 + 1;
140140

141141
float *lk;
142-
lk = new float[t_width];
142+
lk = new (nothrow) float[t_width];
143143
if (lk == NULL)
144144
return NULL;
145145

@@ -162,7 +162,7 @@ static uint32_t *MCBitmapEffectComputeBlurKernel(uint4 r)
162162
lk = MCBitmapEffectComputeGaussianKernel(r);
163163

164164
float *k, t_sum;
165-
k = new float[t_width * t_width];
165+
k = new (nothrow) float[t_width * t_width];
166166
t_sum = 0.0;
167167
for(uint4 i = 0; i < t_width; i++)
168168
for(uint4 j = 0; j < t_width; j++)
@@ -174,7 +174,7 @@ static uint32_t *MCBitmapEffectComputeBlurKernel(uint4 r)
174174
}
175175

176176
uint32_t *ik;
177-
ik = new uint32_t[t_width * t_width];
177+
ik = new (nothrow) uint32_t[t_width * t_width];
178178
for(uint4 i = 0; i < t_width; i++)
179179
for(uint4 j = 0; j < t_width; j++)
180180
ik[i * t_width + j] = (uint32_t)(k[i * t_width + j] * 0x1000000 / t_sum);
@@ -332,7 +332,7 @@ bool MCBitmapEffectFastGaussianBlur::Initialize(const MCBitmapEffectBlurParamete
332332
if (params . radius != 0)
333333
{
334334
float *lk = MCBitmapEffectComputeGaussianKernel(t_spread_radius);
335-
kernel = new uint32_t[t_width];
335+
kernel = new (nothrow) uint32_t[t_width];
336336
float t_sum = 0;
337337
for (uint32_t i=0; i<(t_spread_radius * 2 + 1); i++)
338338
{
@@ -364,7 +364,7 @@ bool MCBitmapEffectFastGaussianBlur::Initialize(const MCBitmapEffectBlurParamete
364364

365365
buffer_height = t_width;
366366
buffer_nextrow = top;
367-
buffer = new uint32_t[buffer_height * output_rect.width];
367+
buffer = new (nothrow) uint32_t[buffer_height * output_rect.width];
368368
buffer_stride = output_rect.width;
369369

370370
if (radius > 0)
@@ -619,7 +619,7 @@ bool MCBitmapEffectBoxBlur::Initialize(const MCBitmapEffectBlurParameters& param
619619
if (t_radius == 0)
620620
m_passes = 0;
621621

622-
pass_info = new MCBitmapEffectBoxBlurPassInfo[m_passes];
622+
pass_info = new (nothrow) MCBitmapEffectBoxBlurPassInfo[m_passes];
623623

624624
int32_t t_maxwidth = 0;
625625
for (uint32_t i=0; i<m_passes; i++)
@@ -646,7 +646,7 @@ bool MCBitmapEffectBoxBlur::Initialize(const MCBitmapEffectBlurParameters& param
646646
t_pass->stride = t_pass->width + 1;
647647
t_pass->height = t_pass->bottom - t_pass->top;
648648
t_pass->buffer_height = t_pass->height + 1;
649-
t_pass->buffer = new uint32_t[(t_pass->stride) * t_pass->buffer_height];
649+
t_pass->buffer = new (nothrow) uint32_t[(t_pass->stride) * t_pass->buffer_height];
650650
memset(pass_info[i].buffer, 0, (t_pass->stride) * t_pass->buffer_height * sizeof(uint32_t));
651651

652652
t_pass->buffer_nextrow = t_pass->top;
@@ -665,7 +665,7 @@ bool MCBitmapEffectBoxBlur::Initialize(const MCBitmapEffectBlurParameters& param
665665
t_buff_bottom -= t_pass->radius;
666666
}
667667

668-
row_buffer = new uint32_t[t_maxwidth];
668+
row_buffer = new (nothrow) uint32_t[t_maxwidth];
669669

670670
if (m_passes > 0)
671671
pixels = src_pixels + stride * pass_info[0].top;
@@ -909,19 +909,19 @@ static bool MCBitmapEffectBlurFactory(MCBitmapEffectFilter p_type, MCBitmapEffec
909909
switch(p_type)
910910
{
911911
case kMCBitmapEffectFilterFastGaussian:
912-
r_blur = new MCBitmapEffectFastGaussianBlur;
912+
r_blur = new (nothrow) MCBitmapEffectFastGaussianBlur;
913913
return true;
914914

915915
case kMCBitmapEffectFilterOnePassBox:
916-
r_blur = new MCBitmapEffectBoxBlur(1);
916+
r_blur = new (nothrow) MCBitmapEffectBoxBlur(1);
917917
return true;
918918

919919
case kMCBitmapEffectFilterTwoPassBox:
920-
r_blur = new MCBitmapEffectBoxBlur(2);
920+
r_blur = new (nothrow) MCBitmapEffectBoxBlur(2);
921921
return true;
922922

923923
case kMCBitmapEffectFilterThreePassBox:
924-
r_blur = new MCBitmapEffectBoxBlur(3);
924+
r_blur = new (nothrow) MCBitmapEffectBoxBlur(3);
925925
return true;
926926

927927
default:

engine/src/block.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ MCBlock::MCBlock(const MCBlock &bref) : MCDLlist(bref)
8282
flags = bref.flags;
8383
if (flags & F_HAS_ATTS)
8484
{
85-
atts = new Blockatts;
85+
atts = new (nothrow) Blockatts;
8686
if (flags & F_HAS_COLOR)
8787
{
88-
atts->color = new MCColor;
88+
atts->color = new (nothrow) MCColor;
8989
*atts->color = *bref.atts->color;
9090
}
9191
if (flags & F_HAS_BACK_COLOR)
9292
{
93-
atts->backcolor = new MCColor;
93+
atts->backcolor = new (nothrow) MCColor;
9494
*atts->backcolor = *bref.atts->backcolor;
9595
}
9696

@@ -193,7 +193,7 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
193193
flags &= ~F_FLAGGED;
194194

195195
if (atts == NULL)
196-
atts = new Blockatts;
196+
atts = new (nothrow) Blockatts;
197197

198198
// MW-2012-02-17: [[ SplitTextAttrs ]] If the font flag is present, it means there
199199
// is a font record to read.
@@ -239,7 +239,7 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
239239
}
240240
if (flags & F_HAS_COLOR)
241241
{
242-
atts->color = new MCColor;
242+
atts->color = new (nothrow) MCColor;
243243
if ((stat = IO_read_mccolor(*atts->color, stream)) != IO_NORMAL)
244244
return checkloadstat(stat);
245245
if (flags & F_HAS_COLOR_NAME)
@@ -257,7 +257,7 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
257257
}
258258
if (flags & F_HAS_BACK_COLOR)
259259
{
260-
atts->backcolor = new MCColor;
260+
atts->backcolor = new (nothrow) MCColor;
261261
if ((stat = IO_read_mccolor(*atts->backcolor, stream)) != IO_NORMAL)
262262
return checkloadstat(stat);
263263
if (version < kMCStackFileFormatVersion_2_0 || flags & F_HAS_BACK_COLOR_NAME)
@@ -896,7 +896,7 @@ bool MCBlock::fit(coord_t x, coord_t maxwidth, findex_t& r_break_index, bool& r_
896896

897897
void MCBlock::split(findex_t p_index)
898898
{
899-
MCBlock *bptr = new MCBlock(*this);
899+
MCBlock *bptr = new (nothrow) MCBlock(*this);
900900
findex_t newlength = m_size - (p_index - m_index);
901901
bptr->SetRange(p_index, newlength);
902902
m_size -= newlength;
@@ -1580,7 +1580,7 @@ void MCBlock::setshift(int2 in)
15801580
else
15811581
{
15821582
if (atts == NULL)
1583-
atts = new Blockatts;
1583+
atts = new (nothrow) Blockatts;
15841584
atts->shift = in;
15851585
flags |= F_HAS_SHIFT;
15861586
}
@@ -1615,9 +1615,9 @@ void MCBlock::setcolor(const MCColor *newcolor)
16151615
else
16161616
{
16171617
if (atts == NULL)
1618-
atts = new Blockatts;
1618+
atts = new (nothrow) Blockatts;
16191619
if (!(flags & F_HAS_COLOR))
1620-
atts->color = new MCColor;
1620+
atts->color = new (nothrow) MCColor;
16211621
*atts->color = *newcolor;
16221622
flags |= F_HAS_COLOR;
16231623
}
@@ -1636,9 +1636,9 @@ void MCBlock::setbackcolor(const MCColor *newcolor)
16361636
else
16371637
{
16381638
if (atts == NULL)
1639-
atts = new Blockatts;
1639+
atts = new (nothrow) Blockatts;
16401640
if (!(flags & F_HAS_BACK_COLOR))
1641-
atts->backcolor = new MCColor;
1641+
atts->backcolor = new (nothrow) MCColor;
16421642
*atts->backcolor = *newcolor;
16431643
flags |= F_HAS_BACK_COLOR;
16441644
}

0 commit comments

Comments
 (0)