[Libreoffice-commits] core.git: 9 commits - compilerplugins/clang include/jvmfwk jvmfwk/inc jvmfwk/plugins jvmfwk/source
Stephan Bergmann
sbergman at redhat.com
Thu Apr 13 15:33:19 UTC 2017
compilerplugins/clang/useuniqueptr.cxx | 9
include/jvmfwk/framework.hxx | 1
jvmfwk/inc/elements.hxx | 7
jvmfwk/inc/vendorplugin.hxx | 27 -
jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 51 +--
jvmfwk/source/elements.cxx | 20 -
jvmfwk/source/framework.cxx | 290 +++++---------------
jvmfwk/source/framework.hxx | 36 --
8 files changed, 115 insertions(+), 326 deletions(-)
New commits:
commit 13180e0c7cdfbaa86b8380fe7e8966f8ebaf1e00
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 17:01:13 2017 +0200
Use std::unique_ptr<JavaInfo> in createJavaInfo
Change-Id: Ie39c40e0fd05f75e734d8cd2d33a7fb13c746f77
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index 273db8f5a99e..a725b2cec55d 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -148,14 +148,9 @@ OString getPluginJarPath(
#endif // UNX
-JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info)
+std::unique_ptr<JavaInfo> createJavaInfo(
+ const rtl::Reference<VendorBase> & info)
{
- JavaInfo* pInfo = new JavaInfo;
- pInfo->sVendor = info->getVendor();
- pInfo->sLocation = info->getHome();
- pInfo->sVersion = info->getVersion();
- pInfo->nFeatures = info->supportsAccessibility() ? 1 : 0;
- pInfo->nRequirements = info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0;
OUStringBuffer buf(1024);
buf.append(info->getRuntimeLibrary());
if (!info->getLibraryPath().isEmpty())
@@ -164,13 +159,15 @@ JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info)
buf.append(info->getLibraryPath());
buf.append("\n");
}
-
OUString sVendorData = buf.makeStringAndClear();
- pInfo->arVendorData = rtl::ByteSequence(
- reinterpret_cast<sal_Int8*>(sVendorData.pData->buffer),
- sVendorData.getLength() * sizeof(sal_Unicode));
-
- return pInfo;
+ return std::unique_ptr<JavaInfo>(
+ new JavaInfo{
+ info->getVendor(), info->getHome(), info->getVersion(),
+ sal_uInt64(info->supportsAccessibility() ? 1 : 0),
+ sal_uInt64(info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0),
+ rtl::ByteSequence(
+ reinterpret_cast<sal_Int8*>(sVendorData.pData->buffer),
+ sVendorData.getLength() * sizeof(sal_Unicode))});
}
OUString getRuntimeLib(const rtl::ByteSequence & data)
@@ -337,7 +334,7 @@ javaPluginError jfw_plugin_getAllJavaInfos(
typedef vector<rtl::Reference<VendorBase> >::const_iterator cit;
for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii)
{
- parJavaInfo->push_back(std::unique_ptr<JavaInfo>(createJavaInfo(*ii)));
+ parJavaInfo->push_back(createJavaInfo(*ii));
}
return javaPluginError::NONE;
@@ -371,7 +368,7 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
aVendorInfo, sMinVersion, sMaxVersion, arExcludeList);
if (errorcode == javaPluginError::NONE)
- ppInfo->reset(createJavaInfo(aVendorInfo));
+ *ppInfo = createJavaInfo(aVendorInfo);
return errorcode;
}
@@ -407,7 +404,7 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
if (errorcode == javaPluginError::NONE)
{
- ppInfo->reset(createJavaInfo(infoJavaHome[0]));
+ *ppInfo = createJavaInfo(infoJavaHome[0]);
return javaPluginError::NONE;
}
}
@@ -449,8 +446,7 @@ javaPluginError jfw_plugin_getJavaInfosFromPath(
if (errorcode == javaPluginError::NONE)
{
- vecVerifiedInfos.push_back(
- std::unique_ptr<JavaInfo>(createJavaInfo(currentInfo)));
+ vecVerifiedInfos.push_back(createJavaInfo(currentInfo));
}
}
}
commit f276171835c7b820ba271e7d3c28d6704ec823b0
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 16:54:32 2017 +0200
Use std::unique_ptr<JavaInfo> in jfw_plugin_getAllJavaInfos
Change-Id: I2beb95c42c666a788a87a45f59bc15ccfcf25aa6
diff --git a/jvmfwk/inc/vendorplugin.hxx b/jvmfwk/inc/vendorplugin.hxx
index 141a93689a8e..a8a7a4b3c7ae 100644
--- a/jvmfwk/inc/vendorplugin.hxx
+++ b/jvmfwk/inc/vendorplugin.hxx
@@ -74,13 +74,6 @@ enum class javaPluginError
The JavaInfo structures returned in <code>parJavaInfo</code> should be ordered
according to their version. The one, representing a JRE with the highest
version should be the first in the array. </p>
- <p>
- The function allocates memory for an array and all the JavaInfo objects returned
- in <code>parJavaInfo</code>. The caller must delete each JavaInfo object.
- The array is to be
- freed by rtl_freeMemory.
- In case an error occurred <code>parJavaInfo</code> need not be freed.
- </p>
@param sVendor
[in] only JREs from this vendor are examined. This parameter always contains
a vendor string. That is, the string it is not empty.
@@ -93,10 +86,7 @@ enum class javaPluginError
versions must not be returned by this function.
@param parJavaInfo
[out] if the function runs successfully then <code>parJavaInfo</code> contains
- on return an array of pointers to <code>JavaInfo</code> objects.
- @param nSizeJavaInfo
- [out] the number of <code>JavaInfo</code> pointers contained in
- <code>parJavaInfo</code>.
+ on return a vector of pointers to <code>JavaInfo</code> objects.
@return
javaPluginError::NONE the function ran successfully.</br>
@@ -112,8 +102,7 @@ javaPluginError jfw_plugin_getAllJavaInfos(
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const & arExcludeList,
- JavaInfo*** parJavaInfo,
- sal_Int32 *nSizeJavaInfo,
+ std::vector<std::unique_ptr<JavaInfo>> * parJavaInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
/** obtains information for a JRE at a given location.
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index 261c648f5da5..273db8f5a99e 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -299,19 +299,15 @@ javaPluginError jfw_plugin_getAllJavaInfos(
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const &arExcludeList,
- JavaInfo*** parJavaInfo,
- sal_Int32 *nLenInfoList,
+ std::vector<std::unique_ptr<JavaInfo>>* parJavaInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos)
{
assert(parJavaInfo);
- assert(nLenInfoList);
OSL_ASSERT(!sVendor.isEmpty());
if (sVendor.isEmpty())
return javaPluginError::InvalidArg;
- JavaInfo** arInfo = nullptr;
-
//Find all JREs
vector<rtl::Reference<VendorBase> > vecInfos =
addAllJREInfos(checkJavaHomeAndPath, infos);
@@ -337,17 +333,13 @@ javaPluginError jfw_plugin_getAllJavaInfos(
}
//Now vecVerifiedInfos contains all those JREs which meet the version requirements
//Transfer them into the array that is passed out.
- arInfo = static_cast<JavaInfo**>(rtl_allocateMemory(vecVerifiedInfos.size() * sizeof (JavaInfo*)));
- int j = 0;
+ parJavaInfo->clear();
typedef vector<rtl::Reference<VendorBase> >::const_iterator cit;
- for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii, ++j)
+ for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii)
{
- arInfo[j] = createJavaInfo(*ii);
+ parJavaInfo->push_back(std::unique_ptr<JavaInfo>(createJavaInfo(*ii)));
}
- *nLenInfoList = vecVerifiedInfos.size();
-
- *parJavaInfo = arInfo;
return javaPluginError::NONE;
}
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 90aa407e2eb7..ddc5e6c19747 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -75,8 +75,7 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
//get all installations of one vendor according to minVersion,
//maxVersion and excludeVersions
- sal_Int32 cInfos = 0;
- JavaInfo** arInfos = nullptr;
+ std::vector<std::unique_ptr<JavaInfo>> arInfos;
std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
javaPluginError plerr = jfw_plugin_getAllJavaInfos(
true,
@@ -85,16 +84,13 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
& arInfos,
- & cInfos,
infos);
if (plerr != javaPluginError::NONE)
return JFW_E_ERROR;
- for (int j = 0; j < cInfos; j++)
- vecInfo.push_back(std::unique_ptr<JavaInfo>(arInfos[j]));
-
- rtl_freeMemory(arInfos);
+ for (auto & j: arInfos)
+ vecInfo.push_back(std::move(j));
//Check if the current plugin can detect JREs at the location
// of the paths added by jfw_addJRELocation
@@ -423,8 +419,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
//get all installations of one vendor according to minVersion,
//maxVersion and excludeVersions
- sal_Int32 cInfos = 0;
- JavaInfo** arInfos = nullptr;
+ std::vector<std::unique_ptr<JavaInfo>> arInfos;
javaPluginError plerr = jfw_plugin_getAllJavaInfos(
false,
vendor,
@@ -432,22 +427,14 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
& arInfos,
- & cInfos,
infos);
if (plerr != javaPluginError::NONE)
continue;
//iterate over all installations to find the best which has
//all features
- if (cInfos == 0)
+ for (auto & pJInfo: arInfos)
{
- rtl_freeMemory(arInfos);
- continue;
- }
- for (int ii = 0; ii < cInfos; ii++)
- {
- JavaInfo* pJInfo = arInfos[ii];
-
// compare features
// If the user does not require any features (nFeatureFlags = 0)
// then the first installation is used
@@ -455,8 +442,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
//the just found Java implements all required features
//currently there is only accessibility!!!
- aCurrentInfo.reset(
- jfw::CJavaInfo::copyJavaInfo(pJInfo));
+ aCurrentInfo = std::move(pJInfo);
bInfoFound = true;
break;
}
@@ -464,15 +450,9 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
// We remember the first installation in aCurrentInfo if
// no JavaInfo has been found before:
- aCurrentInfo.reset(
- jfw::CJavaInfo::copyJavaInfo(pJInfo));
+ aCurrentInfo = std::move(pJInfo);
}
}
- //The array returned by jfw_plugin_getAllJavaInfos must be freed as well as
- //its contents
- for (int j = 0; j < cInfos; j++)
- delete arInfos[j];
- rtl_freeMemory(arInfos);
if (bInfoFound)
break;
@@ -928,9 +908,4 @@ void jfw_unlock()
jfw::FwkMutex::get().release();
}
-JavaInfo * jfw::CJavaInfo::copyJavaInfo(const JavaInfo * pInfo)
-{
- return pInfo == nullptr ? nullptr : new JavaInfo(*pInfo);
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmfwk/source/framework.hxx b/jvmfwk/source/framework.hxx
index 3ecd08314ddb..590543b8d6ba 100644
--- a/jvmfwk/source/framework.hxx
+++ b/jvmfwk/source/framework.hxx
@@ -27,11 +27,6 @@
namespace jfw
{
-namespace CJavaInfo
-{
- JavaInfo * copyJavaInfo(const JavaInfo * pInfo);
-}
-
class FrameworkException : public std::exception
{
public:
commit 8d475bb13fa44a3a2385635dfbc49ab1b2765dd1
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 16:06:17 2017 +0200
Use std::unique_ptr<JavaInfo> in jfw_plugin_getJavaInfoByPath
Change-Id: I3511eaa12bb689a374a775204a3480d7c667a915
diff --git a/jvmfwk/inc/vendorplugin.hxx b/jvmfwk/inc/vendorplugin.hxx
index edd32854dda7..141a93689a8e 100644
--- a/jvmfwk/inc/vendorplugin.hxx
+++ b/jvmfwk/inc/vendorplugin.hxx
@@ -160,7 +160,7 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const &arExcludeList,
- JavaInfo ** ppInfo);
+ std::unique_ptr<JavaInfo> * ppInfo);
/** obtains information for a JRE referenced by the JAVA_HOME environment variable.
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index f336532f3515..261c648f5da5 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -357,7 +357,7 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const &arExcludeList,
- JavaInfo ** ppInfo)
+ std::unique_ptr<JavaInfo> * ppInfo)
{
assert(ppInfo != nullptr);
OSL_ASSERT(!sPath.isEmpty());
@@ -379,7 +379,7 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
aVendorInfo, sMinVersion, sMaxVersion, arExcludeList);
if (errorcode == javaPluginError::NONE)
- *ppInfo = createJavaInfo(aVendorInfo);
+ ppInfo->reset(createJavaInfo(aVendorInfo));
return errorcode;
}
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 87f4d3adce2b..90aa407e2eb7 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -101,15 +101,14 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
//Check every manually added location
for (auto const & ii: vecJRELocations)
{
- JavaInfo * info;
+ std::unique_ptr<JavaInfo> aInfo;
plerr = jfw_plugin_getJavaInfoByPath(
ii,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
- &info);
- std::unique_ptr<JavaInfo> aInfo(info);
+ &aInfo);
if (plerr == javaPluginError::NoJre)
continue;
if (plerr == javaPluginError::FailedVersion)
@@ -499,15 +498,14 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
for (citLoc it = vecJRELocations.begin();
it != vecJRELocations.end(); ++it)
{
- JavaInfo * info;
+ std::unique_ptr<JavaInfo> aInfo;
javaPluginError err = jfw_plugin_getJavaInfoByPath(
*it,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
- &info);
- std::unique_ptr<JavaInfo> aInfo(info);
+ &aInfo);
if (err == javaPluginError::NoJre)
continue;
if (err == javaPluginError::FailedVersion)
@@ -667,18 +665,16 @@ javaFrameworkError jfw_getJavaInfoByPath(OUString const & pPath, std::unique_ptr
//ask the plugin if this is a JRE.
//If so check if it meets the version requirements.
//Only if it does return a JavaInfo
- JavaInfo* pInfo = nullptr;
javaPluginError plerr = jfw_plugin_getJavaInfoByPath(
pPath,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
- & pInfo);
+ ppInfo);
if (plerr == javaPluginError::NONE)
{
- ppInfo->reset(pInfo);
break;
}
else if(plerr == javaPluginError::FailedVersion)
commit 74315cbccf13b578551390762d5efc0a30c2d65b
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 15:25:28 2017 +0200
Use std::unique_ptr<JavaInfo> in jfw_plugin_getJavaInfoFromJavaHome
Change-Id: I8be48d1eec799f347a5edaa67837cf1bbf4d2cc3
diff --git a/jvmfwk/inc/vendorplugin.hxx b/jvmfwk/inc/vendorplugin.hxx
index 875185551688..edd32854dda7 100644
--- a/jvmfwk/inc/vendorplugin.hxx
+++ b/jvmfwk/inc/vendorplugin.hxx
@@ -190,7 +190,7 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
*/
javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
- JavaInfo ** ppInfo,
+ std::unique_ptr<JavaInfo> * ppInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index da7f6218d0d3..f336532f3515 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -386,7 +386,8 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
std::vector<pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
- JavaInfo ** ppInfo, std::vector<rtl::Reference<VendorBase>> & infos)
+ std::unique_ptr<JavaInfo> * ppInfo,
+ std::vector<rtl::Reference<VendorBase>> & infos)
{
assert(ppInfo);
@@ -414,7 +415,7 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
if (errorcode == javaPluginError::NONE)
{
- *ppInfo = createJavaInfo(infoJavaHome[0]);
+ ppInfo->reset(createJavaInfo(infoJavaHome[0]));
return javaPluginError::NONE;
}
}
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 0dd643d92d45..87f4d3adce2b 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -364,20 +364,17 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
// first inspect Java installation that the JAVA_HOME
// environment variable points to (if it is set)
- JavaInfo* pHomeInfo = nullptr;
- if (jfw_plugin_getJavaInfoFromJavaHome(versionInfos, &pHomeInfo, infos)
+ if (jfw_plugin_getJavaInfoFromJavaHome(
+ versionInfos, &aCurrentInfo, infos)
== javaPluginError::NONE)
{
- aCurrentInfo.reset(pHomeInfo);
-
// compare features
// if the user does not require any features (nFeatureFlags = 0)
// or the Java installation provides all features, then this installation is used
- if ((pHomeInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
+ if ((aCurrentInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
{
bInfoFound = true;
}
- delete pHomeInfo;
}
// if no Java installation providing all features was detected by using JAVA_HOME,
commit 626dec44e33727a56353efb7f4eee83e93bc2f3d
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 15:19:17 2017 +0200
Use std::unique_ptr<JavaInfo> in jfw_plugin_getJavaInfosFromPath
...thereby fixing a memory leak
Change-Id: I1aa91eeb407987abcdaa5221f4abd447f881c5d2
diff --git a/jvmfwk/inc/vendorplugin.hxx b/jvmfwk/inc/vendorplugin.hxx
index d456fe74a59c..875185551688 100644
--- a/jvmfwk/inc/vendorplugin.hxx
+++ b/jvmfwk/inc/vendorplugin.hxx
@@ -25,6 +25,8 @@
#include <rtl/ref.hxx>
#include <rtl/ustring.h>
#include "jni.h"
+
+#include <memory>
#include <vector>
#include <utility>
#include "elements.hxx"
@@ -204,10 +206,6 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
The JavaInfo structures returned in <code>vecJavaInfosFromPath</code> should be ordered
according to their occurrence in the PATH. The one that is the first one on the PATH
is also the first element in the vector.</p>
- <p>
- The function allocates memory for all the JavaInfo objects returned
- in <code>vecJavaInfosFromPath</code>. The caller must delete each JavaInfo object.
- </p>
@param vecVendorInfos
[in] vector specifying the vendor and version requirements that the JRE must fulfill.
The vector contains pairs of vendors and the respective version requirements
@@ -230,7 +228,7 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
javaPluginError jfw_plugin_getJavaInfosFromPath(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
- std::vector<JavaInfo*> & vecJavaInfosFromPath,
+ std::vector<std::unique_ptr<JavaInfo>> & vecJavaInfosFromPath,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
/** starts a Java Virtual Machine.
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index 7ade439ed694..da7f6218d0d3 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -32,6 +32,7 @@
#include <cassert>
#include <memory>
+#include <utility>
#include <vector>
#include "config_options.h"
@@ -424,14 +425,14 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
javaPluginError jfw_plugin_getJavaInfosFromPath(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
- std::vector<JavaInfo*> & javaInfosFromPath,
+ std::vector<std::unique_ptr<JavaInfo>> & javaInfosFromPath,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos)
{
// find JREs from PATH
vector<rtl::Reference<VendorBase>> vecInfosFromPath;
addJavaInfosFromPath(infos, vecInfosFromPath);
- vector<JavaInfo*> vecVerifiedInfos;
+ vector<std::unique_ptr<JavaInfo>> vecVerifiedInfos;
// copy infos of JREs that meet version requirements to vecVerifiedInfos
typedef vector<rtl::Reference<VendorBase> >::iterator it;
@@ -455,7 +456,8 @@ javaPluginError jfw_plugin_getJavaInfosFromPath(
if (errorcode == javaPluginError::NONE)
{
- vecVerifiedInfos.push_back(createJavaInfo(currentInfo));
+ vecVerifiedInfos.push_back(
+ std::unique_ptr<JavaInfo>(createJavaInfo(currentInfo)));
}
}
}
@@ -464,7 +466,7 @@ javaPluginError jfw_plugin_getJavaInfosFromPath(
if (vecVerifiedInfos.empty())
return javaPluginError::NoJre;
- javaInfosFromPath = vecVerifiedInfos;
+ javaInfosFromPath = std::move(vecVerifiedInfos);
return javaPluginError::NONE;
}
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 63d5733f445a..0dd643d92d45 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -384,35 +384,28 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
// query PATH for Java installations
if (!bInfoFound)
{
- std::vector<JavaInfo*> vecJavaInfosFromPath;
+ std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath;
if (jfw_plugin_getJavaInfosFromPath(
versionInfos, vecJavaInfosFromPath, infos)
== javaPluginError::NONE)
{
- std::vector<JavaInfo*>::const_iterator it = vecJavaInfosFromPath.begin();
- while(it != vecJavaInfosFromPath.end() && !bInfoFound)
+ for (auto & pJInfo: vecJavaInfosFromPath)
{
- JavaInfo* pJInfo = *it;
- if (pJInfo != nullptr)
+ // if the current Java installation implements all required features: use it
+ if ((pJInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
{
- // if the current Java installation implements all required features: use it
- if ((pJInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
- {
- aCurrentInfo.reset(pJInfo);
- bInfoFound = true;
- }
- else if (!aCurrentInfo)
- {
- // current Java installation does not provide all features
- // but no Java installation has been detected before
- // -> remember the current one until one is found
- // that provides all features
- aCurrentInfo.reset(pJInfo);
- }
- else
- delete pJInfo;
+ aCurrentInfo = std::move(pJInfo);
+ bInfoFound = true;
+ break;
+ }
+ else if (!aCurrentInfo)
+ {
+ // current Java installation does not provide all features
+ // but no Java installation has been detected before
+ // -> remember the current one until one is found
+ // that provides all features
+ aCurrentInfo = std::move(pJInfo);
}
- ++it;
}
}
}
commit 6925007c2a86d45a8d71f08ef46e56bb3eda21e3
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 15:18:14 2017 +0200
Simplify jfw_findAllJREs
...dropping remaining uses of CJavaInfo
Change-Id: I76afd5af927233712181f58b14fe6f4c1a9c15c2
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 9b607ecffea3..f038bd9c1485 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -43,12 +43,6 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
if (isInUnoIncludeFile(destructorDecl))
return true;
-/*
- StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(destructorDecl->getLocStart()));
- // weird stuff, passing pointers to internal members of struct
- if (aFileName.startswith(SRCDIR "/include/jvmfwk/framework.hxx"))
- return true;
-*/
if (destructorDecl->getBody() == nullptr)
return true;
const CompoundStmt* compoundStmt = dyn_cast< CompoundStmt >( destructorDecl->getBody() );
@@ -88,9 +82,6 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(pFieldDecl->getLocStart()));
if (aFileName.startswith(WORKDIR))
return true;
- // weird stuff, passing pointers to internal members of struct
- if (aFileName == SRCDIR "/jvmfwk/source/framework.hxx")
- return true;
// passes and stores pointers to member fields
if (aFileName.startswith(SRCDIR "/sot/source/sdstor/stgdir.hxx"))
return true;
diff --git a/include/jvmfwk/framework.hxx b/include/jvmfwk/framework.hxx
index afab60eef427..767727146c63 100644
--- a/include/jvmfwk/framework.hxx
+++ b/include/jvmfwk/framework.hxx
@@ -378,7 +378,6 @@ JVMFWK_DLLPUBLIC javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInf
@param parInfo
[out] on returns it contains a vector of <code>JavaInfo</code> pointers.
- Any previously contained elements are removed first.
@return
JFW_E_NONE function ran successfully.<br/>
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index d817bd36ee2c..63d5733f445a 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -21,6 +21,8 @@
#include <cassert>
#include <memory>
+#include <utility>
+
#include "rtl/ustring.hxx"
#include "rtl/bootstrap.hxx"
#include "osl/thread.hxx"
@@ -28,7 +30,6 @@
#include "jvmfwk/framework.hxx"
#include "vendorplugin.hxx"
#include <vector>
-#include <functional>
#include <algorithm>
#include "framework.hxx"
#include "fwkutil.hxx"
@@ -55,30 +56,20 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
try
{
osl::MutexGuard guard(jfw::FwkMutex::get());
- pparInfo->clear();
jfw::VendorSettings aVendorSettings;
std::vector<OUString> vecVendors =
aVendorSettings.getSupportedVendors();
//Add the JavaInfos found by jfw_plugin_getAllJavaInfos to the vector
- //Make sure that the contents are destroyed if this
- //function returns with an error
- std::vector<jfw::CJavaInfo> vecInfo;
- //Add the JavaInfos found by jfw_plugin_getJavaInfoByPath to this vector
- //Make sure that the contents are destroyed if this
- //function returns with an error
- std::vector<jfw::CJavaInfo> vecInfoManual;
- typedef std::vector<jfw::CJavaInfo>::iterator it_info;
+ std::vector<std::unique_ptr<JavaInfo>> vecInfo;
//get the list of paths to jre locations which have been
//added manually
const jfw::MergedSettings settings;
const std::vector<OUString>& vecJRELocations =
settings.getJRELocations();
//Use every plug-in library to get Java installations.
- typedef std::vector<OUString>::const_iterator ci_pl;
- for (ci_pl i = vecVendors.begin(); i != vecVendors.end(); ++i)
+ for (auto const & vendor: vecVendors)
{
- const OUString & vendor = *i;
jfw::VersionInfo versionInfo =
aVendorSettings.getVersionInformation(vendor);
@@ -101,26 +92,24 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
return JFW_E_ERROR;
for (int j = 0; j < cInfos; j++)
- vecInfo.push_back(jfw::CJavaInfo::createWrapper(arInfos[j]));
+ vecInfo.push_back(std::unique_ptr<JavaInfo>(arInfos[j]));
rtl_freeMemory(arInfos);
//Check if the current plugin can detect JREs at the location
// of the paths added by jfw_addJRELocation
- //get the function from the plugin
- typedef std::vector<OUString>::const_iterator citLoc;
//Check every manually added location
- for (citLoc ii = vecJRELocations.begin();
- ii != vecJRELocations.end(); ++ii)
+ for (auto const & ii: vecJRELocations)
{
- jfw::CJavaInfo aInfo;
+ JavaInfo * info;
plerr = jfw_plugin_getJavaInfoByPath(
- *ii,
+ ii,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
- & aInfo.pInfo);
+ &info);
+ std::unique_ptr<JavaInfo> aInfo(info);
if (plerr == javaPluginError::NoJre)
continue;
if (plerr == javaPluginError::FailedVersion)
@@ -128,53 +117,29 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
else if (plerr != javaPluginError::NONE)
return JFW_E_ERROR;
- if (aInfo)
+ // Was this JRE already added? Different plugins could detect
+ // the same JRE. Also make sure vecInfo contains only JavaInfos
+ // for the vendors for which there is a javaSelection/plugins/
+ // library entry in the javavendors.xml; jfw_getJavaInfoByPath
+ // can return a JavaInfo of any vendor:
+ if ((std::find_if(
+ vecInfo.begin(), vecInfo.end(),
+ [&aInfo](std::unique_ptr<JavaInfo> const & info) {
+ return areEqualJavaInfo(
+ info.get(), aInfo.get());
+ })
+ == vecInfo.end())
+ && (std::find(
+ vecVendors.begin(), vecVendors.end(),
+ aInfo->sVendor)
+ != vecVendors.end()))
{
- //Was this JRE already added?. Different plugins could detect
- //the same JRE
- it_info it_duplicate =
- std::find_if(vecInfoManual.begin(), vecInfoManual.end(),
- std::bind(areEqualJavaInfo, std::placeholders::_1, aInfo));
- if (it_duplicate == vecInfoManual.end())
- vecInfoManual.push_back(aInfo);
- }
- }
- }
- //Make sure vecInfoManual contains only JavaInfos for the vendors for which
- //there is a javaSelection/plugins/library entry in the javavendors.xml
- //To obtain the JavaInfos for the manually added JRE locations the function
- //jfw_getJavaInfoByPath is called which can return a JavaInfo of any vendor.
- std::vector<jfw::CJavaInfo> vecInfoManual2;
- for (it_info ivm = vecInfoManual.begin(); ivm != vecInfoManual.end(); ++ivm)
- {
- for (ci_pl ii = vecVendors.begin(); ii != vecVendors.end(); ++ii)
- {
- if ( ii->equals((*ivm)->sVendor))
- {
- vecInfoManual2.push_back(*ivm);
- break;
+ vecInfo.push_back(std::move(aInfo));
}
}
}
- //Check which JavaInfo from vector vecInfoManual2 is already
- //contained in vecInfo. If it already exists then remove it from
- //vecInfoManual2
- for (it_info j = vecInfo.begin(); j != vecInfo.end(); ++j)
- {
- it_info it_duplicate =
- std::find_if(vecInfoManual2.begin(), vecInfoManual2.end(),
- std::bind(areEqualJavaInfo, std::placeholders::_1, *j));
- if (it_duplicate != vecInfoManual2.end())
- vecInfoManual2.erase(it_duplicate);
- }
- typedef std::vector<jfw::CJavaInfo>::iterator it;
- //Add the automatically detected JREs
- for (it k = vecInfo.begin(); k != vecInfo.end(); ++k)
- pparInfo->push_back(std::unique_ptr<JavaInfo>(k->detach()));
- //Add the manually detected JREs
- for (it l = vecInfoManual2.begin(); l != vecInfoManual2.end(); ++l)
- pparInfo->push_back(std::unique_ptr<JavaInfo>(l->detach()));
+ *pparInfo = std::move(vecInfo);
return JFW_E_NONE;
}
@@ -977,68 +942,9 @@ void jfw_unlock()
jfw::FwkMutex::get().release();
}
-
-namespace jfw
-{
-CJavaInfo::CJavaInfo(): pInfo(nullptr)
-{
-}
-
-CJavaInfo::CJavaInfo(const CJavaInfo & info)
-{
- pInfo = copyJavaInfo(info.pInfo);
-}
-
-CJavaInfo::CJavaInfo(::JavaInfo * info, _transfer_ownership)
-{
- pInfo = info;
-}
-CJavaInfo CJavaInfo::createWrapper(::JavaInfo* info)
-{
- return CJavaInfo(info, TRANSFER);
-}
-void CJavaInfo::attach(::JavaInfo * info)
-{
- delete pInfo;
- pInfo = info;
-}
-::JavaInfo * CJavaInfo::detach()
-{
- JavaInfo * tmp = pInfo;
- pInfo = nullptr;
- return tmp;
-}
-
-CJavaInfo::~CJavaInfo()
-{
- delete pInfo;
-}
-
-
-JavaInfo * CJavaInfo::copyJavaInfo(const JavaInfo * pInfo)
+JavaInfo * jfw::CJavaInfo::copyJavaInfo(const JavaInfo * pInfo)
{
return pInfo == nullptr ? nullptr : new JavaInfo(*pInfo);
}
-CJavaInfo & CJavaInfo::operator = (const CJavaInfo& info)
-{
- if (&info == this)
- return *this;
-
- delete pInfo;
- pInfo = copyJavaInfo(info.pInfo);
- return *this;
-}
-CJavaInfo & CJavaInfo::operator = (const ::JavaInfo* info)
-{
- if (info == pInfo)
- return *this;
-
- delete pInfo;
- pInfo = copyJavaInfo(info);
- return *this;
-}
-
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmfwk/source/framework.hxx b/jvmfwk/source/framework.hxx
index 3f9e5ff6ab85..3ecd08314ddb 100644
--- a/jvmfwk/source/framework.hxx
+++ b/jvmfwk/source/framework.hxx
@@ -27,38 +27,10 @@
namespace jfw
{
-class CJavaInfo
+namespace CJavaInfo
{
- enum _transfer_ownership {TRANSFER};
- /*Attaching the pointer to this class. The argument pInfo must not
- be freed afterwards.
- */
- CJavaInfo(::JavaInfo * info, _transfer_ownership);
-
-public:
- ::JavaInfo * pInfo;
-
-
- CJavaInfo();
- CJavaInfo(const CJavaInfo &);
- ~CJavaInfo();
- CJavaInfo& operator =(const ::JavaInfo* info);
- CJavaInfo & operator = (const CJavaInfo& info);
-
- /* The returned class takes ownership of the argument info. info
- must not been freed afterwards.
- */
- static CJavaInfo createWrapper(::JavaInfo* info);
- /*Attaching the pointer to this class. The argument pInfo must not
- be freed afterwards.
- */
- void attach(::JavaInfo* pInfo);
- ::JavaInfo * detach();
- const ::JavaInfo* operator ->() const { return pInfo;}
- operator ::JavaInfo* () { return pInfo;}
-
- static JavaInfo * copyJavaInfo(const JavaInfo * pInfo);
-};
+ JavaInfo * copyJavaInfo(const JavaInfo * pInfo);
+}
class FrameworkException : public std::exception
{
commit 77e5a6d857bd3a1a6a59891aab9b5d9bb9bc85cf
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 12:27:50 2017 +0200
Replace a use of CJavaInfo with std::unique_ptr<JavaInfo>
Change-Id: Ib659d6edf362901a95cfb50ac008520805ad0fb0
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 4786b9424844..d817bd36ee2c 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -366,7 +366,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
return JFW_E_DIRECT_MODE;
sal_uInt64 nFeatureFlags = 0;
- jfw::CJavaInfo aCurrentInfo;
+ std::unique_ptr<JavaInfo> aCurrentInfo;
//Determine if accessibility support is needed
bool bSupportAccessibility = jfw::isAccessibilitySupportDesired();
nFeatureFlags = bSupportAccessibility ?
@@ -403,7 +403,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
if (jfw_plugin_getJavaInfoFromJavaHome(versionInfos, &pHomeInfo, infos)
== javaPluginError::NONE)
{
- aCurrentInfo = pHomeInfo;
+ aCurrentInfo.reset(pHomeInfo);
// compare features
// if the user does not require any features (nFeatureFlags = 0)
@@ -433,19 +433,19 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
// if the current Java installation implements all required features: use it
if ((pJInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
{
- aCurrentInfo = pJInfo;
+ aCurrentInfo.reset(pJInfo);
bInfoFound = true;
}
- else if (static_cast<JavaInfo*>(aCurrentInfo) == nullptr)
+ else if (!aCurrentInfo)
{
// current Java installation does not provide all features
// but no Java installation has been detected before
// -> remember the current one until one is found
// that provides all features
- aCurrentInfo = pJInfo;
+ aCurrentInfo.reset(pJInfo);
}
-
- delete pJInfo;
+ else
+ delete pJInfo;
}
++it;
}
@@ -494,10 +494,6 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
JavaInfo* pJInfo = arInfos[ii];
- //We remember the first installation in aCurrentInfo
- // if no JavaInfo has been found before
- if (aCurrentInfo.getLocation().isEmpty())
- aCurrentInfo = pJInfo;
// compare features
// If the user does not require any features (nFeatureFlags = 0)
// then the first installation is used
@@ -505,10 +501,18 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
//the just found Java implements all required features
//currently there is only accessibility!!!
- aCurrentInfo = pJInfo;
+ aCurrentInfo.reset(
+ jfw::CJavaInfo::copyJavaInfo(pJInfo));
bInfoFound = true;
break;
}
+ else if (!aCurrentInfo)
+ {
+ // We remember the first installation in aCurrentInfo if
+ // no JavaInfo has been found before:
+ aCurrentInfo.reset(
+ jfw::CJavaInfo::copyJavaInfo(pJInfo));
+ }
}
//The array returned by jfw_plugin_getAllJavaInfos must be freed as well as
//its contents
@@ -521,7 +525,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
//All Java installations found by the current plug-in lib
//do not provide the required features. Try the next plug-in
}
- if (static_cast<JavaInfo*>(aCurrentInfo) == nullptr)
+ if (!aCurrentInfo)
{//The plug-ins did not find a suitable Java. Now try the paths which have been
//added manually.
//get the list of paths to jre locations which have been added manually
@@ -565,15 +569,15 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
//the just found Java implements all required features
//currently there is only accessibility!!!
- aCurrentInfo = aInfo.release();
+ aCurrentInfo = std::move(aInfo);
bInfoFound = true;
break;
}
- else if (aCurrentInfo.getLocation().isEmpty())
+ else if (!aCurrentInfo)
{
// We remember the very first installation in
// aCurrentInfo:
- aCurrentInfo = aInfo.release();
+ aCurrentInfo = std::move(aInfo);
}
}
}//end iterate over paths
@@ -582,18 +586,17 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
}// end iterate plug-ins
}
}
- if (static_cast<JavaInfo*>(aCurrentInfo))
+ if (aCurrentInfo)
{
jfw::NodeJava javaNode(jfw::NodeJava::USER);
- javaNode.setJavaInfo(aCurrentInfo,true);
+ javaNode.setJavaInfo(aCurrentInfo.get(),true);
javaNode.write();
//remember that this JRE was selected in this process
jfw::setJavaSelected();
if (pInfo !=nullptr)
{
- //copy to out param
- pInfo->reset(jfw::CJavaInfo::copyJavaInfo(aCurrentInfo.pInfo));
+ *pInfo = std::move(aCurrentInfo);
}
}
else
@@ -1036,14 +1039,6 @@ CJavaInfo & CJavaInfo::operator = (const ::JavaInfo* info)
return *this;
}
-OUString CJavaInfo::getLocation() const
-{
- if (pInfo)
- return OUString(pInfo->sLocation);
- else
- return OUString();
-}
-
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmfwk/source/framework.hxx b/jvmfwk/source/framework.hxx
index 04fdf86165bf..3f9e5ff6ab85 100644
--- a/jvmfwk/source/framework.hxx
+++ b/jvmfwk/source/framework.hxx
@@ -57,8 +57,6 @@ public:
const ::JavaInfo* operator ->() const { return pInfo;}
operator ::JavaInfo* () { return pInfo;}
- OUString getLocation() const;
-
static JavaInfo * copyJavaInfo(const JavaInfo * pInfo);
};
commit 2767dcc7b2dd4c82981ffdae74547223162c71ff
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 12:16:19 2017 +0200
Replace a use of CJavaInfo with std::unique_ptr<JavaInfo>
Change-Id: I89cb19969285200a61c47d29e819a50845fa692b
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index b4e94e0d93bf..4786b9424844 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -540,14 +540,15 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
for (citLoc it = vecJRELocations.begin();
it != vecJRELocations.end(); ++it)
{
- jfw::CJavaInfo aInfo;
+ JavaInfo * info;
javaPluginError err = jfw_plugin_getJavaInfoByPath(
*it,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
- & aInfo.pInfo);
+ &info);
+ std::unique_ptr<JavaInfo> aInfo(info);
if (err == javaPluginError::NoJre)
continue;
if (err == javaPluginError::FailedVersion)
@@ -557,20 +558,23 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
if (aInfo)
{
- //We remember the very first installation in aCurrentInfo
- if (aCurrentInfo.getLocation().isEmpty())
- aCurrentInfo = aInfo;
// compare features
// If the user does not require any features (nFeatureFlags = 0)
// then the first installation is used
- if ((aInfo.getFeatures() & nFeatureFlags) == nFeatureFlags)
+ if ((aInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
{
//the just found Java implements all required features
//currently there is only accessibility!!!
- aCurrentInfo = aInfo;
+ aCurrentInfo = aInfo.release();
bInfoFound = true;
break;
}
+ else if (aCurrentInfo.getLocation().isEmpty())
+ {
+ // We remember the very first installation in
+ // aCurrentInfo:
+ aCurrentInfo = aInfo.release();
+ }
}
}//end iterate over paths
if (bInfoFound)
@@ -1040,14 +1044,6 @@ OUString CJavaInfo::getLocation() const
return OUString();
}
-sal_uInt64 CJavaInfo::getFeatures() const
-{
- if (pInfo)
- return pInfo->nFeatures;
- else
- return 0l;
-}
-
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmfwk/source/framework.hxx b/jvmfwk/source/framework.hxx
index f514964db995..04fdf86165bf 100644
--- a/jvmfwk/source/framework.hxx
+++ b/jvmfwk/source/framework.hxx
@@ -58,7 +58,6 @@ public:
operator ::JavaInfo* () { return pInfo;}
OUString getLocation() const;
- sal_uInt64 getFeatures() const;
static JavaInfo * copyJavaInfo(const JavaInfo * pInfo);
};
commit 41a20d3b3750fa6eeb8061af9dd25723d4698feb
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 13 12:08:05 2017 +0200
More std::unique_ptr<JavaInfo> lifecycle management
Change-Id: If53347633ec4b2f8c2b221ba2057e0c38fa97b67
diff --git a/jvmfwk/inc/elements.hxx b/jvmfwk/inc/elements.hxx
index f4766a5c92bd..047c5aab85bc 100644
--- a/jvmfwk/inc/elements.hxx
+++ b/jvmfwk/inc/elements.hxx
@@ -19,6 +19,9 @@
#ifndef INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX
#define INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX
+#include <sal/config.h>
+
+#include <memory>
#include <vector>
#include "jvmfwk/framework.hxx"
#include "fwkutil.hxx"
@@ -98,7 +101,7 @@ public:
/** returns NULL if javaInfo is nil.
*/
- JavaInfo * makeJavaInfo() const;
+ std::unique_ptr<JavaInfo> makeJavaInfo() const;
};
/** this class represents the java settings based on a particular
@@ -294,7 +297,7 @@ public:
which needs to be freed by the caller.
If both, user and share settings are nil, then NULL is returned.
*/
- JavaInfo * createJavaInfo() const;
+ std::unique_ptr<JavaInfo> createJavaInfo() const;
/** returns the value of the attribute /java/javaInfo[@vendorUpdate].
*/
diff --git a/jvmfwk/source/elements.cxx b/jvmfwk/source/elements.cxx
index 4da38c001ed9..353eab37ba6f 100644
--- a/jvmfwk/source/elements.cxx
+++ b/jvmfwk/source/elements.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <cassert>
+#include <memory>
#include "elements.hxx"
#include "osl/mutex.hxx"
@@ -925,19 +926,14 @@ void CNodeJavaInfo::writeToNode(xmlDoc* pDoc,
xmlAddChild(pJavaInfoNode, nodeCrLf);
}
-JavaInfo * CNodeJavaInfo::makeJavaInfo() const
+std::unique_ptr<JavaInfo> CNodeJavaInfo::makeJavaInfo() const
{
if (bNil || m_bEmptyNode)
- return nullptr;
- JavaInfo * pInfo = new JavaInfo;
- memset(pInfo, 0, sizeof(JavaInfo));
- pInfo->sVendor = sVendor;
- pInfo->sLocation = sLocation;
- pInfo->sVersion = sVersion;
- pInfo->nFeatures = nFeatures;
- pInfo->nRequirements = nRequirements;
- pInfo->arVendorData = arVendorData;
- return pInfo;
+ return std::unique_ptr<JavaInfo>();
+ return std::unique_ptr<JavaInfo>(
+ new JavaInfo{
+ sVendor, sLocation, sVersion, nFeatures, nRequirements,
+ arVendorData});
}
@@ -1002,7 +998,7 @@ void MergedSettings::merge(const NodeJava & share, const NodeJava & user)
}
-JavaInfo * MergedSettings::createJavaInfo() const
+std::unique_ptr<JavaInfo> MergedSettings::createJavaInfo() const
{
return m_javaInfo.makeJavaInfo();
}
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 42d99557fc0b..b4e94e0d93bf 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -213,7 +213,7 @@ javaFrameworkError jfw_startVM(
const jfw::MergedSettings settings;
if (!settings.getEnabled())
return JFW_E_JAVA_DISABLED;
- aInfo.reset(settings.createJavaInfo());
+ aInfo = settings.createJavaInfo();
//check if a Java has ever been selected
if (!aInfo)
return JFW_E_NO_SELECT;
@@ -650,7 +650,7 @@ javaFrameworkError jfw_getSelectedJRE(std::unique_ptr<JavaInfo> *ppInfo)
}
const jfw::MergedSettings settings;
- ppInfo->reset(settings.createJavaInfo());
+ *ppInfo = settings.createJavaInfo();
if (!*ppInfo)
{
return JFW_E_NONE;
More information about the Libreoffice-commits
mailing list