Kaydet (Commit) 77243437 authored tarafından Noel Grandin's avatar Noel Grandin

use unique_ptr in sc

Change-Id: I780157687ba0727ee11f5ccdaf64412eb89c1757
Reviewed-on: https://gerrit.libreoffice.org/66418
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ba4a3e65
...@@ -3769,7 +3769,7 @@ public: ...@@ -3769,7 +3769,7 @@ public:
DynamicKernel( const ScCalcConfig& config, const FormulaTreeNodeRef& r, int nResultSize ); DynamicKernel( const ScCalcConfig& config, const FormulaTreeNodeRef& r, int nResultSize );
virtual ~DynamicKernel() override; virtual ~DynamicKernel() override;
static DynamicKernel* create( const ScCalcConfig& config, const ScTokenArray& rCode, int nResultSize ); static std::unique_ptr<DynamicKernel> create( const ScCalcConfig& config, const ScTokenArray& rCode, int nResultSize );
/// OpenCL code generation /// OpenCL code generation
void CodeGen(); void CodeGen();
...@@ -4077,7 +4077,7 @@ ScMatrixRef FormulaGroupInterpreterOpenCL::inverseMatrix( const ScMatrix& ) ...@@ -4077,7 +4077,7 @@ ScMatrixRef FormulaGroupInterpreterOpenCL::inverseMatrix( const ScMatrix& )
return nullptr; return nullptr;
} }
DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScTokenArray& rCode, int nResultSize ) std::unique_ptr<DynamicKernel> DynamicKernel::create( const ScCalcConfig& rConfig, const ScTokenArray& rCode, int nResultSize )
{ {
// Constructing "AST" // Constructing "AST"
FormulaTokenIterator aCode(rCode); FormulaTokenIterator aCode(rCode);
...@@ -4119,7 +4119,7 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken ...@@ -4119,7 +4119,7 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken
FormulaTreeNodeRef Root = std::make_shared<FormulaTreeNode>(nullptr); FormulaTreeNodeRef Root = std::make_shared<FormulaTreeNode>(nullptr);
Root->Children.push_back(aHashMap[aTokenVector.back()]); Root->Children.push_back(aHashMap[aTokenVector.back()]);
DynamicKernel* pDynamicKernel = new DynamicKernel(rConfig, Root, nResultSize); std::unique_ptr<DynamicKernel> pDynamicKernel(new DynamicKernel(rConfig, Root, nResultSize));
// OpenCL source code generation and kernel compilation // OpenCL source code generation and kernel compilation
try try
...@@ -4130,14 +4130,12 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken ...@@ -4130,14 +4130,12 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken
catch (const UnhandledToken& ut) catch (const UnhandledToken& ut)
{ {
SAL_INFO("sc.opencl", "Dynamic formula compiler: UnhandledToken: " << ut.mMessage << " at " << ut.mFile << ":" << ut.mLineNumber); SAL_INFO("sc.opencl", "Dynamic formula compiler: UnhandledToken: " << ut.mMessage << " at " << ut.mFile << ":" << ut.mLineNumber);
delete pDynamicKernel;
return nullptr; return nullptr;
} }
catch (const InvalidParameterCount& ipc) catch (const InvalidParameterCount& ipc)
{ {
SAL_INFO("sc.opencl", "Dynamic formula compiler: InvalidParameterCount " << ipc.mParameterCount SAL_INFO("sc.opencl", "Dynamic formula compiler: InvalidParameterCount " << ipc.mParameterCount
<< " at " << ipc.mFile << ":" << ipc.mLineNumber); << " at " << ipc.mFile << ":" << ipc.mLineNumber);
delete pDynamicKernel;
return nullptr; return nullptr;
} }
catch (const OpenCLError& oce) catch (const OpenCLError& oce)
...@@ -4148,7 +4146,6 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken ...@@ -4148,7 +4146,6 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken
// OpenCLError used to go to the catch-all below, and not delete pDynamicKernel. Was that // OpenCLError used to go to the catch-all below, and not delete pDynamicKernel. Was that
// intentional, should we not do it here then either? // intentional, should we not do it here then either?
delete pDynamicKernel;
openclwrapper::kernelFailures++; openclwrapper::kernelFailures++;
return nullptr; return nullptr;
} }
...@@ -4158,7 +4155,6 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken ...@@ -4158,7 +4155,6 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken
// Unhandled used to go to the catch-all below, and not delete pDynamicKernel. Was that // Unhandled used to go to the catch-all below, and not delete pDynamicKernel. Was that
// intentional, should we not do it here then either? // intentional, should we not do it here then either?
delete pDynamicKernel;
openclwrapper::kernelFailures++; openclwrapper::kernelFailures++;
return nullptr; return nullptr;
} }
...@@ -4166,7 +4162,6 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken ...@@ -4166,7 +4162,6 @@ DynamicKernel* DynamicKernel::create( const ScCalcConfig& rConfig, const ScToken
{ {
// FIXME: Do we really want to catch random exceptions here? // FIXME: Do we really want to catch random exceptions here?
SAL_WARN("sc.opencl", "Dynamic formula compiler: unexpected exception"); SAL_WARN("sc.opencl", "Dynamic formula compiler: unexpected exception");
// FIXME: Not deleting pDynamicKernel here!?, is that intentional?
openclwrapper::kernelFailures++; openclwrapper::kernelFailures++;
return nullptr; return nullptr;
} }
...@@ -4258,10 +4253,10 @@ public: ...@@ -4258,10 +4253,10 @@ public:
return mpKernel != nullptr; return mpKernel != nullptr;
} }
void setManagedKernel( DynamicKernel* pKernel ) void setManagedKernel( std::unique_ptr<DynamicKernel> pKernel )
{ {
mpKernelStore.reset(pKernel); mpKernelStore = std::move(pKernel);
mpKernel = pKernel; mpKernel = mpKernelStore.get();
} }
CLInterpreterResult launchKernel() CLInterpreterResult launchKernel()
......
...@@ -1137,15 +1137,15 @@ void ScDBFunc::GroupDataPilot() ...@@ -1137,15 +1137,15 @@ void ScDBFunc::GroupDataPilot()
} }
} }
ScDPSaveGroupDimension* pNewGroupDim = nullptr; std::unique_ptr<ScDPSaveGroupDimension> pNewGroupDim;
if ( !pGroupDimension ) if ( !pGroupDimension )
{ {
// create a new group dimension // create a new group dimension
OUString aGroupDimName = OUString aGroupDimName =
pDimData->CreateGroupDimName(aBaseDimName, *pDPObj, false, nullptr); pDimData->CreateGroupDimName(aBaseDimName, *pDPObj, false, nullptr);
pNewGroupDim = new ScDPSaveGroupDimension( aBaseDimName, aGroupDimName ); pNewGroupDim.reset(new ScDPSaveGroupDimension( aBaseDimName, aGroupDimName ));
pGroupDimension = pNewGroupDim; // make changes to the new dim if none existed pGroupDimension = pNewGroupDim.get(); // make changes to the new dim if none existed
if ( pBaseGroupDim ) if ( pBaseGroupDim )
{ {
...@@ -1195,10 +1195,10 @@ void ScDBFunc::GroupDataPilot() ...@@ -1195,10 +1195,10 @@ void ScDBFunc::GroupDataPilot()
if ( pNewGroupDim ) if ( pNewGroupDim )
{ {
pDimData->AddGroupDimension( *pNewGroupDim ); pDimData->AddGroupDimension( *pNewGroupDim );
delete pNewGroupDim; // AddGroupDimension copies the object pNewGroupDim.reset(); // AddGroupDimension copies the object
// don't access pGroupDimension after here // don't access pGroupDimension after here
} }
pGroupDimension = pNewGroupDim = nullptr; pGroupDimension = nullptr;
// set orientation // set orientation
ScDPSaveDimension* pSaveDimension = aData.GetDimensionByName( aGroupDimName ); ScDPSaveDimension* pSaveDimension = aData.GetDimensionByName( aGroupDimName );
......
...@@ -555,13 +555,13 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId, ...@@ -555,13 +555,13 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
uno::Reference <io::XInputStream> xStm = aDataHelper.GetInputStream(nFormatId, OUString()); uno::Reference <io::XInputStream> xStm = aDataHelper.GetInputStream(nFormatId, OUString());
if (xStm.is()) if (xStm.is())
{ {
ScDocument* pInsDoc = new ScDocument( SCDOCMODE_CLIP ); std::unique_ptr<ScDocument> pInsDoc(new ScDocument( SCDOCMODE_CLIP ));
SCTAB nSrcTab = 0; // Biff5 in clipboard: always sheet 0 SCTAB nSrcTab = 0; // Biff5 in clipboard: always sheet 0
pInsDoc->ResetClip( pDoc, nSrcTab ); pInsDoc->ResetClip( pDoc, nSrcTab );
SfxMedium aMed; SfxMedium aMed;
aMed.GetItemSet()->Put( SfxUnoAnyItem( SID_INPUTSTREAM, uno::makeAny( xStm ) ) ); aMed.GetItemSet()->Put( SfxUnoAnyItem( SID_INPUTSTREAM, uno::makeAny( xStm ) ) );
ErrCode eErr = ScFormatFilter::Get().ScImportExcel( aMed, pInsDoc, EIF_AUTO ); ErrCode eErr = ScFormatFilter::Get().ScImportExcel( aMed, pInsDoc.get(), EIF_AUTO );
if ( eErr == ERRCODE_NONE ) if ( eErr == ERRCODE_NONE )
{ {
ScRange aSource; ScRange aSource;
...@@ -600,11 +600,9 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId, ...@@ -600,11 +600,9 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
} }
pInsDoc->SetClipArea( aSource ); pInsDoc->SetClipArea( aSource );
PasteFromClip( InsertDeleteFlags::ALL, pInsDoc, PasteFromClip( InsertDeleteFlags::ALL, pInsDoc.get(),
ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE, ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
bAllowDialogs ); bAllowDialogs );
delete pInsDoc;
bRet = true; bRet = true;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment