Remove variable length arrays of non-PODs.

Variable length arrays of non-PODs are not part of the C++ standard, but
a GNU extension that never worked correctly. Instead, BStackOrHeap array
is used now, which makes sure that it's not too big for the stack, calls
all constructors and is valid C++.
This commit is contained in:
Jonathan Schleifer 2014-01-10 21:06:36 +01:00 committed by Stephan Aßmus
parent 4bda0212ce
commit f4c2f7ebdb
9 changed files with 30 additions and 19 deletions

View File

@ -16,6 +16,7 @@
#include <BufferProducer.h>
#include <MediaNode.h>
#include <RealtimeAlloc.h>
#include <StackOrHeapArray.h>
#include <StopWatch.h>
#include <TimeSource.h>
@ -520,8 +521,9 @@ MixerCore::_MixThread()
uint64 bufferIndex = 0;
#endif
RtList<chan_info> inputChanInfos[MAX_CHANNEL_TYPES];
RtList<chan_info> mixChanInfos[fMixBufferChannelCount];
typedef RtList<chan_info> chan_info_list;
chan_info_list inputChanInfos[MAX_CHANNEL_TYPES];
BStackOrHeapArray<chan_info_list, 16> mixChanInfos(fMixBufferChannelCount);
// TODO: this does not support changing output channel count
bigtime_t eventTime = timeBase;

View File

@ -20,6 +20,7 @@
#include <Message.h>
#include <Shape.h>
#include <String.h>
#include <StackOrHeapArray.h>
#include "messages.h"
@ -99,7 +100,7 @@ FontDemoView::_DrawView(BView* view)
view->SetFont(&fFont, B_FONT_ALL);
const size_t size = fString.CountChars();
BRect boundBoxes[size];
BStackOrHeapArray<BRect, 64> boundBoxes(size);
if (OutLineLevel())
fFont.GetGlyphShapes(fString, size, fShapes);
@ -456,4 +457,4 @@ FontDemoView::_NewBitmap(BRect rect)
delete fBitmap;
fBitmap = NULL;
}
}
}

View File

@ -14,6 +14,7 @@
#include <Message.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <StackOrHeapArray.h>
#include <Window.h>
#include "cursors.h"
@ -1703,7 +1704,7 @@ PathManipulator::_Nudge(BPoint direction)
int32 count = fromSelection ? fSelection->CountItems()
: fPath->CountPoints();
int32 indices[count];
control_point points[count];
BStackOrHeapArray<control_point, 64> points(count);
// init indices and points
for (int32 i = 0; i < count; i++) {

View File

@ -11,6 +11,7 @@
#include <MediaDefs.h>
#include <Screen.h>
#include <StackOrHeapArray.h>
#include <Window.h>
#include "DrawingTidbits.h"
@ -108,7 +109,7 @@ VUView::_RenderLaunch(void *data)
void
VUView::_RenderLoop()
{
rgb_color levels[fLevelCount][2];
BStackOrHeapArray<rgb_color[2], 64> levels(fLevelCount);
for (int32 i = 0; i < fLevelCount; i++) {
levels[i][0] = levels[i][1] = back_color;

View File

@ -18,6 +18,7 @@
#include <algorithm>
#include <StackOrHeapArray.h>
#include <String.h>
#include "TermConst.h"
@ -537,7 +538,7 @@ BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start,
int32 patternByteLen = strlen(_pattern);
// convert pattern to UTF8Char array
UTF8Char pattern[patternByteLen];
BStackOrHeapArray<UTF8Char, 64> pattern(patternByteLen);
int32 patternLen = 0;
while (*_pattern != '\0') {
int32 charLen = UTF8Char::ByteCount(*_pattern);

View File

@ -25,6 +25,7 @@
#include <GradientConic.h>
#include <Region.h>
#include <Shape.h>
#include <StackOrHeapArray.h>
#include <ServerProtocol.h>
@ -96,11 +97,11 @@ ServerLink::ReadShape(BShape* shape)
fReceiver->Read(&opCount, sizeof(int32));
fReceiver->Read(&ptCount, sizeof(int32));
uint32 opList[opCount];
BStackOrHeapArray<uint32, 64> opList(opCount);
if (opCount > 0)
fReceiver->Read(opList, opCount * sizeof(uint32));
BPoint ptList[ptCount];
BStackOrHeapArray<BPoint, 64> ptList(ptCount);
if (ptCount > 0)
fReceiver->Read(ptList, ptCount * sizeof(BPoint));

View File

@ -11,6 +11,8 @@
#include <syslog.h>
#include <typeinfo>
#include <StackOrHeapArray.h>
namespace BPrivate {
namespace Archiving {
@ -163,7 +165,7 @@ BArchiveManager::ArchiverLeaving(const BArchiver* archiver, status_t err)
if (archiver == fCreator && fError == B_OK) {
// first, we must sort the objects into the order they were archived in
typedef std::pair<BMessage*, const BArchivable*> ArchivePair;
ArchivePair pairs[fTokenMap.size()];
BStackOrHeapArray<ArchivePair, 64> pairs(fTokenMap.size());
for(TokenMap::iterator it = fTokenMap.begin(), end = fTokenMap.end();
it != end; it++) {

View File

@ -34,6 +34,7 @@
#include <ScrollBar.h>
#include <Shape.h>
#include <String.h>
#include <StackOrHeapArray.h>
#include <FontPrivate.h>
#include <MessengerPrivate.h>
@ -1856,10 +1857,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
size = 0.0f;
}
// TODO: don't use the stack for this - numStrings could be large
float widthArray[numStrings];
int32 lengthArray[numStrings];
char *stringArray[numStrings];
BStackOrHeapArray<float, 64> widthArray(numStrings);
BStackOrHeapArray<int32, 64> lengthArray(numStrings);
BStackOrHeapArray<char*, 64> stringArray(numStrings);
for (int32 i = 0; i < numStrings; i++) {
// This version of ReadString allocates the strings, we free
// them below
@ -1882,7 +1882,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
}
fLink.StartMessage(B_OK);
fLink.Attach(widthArray, sizeof(widthArray));
fLink.Attach(widthArray, numStrings * sizeof(float));
} else
fLink.StartMessage(B_BAD_VALUE);
@ -2497,8 +2497,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
link.Read<escapement_delta>(&deltaArray[i]);
}
// TODO: don't do this on the heap! (at least check the size before)
BRect rectArray[numStrings];
BStackOrHeapArray<BRect, 64> rectArray(numStrings);
ServerFont font;
bool success = false;
@ -2513,7 +2512,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
if (font.GetBoundingBoxesForStrings(stringArray, lengthArray,
numStrings, rectArray, mode, deltaArray) == B_OK) {
fLink.StartMessage(B_OK);
fLink.Attach(rectArray, sizeof(rectArray));
fLink.Attach(rectArray, numStrings * sizeof(BRect));
success = true;
}
}

View File

@ -10,7 +10,10 @@
#include "DrawingEngine.h"
#include <Bitmap.h>
#include <StackOrHeapArray.h>
#include <stdio.h>
#include <algorithm>
#include <stack>
@ -469,7 +472,7 @@ DrawingEngine::CopyRegion(/*const*/ BRegion* region, int32 xOffset,
// TODO: make this step unnecessary
// (by using different stack impl inside node)
node nodes[count];
BStackOrHeapArray<node, 64> nodes(count);
for (int32 i= 0; i < count; i++) {
nodes[i].init(region->RectAt(i), count);
}