8261300: jpackage: rewrite while(0)/while(false) to proper blocks

Reviewed-by: herrick, asemenyuk, almatvee
This commit is contained in:
Aleksey Shipilev 2021-02-11 11:57:45 +00:00
parent 8b6ab31d31
commit 9fed6048a2
2 changed files with 70 additions and 74 deletions

View File

@ -53,7 +53,7 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
const CfgFile::Properties& appOptions = cfgFile.getProperties( const CfgFile::Properties& appOptions = cfgFile.getProperties(
SectionName::Application); SectionName::Application);
do { {
const CfgFile::Properties::const_iterator modulepath = appOptions.find( const CfgFile::Properties::const_iterator modulepath = appOptions.find(
PropertyName::modulepath); PropertyName::modulepath);
if (modulepath != appOptions.end()) { if (modulepath != appOptions.end()) {
@ -64,18 +64,18 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
addArgument(*it); addArgument(*it);
}; };
} }
} while (0); }
do { {
const CfgFile::Properties::const_iterator classpath = appOptions.find( const CfgFile::Properties::const_iterator classpath = appOptions.find(
PropertyName::classpath); PropertyName::classpath);
if (classpath != appOptions.end()) { if (classpath != appOptions.end()) {
addArgument(_T("-classpath")); addArgument(_T("-classpath"));
addArgument(CfgFile::asPathList(*classpath)); addArgument(CfgFile::asPathList(*classpath));
} }
} while (0); }
do { {
const CfgFile::Properties::const_iterator splash = appOptions.find( const CfgFile::Properties::const_iterator splash = appOptions.find(
PropertyName::splash); PropertyName::splash);
if (splash != appOptions.end()) { if (splash != appOptions.end()) {
@ -88,9 +88,9 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
<< splashPath << "\" not found"); << splashPath << "\" not found");
} }
} }
} while (0); }
do { {
const CfgFile::Properties& section = cfgFile.getProperties( const CfgFile::Properties& section = cfgFile.getProperties(
SectionName::JavaOptions); SectionName::JavaOptions);
const CfgFile::Properties::const_iterator javaOptions = section.find( const CfgFile::Properties::const_iterator javaOptions = section.find(
@ -102,44 +102,44 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
addArgument(*it); addArgument(*it);
}; };
} }
} while (0); }
do { {
addArgument(_T("-Djpackage.app-path=") addArgument(_T("-Djpackage.app-path=")
+ SysInfo::getProcessModulePath()); + SysInfo::getProcessModulePath());
} while (0); }
// No validation of data in config file related to how Java app should be // No validation of data in config file related to how Java app should be
// launched intentionally. // launched intentionally.
// Just read what is in config file and put on jvm's command line as is. // Just read what is in config file and put on jvm's command line as is.
do { // Run modular app { // Run modular app
const CfgFile::Properties::const_iterator mainmodule = appOptions.find( const CfgFile::Properties::const_iterator mainmodule = appOptions.find(
PropertyName::mainmodule); PropertyName::mainmodule);
if (mainmodule != appOptions.end()) { if (mainmodule != appOptions.end()) {
addArgument(_T("-m")); addArgument(_T("-m"));
addArgument(CfgFile::asString(*mainmodule)); addArgument(CfgFile::asString(*mainmodule));
} }
} while (0); }
do { // Run main class { // Run main class
const CfgFile::Properties::const_iterator mainclass = appOptions.find( const CfgFile::Properties::const_iterator mainclass = appOptions.find(
PropertyName::mainclass); PropertyName::mainclass);
if (mainclass != appOptions.end()) { if (mainclass != appOptions.end()) {
addArgument(CfgFile::asString(*mainclass)); addArgument(CfgFile::asString(*mainclass));
} }
} while (0); }
do { // Run jar { // Run jar
const CfgFile::Properties::const_iterator mainjar = appOptions.find( const CfgFile::Properties::const_iterator mainjar = appOptions.find(
PropertyName::mainjar); PropertyName::mainjar);
if (mainjar != appOptions.end()) { if (mainjar != appOptions.end()) {
addArgument(_T("-jar")); addArgument(_T("-jar"));
addArgument(CfgFile::asString(*mainjar)); addArgument(CfgFile::asString(*mainjar));
} }
} while (0); }
do { {
const CfgFile::Properties& section = cfgFile.getProperties( const CfgFile::Properties& section = cfgFile.getProperties(
SectionName::ArgOptions); SectionName::ArgOptions);
const CfgFile::Properties::const_iterator arguments = section.find( const CfgFile::Properties::const_iterator arguments = section.find(
@ -151,7 +151,7 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
addArgument(*it); addArgument(*it);
}; };
} }
} while (0); }
return *this; return *this;
} }
@ -233,7 +233,7 @@ private:
int initJvmlLauncherData(JvmlLauncherData* ptr) const { int initJvmlLauncherData(JvmlLauncherData* ptr) const {
// Store path to JLI library just behind JvmlLauncherData header. // Store path to JLI library just behind JvmlLauncherData header.
char* curPtr = reinterpret_cast<char*>(ptr + 1); char* curPtr = reinterpret_cast<char*>(ptr + 1);
do { {
const size_t count = sizeof(char) const size_t count = sizeof(char)
* (jliLibPath.size() + 1 /* trailing zero */); * (jliLibPath.size() + 1 /* trailing zero */);
if (ptr) { if (ptr) {
@ -241,7 +241,7 @@ private:
ptr->jliLibPath = curPtr; ptr->jliLibPath = curPtr;
} }
curPtr += count; curPtr += count;
} while (false); }
// Next write array of char* pointing to JLI lib arg strings. // Next write array of char* pointing to JLI lib arg strings.
if (ptr) { if (ptr) {
@ -284,13 +284,13 @@ JvmlLauncherHandle Jvm::exportLauncher() const {
result->jliLibPath = tstrings::toUtf8(jvmPath); result->jliLibPath = tstrings::toUtf8(jvmPath);
#ifdef TSTRINGS_WITH_WCHAR #ifdef TSTRINGS_WITH_WCHAR
do { {
tstring_array::const_iterator it = args.begin(); tstring_array::const_iterator it = args.begin();
const tstring_array::const_iterator end = args.end(); const tstring_array::const_iterator end = args.end();
for (; it != end; ++it) { for (; it != end; ++it) {
result->args.push_back(tstrings::toACP(*it)); result->args.push_back(tstrings::toACP(*it));
} }
} while (0); }
#else #else
result->args = args; result->args = args;
#endif #endif

View File

@ -207,7 +207,6 @@ namespace {
*/ */
std::string toMultiByte(const std::wstring& utf16str, int encoding) { std::string toMultiByte(const std::wstring& utf16str, int encoding) {
std::string reply; std::string reply;
do {
int cm = WideCharToMultiByte(encoding, int cm = WideCharToMultiByte(encoding,
0, 0,
utf16str.c_str(), utf16str.c_str(),
@ -220,7 +219,7 @@ std::string toMultiByte(const std::wstring& utf16str, int encoding) {
JP_THROW("Unexpected reply from WideCharToMultiByte()"); JP_THROW("Unexpected reply from WideCharToMultiByte()");
} }
if (0 == cm) { if (0 == cm) {
break; return reply;
} }
reply.resize(cm); reply.resize(cm);
@ -235,7 +234,6 @@ std::string toMultiByte(const std::wstring& utf16str, int encoding) {
if (cm != cm2) { if (cm != cm2) {
JP_THROW("Unexpected reply from WideCharToMultiByte()"); JP_THROW("Unexpected reply from WideCharToMultiByte()");
} }
} while(0);
return reply; return reply;
} }
@ -245,7 +243,6 @@ std::string toMultiByte(const std::wstring& utf16str, int encoding) {
*/ */
std::wstring fromMultiByte(const std::string& str, int encoding) { std::wstring fromMultiByte(const std::string& str, int encoding) {
std::wstring utf16; std::wstring utf16;
do {
int cw = MultiByteToWideChar(encoding, int cw = MultiByteToWideChar(encoding,
MB_ERR_INVALID_CHARS, MB_ERR_INVALID_CHARS,
str.c_str(), str.c_str(),
@ -256,7 +253,7 @@ std::wstring fromMultiByte(const std::string& str, int encoding) {
JP_THROW("Unexpected reply from MultiByteToWideChar()"); JP_THROW("Unexpected reply from MultiByteToWideChar()");
} }
if (0 == cw) { if (0 == cw) {
break; return utf16;
} }
utf16.resize(cw); utf16.resize(cw);
@ -269,7 +266,6 @@ std::wstring fromMultiByte(const std::string& str, int encoding) {
if (cw != cw2) { if (cw != cw2) {
JP_THROW("Unexpected reply from MultiByteToWideChar()"); JP_THROW("Unexpected reply from MultiByteToWideChar()");
} }
} while(0);
return utf16; return utf16;
} }