This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new c1093a4741 Switch libtscore to static and deal with the fallout (#9974)
c1093a4741 is described below

commit c1093a4741e325b9101c61d4c1d54d4adf8e0f04
Author: Chris McFarlen <[email protected]>
AuthorDate: Thu Jul 13 10:29:32 2023 -0500

    Switch libtscore to static and deal with the fallout (#9974)
    
    This also makes tscppapi and tscpputil shared libraries.
---
 include/tscore/BufferWriter.h                      |  1 -
 include/tscore/Extendible.h                        | 28 +--------
 iocore/aio/CMakeLists.txt                          |  3 +-
 iocore/cache/Makefile.am                           |  2 +-
 iocore/cache/test/stub.cc                          | 67 ----------------------
 iocore/net/CMakeLists.txt                          |  3 -
 src/records/CMakeLists.txt                         | 13 +----
 src/traffic_server/CMakeLists.txt                  |  2 +-
 src/tscore/BufferWriterFormat.cc                   | 26 ++++++---
 src/tscore/CMakeLists.txt                          | 30 ++++------
 src/tscore/Extendible.cc                           | 25 ++++++++
 src/tscore/ink_mutex.cc                            |  3 +-
 src/tscpp/api/CMakeLists.txt                       | 10 ++--
 src/tscpp/util/CMakeLists.txt                      | 15 ++---
 .../gold_tests/pluginTest/TSVConnFd/CMakeLists.txt |  2 +-
 15 files changed, 73 insertions(+), 157 deletions(-)

diff --git a/include/tscore/BufferWriter.h b/include/tscore/BufferWriter.h
index f58dbcf13c..cb3ddbe5ea 100644
--- a/include/tscore/BufferWriter.h
+++ b/include/tscore/BufferWriter.h
@@ -546,7 +546,6 @@ namespace bw_fmt
   /// Global named argument table.
   using GlobalSignature = void (*)(BufferWriter &, BWFSpec const &);
   using GlobalTable     = std::map<std::string_view, GlobalSignature>;
-  extern GlobalTable BWF_GLOBAL_TABLE;
   extern GlobalSignature Global_Table_Find(std::string_view name);
 
   /// Generic integral conversion.
diff --git a/include/tscore/Extendible.h b/include/tscore/Extendible.h
index 069c90d3ba..6e4e4f7439 100644
--- a/include/tscore/Extendible.h
+++ b/include/tscore/Extendible.h
@@ -127,12 +127,7 @@ namespace details // internal stuff
 
   //////////////////////////////////////////
 
-  bool &
-  areFieldsFinalized()
-  {
-    static bool finalized = false;
-    return finalized;
-  }
+  bool &areFieldsFinalized();
 
   /////////////////////////////////////////////////////////////////////
   /// ext::details::FieldDesc - type erased field descriptor, with type 
specific std::functions
@@ -729,7 +724,7 @@ viewFormat(T const &t, uintptr_t _base_addr = 0, int 
_full_size = ext::sizeOf<T>
 
 namespace details
 {
-  std::string
+  inline std::string
   ltrim(std::string const &str, const std::string &chars = "\t\n\v\f\r ")
   {
     std::string r(str);
@@ -779,22 +774,3 @@ toString(T const &t)
   return ss.str();
 }
 } // namespace ext
-
-// C API
-//
-
-FieldPtr
-ExtFieldPtr(DerivedPtr derived, ExtFieldContext field_context, int *size /*= 
nullptr*/)
-{
-  using namespace ext;
-  using namespace ext::details;
-  ink_assert(field_context);
-  ink_assert(derived);
-  FieldDesc const &desc = *static_cast<FieldDesc const *>(field_context);
-  if (size) {
-    *size = desc.size;
-  }
-
-  Offest_t const *loc = (Offest_t const *)(uintptr_t(derived) + 
desc.ext_loc_offset);
-  return FieldPtr(uintptr_t(derived) + (*loc) + desc.field_offset);
-}
diff --git a/iocore/aio/CMakeLists.txt b/iocore/aio/CMakeLists.txt
index aaef0c1402..c6e7df6f7b 100644
--- a/iocore/aio/CMakeLists.txt
+++ b/iocore/aio/CMakeLists.txt
@@ -16,7 +16,6 @@
 #######################
 
 
-add_library(aio)
+add_library(aio STATIC)
 target_sources(aio PRIVATE AIO.cc Inline.cc)
 target_include_directories(aio PRIVATE ${CMAKE_SOURCE_DIR}/iocore/eventsystem 
${CMAKE_SOURCE_DIR}/iocore/io_uring)
-
diff --git a/iocore/cache/Makefile.am b/iocore/cache/Makefile.am
index a0e37c5532..ada3be6d52 100644
--- a/iocore/cache/Makefile.am
+++ b/iocore/cache/Makefile.am
@@ -88,11 +88,11 @@ test_CPPFLAGS = \
        @OPENSSL_INCLUDES@
 
 test_LDADD = \
-       $(top_builddir)/src/tscpp/util/libtscpputil.la \
        $(top_builddir)/iocore/cache/libinkcache.a \
        $(top_builddir)/proxy/libproxy.a \
        $(top_builddir)/proxy/http/libhttp.a \
        $(top_builddir)/proxy/http/remap/libhttp_remap.a \
+       $(top_builddir)/src/tscpp/util/libtscpputil.la \
        $(top_builddir)/proxy/libproxy.a \
        $(top_builddir)/iocore/net/libinknet.a \
        $(top_builddir)/iocore/dns/libinkdns.a \
diff --git a/iocore/cache/test/stub.cc b/iocore/cache/test/stub.cc
index 4849ad8824..1ea495ec96 100644
--- a/iocore/cache/test/stub.cc
+++ b/iocore/cache/test/stub.cc
@@ -107,73 +107,6 @@ ConfigUpdateCbTable *global_config_cbs = nullptr;
 
 HttpBodyFactory *body_factory = nullptr;
 
-intmax_t
-ts::svtoi(TextView src, TextView *out, int base)
-{
-  intmax_t zret = 0;
-
-  if (out) {
-    out->clear();
-  }
-  if (!(0 <= base && base <= 36)) {
-    return 0;
-  }
-  if (src.ltrim_if(&isspace) && src) {
-    const char *start = src.data();
-    int8_t v;
-    bool neg = false;
-    if ('-' == *src) {
-      ++src;
-      neg = true;
-    }
-    // If base is 0, it wasn't specified - check for standard base prefixes
-    if (0 == base) {
-      base = 10;
-      if ('0' == *src) {
-        ++src;
-        base = 8;
-        if (src && ('x' == *src || 'X' == *src)) {
-          ++src;
-          base = 16;
-        }
-      }
-    }
-
-    // For performance in common cases, use the templated conversion.
-    switch (base) {
-    case 8:
-      zret = svto_radix<8>(src);
-      break;
-    case 10:
-      zret = svto_radix<10>(src);
-      break;
-    case 16:
-      zret = svto_radix<16>(src);
-      break;
-    default:
-      while (src.size() && (0 <= (v = svtoi_convert[static_cast<unsigned 
char>(*src)])) && v < base) {
-        auto n = zret * base + v;
-        if (n < zret) {
-          zret = std::numeric_limits<uintmax_t>::max();
-          break; // overflow, stop parsing.
-        }
-        zret = n;
-        ++src;
-      }
-      break;
-    }
-
-    if (out && (src.data() > (neg ? start + 1 : start))) {
-      out->assign(start, src.data());
-    }
-
-    if (neg) {
-      zret = -zret;
-    }
-  }
-  return zret;
-}
-
 void
 HostStatus::setHostStatus(const std::string_view name, const TSHostStatus 
status, const unsigned int down_time,
                           const unsigned int reason)
diff --git a/iocore/net/CMakeLists.txt b/iocore/net/CMakeLists.txt
index 618f2e49d4..663e47dbfe 100644
--- a/iocore/net/CMakeLists.txt
+++ b/iocore/net/CMakeLists.txt
@@ -118,9 +118,6 @@ target_include_directories(inknet PUBLIC
         ${OPENSSL_INCLUDE_DIRS}
         ${YAML_INCLUDE_DIRS}
         )
-if(TS_USE_POSIX_CAP)
-    target_link_libraries(inknet PUBLIC cap::cap)
-endif()
 
 # Fails to link because of circular dep with proxy (ParentSelection)
 # add_executable(test_net unit_tests/test_ProxyProtocol.cc)
diff --git a/src/records/CMakeLists.txt b/src/records/CMakeLists.txt
index a833909460..32e28af9bb 100644
--- a/src/records/CMakeLists.txt
+++ b/src/records/CMakeLists.txt
@@ -15,7 +15,7 @@
 #
 #######################
 
-add_library(records_p SHARED
+add_library(records_p STATIC
         P_RecCore.cc
         RecConfigParse.cc
         RecCore.cc
@@ -42,13 +42,4 @@ target_include_directories(records_p
         "${CMAKE_SOURCE_DIR}/iocore/utils"
 )
 
-target_link_libraries(records_p
-    PUBLIC
-        libswoc
-        #ts::inkevent cyclic dependency; I_RecProcess.h and P_RecProcess.h
-        ts::tscore
-        ts::tscpputil
-        yaml-cpp::yaml-cpp
-)
-
-install(TARGETS records_p)
+target_link_libraries(records_p PUBLIC ts::tscore)
diff --git a/src/traffic_server/CMakeLists.txt 
b/src/traffic_server/CMakeLists.txt
index ce2c2da9fe..895a0e2285 100644
--- a/src/traffic_server/CMakeLists.txt
+++ b/src/traffic_server/CMakeLists.txt
@@ -35,6 +35,7 @@ target_include_directories(traffic_server PRIVATE
 )
 target_link_libraries(traffic_server
     PRIVATE
+        tscore
         http
         http_remap
         http2
@@ -49,7 +50,6 @@ target_link_libraries(traffic_server
         inkcache
         fastlz
         aio
-        tscore
         tscpputil
         proxy
         inknet
diff --git a/src/tscore/BufferWriterFormat.cc b/src/tscore/BufferWriterFormat.cc
index 1551cc061e..bc7c938fe4 100644
--- a/src/tscore/BufferWriterFormat.cc
+++ b/src/tscore/BufferWriterFormat.cc
@@ -217,7 +217,13 @@ BWFSpec::BWFSpec(TextView fmt) : 
_name(fmt.take_prefix_at(':'))
 
 namespace bw_fmt
 {
-  GlobalTable BWF_GLOBAL_TABLE;
+  GlobalTable &
+  bwf_global_table()
+  {
+    static GlobalTable BWF_GLOBAL_TABLE;
+
+    return BWF_GLOBAL_TABLE;
+  }
 
   void
   Err_Bad_Arg_Index(BufferWriter &w, int i, size_t n)
@@ -726,8 +732,9 @@ bw_fmt::GlobalSignature
 bw_fmt::Global_Table_Find(std::string_view name)
 {
   if (name.size()) {
-    auto spot = bw_fmt::BWF_GLOBAL_TABLE.find(name);
-    if (spot != bw_fmt::BWF_GLOBAL_TABLE.end()) {
+    auto &global_table = bw_fmt::bwf_global_table();
+    auto spot          = global_table.find(name);
+    if (spot != global_table.end()) {
       return spot->second;
     }
   }
@@ -749,7 +756,7 @@ FixedBufferWriter::operator>>(int fd) const
 bool
 bwf_register_global(std::string_view name, BWGlobalNameSignature formatter)
 {
-  return ts::bw_fmt::BWF_GLOBAL_TABLE.emplace(name, formatter).second;
+  return ts::bw_fmt::bwf_global_table().emplace(name, formatter).second;
 }
 
 BufferWriter &
@@ -980,11 +987,12 @@ BWF_ThreadName(ts::BufferWriter &w, ts::BWFSpec const 
&spec)
 }
 
 static bool BW_INITIALIZED __attribute__((unused)) = []() -> bool {
-  ts::bw_fmt::BWF_GLOBAL_TABLE.emplace("now", &BWF_Now);
-  ts::bw_fmt::BWF_GLOBAL_TABLE.emplace("tick", &BWF_Tick);
-  ts::bw_fmt::BWF_GLOBAL_TABLE.emplace("timestamp", &BWF_Timestamp);
-  ts::bw_fmt::BWF_GLOBAL_TABLE.emplace("thread-id", &BWF_ThreadID);
-  ts::bw_fmt::BWF_GLOBAL_TABLE.emplace("thread-name", &BWF_ThreadName);
+  auto &global_table = ts::bw_fmt::bwf_global_table();
+  global_table.emplace("now", &BWF_Now);
+  global_table.emplace("tick", &BWF_Tick);
+  global_table.emplace("timestamp", &BWF_Timestamp);
+  global_table.emplace("thread-id", &BWF_ThreadID);
+  global_table.emplace("thread-name", &BWF_ThreadName);
   return true;
 }();
 
diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt
index 385f3e38d9..8e49d73956 100644
--- a/src/tscore/CMakeLists.txt
+++ b/src/tscore/CMakeLists.txt
@@ -29,7 +29,7 @@ add_custom_command(
 
 add_custom_target(ParseRules ALL DEPENDS ParseRulesCType 
ParseRulesCTypeToUpper ParseRulesCTypeToLower)
 
-add_library(tscore SHARED
+add_library(tscore STATIC
         AcidPtr.cc
         AcidPtr.cc
         Arena.cc
@@ -111,30 +111,18 @@ else()
     target_sources(tscore PRIVATE HKDF_openssl.cc)
 endif()
 
+if(TS_USE_POSIX_CAP)
+    target_link_libraries(tscore PUBLIC cap::cap)
+endif()
+
 add_dependencies(tscore ParseRules tscpputil)
 target_include_directories(tscore PRIVATE
         ${CMAKE_CURRENT_BINARY_DIR}
         ${YAML_INCLUDE_DIRS}
 )
-target_link_libraries(tscore
-    PUBLIC
-        libswoc
-        ${OPENSSL_LIBRARIES}
-        ${PCRE_LIBRARIES}
-        resolv
-        tscpputil
-    PRIVATE
-        yaml-cpp::yaml-cpp
-)
-if(TS_USE_HWLOC)
-    target_link_libraries(tscore PUBLIC hwloc::hwloc)
-endif()
 if(TS_HAS_128BIT_CAS AND TS_NEEDS_MCX16_FOR_CAS)
     target_compile_options(tscore PUBLIC "-mcx16")
 endif()
-if(TS_USE_POSIX_CAP)
-    target_link_libraries(tscore PUBLIC cap::cap)
-endif()
 
 add_executable(test_tscore
         unit_tests/test_AcidPtr.cc
@@ -172,6 +160,12 @@ target_link_libraries(test_tscore
     PRIVATE
         libswoc
         tscore
+        yaml-cpp::yaml-cpp
+        libswoc
+        ${OPENSSL_LIBRARIES}
+        ${PCRE_LIBRARIES}
+        resolv
+        tscpputil
 )
 if(TS_USE_HWLOC)
     target_link_libraries(test_tscore PRIVATE hwloc::hwloc)
@@ -179,5 +173,3 @@ endif()
 target_include_directories(test_tscore PRIVATE ${CMAKE_SOURCE_DIR}/include 
${CATCH_INCLUDE_DIR})
 
 add_test(NAME test_tscore COMMAND $<TARGET_FILE:test_tscore>)
-
-install(TARGETS tscore)
diff --git a/src/tscore/Extendible.cc b/src/tscore/Extendible.cc
index cff9556601..4e27c249e1 100644
--- a/src/tscore/Extendible.cc
+++ b/src/tscore/Extendible.cc
@@ -135,6 +135,31 @@ namespace details
   {
     return cnt_constructed == cnt_destructed;
   }
+
+  bool &
+  areFieldsFinalized()
+  {
+    static bool finalized = false;
+    return finalized;
+  }
 } // namespace details
 
 } // namespace ext
+// C API
+//
+
+FieldPtr
+ExtFieldPtr(DerivedPtr derived, ExtFieldContext field_context, int *size /*= 
nullptr*/)
+{
+  using namespace ext;
+  using namespace ext::details;
+  ink_assert(field_context);
+  ink_assert(derived);
+  FieldDesc const &desc = *static_cast<FieldDesc const *>(field_context);
+  if (size) {
+    *size = desc.size;
+  }
+
+  Offest_t const *loc = (Offest_t const *)(uintptr_t(derived) + 
desc.ext_loc_offset);
+  return FieldPtr(uintptr_t(derived) + (*loc) + desc.field_offset);
+}
diff --git a/src/tscore/ink_mutex.cc b/src/tscore/ink_mutex.cc
index 606359b3b9..ccbc0666bc 100644
--- a/src/tscore/ink_mutex.cc
+++ b/src/tscore/ink_mutex.cc
@@ -49,12 +49,11 @@ public:
   pthread_mutexattr_t attr;
 };
 
-static x_pthread_mutexattr_t attr;
-
 void
 ink_mutex_init(ink_mutex *m)
 {
   int error;
+  static x_pthread_mutexattr_t attr;
 
   error = pthread_mutex_init(m, &attr.attr);
   if (unlikely(error != 0)) {
diff --git a/src/tscpp/api/CMakeLists.txt b/src/tscpp/api/CMakeLists.txt
index 22f1b76b14..c31a876bf5 100644
--- a/src/tscpp/api/CMakeLists.txt
+++ b/src/tscpp/api/CMakeLists.txt
@@ -15,7 +15,7 @@
 #
 #######################
 
-add_library(tscppapi STATIC
+add_library(tscppapi SHARED
         AsyncHttpFetch.cc
         AsyncTimer.cc
         CaseInsensitiveStringComparator.cc
@@ -42,8 +42,8 @@ add_library(tscppapi STATIC
         utils_internal.cc
         )
 add_library(ts::tscppapi ALIAS tscppapi)
-
-# server_push_preload plugin links directly to tscppapi
-set_target_properties(tscppapi PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
-
+target_link_libraries(tscppapi
+    PUBLIC
+    libswoc
+    yaml-cpp::yaml-cpp)
 install(TARGETS tscppapi)
diff --git a/src/tscpp/util/CMakeLists.txt b/src/tscpp/util/CMakeLists.txt
index 2d02673fd5..9d5b764b97 100644
--- a/src/tscpp/util/CMakeLists.txt
+++ b/src/tscpp/util/CMakeLists.txt
@@ -23,13 +23,11 @@ add_library(tscpputil SHARED
         YamlCfg.cc
         ts_unit_parser.cc)
 add_library(ts::tscpputil ALIAS tscpputil)
-
 target_link_libraries(tscpputil
-    PUBLIC
-        libswoc
-        # ts::tscore cyclic dependency
-        yaml-cpp::yaml-cpp
-)
+       PUBLIC
+               libswoc
+               yaml-cpp::yaml-cpp)
+install(TARGETS tscpputil)
 
 add_executable(test_tscpputil
         unit_tests/test_IntrusiveDList.cc
@@ -38,11 +36,10 @@ add_executable(test_tscpputil
         unit_tests/test_TextView.cc
         unit_tests/test_Strerror.cc
         unit_tests/test_ts_meta.cc
-       unit_tests/test_time_parser.cc
+        unit_tests/test_time_parser.cc
         unit_tests/unit_test_main.cc
-        )
+)
 target_link_libraries(test_tscpputil PRIVATE tscpputil libswoc)
 target_include_directories(test_tscpputil PRIVATE ${CMAKE_SOURCE_DIR}/include 
${CATCH_INCLUDE_DIR})
-install(TARGETS tscpputil)
 
 add_test(NAME test_tscpputil COMMAND $<TARGET_FILE:test_tscpputil>)
diff --git a/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt 
b/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
index 13817d9175..649ef618cc 100644
--- a/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
+++ b/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
@@ -22,4 +22,4 @@ set_target_properties(TSVConnFd PROPERTIES
     PREFIX ""
     SUFFIX ".so"
 )
-target_link_libraries(TSVConnFd PRIVATE tscore traffic_server)
+target_link_libraries(TSVConnFd PRIVATE traffic_server)

Reply via email to