tools/locale: Fix using auto_ptr to array.
Use BStackOrHeapArray instead of using auto_ptr to array. Change-Id: I171cb002829c36ec51ba7d1e387869263e2a40f2 Reviewed-on: https://review.haiku-os.org/745 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
6439130107
commit
4c5e5d8b04
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Jonathan Schleifer <[email protected]>. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _SUPPORT_STACKORHEAPARRAY_H
|
||||||
|
#define _SUPPORT_STACKORHEAPARRAY_H
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
template <typename Type, int StackSize>
|
||||||
|
class BStackOrHeapArray {
|
||||||
|
public:
|
||||||
|
BStackOrHeapArray(size_t count)
|
||||||
|
{
|
||||||
|
if (count > StackSize)
|
||||||
|
fData = new(std::nothrow) Type[count];
|
||||||
|
else
|
||||||
|
fData = fStackData;
|
||||||
|
}
|
||||||
|
|
||||||
|
~BStackOrHeapArray()
|
||||||
|
{
|
||||||
|
if (fData != fStackData)
|
||||||
|
delete[] fData;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsValid() const
|
||||||
|
{
|
||||||
|
return fData != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator Type*()
|
||||||
|
{
|
||||||
|
return fData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type fStackData[StackSize];
|
||||||
|
Type* fData;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
@@ -24,6 +23,7 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
#include <StackOrHeapArray.h>
|
||||||
|
|
||||||
#include <DefaultCatalog.h>
|
#include <DefaultCatalog.h>
|
||||||
#include <LocaleRoster.h>
|
#include <LocaleRoster.h>
|
||||||
@@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
|
|
||||||
using BPrivate::DefaultCatalog;
|
using BPrivate::DefaultCatalog;
|
||||||
using std::auto_ptr;
|
|
||||||
|
|
||||||
|
|
||||||
/*! This file implements the default catalog-type for the opentracker locale
|
/*! This file implements the default catalog-type for the opentracker locale
|
||||||
@@ -150,12 +149,12 @@ DefaultCatalog::ReadFromFile(const char *path)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto_ptr<char> buf(new(std::nothrow) char [sz]);
|
BStackOrHeapArray<char, 0> buf(sz);
|
||||||
if (buf.get() == NULL) {
|
if (!buf.IsValid()) {
|
||||||
fprintf(stderr, "couldn't allocate array of %Ld chars\n", sz);
|
fprintf(stderr, "couldn't allocate array of %Ld chars\n", sz);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
res = catalogFile.Read(buf.get(), sz);
|
res = catalogFile.Read(buf, sz);
|
||||||
if (res < B_OK) {
|
if (res < B_OK) {
|
||||||
fprintf(stderr, "couldn't read from catalog-file %s\n", path);
|
fprintf(stderr, "couldn't read from catalog-file %s\n", path);
|
||||||
return res;
|
return res;
|
||||||
@@ -166,7 +165,7 @@ DefaultCatalog::ReadFromFile(const char *path)
|
|||||||
path);
|
path);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
BMemoryIO memIO(buf.get(), sz);
|
BMemoryIO memIO(buf, sz);
|
||||||
res = Unflatten(&memIO);
|
res = Unflatten(&memIO);
|
||||||
|
|
||||||
if (res == B_OK) {
|
if (res == B_OK) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <memory>
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -32,7 +31,6 @@
|
|||||||
|
|
||||||
|
|
||||||
using BPrivate::PlainTextCatalog;
|
using BPrivate::PlainTextCatalog;
|
||||||
using std::auto_ptr;
|
|
||||||
using std::min;
|
using std::min;
|
||||||
using std::max;
|
using std::max;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
|||||||
Reference in New Issue
Block a user