vcl: replace alloca() with std::unique_ptr

Change-Id: I82b982895ee422bcf5a23756df4d81c89bc47636
This commit is contained in:
Michael Stahl
2015-09-29 14:25:23 +02:00
parent 9555d03c98
commit 28f18b68db
4 changed files with 8 additions and 14 deletions

View File

@@ -53,8 +53,6 @@ using namespace psp;
#include "rtl/ustrbuf.hxx" #include "rtl/ustrbuf.hxx"
#include "sal/alloca.h"
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
@@ -1086,7 +1084,7 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi
// update rMissingCodes by removing resolved unicodes // update rMissingCodes by removing resolved unicodes
if( !rMissingCodes.isEmpty() ) if( !rMissingCodes.isEmpty() )
{ {
sal_uInt32* pRemainingCodes = static_cast<sal_uInt32*>(alloca( rMissingCodes.getLength() * sizeof(sal_uInt32) )); std::unique_ptr<sal_uInt32[]> const pRemainingCodes(new sal_uInt32[rMissingCodes.getLength()]);
int nRemainingLen = 0; int nRemainingLen = 0;
FcCharSet* unicodes; FcCharSet* unicodes;
if (!FcPatternGetCharSet(pSet->fonts[0], FC_CHARSET, 0, &unicodes)) if (!FcPatternGetCharSet(pSet->fonts[0], FC_CHARSET, 0, &unicodes))
@@ -1099,7 +1097,7 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi
pRemainingCodes[ nRemainingLen++ ] = nCode; pRemainingCodes[ nRemainingLen++ ] = nCode;
} }
} }
OUString sStillMissing(pRemainingCodes, nRemainingLen); OUString sStillMissing(pRemainingCodes.get(), nRemainingLen);
#if defined(ENABLE_DBUS) && defined(ENABLE_PACKAGEKIT) #if defined(ENABLE_DBUS) && defined(ENABLE_PACKAGEKIT)
if (get_xid_for_dbus()) if (get_xid_for_dbus())
{ {

View File

@@ -59,8 +59,6 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
#include "sal/alloca.h"
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <unordered_set> #include <unordered_set>
@@ -472,7 +470,7 @@ bool PrintFontManager::PrintFont::readAfmMetrics( MultiAtomProvider* pProvider,
// first transform the character codes to unicode // first transform the character codes to unicode
// note: this only works with single byte encodings // note: this only works with single byte encodings
sal_Unicode* pUnicodes = static_cast<sal_Unicode*>(alloca( pInfo->numOfChars * sizeof(sal_Unicode))); std::unique_ptr<sal_Unicode[]> const pUnicodes(new sal_Unicode[pInfo->numOfChars]);
CharMetricInfo* pChar = pInfo->cmi; CharMetricInfo* pChar = pInfo->cmi;
int i; int i;

View File

@@ -18,7 +18,6 @@
*/ */
#include <sal/types.h> #include <sal/types.h>
#include <sal/alloca.h>
#include <vector> #include <vector>
@@ -244,7 +243,7 @@ PhysicalFontFamily* PhysicalFontCollection::GetGlyphFallbackFont( FontSelectPatt
// there is a matching fallback in the cache // there is a matching fallback in the cache
// so update rMissingCodes with codepoints not yet resolved by this fallback // so update rMissingCodes with codepoints not yet resolved by this fallback
int nRemainingLength = 0; int nRemainingLength = 0;
sal_UCS4* pRemainingCodes = static_cast<sal_UCS4*>(alloca( rMissingCodes.getLength() * sizeof(sal_UCS4) )); std::unique_ptr<sal_UCS4[]> const pRemainingCodes(new sal_UCS4[rMissingCodes.getLength()]);
OUString aFontName; OUString aFontName;
while( nStrIndex < rMissingCodes.getLength() ) while( nStrIndex < rMissingCodes.getLength() )
@@ -254,7 +253,7 @@ PhysicalFontFamily* PhysicalFontCollection::GetGlyphFallbackFont( FontSelectPatt
if( !bCached || (rFontSelData.maSearchName != aFontName) ) if( !bCached || (rFontSelData.maSearchName != aFontName) )
pRemainingCodes[ nRemainingLength++ ] = cChar; pRemainingCodes[ nRemainingLength++ ] = cChar;
} }
rMissingCodes = OUString( pRemainingCodes, nRemainingLength ); rMissingCodes = OUString( pRemainingCodes.get(), nRemainingLength );
} }
else else
{ {

View File

@@ -22,7 +22,6 @@
#include "vcl/printerinfomanager.hxx" #include "vcl/printerinfomanager.hxx"
#include "tools/stream.hxx" #include "tools/stream.hxx"
#include <sal/alloca.h>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <memory> #include <memory>
@@ -293,9 +292,9 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
{ {
rJobData.m_aContext.setParser( rJobData.m_pParser ); rJobData.m_aContext.setParser( rJobData.m_pParser );
int nBytes = bytes - aStream.Tell(); int nBytes = bytes - aStream.Tell();
char* pRemain = static_cast<char*>(alloca( bytes - aStream.Tell() )); std::unique_ptr<char[]> pRemain(new char[bytes - aStream.Tell()]);
aStream.Read( pRemain, nBytes ); aStream.Read( pRemain.get(), nBytes );
rJobData.m_aContext.rebuildFromStreamBuffer( pRemain, nBytes ); rJobData.m_aContext.rebuildFromStreamBuffer( pRemain.get(), nBytes );
bContext = true; bContext = true;
} }
} }