diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-04-13 16:54:32 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-04-13 17:32:44 +0200 |
commit | f276171835c7b820ba271e7d3c28d6704ec823b0 (patch) | |
tree | cb9cde159b71fef50465d85d8eecf052c7e1221e /jvmfwk | |
parent | 8d475bb13fa44a3a2385635dfbc49ab1b2765dd1 (diff) |
Use std::unique_ptr<JavaInfo> in jfw_plugin_getAllJavaInfos
Change-Id: I2beb95c42c666a788a87a45f59bc15ccfcf25aa6
Diffstat (limited to 'jvmfwk')
-rw-r--r-- | jvmfwk/inc/vendorplugin.hxx | 15 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 16 | ||||
-rw-r--r-- | jvmfwk/source/framework.cxx | 39 | ||||
-rw-r--r-- | jvmfwk/source/framework.hxx | 5 |
4 files changed, 13 insertions, 62 deletions
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: |