/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2022 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// ************************************************************************* // ** Attention compatibility! ** // ** These functions are used to parse JVM arguments (-XX). Be careful ** // ** with behavioral changes here. ** // *************************************************************************
template <typename T, ENABLE_IF(std::is_signed<T>::value), ENABLE_IF(sizeof(T) == 4)> // signed 32-bit inlinebool parse_integer_impl(constchar *s, char **endptr, int base, T* result) { // Don't use strtol -- on 64-bit builds, "long" could be either 32- or 64-bits // so the range tests could be tautological and might cause compiler warnings.
STATIC_ASSERT(sizeof(longlong) >= 8); // C++ specification
errno = 0; // errno is thread safe longlong v = strtoll(s, endptr, base); if (errno != 0 || v < min_jint || v > max_jint) { returnfalse;
}
*result = static_cast<T>(v); returntrue;
}
template <typename T, ENABLE_IF(!std::is_signed<T>::value), ENABLE_IF(sizeof(T) == 4)> // unsigned 32-bit inlinebool parse_integer_impl(constchar *s, char **endptr, int base, T* result) { if (s[0] == '-') { returnfalse;
} // Don't use strtoul -- same reason as above.
STATIC_ASSERT(sizeof(unsignedlonglong) >= 8); // C++ specification
errno = 0; // errno is thread safe unsignedlonglong v = strtoull(s, endptr, base); if (errno != 0 || v > max_juint) { returnfalse;
}
*result = static_cast<T>(v); returntrue;
}
// Helper for parse_memory_size template<typename T> inlinebool multiply_by_1k(T& n) { if (n >= std::numeric_limits<T>::min() / 1024 &&
n <= std::numeric_limits<T>::max() / 1024) {
n *= 1024; returntrue;
} else { returnfalse;
}
}
// Parses a memory size in the form "<number>[<unit>]" with valid units being // "k", "K", "m", "M", "g", "G", "t", "T". Unit omitted means bytes. If unit is given, // no space is allowed between number and unit. Number can be in either decimal form // or in hexadecimal form, the latter must start with "0x". // // Valid template arguments for T are signed/unsigned 32/64-bit values. // // This function will parse until it encounters unparseable parts, then // stop. If it read no valid memory size, it will fail. // // Example: "1024M:oom" will yield true, result=1G, endptr pointing to ":oom"
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.