summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/CMakeLists.txt96
-rw-r--r--indra/llcommon/apply.h68
-rw-r--r--indra/llcommon/classic_callback.cpp16
-rw-r--r--indra/llcommon/classic_callback.h292
-rw-r--r--indra/llcommon/hbxxh.cpp377
-rw-r--r--indra/llcommon/hbxxh.h259
-rw-r--r--indra/llcommon/llalignedarray.h10
-rw-r--r--indra/llcommon/llallocator_heap_profile.cpp10
-rw-r--r--indra/llcommon/llapp.cpp49
-rw-r--r--indra/llcommon/llapr.cpp4
-rw-r--r--indra/llcommon/llassettype.cpp16
-rw-r--r--indra/llcommon/llbase64.cpp4
-rw-r--r--indra/llcommon/llcallbacklist.cpp2
-rw-r--r--indra/llcommon/llcallstack.cpp18
-rw-r--r--indra/llcommon/llcoros.cpp91
-rw-r--r--indra/llcommon/llcoros.h33
-rw-r--r--indra/llcommon/lldefs.h62
-rw-r--r--indra/llcommon/lldependencies.cpp2
-rw-r--r--indra/llcommon/lldependencies.h4
-rw-r--r--indra/llcommon/llerror.cpp16
-rw-r--r--indra/llcommon/llevent.cpp16
-rw-r--r--indra/llcommon/lleventdispatcher.cpp24
-rw-r--r--indra/llcommon/llheteromap.cpp10
-rw-r--r--indra/llcommon/llinitdestroyclass.cpp7
-rw-r--r--indra/llcommon/llinitparam.cpp86
-rw-r--r--indra/llcommon/llinitparam.h14
-rw-r--r--indra/llcommon/llinstancetracker.h4
-rw-r--r--indra/llcommon/llkeybind.cpp68
-rw-r--r--indra/llcommon/llkeybind.h4
-rw-r--r--indra/llcommon/llleap.cpp6
-rw-r--r--indra/llcommon/llmd5.cpp34
-rw-r--r--indra/llcommon/llmd5.h8
-rw-r--r--indra/llcommon/llmemory.cpp8
-rw-r--r--indra/llcommon/llmetricperformancetester.cpp13
-rw-r--r--indra/llcommon/llmetricperformancetester.h4
-rw-r--r--indra/llcommon/llmortician.cpp4
-rw-r--r--indra/llcommon/llmortician.h4
-rw-r--r--indra/llcommon/llnametable.h8
-rw-r--r--indra/llcommon/llpriqueuemap.h4
-rw-r--r--indra/llcommon/llprocess.cpp8
-rw-r--r--indra/llcommon/llprocessor.cpp139
-rw-r--r--indra/llcommon/llprocessor.h5
-rw-r--r--indra/llcommon/llqueuedthread.cpp17
-rw-r--r--indra/llcommon/llqueuedthread.h10
-rw-r--r--indra/llcommon/llrefcount.cpp2
-rw-r--r--indra/llcommon/llregistry.h24
-rw-r--r--indra/llcommon/llrun.cpp2
-rw-r--r--indra/llcommon/llrun.h2
-rw-r--r--indra/llcommon/llsd.cpp120
-rw-r--r--indra/llcommon/llsd.h44
-rw-r--r--indra/llcommon/llsdjson.h2
-rw-r--r--indra/llcommon/llsdparam.cpp6
-rw-r--r--indra/llcommon/llsdserialize.cpp207
-rw-r--r--indra/llcommon/llsdserialize.h26
-rw-r--r--indra/llcommon/llsdserialize_xml.cpp10
-rw-r--r--indra/llcommon/llsdutil.cpp5
-rw-r--r--indra/llcommon/llsdutil.h69
-rw-r--r--indra/llcommon/llstl.h81
-rw-r--r--indra/llcommon/llstreamtools.cpp40
-rw-r--r--indra/llcommon/llstring.cpp10
-rw-r--r--indra/llcommon/llstring.h2
-rw-r--r--indra/llcommon/llstringtable.cpp23
-rw-r--r--indra/llcommon/llstringtable.h4
-rw-r--r--indra/llcommon/llsys.cpp130
-rw-r--r--indra/llcommon/llsys.h18
-rw-r--r--indra/llcommon/llsys_objc.h37
-rw-r--r--indra/llcommon/llsys_objc.mm64
-rw-r--r--indra/llcommon/llthreadlocalstorage.cpp115
-rw-r--r--indra/llcommon/llthreadlocalstorage.h98
-rw-r--r--indra/llcommon/llthreadsafequeue.h6
-rw-r--r--indra/llcommon/lltimer.cpp11
-rw-r--r--indra/llcommon/lltrace.cpp4
-rw-r--r--indra/llcommon/lltrace.h4
-rw-r--r--indra/llcommon/lltraceaccumulators.cpp6
-rw-r--r--indra/llcommon/lltracerecording.cpp89
-rw-r--r--indra/llcommon/lltracerecording.h100
-rw-r--r--indra/llcommon/lltracethreadrecorder.cpp18
-rw-r--r--indra/llcommon/lltracethreadrecorder.h5
-rw-r--r--indra/llcommon/lluri.cpp4
-rw-r--r--indra/llcommon/lluuid.cpp54
-rw-r--r--indra/llcommon/lluuid.h8
-rw-r--r--indra/llcommon/llworkerthread.cpp23
-rw-r--r--indra/llcommon/llworkerthread.h2
-rw-r--r--indra/llcommon/stdtypes.h106
-rw-r--r--indra/llcommon/stringize.h2
-rw-r--r--indra/llcommon/tests/classic_callback_test.cpp144
-rw-r--r--indra/llcommon/tests/lleventdispatcher_test.cpp184
-rw-r--r--indra/llcommon/tests/llleap_test.cpp14
-rw-r--r--indra/llcommon/tests/llprocess_test.cpp40
-rw-r--r--indra/llcommon/tests/llsdserialize_test.cpp8
-rw-r--r--indra/llcommon/threadpool.cpp1
-rw-r--r--indra/llcommon/threadpool.h4
-rw-r--r--indra/llcommon/threadsafeschedule.h4
-rw-r--r--indra/llcommon/workqueue.h8
94 files changed, 2547 insertions, 1377 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 36b2e09dc5..91ae2440fa 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -10,23 +10,10 @@ include(Boost)
include(LLSharedLibs)
include(JsonCpp)
include(Copy3rdPartyLibs)
-include(ZLIB)
+include(ZLIBNG)
include(URIPARSER)
include(Tracy)
-include_directories(
- ${EXPAT_INCLUDE_DIRS}
- ${LLCOMMON_INCLUDE_DIRS}
- ${JSONCPP_INCLUDE_DIR}
- ${ZLIB_INCLUDE_DIRS}
- ${URIPARSER_INCLUDE_DIRS}
- ${TRACY_INCLUDE_DIR}
- )
-
-# add_executable(lltreeiterators lltreeiterators.cpp)
-#
-# target_link_libraries(lltreeiterators
-# ${LLCOMMON_LIBRARIES})
set(llcommon_SOURCE_FILES
indra_constants.cpp
@@ -109,7 +96,6 @@ set(llcommon_SOURCE_FILES
llsys.cpp
lltempredirect.cpp
llthread.cpp
- llthreadlocalstorage.cpp
llthreadsafequeue.cpp
lltimer.cpp
lltrace.cpp
@@ -120,6 +106,7 @@ set(llcommon_SOURCE_FILES
lluriparser.cpp
lluuid.cpp
llworkerthread.cpp
+ hbxxh.cpp
u64.cpp
threadpool.cpp
workqueue.cpp
@@ -131,6 +118,7 @@ set(llcommon_HEADER_FILES
apply.h
chrono.h
+ classic_callback.h
ctype_workaround.h
fix_macros.h
indra_constants.h
@@ -257,6 +245,7 @@ set(llcommon_HEADER_FILES
llwin32headers.h
llwin32headerslean.h
llworkerthread.h
+ hbxxh.h
lockstatic.h
stdtypes.h
stringize.h
@@ -268,58 +257,30 @@ set(llcommon_HEADER_FILES
workqueue.h
StackWalker.h
)
-
-set_source_files_properties(${llcommon_HEADER_FILES}
- PROPERTIES HEADER_FILE_ONLY TRUE)
-
-if (USE_BUGSPLAT)
- set_source_files_properties(${llcommon_SOURCE_FILES}
- PROPERTIES COMPILE_DEFINITIONS "${BUGSPLAT_DEFINE}")
-endif (USE_BUGSPLAT)
+
+if (DARWIN)
+ list(APPEND llcommon_HEADER_FILES llsys_objc.h)
+ list(APPEND llcommon_SOURCE_FILES llsys_objc.mm)
+endif (DARWIN)
list(APPEND llcommon_SOURCE_FILES ${llcommon_HEADER_FILES})
-if(LLCOMMON_LINK_SHARED)
- add_library (llcommon SHARED ${llcommon_SOURCE_FILES})
- if(NOT ADDRESS_SIZE EQUAL 32)
- if(WINDOWS)
- ##add_definitions(/FIXED:NO)
- else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
- add_definitions(-fPIC)
- endif(WINDOWS)
- endif(NOT ADDRESS_SIZE EQUAL 32)
- if(WINDOWS)
- # always generate llcommon.pdb, even for "Release" builds
- set_target_properties(llcommon PROPERTIES LINK_FLAGS "/DEBUG")
- endif(WINDOWS)
- ll_stage_sharedlib(llcommon)
-else(LLCOMMON_LINK_SHARED)
- add_library (llcommon ${llcommon_SOURCE_FILES})
-endif(LLCOMMON_LINK_SHARED)
+add_library (llcommon ${llcommon_SOURCE_FILES})
target_link_libraries(
- llcommon
- ${APRUTIL_LIBRARIES}
- ${APR_LIBRARIES}
- ${EXPAT_LIBRARIES}
- ${JSONCPP_LIBRARIES}
- ${ZLIB_LIBRARIES}
- ${WINDOWS_LIBRARIES}
- ${BOOST_FIBER_LIBRARY}
- ${BOOST_CONTEXT_LIBRARY}
- ${BOOST_PROGRAM_OPTIONS_LIBRARY}
- ${BOOST_REGEX_LIBRARY}
- ${BOOST_SYSTEM_LIBRARY}
- ${GOOGLE_PERFTOOLS_LIBRARIES}
- ${URIPARSER_LIBRARIES}
- ${TRACY_LIBRARY}
+ llcommon
+ ll::apr
+ ll::expat
+ ll::jsoncpp
+ ll::zlib-ng
+ ll::boost
+ ll::uriparser
+ ll::oslibraries
+ ll::tracy
)
-if (DARWIN)
- include(CMakeFindFrameworks)
- find_library(CARBON_LIBRARY Carbon)
- target_link_libraries(llcommon ${CARBON_LIBRARY})
-endif (DARWIN)
+target_include_directories(llcommon INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(llcommon PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(llcommon stage_third_party_libs)
@@ -331,16 +292,9 @@ if (LL_TESTS)
LL_ADD_PROJECT_UNIT_TESTS(llcommon "${llcommon_TEST_SOURCE_FILES}")
#set(TEST_DEBUG on)
- set(test_libs llcommon
- ${LLCOMMON_LIBRARIES}
- ${WINDOWS_LIBRARIES}
- ${GOOGLEMOCK_LIBRARIES}
- ${BOOST_FIBER_LIBRARY}
- ${BOOST_CONTEXT_LIBRARY}
- ${BOOST_THREAD_LIBRARY}
- ${BOOST_SYSTEM_LIBRARY})
+ set(test_libs llcommon)
+ LL_ADD_INTEGRATION_TEST(classic_callback "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(commonmisc "" "${test_libs}")
- LL_ADD_INTEGRATION_TEST(bitpack "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lazyeventapi "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llbase64 "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llcond "" "${test_libs}")
@@ -348,8 +302,8 @@ if (LL_TESTS)
LL_ADD_INTEGRATION_TEST(lldeadmantimer "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lldependencies "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llerror "" "${test_libs}")
- LL_ADD_INTEGRATION_TEST(lleventdispatcher "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lleventcoro "" "${test_libs}")
+ LL_ADD_INTEGRATION_TEST(lleventdispatcher "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lleventfilter "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llframetimer "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llheteromap "" "${test_libs}")
@@ -367,8 +321,8 @@ if (LL_TESTS)
LL_ADD_INTEGRATION_TEST(llstring "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lltrace "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lltreeiterators "" "${test_libs}")
- LL_ADD_INTEGRATION_TEST(lluri "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llunits "" "${test_libs}")
+ LL_ADD_INTEGRATION_TEST(lluri "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(stringize "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(threadsafeschedule "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(tuple "" "${test_libs}")
diff --git a/indra/llcommon/apply.h b/indra/llcommon/apply.h
index ef4a8fd68b..7c58d63bc0 100644
--- a/indra/llcommon/apply.h
+++ b/indra/llcommon/apply.h
@@ -12,11 +12,48 @@
#if ! defined(LL_APPLY_H)
#define LL_APPLY_H
+#include <boost/type_traits/function_traits.hpp>
#include <tuple>
namespace LL
{
+/**
+ * USAGE NOTE:
+ * https://stackoverflow.com/a/40523474/5533635
+ *
+ * If you're trying to pass apply() a variadic function, the compiler
+ * complains that it can't deduce the callable type, presumably because it
+ * doesn't know which arity to reify to pass.
+ *
+ * But it works to wrap the variadic function in a generic lambda, e.g.:
+ *
+ * @CODE
+ * LL::apply(
+ * [](auto&&... args)
+ * {
+ * return variadic(std::forward<decltype(args)>(args)...);
+ * },
+ * args);
+ * @ENDCODE
+ *
+ * Presumably this is because there's only one instance of the generic lambda
+ * @em type, with a variadic <tt>operator()()</tt>.
+ *
+ * It's pointless to provide a wrapper @em function that implicitly supplies
+ * the generic lambda. You couldn't pass your variadic function to our wrapper
+ * function, for the same original reason!
+ *
+ * Instead we provide a wrapper @em macro. Sorry, Dr. Stroustrup.
+ */
+#define VAPPLY(FUNC, ARGS) \
+ LL::apply( \
+ [](auto&&... args) \
+ { \
+ return (FUNC)(std::forward<decltype(args)>(args)...); \
+ }, \
+ (ARGS))
+
#if __cplusplus >= 201703L
// C++17 implementation
@@ -34,16 +71,43 @@ auto apply_impl(CALLABLE&& func, TUPLE&& args, std::index_sequence<I...>)
}
template <typename CALLABLE, typename... ARGS>
-auto apply(CALLABLE&& func, std::tuple<ARGS...>&& args)
+auto apply(CALLABLE&& func, const std::tuple<ARGS...>& args)
{
// std::index_sequence_for is the magic sauce here, generating an argument
// pack of indexes for each entry in args. apply_impl() can then pass
// those to std::get() to unpack args into individual arguments.
return apply_impl(std::forward<CALLABLE>(func),
- std::forward<std::tuple<ARGS...>>(args),
+ args,
std::index_sequence_for<ARGS...>{});
}
+// per https://stackoverflow.com/a/57510428/5533635
+template <typename CALLABLE, typename T, size_t SIZE>
+auto apply(CALLABLE&& func, const std::array<T, SIZE>& args)
+{
+ return apply(std::forward<CALLABLE>(func), std::tuple_cat(args));
+}
+
+// per https://stackoverflow.com/a/28411055/5533635
+template <typename CALLABLE, typename T, std::size_t... I>
+auto apply_impl(CALLABLE&& func, const std::vector<T>& args, std::index_sequence<I...>)
+{
+ return apply_impl(std::forward<CALLABLE>(func),
+ std::make_tuple(std::forward<T>(args[I])...),
+ I...);
+}
+
+// this goes beyond C++17 std::apply()
+template <typename CALLABLE, typename T>
+auto apply(CALLABLE&& func, const std::vector<T>& args)
+{
+ constexpr auto arity = boost::function_traits<CALLABLE>::arity;
+ assert(args.size() == arity);
+ return apply_impl(std::forward<CALLABLE>(func),
+ args,
+ std::make_index_sequence<arity>());
+}
+
#endif // C++14
} // namespace LL
diff --git a/indra/llcommon/classic_callback.cpp b/indra/llcommon/classic_callback.cpp
new file mode 100644
index 0000000000..5674e0a44d
--- /dev/null
+++ b/indra/llcommon/classic_callback.cpp
@@ -0,0 +1,16 @@
+/**
+ * @file classic_callback.cpp
+ * @author Nat Goodspeed
+ * @date 2021-09-23
+ * @brief Implementation for classic_callback.
+ *
+ * $LicenseInfo:firstyear=2021&license=viewerlgpl$
+ * Copyright (c) 2021, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+namespace {
+
+const char dummy[] = "cpp file required to build test program";
+
+} // anonymous namespace
diff --git a/indra/llcommon/classic_callback.h b/indra/llcommon/classic_callback.h
new file mode 100644
index 0000000000..1ad6dbc58f
--- /dev/null
+++ b/indra/llcommon/classic_callback.h
@@ -0,0 +1,292 @@
+/**
+ * @file classic_callback.h
+ * @author Nat Goodspeed
+ * @date 2016-06-21
+ * @brief ClassicCallback and HeapClassicCallback
+ *
+ * This header file addresses the problem of passing a method on a C++ object
+ * to an API that requires a classic-C function pointer. Typically such a
+ * callback API accepts a void* pointer along with the function pointer, and
+ * the function pointer signature accepts a void* parameter. The API passes
+ * the caller's pointer value into the callback function so it can find its
+ * data. In C++, there are a few ways to deal with this case:
+ *
+ * - Use a static method with correct signature. If you don't need access to a
+ * specific instance, that works fine.
+ * - Store the object statically (or store a static pointer to a non-static
+ * instance). As long as you only care about one instance, that works, but
+ * starts to get a little icky. As soon as there's more than one pertinent
+ * instance, fight valiantly against the temptation to stuff the instance
+ * pointer into a static pointer variable "just for a moment."
+ * - Code a static trampoline callback function that accepts the void* user
+ * data pointer, casts it to the appropriate class type and calls the actual
+ * method on that class.
+ *
+ * ClassicCallback encapsulates the last. You need only construct a
+ * ClassicCallback instance somewhere that will survive until the callback is
+ * called, binding the target C++ callable. You then call its get_callback()
+ * and get_userdata() methods to pass an appropriate classic-C function
+ * pointer and void* user data pointer, respectively, to the old-style
+ * callback API. get_callback() synthesizes a static trampoline function
+ * that casts the user data pointer and calls the bound C++ callable.
+ *
+ * $LicenseInfo:firstyear=2016&license=viewerlgpl$
+ * Copyright (c) 2016, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+#if ! defined(LL_CLASSIC_CALLBACK_H)
+#define LL_CLASSIC_CALLBACK_H
+
+#include <tuple>
+#include <type_traits> // std::is_same
+
+/*****************************************************************************
+* Helpers
+*****************************************************************************/
+
+// find a type in a parameter pack: http://stackoverflow.com/q/17844867/5533635
+// usage: index_of<0, sought_t, PackName...>::value
+template <int idx, typename sought, typename candidate, typename ...rest>
+struct index_of
+{
+ static constexpr int const value =
+ std::is_same<sought, candidate>::value ?
+ idx : index_of<idx + 1, sought, rest...>::value;
+};
+
+// recursion tail
+template <int idx, typename sought, typename candidate>
+struct index_of<idx, sought, candidate>
+{
+ static constexpr int const value =
+ std::is_same<sought, candidate>::value ? idx : -1;
+};
+
+/*****************************************************************************
+* ClassicCallback
+*****************************************************************************/
+/**
+ * Instantiate ClassicCallback in whatever storage will persist long enough
+ * for the callback to be called. It holds a modern C++ callable, providing a
+ * static function pointer and a USERDATA (default void*) capable of being
+ * passed through a classic-C callback API. When the static function is called
+ * with that USERDATA pointer, ClassicCallback forwards the call to the bound
+ * C++ callable.
+ *
+ * Usage:
+ * @code
+ * // callback signature required by the API of interest
+ * typedef void (*callback_t)(int, const char*, void*, double);
+ * // old-style API that accepts a classic-C callback function pointer
+ * void oldAPI(callback_t callback, void* userdata);
+ * // but I want to pass a lambda that references data local to my function!
+ * // (We don't need to name the void* parameter in the C++ callable;
+ * // ClassicCallback already used it to locate the lambda instance.)
+ * auto ccb{
+ * makeClassicCallback<callback_t>(
+ * [=](int n, const char* s, void*, double f){ ... }) };
+ * oldAPI(ccb.get_callback(), ccb.get_userdata());
+ * // If the passed callback is called before oldAPI() returns, we can now
+ * // safely destroy ccb. If the callback might be called later, consider
+ * // HeapClassicCallback instead.
+ * @endcode
+ *
+ * If you have a callable object in hand, and you want to pass that to
+ * ClassicCallback, you may either consume it by passing std::move(object), or
+ * explicitly specify a reference to that object type as the CALLABLE template
+ * parameter:
+ * @code
+ * CallableObject obj;
+ * ClassicCallback<callback_t, void*, CallableObject&> ccb{obj};
+ * @endcode
+ */
+// CALLABLE should either be deduced, e.g. by makeClassicCallback(), or
+// specified explicitly. Its default type is meaningless, coded only so we can
+// provide a useful default for USERDATA.
+template <typename SIGNATURE, typename USERDATA=void*, typename CALLABLE=void(*)()>
+class ClassicCallback
+{
+ typedef ClassicCallback<SIGNATURE, USERDATA, CALLABLE> self_t;
+
+public:
+ /// ClassicCallback binds any modern C++ callable.
+ ClassicCallback(CALLABLE&& callable):
+ mCallable(std::forward<CALLABLE>(callable))
+ {}
+
+ /**
+ * ClassicCallback must not itself be copied or moved! Once you've passed
+ * get_userdata() to some API, this object MUST remain at that address.
+ */
+ // However, we can't yet count on C++17 Class Template Argument Deduction,
+ // which means makeClassicCallback() is still useful, which means we MUST
+ // be able to return one to construct into caller's instance (move ctor).
+ // Possible defense: bool 'referenced' data member set by get_userdata(),
+ // with an llassert_always(! referenced) check in the move constructor.
+ ClassicCallback(ClassicCallback const&) = delete;
+ ClassicCallback(ClassicCallback&&) = default; // delete;
+ ClassicCallback& operator=(ClassicCallback const&) = delete;
+ ClassicCallback& operator=(ClassicCallback&&) = delete;
+
+ /// Call get_callback() to get the necessary function pointer.
+ SIGNATURE get_callback() const
+ {
+ // This declaration is where the compiler instantiates the correct
+ // signature for the call() function template.
+ SIGNATURE callback = call;
+ return callback;
+ }
+
+ /// Call get_userdata() to get the opaque USERDATA pointer to pass
+ /// through the classic-C callback API.
+ USERDATA get_userdata() const
+ {
+ // The USERDATA userdata is of course a pointer to this object.
+ return static_cast<USERDATA>(const_cast<self_t*>(this));
+ }
+
+protected:
+ /**
+ * This call() method accepts one or more callback arguments. It assumes
+ * the first USERDATA parameter is the userdata.
+ */
+ // Note that we're not literally using C++ perfect forwarding here -- it
+ // doesn't work to specify (Args&&... args). But that's okay because we're
+ // dealing with a classic-C callback! It's not going to pass any move-only
+ // types.
+ template <typename... Args>
+ static auto call(Args... args)
+ {
+ auto userdata = extract_userdata(std::forward<Args>(args)...);
+ // cast the userdata param to 'this' and call mCallable
+ return static_cast<self_t*>(userdata)->
+ mCallable(std::forward<Args>(args)...);
+ }
+
+ template <typename... Args>
+ static USERDATA extract_userdata(Args... args)
+ {
+ // Search for the first USERDATA parameter type, then extract that pointer.
+ // extract value from parameter pack: http://stackoverflow.com/a/24710433/5533635
+ return std::get<index_of<0, USERDATA, Args...>::value>(std::forward_as_tuple(args...));
+ }
+
+ CALLABLE mCallable;
+};
+
+/**
+ * Usage:
+ * @code
+ * auto ccb{ makeClassicCallback<classic_callback_signature>(actual_callback) };
+ * @endcode
+ */
+template <typename SIGNATURE, typename USERDATA=void*, typename CALLABLE=void(*)()>
+auto makeClassicCallback(CALLABLE&& callable)
+{
+ return std::move(ClassicCallback<SIGNATURE, USERDATA, CALLABLE>
+ (std::forward<CALLABLE>(callable)));
+}
+
+/*****************************************************************************
+* HeapClassicCallback
+*****************************************************************************/
+/**
+ * HeapClassicCallback is like ClassicCallback, with this exception: it MUST
+ * be allocated on the heap because, once the callback has been called, it
+ * deletes itself. This addresses the problem of a callback whose lifespan
+ * must persist beyond the scope in which the callback API is engaged -- but
+ * naturally this callback must be called exactly ONCE.
+ *
+ * Usage:
+ * @code
+ * // callback signature required by the API of interest
+ * typedef void (*callback_t)(int, const char*, void*, double);
+ * // here's the old-style API
+ * void oldAPI(callback_t callback, void* userdata);
+ * // want to call someObjPtr->method() when oldAPI() fires the callback,
+ * // sometime in the future after the enclosing function has returned
+ * auto ccb{
+ * makeHeapClassicCallback<callback_t>(
+ * [someObjPtr](int n, const char* s, void*, double f)
+ * { someObjPtr->method(); }) };
+ * oldAPI(ccb.get_callback(), ccb.get_userdata());
+ * // We don't need a smart pointer for ccb, because it will be deleted once
+ * // oldAPI() calls the bound lambda. HeapClassicCallback is for when the
+ * // callback will be called exactly once. If the classic API might call the
+ * // passed callback more than once -- or might never call it at all --
+ * // manually construct a ClassicCallback on the heap and manage its lifespan
+ * // explicitly.
+ * @endcode
+ */
+template <typename SIGNATURE, typename USERDATA=void*, typename CALLABLE=void(*)()>
+class HeapClassicCallback: public ClassicCallback<SIGNATURE, USERDATA, CALLABLE>
+{
+ typedef ClassicCallback<SIGNATURE, USERDATA, CALLABLE> super;
+ typedef HeapClassicCallback<SIGNATURE, USERDATA, CALLABLE> self_t;
+
+ // This destructor is intentionally private to prevent allocation anywhere
+ // but the heap. (The Design and Evolution of C++, section 11.4.2: Control
+ // of Allocation)
+ ~HeapClassicCallback() {}
+
+public:
+ HeapClassicCallback(CALLABLE&& callable):
+ super(std::forward<CALLABLE>(callable))
+ {}
+
+ // makeHeapClassicCallback() only needs to return a pointer -- not an
+ // instance -- so we can lock down our move constructor too.
+ HeapClassicCallback(HeapClassicCallback&&) = delete;
+
+ /// Replicate get_callback() from the base class because we must
+ /// instantiate OUR call() function template.
+ SIGNATURE get_callback() const
+ {
+ // This declaration is where the compiler instantiates the correct
+ // signature for the call() function template.
+ SIGNATURE callback = call;
+ return callback;
+ }
+
+ /// Replicate get_userdata() from the base class because our call()
+ /// method must be able to reconstitute a pointer to this subclass.
+ USERDATA get_userdata() const
+ {
+ // The USERDATA userdata is of course a pointer to this object.
+ return static_cast<const USERDATA>(const_cast<self_t*>(this));
+ }
+
+private:
+ // call() uses a helper class to delete the HeapClassicCallback when done,
+ // for two reasons. Most importantly, this deletes even if the callback
+ // throws an exception. But also, call() must directly return the callback
+ // result for return-type deduction.
+ struct Destroyer
+ {
+ Destroyer(self_t* p): mPtr(p) {}
+ ~Destroyer() { delete mPtr; }
+
+ self_t* mPtr;
+ };
+
+ template <typename... Args>
+ static auto call(Args... args)
+ {
+ // extract userdata at this level too
+ USERDATA userdata = super::extract_userdata(std::forward<Args>(args)...);
+ // arrange to delete it when we leave by whatever means
+ Destroyer destroy(static_cast<self_t*>(userdata));
+
+ return super::call(std::forward<Args>(args)...);
+ }
+};
+
+template <typename SIGNATURE, typename USERDATA=void*, typename CALLABLE=void(*)()>
+auto makeHeapClassicCallback(CALLABLE&& callable)
+{
+ return new HeapClassicCallback<SIGNATURE, USERDATA, CALLABLE>
+ (std::forward<CALLABLE>(callable));
+}
+
+#endif /* ! defined(LL_CLASSIC_CALLBACK_H) */
diff --git a/indra/llcommon/hbxxh.cpp b/indra/llcommon/hbxxh.cpp
new file mode 100644
index 0000000000..388269d6c8
--- /dev/null
+++ b/indra/llcommon/hbxxh.cpp
@@ -0,0 +1,377 @@
+/**
+ * @file hbxxh.cpp
+ * @brief High performances vectorized hashing based on xxHash.
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (c) 2023, Henri Beauchamp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+
+// This define ensures that xxHash will be compiled within this module, with
+// vectorized (*) and inlined functions (with no exported API symbol); our
+// xxhash "pre-built library" package actually only contains the xxhash.h
+// header (no library needed at link time).
+// (*) SSE2 is normally used for x86(_64) builds, unless you enabled AVX2
+// in your build, in which case the latter would be used instead. For ARM64
+// builds, this would also automatically enable NEON vectorization.
+#define XXH_INLINE_ALL
+#include "xxhash/xxhash.h"
+
+#include "hbxxh.h"
+
+// How many bytes to grab at a time when hashing files or streams
+constexpr size_t BLOCK_LEN = 4096;
+
+///////////////////////////////////////////////////////////////////////////////
+// HBXXH64 class
+///////////////////////////////////////////////////////////////////////////////
+
+//static
+U64 HBXXH64::digest(const void* buffer, size_t len)
+{
+ return XXH3_64bits(buffer, len);
+}
+
+//static
+U64 HBXXH64::digest(const char* str)
+{
+ return XXH3_64bits((const void*)str, strlen(str));
+}
+
+//static
+U64 HBXXH64::digest(const std::string& str)
+{
+ return XXH3_64bits((const void*)str.c_str(), str.size());
+}
+
+// Must be called by all constructors.
+void HBXXH64::init()
+{
+ mDigest = 0;
+ mState = (void*)XXH3_createState();
+ if (!mState || XXH3_64bits_reset((XXH3_state_t*)mState) != XXH_OK)
+ {
+ LL_WARNS() << "Failed to initialize state !" << LL_ENDL;
+ }
+}
+
+HBXXH64::~HBXXH64()
+{
+ if (mState)
+ {
+ XXH3_freeState((XXH3_state_t*)mState);
+ }
+}
+
+void HBXXH64::update(const void* buffer, size_t len)
+{
+ if (mState)
+ {
+ XXH3_64bits_update((XXH3_state_t*)mState, buffer, len);
+ }
+ else
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ }
+}
+
+void HBXXH64::update(const std::string& str)
+{
+ if (mState)
+ {
+ XXH3_64bits_update((XXH3_state_t*)mState, (const void*)str.c_str(),
+ str.length());
+ }
+ else
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ }
+}
+
+void HBXXH64::update(std::istream& stream)
+{
+ if (!mState)
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ return;
+ }
+
+ char buffer[BLOCK_LEN];
+ size_t len;
+ while (stream.good())
+ {
+ stream.read(buffer, BLOCK_LEN);
+ len = stream.gcount();
+ XXH3_64bits_update((XXH3_state_t*)mState, (const void*)buffer, len);
+ }
+}
+
+void HBXXH64::update(FILE* file)
+{
+ if (!mState)
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ return;
+ }
+
+ char buffer[BLOCK_LEN];
+ size_t len;
+ while ((len = fread((void*)buffer, 1, BLOCK_LEN, file)))
+ {
+ XXH3_64bits_update((XXH3_state_t*)mState, (const void*)buffer, len);
+ }
+ fclose(file);
+}
+
+void HBXXH64::finalize()
+{
+ if (!mState)
+ {
+ LL_WARNS() << "Already finalized !" << LL_ENDL;
+ return;
+ }
+ mDigest = XXH3_64bits_digest((XXH3_state_t*)mState);
+ XXH3_freeState((XXH3_state_t*)mState);
+ mState = NULL;
+}
+
+U64 HBXXH64::digest() const
+{
+ return mState ? XXH3_64bits_digest((XXH3_state_t*)mState) : mDigest;
+}
+
+std::ostream& operator<<(std::ostream& stream, HBXXH64 context)
+{
+ stream << context.digest();
+ return stream;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// HBXXH128 class
+///////////////////////////////////////////////////////////////////////////////
+
+//static
+LLUUID HBXXH128::digest(const void* buffer, size_t len)
+{
+ XXH128_hash_t hash = XXH3_128bits(buffer, len);
+ LLUUID id;
+ U64* data = (U64*)id.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+ return id;
+}
+
+//static
+LLUUID HBXXH128::digest(const char* str)
+{
+ XXH128_hash_t hash = XXH3_128bits((const void*)str, strlen(str));
+ LLUUID id;
+ U64* data = (U64*)id.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+ return id;
+}
+
+//static
+LLUUID HBXXH128::digest(const std::string& str)
+{
+ XXH128_hash_t hash = XXH3_128bits((const void*)str.c_str(), str.size());
+ LLUUID id;
+ U64* data = (U64*)id.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+ return id;
+}
+
+//static
+void HBXXH128::digest(LLUUID& result, const void* buffer, size_t len)
+{
+ XXH128_hash_t hash = XXH3_128bits(buffer, len);
+ U64* data = (U64*)result.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+}
+
+//static
+void HBXXH128::digest(LLUUID& result, const char* str)
+{
+ XXH128_hash_t hash = XXH3_128bits((const void*)str, strlen(str));
+ U64* data = (U64*)result.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+}
+
+//static
+void HBXXH128::digest(LLUUID& result, const std::string& str)
+{
+ XXH128_hash_t hash = XXH3_128bits((const void*)str.c_str(), str.size());
+ U64* data = (U64*)result.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+}
+
+// Must be called by all constructors.
+void HBXXH128::init()
+{
+ mState = (void*)XXH3_createState();
+ if (!mState || XXH3_128bits_reset((XXH3_state_t*)mState) != XXH_OK)
+ {
+ LL_WARNS() << "Failed to initialize state !" << LL_ENDL;
+ }
+}
+
+HBXXH128::~HBXXH128()
+{
+ if (mState)
+ {
+ XXH3_freeState((XXH3_state_t*)mState);
+ }
+}
+
+void HBXXH128::update(const void* buffer, size_t len)
+{
+ if (mState)
+ {
+ XXH3_128bits_update((XXH3_state_t*)mState, buffer, len);
+ }
+ else
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ }
+}
+
+void HBXXH128::update(const std::string& str)
+{
+ if (mState)
+ {
+ XXH3_128bits_update((XXH3_state_t*)mState, (const void*)str.c_str(),
+ str.length());
+ }
+ else
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ }
+}
+
+void HBXXH128::update(std::istream& stream)
+{
+ if (!mState)
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ return;
+ }
+
+ char buffer[BLOCK_LEN];
+ size_t len;
+ while (stream.good())
+ {
+ stream.read(buffer, BLOCK_LEN);
+ len = stream.gcount();
+ XXH3_128bits_update((XXH3_state_t*)mState, (const void*)buffer, len);
+ }
+}
+
+void HBXXH128::update(FILE* file)
+{
+ if (!mState)
+ {
+ LL_WARNS() << "Cannot update a finalized digest !" << LL_ENDL;
+ return;
+ }
+
+ char buffer[BLOCK_LEN];
+ size_t len;
+ while ((len = fread((void*)buffer, 1, BLOCK_LEN, file)))
+ {
+ XXH3_128bits_update((XXH3_state_t*)mState, (const void*)buffer, len);
+ }
+ fclose(file);
+}
+
+void HBXXH128::finalize()
+{
+ if (!mState)
+ {
+ LL_WARNS() << "Already finalized !" << LL_ENDL;
+ return;
+ }
+ XXH128_hash_t hash = XXH3_128bits_digest((XXH3_state_t*)mState);
+ U64* data = (U64*)mDigest.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+ XXH3_freeState((XXH3_state_t*)mState);
+ mState = NULL;
+}
+
+const LLUUID& HBXXH128::digest() const
+{
+ if (mState)
+ {
+ XXH128_hash_t hash = XXH3_128bits_digest((XXH3_state_t*)mState);
+ // We cheat the const-ness of the method here, but this is OK, since
+ // mDigest is private and cannot be accessed indirectly by other
+ // methods than digest() ones, that do check for mState to decide
+ // wether mDigest's current value may be provided as is or not. This
+ // cheat saves us a temporary LLLUID copy.
+ U64* data = (U64*)mDigest.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+ }
+ return mDigest;
+}
+
+void HBXXH128::digest(LLUUID& result) const
+{
+ if (!mState)
+ {
+ result = mDigest;
+ return;
+ }
+ XXH128_hash_t hash = XXH3_128bits_digest((XXH3_state_t*)mState);
+ U64* data = (U64*)result.mData;
+ // Note: we do not check endianness here and we just store in the same
+ // order as XXH128_hash_t, that is low word "first".
+ data[0] = hash.low64;
+ data[1] = hash.high64;
+}
+
+std::ostream& operator<<(std::ostream& stream, HBXXH128 context)
+{
+ stream << context.digest();
+ return stream;
+}
diff --git a/indra/llcommon/hbxxh.h b/indra/llcommon/hbxxh.h
new file mode 100644
index 0000000000..236716722a
--- /dev/null
+++ b/indra/llcommon/hbxxh.h
@@ -0,0 +1,259 @@
+/**
+ * @file hbxxh.h
+ * @brief High performances vectorized hashing based on xxHash.
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (c) 2023, Henri Beauchamp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_HBXXH_H
+#define LL_HBXXH_H
+
+#include "lluuid.h"
+
+// HBXXH* classes are to be used where speed matters and cryptographic quality
+// is not required (no "one-way" guarantee, though they are likely not worst in
+// this respect than MD5 which got busted and is now considered too weak). The
+// xxHash code they are built upon is vectorized and about 50 times faster than
+// MD5. A 64 bits hash class is also provided for when 128 bits of entropy are
+// not needed. The hashes collision rate is similar to MD5's.
+// See https://github.com/Cyan4973/xxHash#readme for details.
+
+// 64 bits hashing class
+
+class HBXXH64
+{
+ friend std::ostream& operator<<(std::ostream&, HBXXH64);
+
+protected:
+ LOG_CLASS(HBXXH64);
+
+public:
+ inline HBXXH64() { init(); }
+
+ // Constructors for special circumstances; they all digest the first passed
+ // parameter. Set 'do_finalize' to false if you do not want to finalize the
+ // context, which is useful/needed when you want to update() it afterwards.
+ // Ideally, the compiler should be smart enough to get our clue and
+ // optimize out the const bool test during inlining...
+
+ inline HBXXH64(const void* buffer, size_t len,
+ const bool do_finalize = true)
+ {
+ init();
+ update(buffer, len);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ inline HBXXH64(const std::string& str, const bool do_finalize = true)
+ {
+ init();
+ update(str);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ inline HBXXH64(std::istream& s, const bool do_finalize = true)
+ {
+ init();
+ update(s);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ inline HBXXH64(FILE* file, const bool do_finalize = true)
+ {
+ init();
+ update(file);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ ~HBXXH64();
+
+ void update(const void* buffer, size_t len);
+ void update(const std::string& str);
+ void update(std::istream& s);
+ void update(FILE* file);
+
+ // Note that unlike what happens with LLMD5, you do not need to finalize()
+ // HBXXH64 before using digest(), and you may keep updating() it even after
+ // you got a first digest() (the next digest would of course change after
+ // any update). It is still useful to use finalize() when you do not want
+ // to store a final digest() result in a separate U64; after this method
+ // has been called, digest() simply returns mDigest value.
+ void finalize();
+
+ U64 digest() const;
+
+ // Fast static methods. Use them when hashing just one contiguous block of
+ // data.
+ static U64 digest(const void* buffer, size_t len);
+ static U64 digest(const char* str); // str must be NUL-terminated
+ static U64 digest(const std::string& str);
+
+private:
+ void init();
+
+private:
+ // We use a void pointer to avoid including xxhash.h here for XXH3_state_t
+ // (which cannot either be trivially forward-declared, due to complex API
+ // related pre-processor macros in xxhash.h).
+ void* mState;
+ U64 mDigest;
+};
+
+inline bool operator==(const HBXXH64& a, const HBXXH64& b)
+{
+ return a.digest() == b.digest();
+}
+
+inline bool operator!=(const HBXXH64& a, const HBXXH64& b)
+{
+ return a.digest() != b.digest();
+}
+
+// 128 bits hashing class
+
+class HBXXH128
+{
+ friend std::ostream& operator<<(std::ostream&, HBXXH128);
+
+protected:
+ LOG_CLASS(HBXXH128);
+
+public:
+ inline HBXXH128() { init(); }
+
+ // Constructors for special circumstances; they all digest the first passed
+ // parameter. Set 'do_finalize' to false if you do not want to finalize the
+ // context, which is useful/needed when you want to update() it afterwards.
+ // Ideally, the compiler should be smart enough to get our clue and
+ // optimize out the const bool test during inlining...
+
+ inline HBXXH128(const void* buffer, size_t len,
+ const bool do_finalize = true)
+ {
+ init();
+ update(buffer, len);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ inline HBXXH128(const std::string& str, const bool do_finalize = true)
+ {
+ init();
+ update(str);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ inline HBXXH128(std::istream& s, const bool do_finalize = true)
+ {
+ init();
+ update(s);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ inline HBXXH128(FILE* file, const bool do_finalize = true)
+ {
+ init();
+ update(file);
+ if (do_finalize)
+ {
+ finalize();
+ }
+ }
+
+ ~HBXXH128();
+
+ void update(const void* buffer, size_t len);
+ void update(const std::string& str);
+ void update(std::istream& s);
+ void update(FILE* file);
+
+ // Note that unlike what happens with LLMD5, you do not need to finalize()
+ // HBXXH128 before using digest(), and you may keep updating() it even
+ // after you got a first digest() (the next digest would of course change
+ // after any update). It is still useful to use finalize() when you do not
+ // want to store a final digest() result in a separate LLUUID; after this
+ // method has been called, digest() simply returns a reference on mDigest.
+ void finalize();
+
+ // We use an LLUUID for the digest, since this is a 128 bits wide native
+ // type available in the viewer code, making it easy to manipulate. It also
+ // allows to use HBXXH128 efficiently in LLUUID generate() and combine()
+ // methods.
+ const LLUUID& digest() const;
+
+ // Here, we avoid an LLUUID copy whenever we already got one to store the
+ // result *and* we did not yet call finalize().
+ void digest(LLUUID& result) const;
+
+ // Fast static methods. Use them when hashing just one contiguous block of
+ // data.
+ static LLUUID digest(const void* buffer, size_t len);
+ static LLUUID digest(const char* str); // str must be NUL-terminated
+ static LLUUID digest(const std::string& str);
+ // Same as above, but saves you from an LLUUID copy when you already got
+ // one for storage use.
+ static void digest(LLUUID& result, const void* buffer, size_t len);
+ static void digest(LLUUID& result, const char* str); // str NUL-terminated
+ static void digest(LLUUID& result, const std::string& str);
+
+private:
+ void init();
+
+private:
+ // We use a void pointer to avoid including xxhash.h here for XXH3_state_t
+ // (which cannot either be trivially forward-declared, due to complex API
+ // related pre-processor macros in xxhash.h).
+ void* mState;
+ LLUUID mDigest;
+};
+
+inline bool operator==(const HBXXH128& a, const HBXXH128& b)
+{
+ return a.digest() == b.digest();
+}
+
+inline bool operator!=(const HBXXH128& a, const HBXXH128& b)
+{
+ return a.digest() != b.digest();
+}
+
+#endif // LL_HBXXH_H
diff --git a/indra/llcommon/llalignedarray.h b/indra/llcommon/llalignedarray.h
index b68e9e0f82..da9d98c16c 100644
--- a/indra/llcommon/llalignedarray.h
+++ b/indra/llcommon/llalignedarray.h
@@ -116,14 +116,20 @@ void LLAlignedArray<T, alignment>::resize(U32 size)
template <class T, U32 alignment>
T& LLAlignedArray<T, alignment>::operator[](int idx)
{
- llassert(idx < mElementCount);
+ if(idx >= mElementCount || idx < 0)
+ {
+ LL_ERRS() << "Out of bounds LLAlignedArray, requested: " << (S32)idx << " size: " << mElementCount << LL_ENDL;
+ }
return mArray[idx];
}
template <class T, U32 alignment>
const T& LLAlignedArray<T, alignment>::operator[](int idx) const
{
- llassert(idx < mElementCount);
+ if (idx >= mElementCount || idx < 0)
+ {
+ LL_ERRS() << "Out of bounds LLAlignedArray, requested: " << (S32)idx << " size: " << mElementCount << LL_ENDL;
+ }
return mArray[idx];
}
diff --git a/indra/llcommon/llallocator_heap_profile.cpp b/indra/llcommon/llallocator_heap_profile.cpp
index b2eafde1aa..c6d9542b42 100644
--- a/indra/llcommon/llallocator_heap_profile.cpp
+++ b/indra/llcommon/llallocator_heap_profile.cpp
@@ -130,15 +130,13 @@ void LLAllocatorHeapProfile::parse(std::string const & prof_text)
void LLAllocatorHeapProfile::dump(std::ostream & out) const
{
- lines_t::const_iterator i;
- for(i = mLines.begin(); i != mLines.end(); ++i)
+ for (const LLAllocatorHeapProfile::line& line : mLines)
{
- out << i->mLiveCount << ": " << i->mLiveSize << '[' << i->mTotalCount << ": " << i->mTotalSize << "] @";
+ out << line.mLiveCount << ": " << line.mLiveSize << '[' << line.mTotalCount << ": " << line.mTotalSize << "] @";
- stack_trace::const_iterator j;
- for(j = i->mTrace.begin(); j != i->mTrace.end(); ++j)
+ for (const stack_marker marker : line.mTrace)
{
- out << ' ' << *j;
+ out << ' ' << marker;
}
out << '\n';
}
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index 8ddd132793..d839b19c99 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -68,10 +68,6 @@ void setup_signals();
void default_unix_signal_handler(int signum, siginfo_t *info, void *);
#if LL_LINUX
-#include "google_breakpad/minidump_descriptor.h"
-static bool unix_minidump_callback(const google_breakpad::MinidumpDescriptor& minidump_desc,
- void* context,
- bool succeeded);
#else
// Called by breakpad exception handler after the minidump has been generated.
bool unix_post_minidump_callback(const char *dump_dir,
@@ -856,47 +852,8 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
}
#if LL_LINUX
-bool unix_minidump_callback(const google_breakpad::MinidumpDescriptor& minidump_desc, void* context, bool succeeded)
-{
- // Copy minidump file path into fixed buffer in the app instance to avoid
- // heap allocations in a crash handler.
-
- // path format: <dump_dir>/<minidump_id>.dmp
-
- //HACK: *path points to the buffer in getMiniDumpFilename which has already allocated space
- //to avoid doing allocation during crash.
- char * path = LLApp::instance()->getMiniDumpFilename();
- int dir_path_len = strlen(path);
-
- // The path must not be truncated.
- S32 remaining = LLApp::MAX_MINDUMP_PATH_LENGTH - dir_path_len;
-
- llassert( (remaining - strlen(minidump_desc.path())) > 5);
-
- path += dir_path_len;
-
- if (dir_path_len > 0 && path[-1] != '/')
- {
- *path++ = '/';
- --remaining;
- }
-
- strncpy(path, minidump_desc.path(), remaining);
-
- LL_INFOS("CRASHREPORT") << "generated minidump: " << LLApp::instance()->getMiniDumpFilename() << LL_ENDL;
- LLApp::runErrorHandler();
-
-#ifndef LL_RELEASE_FOR_DOWNLOAD
- clear_signals();
- return false;
-#else
- return true;
#endif
-}
-#endif
-
-
bool unix_post_minidump_callback(const char *dump_dir,
const char *minidump_id,
void *context, bool succeeded)
@@ -905,14 +862,14 @@ bool unix_post_minidump_callback(const char *dump_dir,
// heap allocations in a crash handler.
// path format: <dump_dir>/<minidump_id>.dmp
- int dirPathLength = strlen(dump_dir);
- int idLength = strlen(minidump_id);
+ auto dirPathLength = strlen(dump_dir);
+ auto idLength = strlen(minidump_id);
// The path must not be truncated.
llassert((dirPathLength + idLength + 5) <= LLApp::MAX_MINDUMP_PATH_LENGTH);
char * path = LLApp::instance()->getMiniDumpFilename();
- S32 remaining = LLApp::MAX_MINDUMP_PATH_LENGTH;
+ auto remaining = LLApp::MAX_MINDUMP_PATH_LENGTH;
strncpy(path, dump_dir, remaining);
remaining -= dirPathLength;
path += dirPathLength;
diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp
index db94765871..435531f86f 100644
--- a/indra/llcommon/llapr.cpp
+++ b/indra/llcommon/llapr.cpp
@@ -30,7 +30,6 @@
#include "llapr.h"
#include "llmutex.h"
#include "apr_dso.h"
-#include "llthreadlocalstorage.h"
apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool
LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool.
@@ -54,7 +53,6 @@ void ll_init_apr()
LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE) ;
}
- LLThreadLocalPointerBase::initAllThreadLocalStorage();
gAPRInitialized = true;
}
@@ -70,8 +68,6 @@ void ll_cleanup_apr()
LL_DEBUGS("APR") << "Cleaning up APR" << LL_ENDL;
- LLThreadLocalPointerBase::destroyAllThreadLocalStorage();
-
if (gAPRPoolp)
{
apr_pool_destroy(gAPRPoolp);
diff --git a/indra/llcommon/llassettype.cpp b/indra/llcommon/llassettype.cpp
index e6cc06e8d0..4c84223dad 100644
--- a/indra/llcommon/llassettype.cpp
+++ b/indra/llcommon/llassettype.cpp
@@ -150,14 +150,12 @@ LLAssetType::EType LLAssetType::lookup(const char* name)
LLAssetType::EType LLAssetType::lookup(const std::string& type_name)
{
const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
- for (LLAssetDictionary::const_iterator iter = dict->begin();
- iter != dict->end();
- iter++)
+ for (const LLAssetDictionary::value_type& pair : *dict)
{
- const AssetEntry *entry = iter->second;
+ const AssetEntry *entry = pair.second;
if (type_name == entry->mTypeName)
{
- return iter->first;
+ return pair.first;
}
}
return AT_UNKNOWN;
@@ -188,14 +186,12 @@ LLAssetType::EType LLAssetType::lookupHumanReadable(const char* name)
LLAssetType::EType LLAssetType::lookupHumanReadable(const std::string& readable_name)
{
const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
- for (LLAssetDictionary::const_iterator iter = dict->begin();
- iter != dict->end();
- iter++)
+ for (const LLAssetDictionary::value_type& pair : *dict)
{
- const AssetEntry *entry = iter->second;
+ const AssetEntry *entry = pair.second;
if (entry->mHumanName && (readable_name == entry->mHumanName))
{
- return iter->first;
+ return pair.first;
}
}
return AT_NONE;
diff --git a/indra/llcommon/llbase64.cpp b/indra/llcommon/llbase64.cpp
index 4e82cf7f20..bb85fe32a3 100644
--- a/indra/llcommon/llbase64.cpp
+++ b/indra/llcommon/llbase64.cpp
@@ -42,7 +42,7 @@ std::string LLBase64::encode(const U8* input, size_t input_size)
&& input_size > 0)
{
// Yes, it returns int.
- int b64_buffer_length = apr_base64_encode_len(input_size);
+ int b64_buffer_length = apr_base64_encode_len(narrow(input_size));
char* b64_buffer = new char[b64_buffer_length];
// This is faster than apr_base64_encode() if you know
@@ -52,7 +52,7 @@ std::string LLBase64::encode(const U8* input, size_t input_size)
b64_buffer_length = apr_base64_encode_binary(
b64_buffer,
input,
- input_size);
+ narrow(input_size));
output.assign(b64_buffer);
delete[] b64_buffer;
}
diff --git a/indra/llcommon/llcallbacklist.cpp b/indra/llcommon/llcallbacklist.cpp
index 541ff75ee4..93d0a035da 100644
--- a/indra/llcommon/llcallbacklist.cpp
+++ b/indra/llcommon/llcallbacklist.cpp
@@ -109,7 +109,7 @@ void LLCallbackList::deleteAllFunctions()
void LLCallbackList::callFunctions()
{
- for (callback_list_t::iterator iter = mCallbackList.begin(); iter != mCallbackList.end(); )
+ for (callback_list_t::iterator iter = mCallbackList.begin(); iter != mCallbackList.end(); )
{
callback_list_t::iterator curiter = iter++;
curiter->first(curiter->second);
diff --git a/indra/llcommon/llcallstack.cpp b/indra/llcommon/llcallstack.cpp
index 8db291eed1..83d5ae2a63 100644
--- a/indra/llcommon/llcallstack.cpp
+++ b/indra/llcommon/llcallstack.cpp
@@ -91,10 +91,9 @@ LLCallStack::LLCallStack(S32 skip_count, bool verbose):
bool LLCallStack::contains(const std::string& str)
{
- for (std::vector<std::string>::const_iterator it = m_strings.begin();
- it != m_strings.end(); ++it)
+ for (const std::string& src_str : m_strings)
{
- if (it->find(str) != std::string::npos)
+ if (src_str.find(str) != std::string::npos)
{
return true;
}
@@ -105,10 +104,9 @@ bool LLCallStack::contains(const std::string& str)
std::ostream& operator<<(std::ostream& s, const LLCallStack& call_stack)
{
#ifndef LL_RELEASE_FOR_DOWNLOAD
- std::vector<std::string>::const_iterator it;
- for (it=call_stack.m_strings.begin(); it!=call_stack.m_strings.end(); ++it)
+ for (const std::string& str : call_stack.m_strings)
{
- s << *it;
+ s << str;
}
#else
s << "UNAVAILABLE IN RELEASE";
@@ -156,9 +154,9 @@ bool LLContextStrings::contains(const std::string& str)
{
const std::map<std::string,S32>& strings =
LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->m_contextStrings;
- for (std::map<std::string,S32>::const_iterator it = strings.begin(); it!=strings.end(); ++it)
+ for (const std::map<std::string,S32>::value_type& str_pair : strings)
{
- if (it->first.find(str) != std::string::npos)
+ if (str_pair.first.find(str) != std::string::npos)
{
return true;
}
@@ -171,9 +169,9 @@ void LLContextStrings::output(std::ostream& os)
{
const std::map<std::string,S32>& strings =
LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->m_contextStrings;
- for (std::map<std::string,S32>::const_iterator it = strings.begin(); it!=strings.end(); ++it)
+ for (const std::map<std::string,S32>::value_type& str_pair : strings)
{
- os << it->first << "[" << it->second << "]" << "\n";
+ os << str_pair.first << "[" << str_pair.second << "]" << "\n";
}
}
diff --git a/indra/llcommon/llcoros.cpp b/indra/llcommon/llcoros.cpp
index c2d353b0fc..70d8dfc8b9 100644
--- a/indra/llcommon/llcoros.cpp
+++ b/indra/llcommon/llcoros.cpp
@@ -35,6 +35,7 @@
// STL headers
// std headers
#include <atomic>
+#include <stdexcept>
// external library headers
#include <boost/bind.hpp>
#include <boost/fiber/fiber.hpp>
@@ -214,6 +215,22 @@ std::string LLCoros::logname()
return data.mName.empty()? data.getKey() : data.mName;
}
+void LLCoros::saveException(const std::string& name, std::exception_ptr exc)
+{
+ mExceptionQueue.emplace(name, exc);
+}
+
+void LLCoros::rethrow()
+{
+ if (! mExceptionQueue.empty())
+ {
+ ExceptionData front = mExceptionQueue.front();
+ mExceptionQueue.pop();
+ LL_WARNS("LLCoros") << "Rethrowing exception from coroutine " << front.name << LL_ENDL;
+ std::rethrow_exception(front.exception);
+ }
+}
+
void LLCoros::setStackSize(S32 stacksize)
{
LL_DEBUGS("LLCoros") << "Setting coroutine stack size to " << stacksize << LL_ENDL;
@@ -271,25 +288,15 @@ std::string LLCoros::launch(const std::string& prefix, const callable_t& callabl
return name;
}
+namespace
+{
+
#if LL_WINDOWS
static const U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific
-U32 cpp_exception_filter(U32 code, struct _EXCEPTION_POINTERS *exception_infop, const std::string& name)
+U32 exception_filter(U32 code, struct _EXCEPTION_POINTERS *exception_infop)
{
- // C++ exceptions were logged in toplevelTryWrapper, but not SEH
- // log SEH exceptions here, to make sure it gets into bugsplat's
- // report and because __try won't allow std::string operations
- if (code != STATUS_MSC_EXCEPTION)
- {
- LL_WARNS() << "SEH crash in " << name << ", code: " << code << LL_ENDL;
- }
- // Handle bugsplat here, since GetExceptionInformation() can only be
- // called from within filter for __except(filter), not from __except's {}
- // Bugsplat should get all exceptions, C++ and SEH
- LLApp::instance()->reportCrashToBugsplat(exception_infop);
-
- // Only convert non C++ exceptions.
if (code == STATUS_MSC_EXCEPTION)
{
// C++ exception, go on
@@ -302,29 +309,38 @@ U32 cpp_exception_filter(U32 code, struct _EXCEPTION_POINTERS *exception_infop,
}
}
-void LLCoros::winlevel(const std::string& name, const callable_t& callable)
+void sehandle(const LLCoros::callable_t& callable)
{
__try
{
- toplevelTryWrapper(name, callable);
+ callable();
}
- __except (cpp_exception_filter(GetExceptionCode(), GetExceptionInformation(), name))
+ __except (exception_filter(GetExceptionCode(), GetExceptionInformation()))
{
- // convert to C++ styled exception for handlers other than bugsplat
+ // convert to C++ styled exception
// Note: it might be better to use _se_set_translator
// if you want exception to inherit full callstack
- //
- // in case of bugsplat this will get to exceptionTerminateHandler and
- // looks like fiber will terminate application after that
char integer_string[512];
- sprintf(integer_string, "SEH crash in %s, code: %lu\n", name.c_str(), GetExceptionCode());
+ sprintf(integer_string, "SEH, code: %lu\n", GetExceptionCode());
throw std::exception(integer_string);
}
}
-#endif
+#else // ! LL_WINDOWS
+
+inline void sehandle(const LLCoros::callable_t& callable)
+{
+ callable();
+}
-void LLCoros::toplevelTryWrapper(const std::string& name, const callable_t& callable)
+#endif // ! LL_WINDOWS
+
+} // anonymous namespace
+
+// Top-level wrapper around caller's coroutine callable.
+// Normally we like to pass strings and such by const reference -- but in this
+// case, we WANT to copy both the name and the callable to our local stack!
+void LLCoros::toplevel(std::string name, callable_t callable)
{
// keep the CoroData on this top-level function's stack frame
CoroData corodata(name);
@@ -334,12 +350,12 @@ void LLCoros::toplevelTryWrapper(const std::string& name, const callable_t& call
// run the code the caller actually wants in the coroutine
try
{
- callable();
+ sehandle(callable);
}
catch (const Stop& exc)
{
LL_INFOS("LLCoros") << "coroutine " << name << " terminating because "
- << exc.what() << LL_ENDL;
+ << exc.what() << LL_ENDL;
}
catch (const LLContinueError&)
{
@@ -350,27 +366,14 @@ void LLCoros::toplevelTryWrapper(const std::string& name, const callable_t& call
}
catch (...)
{
- // Any OTHER kind of uncaught exception will cause the viewer to
- // crash, hopefully informatively.
- LOG_UNHANDLED_EXCEPTION(STRINGIZE("coroutine " << name));
- // to not modify callstack
- throw;
+ // Stash any OTHER kind of uncaught exception in the rethrow() queue
+ // to be rethrown by the main fiber.
+ LL_WARNS("LLCoros") << "Capturing uncaught exception in coroutine "
+ << name << LL_ENDL;
+ LLCoros::instance().saveException(name, std::current_exception());
}
}
-// Top-level wrapper around caller's coroutine callable.
-// Normally we like to pass strings and such by const reference -- but in this
-// case, we WANT to copy both the name and the callable to our local stack!
-void LLCoros::toplevel(std::string name, callable_t callable)
-{
-#if LL_WINDOWS
- // Can not use __try in functions that require unwinding, so use one more wrapper
- winlevel(name, callable);
-#else
- toplevelTryWrapper(name, callable);
-#endif
-}
-
//static
void LLCoros::checkStop()
{
diff --git a/indra/llcommon/llcoros.h b/indra/llcommon/llcoros.h
index a94cfca19f..966ce03296 100644
--- a/indra/llcommon/llcoros.h
+++ b/indra/llcommon/llcoros.h
@@ -38,6 +38,8 @@
#include "llinstancetracker.h"
#include <boost/function.hpp>
#include <string>
+#include <exception>
+#include <queue>
// e.g. #include LLCOROS_MUTEX_HEADER
#define LLCOROS_MUTEX_HEADER <boost/fiber/mutex.hpp>
@@ -156,6 +158,19 @@ public:
* LLCoros::launch()).
*/
static std::string getName();
+
+ /**
+ * rethrow() is called by the thread's main fiber to propagate an
+ * exception from any coroutine into the main fiber, where it can engage
+ * the normal unhandled-exception machinery, up to and including crash
+ * reporting.
+ *
+ * LLCoros maintains a queue of otherwise-uncaught exceptions from
+ * terminated coroutines. Each call to rethrow() pops the first of those
+ * and rethrows it. When the queue is empty (normal case), rethrow() is a
+ * no-op.
+ */
+ void rethrow();
/**
* This variation returns a name suitable for log messages: the explicit
@@ -292,13 +307,23 @@ public:
private:
std::string generateDistinctName(const std::string& prefix) const;
-#if LL_WINDOWS
- void winlevel(const std::string& name, const callable_t& callable);
-#endif
- void toplevelTryWrapper(const std::string& name, const callable_t& callable);
void toplevel(std::string name, callable_t callable);
struct CoroData;
static CoroData& get_CoroData(const std::string& caller);
+ void saveException(const std::string& name, std::exception_ptr exc);
+
+ struct ExceptionData
+ {
+ ExceptionData(const std::string& nm, std::exception_ptr exc):
+ name(nm),
+ exception(exc)
+ {}
+ // name of coroutine that originally threw this exception
+ std::string name;
+ // the thrown exception
+ std::exception_ptr exception;
+ };
+ std::queue<ExceptionData> mExceptionQueue;
S32 mStackSize;
diff --git a/indra/llcommon/lldefs.h b/indra/llcommon/lldefs.h
index 5a4b8325f4..5c46f6a796 100644
--- a/indra/llcommon/lldefs.h
+++ b/indra/llcommon/lldefs.h
@@ -28,6 +28,7 @@
#define LL_LLDEFS_H
#include "stdtypes.h"
+#include <type_traits>
// Often used array indices
const U32 VX = 0;
@@ -168,80 +169,79 @@ const U32 MAXADDRSTR = 17; // 123.567.901.345 = 15 chars + \0 + 1 for good luc
// llclampb(a) // clamps a to [0 .. 255]
//
-template <class LLDATATYPE>
-inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2)
+template <typename T1, typename T2>
+inline auto llmax(T1 d1, T2 d2)
{
return (d1 > d2) ? d1 : d2;
}
-template <class LLDATATYPE>
-inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3)
+template <typename T1, typename T2, typename T3>
+inline auto llmax(T1 d1, T2 d2, T3 d3)
{
- LLDATATYPE r = llmax(d1,d2);
+ auto r = llmax(d1,d2);
return llmax(r, d3);
}
-template <class LLDATATYPE>
-inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3, const LLDATATYPE& d4)
+template <typename T1, typename T2, typename T3, typename T4>
+inline auto llmax(T1 d1, T2 d2, T3 d3, T4 d4)
{
- LLDATATYPE r1 = llmax(d1,d2);
- LLDATATYPE r2 = llmax(d3,d4);
+ auto r1 = llmax(d1,d2);
+ auto r2 = llmax(d3,d4);
return llmax(r1, r2);
}
-template <class LLDATATYPE>
-inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2)
+template <typename T1, typename T2>
+inline auto llmin(T1 d1, T2 d2)
{
return (d1 < d2) ? d1 : d2;
}
-template <class LLDATATYPE>
-inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3)
+template <typename T1, typename T2, typename T3>
+inline auto llmin(T1 d1, T2 d2, T3 d3)
{
- LLDATATYPE r = llmin(d1,d2);
+ auto r = llmin(d1,d2);
return (r < d3 ? r : d3);
}
-template <class LLDATATYPE>
-inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3, const LLDATATYPE& d4)
+template <typename T1, typename T2, typename T3, typename T4>
+inline auto llmin(T1 d1, T2 d2, T3 d3, T4 d4)
{
- LLDATATYPE r1 = llmin(d1,d2);
- LLDATATYPE r2 = llmin(d3,d4);
+ auto r1 = llmin(d1,d2);
+ auto r2 = llmin(d3,d4);
return llmin(r1, r2);
}
-template <class LLDATATYPE>
-inline LLDATATYPE llclamp(const LLDATATYPE& a, const LLDATATYPE& minval, const LLDATATYPE& maxval)
+template <typename A, typename MIN, typename MAX>
+inline A llclamp(A a, MIN minval, MAX maxval)
{
- if ( a < minval )
+ A aminval{ static_cast<A>(minval) }, amaxval{ static_cast<A>(maxval) };
+ if ( a < aminval )
{
- return minval;
+ return aminval;
}
- else if ( a > maxval )
+ else if ( a > amaxval )
{
- return maxval;
+ return amaxval;
}
return a;
}
template <class LLDATATYPE>
-inline LLDATATYPE llclampf(const LLDATATYPE& a)
+inline LLDATATYPE llclampf(LLDATATYPE a)
{
- return llmin(llmax(a, (LLDATATYPE)0), (LLDATATYPE)1);
+ return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(1));
}
template <class LLDATATYPE>
-inline LLDATATYPE llclampb(const LLDATATYPE& a)
+inline LLDATATYPE llclampb(LLDATATYPE a)
{
- return llmin(llmax(a, (LLDATATYPE)0), (LLDATATYPE)255);
+ return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(255));
}
template <class LLDATATYPE>
inline void llswap(LLDATATYPE& lhs, LLDATATYPE& rhs)
{
- LLDATATYPE tmp = lhs;
- lhs = rhs;
- rhs = tmp;
+ std::swap(lhs, rhs);
}
#endif // LL_LLDEFS_H
diff --git a/indra/llcommon/lldependencies.cpp b/indra/llcommon/lldependencies.cpp
index 0d5757effd..db546c5c3b 100644
--- a/indra/llcommon/lldependencies.cpp
+++ b/indra/llcommon/lldependencies.cpp
@@ -42,7 +42,7 @@
// other Linden headers
#include "llexception.h"
-LLDependenciesBase::VertexList LLDependenciesBase::topo_sort(int vertices, const EdgeList& edges) const
+LLDependenciesBase::VertexList LLDependenciesBase::topo_sort(size_t vertices, const EdgeList& edges) const
{
// Construct a Boost Graph Library graph according to the constraints
// we've collected. It seems as though we ought to be able to capture
diff --git a/indra/llcommon/lldependencies.h b/indra/llcommon/lldependencies.h
index db2bbab8b0..950af4a4ad 100644
--- a/indra/llcommon/lldependencies.h
+++ b/indra/llcommon/lldependencies.h
@@ -126,7 +126,7 @@ public:
protected:
typedef std::vector< std::pair<std::size_t, std::size_t> > EdgeList;
typedef std::vector<std::size_t> VertexList;
- VertexList topo_sort(int vertices, const EdgeList& edges) const;
+ VertexList topo_sort(size_t vertices, const EdgeList& edges) const;
/**
* refpair is specifically intended to capture a pair of references. This
@@ -539,7 +539,7 @@ public:
for (typename DepNodeMap::const_iterator nmi = mNodes.begin(), nmend = mNodes.end();
nmi != nmend; ++nmi)
{
- int thisnode = vmap[nmi->first];
+ auto thisnode = vmap[nmi->first];
// after dependencies: build edges from the named node to this one
for (typename DepNode::dep_set::const_iterator ai = nmi->second.after.begin(),
aend = nmi->second.after.end();
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index 919d2dabc4..02cb186275 100644
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -586,11 +586,9 @@ namespace
void Globals::invalidateCallSites()
{
- for (CallSiteVector::const_iterator i = callSites.begin();
- i != callSites.end();
- ++i)
+ for (LLError::CallSite* site : callSites)
{
- (*i)->invalidate();
+ site->invalidate();
}
callSites.clear();
@@ -943,7 +941,7 @@ namespace LLError
for (a = sets.beginArray(), end = sets.endArray(); a != end; ++a)
{
const LLSD& entry = *a;
- if (entry.isMap() && !entry.emptyMap())
+ if (entry.isMap() && entry.size() != 0)
{
ELevel level = decodeLevel(entry["level"]);
@@ -1224,12 +1222,8 @@ namespace
std::string escaped_message;
LLMutexLock lock(&s->mRecorderMutex);
- for (Recorders::const_iterator i = s->mRecorders.begin();
- i != s->mRecorders.end();
- ++i)
+ for (LLError::RecorderPtr& r : s->mRecorders)
{
- LLError::RecorderPtr r = *i;
-
if (!r->enabled())
{
continue;
@@ -1514,7 +1508,7 @@ namespace LLError
const size_t BUF_SIZE = 64;
char time_str[BUF_SIZE]; /* Flawfinder: ignore */
- int chars = strftime(time_str, BUF_SIZE,
+ auto chars = strftime(time_str, BUF_SIZE,
"%Y-%m-%dT%H:%M:%SZ",
gmtime(&now));
diff --git a/indra/llcommon/llevent.cpp b/indra/llcommon/llevent.cpp
index 633df01588..501d06e3cd 100644
--- a/indra/llcommon/llevent.cpp
+++ b/indra/llcommon/llevent.cpp
@@ -203,10 +203,9 @@ void LLSimpleDispatcher::removeListener(LLEventListener* listener)
std::vector<LLListenerEntry> LLSimpleDispatcher::getListeners() const
{
std::vector<LLListenerEntry> ret;
- std::vector<LLListenerEntry>::const_iterator itor;
- for (itor=mListeners.begin(); itor!=mListeners.end(); ++itor)
+ for (const LLListenerEntry& entry : mListeners)
{
- ret.push_back(*itor);
+ ret.push_back(entry);
}
return ret;
@@ -215,14 +214,12 @@ std::vector<LLListenerEntry> LLSimpleDispatcher::getListeners() const
// virtual
bool LLSimpleDispatcher::fireEvent(LLPointer<LLEvent> event, LLSD filter)
{
- std::vector<LLListenerEntry>::iterator itor;
std::string filter_string = filter.asString();
- for (itor=mListeners.begin(); itor!=mListeners.end(); ++itor)
+ for (LLListenerEntry& entry : mListeners)
{
- LLListenerEntry& entry = *itor;
if (filter_string == "" || entry.filter.asString() == filter_string)
{
- (entry.listener)->handleEvent(event, (*itor).userdata);
+ (entry.listener)->handleEvent(event, entry.userdata);
}
}
return true;
@@ -276,10 +273,9 @@ void LLSimpleListener::clearDispatchers()
bool LLSimpleListener::handleAttach(LLEventDispatcher *dispatcher)
{
// Add dispatcher if it doesn't already exist
- std::vector<LLEventDispatcher *>::iterator itor;
- for (itor = mDispatchers.begin(); itor != mDispatchers.end(); ++itor)
+ for (LLEventDispatcher* disp : mDispatchers)
{
- if ((*itor) == dispatcher) return true;
+ if (disp == dispatcher) return true;
}
mDispatchers.push_back(dispatcher);
return true;
diff --git a/indra/llcommon/lleventdispatcher.cpp b/indra/llcommon/lleventdispatcher.cpp
index 7ba8c5ada7..0c3bb35cfe 100644
--- a/indra/llcommon/lleventdispatcher.cpp
+++ b/indra/llcommon/lleventdispatcher.cpp
@@ -187,7 +187,7 @@ private:
// store it as a map from name string to position index. Of course that's
// easy to generate from the incoming names array, but why do it more than
// once?
- typedef std::map<LLSD::String, LLSD::Integer> IndexMap;
+ typedef std::map<LLSD::String, size_t> IndexMap;
IndexMap _indexes;
// Generated array of default values, aligned with the array of param names.
LLSD _defaults;
@@ -206,9 +206,9 @@ LLSDArgsMapper::LLSDArgsMapper(const std::string& function,
{
LLTHROW(DispatchError(stringize(function, " names must be an array, not ", names)));
}
- LLSD::Integer nparams(_names.size());
+ auto nparams(_names.size());
// From _names generate _indexes.
- for (LLSD::Integer ni = 0, nend = _names.size(); ni < nend; ++ni)
+ for (size_t ni = 0, nend = _names.size(); ni < nend; ++ni)
{
_indexes[_names[ni]] = ni;
}
@@ -223,7 +223,7 @@ LLSDArgsMapper::LLSDArgsMapper(const std::string& function,
if (defaults.isUndefined() || defaults.isArray())
{
- LLSD::Integer ndefaults = defaults.size();
+ auto ndefaults = defaults.size();
// defaults is a (possibly empty) array. Right-align it with names.
if (ndefaults > nparams)
{
@@ -233,10 +233,10 @@ LLSDArgsMapper::LLSDArgsMapper(const std::string& function,
// Offset by which we slide defaults array right to right-align with
// _names array
- LLSD::Integer offset = nparams - ndefaults;
+ auto offset = nparams - ndefaults;
// Fill rightmost _defaults entries from defaults, and mark them as
// filled
- for (LLSD::Integer i = 0, iend = ndefaults; i < iend; ++i)
+ for (size_t i = 0, iend = ndefaults; i < iend; ++i)
{
_defaults[i + offset] = defaults[i];
_has_dft[i + offset] = 1;
@@ -256,7 +256,7 @@ LLSDArgsMapper::LLSDArgsMapper(const std::string& function,
continue;
}
- LLSD::Integer pos = ixit->second;
+ auto pos = ixit->second;
// Store default value at that position in the _defaults array.
_defaults[pos] = mi->second;
// Don't forget to record the fact that we've filled this
@@ -310,7 +310,7 @@ LLSD LLSDArgsMapper::map(const LLSD& argsmap) const
{
// Fill args from array. If there are too many args in passed array,
// ignore the rest.
- LLSD::Integer size(argsmap.size());
+ auto size(argsmap.size());
if (size > args.size())
{
// We don't just use std::min() because we want to sneak in this
@@ -347,7 +347,7 @@ LLSD LLSDArgsMapper::map(const LLSD& argsmap) const
<< mi->first << "=" << mi->second << LL_ENDL;
continue;
}
- LLSD::Integer pos = ixit->second;
+ auto pos = ixit->second;
// Store the value at that position in the args array.
args[pos] = mi->second;
// Don't forget to record the fact that we've filled this
@@ -358,7 +358,7 @@ LLSD LLSDArgsMapper::map(const LLSD& argsmap) const
// Fill any remaining holes from _defaults.
LLSD unfilled(LLSD::emptyArray());
- for (LLSD::Integer i = 0, iend = args.size(); i < iend; ++i)
+ for (size_t i = 0, iend = args.size(); i < iend; ++i)
{
if (! filled[i])
{
@@ -512,9 +512,9 @@ struct LLEventDispatcher::MapParamsDispatchEntry: public LLEventDispatcher::Para
if (defaults.isArray() || defaults.isUndefined())
{
// Right-align the params and defaults arrays.
- LLSD::Integer offset = params.size() - defaults.size();
+ auto offset = params.size() - defaults.size();
// Now the name of every defaults[i] is at params[i + offset].
- for (LLSD::Integer i(0), iend(defaults.size()); i < iend; ++i)
+ for (size_t i(0), iend(defaults.size()); i < iend; ++i)
{
// Erase this optional param from mRequired.
mRequired.erase(params[i + offset].asString());
diff --git a/indra/llcommon/llheteromap.cpp b/indra/llcommon/llheteromap.cpp
index 7c19196e0c..c84e49d085 100644
--- a/indra/llcommon/llheteromap.cpp
+++ b/indra/llcommon/llheteromap.cpp
@@ -22,11 +22,11 @@ LLHeteroMap::~LLHeteroMap()
{
// For each entry in our map, we must call its deleter, which is the only
// record we have of its original type.
- for (TypeMap::iterator mi(mMap.begin()), me(mMap.end()); mi != me; ++mi)
+ for (TypeMap::value_type& pair : mMap)
{
- // mi->second is the std::pair; mi->second.first is the void*;
- // mi->second.second points to the deleter function
- (mi->second.second)(mi->second.first);
- mi->second.first = NULL;
+ // pair.second is the std::pair; pair.second.first is the void*;
+ // pair.second.second points to the deleter function
+ (pair.second.second)(pair.second.first);
+ pair.second.first = NULL;
}
}
diff --git a/indra/llcommon/llinitdestroyclass.cpp b/indra/llcommon/llinitdestroyclass.cpp
index e6382a7924..e3b9e6d099 100644
--- a/indra/llcommon/llinitdestroyclass.cpp
+++ b/indra/llcommon/llinitdestroyclass.cpp
@@ -21,10 +21,9 @@
void LLCallbackRegistry::fireCallbacks() const
{
- for (FuncList::const_iterator fi = mCallbacks.begin(), fe = mCallbacks.end();
- fi != fe; ++fi)
+ for (FuncList::value_type pair : mCallbacks)
{
- LL_INFOS("LLInitDestroyClass") << "calling " << fi->first << "()" << LL_ENDL;
- fi->second();
+ LL_INFOS("LLInitDestroyClass") << "calling " << pair.first << "()" << LL_ENDL;
+ pair.second();
}
}
diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp
index aa2f4eb289..d15bd2f619 100644
--- a/indra/llcommon/llinitparam.cpp
+++ b/indra/llcommon/llinitparam.cpp
@@ -207,10 +207,10 @@ namespace LLInitParam
if (!mValidated)
{
const BlockDescriptor& block_data = mostDerivedBlockDescriptor();
- for (BlockDescriptor::param_validation_list_t::const_iterator it = block_data.mValidationList.begin(); it != block_data.mValidationList.end(); ++it)
+ for (const BlockDescriptor::param_validation_list_t::value_type& pair : block_data.mValidationList)
{
- const Param* param = getParamFromHandle(it->first);
- if (!it->second(param))
+ const Param* param = getParamFromHandle(pair.first);
+ if (!pair.second(param))
{
if (emit_errors)
{
@@ -235,13 +235,11 @@ namespace LLInitParam
// unnamed param is like LLView::Params::rect - implicit
const BlockDescriptor& block_data = mostDerivedBlockDescriptor();
- for (BlockDescriptor::param_list_t::const_iterator it = block_data.mUnnamedParams.begin();
- it != block_data.mUnnamedParams.end();
- ++it)
+ for (const ParamDescriptorPtr& ptr : block_data.mUnnamedParams)
{
- param_handle_t param_handle = (*it)->mParamHandle;
+ param_handle_t param_handle = ptr->mParamHandle;
const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::serialize_func_t serialize_func = (*it)->mSerializeFunc;
+ ParamDescriptor::serialize_func_t serialize_func = ptr->mSerializeFunc;
if (serialize_func && predicate_rule.check(ll_make_predicate(PROVIDED, param->anyProvided())))
{
const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL;
@@ -249,23 +247,19 @@ namespace LLInitParam
}
}
- for(BlockDescriptor::param_map_t::const_iterator it = block_data.mNamedParams.begin();
- it != block_data.mNamedParams.end();
- ++it)
+ for (const BlockDescriptor::param_map_t::value_type& pair : block_data.mNamedParams)
{
- param_handle_t param_handle = it->second->mParamHandle;
+ param_handle_t param_handle = pair.second->mParamHandle;
const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::serialize_func_t serialize_func = it->second->mSerializeFunc;
+ ParamDescriptor::serialize_func_t serialize_func = pair.second->mSerializeFunc;
if (serialize_func && predicate_rule.check(ll_make_predicate(PROVIDED, param->anyProvided())))
{
// Ensure this param has not already been serialized
// Prevents <rect> from being serialized as its own tag.
bool duplicate = false;
- for (BlockDescriptor::param_list_t::const_iterator it2 = block_data.mUnnamedParams.begin();
- it2 != block_data.mUnnamedParams.end();
- ++it2)
+ for (const ParamDescriptorPtr& ptr : block_data.mUnnamedParams)
{
- if (param_handle == (*it2)->mParamHandle)
+ if (param_handle == ptr->mParamHandle)
{
duplicate = true;
break;
@@ -279,7 +273,7 @@ namespace LLInitParam
continue;
}
- name_stack.push_back(std::make_pair(it->first, !duplicate));
+ name_stack.push_back(std::make_pair(pair.first, !duplicate));
const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL;
serialized |= serialize_func(*param, parser, name_stack, predicate_rule, diff_param);
name_stack.pop_back();
@@ -300,45 +294,39 @@ namespace LLInitParam
// unnamed param is like LLView::Params::rect - implicit
const BlockDescriptor& block_data = mostDerivedBlockDescriptor();
- for (BlockDescriptor::param_list_t::const_iterator it = block_data.mUnnamedParams.begin();
- it != block_data.mUnnamedParams.end();
- ++it)
+ for (const ParamDescriptorPtr& ptr : block_data.mUnnamedParams)
{
- param_handle_t param_handle = (*it)->mParamHandle;
+ param_handle_t param_handle = ptr->mParamHandle;
const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::inspect_func_t inspect_func = (*it)->mInspectFunc;
+ ParamDescriptor::inspect_func_t inspect_func = ptr->mInspectFunc;
if (inspect_func)
{
name_stack.push_back(std::make_pair("", true));
- inspect_func(*param, parser, name_stack, (*it)->mMinCount, (*it)->mMaxCount);
+ inspect_func(*param, parser, name_stack, ptr->mMinCount, ptr->mMaxCount);
name_stack.pop_back();
}
}
- for(BlockDescriptor::param_map_t::const_iterator it = block_data.mNamedParams.begin();
- it != block_data.mNamedParams.end();
- ++it)
+ for(const BlockDescriptor::param_map_t::value_type& pair : block_data.mNamedParams)
{
- param_handle_t param_handle = it->second->mParamHandle;
+ param_handle_t param_handle = pair.second->mParamHandle;
const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::inspect_func_t inspect_func = it->second->mInspectFunc;
+ ParamDescriptor::inspect_func_t inspect_func = pair.second->mInspectFunc;
if (inspect_func)
{
// Ensure this param has not already been inspected
bool duplicate = false;
- for (BlockDescriptor::param_list_t::const_iterator it2 = block_data.mUnnamedParams.begin();
- it2 != block_data.mUnnamedParams.end();
- ++it2)
+ for (const ParamDescriptorPtr &ptr : block_data.mUnnamedParams)
{
- if (param_handle == (*it2)->mParamHandle)
+ if (param_handle == ptr->mParamHandle)
{
duplicate = true;
break;
}
}
- name_stack.push_back(std::make_pair(it->first, !duplicate));
- inspect_func(*param, parser, name_stack, it->second->mMinCount, it->second->mMaxCount);
+ name_stack.push_back(std::make_pair(pair.first, !duplicate));
+ inspect_func(*param, parser, name_stack, pair.second->mMinCount, pair.second->mMaxCount);
name_stack.pop_back();
}
}
@@ -382,12 +370,10 @@ namespace LLInitParam
}
// try to parse unnamed parameters, in declaration order
- for ( BlockDescriptor::param_list_t::iterator it = block_data.mUnnamedParams.begin();
- it != block_data.mUnnamedParams.end();
- ++it)
+ for (ParamDescriptorPtr& ptr : block_data.mUnnamedParams)
{
- Param* paramp = getParamFromHandle((*it)->mParamHandle);
- ParamDescriptor::deserialize_func_t deserialize_func = (*it)->mDeserializeFunc;
+ Param* paramp = getParamFromHandle(ptr->mParamHandle);
+ ParamDescriptor::deserialize_func_t deserialize_func = ptr->mDeserializeFunc;
if (deserialize_func && deserialize_func(*paramp, p, name_stack_range, new_name))
{
@@ -453,12 +439,9 @@ namespace LLInitParam
{
param_handle_t handle = getHandleFromParam(&param);
BlockDescriptor& descriptor = mostDerivedBlockDescriptor();
- BlockDescriptor::all_params_list_t::iterator end_it = descriptor.mAllParams.end();
- for (BlockDescriptor::all_params_list_t::iterator it = descriptor.mAllParams.begin();
- it != end_it;
- ++it)
+ for (ParamDescriptorPtr& ptr : descriptor.mAllParams)
{
- if ((*it)->mParamHandle == handle) return *it;
+ if (ptr->mParamHandle == handle) return ptr;
}
return ParamDescriptorPtr();
}
@@ -468,17 +451,14 @@ namespace LLInitParam
bool BaseBlock::mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite)
{
bool some_param_changed = false;
- BlockDescriptor::all_params_list_t::const_iterator end_it = block_data.mAllParams.end();
- for (BlockDescriptor::all_params_list_t::const_iterator it = block_data.mAllParams.begin();
- it != end_it;
- ++it)
+ for (const ParamDescriptorPtr& ptr : block_data.mAllParams)
{
- const Param* other_paramp = other.getParamFromHandle((*it)->mParamHandle);
- ParamDescriptor::merge_func_t merge_func = (*it)->mMergeFunc;
+ const Param* other_paramp = other.getParamFromHandle(ptr->mParamHandle);
+ ParamDescriptor::merge_func_t merge_func = ptr->mMergeFunc;
if (merge_func)
{
- Param* paramp = getParamFromHandle((*it)->mParamHandle);
- llassert(paramp->getEnclosingBlockOffset() == (*it)->mParamHandle);
+ Param* paramp = getParamFromHandle(ptr->mParamHandle);
+ llassert(paramp->getEnclosingBlockOffset() == ptr->mParamHandle);
some_param_changed |= merge_func(*paramp, *other_paramp, overwrite);
}
}
diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h
index 7f5b9b4ac2..9edc7e40f3 100644
--- a/indra/llcommon/llinitparam.h
+++ b/indra/llcommon/llinitparam.h
@@ -325,13 +325,11 @@ namespace LLInitParam
std::string calcValueName(const value_t& value) const
{
value_name_map_t* map = getValueNames();
- for (typename value_name_map_t::iterator it = map->begin(), end_it = map->end();
- it != end_it;
- ++it)
+ for (typename value_name_map_t::value_type& map_pair : *map)
{
- if (ParamCompare<T>::equals(it->second, value))
+ if (ParamCompare<T>::equals(map_pair.second, value))
{
- return it->first;
+ return map_pair.first;
}
}
@@ -376,11 +374,9 @@ namespace LLInitParam
static std::vector<std::string> sValues;
value_name_map_t* map = getValueNames();
- for (typename value_name_map_t::iterator it = map->begin(), end_it = map->end();
- it != end_it;
- ++it)
+ for (typename value_name_map_t::value_type& map_pair : *map)
{
- sValues.push_back(it->first);
+ sValues.push_back(map_pair.first);
}
return &sValues;
}
diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h
index 02535a59e7..34f2a5985a 100644
--- a/indra/llcommon/llinstancetracker.h
+++ b/indra/llcommon/llinstancetracker.h
@@ -99,7 +99,7 @@ public:
return mSelf;
}
- static S32 instanceCount()
+ static size_t instanceCount()
{
return LockStatic()->mMap.size();
}
@@ -363,7 +363,7 @@ public:
return mSelf;
}
- static S32 instanceCount()
+ static size_t instanceCount()
{
return LockStatic()->mSet.size();
}
diff --git a/indra/llcommon/llkeybind.cpp b/indra/llcommon/llkeybind.cpp
index 38696c2258..b89160cc55 100644
--- a/indra/llcommon/llkeybind.cpp
+++ b/indra/llcommon/llkeybind.cpp
@@ -30,6 +30,7 @@
#include "llsd.h"
#include "llsdutil.h"
+#include <algorithm>
LLKeyData::LLKeyData()
:
@@ -180,10 +181,10 @@ LLKeyBind::LLKeyBind(const LLSD &key_bind)
bool LLKeyBind::operator==(const LLKeyBind& rhs)
{
- U32 size = mData.size();
+ auto size = mData.size();
if (size != rhs.mData.size()) return false;
- for (U32 i = 0; i < size; i++)
+ for (size_t i = 0; i < size; i++)
{
if (mData[i] != rhs.mData[i]) return false;
}
@@ -193,7 +194,7 @@ bool LLKeyBind::operator==(const LLKeyBind& rhs)
bool LLKeyBind::operator!=(const LLKeyBind& rhs)
{
- U32 size = mData.size();
+ auto size = mData.size();
if (size != rhs.mData.size()) return true;
for (U32 i = 0; i < size; i++)
@@ -206,26 +207,29 @@ bool LLKeyBind::operator!=(const LLKeyBind& rhs)
bool LLKeyBind::isEmpty() const
{
- for (data_vector_t::const_iterator iter = mData.begin(); iter != mData.end(); iter++)
+ for (const LLKeyData& key_data : mData)
{
- if (!iter->isEmpty()) return false;
+ if (!key_data.isEmpty()) return false;
}
return true;
}
-LLSD LLKeyBind::asLLSD() const
+LLKeyBind::data_vector_t::const_iterator LLKeyBind::endNonEmpty() const
{
- S32 last = mData.size() - 1;
- while (mData[last].empty())
- {
- last--;
- }
+ // search backwards for last non-empty entry, then turn back into forwards
+ // iterator (.base() call)
+ return std::find_if_not(mData.rbegin(), mData.rend(),
+ [](const auto& kdata){ return kdata.empty(); }).base();
+}
+LLSD LLKeyBind::asLLSD() const
+{
LLSD data;
- for (S32 i = 0; i <= last; ++i)
+ for (const LLKeyData& key_data : mData)
{
- // append even if empty to not affect visual representation
- data.append(mData[i].asLLSD());
+ // append intermediate entries even if empty to not affect visual
+ // representation
+ data.append(key_data.asLLSD());
}
return data;
}
@@ -238,9 +242,9 @@ bool LLKeyBind::canHandle(EMouseClickType mouse, KEY key, MASK mask) const
return false;
}
- for (data_vector_t::const_iterator iter = mData.begin(); iter != mData.end(); iter++)
+ for (const LLKeyData& key_data : mData)
{
- if (iter->canHandle(mouse, key, mask))
+ if (key_data.canHandle(mouse, key, mask))
{
return true;
}
@@ -262,12 +266,12 @@ bool LLKeyBind::hasKeyData(EMouseClickType mouse, KEY key, MASK mask, bool ignor
{
if (mouse != CLICK_NONE || key != KEY_NONE)
{
- for (data_vector_t::const_iterator iter = mData.begin(); iter != mData.end(); iter++)
+ for (const LLKeyData& key_data : mData)
{
- if (iter->mKey == key
- && iter->mMask == mask
- && iter->mMouse == mouse
- && iter->mIgnoreMasks == ignore)
+ if (key_data.mKey == key
+ && key_data.mMask == mask
+ && key_data.mMouse == mouse
+ && key_data.mIgnoreMasks == ignore)
{
return true;
}
@@ -349,16 +353,16 @@ void LLKeyBind::replaceKeyData(const LLKeyData& data, U32 index)
{
// if both click and key are none (isEmpty()), we are inserting a placeholder, we don't want to reset anything
// otherwise reset identical key
- for (data_vector_t::iterator iter = mData.begin(); iter != mData.end(); iter++)
+ for (LLKeyData& key_data : mData)
{
- if (iter->mKey == data.mKey
- && iter->mMouse == data.mMouse
- && iter->mIgnoreMasks == data.mIgnoreMasks
- && iter->mMask == data.mMask)
+ if (key_data.mKey == data.mKey
+ && key_data.mMouse == data.mMouse
+ && key_data.mIgnoreMasks == data.mIgnoreMasks
+ && key_data.mMask == data.mMask)
{
// Replacing only fully equal combinations even in case 'ignore' is set
// Reason: Simplicity and user might decide to do a 'move' command as W and Shift+Ctrl+W, and 'run' as Shift+W
- iter->reset();
+ key_data.reset();
break;
}
}
@@ -380,16 +384,10 @@ void LLKeyBind::resetKeyData(S32 index)
void LLKeyBind::trimEmpty()
{
- S32 last = mData.size() - 1;
- while (last >= 0 && mData[last].empty())
- {
- mData.erase(mData.begin() + last);
- last--;
- }
+ mData.erase(endNonEmpty(), mData.end());
}
-U32 LLKeyBind::getDataCount()
+size_t LLKeyBind::getDataCount()
{
return mData.size();
}
-
diff --git a/indra/llcommon/llkeybind.h b/indra/llcommon/llkeybind.h
index c6b4bd970f..488f509411 100644
--- a/indra/llcommon/llkeybind.h
+++ b/indra/llcommon/llkeybind.h
@@ -95,11 +95,13 @@ public:
void clear() { mData.clear(); }
// if there any empty LLKeyData in the end of the array, remove them
void trimEmpty();
- U32 getDataCount();
+ size_t getDataCount();
private:
typedef std::vector<LLKeyData> data_vector_t;
data_vector_t mData;
+
+ data_vector_t::const_iterator endNonEmpty() const;
};
diff --git a/indra/llcommon/llleap.cpp b/indra/llcommon/llleap.cpp
index 2704f8b6de..c87c0758fe 100644
--- a/indra/llcommon/llleap.cpp
+++ b/indra/llcommon/llleap.cpp
@@ -231,7 +231,8 @@ public:
}
|*==========================================================================*/
- LL_DEBUGS("EventHost") << "Sending: " << buffer.tellp() << ':';
+ LL_DEBUGS("EventHost") << "Sending: "
+ << static_cast<U64>(buffer.tellp()) << ':';
std::string::size_type truncate(80);
if (buffer.tellp() <= truncate)
{
@@ -244,7 +245,8 @@ public:
LL_CONT << LL_ENDL;
LLProcess::WritePipe& childin(mChild->getWritePipe(LLProcess::STDIN));
- childin.get_ostream() << buffer.tellp() << ':' << buffer.str() << std::flush;
+ childin.get_ostream() << static_cast<U64>(buffer.tellp())
+ << ':' << buffer.str() << std::flush;
return false;
}
diff --git a/indra/llcommon/llmd5.cpp b/indra/llcommon/llmd5.cpp
index f942a976b7..9b2a2bab60 100644
--- a/indra/llcommon/llmd5.cpp
+++ b/indra/llcommon/llmd5.cpp
@@ -96,10 +96,10 @@ LLMD5::LLMD5()
// operation, processing another message block, and updating the
// context.
-void LLMD5::update (const uint1 *input, const uint4 input_length) {
+void LLMD5::update (const uint1 *input, const size_t input_length) {
- uint4 input_index, buffer_index;
- uint4 buffer_space; // how much space is left in buffer
+ size_t input_index, buffer_index;
+ size_t buffer_space; // how much space is left in buffer
if (finalized){ // so we can't update!
std::cerr << "LLMD5::update: Can't update a finalized digest!" << std::endl;
@@ -107,14 +107,10 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) {
}
// Compute number of bytes mod 64
- buffer_index = (unsigned int)((count[0] >> 3) & 0x3F);
+ buffer_index = size_t((count >> 3) & 0x3F);
// Update number of bits
- if ( (count[0] += ((uint4) input_length << 3))<((uint4) input_length << 3) )
- count[1]++;
-
- count[1] += ((uint4)input_length >> 29);
-
+ count += input_length << 3;
buffer_space = 64 - buffer_index; // how much space is left in buffer
@@ -192,7 +188,7 @@ void LLMD5::update(const std::string& s)
void LLMD5::finalize (){
unsigned char bits[8]; /* Flawfinder: ignore */
- unsigned int index, padLen;
+ size_t index, padLen;
static uint1 PADDING[64]={
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -204,11 +200,12 @@ void LLMD5::finalize (){
return;
}
- // Save number of bits
- encode (bits, count, 8);
+ // Save number of bits.
+ // Treat count, a uint64_t, as uint4[2].
+ encode (bits, reinterpret_cast<uint4*>(&count), 8);
// Pad out to 56 mod 64.
- index = (uint4) ((count[0] >> 3) & 0x3f);
+ index = size_t((count >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
update (PADDING, padLen);
@@ -340,8 +337,7 @@ void LLMD5::init(){
finalized=0; // we just started!
// Nothing counted, so count=0
- count[0] = 0;
- count[1] = 0;
+ count = 0;
// Load magic initialization constants.
state[0] = 0x67452301;
@@ -508,9 +504,9 @@ void LLMD5::transform (const U8 block[64]){
// Encodes input (UINT4) into output (unsigned char). Assumes len is
// a multiple of 4.
-void LLMD5::encode (uint1 *output, const uint4 *input, const uint4 len) {
+void LLMD5::encode (uint1 *output, const uint4 *input, const size_t len) {
- unsigned int i, j;
+ size_t i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (uint1) (input[i] & 0xff);
@@ -525,9 +521,9 @@ void LLMD5::encode (uint1 *output, const uint4 *input, const uint4 len) {
// Decodes input (unsigned char) into output (UINT4). Assumes len is
// a multiple of 4.
-void LLMD5::decode (uint4 *output, const uint1 *input, const uint4 len){
+void LLMD5::decode (uint4 *output, const uint1 *input, const size_t len){
- unsigned int i, j;
+ size_t i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) |
diff --git a/indra/llcommon/llmd5.h b/indra/llcommon/llmd5.h
index 1526e6ac3c..8530dc0389 100644
--- a/indra/llcommon/llmd5.h
+++ b/indra/llcommon/llmd5.h
@@ -86,7 +86,7 @@ class LL_COMMON_API LLMD5 {
public:
// methods for controlled operation:
LLMD5 (); // simple initializer
- void update (const uint1 *input, const uint4 input_length);
+ void update (const uint1 *input, const size_t input_length);
void update (std::istream& stream);
void update (FILE *file);
void update (const std::string& str);
@@ -110,7 +110,7 @@ private:
// next, the private data:
uint4 state[4];
- uint4 count[2]; // number of *bits*, mod 2^64
+ uint64_t count; // number of *bits*, mod 2^64
uint1 buffer[64]; // input buffer
uint1 digest[16];
uint1 finalized;
@@ -120,8 +120,8 @@ private:
void transform (const uint1 *buffer); // does the real update work. Note
// that length is implied to be 64.
- static void encode (uint1 *dest, const uint4 *src, const uint4 length);
- static void decode (uint4 *dest, const uint1 *src, const uint4 length);
+ static void encode (uint1 *dest, const uint4 *src, const size_t length);
+ static void decode (uint4 *dest, const uint1 *src, const size_t length);
};
diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp
index 849867586a..d6ae1284d3 100644
--- a/indra/llcommon/llmemory.cpp
+++ b/indra/llcommon/llmemory.cpp
@@ -212,11 +212,9 @@ U64 LLMemory::getCurrentRSS()
mach_msg_type_number_t basicInfoCount = MACH_TASK_BASIC_INFO_COUNT;
if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&basicInfo, &basicInfoCount) == KERN_SUCCESS)
{
-// residentSize = basicInfo.resident_size;
- // Although this method is defined to return the "resident set size,"
- // in fact what callers want from it is the total virtual memory
- // consumed by the application.
- residentSize = basicInfo.virtual_size;
+ residentSize = basicInfo.resident_size;
+ // 64-bit macos apps allocate 32 GB or more at startup, and this is reflected in virtual_size.
+ // basicInfo.virtual_size is not what we want.
}
else
{
diff --git a/indra/llcommon/llmetricperformancetester.cpp b/indra/llcommon/llmetricperformancetester.cpp
index 100eb57555..ab509b46eb 100644
--- a/indra/llcommon/llmetricperformancetester.cpp
+++ b/indra/llcommon/llmetricperformancetester.cpp
@@ -42,9 +42,9 @@ LLMetricPerformanceTesterBasic::name_tester_map_t LLMetricPerformanceTesterBasic
/*static*/
void LLMetricPerformanceTesterBasic::cleanupClass()
{
- for (name_tester_map_t::iterator iter = sTesterMap.begin() ; iter != sTesterMap.end() ; ++iter)
+ for (name_tester_map_t::value_type& pair : sTesterMap)
{
- delete iter->second ;
+ delete pair.second;
}
sTesterMap.clear() ;
}
@@ -111,8 +111,8 @@ LLSD LLMetricPerformanceTesterBasic::analyzeMetricPerformanceLog(std::istream& i
{
ret[label]["Name"] = iter->second["Name"] ;
- S32 num_of_metrics = tester->getNumberOfMetrics() ;
- for(S32 index = 0 ; index < num_of_metrics ; index++)
+ auto num_of_metrics = tester->getNumberOfMetrics() ;
+ for(size_t index = 0 ; index < num_of_metrics ; index++)
{
ret[label][ tester->getMetricName(index) ] = iter->second[ tester->getMetricName(index) ] ;
}
@@ -154,10 +154,9 @@ void LLMetricPerformanceTesterBasic::doAnalysisMetrics(std::string baseline, std
llofstream os(output.c_str());
os << "Label, Metric, Base(B), Target(T), Diff(T-B), Percentage(100*T/B)\n";
- for(LLMetricPerformanceTesterBasic::name_tester_map_t::iterator iter = LLMetricPerformanceTesterBasic::sTesterMap.begin() ;
- iter != LLMetricPerformanceTesterBasic::sTesterMap.end() ; ++iter)
+ for (LLMetricPerformanceTesterBasic::name_tester_map_t::value_type& pair : LLMetricPerformanceTesterBasic::sTesterMap)
{
- LLMetricPerformanceTesterBasic* tester = ((LLMetricPerformanceTesterBasic*)iter->second) ;
+ LLMetricPerformanceTesterBasic* tester = ((LLMetricPerformanceTesterBasic*)pair.second);
tester->analyzePerformance(&os, &base, &current) ;
}
diff --git a/indra/llcommon/llmetricperformancetester.h b/indra/llcommon/llmetricperformancetester.h
index 2e99ed979d..6561a78f03 100644
--- a/indra/llcommon/llmetricperformancetester.h
+++ b/indra/llcommon/llmetricperformancetester.h
@@ -67,12 +67,12 @@ public:
/**
* @return Returns the number of the test metrics in this tester instance.
*/
- S32 getNumberOfMetrics() const { return mMetricStrings.size() ;}
+ auto getNumberOfMetrics() const { return mMetricStrings.size() ;}
/**
* @return Returns the metric name at index
* @param[in] index - Index on the list of metrics managed by this tester instance.
*/
- std::string getMetricName(S32 index) const { return mMetricStrings[index] ;}
+ std::string getMetricName(size_t index) const { return mMetricStrings[index] ;}
protected:
/**
diff --git a/indra/llcommon/llmortician.cpp b/indra/llcommon/llmortician.cpp
index 93c7d520f2..b6ad40c2af 100644
--- a/indra/llcommon/llmortician.cpp
+++ b/indra/llcommon/llmortician.cpp
@@ -37,9 +37,9 @@ LLMortician::~LLMortician()
sGraveyard.remove(this);
}
-U32 LLMortician::logClass(std::stringstream &str)
+size_t LLMortician::logClass(std::stringstream &str)
{
- U32 size = sGraveyard.size();
+ auto size = sGraveyard.size();
str << "Mortician graveyard count: " << size;
str << " Zealous: " << (sDestroyImmediate ? "True" : "False");
if (size == 0)
diff --git a/indra/llcommon/llmortician.h b/indra/llcommon/llmortician.h
index 41cb49fab1..f92c5a11db 100644
--- a/indra/llcommon/llmortician.h
+++ b/indra/llcommon/llmortician.h
@@ -34,8 +34,8 @@ class LL_COMMON_API LLMortician
{
public:
LLMortician() { mIsDead = FALSE; }
- static U32 graveyardCount() { return sGraveyard.size(); };
- static U32 logClass(std::stringstream &str);
+ static auto graveyardCount() { return sGraveyard.size(); };
+ static size_t logClass(std::stringstream &str);
static void updateClass();
virtual ~LLMortician();
void die();
diff --git a/indra/llcommon/llnametable.h b/indra/llcommon/llnametable.h
index d3283543f3..2c8e71263e 100644
--- a/indra/llcommon/llnametable.h
+++ b/indra/llcommon/llnametable.h
@@ -86,12 +86,10 @@ public:
// O(N)! (currently only used in one place... (newsim/llstate.cpp))
const char *resolveData(const DATA &data) const
{
- const_iter_t iter = mNameMap.begin();
- const_iter_t end = mNameMap.end();
- for (; iter != end; ++iter)
+ for (const name_map_t::value_type& pair : mNameMap)
{
- if (iter->second == data)
- return iter->first;
+ if (pair.second == data)
+ return pair.first;
}
return NULL;
}
diff --git a/indra/llcommon/llpriqueuemap.h b/indra/llcommon/llpriqueuemap.h
index d8d3edd48a..030e2e0f21 100644
--- a/indra/llcommon/llpriqueuemap.h
+++ b/indra/llcommon/llpriqueuemap.h
@@ -115,9 +115,9 @@ public:
LL_WARNS() << "Data not on priority queue!" << LL_ENDL;
// OK, try iterating through all of the data and seeing if we just screwed up the priority
// somehow.
- for (iter = mMap.begin(); iter != mMap.end(); iter++)
+ for (pqm_pair pair : mMap)
{
- if ((*(iter)).second == data)
+ if (pair.second == data)
{
LL_ERRS() << "Data on priority queue but priority not matched!" << LL_ENDL;
}
diff --git a/indra/llcommon/llprocess.cpp b/indra/llcommon/llprocess.cpp
index 23936f0526..97a38ea992 100644
--- a/indra/llcommon/llprocess.cpp
+++ b/indra/llcommon/llprocess.cpp
@@ -272,6 +272,14 @@ public:
boost::bind(&ReadPipeImpl::tick, this, _1));
}
+ ~ReadPipeImpl()
+ {
+ if (mConnection.connected())
+ {
+ mConnection.disconnect();
+ }
+ }
+
// Much of the implementation is simply connecting the abstract virtual
// methods with implementation data concealed from the base class.
virtual std::istream& get_istream() { return mStream; }
diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp
index 818df07bb2..4a1a81f083 100644
--- a/indra/llcommon/llprocessor.cpp
+++ b/indra/llcommon/llprocessor.cpp
@@ -118,7 +118,11 @@ namespace
eMONTIOR_MWAIT=33,
eCPLDebugStore=34,
eThermalMonitor2=35,
- eAltivec=36
+ eAltivec=36,
+ eSSE3S_Features = 37,
+ eSSE4_1_Features = 38,
+ eSSE4_2_Features = 39,
+ eSSE4a_Features = 40,
};
const char* cpu_feature_names[] =
@@ -161,7 +165,11 @@ namespace
"CPL Qualified Debug Store",
"Thermal Monitor 2",
- "Altivec"
+ "Altivec",
+ "SSE3S Instructions",
+ "SSE4.1 Instructions",
+ "SSE4.2 Instructions",
+ "SSE4a Instructions",
};
std::string intel_CPUFamilyName(int composed_family)
@@ -250,6 +258,31 @@ public:
return hasExtension(cpu_feature_names[eSSE2_Ext]);
}
+ bool hasSSE3() const
+ {
+ return hasExtension(cpu_feature_names[eSSE3_Features]);
+ }
+
+ bool hasSSE3S() const
+ {
+ return hasExtension(cpu_feature_names[eSSE3S_Features]);
+ }
+
+ bool hasSSE41() const
+ {
+ return hasExtension(cpu_feature_names[eSSE4_1_Features]);
+ }
+
+ bool hasSSE42() const
+ {
+ return hasExtension(cpu_feature_names[eSSE4_2_Features]);
+ }
+
+ bool hasSSE4a() const
+ {
+ return hasExtension(cpu_feature_names[eSSE4a_Features]);
+ }
+
bool hasAltivec() const
{
return hasExtension("Altivec");
@@ -473,6 +506,12 @@ private:
*((int*)(cpu_vendor+4)) = cpu_info[3];
*((int*)(cpu_vendor+8)) = cpu_info[2];
setInfo(eVendor, cpu_vendor);
+ std::string cmp_vendor(cpu_vendor);
+ bool is_amd = false;
+ if (cmp_vendor == "AuthenticAMD")
+ {
+ is_amd = true;
+ }
// Get the information associated with each valid Id
for(unsigned int i=0; i<=ids; ++i)
@@ -504,6 +543,7 @@ private:
if(cpu_info[2] & 0x8)
{
+ // intel specific SSE3 suplements
setExtension(cpu_feature_names[eMONTIOR_MWAIT]);
}
@@ -516,7 +556,22 @@ private:
{
setExtension(cpu_feature_names[eThermalMonitor2]);
}
-
+
+ if (cpu_info[2] & 0x200)
+ {
+ setExtension(cpu_feature_names[eSSE3S_Features]);
+ }
+
+ if (cpu_info[2] & 0x80000)
+ {
+ setExtension(cpu_feature_names[eSSE4_1_Features]);
+ }
+
+ if (cpu_info[2] & 0x100000)
+ {
+ setExtension(cpu_feature_names[eSSE4_2_Features]);
+ }
+
unsigned int feature_info = (unsigned int) cpu_info[3];
for(unsigned int index = 0, bit = 1; index < eSSE3_Features; ++index, bit <<= 1)
{
@@ -543,8 +598,17 @@ private:
__cpuid(cpu_info, i);
// Interpret CPU brand string and cache information.
- if (i == 0x80000002)
- memcpy(cpu_brand_string, cpu_info, sizeof(cpu_info));
+ if (i == 0x80000001)
+ {
+ if (is_amd)
+ {
+ setExtension(cpu_feature_names[eSSE4a_Features]);
+ }
+ }
+ else if (i == 0x80000002)
+ {
+ memcpy(cpu_brand_string, cpu_info, sizeof(cpu_info));
+ }
else if (i == 0x80000003)
memcpy(cpu_brand_string + 16, cpu_info, sizeof(cpu_info));
else if (i == 0x80000004)
@@ -690,6 +754,41 @@ private:
uint64_t ext_feature_info = getSysctlInt64("machdep.cpu.extfeature_bits");
S32 *ext_feature_infos = (S32*)(&ext_feature_info);
setConfig(eExtFeatureBits, ext_feature_infos[0]);
+
+
+ char cpu_features[1024];
+ len = sizeof(cpu_features);
+ memset(cpu_features, 0, len);
+ sysctlbyname("machdep.cpu.features", (void*)cpu_features, &len, NULL, 0);
+
+ std::string cpu_features_str(cpu_features);
+ cpu_features_str = " " + cpu_features_str + " ";
+
+ if (cpu_features_str.find(" SSE3 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE3_Features]);
+ }
+
+ if (cpu_features_str.find(" SSSE3 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE3S_Features]);
+ }
+
+ if (cpu_features_str.find(" SSE4.1 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE4_1_Features]);
+ }
+
+ if (cpu_features_str.find(" SSE4.2 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE4_2_Features]);
+ }
+
+ if (cpu_features_str.find(" SSE4A ") != std::string::npos)
+ {
+ // Not supposed to happen?
+ setExtension(cpu_feature_names[eSSE4a_Features]);
+ }
}
};
@@ -800,6 +899,31 @@ private:
{
setExtension(cpu_feature_names[eSSE2_Ext]);
}
+
+ if (flags.find(" pni ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE3_Features]);
+ }
+
+ if (flags.find(" ssse3 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE3S_Features]);
+ }
+
+ if (flags.find(" sse4_1 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE4_1_Features]);
+ }
+
+ if (flags.find(" sse4_2 ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE4_2_Features]);
+ }
+
+ if (flags.find(" sse4a ") != std::string::npos)
+ {
+ setExtension(cpu_feature_names[eSSE4a_Features]);
+ }
# endif // LL_X86
}
@@ -860,6 +984,11 @@ LLProcessorInfo::~LLProcessorInfo() {}
F64MegahertzImplicit LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); }
bool LLProcessorInfo::hasSSE() const { return mImpl->hasSSE(); }
bool LLProcessorInfo::hasSSE2() const { return mImpl->hasSSE2(); }
+bool LLProcessorInfo::hasSSE3() const { return mImpl->hasSSE3(); }
+bool LLProcessorInfo::hasSSE3S() const { return mImpl->hasSSE3S(); }
+bool LLProcessorInfo::hasSSE41() const { return mImpl->hasSSE41(); }
+bool LLProcessorInfo::hasSSE42() const { return mImpl->hasSSE42(); }
+bool LLProcessorInfo::hasSSE4a() const { return mImpl->hasSSE4a(); }
bool LLProcessorInfo::hasAltivec() const { return mImpl->hasAltivec(); }
std::string LLProcessorInfo::getCPUFamilyName() const { return mImpl->getCPUFamilyName(); }
std::string LLProcessorInfo::getCPUBrandName() const { return mImpl->getCPUBrandName(); }
diff --git a/indra/llcommon/llprocessor.h b/indra/llcommon/llprocessor.h
index b77eb22c3a..1a473ddc97 100644
--- a/indra/llcommon/llprocessor.h
+++ b/indra/llcommon/llprocessor.h
@@ -54,6 +54,11 @@ public:
F64MegahertzImplicit getCPUFrequency() const;
bool hasSSE() const;
bool hasSSE2() const;
+ bool hasSSE3() const;
+ bool hasSSE3S() const;
+ bool hasSSE41() const;
+ bool hasSSE42() const;
+ bool hasSSE4a() const;
bool hasAltivec() const;
std::string getCPUFamilyName() const;
std::string getCPUBrandName() const;
diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp
index 8cef4293cd..b06fee0ec2 100644
--- a/indra/llcommon/llqueuedthread.cpp
+++ b/indra/llcommon/llqueuedthread.cpp
@@ -110,7 +110,7 @@ void LLQueuedThread::shutdown()
// MAIN THREAD
// virtual
-S32 LLQueuedThread::update(F32 max_time_ms)
+size_t LLQueuedThread::update(F32 max_time_ms)
{
if (!mStarted)
{
@@ -123,11 +123,11 @@ S32 LLQueuedThread::update(F32 max_time_ms)
return updateQueue(max_time_ms);
}
-S32 LLQueuedThread::updateQueue(F32 max_time_ms)
+size_t LLQueuedThread::updateQueue(F32 max_time_ms)
{
F64 max_time = (F64)max_time_ms * .001;
LLTimer timer;
- S32 pending = 1;
+ size_t pending = 1;
// Frame Update
if (mThreaded)
@@ -164,9 +164,9 @@ void LLQueuedThread::incQueue()
//virtual
// May be called from any thread
-S32 LLQueuedThread::getPending()
+size_t LLQueuedThread::getPending()
{
- S32 res;
+ size_t res;
lockData();
res = mRequestQueue.size();
unlockData();
@@ -399,7 +399,7 @@ bool LLQueuedThread::check()
//============================================================================
// Runs on its OWN thread
-S32 LLQueuedThread::processNextRequest()
+size_t LLQueuedThread::processNextRequest()
{
QueuedRequest *req;
// Get next request from pool
@@ -473,8 +473,7 @@ S32 LLQueuedThread::processNextRequest()
LLTrace::get_thread_recorder()->pushToParent();
}
- S32 pending = getPending();
- return pending;
+ return getPending();
}
// virtual
@@ -511,7 +510,7 @@ void LLQueuedThread::run()
threadedUpdate();
- int pending_work = processNextRequest();
+ auto pending_work = processNextRequest();
if (pending_work == 0)
{
diff --git a/indra/llcommon/llqueuedthread.h b/indra/llcommon/llqueuedthread.h
index 5d3f873646..90fce3dc5d 100644
--- a/indra/llcommon/llqueuedthread.h
+++ b/indra/llcommon/llqueuedthread.h
@@ -167,19 +167,19 @@ private:
protected:
handle_t generateHandle();
bool addRequest(QueuedRequest* req);
- S32 processNextRequest(void);
+ size_t processNextRequest(void);
void incQueue();
public:
bool waitForResult(handle_t handle, bool auto_complete = true);
- virtual S32 update(F32 max_time_ms);
- S32 updateQueue(F32 max_time_ms);
-
+ virtual size_t update(F32 max_time_ms);
+ size_t updateQueue(F32 max_time_ms);
+
void waitOnPending();
void printQueueStats();
- virtual S32 getPending();
+ virtual size_t getPending();
bool getThreaded() { return mThreaded ? true : false; }
// Request accessors
diff --git a/indra/llcommon/llrefcount.cpp b/indra/llcommon/llrefcount.cpp
index 5cbd346411..6852b5536a 100644
--- a/indra/llcommon/llrefcount.cpp
+++ b/indra/llcommon/llrefcount.cpp
@@ -30,7 +30,7 @@
#include "llerror.h"
// maximum reference count before sounding memory leak alarm
-const S32 gMaxRefCount = 65536;
+const S32 gMaxRefCount = S32_MAX;
LLRefCount::LLRefCount(const LLRefCount& other)
: mRef(0)
diff --git a/indra/llcommon/llregistry.h b/indra/llcommon/llregistry.h
index 750fe9fdc8..e272d7a9b8 100644
--- a/indra/llcommon/llregistry.h
+++ b/indra/llcommon/llregistry.h
@@ -141,11 +141,9 @@ public:
ptr_value_t getValue(ref_const_key_t key)
{
- for(scope_list_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
+ for(Registrar* scope : mActiveScopes)
{
- ptr_value_t valuep = (*it)->getValue(key);
+ ptr_value_t valuep = scope->getValue(key);
if (valuep != NULL) return valuep;
}
return mDefaultRegistrar.getValue(key);
@@ -153,11 +151,9 @@ public:
ptr_const_value_t getValue(ref_const_key_t key) const
{
- for(scope_list_const_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
+ for(const Registrar* scope : mActiveScopes)
{
- ptr_value_t valuep = (*it)->getValue(key);
+ ptr_const_value_t valuep = scope->getValue(key);
if (valuep != NULL) return valuep;
}
return mDefaultRegistrar.getValue(key);
@@ -165,11 +161,9 @@ public:
bool exists(ref_const_key_t key) const
{
- for(scope_list_const_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
+ for(const Registrar* scope : mActiveScopes)
{
- if ((*it)->exists(key)) return true;
+ if (scope->exists(key)) return true;
}
return mDefaultRegistrar.exists(key);
@@ -177,11 +171,9 @@ public:
bool empty() const
{
- for(scope_list_const_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
+ for(const Registrar* scope : mActiveScopes)
{
- if (!(*it)->empty()) return false;
+ if (!scope->empty()) return false;
}
return mDefaultRegistrar.empty();
diff --git a/indra/llcommon/llrun.cpp b/indra/llcommon/llrun.cpp
index f5d3f302fa..a3b3fccf4b 100644
--- a/indra/llcommon/llrun.cpp
+++ b/indra/llcommon/llrun.cpp
@@ -47,7 +47,7 @@ LLRunner::~LLRunner()
mRunEvery.clear();
}
-S32 LLRunner::run()
+size_t LLRunner::run()
{
// We collect all of the runnables which should be run. Since the
// runnables are allowed to adjust the run list, we need to copy
diff --git a/indra/llcommon/llrun.h b/indra/llcommon/llrun.h
index a117405366..d610f86234 100644
--- a/indra/llcommon/llrun.h
+++ b/indra/llcommon/llrun.h
@@ -85,7 +85,7 @@ public:
*
* @return Returns the number of runnables run.
*/
- S32 run();
+ size_t run();
/**
* @brief Add a runnable to the run list.
diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp
index 807b3d13f8..590915e9d2 100644
--- a/indra/llcommon/llsd.cpp
+++ b/indra/llcommon/llsd.cpp
@@ -36,6 +36,18 @@
#include "llsdserialize.h"
#include "stringize.h"
+#include <limits>
+
+// Defend against a caller forcibly passing a negative number into an unsigned
+// size_t index param
+inline
+bool was_negative(size_t i)
+{
+ return (i > std::numeric_limits<int>::max());
+}
+#define NEGATIVE_EXIT(i) if (was_negative(i)) return
+#define NEGATIVE_RETURN(i, result) NEGATIVE_EXIT(i) (result)
+
#ifndef LL_RELEASE_FOR_DOWNLOAD
#define NAME_UNNAMED_NAMESPACE
#endif
@@ -136,10 +148,10 @@ public:
virtual void erase(const String&) { }
virtual const LLSD& ref(const String&) const{ return undef(); }
- virtual int size() const { return 0; }
- virtual LLSD get(Integer) const { return LLSD(); }
- virtual void erase(Integer) { }
- virtual const LLSD& ref(Integer) const { return undef(); }
+ virtual size_t size() const { return 0; }
+ virtual LLSD get(size_t) const { return LLSD(); }
+ virtual void erase(size_t) { }
+ virtual const LLSD& ref(size_t) const { return undef(); }
virtual LLSD::map_const_iterator beginMap() const { return endMap(); }
virtual LLSD::map_const_iterator endMap() const { static const std::map<String, LLSD> empty; return empty.end(); }
@@ -272,7 +284,7 @@ namespace
virtual LLSD::UUID asUUID() const { return LLUUID(mValue); }
virtual LLSD::Date asDate() const { return LLDate(mValue); }
virtual LLSD::URI asURI() const { return LLURI(mValue); }
- virtual int size() const { return mValue.size(); }
+ virtual size_t size() const { return mValue.size(); }
virtual const LLSD::String& asStringRef() const { return mValue; }
};
@@ -377,9 +389,9 @@ namespace
virtual bool has(const LLSD::String&) const;
- using LLSD::Impl::get; // Unhiding get(LLSD::Integer)
- using LLSD::Impl::erase; // Unhiding erase(LLSD::Integer)
- using LLSD::Impl::ref; // Unhiding ref(LLSD::Integer)
+ using LLSD::Impl::get; // Unhiding get(size_t)
+ using LLSD::Impl::erase; // Unhiding erase(size_t)
+ using LLSD::Impl::ref; // Unhiding ref(size_t)
virtual LLSD get(const LLSD::String&) const;
virtual LLSD getKeys() const;
void insert(const LLSD::String& k, const LLSD& v);
@@ -387,7 +399,7 @@ namespace
LLSD& ref(const LLSD::String&);
virtual const LLSD& ref(const LLSD::String&) const;
- virtual int size() const { return mData.size(); }
+ virtual size_t size() const { return mData.size(); }
LLSD::map_iterator beginMap() { return mData.begin(); }
LLSD::map_iterator endMap() { return mData.end(); }
@@ -518,14 +530,14 @@ namespace
using LLSD::Impl::get; // Unhiding get(LLSD::String)
using LLSD::Impl::erase; // Unhiding erase(LLSD::String)
using LLSD::Impl::ref; // Unhiding ref(LLSD::String)
- virtual int size() const;
- virtual LLSD get(LLSD::Integer) const;
- void set(LLSD::Integer, const LLSD&);
- void insert(LLSD::Integer, const LLSD&);
+ virtual size_t size() const;
+ virtual LLSD get(size_t) const;
+ void set(size_t, const LLSD&);
+ void insert(size_t, const LLSD&);
LLSD& append(const LLSD&);
- virtual void erase(LLSD::Integer);
- LLSD& ref(LLSD::Integer);
- virtual const LLSD& ref(LLSD::Integer) const;
+ virtual void erase(size_t);
+ LLSD& ref(size_t);
+ virtual const LLSD& ref(size_t) const;
LLSD::array_iterator beginArray() { return mData.begin(); }
LLSD::array_iterator endArray() { return mData.end(); }
@@ -550,85 +562,82 @@ namespace
return *this;
}
}
-
- int ImplArray::size() const { return mData.size(); }
-
- LLSD ImplArray::get(LLSD::Integer i) const
+
+ size_t ImplArray::size() const { return mData.size(); }
+
+ LLSD ImplArray::get(size_t i) const
{
- if (i < 0) { return LLSD(); }
+ NEGATIVE_RETURN(i, LLSD());
DataVector::size_type index = i;
-
+
return (index < mData.size()) ? mData[index] : LLSD();
}
-
- void ImplArray::set(LLSD::Integer i, const LLSD& v)
+
+ void ImplArray::set(size_t i, const LLSD& v)
{
- if (i < 0) { return; }
+ NEGATIVE_EXIT(i);
DataVector::size_type index = i;
-
+
if (index >= mData.size())
{
mData.resize(index + 1);
}
-
+
mData[index] = v;
}
-
- void ImplArray::insert(LLSD::Integer i, const LLSD& v)
+
+ void ImplArray::insert(size_t i, const LLSD& v)
{
- if (i < 0)
- {
- return;
- }
+ NEGATIVE_EXIT(i);
DataVector::size_type index = i;
-
+
if (index >= mData.size()) // tbd - sanity check limit for index ?
{
mData.resize(index + 1);
}
-
+
mData.insert(mData.begin() + index, v);
}
-
+
LLSD& ImplArray::append(const LLSD& v)
{
mData.push_back(v);
return mData.back();
}
-
- void ImplArray::erase(LLSD::Integer i)
+
+ void ImplArray::erase(size_t i)
{
- if (i < 0) { return; }
+ NEGATIVE_EXIT(i);
DataVector::size_type index = i;
-
+
if (index < mData.size())
{
mData.erase(mData.begin() + index);
}
}
-
- LLSD& ImplArray::ref(LLSD::Integer i)
+
+ LLSD& ImplArray::ref(size_t i)
{
- DataVector::size_type index = i >= 0 ? i : 0;
-
+ DataVector::size_type index = was_negative(i)? 0 : i;
+
if (index >= mData.size())
{
- mData.resize(i + 1);
+ mData.resize(index + 1);
}
-
+
return mData[index];
}
- const LLSD& ImplArray::ref(LLSD::Integer i) const
+ const LLSD& ImplArray::ref(size_t i) const
{
- if (i < 0) { return undef(); }
+ NEGATIVE_RETURN(i, undef());
DataVector::size_type index = i;
-
+
if (index >= mData.size())
{
return undef();
}
-
+
return mData[index];
}
@@ -841,9 +850,6 @@ LLSD::LLSD(const Date& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
LLSD::LLSD(const URI& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
LLSD::LLSD(const Binary& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
-// Convenience Constructors
-LLSD::LLSD(F32 v) : impl(0) { ALLOC_LLSD_OBJECT; assign((Real)v); }
-
// Scalar Assignment
void LLSD::assign(Boolean v) { safe(impl).assign(impl, v); }
void LLSD::assign(Integer v) { safe(impl).assign(impl, v); }
@@ -912,7 +918,7 @@ LLSD LLSD::emptyArray()
return v;
}
-int LLSD::size() const { return safe(impl).size(); }
+size_t LLSD::size() const { return safe(impl).size(); }
LLSD LLSD::get(Integer i) const { return safe(impl).get(i); }
void LLSD::set(Integer i, const LLSD& v){ makeArray(impl).set(i, v); }
@@ -926,12 +932,12 @@ LLSD& LLSD::with(Integer i, const LLSD& v)
LLSD& LLSD::append(const LLSD& v) { return makeArray(impl).append(v); }
void LLSD::erase(Integer i) { makeArray(impl).erase(i); }
-LLSD& LLSD::operator[](Integer i)
+LLSD& LLSD::operator[](size_t i)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_LLSD;
return makeArray(impl).ref(i);
}
-const LLSD& LLSD::operator[](Integer i) const
+const LLSD& LLSD::operator[](size_t i) const
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_LLSD;
return safe(impl).ref(i);
@@ -956,7 +962,7 @@ static const char *llsd_dump(const LLSD &llsd, bool useXMLFormat)
out << LLSDNotationStreamer(llsd);
out_string = out.str();
}
- int len = out_string.length();
+ auto len = out_string.length();
sStorage = new char[len + 1];
memcpy(sStorage, out_string.c_str(), len);
sStorage[len] = '\0';
diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h
index 24cb9bbce1..cdb9a7ed8a 100644
--- a/indra/llcommon/llsd.h
+++ b/indra/llcommon/llsd.h
@@ -192,7 +192,17 @@ public:
/** @name Convenience Constructors */
//@{
- LLSD(F32); // F32 -> Real
+ // support construction from size_t et al.
+ template <typename VALUE,
+ typename std::enable_if<std::is_integral<VALUE>::value &&
+ ! std::is_same<VALUE, Boolean>::value,
+ bool>::type = true>
+ LLSD(VALUE v): LLSD(Integer(narrow(v))) {}
+ // support construction from F32 et al.
+ template <typename VALUE,
+ typename std::enable_if<std::is_floating_point<VALUE>::value,
+ bool>::type = true>
+ LLSD(VALUE v): LLSD(Real(narrow(v))) {}
//@}
/** @name Scalar Assignment */
@@ -275,7 +285,7 @@ public:
//@{
LLSD(const char*);
void assign(const char*);
- LLSD& operator=(const char* v) { assign(v); return *this; }
+ LLSD& operator=(const char* v) { assign(v); return *this; }
//@}
/** @name Map Values */
@@ -313,14 +323,24 @@ public:
LLSD& append(const LLSD&);
void erase(Integer);
LLSD& with(Integer, const LLSD&);
-
- const LLSD& operator[](Integer) const;
- LLSD& operator[](Integer);
+
+ // accept size_t so we can index relative to size()
+ const LLSD& operator[](size_t) const;
+ LLSD& operator[](size_t);
+ // template overloads to support int literals, U32 et al.
+ template <typename IDX,
+ typename std::enable_if<std::is_convertible<IDX, size_t>::value,
+ bool>::type = true>
+ const LLSD& operator[](IDX i) const { return (*this)[size_t(i)]; }
+ template <typename IDX,
+ typename std::enable_if<std::is_convertible<IDX, size_t>::value,
+ bool>::type = true>
+ LLSD& operator[](IDX i) { return (*this)[size_t(i)]; }
//@}
/** @name Iterators */
//@{
- int size() const;
+ size_t size() const;
typedef std::map<String, LLSD>::iterator map_iterator;
typedef std::map<String, LLSD>::const_iterator map_const_iterator;
@@ -421,42 +441,42 @@ public:
static std::string typeString(Type type); // Return human-readable type as a string
};
-struct llsd_select_bool : public std::unary_function<LLSD, LLSD::Boolean>
+struct llsd_select_bool
{
LLSD::Boolean operator()(const LLSD& sd) const
{
return sd.asBoolean();
}
};
-struct llsd_select_integer : public std::unary_function<LLSD, LLSD::Integer>
+struct llsd_select_integer
{
LLSD::Integer operator()(const LLSD& sd) const
{
return sd.asInteger();
}
};
-struct llsd_select_real : public std::unary_function<LLSD, LLSD::Real>
+struct llsd_select_real
{
LLSD::Real operator()(const LLSD& sd) const
{
return sd.asReal();
}
};
-struct llsd_select_float : public std::unary_function<LLSD, F32>
+struct llsd_select_float
{
F32 operator()(const LLSD& sd) const
{
return (F32)sd.asReal();
}
};
-struct llsd_select_uuid : public std::unary_function<LLSD, LLSD::UUID>
+struct llsd_select_uuid
{
LLSD::UUID operator()(const LLSD& sd) const
{
return sd.asUUID();
}
};
-struct llsd_select_string : public std::unary_function<LLSD, LLSD::String>
+struct llsd_select_string
{
LLSD::String operator()(const LLSD& sd) const
{
diff --git a/indra/llcommon/llsdjson.h b/indra/llcommon/llsdjson.h
index 2be7112404..e56cf03b45 100644
--- a/indra/llcommon/llsdjson.h
+++ b/indra/llcommon/llsdjson.h
@@ -34,7 +34,7 @@
#include "stdtypes.h"
#include "llsd.h"
-#include "value.h"
+#include "json/value.h"
/// Convert a parsed JSON structure into LLSD maintaining member names and
/// array indexes.
diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp
index af4ccf25fd..30f49b27ea 100644
--- a/indra/llcommon/llsdparam.cpp
+++ b/indra/llcommon/llsdparam.cpp
@@ -113,11 +113,9 @@ void LLParamSDParser::writeSDImpl(LLSD& sd, const LLInitParam::BaseBlock& block,
/*virtual*/ std::string LLParamSDParser::getCurrentElementName()
{
std::string full_name = "sd";
- for (name_stack_t::iterator it = mNameStack.begin();
- it != mNameStack.end();
- ++it)
+ for (name_stack_t::value_type& stack_pair : mNameStack)
{
- full_name += llformat("[%s]", it->first.c_str());
+ full_name += llformat("[%s]", stack_pair.first.c_str());
}
return full_name;
diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp
index 022a5d4659..b7e316da10 100644
--- a/indra/llcommon/llsdserialize.cpp
+++ b/indra/llcommon/llsdserialize.cpp
@@ -34,10 +34,13 @@
#include <iostream>
#include "apr_base64.h"
+#include <boost/iostreams/device/array.hpp>
+#include <boost/iostreams/stream.hpp>
+
#ifdef LL_USESYSTEMLIBS
# include <zlib.h>
#else
-# include "zlib/zlib.h" // for davep's dirty little zip functions
+# include "zlib-ng/zlib.h" // for davep's dirty little zip functions
#endif
#if !LL_WINDOWS
@@ -50,7 +53,7 @@
#include "lluri.h"
// File constants
-static const int MAX_HDR_LEN = 20;
+static const size_t MAX_HDR_LEN = 20;
static const S32 UNZIP_LLSD_MAX_DEPTH = 96;
static const char LEGACY_NON_HEADER[] = "<llsd>";
const std::string LLSD_BINARY_HEADER("LLSD/Binary");
@@ -99,7 +102,7 @@ void LLSDSerialize::serialize(const LLSD& sd, std::ostream& str, ELLSD_Serialize
}
// static
-bool LLSDSerialize::deserialize(LLSD& sd, std::istream& str, S32 max_bytes)
+bool LLSDSerialize::deserialize(LLSD& sd, std::istream& str, llssize max_bytes)
{
LLPointer<LLSDParser> p = NULL;
char hdr_buf[MAX_HDR_LEN + 1] = ""; /* Flawfinder: ignore */
@@ -252,7 +255,7 @@ F64 ll_ntohd(F64 netdouble)
* @return Returns number of bytes read off of the stream. Returns
* PARSE_FAILURE (-1) on failure.
*/
-int deserialize_string(std::istream& istr, std::string& value, S32 max_bytes);
+llssize deserialize_string(std::istream& istr, std::string& value, llssize max_bytes);
/**
* @brief Parse a delimited string.
@@ -263,7 +266,7 @@ int deserialize_string(std::istream& istr, std::string& value, S32 max_bytes);
* @return Returns number of bytes read off of the stream. Returns
* PARSE_FAILURE (-1) on failure.
*/
-int deserialize_string_delim(std::istream& istr, std::string& value, char d);
+llssize deserialize_string_delim(std::istream& istr, std::string& value, char d);
/**
* @brief Read a raw string off the stream.
@@ -277,10 +280,10 @@ int deserialize_string_delim(std::istream& istr, std::string& value, char d);
* @return Returns number of bytes read off of the stream. Returns
* PARSE_FAILURE (-1) on failure.
*/
-int deserialize_string_raw(
+llssize deserialize_string_raw(
std::istream& istr,
std::string& value,
- S32 max_bytes);
+ llssize max_bytes);
/**
* @brief helper method for dealing with the different notation boolean format.
@@ -292,7 +295,7 @@ int deserialize_string_raw(
* @return Returns number of bytes read off of the stream. Returns
* PARSE_FAILURE (-1) on failure.
*/
-int deserialize_boolean(
+llssize deserialize_boolean(
std::istream& istr,
LLSD& data,
const std::string& compare,
@@ -329,7 +332,7 @@ LLSDParser::LLSDParser()
LLSDParser::~LLSDParser()
{ }
-S32 LLSDParser::parse(std::istream& istr, LLSD& data, S32 max_bytes, S32 max_depth)
+S32 LLSDParser::parse(std::istream& istr, LLSD& data, llssize max_bytes, S32 max_depth)
{
mCheckLimits = (LLSDSerialize::SIZE_UNLIMITED == max_bytes) ? false : true;
mMaxBytesLeft = max_bytes;
@@ -359,7 +362,7 @@ std::istream& LLSDParser::get(
char delim) const
{
istr.get(s, n, delim);
- if(mCheckLimits) mMaxBytesLeft -= (int)istr.gcount();
+ if(mCheckLimits) mMaxBytesLeft -= istr.gcount();
return istr;
}
@@ -369,7 +372,7 @@ std::istream& LLSDParser::get(
char delim) const
{
istr.get(sb, delim);
- if(mCheckLimits) mMaxBytesLeft -= (int)istr.gcount();
+ if(mCheckLimits) mMaxBytesLeft -= istr.gcount();
return istr;
}
@@ -393,11 +396,11 @@ std::istream& LLSDParser::read(
std::streamsize n) const
{
istr.read(s, n);
- if(mCheckLimits) mMaxBytesLeft -= (int)istr.gcount();
+ if(mCheckLimits) mMaxBytesLeft -= istr.gcount();
return istr;
}
-void LLSDParser::account(S32 bytes) const
+void LLSDParser::account(llssize bytes) const
{
if(mCheckLimits) mMaxBytesLeft -= bytes;
}
@@ -502,7 +505,7 @@ S32 LLSDNotationParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) c
c = istr.peek();
if(isalpha(c))
{
- int cnt = deserialize_boolean(
+ auto cnt = deserialize_boolean(
istr,
data,
NOTATION_FALSE_SERIAL,
@@ -532,7 +535,7 @@ S32 LLSDNotationParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) c
c = istr.peek();
if(isalpha(c))
{
- int cnt = deserialize_boolean(istr,data,NOTATION_TRUE_SERIAL,true);
+ auto cnt = deserialize_boolean(istr,data,NOTATION_TRUE_SERIAL,true);
if(PARSE_FAILURE == cnt) parse_count = cnt;
else account(cnt);
}
@@ -608,7 +611,7 @@ S32 LLSDNotationParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) c
c = get(istr); // pop the 'l'
c = get(istr); // pop the delimiter
std::string str;
- int cnt = deserialize_string_delim(istr, str, c);
+ auto cnt = deserialize_string_delim(istr, str, c);
if(PARSE_FAILURE == cnt)
{
parse_count = PARSE_FAILURE;
@@ -631,7 +634,7 @@ S32 LLSDNotationParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) c
c = get(istr); // pop the 'd'
c = get(istr); // pop the delimiter
std::string str;
- int cnt = deserialize_string_delim(istr, str, c);
+ auto cnt = deserialize_string_delim(istr, str, c);
if(PARSE_FAILURE == cnt)
{
parse_count = PARSE_FAILURE;
@@ -663,7 +666,7 @@ S32 LLSDNotationParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) c
default:
parse_count = PARSE_FAILURE;
- LL_INFOS() << "Unrecognized character while parsing: int(" << (int)c
+ LL_INFOS() << "Unrecognized character while parsing: int(" << int(c)
<< ")" << LL_ENDL;
break;
}
@@ -694,7 +697,7 @@ S32 LLSDNotationParser::parseMap(std::istream& istr, LLSD& map, S32 max_depth) c
{
putback(istr, c);
found_name = true;
- int count = deserialize_string(istr, name, mMaxBytesLeft);
+ auto count = deserialize_string(istr, name, mMaxBytesLeft);
if(PARSE_FAILURE == count) return PARSE_FAILURE;
account(count);
}
@@ -776,7 +779,7 @@ S32 LLSDNotationParser::parseArray(std::istream& istr, LLSD& array, S32 max_dept
bool LLSDNotationParser::parseString(std::istream& istr, LLSD& data) const
{
std::string value;
- int count = deserialize_string(istr, value, mMaxBytesLeft);
+ auto count = deserialize_string(istr, value, mMaxBytesLeft);
if(PARSE_FAILURE == count) return false;
account(count);
data = value;
@@ -803,13 +806,13 @@ bool LLSDNotationParser::parseBinary(std::istream& istr, LLSD& data) const
{
// We probably have a valid raw binary stream. determine
// the size, and read it.
- S32 len = strtol(buf + 2, NULL, 0);
+ auto len = strtol(buf + 2, NULL, 0);
if(mCheckLimits && (len > mMaxBytesLeft)) return false;
std::vector<U8> value;
if(len)
{
value.resize(len);
- account((int)fullread(istr, (char *)&value[0], len));
+ account(fullread(istr, (char *)&value[0], len));
}
c = get(istr); // strip off the trailing double-quote
data = value;
@@ -1006,7 +1009,7 @@ S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) con
case '"':
{
std::string value;
- int cnt = deserialize_string_delim(istr, value, c);
+ auto cnt = deserialize_string_delim(istr, value, c);
if(PARSE_FAILURE == cnt)
{
parse_count = PARSE_FAILURE;
@@ -1093,7 +1096,7 @@ S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) con
if(size > 0)
{
value.resize(size);
- account((int)fullread(istr, (char*)&value[0], size));
+ account(fullread(istr, (char*)&value[0], size));
}
data = value;
}
@@ -1107,7 +1110,7 @@ S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data, S32 max_depth) con
default:
parse_count = PARSE_FAILURE;
- LL_INFOS() << "Unrecognized character while parsing: int(" << (int)c
+ LL_INFOS() << "Unrecognized character while parsing: int(" << int(c)
<< ")" << LL_ENDL;
break;
}
@@ -1141,7 +1144,7 @@ S32 LLSDBinaryParser::parseMap(std::istream& istr, LLSD& map, S32 max_depth) con
case '\'':
case '"':
{
- int cnt = deserialize_string_delim(istr, name, c);
+ auto cnt = deserialize_string_delim(istr, name, c);
if(PARSE_FAILURE == cnt) return PARSE_FAILURE;
account(cnt);
break;
@@ -1225,7 +1228,7 @@ bool LLSDBinaryParser::parseString(
if(size)
{
buf.resize(size);
- account((int)fullread(istr, &buf[0], size));
+ account(fullread(istr, &buf[0], size));
value.assign(buf.begin(), buf.end());
}
return true;
@@ -1429,7 +1432,7 @@ S32 LLSDNotationFormatter::format_impl(const LLSD& data, std::ostream& ostr,
ostr << std::uppercase;
auto oldfill(ostr.fill('0'));
auto oldwidth(ostr.width());
- for (int i = 0; i < buffer.size(); i++)
+ for (size_t i = 0; i < buffer.size(); i++)
{
// have to restate setw() before every conversion
ostr << std::setw(2) << (int) buffer[i];
@@ -1592,7 +1595,7 @@ void LLSDBinaryFormatter::formatString(
/**
* local functions
*/
-int deserialize_string(std::istream& istr, std::string& value, S32 max_bytes)
+llssize deserialize_string(std::istream& istr, std::string& value, llssize max_bytes)
{
int c = istr.get();
if(istr.fail())
@@ -1602,7 +1605,7 @@ int deserialize_string(std::istream& istr, std::string& value, S32 max_bytes)
return LLSDParser::PARSE_FAILURE;
}
- int rv = LLSDParser::PARSE_FAILURE;
+ llssize rv = LLSDParser::PARSE_FAILURE;
switch(c)
{
case '\'':
@@ -1622,7 +1625,7 @@ int deserialize_string(std::istream& istr, std::string& value, S32 max_bytes)
return rv + 1; // account for the character grabbed at the top.
}
-int deserialize_string_delim(
+llssize deserialize_string_delim(
std::istream& istr,
std::string& value,
char delim)
@@ -1632,7 +1635,7 @@ int deserialize_string_delim(
bool found_hex = false;
bool found_digit = false;
U8 byte = 0;
- int count = 0;
+ llssize count = 0;
while (true)
{
@@ -1647,7 +1650,7 @@ int deserialize_string_delim(
}
char next_char = (char)next_byte; // Now that we know it's not EOF
-
+
if(found_escape)
{
// next character(s) is a special sequence.
@@ -1725,16 +1728,16 @@ int deserialize_string_delim(
return count;
}
-int deserialize_string_raw(
+llssize deserialize_string_raw(
std::istream& istr,
std::string& value,
- S32 max_bytes)
+ llssize max_bytes)
{
- int count = 0;
+ llssize count = 0;
const S32 BUF_LEN = 20;
char buf[BUF_LEN]; /* Flawfinder: ignore */
istr.get(buf, BUF_LEN - 1, ')');
- count += (int)istr.gcount();
+ count += istr.gcount();
int c = istr.get();
c = istr.get();
count += 2;
@@ -1743,13 +1746,13 @@ int deserialize_string_raw(
// We probably have a valid raw string. determine
// the size, and read it.
// *FIX: This is memory inefficient.
- S32 len = strtol(buf + 1, NULL, 0);
+ auto len = strtol(buf + 1, NULL, 0);
if((max_bytes>0)&&(len>max_bytes)) return LLSDParser::PARSE_FAILURE;
std::vector<char> buf;
if(len)
{
buf.resize(len);
- count += (int)fullread(istr, (char *)&buf[0], len);
+ count += fullread(istr, (char *)&buf[0], len);
value.assign(buf.begin(), buf.end());
}
c = istr.get();
@@ -2038,7 +2041,7 @@ void serialize_string(const std::string& value, std::ostream& str)
}
}
-int deserialize_boolean(
+llssize deserialize_boolean(
std::istream& istr,
LLSD& data,
const std::string& compare,
@@ -2055,7 +2058,7 @@ int deserialize_boolean(
// * set data to LLSD::null
// * return LLSDParser::PARSE_FAILURE (-1)
//
- int bytes_read = 0;
+ llssize bytes_read = 0;
std::string::size_type ii = 0;
char c = istr.peek();
while((++ii < compare.size())
@@ -2110,7 +2113,7 @@ std::string zip_llsd(LLSD& data)
U8 out[CHUNK];
- strm.avail_in = source.size();
+ strm.avail_in = narrow(source.size());
strm.next_in = (U8*) source.data();
U8* output = NULL;
@@ -2128,7 +2131,9 @@ std::string zip_llsd(LLSD& data)
{ //copy result into output
if (strm.avail_out >= CHUNK)
{
- free(output);
+ deflateEnd(&strm);
+ if(output)
+ free(output);
LL_WARNS() << "Failed to compress LLSD block." << LL_ENDL;
return std::string();
}
@@ -2151,7 +2156,9 @@ std::string zip_llsd(LLSD& data)
}
else
{
- free(output);
+ deflateEnd(&strm);
+ if(output)
+ free(output);
LL_WARNS() << "Failed to compress LLSD block." << LL_ENDL;
return std::string();
}
@@ -2162,7 +2169,8 @@ std::string zip_llsd(LLSD& data)
std::string result((char*) output, size);
deflateEnd(&strm);
- free(output);
+ if(output)
+ free(output);
return result;
}
@@ -2172,53 +2180,66 @@ std::string zip_llsd(LLSD& data)
// and deserializes from that copy using LLSDSerialize
LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is, S32 size)
{
+ std::unique_ptr<U8[]> in = std::unique_ptr<U8[]>(new(std::nothrow) U8[size]);
+ if (!in)
+ {
+ return ZR_MEM_ERROR;
+ }
+ is.read((char*) in.get(), size);
+
+ return unzip_llsd(data, in.get(), size);
+}
+
+LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, const U8* in, S32 size)
+{
U8* result = NULL;
U32 cur_size = 0;
z_stream strm;
- const U32 CHUNK = 65536;
+ constexpr U32 CHUNK = 1024 * 512;
- U8 *in = new(std::nothrow) U8[size];
- if (!in)
+ static thread_local std::unique_ptr<U8[]> out;
+ if (!out)
{
- return ZR_MEM_ERROR;
+ out = std::unique_ptr<U8[]>(new(std::nothrow) U8[CHUNK]);
}
- is.read((char*) in, size);
-
- U8 out[CHUNK];
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = size;
- strm.next_in = in;
+ strm.next_in = const_cast<U8*>(in);
S32 ret = inflateInit(&strm);
do
{
strm.avail_out = CHUNK;
- strm.next_out = out;
+ strm.next_out = out.get();
ret = inflate(&strm, Z_NO_FLUSH);
- if (ret == Z_STREAM_ERROR)
+ switch (ret)
+ {
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
{
inflateEnd(&strm);
free(result);
- delete [] in;
return ZR_DATA_ERROR;
}
-
- switch (ret)
+ case Z_STREAM_ERROR:
+ case Z_BUF_ERROR:
{
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR;
- case Z_DATA_ERROR:
+ inflateEnd(&strm);
+ free(result);
+ return ZR_BUFFER_ERROR;
+ }
+
case Z_MEM_ERROR:
+ {
inflateEnd(&strm);
free(result);
- delete [] in;
return ZR_MEM_ERROR;
- break;
+ }
}
U32 have = CHUNK-strm.avail_out;
@@ -2231,17 +2252,15 @@ LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is,
{
free(result);
}
- delete[] in;
return ZR_MEM_ERROR;
}
result = new_result;
- memcpy(result+cur_size, out, have);
+ memcpy(result+cur_size, out.get(), have);
cur_size += have;
- } while (ret == Z_OK);
+ } while (ret == Z_OK && ret != Z_STREAM_END);
inflateEnd(&strm);
- delete [] in;
if (ret != Z_STREAM_END)
{
@@ -2251,37 +2270,11 @@ LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is,
//result now points to the decompressed LLSD block
{
- std::istringstream istr;
- // Since we are using this for meshes, data we are dealing with tend to be large.
- // So string can potentially fail to allocate, make sure this won't cause problems
- try
- {
- std::string res_str((char*)result, cur_size);
+ char* result_ptr = strip_deprecated_header((char*)result, cur_size);
- std::string deprecated_header("<? LLSD/Binary ?>");
-
- if (res_str.substr(0, deprecated_header.size()) == deprecated_header)
- {
- res_str = res_str.substr(deprecated_header.size() + 1, cur_size);
- }
- cur_size = res_str.size();
-
- istr.str(res_str);
- }
-#ifdef LL_WINDOWS
- catch (std::length_error)
- {
- free(result);
- return ZR_SIZE_ERROR;
- }
-#endif
- catch (std::bad_alloc&)
- {
- free(result);
- return ZR_MEM_ERROR;
- }
-
- if (!LLSDSerialize::fromBinary(data, istr, cur_size, UNZIP_LLSD_MAX_DEPTH))
+ boost::iostreams::stream<boost::iostreams::array_source> istrm(result_ptr, cur_size);
+
+ if (!LLSDSerialize::fromBinary(data, istrm, cur_size, UNZIP_LLSD_MAX_DEPTH))
{
free(result);
return ZR_PARSE_ERROR;
@@ -2294,7 +2287,7 @@ LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is,
//This unzip function will only work with a gzip header and trailer - while the contents
//of the actual compressed data is the same for either format (gzip vs zlib ), the headers
//and trailers are different for the formats.
-U8* unzip_llsdNavMesh( bool& valid, unsigned int& outsize, std::istream& is, S32 size )
+U8* unzip_llsdNavMesh( bool& valid, size_t& outsize, std::istream& is, S32 size )
{
if (size == 0)
{
@@ -2395,4 +2388,22 @@ U8* unzip_llsdNavMesh( bool& valid, unsigned int& outsize, std::istream& is, S32
return result;
}
+char* strip_deprecated_header(char* in, U32& cur_size, U32* header_size)
+{
+ const char* deprecated_header = "<? LLSD/Binary ?>";
+ constexpr size_t deprecated_header_size = 17;
+
+ if (cur_size > deprecated_header_size
+ && memcmp(in, deprecated_header, deprecated_header_size) == 0)
+ {
+ in = in + deprecated_header_size;
+ cur_size = cur_size - deprecated_header_size;
+ if (header_size)
+ {
+ *header_size = deprecated_header_size + 1;
+ }
+ }
+
+ return in;
+}
diff --git a/indra/llcommon/llsdserialize.h b/indra/llcommon/llsdserialize.h
index d6079fd9fa..2f12c6d1ff 100644
--- a/indra/llcommon/llsdserialize.h
+++ b/indra/llcommon/llsdserialize.h
@@ -77,7 +77,7 @@ public:
* @return Returns the number of LLSD objects parsed into
* data. Returns PARSE_FAILURE (-1) on parse failure.
*/
- S32 parse(std::istream& istr, LLSD& data, S32 max_bytes, S32 max_depth = -1);
+ S32 parse(std::istream& istr, LLSD& data, llssize max_bytes, S32 max_depth = -1);
/** Like parse(), but uses a different call (istream.getline()) to read by lines
* This API is better suited for XML, where the parse cannot tell
@@ -194,7 +194,7 @@ protected:
* Conceptually const since it only modifies mutable members.
* @param bytes The number of bytes read.
*/
- void account(S32 bytes) const;
+ void account(llssize bytes) const;
protected:
/**
@@ -205,7 +205,7 @@ protected:
/**
* @brief The maximum number of bytes left to be parsed.
*/
- mutable S32 mMaxBytesLeft;
+ mutable llssize mMaxBytesLeft;
/**
* @brief Use line-based reading to get text
@@ -336,7 +336,7 @@ private:
class Impl;
Impl& impl;
- void parsePart(const char* buf, int len);
+ void parsePart(const char* buf, llssize len);
friend class LLSDSerialize;
};
@@ -756,7 +756,7 @@ public:
* @param max_bytes the maximum number of bytes to parse
* @return Returns true if the stream appears to contain valid data
*/
- static bool deserialize(LLSD& sd, std::istream& str, S32 max_bytes);
+ static bool deserialize(LLSD& sd, std::istream& str, llssize max_bytes);
/*
* Notation Methods
@@ -778,12 +778,12 @@ public:
LLSDFormatter::EFormatterOptions(LLSDFormatter::OPTIONS_PRETTY |
LLSDFormatter::OPTIONS_PRETTY_BINARY));
}
- static S32 fromNotation(LLSD& sd, std::istream& str, S32 max_bytes)
+ static S32 fromNotation(LLSD& sd, std::istream& str, llssize max_bytes)
{
LLPointer<LLSDNotationParser> p = new LLSDNotationParser;
return p->parse(str, sd, max_bytes);
}
- static LLSD fromNotation(std::istream& str, S32 max_bytes)
+ static LLSD fromNotation(std::istream& str, llssize max_bytes)
{
LLPointer<LLSDNotationParser> p = new LLSDNotationParser;
LLSD sd;
@@ -834,12 +834,12 @@ public:
LLPointer<LLSDBinaryFormatter> f = new LLSDBinaryFormatter;
return f->format(sd, str, LLSDFormatter::OPTIONS_NONE);
}
- static S32 fromBinary(LLSD& sd, std::istream& str, S32 max_bytes, S32 max_depth = -1)
+ static S32 fromBinary(LLSD& sd, std::istream& str, llssize max_bytes, S32 max_depth = -1)
{
LLPointer<LLSDBinaryParser> p = new LLSDBinaryParser;
return p->parse(str, sd, max_bytes, max_depth);
}
- static LLSD fromBinary(std::istream& str, S32 max_bytes, S32 max_depth = -1)
+ static LLSD fromBinary(std::istream& str, llssize max_bytes, S32 max_depth = -1)
{
LLPointer<LLSDBinaryParser> p = new LLSDBinaryParser;
LLSD sd;
@@ -858,14 +858,20 @@ public:
ZR_SIZE_ERROR,
ZR_DATA_ERROR,
ZR_PARSE_ERROR,
+ ZR_BUFFER_ERROR,
+ ZR_VERSION_ERROR
} EZipRresult;
// return OK or reason for failure
static EZipRresult unzip_llsd(LLSD& data, std::istream& is, S32 size);
+ static EZipRresult unzip_llsd(LLSD& data, const U8* in, S32 size);
};
//dirty little zip functions -- yell at davep
LL_COMMON_API std::string zip_llsd(LLSD& data);
-LL_COMMON_API U8* unzip_llsdNavMesh( bool& valid, unsigned int& outsize,std::istream& is, S32 size);
+LL_COMMON_API U8* unzip_llsdNavMesh( bool& valid, size_t& outsize,std::istream& is, S32 size);
+
+// returns a pointer to the array or past the array if the deprecated header exists
+LL_COMMON_API char* strip_deprecated_header(char* in, U32& cur_size, U32* header_size = nullptr);
#endif // LL_LLSDSERIALIZE_H
diff --git a/indra/llcommon/llsdserialize_xml.cpp b/indra/llcommon/llsdserialize_xml.cpp
index 0da824d694..ac128c9f86 100644
--- a/indra/llcommon/llsdserialize_xml.cpp
+++ b/indra/llcommon/llsdserialize_xml.cpp
@@ -196,12 +196,12 @@ S32 LLSDXMLFormatter::format_impl(const LLSD& data, std::ostream& ostr,
// *FIX: memory inefficient.
// *TODO: convert to use LLBase64
ostr << pre << "<binary encoding=\"base64\">";
- int b64_buffer_length = apr_base64_encode_len(buffer.size());
+ int b64_buffer_length = apr_base64_encode_len(narrow(buffer.size()));
char* b64_buffer = new char[b64_buffer_length];
b64_buffer_length = apr_base64_encode_binary(
b64_buffer,
&buffer[0],
- buffer.size());
+ narrow(buffer.size()));
ostr.write(b64_buffer, b64_buffer_length - 1);
delete[] b64_buffer;
ostr << "</binary>" << post;
@@ -260,7 +260,7 @@ public:
S32 parse(std::istream& input, LLSD& data);
S32 parseLines(std::istream& input, LLSD& data);
- void parsePart(const char *buf, int len);
+ void parsePart(const char *buf, llssize len);
void reset();
@@ -542,7 +542,7 @@ LLSDXMLParser::Impl::findAttribute(const XML_Char* name, const XML_Char** pairs)
return NULL;
}
-void LLSDXMLParser::Impl::parsePart(const char* buf, int len)
+void LLSDXMLParser::Impl::parsePart(const char* buf, llssize len)
{
if ( buf != NULL
&& len > 0 )
@@ -915,7 +915,7 @@ LLSDXMLParser::~LLSDXMLParser()
delete &impl;
}
-void LLSDXMLParser::parsePart(const char *buf, int len)
+void LLSDXMLParser::parsePart(const char *buf, llssize len)
{
impl.parsePart(buf, len);
}
diff --git a/indra/llcommon/llsdutil.cpp b/indra/llcommon/llsdutil.cpp
index 8e90d1e8b8..f70bee9903 100644
--- a/indra/llcommon/llsdutil.cpp
+++ b/indra/llcommon/llsdutil.cpp
@@ -148,10 +148,9 @@ LLSD ll_binary_from_string(const LLSD& sd)
std::vector<U8> binary_value;
std::string string_value = sd.asString();
- for (std::string::iterator iter = string_value.begin();
- iter != string_value.end(); ++iter)
+ for (const U8 c : string_value)
{
- binary_value.push_back(*iter);
+ binary_value.push_back(c);
}
binary_value.push_back('\0');
diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h
index 1321615805..372278c51a 100644
--- a/indra/llcommon/llsdutil.h
+++ b/indra/llcommon/llsdutil.h
@@ -191,75 +191,6 @@ LLSD& drill_ref( LLSD& blob, const LLSD& path);
}
-/*****************************************************************************
-* LLSDArray
-*****************************************************************************/
-/**
- * Construct an LLSD::Array inline, with implicit conversion to LLSD. Usage:
- *
- * @code
- * void somefunc(const LLSD&);
- * ...
- * somefunc(LLSDArray("text")(17)(3.14));
- * @endcode
- *
- * For completeness, LLSDArray() with no args constructs an empty array, so
- * <tt>LLSDArray()("text")(17)(3.14)</tt> produces an array equivalent to the
- * above. But for most purposes, LLSD() is already equivalent to an empty
- * array, and if you explicitly want an empty isArray(), there's
- * LLSD::emptyArray(). However, supporting a no-args LLSDArray() constructor
- * follows the principle of least astonishment.
- */
-class LLSDArray
-{
-public:
- LLSDArray():
- _data(LLSD::emptyArray())
- {}
-
- /**
- * Need an explicit copy constructor. Consider the following:
- *
- * @code
- * LLSD array_of_arrays(LLSDArray(LLSDArray(17)(34))
- * (LLSDArray("x")("y")));
- * @endcode
- *
- * The coder intends to construct [[17, 34], ["x", "y"]].
- *
- * With the compiler's implicit copy constructor, s/he gets instead
- * [17, 34, ["x", "y"]].
- *
- * The expression LLSDArray(17)(34) constructs an LLSDArray with those two
- * values. The reader assumes it should be converted to LLSD, as we always
- * want with LLSDArray, before passing it to the @em outer LLSDArray
- * constructor! This copy constructor makes that happen.
- */
- LLSDArray(const LLSDArray& inner):
- _data(LLSD::emptyArray())
- {
- _data.append(inner);
- }
-
- LLSDArray(const LLSD& value):
- _data(LLSD::emptyArray())
- {
- _data.append(value);
- }
-
- LLSDArray& operator()(const LLSD& value)
- {
- _data.append(value);
- return *this;
- }
-
- operator LLSD() const { return _data; }
- LLSD get() const { return _data; }
-
-private:
- LLSD _data;
-};
-
namespace llsd
{
diff --git a/indra/llcommon/llstl.h b/indra/llcommon/llstl.h
index a90c2c7e08..25131291f9 100644
--- a/indra/llcommon/llstl.h
+++ b/indra/llcommon/llstl.h
@@ -142,7 +142,7 @@ struct DeletePairedPointerArray
// llselect2nd<map_type::value_type>()));
template<typename T>
-struct DeletePointerFunctor : public std::unary_function<T*, bool>
+struct DeletePointerFunctor
{
bool operator()(T* ptr) const
{
@@ -153,7 +153,7 @@ struct DeletePointerFunctor : public std::unary_function<T*, bool>
// See notes about DeleteArray for why you should consider avoiding this.
template<typename T>
-struct DeleteArrayFunctor : public std::unary_function<T*, bool>
+struct DeleteArrayFunctor
{
bool operator()(T* ptr) const
{
@@ -395,16 +395,17 @@ OutputIter ll_transform_n(
// select... with the stl. Look up usage on the sgi website.
template <class _Pair>
-struct _LLSelect1st : public std::unary_function<_Pair, typename _Pair::first_type> {
- const typename _Pair::first_type& operator()(const _Pair& __x) const {
+struct _LLSelect1st
+{
+ const auto& operator()(const _Pair& __x) const {
return __x.first;
}
};
template <class _Pair>
-struct _LLSelect2nd : public std::unary_function<_Pair, typename _Pair::second_type>
+struct _LLSelect2nd
{
- const typename _Pair::second_type& operator()(const _Pair& __x) const {
+ const auto& operator()(const _Pair& __x) const {
return __x.second;
}
};
@@ -416,9 +417,7 @@ template <class _Pair> struct llselect2nd : public _LLSelect2nd<_Pair> {};
// compose... with the stl. Look up usage on the sgi website.
template <class _Operation1, class _Operation2>
-class ll_unary_compose :
- public std::unary_function<typename _Operation2::argument_type,
- typename _Operation1::result_type>
+class ll_unary_compose
{
protected:
_Operation1 __op1;
@@ -426,8 +425,9 @@ protected:
public:
ll_unary_compose(const _Operation1& __x, const _Operation2& __y)
: __op1(__x), __op2(__y) {}
- typename _Operation1::result_type
- operator()(const typename _Operation2::argument_type& __x) const {
+ template <typename _Op2Arg>
+ auto
+ operator()(const _Op2Arg& __x) const {
return __op1(__op2(__x));
}
};
@@ -441,8 +441,7 @@ llcompose1(const _Operation1& __op1, const _Operation2& __op2)
template <class _Operation1, class _Operation2, class _Operation3>
class ll_binary_compose
- : public std::unary_function<typename _Operation2::argument_type,
- typename _Operation1::result_type> {
+{
protected:
_Operation1 _M_op1;
_Operation2 _M_op2;
@@ -451,8 +450,9 @@ public:
ll_binary_compose(const _Operation1& __x, const _Operation2& __y,
const _Operation3& __z)
: _M_op1(__x), _M_op2(__y), _M_op3(__z) { }
- typename _Operation1::result_type
- operator()(const typename _Operation2::argument_type& __x) const {
+ template<typename OP2ARG>
+ auto
+ operator()(const OP2ARG& __x) const {
return _M_op1(_M_op2(__x), _M_op3(__x));
}
};
@@ -468,54 +468,51 @@ llcompose2(const _Operation1& __op1, const _Operation2& __op2,
// helpers to deal with the fact that MSDev does not package
// bind... with the stl. Again, this is from sgi.
-template <class _Operation>
-class llbinder1st :
- public std::unary_function<typename _Operation::second_argument_type,
- typename _Operation::result_type> {
+template <class _Operation, typename _Arg1>
+class llbinder1st
+{
protected:
_Operation op;
- typename _Operation::first_argument_type value;
+ _Arg1 value;
public:
- llbinder1st(const _Operation& __x,
- const typename _Operation::first_argument_type& __y)
+ llbinder1st(const _Operation& __x, const _Arg1& __y)
: op(__x), value(__y) {}
- typename _Operation::result_type
- operator()(const typename _Operation::second_argument_type& __x) const {
- return op(value, __x);
- }
+ template <typename _Arg2>
+ auto
+ operator()(const _Arg2& __x) const {
+ return op(value, __x);
+ }
};
template <class _Operation, class _Tp>
-inline llbinder1st<_Operation>
+inline auto
llbind1st(const _Operation& __oper, const _Tp& __x)
{
- typedef typename _Operation::first_argument_type _Arg1_type;
- return llbinder1st<_Operation>(__oper, _Arg1_type(__x));
+ return llbinder1st<_Operation, _Tp>(__oper, __x);
}
-template <class _Operation>
+template <class _Operation, typename _Arg2>
class llbinder2nd
- : public std::unary_function<typename _Operation::first_argument_type,
- typename _Operation::result_type> {
+{
protected:
_Operation op;
- typename _Operation::second_argument_type value;
+ _Arg2 value;
public:
llbinder2nd(const _Operation& __x,
- const typename _Operation::second_argument_type& __y)
+ const _Arg2& __y)
: op(__x), value(__y) {}
- typename _Operation::result_type
- operator()(const typename _Operation::first_argument_type& __x) const {
+ template <typename _Arg1>
+ auto
+ operator()(const _Arg1& __x) const {
return op(__x, value);
}
};
template <class _Operation, class _Tp>
-inline llbinder2nd<_Operation>
+inline auto
llbind2nd(const _Operation& __oper, const _Tp& __x)
{
- typedef typename _Operation::second_argument_type _Arg2_type;
- return llbinder2nd<_Operation>(__oper, _Arg2_type(__x));
+ return llbinder2nd<_Operation, _Tp>(__oper, __x);
}
/**
@@ -548,8 +545,7 @@ bool before(const std::type_info* lhs, const std::type_info* rhs)
namespace std
{
template <>
- struct less<const std::type_info*>:
- public std::binary_function<const std::type_info*, const std::type_info*, bool>
+ struct less<const std::type_info*>
{
bool operator()(const std::type_info* lhs, const std::type_info* rhs) const
{
@@ -558,8 +554,7 @@ namespace std
};
template <>
- struct less<std::type_info*>:
- public std::binary_function<std::type_info*, std::type_info*, bool>
+ struct less<std::type_info*>
{
bool operator()(std::type_info* lhs, std::type_info* rhs) const
{
diff --git a/indra/llcommon/llstreamtools.cpp b/indra/llcommon/llstreamtools.cpp
index d7a6f47932..1ff15fcf89 100644
--- a/indra/llcommon/llstreamtools.cpp
+++ b/indra/llcommon/llstreamtools.cpp
@@ -118,7 +118,7 @@ bool skip_to_next_word(std::istream& input_stream)
bool skip_to_end_of_next_keyword(const char* keyword, std::istream& input_stream)
{
- int key_length = strlen(keyword); /*Flawfinder: ignore*/
+ auto key_length = strlen(keyword); /*Flawfinder: ignore*/
if (0 == key_length)
{
return false;
@@ -315,7 +315,7 @@ bool unget_line(const std::string& line, std::istream& input_stream)
// returns true if removed last char
bool remove_last_char(char c, std::string& line)
{
- int line_size = line.size();
+ auto line_size = line.size();
if (line_size > 1
&& c == line[line_size - 1])
{
@@ -330,9 +330,8 @@ bool remove_last_char(char c, std::string& line)
// "\\n" ---> '\n' (backslash n becomes carriage return)
void unescape_string(std::string& line)
{
- int line_size = line.size();
- int index = 0;
- while (index < line_size - 1)
+ auto line_size = line.size();
+ for (size_t index = 0; line_size >= 1 && index < line_size - 1; ++index)
{
if ('\\' == line[index])
{
@@ -347,7 +346,6 @@ void unescape_string(std::string& line)
line_size--;
}
}
- index++;
}
}
@@ -356,9 +354,8 @@ void unescape_string(std::string& line)
// '\n' ---> "\\n" (carriage return becomes backslash n)
void escape_string(std::string& line)
{
- int line_size = line.size();
- int index = 0;
- while (index < line_size)
+ auto line_size = line.size();
+ for (size_t index = 0; index < line_size; ++index)
{
if ('\\' == line[index])
{
@@ -372,31 +369,27 @@ void escape_string(std::string& line)
line_size++;
index++;
}
- index++;
}
}
// removes '\n' characters
void replace_newlines_with_whitespace(std::string& line)
{
- int line_size = line.size();
- int index = 0;
- while (index < line_size)
+ auto line_size = line.size();
+ for (size_t index = 0; index < line_size; ++index)
{
if ('\n' == line[index])
{
line.replace(index, 1, " ");
}
- index++;
}
}
// erases any double-quote characters in 'line'
void remove_double_quotes(std::string& line)
{
- int index = 0;
- int line_size = line.size();
- while (index < line_size)
+ auto line_size = line.size();
+ for (size_t index = 0; index < line_size; )
{
if ('"' == line[index])
{
@@ -424,22 +417,21 @@ void get_keyword_and_value(std::string& keyword,
const std::string& line)
{
// skip initial whitespace
- int line_size = line.size();
- int line_index = 0;
+ auto line_size = line.size();
+ size_t line_index = 0;
char c;
- while (line_index < line_size)
+ for ( ; line_index < line_size; ++line_index)
{
c = line[line_index];
if (!LLStringOps::isSpace(c))
{
break;
}
- line_index++;
}
// get the keyword
keyword.clear();
- while (line_index < line_size)
+ for ( ; line_index < line_size; ++line_index)
{
c = line[line_index];
if (LLStringOps::isSpace(c) || '\r' == c || '\n' == c)
@@ -447,7 +439,6 @@ void get_keyword_and_value(std::string& keyword,
break;
}
keyword += c;
- line_index++;
}
// get the value
@@ -465,7 +456,7 @@ void get_keyword_and_value(std::string& keyword,
line_index++;
}
- while (line_index < line_size)
+ for ( ; line_index < line_size; ++line_index)
{
c = line[line_index];
if ('\r' == c || '\n' == c)
@@ -473,7 +464,6 @@ void get_keyword_and_value(std::string& keyword,
break;
}
value += c;
- line_index++;
}
}
}
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp
index 7f501f2e77..f6629803ee 100644
--- a/indra/llcommon/llstring.cpp
+++ b/indra/llcommon/llstring.cpp
@@ -141,7 +141,7 @@ std::string rawstr_to_utf8(const std::string& raw)
return wstring_to_utf8str(wstr);
}
-S32 wchar_to_utf8chars(llwchar in_char, char* outchars)
+std::ptrdiff_t wchar_to_utf8chars(llwchar in_char, char* outchars)
{
U32 cur_char = (U32)in_char;
char* base = outchars;
@@ -192,7 +192,7 @@ S32 wchar_to_utf8chars(llwchar in_char, char* outchars)
return outchars - base;
}
-S32 utf16chars_to_wchar(const U16* inchars, llwchar* outchar)
+auto utf16chars_to_wchar(const U16* inchars, llwchar* outchar)
{
const U16* base = inchars;
U16 cur_char = *inchars++;
@@ -310,7 +310,7 @@ S32 wstring_utf16_length(const LLWString &wstr, const S32 woffset, const S32 wle
// and whose equivalent utf-16 string does not exceeds the given utf16_length.
S32 wstring_wstring_length_from_utf16_length(const LLWString & wstr, const S32 woffset, const S32 utf16_length, BOOL *unaligned)
{
- const S32 end = wstr.length();
+ const auto end = wstr.length();
BOOL u = FALSE;
S32 n = woffset + utf16_length;
S32 i = woffset;
@@ -426,7 +426,7 @@ LLWString utf8str_to_wstring(const char* utf8str, size_t len)
}
// Check that this character doesn't go past the end of the string
- S32 end = (len < (i + cont_bytes)) ? len : (i + cont_bytes);
+ auto end = (len < (i + cont_bytes)) ? len : (i + cont_bytes);
do
{
++i;
@@ -471,7 +471,7 @@ std::string wstring_to_utf8str(const llwchar* utf32str, size_t len)
while (i < len)
{
char tchars[8]; /* Flawfinder: ignore */
- S32 n = wchar_to_utf8chars(utf32str[i], tchars);
+ auto n = wchar_to_utf8chars(utf32str[i], tchars);
tchars[n] = 0;
out += tchars;
i++;
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h
index d94f549480..1fd6cac14a 100644
--- a/indra/llcommon/llstring.h
+++ b/indra/llcommon/llstring.h
@@ -664,7 +664,7 @@ ll_convert_forms(ll_convert_alias, LLWString, std::string, utf8str_to_
// Same function, better name. JC
inline LLWString utf8string_to_wstring(const std::string& utf8_string) { return utf8str_to_wstring(utf8_string); }
-LL_COMMON_API S32 wchar_to_utf8chars(llwchar inchar, char* outchars);
+LL_COMMON_API std::ptrdiff_t wchar_to_utf8chars(llwchar inchar, char* outchars);
ll_convert_forms(ll_convert_alias, std::string, LLWString, wstring_to_utf8str);
ll_convert_forms(ll_convert_u16_alias, std::string, llutf16string, utf16str_to_utf8str);
diff --git a/indra/llcommon/llstringtable.cpp b/indra/llcommon/llstringtable.cpp
index f288999964..92a5e777a6 100644
--- a/indra/llcommon/llstringtable.cpp
+++ b/indra/llcommon/llstringtable.cpp
@@ -89,9 +89,8 @@ LLStringTable::~LLStringTable()
{
if (mStringList[i])
{
- string_list_t::iterator iter;
- for (iter = mStringList[i]->begin(); iter != mStringList[i]->end(); iter++)
- delete *iter; // *iter = (LLStringTableEntry*)
+ for (LLStringTableEntry* entry : *mStringList[i])
+ delete entry;
}
delete mStringList[i];
}
@@ -156,9 +155,9 @@ LLStringTableEntry* LLStringTable::checkStringEntry(const char *str)
if (str)
{
char *ret_val;
- LLStringTableEntry *entry;
U32 hash_value = hash_my_string(str, mMaxEntries);
#if STRING_TABLE_HASH_MAP
+ LLStringTableEntry *entry;
#if 1 // Microsoft
string_hash_t::iterator lower = mStringHash.lower_bound(hash_value);
string_hash_t::iterator upper = mStringHash.upper_bound(hash_value);
@@ -180,10 +179,8 @@ LLStringTableEntry* LLStringTable::checkStringEntry(const char *str)
string_list_t *strlist = mStringList[hash_value];
if (strlist)
{
- string_list_t::iterator iter;
- for (iter = strlist->begin(); iter != strlist->end(); iter++)
+ for (LLStringTableEntry* entry : *strlist)
{
- entry = *iter;
ret_val = entry->mString;
if (!strncmp(ret_val, str, MAX_STRINGS_LENGTH))
{
@@ -226,9 +223,9 @@ LLStringTableEntry* LLStringTable::addStringEntry(const char *str)
if (str)
{
char *ret_val = NULL;
- LLStringTableEntry *entry;
U32 hash_value = hash_my_string(str, mMaxEntries);
#if STRING_TABLE_HASH_MAP
+ LLStringTableEntry *entry;
#if 1 // Microsoft
string_hash_t::iterator lower = mStringHash.lower_bound(hash_value);
string_hash_t::iterator upper = mStringHash.upper_bound(hash_value);
@@ -257,10 +254,8 @@ LLStringTableEntry* LLStringTable::addStringEntry(const char *str)
if (strlist)
{
- string_list_t::iterator iter;
- for (iter = strlist->begin(); iter != strlist->end(); iter++)
+ for (LLStringTableEntry* entry : *strlist)
{
- entry = *iter;
ret_val = entry->mString;
if (!strncmp(ret_val, str, MAX_STRINGS_LENGTH))
{
@@ -294,10 +289,10 @@ void LLStringTable::removeString(const char *str)
if (str)
{
char *ret_val;
- LLStringTableEntry *entry;
U32 hash_value = hash_my_string(str, mMaxEntries);
#if STRING_TABLE_HASH_MAP
{
+ LLStringTableEntry *entry;
#if 1 // Microsoft
string_hash_t::iterator lower = mStringHash.lower_bound(hash_value);
string_hash_t::iterator upper = mStringHash.upper_bound(hash_value);
@@ -331,10 +326,8 @@ void LLStringTable::removeString(const char *str)
if (strlist)
{
- string_list_t::iterator iter;
- for (iter = strlist->begin(); iter != strlist->end(); iter++)
+ for (LLStringTableEntry* entry : *strlist)
{
- entry = *iter;
ret_val = entry->mString;
if (!strncmp(ret_val, str, MAX_STRINGS_LENGTH))
{
diff --git a/indra/llcommon/llstringtable.h b/indra/llcommon/llstringtable.h
index ff09e71677..0a292c8bac 100644
--- a/indra/llcommon/llstringtable.h
+++ b/indra/llcommon/llstringtable.h
@@ -136,9 +136,9 @@ public:
for (S32 i = 0; i<mTableSize; i++)
{
string_set_t& stringset = mStringList[i];
- for (string_set_t::iterator iter = stringset.begin(); iter != stringset.end(); iter++)
+ for (LLStdStringHandle str : stringset)
{
- delete *iter;
+ delete str;
}
stringset.clear();
}
diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp
index f717b2cf34..91cb65b815 100644
--- a/indra/llcommon/llsys.cpp
+++ b/indra/llcommon/llsys.cpp
@@ -36,7 +36,7 @@
#ifdef LL_USESYSTEMLIBS
# include <zlib.h>
#else
-# include "zlib/zlib.h"
+# include "zlib-ng/zlib.h"
#endif
#include "llprocessor.h"
@@ -64,6 +64,7 @@ using namespace llsd;
# include <psapi.h> // GetPerformanceInfo() et al.
# include <VersionHelpers.h>
#elif LL_DARWIN
+# include "llsys_objc.h"
# include <errno.h>
# include <sys/sysctl.h>
# include <sys/utsname.h>
@@ -74,12 +75,6 @@ using namespace llsd;
# include <mach/mach_host.h>
# include <mach/task.h>
# include <mach/task_info.h>
-
-// disable warnings about Gestalt calls being deprecated
-// until Apple get's on the ball and provides an alternative
-//
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
#elif LL_LINUX
# include <errno.h>
# include <sys/utsname.h>
@@ -278,12 +273,9 @@ LLOSInfo::LLOSInfo() :
{
const char * DARWIN_PRODUCT_NAME = "Mac OS X";
- SInt32 major_version, minor_version, bugfix_version;
- OSErr r1 = Gestalt(gestaltSystemVersionMajor, &major_version);
- OSErr r2 = Gestalt(gestaltSystemVersionMinor, &minor_version);
- OSErr r3 = Gestalt(gestaltSystemVersionBugFix, &bugfix_version);
+ int64_t major_version, minor_version, bugfix_version = 0;
- if((r1 == noErr) && (r2 == noErr) && (r3 == noErr))
+ if (LLGetDarwinOSInfo(major_version, minor_version, bugfix_version))
{
mMajorVer = major_version;
mMinorVer = minor_version;
@@ -456,18 +448,20 @@ LLOSInfo::LLOSInfo() :
dotted_version_string << mMajorVer << "." << mMinorVer << "." << mBuild;
mOSVersionString.append(dotted_version_string.str());
+ mOSBitness = is64Bit() ? 64 : 32;
+ LL_INFOS("LLOSInfo") << "OS bitness: " << mOSBitness << LL_ENDL;
}
#ifndef LL_WINDOWS
// static
-S32 LLOSInfo::getMaxOpenFiles()
+long LLOSInfo::getMaxOpenFiles()
{
- const S32 OPEN_MAX_GUESS = 256;
+ const long OPEN_MAX_GUESS = 256;
#ifdef OPEN_MAX
- static S32 open_max = OPEN_MAX;
+ static long open_max = OPEN_MAX;
#else
- static S32 open_max = 0;
+ static long open_max = 0;
#endif
if (0 == open_max)
@@ -511,6 +505,11 @@ const std::string& LLOSInfo::getOSVersionString() const
return mOSVersionString;
}
+const S32 LLOSInfo::getOSBitness() const
+{
+ return mOSBitness;
+}
+
//static
U32 LLOSInfo::getProcessVirtualSizeKB()
{
@@ -564,6 +563,25 @@ U32 LLOSInfo::getProcessResidentSizeKB()
return resident_size;
}
+//static
+bool LLOSInfo::is64Bit()
+{
+#if LL_WINDOWS
+#if defined(_WIN64)
+ return true;
+#elif defined(_WIN32)
+ // 32-bit viewer may be run on both 32-bit and 64-bit Windows, need to elaborate
+ BOOL f64 = FALSE;
+ return IsWow64Process(GetCurrentProcess(), &f64) && f64;
+#else
+ return false;
+#endif
+#else // ! LL_WINDOWS
+ // we only build a 64-bit mac viewer and currently we don't build for linux at all
+ return true;
+#endif
+}
+
LLCPUInfo::LLCPUInfo()
{
std::ostringstream out;
@@ -571,6 +589,11 @@ LLCPUInfo::LLCPUInfo()
// proc.WriteInfoTextFile("procInfo.txt");
mHasSSE = proc.hasSSE();
mHasSSE2 = proc.hasSSE2();
+ mHasSSE3 = proc.hasSSE3();
+ mHasSSE3S = proc.hasSSE3S();
+ mHasSSE41 = proc.hasSSE41();
+ mHasSSE42 = proc.hasSSE42();
+ mHasSSE4a = proc.hasSSE4a();
mHasAltivec = proc.hasAltivec();
mCPUMHz = (F64)proc.getCPUFrequency();
mFamily = proc.getCPUFamilyName();
@@ -583,6 +606,35 @@ LLCPUInfo::LLCPUInfo()
}
mCPUString = out.str();
LLStringUtil::trim(mCPUString);
+
+ if (mHasSSE)
+ {
+ mSSEVersions.append("1");
+ }
+ if (mHasSSE2)
+ {
+ mSSEVersions.append("2");
+ }
+ if (mHasSSE3)
+ {
+ mSSEVersions.append("3");
+ }
+ if (mHasSSE3S)
+ {
+ mSSEVersions.append("3S");
+ }
+ if (mHasSSE41)
+ {
+ mSSEVersions.append("4.1");
+ }
+ if (mHasSSE42)
+ {
+ mSSEVersions.append("4.2");
+ }
+ if (mHasSSE4a)
+ {
+ mSSEVersions.append("4a");
+ }
}
bool LLCPUInfo::hasAltivec() const
@@ -600,6 +652,31 @@ bool LLCPUInfo::hasSSE2() const
return mHasSSE2;
}
+bool LLCPUInfo::hasSSE3() const
+{
+ return mHasSSE3;
+}
+
+bool LLCPUInfo::hasSSE3S() const
+{
+ return mHasSSE3S;
+}
+
+bool LLCPUInfo::hasSSE41() const
+{
+ return mHasSSE41;
+}
+
+bool LLCPUInfo::hasSSE42() const
+{
+ return mHasSSE42;
+}
+
+bool LLCPUInfo::hasSSE4a() const
+{
+ return mHasSSE4a;
+}
+
F64 LLCPUInfo::getMHz() const
{
return mCPUMHz;
@@ -610,6 +687,11 @@ std::string LLCPUInfo::getCPUString() const
return mCPUString;
}
+const LLSD& LLCPUInfo::getSSEVersions() const
+{
+ return mSSEVersions;
+}
+
void LLCPUInfo::stream(std::ostream& s) const
{
// gather machine information.
@@ -619,6 +701,11 @@ void LLCPUInfo::stream(std::ostream& s) const
// CPU's attributes regardless of platform
s << "->mHasSSE: " << (U32)mHasSSE << std::endl;
s << "->mHasSSE2: " << (U32)mHasSSE2 << std::endl;
+ s << "->mHasSSE3: " << (U32)mHasSSE3 << std::endl;
+ s << "->mHasSSE3S: " << (U32)mHasSSE3S << std::endl;
+ s << "->mHasSSE41: " << (U32)mHasSSE41 << std::endl;
+ s << "->mHasSSE42: " << (U32)mHasSSE42 << std::endl;
+ s << "->mHasSSE4a: " << (U32)mHasSSE4a << std::endl;
s << "->mHasAltivec: " << (U32)mHasAltivec << std::endl;
s << "->mCPUMHz: " << mCPUMHz << std::endl;
s << "->mCPUString: " << mCPUString << std::endl;
@@ -822,7 +909,7 @@ void LLMemoryInfo::stream(std::ostream& s) const
// Now stream stats
BOOST_FOREACH(const MapEntry& pair, inMap(mStatsMap))
{
- s << pfx << std::setw(key_width+1) << (pair.first + ':') << ' ';
+ s << pfx << std::setw(narrow(key_width+1)) << (pair.first + ':') << ' ';
LLSD value(pair.second);
if (value.isInteger())
s << std::setw(12) << value.asInteger();
@@ -1193,7 +1280,7 @@ public:
<< " seconds ";
}
- S32 precision = LL_CONT.precision();
+ auto precision = LL_CONT.precision();
LL_CONT << std::fixed << std::setprecision(1) << framerate << '\n'
<< LLMemoryInfo();
@@ -1315,10 +1402,3 @@ BOOL gzip_file(const std::string& srcfile, const std::string& dstfile)
if (dst != NULL) gzclose(dst);
return retval;
}
-
-#if LL_DARWIN
-// disable warnings about Gestalt calls being deprecated
-// until Apple get's on the ball and provides an alternative
-//
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
diff --git a/indra/llcommon/llsys.h b/indra/llcommon/llsys.h
index 5ab97939b9..70a03810c5 100644
--- a/indra/llcommon/llsys.h
+++ b/indra/llcommon/llsys.h
@@ -51,14 +51,17 @@ public:
const std::string& getOSStringSimple() const;
const std::string& getOSVersionString() const;
+
+ const S32 getOSBitness() const;
S32 mMajorVer;
S32 mMinorVer;
S32 mBuild;
#ifndef LL_WINDOWS
- static S32 getMaxOpenFiles();
+ static long getMaxOpenFiles();
#endif
+ static bool is64Bit();
static U32 getProcessVirtualSizeKB();
static U32 getProcessResidentSizeKB();
@@ -66,6 +69,7 @@ private:
std::string mOSString;
std::string mOSStringSimple;
std::string mOSVersionString;
+ S32 mOSBitness;
};
@@ -76,10 +80,16 @@ public:
void stream(std::ostream& s) const;
std::string getCPUString() const;
+ const LLSD& getSSEVersions() const;
bool hasAltivec() const;
bool hasSSE() const;
bool hasSSE2() const;
+ bool hasSSE3() const;
+ bool hasSSE3S() const;
+ bool hasSSE41() const;
+ bool hasSSE42() const;
+ bool hasSSE4a() const;
F64 getMHz() const;
// Family is "AMD Duron" or "Intel Pentium Pro"
@@ -88,10 +98,16 @@ public:
private:
bool mHasSSE;
bool mHasSSE2;
+ bool mHasSSE3;
+ bool mHasSSE3S;
+ bool mHasSSE41;
+ bool mHasSSE42;
+ bool mHasSSE4a;
bool mHasAltivec;
F64 mCPUMHz;
std::string mFamily;
std::string mCPUString;
+ LLSD mSSEVersions;
};
//=============================================================================
diff --git a/indra/llcommon/llsys_objc.h b/indra/llcommon/llsys_objc.h
new file mode 100644
index 0000000000..b48ff97bdb
--- /dev/null
+++ b/indra/llcommon/llsys_objc.h
@@ -0,0 +1,37 @@
+/**
+ * @file llsys_objc.h
+ * @brief Header file for llsys_objc.mm
+ *
+ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2022, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLSYS_OBJC_H
+#define LL_LLSYS_OBJC_H
+
+#include <cstdint>
+
+// C++ land doesn't define NSInteger, and we don't want to introduce that for
+// this one case, so use int64_t instead (which is equivalent).
+bool LLGetDarwinOSInfo(int64_t &major, int64_t &minor, int64_t &patch);
+
+
+#endif // LL_LLSYS_OBJC_H
diff --git a/indra/llcommon/llsys_objc.mm b/indra/llcommon/llsys_objc.mm
new file mode 100644
index 0000000000..3fd85fb1c9
--- /dev/null
+++ b/indra/llcommon/llsys_objc.mm
@@ -0,0 +1,64 @@
+/**
+ * @file llsys_objc.mm
+ * @brief obj-c implementation of the system information functions
+ *
+ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2022, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#import "llsys_objc.h"
+#import <AppKit/AppKit.h>
+
+static auto intAtStringIndex(NSArray *array, int index)
+{
+ return [(NSString *)[array objectAtIndex:index] integerValue];
+}
+
+bool LLGetDarwinOSInfo(int64_t &major, int64_t &minor, int64_t &patch)
+{
+ if (NSAppKitVersionNumber > NSAppKitVersionNumber10_8)
+ {
+ NSOperatingSystemVersion osVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
+ major = osVersion.majorVersion;
+ minor = osVersion.minorVersion;
+ patch = osVersion.patchVersion;
+ }
+ else
+ {
+ NSString* versionString = [[NSDictionary dictionaryWithContentsOfFile:
+ @"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"];
+ NSArray* versions = [versionString componentsSeparatedByString:@"."];
+ NSUInteger count = [versions count];
+ if (count > 0)
+ {
+ major = intAtStringIndex(versions, 0);
+ if (count > 1)
+ {
+ minor = intAtStringIndex(versions, 1);
+ if (count > 2)
+ {
+ patch = intAtStringIndex(versions, 2);
+ }
+ }
+ }
+ }
+ return true;
+}
diff --git a/indra/llcommon/llthreadlocalstorage.cpp b/indra/llcommon/llthreadlocalstorage.cpp
deleted file mode 100644
index d8a063e8d5..0000000000
--- a/indra/llcommon/llthreadlocalstorage.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * @file llthreadlocalstorage.cpp
- * @author Richard
- * @date 2013-1-11
- * @brief implementation of thread local storage utility classes
- *
- * $LicenseInfo:firstyear=2013&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "linden_common.h"
-#include "llthreadlocalstorage.h"
-#include "llapr.h"
-
-//
-//LLThreadLocalPointerBase
-//
-bool LLThreadLocalPointerBase::sInitialized = false;
-
-void LLThreadLocalPointerBase::set( void* value )
-{
- llassert(sInitialized && mThreadKey);
-
- apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey);
- if (result != APR_SUCCESS)
- {
- ll_apr_warn_status(result);
- LL_ERRS() << "Failed to set thread local data" << LL_ENDL;
- }
-}
-
-void* LLThreadLocalPointerBase::get() const
-{
- // llassert(sInitialized);
- void* ptr;
- apr_status_t result =
- apr_threadkey_private_get(&ptr, mThreadKey);
- if (result != APR_SUCCESS)
- {
- ll_apr_warn_status(result);
- LL_ERRS() << "Failed to get thread local data" << LL_ENDL;
- }
- return ptr;
-}
-
-
-void LLThreadLocalPointerBase::initStorage( )
-{
- apr_status_t result = apr_threadkey_private_create(&mThreadKey, NULL, gAPRPoolp);
- if (result != APR_SUCCESS)
- {
- ll_apr_warn_status(result);
- LL_ERRS() << "Failed to allocate thread local data" << LL_ENDL;
- }
-}
-
-void LLThreadLocalPointerBase::destroyStorage()
-{
- if (sInitialized)
- {
- if (mThreadKey)
- {
- apr_status_t result = apr_threadkey_private_delete(mThreadKey);
- if (result != APR_SUCCESS)
- {
- ll_apr_warn_status(result);
- LL_ERRS() << "Failed to delete thread local data" << LL_ENDL;
- }
- }
- }
-}
-
-//static
-void LLThreadLocalPointerBase::initAllThreadLocalStorage()
-{
- if (!sInitialized)
- {
- for (auto& base : instance_snapshot())
- {
- base.initStorage();
- }
- sInitialized = true;
- }
-}
-
-//static
-void LLThreadLocalPointerBase::destroyAllThreadLocalStorage()
-{
- if (sInitialized)
- {
- //for (auto& base : instance_snapshot())
- //{
- // base.destroyStorage();
- //}
- sInitialized = false;
- }
-}
diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h
index 3b5786023f..bdd28ec865 100644
--- a/indra/llcommon/llthreadlocalstorage.h
+++ b/indra/llcommon/llthreadlocalstorage.h
@@ -30,100 +30,6 @@
#include "llinstancetracker.h"
-class LLThreadLocalPointerBase : public LLInstanceTracker<LLThreadLocalPointerBase>
-{
-public:
- LLThreadLocalPointerBase()
- : mThreadKey(NULL)
- {
- if (sInitialized)
- {
- initStorage();
- }
- }
-
- LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other)
- : mThreadKey(NULL)
- {
- if (sInitialized)
- {
- initStorage();
- }
- }
-
- ~LLThreadLocalPointerBase()
- {
- destroyStorage();
- }
-
- static void initAllThreadLocalStorage();
- static void destroyAllThreadLocalStorage();
-
-protected:
- void set(void* value);
-
- void* get() const;
-
- void initStorage();
- void destroyStorage();
-
-protected:
- struct apr_threadkey_t* mThreadKey;
- static bool sInitialized;
-};
-
-template <typename T>
-class LLThreadLocalPointer : public LLThreadLocalPointerBase
-{
-public:
-
- LLThreadLocalPointer()
- {}
-
- explicit LLThreadLocalPointer(T* value)
- {
- set(value);
- }
-
-
- LLThreadLocalPointer(const LLThreadLocalPointer<T>& other)
- : LLThreadLocalPointerBase(other)
- {
- set(other.get());
- }
-
- LL_FORCE_INLINE T* get() const
- {
- return (T*)LLThreadLocalPointerBase::get();
- }
-
- T* operator -> () const
- {
- return (T*)get();
- }
-
- T& operator*() const
- {
- return *(T*)get();
- }
-
- LLThreadLocalPointer<T>& operator = (T* value)
- {
- set((void*)value);
- return *this;
- }
-
- bool operator ==(const T* other) const
- {
- if (!sInitialized) return false;
- return get() == other;
- }
-
- bool isNull() const { return !sInitialized || get() == NULL; }
-
- bool notNull() const { return sInitialized && get() != NULL; }
-};
-
template<typename DERIVED_TYPE>
class LLThreadLocalSingletonPointer
{
@@ -139,10 +45,10 @@ public:
}
private:
- static LL_THREAD_LOCAL DERIVED_TYPE* sInstance;
+ static thread_local DERIVED_TYPE* sInstance;
};
template<typename DERIVED_TYPE>
-LL_THREAD_LOCAL DERIVED_TYPE* LLThreadLocalSingletonPointer<DERIVED_TYPE>::sInstance = NULL;
+thread_local DERIVED_TYPE* LLThreadLocalSingletonPointer<DERIVED_TYPE>::sInstance = NULL;
#endif // LL_LLTHREADLOCALSTORAGE_H
diff --git a/indra/llcommon/llthreadsafequeue.h b/indra/llcommon/llthreadsafequeue.h
index 68d79cdd12..f396a71e6f 100644
--- a/indra/llcommon/llthreadsafequeue.h
+++ b/indra/llcommon/llthreadsafequeue.h
@@ -82,7 +82,7 @@ public:
// Limiting the number of pending items prevents unbounded growth of the
// underlying queue.
- LLThreadSafeQueue(U32 capacity = 1024);
+ LLThreadSafeQueue(size_t capacity = 1024);
virtual ~LLThreadSafeQueue() {}
// Add an element to the queue (will block if the queue has reached
@@ -179,7 +179,7 @@ public:
protected:
typedef QueueT queue_type;
QueueT mStorage;
- U32 mCapacity;
+ size_t mCapacity;
bool mClosed;
boost::fibers::timed_mutex mLock;
@@ -262,7 +262,7 @@ namespace LL
* LLThreadSafeQueue implementation
*****************************************************************************/
template<typename ElementT, typename QueueT>
-LLThreadSafeQueue<ElementT, QueueT>::LLThreadSafeQueue(U32 capacity) :
+LLThreadSafeQueue<ElementT, QueueT>::LLThreadSafeQueue(size_t capacity) :
mCapacity(capacity),
mClosed(false)
{
diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp
index aaa6df325c..58bedacf43 100644
--- a/indra/llcommon/lltimer.cpp
+++ b/indra/llcommon/lltimer.cpp
@@ -121,9 +121,14 @@ U32 micro_sleep(U64 us, U32 max_yields)
U64 start = get_clock_count();
// This is kernel dependent. Currently, our kernel generates software clock
// interrupts at 250 Hz (every 4,000 microseconds).
- const U64 KERNEL_SLEEP_INTERVAL_US = 4000;
-
- S32 num_sleep_intervals = (us - (KERNEL_SLEEP_INTERVAL_US >> 1)) / KERNEL_SLEEP_INTERVAL_US;
+ const S64 KERNEL_SLEEP_INTERVAL_US = 4000;
+
+ // Use signed arithmetic to discover whether a sleep is even necessary. If
+ // either 'us' or KERNEL_SLEEP_INTERVAL_US is unsigned, the compiler
+ // promotes the difference to unsigned. If 'us' is less than half
+ // KERNEL_SLEEP_INTERVAL_US, the unsigned difference will be hugely
+ // positive, resulting in a crazy long wait.
+ auto num_sleep_intervals = (S64(us) - (KERNEL_SLEEP_INTERVAL_US >> 1)) / KERNEL_SLEEP_INTERVAL_US;
if (num_sleep_intervals > 0)
{
U64 sleep_time = (num_sleep_intervals * KERNEL_SLEEP_INTERVAL_US) - (KERNEL_SLEEP_INTERVAL_US >> 1);
diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp
index f59b207ded..ff671a8370 100644
--- a/indra/llcommon/lltrace.cpp
+++ b/indra/llcommon/lltrace.cpp
@@ -40,7 +40,7 @@ StatBase::StatBase( const char* name, const char* description )
mDescription(description ? description : "")
{
#ifndef LL_RELEASE_FOR_DOWNLOAD
- if (LLTrace::get_thread_recorder().notNull())
+ if (LLTrace::get_thread_recorder() != NULL)
{
LL_ERRS() << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << LL_ENDL;
}
@@ -65,7 +65,7 @@ void TimeBlockTreeNode::setParent( BlockTimerStatHandle* parent )
llassert_always(parent != mBlock);
llassert_always(parent != NULL);
- TimeBlockTreeNode* parent_tree_node = get_thread_recorder()->getTimeBlockTreeNode(parent->getIndex());
+ TimeBlockTreeNode* parent_tree_node = get_thread_recorder()->getTimeBlockTreeNode(narrow(parent->getIndex()));
if (!parent_tree_node) return;
if (mParent)
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h
index fcd8753f75..580cf0a5fd 100644
--- a/indra/llcommon/lltrace.h
+++ b/indra/llcommon/lltrace.h
@@ -340,7 +340,7 @@ inline void claim_alloc(MemStatHandle& measurement, const T& value)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
#if LL_TRACE_ENABLED
- S32 size = MeasureMem<T>::measureFootprint(value);
+ auto size = MeasureMem<T>::measureFootprint(value);
if(size == 0) return;
MemAccumulator& accumulator = measurement.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size);
@@ -353,7 +353,7 @@ inline void disclaim_alloc(MemStatHandle& measurement, const T& value)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
#if LL_TRACE_ENABLED
- S32 size = MeasureMem<T>::measureFootprint(value);
+ auto size = MeasureMem<T>::measureFootprint(value);
if(size == 0) return;
MemAccumulator& accumulator = measurement.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size);
diff --git a/indra/llcommon/lltraceaccumulators.cpp b/indra/llcommon/lltraceaccumulators.cpp
index 34299f5a29..6bd886ae98 100644
--- a/indra/llcommon/lltraceaccumulators.cpp
+++ b/indra/llcommon/lltraceaccumulators.cpp
@@ -93,12 +93,12 @@ void AccumulatorBufferGroup::makeCurrent()
mStackTimers.makeCurrent();
mMemStats.makeCurrent();
- ThreadRecorder* thread_recorder = get_thread_recorder().get();
+ ThreadRecorder* thread_recorder = get_thread_recorder();
AccumulatorBuffer<TimeBlockAccumulator>& timer_accumulator_buffer = mStackTimers;
// update stacktimer parent pointers
- for (S32 i = 0, end_i = mStackTimers.size(); i < end_i; i++)
+ for (size_t i = 0, end_i = mStackTimers.size(); i < end_i; i++)
{
- TimeBlockTreeNode* tree_node = thread_recorder->getTimeBlockTreeNode(i);
+ TimeBlockTreeNode* tree_node = thread_recorder->getTimeBlockTreeNode(narrow(i));
if (tree_node)
{
timer_accumulator_buffer[i].mParent = tree_node->mParent;
diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp
index 1613af1dcf..a8dcc5226a 100644
--- a/indra/llcommon/lltracerecording.cpp
+++ b/indra/llcommon/lltracerecording.cpp
@@ -95,7 +95,7 @@ Recording::~Recording()
// allow recording destruction without thread recorder running,
// otherwise thread shutdown could crash if a recording outlives the thread recorder
// besides, recording construction and destruction is fine without a recorder...just don't attempt to start one
- if (isStarted() && LLTrace::get_thread_recorder().notNull())
+ if (isStarted() && LLTrace::get_thread_recorder() != NULL)
{
LLTrace::get_thread_recorder()->deactivate(mBuffers.write());
}
@@ -112,9 +112,9 @@ void Recording::update()
// must have
llassert(mActiveBuffers != NULL
- && LLTrace::get_thread_recorder().notNull());
+ && LLTrace::get_thread_recorder() != NULL);
- if(!mActiveBuffers->isCurrent())
+ if(!mActiveBuffers->isCurrent() && LLTrace::get_thread_recorder() != NULL)
{
AccumulatorBufferGroup* buffers = mBuffers.write();
LLTrace::get_thread_recorder()->deactivate(buffers);
@@ -144,7 +144,7 @@ void Recording::handleStart()
mSamplingTimer.reset();
mBuffers.setStayUnique(true);
// must have thread recorder running on this thread
- llassert(LLTrace::get_thread_recorder().notNull());
+ llassert(LLTrace::get_thread_recorder() != NULL);
mActiveBuffers = LLTrace::get_thread_recorder()->activate(mBuffers.write());
#endif
}
@@ -155,7 +155,7 @@ void Recording::handleStop()
#if LL_TRACE_ENABLED
mElapsedSeconds += mSamplingTimer.getElapsedTimeF64();
// must have thread recorder running on this thread
- llassert(LLTrace::get_thread_recorder().notNull());
+ llassert(LLTrace::get_thread_recorder() != NULL);
LLTrace::get_thread_recorder()->deactivate(mBuffers.write());
mActiveBuffers = NULL;
mBuffers.setStayUnique(false);
@@ -606,7 +606,8 @@ void PeriodicRecording::nextPeriod()
mCurPeriod = (mCurPeriod + 1) % mRecordingPeriods.size();
old_recording.splitTo(getCurRecording());
- mNumRecordedPeriods = llmin((S32)mRecordingPeriods.size() - 1, mNumRecordedPeriods + 1);
+ mNumRecordedPeriods = mRecordingPeriods.empty()? 0 :
+ llmin(mRecordingPeriods.size() - 1, mNumRecordedPeriods + 1);
}
void PeriodicRecording::appendRecording(Recording& recording)
@@ -625,21 +626,21 @@ void PeriodicRecording::appendPeriodicRecording( PeriodicRecording& other )
getCurRecording().update();
other.getCurRecording().update();
- const S32 other_recording_slots = other.mRecordingPeriods.size();
- const S32 other_num_recordings = other.getNumRecordedPeriods();
- const S32 other_current_recording_index = other.mCurPeriod;
- const S32 other_oldest_recording_index = (other_current_recording_index + other_recording_slots - other_num_recordings) % other_recording_slots;
+ const auto other_recording_slots = other.mRecordingPeriods.size();
+ const auto other_num_recordings = other.getNumRecordedPeriods();
+ const auto other_current_recording_index = other.mCurPeriod;
+ const auto other_oldest_recording_index = (other_current_recording_index + other_recording_slots - other_num_recordings) % other_recording_slots;
// append first recording into our current slot
getCurRecording().appendRecording(other.mRecordingPeriods[other_oldest_recording_index]);
// from now on, add new recordings for everything after the first
- S32 other_index = (other_oldest_recording_index + 1) % other_recording_slots;
+ auto other_index = (other_oldest_recording_index + 1) % other_recording_slots;
if (mAutoResize)
{
// push back recordings for everything in the middle
- S32 other_index = (other_oldest_recording_index + 1) % other_recording_slots;
+ auto other_index = (other_oldest_recording_index + 1) % other_recording_slots;
while (other_index != other_current_recording_index)
{
mRecordingPeriods.push_back(other.mRecordingPeriods[other_index]);
@@ -652,8 +653,8 @@ void PeriodicRecording::appendPeriodicRecording( PeriodicRecording& other )
mRecordingPeriods.push_back(other.mRecordingPeriods[other_current_recording_index]);
}
- mCurPeriod = mRecordingPeriods.size() - 1;
- mNumRecordedPeriods = mRecordingPeriods.size() - 1;
+ mCurPeriod = mRecordingPeriods.empty()? 0 : mRecordingPeriods.size() - 1;
+ mNumRecordedPeriods = mCurPeriod;
}
else
{
@@ -682,7 +683,7 @@ void PeriodicRecording::appendPeriodicRecording( PeriodicRecording& other )
llassert(num_to_copy >= 1);
// advance to last recording period copied, and make that our current period
mCurPeriod = (mCurPeriod + num_to_copy - 1) % mRecordingPeriods.size();
- mNumRecordedPeriods = llmin((S32)mRecordingPeriods.size() - 1, mNumRecordedPeriods + num_to_copy - 1);
+ mNumRecordedPeriods = llmin(mRecordingPeriods.size() - 1, mNumRecordedPeriods + num_to_copy - 1);
}
// end with fresh period, otherwise next appendPeriodicRecording() will merge the first
@@ -695,10 +696,10 @@ F64Seconds PeriodicRecording::getDuration() const
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
F64Seconds duration;
- S32 num_periods = mRecordingPeriods.size();
- for (S32 i = 1; i <= num_periods; i++)
+ auto num_periods = mRecordingPeriods.size();
+ for (size_t i = 1; i <= num_periods; i++)
{
- S32 index = (mCurPeriod + num_periods - i) % num_periods;
+ auto index = (mCurPeriod + num_periods - i) % num_periods;
duration += mRecordingPeriods[index].getDuration();
}
return duration;
@@ -734,16 +735,16 @@ const Recording& PeriodicRecording::getCurRecording() const
return mRecordingPeriods[mCurPeriod];
}
-Recording& PeriodicRecording::getPrevRecording( S32 offset )
+Recording& PeriodicRecording::getPrevRecording( size_t offset )
{
- S32 num_periods = mRecordingPeriods.size();
+ auto num_periods = mRecordingPeriods.size();
offset = llclamp(offset, 0, num_periods - 1);
return mRecordingPeriods[(mCurPeriod + num_periods - offset) % num_periods];
}
-const Recording& PeriodicRecording::getPrevRecording( S32 offset ) const
+const Recording& PeriodicRecording::getPrevRecording( size_t offset ) const
{
- S32 num_periods = mRecordingPeriods.size();
+ auto num_periods = mRecordingPeriods.size();
offset = llclamp(offset, 0, num_periods - 1);
return mRecordingPeriods[(mCurPeriod + num_periods - offset) % num_periods];
}
@@ -772,11 +773,9 @@ void PeriodicRecording::handleReset()
}
else
{
- for (std::vector<Recording>::iterator it = mRecordingPeriods.begin(), end_it = mRecordingPeriods.end();
- it != end_it;
- ++it)
+ for (Recording& rec : mRecordingPeriods)
{
- it->reset();
+ rec.reset();
}
}
mCurPeriod = 0;
@@ -790,7 +789,7 @@ void PeriodicRecording::handleSplitTo(PeriodicRecording& other)
getCurRecording().splitTo(other.getCurRecording());
}
-F64 PeriodicRecording::getPeriodMin( const StatType<EventAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodMin( const StatType<EventAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -812,7 +811,7 @@ F64 PeriodicRecording::getPeriodMin( const StatType<EventAccumulator>& stat, S32
: NaN;
}
-F64 PeriodicRecording::getPeriodMax( const StatType<EventAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodMax( const StatType<EventAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -835,7 +834,7 @@ F64 PeriodicRecording::getPeriodMax( const StatType<EventAccumulator>& stat, S32
}
// calculates means using aggregates per period
-F64 PeriodicRecording::getPeriodMean( const StatType<EventAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodMean( const StatType<EventAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -858,7 +857,7 @@ F64 PeriodicRecording::getPeriodMean( const StatType<EventAccumulator>& stat, S3
: NaN;
}
-F64 PeriodicRecording::getPeriodStandardDeviation( const StatType<EventAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodStandardDeviation( const StatType<EventAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -883,7 +882,7 @@ F64 PeriodicRecording::getPeriodStandardDeviation( const StatType<EventAccumulat
: NaN;
}
-F64 PeriodicRecording::getPeriodMin( const StatType<SampleAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodMin( const StatType<SampleAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -905,7 +904,7 @@ F64 PeriodicRecording::getPeriodMin( const StatType<SampleAccumulator>& stat, S3
: NaN;
}
-F64 PeriodicRecording::getPeriodMax(const StatType<SampleAccumulator>& stat, S32 num_periods /*= S32_MAX*/)
+F64 PeriodicRecording::getPeriodMax(const StatType<SampleAccumulator>& stat, size_t num_periods /*= S32_MAX*/)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -928,7 +927,7 @@ F64 PeriodicRecording::getPeriodMax(const StatType<SampleAccumulator>& stat, S32
}
-F64 PeriodicRecording::getPeriodMean( const StatType<SampleAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodMean( const StatType<SampleAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -951,7 +950,7 @@ F64 PeriodicRecording::getPeriodMean( const StatType<SampleAccumulator>& stat, S
: NaN;
}
-F64 PeriodicRecording::getPeriodMedian( const StatType<SampleAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodMedian( const StatType<SampleAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -977,7 +976,7 @@ F64 PeriodicRecording::getPeriodMedian( const StatType<SampleAccumulator>& stat,
return F64((buf.size() % 2 == 0) ? (buf[buf.size() / 2 - 1] + buf[buf.size() / 2]) / 2 : buf[buf.size() / 2]);
}
-F64 PeriodicRecording::getPeriodStandardDeviation( const StatType<SampleAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64 PeriodicRecording::getPeriodStandardDeviation( const StatType<SampleAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -1003,7 +1002,7 @@ F64 PeriodicRecording::getPeriodStandardDeviation( const StatType<SampleAccumula
}
-F64Kilobytes PeriodicRecording::getPeriodMin( const StatType<MemAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64Kilobytes PeriodicRecording::getPeriodMin( const StatType<MemAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -1018,12 +1017,12 @@ F64Kilobytes PeriodicRecording::getPeriodMin( const StatType<MemAccumulator>& st
return min_val;
}
-F64Kilobytes PeriodicRecording::getPeriodMin(const MemStatHandle& stat, S32 num_periods)
+F64Kilobytes PeriodicRecording::getPeriodMin(const MemStatHandle& stat, size_t num_periods)
{
return getPeriodMin(static_cast<const StatType<MemAccumulator>&>(stat), num_periods);
}
-F64Kilobytes PeriodicRecording::getPeriodMax(const StatType<MemAccumulator>& stat, S32 num_periods /*= S32_MAX*/)
+F64Kilobytes PeriodicRecording::getPeriodMax(const StatType<MemAccumulator>& stat, size_t num_periods /*= S32_MAX*/)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -1038,12 +1037,12 @@ F64Kilobytes PeriodicRecording::getPeriodMax(const StatType<MemAccumulator>& sta
return max_val;
}
-F64Kilobytes PeriodicRecording::getPeriodMax(const MemStatHandle& stat, S32 num_periods)
+F64Kilobytes PeriodicRecording::getPeriodMax(const MemStatHandle& stat, size_t num_periods)
{
return getPeriodMax(static_cast<const StatType<MemAccumulator>&>(stat), num_periods);
}
-F64Kilobytes PeriodicRecording::getPeriodMean( const StatType<MemAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64Kilobytes PeriodicRecording::getPeriodMean( const StatType<MemAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -1059,12 +1058,12 @@ F64Kilobytes PeriodicRecording::getPeriodMean( const StatType<MemAccumulator>& s
return mean / F64(num_periods);
}
-F64Kilobytes PeriodicRecording::getPeriodMean(const MemStatHandle& stat, S32 num_periods)
+F64Kilobytes PeriodicRecording::getPeriodMean(const MemStatHandle& stat, size_t num_periods)
{
return getPeriodMean(static_cast<const StatType<MemAccumulator>&>(stat), num_periods);
}
-F64Kilobytes PeriodicRecording::getPeriodStandardDeviation( const StatType<MemAccumulator>& stat, S32 num_periods /*= S32_MAX*/ )
+F64Kilobytes PeriodicRecording::getPeriodStandardDeviation( const StatType<MemAccumulator>& stat, size_t num_periods /*= S32_MAX*/ )
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -1089,7 +1088,7 @@ F64Kilobytes PeriodicRecording::getPeriodStandardDeviation( const StatType<MemAc
: NaN);
}
-F64Kilobytes PeriodicRecording::getPeriodStandardDeviation(const MemStatHandle& stat, S32 num_periods)
+F64Kilobytes PeriodicRecording::getPeriodStandardDeviation(const MemStatHandle& stat, size_t num_periods)
{
return getPeriodStandardDeviation(static_cast<const StatType<MemAccumulator>&>(stat), num_periods);
}
@@ -1181,8 +1180,8 @@ void ExtendablePeriodicRecording::handleSplitTo(ExtendablePeriodicRecording& oth
PeriodicRecording& get_frame_recording()
{
- static LLThreadLocalPointer<PeriodicRecording> sRecording(new PeriodicRecording(200, PeriodicRecording::STARTED));
- return *sRecording;
+ static thread_local PeriodicRecording sRecording(200, PeriodicRecording::STARTED);
+ return sRecording;
}
}
diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h
index 556b7470cf..8b56721f42 100644
--- a/indra/llcommon/lltracerecording.h
+++ b/indra/llcommon/lltracerecording.h
@@ -334,7 +334,7 @@ namespace LLTrace
~PeriodicRecording();
void nextPeriod();
- S32 getNumRecordedPeriods()
+ auto getNumRecordedPeriods()
{
// current period counts if not active
return mNumRecordedPeriods + (isStarted() ? 0 : 1);
@@ -348,24 +348,24 @@ namespace LLTrace
const Recording& getLastRecording() const;
Recording& getCurRecording();
const Recording& getCurRecording() const;
- Recording& getPrevRecording(S32 offset);
- const Recording& getPrevRecording(S32 offset) const;
+ Recording& getPrevRecording(size_t offset);
+ const Recording& getPrevRecording(size_t offset) const;
Recording snapshotCurRecording() const;
template <typename T>
- S32 getSampleCount(const StatType<T>& stat, S32 num_periods = S32_MAX)
- {
- LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
+ auto getSampleCount(const StatType<T>& stat, size_t num_periods = S32_MAX)
+ {
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
- S32 num_samples = 0;
- for (S32 i = 1; i <= num_periods; i++)
+ size_t num_samples = 0;
+ for (size_t i = 1; i <= num_periods; i++)
{
Recording& recording = getPrevRecording(i);
num_samples += recording.getSampleCount(stat);
}
return num_samples;
- }
+ }
//
// PERIODIC MIN
@@ -373,7 +373,7 @@ namespace LLTrace
// catch all for stats that have a defined sum
template <typename T>
- typename T::value_t getPeriodMin(const StatType<T>& stat, S32 num_periods = S32_MAX)
+ typename T::value_t getPeriodMin(const StatType<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -396,33 +396,33 @@ namespace LLTrace
}
template<typename T>
- T getPeriodMin(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ T getPeriodMin(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return T(getPeriodMin(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMin(const StatType<SampleAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMin(const StatType<SampleAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- T getPeriodMin(const SampleStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ T getPeriodMin(const SampleStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return T(getPeriodMin(static_cast<const StatType<SampleAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMin(const StatType<EventAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMin(const StatType<EventAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- T getPeriodMin(const EventStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ T getPeriodMin(const EventStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return T(getPeriodMin(static_cast<const StatType<EventAccumulator>&>(stat), num_periods));
}
- F64Kilobytes getPeriodMin(const StatType<MemAccumulator>& stat, S32 num_periods = S32_MAX);
- F64Kilobytes getPeriodMin(const MemStatHandle& stat, S32 num_periods = S32_MAX);
+ F64Kilobytes getPeriodMin(const StatType<MemAccumulator>& stat, size_t num_periods = S32_MAX);
+ F64Kilobytes getPeriodMin(const MemStatHandle& stat, size_t num_periods = S32_MAX);
template <typename T>
- typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMinPerSec(const StatType<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMinPerSec(const StatType<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -437,7 +437,7 @@ namespace LLTrace
}
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMinPerSec(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMinPerSec(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMinPerSec(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
@@ -449,7 +449,7 @@ namespace LLTrace
// catch all for stats that have a defined sum
template <typename T>
- typename T::value_t getPeriodMax(const StatType<T>& stat, S32 num_periods = S32_MAX)
+ typename T::value_t getPeriodMax(const StatType<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -472,33 +472,33 @@ namespace LLTrace
}
template<typename T>
- T getPeriodMax(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ T getPeriodMax(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return T(getPeriodMax(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMax(const StatType<SampleAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMax(const StatType<SampleAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- T getPeriodMax(const SampleStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ T getPeriodMax(const SampleStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return T(getPeriodMax(static_cast<const StatType<SampleAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMax(const StatType<EventAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMax(const StatType<EventAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- T getPeriodMax(const EventStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ T getPeriodMax(const EventStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return T(getPeriodMax(static_cast<const StatType<EventAccumulator>&>(stat), num_periods));
}
- F64Kilobytes getPeriodMax(const StatType<MemAccumulator>& stat, S32 num_periods = S32_MAX);
- F64Kilobytes getPeriodMax(const MemStatHandle& stat, S32 num_periods = S32_MAX);
+ F64Kilobytes getPeriodMax(const StatType<MemAccumulator>& stat, size_t num_periods = S32_MAX);
+ F64Kilobytes getPeriodMax(const MemStatHandle& stat, size_t num_periods = S32_MAX);
template <typename T>
- typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMaxPerSec(const StatType<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMaxPerSec(const StatType<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -513,7 +513,7 @@ namespace LLTrace
}
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMaxPerSec(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMaxPerSec(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMaxPerSec(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
@@ -525,7 +525,7 @@ namespace LLTrace
// catch all for stats that have a defined sum
template <typename T>
- typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMean(const StatType<T >& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMean(const StatType<T >& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -546,32 +546,32 @@ namespace LLTrace
}
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMean(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMean(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMean(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMean(const StatType<SampleAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMean(const StatType<SampleAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMean(const SampleStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMean(const SampleStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMean(static_cast<const StatType<SampleAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMean(const StatType<EventAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMean(const StatType<EventAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMean(const EventStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMean(const EventStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMean(static_cast<const StatType<EventAccumulator>&>(stat), num_periods));
}
- F64Kilobytes getPeriodMean(const StatType<MemAccumulator>& stat, S32 num_periods = S32_MAX);
- F64Kilobytes getPeriodMean(const MemStatHandle& stat, S32 num_periods = S32_MAX);
+ F64Kilobytes getPeriodMean(const StatType<MemAccumulator>& stat, size_t num_periods = S32_MAX);
+ F64Kilobytes getPeriodMean(const MemStatHandle& stat, size_t num_periods = S32_MAX);
template <typename T>
- typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMeanPerSec(const StatType<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMeanPerSec(const StatType<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -593,16 +593,16 @@ namespace LLTrace
}
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMeanPerSec(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMeanPerSec(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMeanPerSec(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
}
- F64 getPeriodMedian( const StatType<SampleAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodMedian( const StatType<SampleAccumulator>& stat, size_t num_periods = S32_MAX);
template <typename T>
- typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMedianPerSec(const StatType<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMedianPerSec(const StatType<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
num_periods = llmin(num_periods, getNumRecordedPeriods());
@@ -622,7 +622,7 @@ namespace LLTrace
}
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodMedianPerSec(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodMedianPerSec(const CountStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodMedianPerSec(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
@@ -632,25 +632,25 @@ namespace LLTrace
// PERIODIC STANDARD DEVIATION
//
- F64 getPeriodStandardDeviation(const StatType<SampleAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodStandardDeviation(const StatType<SampleAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodStandardDeviation(const SampleStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodStandardDeviation(const SampleStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodStandardDeviation(static_cast<const StatType<SampleAccumulator>&>(stat), num_periods));
}
- F64 getPeriodStandardDeviation(const StatType<EventAccumulator>& stat, S32 num_periods = S32_MAX);
+ F64 getPeriodStandardDeviation(const StatType<EventAccumulator>& stat, size_t num_periods = S32_MAX);
template<typename T>
- typename RelatedTypes<T>::fractional_t getPeriodStandardDeviation(const EventStatHandle<T>& stat, S32 num_periods = S32_MAX)
+ typename RelatedTypes<T>::fractional_t getPeriodStandardDeviation(const EventStatHandle<T>& stat, size_t num_periods = S32_MAX)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_STATS;
return typename RelatedTypes<T>::fractional_t(getPeriodStandardDeviation(static_cast<const StatType<EventAccumulator>&>(stat), num_periods));
}
- F64Kilobytes getPeriodStandardDeviation(const StatType<MemAccumulator>& stat, S32 num_periods = S32_MAX);
- F64Kilobytes getPeriodStandardDeviation(const MemStatHandle& stat, S32 num_periods = S32_MAX);
+ F64Kilobytes getPeriodStandardDeviation(const StatType<MemAccumulator>& stat, size_t num_periods = S32_MAX);
+ F64Kilobytes getPeriodStandardDeviation(const MemStatHandle& stat, size_t num_periods = S32_MAX);
private:
// implementation for LLStopWatchControlsMixin
@@ -662,8 +662,8 @@ namespace LLTrace
private:
std::vector<Recording> mRecordingPeriods;
const bool mAutoResize;
- S32 mCurPeriod;
- S32 mNumRecordedPeriods;
+ size_t mCurPeriod;
+ size_t mNumRecordedPeriods;
};
PeriodicRecording& get_frame_recording();
diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp
index 090d3297a0..282c454a2a 100644
--- a/indra/llcommon/lltracethreadrecorder.cpp
+++ b/indra/llcommon/lltracethreadrecorder.cpp
@@ -125,7 +125,7 @@ ThreadRecorder::~ThreadRecorder()
#endif
}
-TimeBlockTreeNode* ThreadRecorder::getTimeBlockTreeNode( S32 index )
+TimeBlockTreeNode* ThreadRecorder::getTimeBlockTreeNode( size_t index )
{
#if LL_TRACE_ENABLED
if (0 <= index && index < mNumTimeBlockTreeNodes)
@@ -284,13 +284,11 @@ void ThreadRecorder::pullFromChildren()
AccumulatorBufferGroup& target_recording_buffers = mActiveRecordings.back()->mPartialRecording;
target_recording_buffers.sync();
- for (child_thread_recorder_list_t::iterator it = mChildThreadRecorders.begin(), end_it = mChildThreadRecorders.end();
- it != end_it;
- ++it)
- { LLMutexLock lock(&(*it)->mSharedRecordingMutex);
+ for (LLTrace::ThreadRecorder* rec : mChildThreadRecorders)
+ { LLMutexLock lock(&(rec->mSharedRecordingMutex));
- target_recording_buffers.merge((*it)->mSharedRecordingBuffers);
- (*it)->mSharedRecordingBuffers.reset();
+ target_recording_buffers.merge(rec->mSharedRecordingBuffers);
+ rec->mSharedRecordingBuffers.reset();
}
}
#endif
@@ -308,13 +306,13 @@ ThreadRecorder* get_master_thread_recorder()
return sMasterThreadRecorder;
}
-LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder_ptr()
+ThreadRecorder*& get_thread_recorder_ptr()
{
- static LLThreadLocalPointer<ThreadRecorder> s_thread_recorder;
+ static thread_local ThreadRecorder* s_thread_recorder;
return s_thread_recorder;
}
-const LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder()
+ThreadRecorder* get_thread_recorder()
{
return get_thread_recorder_ptr();
}
diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h
index a797c6687e..8ee6729ac6 100644
--- a/indra/llcommon/lltracethreadrecorder.h
+++ b/indra/llcommon/lltracethreadrecorder.h
@@ -32,7 +32,6 @@
#include "llmutex.h"
#include "lltraceaccumulators.h"
-#include "llthreadlocalstorage.h"
namespace LLTrace
{
@@ -58,7 +57,7 @@ namespace LLTrace
void pullFromChildren();
void pushToParent();
- TimeBlockTreeNode* getTimeBlockTreeNode(S32 index);
+ TimeBlockTreeNode* getTimeBlockTreeNode(size_t index);
protected:
void init();
@@ -92,7 +91,7 @@ namespace LLTrace
};
- const LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder();
+ ThreadRecorder* get_thread_recorder();
void set_thread_recorder(ThreadRecorder*);
void set_master_thread_recorder(ThreadRecorder*);
diff --git a/indra/llcommon/lluri.cpp b/indra/llcommon/lluri.cpp
index 22711a83d2..4fb92a8f3e 100644
--- a/indra/llcommon/lluri.cpp
+++ b/indra/llcommon/lluri.cpp
@@ -663,9 +663,9 @@ LLSD LLURI::pathArray() const
tokenizer::iterator end = tokens.end();
LLSD params;
- for ( ; it != end; ++it)
+ for (const std::string& str : tokens)
{
- params.append(*it);
+ params.append(str);
}
return params;
}
diff --git a/indra/llcommon/lluuid.cpp b/indra/llcommon/lluuid.cpp
index acce8366ea..fc04dca08d 100644
--- a/indra/llcommon/lluuid.cpp
+++ b/indra/llcommon/lluuid.cpp
@@ -40,11 +40,12 @@
#include "lluuid.h"
#include "llerror.h"
#include "llrand.h"
-#include "llmd5.h"
#include "llstring.h"
#include "lltimer.h"
#include "llthread.h"
#include "llmutex.h"
+#include "llmd5.h"
+#include "hbxxh.h"
const LLUUID LLUUID::null;
const LLTransactionID LLTransactionID::tnull;
@@ -400,6 +401,9 @@ LLUUID LLUUID::operator^(const LLUUID& rhs) const
return id;
}
+// WARNING: this algorithm SHALL NOT be changed. It is also used by the server
+// and plays a role in some assets validation (e.g. clothing items). Changing
+// it would cause invalid assets.
void LLUUID::combine(const LLUUID& other, LLUUID& result) const
{
LLMD5 md5_uuid;
@@ -857,17 +861,12 @@ void LLUUID::generate()
tmp >>= 8;
mData[8] = (unsigned char) tmp;
- LLMD5 md5_uuid;
-
- md5_uuid.update(mData,16);
- md5_uuid.finalize();
- md5_uuid.raw_digest(mData);
+ HBXXH128::digest(*this, (const void*)mData, 16);
}
void LLUUID::generate(const std::string& hash_string)
{
- LLMD5 md5_uuid((U8*)hash_string.c_str());
- md5_uuid.raw_digest(mData);
+ HBXXH128::digest(*this, hash_string);
}
U32 LLUUID::getRandomSeed()
@@ -885,13 +884,8 @@ U32 LLUUID::getRandomSeed()
seed[7]=(unsigned char)(pid);
getSystemTime((uuid_time_t *)(&seed[8]));
- LLMD5 md5_seed;
-
- md5_seed.update(seed,16);
- md5_seed.finalize();
- md5_seed.raw_digest(seed);
-
- return(*(U32 *)seed);
+ U64 seed64 = HBXXH64((const void*)seed, 16).digest();
+ return U32(seed64) ^ U32(seed64 >> 32);
}
BOOL LLUUID::parseUUID(const std::string& buf, LLUUID* value)
@@ -1009,36 +1003,6 @@ LLUUID::LLUUID()
return !(word[0] | word[1] | word[2] | word[3]);
}
-// Copy constructor
- LLUUID::LLUUID(const LLUUID& rhs)
-{
- U32 *tmp = (U32 *)mData;
- U32 *rhstmp = (U32 *)rhs.mData;
- tmp[0] = rhstmp[0];
- tmp[1] = rhstmp[1];
- tmp[2] = rhstmp[2];
- tmp[3] = rhstmp[3];
-}
-
- LLUUID::~LLUUID()
-{
-}
-
-// Assignment
- LLUUID& LLUUID::operator=(const LLUUID& rhs)
-{
- // No need to check the case where this==&rhs. The branch is slower than the write.
- U32 *tmp = (U32 *)mData;
- U32 *rhstmp = (U32 *)rhs.mData;
- tmp[0] = rhstmp[0];
- tmp[1] = rhstmp[1];
- tmp[2] = rhstmp[2];
- tmp[3] = rhstmp[3];
-
- return *this;
-}
-
-
LLUUID::LLUUID(const char *in_string)
{
if (!in_string || in_string[0] == 0)
diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h
index 86a396ab06..c139c4eb4e 100644
--- a/indra/llcommon/lluuid.h
+++ b/indra/llcommon/lluuid.h
@@ -55,10 +55,7 @@ public:
LLUUID();
explicit LLUUID(const char *in_string); // Convert from string.
explicit LLUUID(const std::string& in_string); // Convert from string.
- LLUUID(const LLUUID &in);
- LLUUID &operator=(const LLUUID &rhs);
-
- ~LLUUID();
+ ~LLUUID() = default;
//
// MANIPULATORS
@@ -131,6 +128,9 @@ public:
U8 mData[UUID_BYTES];
};
+static_assert(std::is_trivially_copyable<LLUUID>::value, "LLUUID must be trivial copy");
+static_assert(std::is_trivially_move_assignable<LLUUID>::value, "LLUUID must be trivial move");
+static_assert(std::is_standard_layout<LLUUID>::value, "LLUUID must be a standard layout type");
typedef std::vector<LLUUID> uuid_vec_t;
typedef std::set<LLUUID> uuid_set_t;
diff --git a/indra/llcommon/llworkerthread.cpp b/indra/llcommon/llworkerthread.cpp
index 4b91b2caca..e5eda1eac7 100644
--- a/indra/llcommon/llworkerthread.cpp
+++ b/indra/llcommon/llworkerthread.cpp
@@ -69,11 +69,11 @@ void LLWorkerThread::clearDeleteList()
<< " entries in delete list." << LL_ENDL;
mDeleteMutex->lock();
- for (delete_list_t::iterator iter = mDeleteList.begin(); iter != mDeleteList.end(); ++iter)
+ for (LLWorkerClass* worker : mDeleteList)
{
- (*iter)->mRequestHandle = LLWorkerThread::nullHandle();
- (*iter)->clearFlags(LLWorkerClass::WCF_HAVE_WORK);
- delete *iter ;
+ worker->mRequestHandle = LLWorkerThread::nullHandle();
+ worker->clearFlags(LLWorkerClass::WCF_HAVE_WORK);
+ delete worker;
}
mDeleteList.clear() ;
mDeleteMutex->unlock() ;
@@ -81,9 +81,9 @@ void LLWorkerThread::clearDeleteList()
}
// virtual
-S32 LLWorkerThread::update(F32 max_time_ms)
+size_t LLWorkerThread::update(F32 max_time_ms)
{
- S32 res = LLQueuedThread::update(max_time_ms);
+ auto res = LLQueuedThread::update(max_time_ms);
// Delete scheduled workers
std::vector<LLWorkerClass*> delete_list;
std::vector<LLWorkerClass*> abort_list;
@@ -108,15 +108,12 @@ S32 LLWorkerThread::update(F32 max_time_ms)
}
mDeleteMutex->unlock();
// abort and delete after releasing mutex
- for (std::vector<LLWorkerClass*>::iterator iter = abort_list.begin();
- iter != abort_list.end(); ++iter)
+ for (LLWorkerClass* worker : abort_list)
{
- (*iter)->abortWork(false);
+ worker->abortWork(false);
}
- for (std::vector<LLWorkerClass*>::iterator iter = delete_list.begin();
- iter != delete_list.end(); ++iter)
+ for (LLWorkerClass* worker : delete_list)
{
- LLWorkerClass* worker = *iter;
if (worker->mRequestHandle)
{
// Finished but not completed
@@ -124,7 +121,7 @@ S32 LLWorkerThread::update(F32 max_time_ms)
worker->mRequestHandle = LLWorkerThread::nullHandle();
worker->clearFlags(LLWorkerClass::WCF_HAVE_WORK);
}
- delete *iter;
+ delete worker;
}
// delete and aborted entries mean there's still work to do
res += delete_list.size() + abort_list.size();
diff --git a/indra/llcommon/llworkerthread.h b/indra/llcommon/llworkerthread.h
index 0387e75c65..e3004d7242 100644
--- a/indra/llcommon/llworkerthread.h
+++ b/indra/llcommon/llworkerthread.h
@@ -88,7 +88,7 @@ public:
LLWorkerThread(const std::string& name, bool threaded = true, bool should_pause = false);
~LLWorkerThread();
- /*virtual*/ S32 update(F32 max_time_ms);
+ /*virtual*/ size_t update(F32 max_time_ms);
handle_t addWorkRequest(LLWorkerClass* workerclass, S32 param, U32 priority = PRIORITY_NORMAL);
diff --git a/indra/llcommon/stdtypes.h b/indra/llcommon/stdtypes.h
index b07805b628..da8512169c 100644
--- a/indra/llcommon/stdtypes.h
+++ b/indra/llcommon/stdtypes.h
@@ -26,16 +26,23 @@
#ifndef LL_STDTYPES_H
#define LL_STDTYPES_H
+#include <cassert>
#include <cfloat>
#include <climits>
+#include <limits>
+#include <type_traits>
-typedef signed char S8;
+typedef signed char S8;
typedef unsigned char U8;
typedef signed short S16;
typedef unsigned short U16;
-typedef signed int S32;
+typedef signed int S32;
typedef unsigned int U32;
+// to express an index that might go negative
+// (ssize_t is provided by SOME compilers, don't collide)
+typedef typename std::make_signed<size_t>::type llssize;
+
#if LL_WINDOWS
// https://docs.microsoft.com/en-us/cpp/build/reference/zc-wchar-t-wchar-t-is-native-type
// https://docs.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp
@@ -45,7 +52,7 @@ typedef unsigned int U32;
// The version of clang available with VS 2019 also defines wchar_t as __wchar_t
// which is also 16 bits.
// In any case, llwchar should be a UTF-32 type.
-typedef U32 llwchar;
+typedef U32 llwchar;
#else
typedef wchar_t llwchar;
// What we'd actually want is a simple module-scope 'if constexpr' to test
@@ -76,7 +83,7 @@ typedef double F64;
typedef S32 BOOL;
typedef U8 KEY;
typedef U32 MASK;
-typedef U32 TPACKETID;
+typedef U32 TPACKETID;
// Use #define instead of consts to avoid conversion headaches
#define S8_MAX (SCHAR_MAX)
@@ -118,4 +125,95 @@ typedef U8 LLPCode;
typedef int intptr_t;
#endif
+/*****************************************************************************
+* Narrowing
+*****************************************************************************/
+/**
+ * narrow() is used to cast a wider type to a narrower type with validation.
+ *
+ * In many cases we take the size() of a container and try to pass it to an
+ * S32 or a U32 parameter. We used to be able to assume that the size of
+ * anything we could fit into memory could be expressed as a 32-bit int. With
+ * 64-bit viewers, though, size_t as returned by size() and length() and so
+ * forth is 64 bits, and the compiler is unhappy about stuffing such values
+ * into 32-bit types.
+ *
+ * It works to force the compiler to truncate, e.g. static_cast<S32>(len) or
+ * S32(len) or (S32)len, but we can do better.
+ *
+ * For:
+ * @code
+ * std::vector<Object> container;
+ * void somefunc(S32 size);
+ * @endcode
+ * call:
+ * @code
+ * somefunc(narrow(container.size()));
+ * @endcode
+ *
+ * narrow() truncates but, in RelWithDebInfo builds, it validates (using
+ * assert()) that the passed value can validly be expressed by the destination
+ * type.
+ */
+// narrow_holder is a struct that accepts the passed value as its original
+// type and provides templated conversion functions to other types. Once we're
+// building with compilers that support Class Template Argument Deduction, we
+// can rename this class template 'narrow' and eliminate the narrow() factory
+// function below.
+template <typename FROM>
+class narrow_holder
+{
+private:
+ FROM mValue;
+
+public:
+ narrow_holder(FROM value): mValue(value) {}
+
+ /*---------------------- Narrowing unsigned to signed ----------------------*/
+ template <typename TO,
+ typename std::enable_if<std::is_unsigned<FROM>::value &&
+ std::is_signed<TO>::value,
+ bool>::type = true>
+ inline
+ operator TO() const
+ {
+ // The reason we skip the
+ // assert(value >= std::numeric_limits<TO>::lowest());
+ // like the overload below is that to perform the above comparison,
+ // the compiler promotes the signed lowest() to the unsigned FROM
+ // type, making it hugely positive -- so a reasonable 'value' will
+ // always fail the assert().
+ assert(mValue <= std::numeric_limits<TO>::max());
+ return static_cast<TO>(mValue);
+ }
+
+ /*----------------------- Narrowing all other cases ------------------------*/
+ template <typename TO,
+ typename std::enable_if<! (std::is_unsigned<FROM>::value &&
+ std::is_signed<TO>::value),
+ bool>::type = true>
+ inline
+ operator TO() const
+ {
+ // two different assert()s so we can tell which condition failed
+ assert(mValue <= std::numeric_limits<TO>::max());
+ // Funny, with floating point types min() is "positive epsilon" rather
+ // than "largest negative" -- that's lowest().
+ assert(mValue >= std::numeric_limits<TO>::lowest());
+ // Do we really expect to use this with floating point types?
+ // If so, does it matter if a very small value truncates to zero?
+ //assert(fabs(mValue) >= std::numeric_limits<TO>::min());
+ return static_cast<TO>(mValue);
+ }
+};
+
+/// narrow() factory function returns a narrow_holder<FROM>(), which can be
+/// implicitly converted to the target type.
+template <typename FROM>
+inline
+narrow_holder<FROM> narrow(FROM value)
+{
+ return { value };
+}
+
#endif
diff --git a/indra/llcommon/stringize.h b/indra/llcommon/stringize.h
index 12df693910..c0b13135f9 100644
--- a/indra/llcommon/stringize.h
+++ b/indra/llcommon/stringize.h
@@ -30,7 +30,7 @@
#define LL_STRINGIZE_H
#include <sstream>
-#include <llstring.h>
+#include "llstring.h"
#include <boost/call_traits.hpp>
/**
diff --git a/indra/llcommon/tests/classic_callback_test.cpp b/indra/llcommon/tests/classic_callback_test.cpp
new file mode 100644
index 0000000000..c060775c24
--- /dev/null
+++ b/indra/llcommon/tests/classic_callback_test.cpp
@@ -0,0 +1,144 @@
+/**
+ * @file classic_callback_test.cpp
+ * @author Nat Goodspeed
+ * @date 2021-09-22
+ * @brief Test ClassicCallback and HeapClassicCallback.
+ *
+ * $LicenseInfo:firstyear=2021&license=viewerlgpl$
+ * Copyright (c) 2021, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+// Precompiled header
+#include "linden_common.h"
+// associated header
+#include "classic_callback.h"
+// STL headers
+#include <iostream>
+#include <string>
+// std headers
+// external library headers
+// other Linden headers
+#include "../test/lltut.h"
+
+/*****************************************************************************
+* example callback
+*****************************************************************************/
+// callback_t is part of the specification of someAPI()
+typedef void (*callback_t)(const char*, void*);
+void someAPI(callback_t callback, void* userdata)
+{
+ callback("called", userdata);
+}
+
+// C++ callable I want as the actual callback
+struct MyCallback
+{
+ void operator()(const char* msg, void*)
+ {
+ mMsg = msg;
+ }
+
+ void callback_with_extra(const std::string& extra, const char* msg)
+ {
+ mMsg = extra + ' ' + msg;
+ }
+
+ std::string mMsg;
+};
+
+/*****************************************************************************
+* example callback accepting several params, and void* userdata isn't first
+*****************************************************************************/
+typedef std::string (*complex_callback)(int, const char*, void*, double);
+std::string otherAPI(complex_callback callback, void* userdata)
+{
+ return callback(17, "hello world", userdata, 3.0);
+}
+
+// struct into which we can capture complex_callback params
+static struct Data
+{
+ void set(int i, const char* s, double f)
+ {
+ mi = i;
+ ms = s;
+ mf = f;
+ }
+
+ void clear() { set(0, "", 0.0); }
+
+ int mi;
+ std::string ms;
+ double mf;
+} sData;
+
+// C++ callable I want to pass
+struct OtherCallback
+{
+ std::string operator()(int num, const char* str, void*, double approx)
+ {
+ sData.set(num, str, approx);
+ return "hello back!";
+ }
+};
+
+/*****************************************************************************
+* TUT
+*****************************************************************************/
+namespace tut
+{
+ struct classic_callback_data
+ {
+ };
+ typedef test_group<classic_callback_data> classic_callback_group;
+ typedef classic_callback_group::object object;
+ classic_callback_group classic_callbackgrp("classic_callback");
+
+ template<> template<>
+ void object::test<1>()
+ {
+ set_test_name("ClassicCallback");
+ // engage someAPI(MyCallback())
+ auto ccb{ makeClassicCallback<callback_t>(MyCallback()) };
+ someAPI(ccb.get_callback(), ccb.get_userdata());
+ // Unfortunately, with the side effect confined to the bound
+ // MyCallback instance, that call was invisible. Bind a reference to a
+ // named instance by specifying a ref type.
+ MyCallback mcb;
+ ClassicCallback<callback_t, void*, MyCallback&> ccb2(mcb);
+ someAPI(ccb2.get_callback(), ccb2.get_userdata());
+ ensure_equals("failed to call through ClassicCallback", mcb.mMsg, "called");
+
+ // try with HeapClassicCallback
+ mcb.mMsg.clear();
+ auto hcbp{ makeHeapClassicCallback<callback_t>(mcb) };
+ someAPI(hcbp->get_callback(), hcbp->get_userdata());
+ ensure_equals("failed to call through HeapClassicCallback", mcb.mMsg, "called");
+
+ // lambda
+ // The tricky thing here is that a lambda is an unspecified type, so
+ // you can't declare a ClassicCallback<signature, void*, that type>.
+ mcb.mMsg.clear();
+ auto xcb(
+ makeClassicCallback<callback_t>(
+ [&mcb](const char* msg, void*)
+ { mcb.callback_with_extra("extra", msg); }));
+ someAPI(xcb.get_callback(), xcb.get_userdata());
+ ensure_equals("failed to call lambda", mcb.mMsg, "extra called");
+
+ // engage otherAPI(OtherCallback())
+ OtherCallback ocb;
+ // Instead of specifying a reference type for the bound CALLBACK, as
+ // with ccb2 above, you can alternatively move the callable object
+ // into the ClassicCallback (of course AFTER any other reference).
+ // That's why OtherCallback uses external data for its observable side
+ // effect.
+ auto occb{ makeClassicCallback<complex_callback>(std::move(ocb)) };
+ std::string result{ otherAPI(occb.get_callback(), occb.get_userdata()) };
+ ensure_equals("failed to return callback result", result, "hello back!");
+ ensure_equals("failed to set int", sData.mi, 17);
+ ensure_equals("failed to set string", sData.ms, "hello world");
+ ensure_equals("failed to set double", sData.mf, 3.0);
+ }
+} // namespace tut
diff --git a/indra/llcommon/tests/lleventdispatcher_test.cpp b/indra/llcommon/tests/lleventdispatcher_test.cpp
index 82a0ddf61b..b38e47a773 100644
--- a/indra/llcommon/tests/lleventdispatcher_test.cpp
+++ b/indra/llcommon/tests/lleventdispatcher_test.cpp
@@ -336,7 +336,7 @@ namespace tut
// Full, partial defaults arrays for params for freena(), freenb()
LLSD dft_array_full, dft_array_partial;
// Start index of partial defaults arrays
- const LLSD::Integer partial_offset;
+ const size_t partial_offset;
// Full, partial defaults maps for params for freena(), freenb()
LLSD dft_map_full, dft_map_partial;
// Most of the above are indexed by "a" or "b". Useful to have an
@@ -346,7 +346,7 @@ namespace tut
lleventdispatcher_data():
work("test dispatcher", "op"),
// map {d=double, array=[3 elements]}
- required(LLSDMap("d", LLSD::Real(0))("array", LLSDArray(LLSD())(LLSD())(LLSD()))),
+ required(LLSDMap("d", LLSD::Real(0))("array", llsd::array(LLSD(), LLSD(), LLSD()))),
// first several params are required, last couple optional
partial_offset(3)
{
@@ -435,8 +435,8 @@ namespace tut
// freena(), methodna(), cmethodna(), smethodna() all take same param list.
// Same for freenb() et al.
- params = LLSDMap("a", LLSDArray("b")("i")("f")("d")("cp"))
- ("b", LLSDArray("s")("uuid")("date")("uri")("bin"));
+ params = LLSDMap("a", llsd::array("b", "i", "f", "d", "cp"))
+ ("b", llsd::array("s", "uuid", "date", "uri", "bin"));
debug("params:\n",
params, "\n"
"params[\"a\"]:\n",
@@ -453,12 +453,12 @@ namespace tut
// LLDate values are, as long as they're different from the
// LLUUID() and LLDate() default values so inspect() will report
// them.
- dft_array_full = LLSDMap("a", LLSDArray(true)(17)(3.14)(123456.78)("classic"))
- ("b", LLSDArray("string")
- (LLUUID::generateNewID())
- (LLDate::now())
- (LLURI("http://www.ietf.org/rfc/rfc3986.txt"))
- (binary));
+ dft_array_full = LLSDMap("a", llsd::array(true, 17, 3.14, 123456.78, "classic"))
+ ("b", llsd::array("string",
+ LLUUID::generateNewID(),
+ LLDate::now(),
+ LLURI("http://www.ietf.org/rfc/rfc3986.txt"),
+ binary));
debug("dft_array_full:\n",
dft_array_full);
// Partial defaults arrays.
@@ -757,7 +757,7 @@ namespace tut
{
set_test_name("map-style registration with non-array params");
// Pass "param names" as scalar or as map
- LLSD attempts(LLSDArray(17)(LLSDMap("pi", 3.14)("two", 2)));
+ LLSD attempts(llsd::array(17, LLSDMap("pi", 3.14)("two", 2)));
foreach(LLSD ae, inArray(attempts))
{
std::string threw = catch_what<std::exception>([this, &ae](){
@@ -772,7 +772,7 @@ namespace tut
{
set_test_name("map-style registration with badly-formed defaults");
std::string threw = catch_what<std::exception>([this](){
- work.add("freena_err", "freena", freena, LLSDArray("a")("b"), 17);
+ work.add("freena_err", "freena", freena, llsd::array("a", "b"), 17);
});
ensure_has(threw, "must be a map or an array");
}
@@ -783,8 +783,8 @@ namespace tut
set_test_name("map-style registration with too many array defaults");
std::string threw = catch_what<std::exception>([this](){
work.add("freena_err", "freena", freena,
- LLSDArray("a")("b"),
- LLSDArray(17)(0.9)("gack"));
+ llsd::array("a", "b"),
+ llsd::array(17, 0.9, "gack"));
});
ensure_has(threw, "shorter than");
}
@@ -795,7 +795,7 @@ namespace tut
set_test_name("map-style registration with too many map defaults");
std::string threw = catch_what<std::exception>([this](){
work.add("freena_err", "freena", freena,
- LLSDArray("a")("b"),
+ llsd::array("a", "b"),
LLSDMap("b", 17)("foo", 3.14)("bar", "sinister"));
});
ensure_has(threw, "nonexistent params");
@@ -832,7 +832,7 @@ namespace tut
void object::test<8>()
{
set_test_name("query Callables with/out required params");
- LLSD names(LLSDArray("free1")("Dmethod1")("Dcmethod1")("method1"));
+ LLSD names(llsd::array("free1", "Dmethod1", "Dcmethod1", "method1"));
foreach(LLSD nm, inArray(names))
{
LLSD metadata(getMetadata(nm));
@@ -855,13 +855,13 @@ namespace tut
{
set_test_name("query array-style functions/methods");
// Associate each registered name with expected arity.
- LLSD expected(LLSDArray
- (LLSDArray
- (0)(LLSDArray("free0_array")("smethod0_array")("method0_array")))
- (LLSDArray
- (5)(LLSDArray("freena_array")("smethodna_array")("methodna_array")))
- (LLSDArray
- (5)(LLSDArray("freenb_array")("smethodnb_array")("methodnb_array"))));
+ LLSD expected(llsd::array
+ (llsd::array
+ (0, llsd::array("free0_array", "smethod0_array", "method0_array")),
+ llsd::array
+ (5, llsd::array("freena_array", "smethodna_array", "methodna_array")),
+ llsd::array
+ (5, llsd::array("freenb_array", "smethodnb_array", "methodnb_array"))));
foreach(LLSD ae, inArray(expected))
{
LLSD::Integer arity(ae[0].asInteger());
@@ -887,7 +887,7 @@ namespace tut
set_test_name("query map-style no-params functions/methods");
// - (Free function | non-static method), map style, no params (ergo
// no defaults)
- LLSD names(LLSDArray("free0_map")("smethod0_map")("method0_map"));
+ LLSD names(llsd::array("free0_map", "smethod0_map", "method0_map"));
foreach(LLSD nm, inArray(names))
{
LLSD metadata(getMetadata(nm));
@@ -911,13 +911,13 @@ namespace tut
// there should (!) be no difference beween array defaults and map
// defaults. Verify, so we can ignore the distinction for all other
// tests.
- LLSD equivalences(LLSDArray
- (LLSDArray("freena_map_adft")("freena_map_mdft"))
- (LLSDArray("freenb_map_adft")("freenb_map_mdft"))
- (LLSDArray("smethodna_map_adft")("smethodna_map_mdft"))
- (LLSDArray("smethodnb_map_adft")("smethodnb_map_mdft"))
- (LLSDArray("methodna_map_adft")("methodna_map_mdft"))
- (LLSDArray("methodnb_map_adft")("methodnb_map_mdft")));
+ LLSD equivalences(llsd::array
+ (llsd::array("freena_map_adft", "freena_map_mdft"),
+ llsd::array("freenb_map_adft", "freenb_map_mdft"),
+ llsd::array("smethodna_map_adft", "smethodna_map_mdft"),
+ llsd::array("smethodnb_map_adft", "smethodnb_map_mdft"),
+ llsd::array("methodna_map_adft", "methodna_map_mdft"),
+ llsd::array("methodnb_map_adft", "methodnb_map_mdft")));
foreach(LLSD eq, inArray(equivalences))
{
LLSD adft(eq[0]);
@@ -987,42 +987,42 @@ namespace tut
debug("skipreq:\n",
skipreq);
- LLSD groups(LLSDArray // array of groups
+ LLSD groups(llsd::array // array of groups
- (LLSDArray // group
- (LLSDArray("freena_map_allreq")("smethodna_map_allreq")("methodna_map_allreq"))
- (LLSDArray(allreq["a"])(LLSD()))) // required, optional
+ (llsd::array // group
+ (llsd::array("freena_map_allreq", "smethodna_map_allreq", "methodna_map_allreq"),
+ llsd::array(allreq["a"], LLSD())), // required, optional
- (LLSDArray // group
- (LLSDArray("freenb_map_allreq")("smethodnb_map_allreq")("methodnb_map_allreq"))
- (LLSDArray(allreq["b"])(LLSD()))) // required, optional
+ llsd::array // group
+ (llsd::array("freenb_map_allreq", "smethodnb_map_allreq", "methodnb_map_allreq"),
+ llsd::array(allreq["b"], LLSD())), // required, optional
- (LLSDArray // group
- (LLSDArray("freena_map_leftreq")("smethodna_map_leftreq")("methodna_map_leftreq"))
- (LLSDArray(leftreq["a"])(rightdft["a"]))) // required, optional
+ llsd::array // group
+ (llsd::array("freena_map_leftreq", "smethodna_map_leftreq", "methodna_map_leftreq"),
+ llsd::array(leftreq["a"], rightdft["a"])), // required, optional
- (LLSDArray // group
- (LLSDArray("freenb_map_leftreq")("smethodnb_map_leftreq")("methodnb_map_leftreq"))
- (LLSDArray(leftreq["b"])(rightdft["b"]))) // required, optional
+ llsd::array // group
+ (llsd::array("freenb_map_leftreq", "smethodnb_map_leftreq", "methodnb_map_leftreq"),
+ llsd::array(leftreq["b"], rightdft["b"])), // required, optional
- (LLSDArray // group
- (LLSDArray("freena_map_skipreq")("smethodna_map_skipreq")("methodna_map_skipreq"))
- (LLSDArray(skipreq["a"])(dft_map_partial["a"]))) // required, optional
+ llsd::array // group
+ (llsd::array("freena_map_skipreq", "smethodna_map_skipreq", "methodna_map_skipreq"),
+ llsd::array(skipreq["a"], dft_map_partial["a"])), // required, optional
- (LLSDArray // group
- (LLSDArray("freenb_map_skipreq")("smethodnb_map_skipreq")("methodnb_map_skipreq"))
- (LLSDArray(skipreq["b"])(dft_map_partial["b"]))) // required, optional
+ llsd::array // group
+ (llsd::array("freenb_map_skipreq", "smethodnb_map_skipreq", "methodnb_map_skipreq"),
+ llsd::array(skipreq["b"], dft_map_partial["b"])), // required, optional
- // We only need mention the full-map-defaults ("_mdft" suffix)
- // registrations, having established their equivalence with the
- // full-array-defaults ("_adft" suffix) registrations in another test.
- (LLSDArray // group
- (LLSDArray("freena_map_mdft")("smethodna_map_mdft")("methodna_map_mdft"))
- (LLSDArray(LLSD::emptyMap())(dft_map_full["a"]))) // required, optional
+ // We only need mention the full-map-defaults ("_mdft" suffix)
+ // registrations, having established their equivalence with the
+ // full-array-defaults ("_adft" suffix) registrations in another test.
+ llsd::array // group
+ (llsd::array("freena_map_mdft", "smethodna_map_mdft", "methodna_map_mdft"),
+ llsd::array(LLSD::emptyMap(), dft_map_full["a"])), // required, optional
- (LLSDArray // group
- (LLSDArray("freenb_map_mdft")("smethodnb_map_mdft")("methodnb_map_mdft"))
- (LLSDArray(LLSD::emptyMap())(dft_map_full["b"])))); // required, optional
+ llsd::array // group
+ (llsd::array("freenb_map_mdft", "smethodnb_map_mdft", "methodnb_map_mdft"),
+ llsd::array(LLSD::emptyMap(), dft_map_full["b"])))); // required, optional
foreach(LLSD grp, inArray(groups))
{
@@ -1105,7 +1105,7 @@ namespace tut
// with 'required'.
LLSD answer(42);
// LLSD value matching 'required' according to llsd_matches() rules.
- LLSD matching(LLSDMap("d", 3.14)("array", LLSDArray("answer")(true)(answer)));
+ LLSD matching(LLSDMap("d", 3.14)("array", llsd::array("answer", true, answer)));
// Okay, walk through 'tests'.
foreach(const CallablesTriple& tr, tests)
{
@@ -1142,17 +1142,17 @@ namespace tut
call_logerr("free0_map", 17, map_exc);
// Passing an array to a map-style function works now! No longer an
// error case!
-// call_exc("free0_map", LLSDArray("a")("b"), map_exc);
+// call_exc("free0_map", llsd::array("a", "b"), map_exc);
}
template<> template<>
void object::test<18>()
{
set_test_name("call no-args functions");
- LLSD names(LLSDArray
- ("free0_array")("free0_map")
- ("smethod0_array")("smethod0_map")
- ("method0_array")("method0_map"));
+ LLSD names(llsd::array
+ ("free0_array", "free0_map",
+ "smethod0_array", "smethod0_map",
+ "method0_array", "method0_map"));
foreach(LLSD name, inArray(names))
{
// Look up the Vars instance for this function.
@@ -1170,10 +1170,10 @@ namespace tut
}
// Break out this data because we use it in a couple different tests.
- LLSD array_funcs(LLSDArray
- (LLSDMap("a", "freena_array") ("b", "freenb_array"))
- (LLSDMap("a", "smethodna_array")("b", "smethodnb_array"))
- (LLSDMap("a", "methodna_array") ("b", "methodnb_array")));
+ LLSD array_funcs(llsd::array
+ (LLSDMap("a", "freena_array") ("b", "freenb_array"),
+ LLSDMap("a", "smethodna_array")("b", "smethodnb_array"),
+ LLSDMap("a", "methodna_array") ("b", "methodnb_array")));
template<> template<>
void object::test<19>()
@@ -1181,7 +1181,7 @@ namespace tut
set_test_name("call array-style functions with too-short arrays");
// Could have two different too-short arrays, one for *na and one for
// *nb, but since they both take 5 params...
- LLSD tooshort(LLSDArray("this")("array")("too")("short"));
+ LLSD tooshort(llsd::array("this", "array", "too", "short"));
foreach(const LLSD& funcsab, inArray(array_funcs))
{
foreach(const llsd::MapEntry& e, inMap(funcsab))
@@ -1200,12 +1200,12 @@ namespace tut
{
binary.push_back((U8)h);
}
- LLSD args(LLSDMap("a", LLSDArray(true)(17)(3.14)(123.456)("char*"))
- ("b", LLSDArray("string")
- (LLUUID("01234567-89ab-cdef-0123-456789abcdef"))
- (LLDate("2011-02-03T15:07:00Z"))
- (LLURI("http://secondlife.com"))
- (binary)));
+ LLSD args(LLSDMap("a", llsd::array(true, 17, 3.14, 123.456, "char*"))
+ ("b", llsd::array("string",
+ LLUUID("01234567-89ab-cdef-0123-456789abcdef"),
+ LLDate("2011-02-03T15:07:00Z"),
+ LLURI("http://secondlife.com"),
+ binary)));
LLSD argsplus(args);
argsplus["a"].append("bogus");
argsplus["b"].append("bogus");
@@ -1219,7 +1219,7 @@ namespace tut
debug("expect: ", expect);
// Use substantially the same logic for args and argsplus
- LLSD argsarrays(LLSDArray(args)(argsplus));
+ LLSD argsarrays(llsd::array(args, argsplus));
// So i==0 selects 'args', i==1 selects argsplus
for (LLSD::Integer i(0), iend(argsarrays.size()); i < iend; ++i)
{
@@ -1264,8 +1264,8 @@ namespace tut
set_test_name("call map-style functions with (full | oversized) (arrays | maps)");
const char binary[] = "\x99\x88\x77\x66\x55";
LLSD array_full(LLSDMap
- ("a", LLSDArray(false)(255)(98.6)(1024.5)("pointer"))
- ("b", LLSDArray("object")(LLUUID::generateNewID())(LLDate::now())(LLURI("http://wiki.lindenlab.com/wiki"))(LLSD::Binary(boost::begin(binary), boost::end(binary)))));
+ ("a", llsd::array(false, 255, 98.6, 1024.5, "pointer"))
+ ("b", llsd::array("object", LLUUID::generateNewID(), LLDate::now(), LLURI("http://wiki.lindenlab.com/wiki"), LLSD::Binary(boost::begin(binary), boost::end(binary)))));
LLSD array_overfull(array_full);
foreach(LLSD::String a, ab)
{
@@ -1308,20 +1308,20 @@ namespace tut
// parameter defaults should make NO DIFFERENCE WHATSOEVER. Every call
// should pass all params.
LLSD names(LLSDMap
- ("a", LLSDArray
- ("freena_map_allreq") ("smethodna_map_allreq") ("methodna_map_allreq")
- ("freena_map_leftreq")("smethodna_map_leftreq")("methodna_map_leftreq")
- ("freena_map_skipreq")("smethodna_map_skipreq")("methodna_map_skipreq")
- ("freena_map_adft") ("smethodna_map_adft") ("methodna_map_adft")
- ("freena_map_mdft") ("smethodna_map_mdft") ("methodna_map_mdft"))
- ("b", LLSDArray
- ("freenb_map_allreq") ("smethodnb_map_allreq") ("methodnb_map_allreq")
- ("freenb_map_leftreq")("smethodnb_map_leftreq")("methodnb_map_leftreq")
- ("freenb_map_skipreq")("smethodnb_map_skipreq")("methodnb_map_skipreq")
- ("freenb_map_adft") ("smethodnb_map_adft") ("methodnb_map_adft")
- ("freenb_map_mdft") ("smethodnb_map_mdft") ("methodnb_map_mdft")));
+ ("a", llsd::array
+ ("freena_map_allreq", "smethodna_map_allreq", "methodna_map_allreq",
+ "freena_map_leftreq", "smethodna_map_leftreq", "methodna_map_leftreq",
+ "freena_map_skipreq", "smethodna_map_skipreq", "methodna_map_skipreq",
+ "freena_map_adft", "smethodna_map_adft", "methodna_map_adft",
+ "freena_map_mdft", "smethodna_map_mdft", "methodna_map_mdft"))
+ ("b", llsd::array
+ ("freenb_map_allreq", "smethodnb_map_allreq", "methodnb_map_allreq",
+ "freenb_map_leftreq", "smethodnb_map_leftreq", "methodnb_map_leftreq",
+ "freenb_map_skipreq", "smethodnb_map_skipreq", "methodnb_map_skipreq",
+ "freenb_map_adft", "smethodnb_map_adft", "methodnb_map_adft",
+ "freenb_map_mdft", "smethodnb_map_mdft", "methodnb_map_mdft")));
// Treat (full | overfull) (array | map) the same.
- LLSD argssets(LLSDArray(array_full)(array_overfull)(map_full)(map_overfull));
+ LLSD argssets(llsd::array(array_full, array_overfull, map_full, map_overfull));
foreach(const LLSD& args, inArray(argssets))
{
foreach(LLSD::String a, ab)
diff --git a/indra/llcommon/tests/llleap_test.cpp b/indra/llcommon/tests/llleap_test.cpp
index 9754353ab0..7ee36a9ea6 100644
--- a/indra/llcommon/tests/llleap_test.cpp
+++ b/indra/llcommon/tests/llleap_test.cpp
@@ -15,10 +15,10 @@
#include "llleap.h"
// STL headers
// std headers
+#include <functional>
// external library headers
#include <boost/assign/list_of.hpp>
#include <boost/phoenix/core/argument.hpp>
-#include <boost/foreach.hpp>
// other Linden headers
#include "../test/lltut.h"
#include "../test/namedtempfile.h"
@@ -29,7 +29,6 @@
#include "llstring.h"
#include "stringize.h"
#include "StringVec.h"
-#include <functional>
using boost::assign::list_of;
@@ -110,11 +109,6 @@ namespace tut
"import os\n"
"import sys\n"
"\n"
- // Don't forget that this Python script is written to some
- // temp directory somewhere! Its __file__ is useless in
- // finding indra/lib/python. Use our __FILE__, with
- // raw-string syntax to deal with Windows pathnames.
- "mydir = os.path.dirname(r'" << __FILE__ << "')\n"
"from llbase import llsd\n"
"\n"
"class ProtocolError(Exception):\n"
@@ -241,9 +235,9 @@ namespace tut
"import sys\n"
"sys.stderr.write('''Hello from Python!\n"
"note partial line''')\n");
+ StringVec vcommand{ PYTHON, script.getName() };
CaptureLog log(LLError::LEVEL_INFO);
- waitfor(LLLeap::create(get_test_name(),
- sv(list_of(PYTHON)(script.getName()))));
+ waitfor(LLLeap::create(get_test_name(), vcommand));
log.messageWith("Hello from Python!");
log.messageWith("note partial line");
}
@@ -531,7 +525,7 @@ namespace tut
result.ensure();
}
- struct TestLargeMessage: public std::binary_function<size_t, size_t, bool>
+ struct TestLargeMessage
{
TestLargeMessage(const std::string& PYTHON_, const std::string& reader_module_,
const std::string& test_name_):
diff --git a/indra/llcommon/tests/llprocess_test.cpp b/indra/llcommon/tests/llprocess_test.cpp
index 999d432079..81449b4a42 100644
--- a/indra/llcommon/tests/llprocess_test.cpp
+++ b/indra/llcommon/tests/llprocess_test.cpp
@@ -356,7 +356,7 @@ namespace tut
// Create a script file in a temporary place.
NamedTempFile script("py",
- "from __future__ import print_function" EOL
+ "from __future__ import print_function" EOL
"import sys" EOL
"import time" EOL
EOL
@@ -366,7 +366,7 @@ namespace tut
"time.sleep(2)" EOL
"print('stderr after wait',file=sys.stderr)" EOL
"sys.stderr.flush()" EOL
- );
+ );
// Arrange to track the history of our interaction with child: what we
// fetched, which pipe it came from, how many tries it took before we
@@ -862,8 +862,8 @@ namespace tut
set_test_name("'bogus' test");
CaptureLog recorder;
PythonProcessLauncher py(get_test_name(),
- "from __future__ import print_function\n"
- "print('Hello world')\n");
+ "from __future__ import print_function\n"
+ "print('Hello world')\n");
py.mParams.files.add(LLProcess::FileParam("bogus"));
py.mPy = LLProcess::create(py.mParams);
ensure("should have rejected 'bogus'", ! py.mPy);
@@ -878,8 +878,8 @@ namespace tut
// Replace this test with one or more real 'file' tests when we
// implement 'file' support
PythonProcessLauncher py(get_test_name(),
- "from __future__ import print_function\n"
- "print('Hello world')\n");
+ "from __future__ import print_function\n"
+ "print('Hello world')\n");
py.mParams.files.add(LLProcess::FileParam());
py.mParams.files.add(LLProcess::FileParam("file"));
py.mPy = LLProcess::create(py.mParams);
@@ -894,8 +894,8 @@ namespace tut
// implement 'tpipe' support
CaptureLog recorder;
PythonProcessLauncher py(get_test_name(),
- "from __future__ import print_function\n"
- "print('Hello world')\n");
+ "from __future__ import print_function\n"
+ "print('Hello world')\n");
py.mParams.files.add(LLProcess::FileParam());
py.mParams.files.add(LLProcess::FileParam("tpipe"));
py.mPy = LLProcess::create(py.mParams);
@@ -912,8 +912,8 @@ namespace tut
// implement 'npipe' support
CaptureLog recorder;
PythonProcessLauncher py(get_test_name(),
- "from __future__ import print_function\n"
- "print('Hello world')\n");
+ "from __future__ import print_function\n"
+ "print('Hello world')\n");
py.mParams.files.add(LLProcess::FileParam());
py.mParams.files.add(LLProcess::FileParam());
py.mParams.files.add(LLProcess::FileParam("npipe"));
@@ -989,20 +989,20 @@ namespace tut
{
set_test_name("get*Pipe() validation");
PythonProcessLauncher py(get_test_name(),
- "from __future__ import print_function\n"
- "print('this output is expected')\n");
+ "from __future__ import print_function\n"
+ "print('this output is expected')\n");
py.mParams.files.add(LLProcess::FileParam("pipe")); // pipe for stdin
py.mParams.files.add(LLProcess::FileParam()); // inherit stdout
py.mParams.files.add(LLProcess::FileParam("pipe")); // pipe for stderr
py.run();
TEST_getPipe(*py.mPy, getWritePipe, getOptWritePipe,
- LLProcess::STDIN, // VALID
- LLProcess::STDOUT, // NOPIPE
- LLProcess::STDERR); // BADPIPE
+ LLProcess::STDIN, // VALID
+ LLProcess::STDOUT, // NOPIPE
+ LLProcess::STDERR); // BADPIPE
TEST_getPipe(*py.mPy, getReadPipe, getOptReadPipe,
- LLProcess::STDERR, // VALID
- LLProcess::STDOUT, // NOPIPE
- LLProcess::STDIN); // BADPIPE
+ LLProcess::STDERR, // VALID
+ LLProcess::STDOUT, // NOPIPE
+ LLProcess::STDIN); // BADPIPE
}
template<> template<>
@@ -1129,8 +1129,8 @@ namespace tut
{
set_test_name("ReadPipe \"eof\" event");
PythonProcessLauncher py(get_test_name(),
- "from __future__ import print_function\n"
- "print('Hello from Python!')\n");
+ "from __future__ import print_function\n"
+ "print('Hello from Python!')\n");
py.mParams.files.add(LLProcess::FileParam()); // stdin
py.mParams.files.add(LLProcess::FileParam("pipe")); // stdout
py.launch();
diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp
index c246f5ee56..5dbcf4c9b8 100644
--- a/indra/llcommon/tests/llsdserialize_test.cpp
+++ b/indra/llcommon/tests/llsdserialize_test.cpp
@@ -1817,10 +1817,10 @@ namespace tut
{
set_test_name("verify sequence to Python");
- LLSD cdata(LLSDArray(17)(3.14)
- ("This string\n"
- "has several\n"
- "lines."));
+ LLSD cdata(llsd::array(17, 3.14,
+ "This string\n"
+ "has several\n"
+ "lines."));
const char pydata[] =
"def verify(iterable):\n"
diff --git a/indra/llcommon/threadpool.cpp b/indra/llcommon/threadpool.cpp
index ba914035e2..d5adf11264 100644
--- a/indra/llcommon/threadpool.cpp
+++ b/indra/llcommon/threadpool.cpp
@@ -22,6 +22,7 @@
#include "stringize.h"
LL::ThreadPool::ThreadPool(const std::string& name, size_t threads, size_t capacity):
+ super(name),
mQueue(name, capacity),
mName("ThreadPool:" + name),
mThreadCount(threads)
diff --git a/indra/llcommon/threadpool.h b/indra/llcommon/threadpool.h
index b79c9b9090..f8eec3b457 100644
--- a/indra/llcommon/threadpool.h
+++ b/indra/llcommon/threadpool.h
@@ -22,8 +22,10 @@
namespace LL
{
- class ThreadPool
+ class ThreadPool: public LLInstanceTracker<ThreadPool, std::string>
{
+ private:
+ using super = LLInstanceTracker<ThreadPool, std::string>;
public:
/**
* Pass ThreadPool a string name. This can be used to look up the
diff --git a/indra/llcommon/threadsafeschedule.h b/indra/llcommon/threadsafeschedule.h
index 3e0da94c02..92bc7da940 100644
--- a/indra/llcommon/threadsafeschedule.h
+++ b/indra/llcommon/threadsafeschedule.h
@@ -82,7 +82,7 @@ namespace LL
using TimePoint = ThreadSafeSchedulePrivate::TimePoint;
using Clock = TimePoint::clock;
- ThreadSafeSchedule(U32 capacity=1024):
+ ThreadSafeSchedule(size_t capacity=1024):
super(capacity)
{}
@@ -248,7 +248,7 @@ namespace LL
TimePoint until = TimePoint::clock::now() + std::chrono::hours(24);
pop_result popped = tryPopUntil_(lock, until, tt);
if (popped == POPPED)
- return std::move(tt);
+ return tt;
// DONE: throw, just as super::pop() does
if (popped == DONE)
diff --git a/indra/llcommon/workqueue.h b/indra/llcommon/workqueue.h
index 96574a18b9..70fd65bd0c 100644
--- a/indra/llcommon/workqueue.h
+++ b/indra/llcommon/workqueue.h
@@ -403,7 +403,7 @@ namespace LL
[result = std::forward<CALLABLE>(callable)(),
callback = std::move(callback)]
()
- { callback(std::move(result)); };
+ mutable { callback(std::move(result)); };
}
};
@@ -449,7 +449,7 @@ namespace LL
callable = std::move(callable),
callback = std::move(callback)]
()
- {
+ mutable {
// Use postMaybe() below in case this originating WorkQueue
// has been closed or destroyed. Remember, the outer lambda is
// now running on a thread servicing the target WorkQueue, and
@@ -513,7 +513,7 @@ namespace LL
// We dare to bind a reference to Promise because it's
// specifically designed for cross-thread communication.
[&promise, callable = std::move(callable)]()
- {
+ mutable {
try
{
// call the caller's callable and trigger promise with result
@@ -542,7 +542,7 @@ namespace LL
time,
// &promise is designed for cross-thread access
[&promise, callable = std::move(callable)]()
- {
+ mutable {
try
{
callable();