Skip to content
Permalink
Browse files
8261300: jpackage: rewrite while(0)/while(false) to proper blocks
Reviewed-by: herrick, asemenyuk, almatvee
  • Loading branch information
shipilev committed Feb 11, 2021
1 parent 8b6ab31 commit 9fed6048a224f47b77373015be78cc2134402238
Showing with 70 additions and 74 deletions.
  1. +22 −22 src/jdk.jpackage/share/native/applauncher/JvmLauncher.cpp
  2. +48 −52 src/jdk.jpackage/share/native/common/tstrings.cpp
@@ -53,7 +53,7 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
const CfgFile::Properties& appOptions = cfgFile.getProperties(
SectionName::Application);

do {
{
const CfgFile::Properties::const_iterator modulepath = appOptions.find(
PropertyName::modulepath);
if (modulepath != appOptions.end()) {
@@ -64,18 +64,18 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
addArgument(*it);
};
}
} while (0);
}

do {
{
const CfgFile::Properties::const_iterator classpath = appOptions.find(
PropertyName::classpath);
if (classpath != appOptions.end()) {
addArgument(_T("-classpath"));
addArgument(CfgFile::asPathList(*classpath));
}
} while (0);
}

do {
{
const CfgFile::Properties::const_iterator splash = appOptions.find(
PropertyName::splash);
if (splash != appOptions.end()) {
@@ -88,9 +88,9 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
<< splashPath << "\" not found");
}
}
} while (0);
}

do {
{
const CfgFile::Properties& section = cfgFile.getProperties(
SectionName::JavaOptions);
const CfgFile::Properties::const_iterator javaOptions = section.find(
@@ -102,44 +102,44 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
addArgument(*it);
};
}
} while (0);
}

do {
{
addArgument(_T("-Djpackage.app-path=")
+ SysInfo::getProcessModulePath());
} while (0);
}

// No validation of data in config file related to how Java app should be
// launched intentionally.
// 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(
PropertyName::mainmodule);
if (mainmodule != appOptions.end()) {
addArgument(_T("-m"));
addArgument(CfgFile::asString(*mainmodule));
}
} while (0);
}

do { // Run main class
{ // Run main class
const CfgFile::Properties::const_iterator mainclass = appOptions.find(
PropertyName::mainclass);
if (mainclass != appOptions.end()) {
addArgument(CfgFile::asString(*mainclass));
}
} while (0);
}

do { // Run jar
{ // Run jar
const CfgFile::Properties::const_iterator mainjar = appOptions.find(
PropertyName::mainjar);
if (mainjar != appOptions.end()) {
addArgument(_T("-jar"));
addArgument(CfgFile::asString(*mainjar));
}
} while (0);
}

do {
{
const CfgFile::Properties& section = cfgFile.getProperties(
SectionName::ArgOptions);
const CfgFile::Properties::const_iterator arguments = section.find(
@@ -151,7 +151,7 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
addArgument(*it);
};
}
} while (0);
}

return *this;
}
@@ -233,15 +233,15 @@ struct JliLaunchData {
int initJvmlLauncherData(JvmlLauncherData* ptr) const {
// Store path to JLI library just behind JvmlLauncherData header.
char* curPtr = reinterpret_cast<char*>(ptr + 1);
do {
{
const size_t count = sizeof(char)
* (jliLibPath.size() + 1 /* trailing zero */);
if (ptr) {
std::memcpy(curPtr, jliLibPath.c_str(), count);
ptr->jliLibPath = curPtr;
}
curPtr += count;
} while (false);
}

// Next write array of char* pointing to JLI lib arg strings.
if (ptr) {
@@ -284,13 +284,13 @@ JvmlLauncherHandle Jvm::exportLauncher() const {
result->jliLibPath = tstrings::toUtf8(jvmPath);

#ifdef TSTRINGS_WITH_WCHAR
do {
{
tstring_array::const_iterator it = args.begin();
const tstring_array::const_iterator end = args.end();
for (; it != end; ++it) {
result->args.push_back(tstrings::toACP(*it));
}
} while (0);
}
#else
result->args = args;
#endif
@@ -207,35 +207,33 @@ namespace {
*/
std::string toMultiByte(const std::wstring& utf16str, int encoding) {
std::string reply;
do {
int cm = WideCharToMultiByte(encoding,
0,
utf16str.c_str(),
int(utf16str.size()),
NULL,
0,
NULL,
NULL);
if (cm < 0) {
JP_THROW("Unexpected reply from WideCharToMultiByte()");
}
if (0 == cm) {
break;
}
int cm = WideCharToMultiByte(encoding,
0,
utf16str.c_str(),
int(utf16str.size()),
NULL,
0,
NULL,
NULL);
if (cm < 0) {
JP_THROW("Unexpected reply from WideCharToMultiByte()");
}
if (0 == cm) {
return reply;
}

reply.resize(cm);
int cm2 = WideCharToMultiByte(encoding,
0,
utf16str.c_str(),
int(utf16str.size()),
&*reply.begin(),
cm,
NULL,
NULL);
if (cm != cm2) {
JP_THROW("Unexpected reply from WideCharToMultiByte()");
}
} while(0);
reply.resize(cm);
int cm2 = WideCharToMultiByte(encoding,
0,
utf16str.c_str(),
int(utf16str.size()),
&*reply.begin(),
cm,
NULL,
NULL);
if (cm != cm2) {
JP_THROW("Unexpected reply from WideCharToMultiByte()");
}

return reply;
}
@@ -245,31 +243,29 @@ std::string toMultiByte(const std::wstring& utf16str, int encoding) {
*/
std::wstring fromMultiByte(const std::string& str, int encoding) {
std::wstring utf16;
do {
int cw = MultiByteToWideChar(encoding,
MB_ERR_INVALID_CHARS,
str.c_str(),
int(str.size()),
NULL,
0);
if (cw < 0) {
JP_THROW("Unexpected reply from MultiByteToWideChar()");
}
if (0 == cw) {
break;
}
int cw = MultiByteToWideChar(encoding,
MB_ERR_INVALID_CHARS,
str.c_str(),
int(str.size()),
NULL,
0);
if (cw < 0) {
JP_THROW("Unexpected reply from MultiByteToWideChar()");
}
if (0 == cw) {
return utf16;
}

utf16.resize(cw);
int cw2 = MultiByteToWideChar(encoding,
MB_ERR_INVALID_CHARS,
str.c_str(),
int(str.size()),
&*utf16.begin(),
cw);
if (cw != cw2) {
JP_THROW("Unexpected reply from MultiByteToWideChar()");
}
} while(0);
utf16.resize(cw);
int cw2 = MultiByteToWideChar(encoding,
MB_ERR_INVALID_CHARS,
str.c_str(),
int(str.size()),
&*utf16.begin(),
cw);
if (cw != cw2) {
JP_THROW("Unexpected reply from MultiByteToWideChar()");
}

return utf16;
}

0 comments on commit 9fed604

Please sign in to comment.