From 3cf1766d6291f59b9b236d52aa3756be19c25ec9 Mon Sep 17 00:00:00 2001 From: Yue Ni Date: Wed, 20 Sep 2023 10:44:02 +0800 Subject: [PATCH] Add minimum test case for verifying exported function registration only happens once. --- cpp/src/gandiva/CMakeLists.txt | 1 + cpp/src/gandiva/exported_funcs.h | 4 +-- cpp/src/gandiva/exported_funcs_registry.cc | 2 +- cpp/src/gandiva/exported_funcs_registry.h | 4 +-- .../gandiva/exported_funcs_registry_test.cc | 28 +++++++++++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 cpp/src/gandiva/exported_funcs_registry_test.cc diff --git a/cpp/src/gandiva/CMakeLists.txt b/cpp/src/gandiva/CMakeLists.txt index 732986478453d..6b6743bc8e52f 100644 --- a/cpp/src/gandiva/CMakeLists.txt +++ b/cpp/src/gandiva/CMakeLists.txt @@ -238,6 +238,7 @@ add_gandiva_test(internals-test tree_expr_test.cc encrypt_utils_test.cc expr_decomposer_test.cc + exported_funcs_registry_test.cc expression_registry_test.cc selection_vector_test.cc lru_cache_test.cc diff --git a/cpp/src/gandiva/exported_funcs.h b/cpp/src/gandiva/exported_funcs.h index 9c110282095ea..82aa020a210c0 100644 --- a/cpp/src/gandiva/exported_funcs.h +++ b/cpp/src/gandiva/exported_funcs.h @@ -18,6 +18,7 @@ #pragma once #include +#include "gandiva/visibility.h" namespace gandiva { @@ -61,6 +62,5 @@ class ExportedHashFunctions : public ExportedFuncsBase { void AddMappings(Engine* engine) const override; }; -void RegisterExportedFuncs(); - +GANDIVA_EXPORT void RegisterExportedFuncs(); } // namespace gandiva diff --git a/cpp/src/gandiva/exported_funcs_registry.cc b/cpp/src/gandiva/exported_funcs_registry.cc index e30825cd4c090..78320f4e03a75 100644 --- a/cpp/src/gandiva/exported_funcs_registry.cc +++ b/cpp/src/gandiva/exported_funcs_registry.cc @@ -22,7 +22,7 @@ namespace gandiva { void ExportedFuncsRegistry::AddMappings(Engine* engine) { - for (auto entry : registered()) { + for (const auto& entry : registered()) { entry->AddMappings(engine); } } diff --git a/cpp/src/gandiva/exported_funcs_registry.h b/cpp/src/gandiva/exported_funcs_registry.h index aa9c3e8359e06..639d1def15d10 100644 --- a/cpp/src/gandiva/exported_funcs_registry.h +++ b/cpp/src/gandiva/exported_funcs_registry.h @@ -21,6 +21,7 @@ #include #include +#include namespace gandiva { @@ -28,7 +29,7 @@ class ExportedFuncsBase; /// Registry for classes that export functions which can be accessed by /// LLVM/IR code. -class ExportedFuncsRegistry { +class GANDIVA_EXPORT ExportedFuncsRegistry { public: using list_type = std::vector>; @@ -40,7 +41,6 @@ class ExportedFuncsRegistry { return true; } - private: static list_type& registered(); }; diff --git a/cpp/src/gandiva/exported_funcs_registry_test.cc b/cpp/src/gandiva/exported_funcs_registry_test.cc new file mode 100644 index 0000000000000..06d7f06018216 --- /dev/null +++ b/cpp/src/gandiva/exported_funcs_registry_test.cc @@ -0,0 +1,28 @@ +// 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 "gandiva/exported_funcs_registry.h" +#include +#include "gandiva/exported_funcs.h" + +namespace gandiva { +TEST(ExportedFuncsRegistry, RegistrationOnlyOnce) { + gandiva::RegisterExportedFuncs(); + auto const& registered_list = ExportedFuncsRegistry::registered(); + EXPECT_EQ(registered_list.size(), 6); +} +} // namespace gandiva