bryancall commented on code in PR #13733:
URL: https://github.com/apache/trafficserver/pull/13733#discussion_r4355540106


##########
src/tscore/Demangle.cc:
##########
@@ -0,0 +1,76 @@
+/** @file
+
+  Readable C++ type names.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "tscore/Demangle.h"
+
+#include <cstdlib>
+#include <cxxabi.h>
+#include <exception>
+
+namespace ts
+{
+std::string
+demangle(std::type_info const &type) noexcept
+{
+  try {
+    int         status = 0;
+    char       *name   = abi::__cxa_demangle(type.name(), nullptr, nullptr, 
&status);
+    std::string result;
+
+    try {
+      result = status == 0 && name != nullptr ? name : type.name();
+    } catch (...) {
+      std::free(name);
+      throw;
+    }
+    std::free(name);
+    return result;
+  } catch (...) {
+    return "<unknown>";
+  }
+}
+
+std::string
+describe_current_exception() noexcept
+{
+  std::exception_ptr const ep = std::current_exception();
+
+  if (!ep) {
+    return "no active exception";
+  }
+
+  try {
+    try {
+      std::rethrow_exception(ep);
+    } catch (std::exception const &ex) {
+      return demangle(typeid(ex)) + ": " + ex.what();
+    } catch (...) {
+      if (std::type_info const *type = abi::__cxa_current_exception_type(); 
type != nullptr) {
+        return "exception of type " + demangle(*type);
+      }
+    }
+  } catch (...) {
+  }
+  return "exception";

Review Comment:
   Changed in f1c2215e13e6, though not by switching to `const char *`: both 
functions return `std::string` and nine other files include the header, so that 
would change the API across the tree. The literal that can allocate is `"no 
active exception"`, which at 19 characters is past libstdc++'s 15-character 
inline buffer, and it sat outside the `try`. It is inside it now, so a failure 
to build it falls through to `return "exception"`. That one and `"<unknown>"` 
in `demangle()` are 9 characters and fit inline on libstdc++ and libc++, so 
neither allocates.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to