From 69acc4e79664e6ccbc46b40de9f28bfecdc5e0c6 Mon Sep 17 00:00:00 2001 From: guxinhong Date: Tue, 17 Oct 2023 14:13:35 -0400 Subject: [PATCH 1/8] .. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e56d344..b05264a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ /out/build/x64-Debug /CMakeSettings.json /build -/.vscode \ No newline at end of file +/.vscode +*.exe +*.obj +*.lib From 1e77f950486b5c380b9d07fa24ed30e3a48bfff7 Mon Sep 17 00:00:00 2001 From: PraneethJain Date: Thu, 13 Jun 2024 14:11:46 +0530 Subject: [PATCH 2/8] feat: add priority queue --- CMakeLists.txt | 1 + include/jlcxx/stl.hpp | 22 ++++++++++++++++++++++ src/stl.cpp | 2 ++ src/stl_priority_queue.cpp | 16 ++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/stl_priority_queue.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e4d6eb..f8c58fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ set(JLCXX_STL_SOURCES ${JLCXX_SOURCE_DIR}/stl_valarray.cpp ${JLCXX_SOURCE_DIR}/stl_deque.cpp ${JLCXX_SOURCE_DIR}/stl_queue.cpp + ${JLCXX_SOURCE_DIR}/stl_priority_queue.cpp ${JLCXX_SOURCE_DIR}/stl_set.cpp ${JLCXX_SOURCE_DIR}/stl_multiset.cpp ${JLCXX_SOURCE_DIR}/stl_unordered_set.cpp diff --git a/include/jlcxx/stl.hpp b/include/jlcxx/stl.hpp index 6c95e0f..25b33d8 100644 --- a/include/jlcxx/stl.hpp +++ b/include/jlcxx/stl.hpp @@ -52,6 +52,7 @@ class JLCXX_API StlWrappers TypeWrapper1 valarray; TypeWrapper1 deque; TypeWrapper1 queue; + TypeWrapper1 priority_queue; TypeWrapper1 set; TypeWrapper1 multiset; TypeWrapper1 unordered_set; @@ -71,6 +72,7 @@ void apply_vector(TypeWrapper1& vector); void apply_valarray(TypeWrapper1& valarray); void apply_deque(TypeWrapper1& deque); void apply_queue(TypeWrapper1& queue); +void apply_priority_queue(TypeWrapper1& priority_queue); void apply_set(TypeWrapper1& set); void apply_multiset(TypeWrapper1& multiset); void apply_unordered_set(TypeWrapper1& unordered_set); @@ -254,6 +256,25 @@ struct WrapQueue } }; +struct WrapPriorityQueue +{ + template + void operator()(TypeWrapperT&& wrapped) + { + using WrappedT = typename TypeWrapperT::type; + using T = typename WrappedT::value_type; + + wrapped.template constructor<>(); + wrapped.module().set_override_module(StlWrappers::instance().module()); + wrapped.method("cppsize", &WrappedT::size); + wrapped.method("pq_push!", [] (WrappedT& v, const T& val) { v.push(val); }); + wrapped.method("pq_pop!", [] (WrappedT& v) { v.pop(); }); + wrapped.method("pq_top", [] (WrappedT& v) { return v.top(); }); + wrapped.method("pq_isempty", [] (WrappedT& v) { return v.empty(); }); + wrapped.module().unset_override_module(); + } +}; + struct WrapSetType { template @@ -343,6 +364,7 @@ inline void apply_stl(jlcxx::Module& mod) { TypeWrapper1(mod, StlWrappers::instance().set).apply>(WrapSetType()); TypeWrapper1(mod, StlWrappers::instance().multiset).apply>(WrapMultisetType()); + TypeWrapper1(mod, StlWrappers::instance().priority_queue).apply>(WrapPriorityQueue()); } if constexpr (is_hashable::value) { diff --git a/src/stl.cpp b/src/stl.cpp index 07d4a7b..18f0fb5 100644 --- a/src/stl.cpp +++ b/src/stl.cpp @@ -21,6 +21,7 @@ JLCXX_API void StlWrappers::instantiate(Module& mod) apply_valarray(m_instance->valarray); apply_deque(m_instance->deque); apply_queue(m_instance->queue); + apply_priority_queue(m_instance->priority_queue); apply_set(m_instance->set); apply_multiset(m_instance->multiset); apply_unordered_set(m_instance->unordered_set); @@ -50,6 +51,7 @@ JLCXX_API StlWrappers::StlWrappers(Module& stl) : valarray(stl.add_type>>("StdValArray", julia_type("AbstractVector"))), deque(stl.add_type>>("StdDeque", julia_type("AbstractVector"))), queue(stl.add_type>>("StdQueue", julia_type("AbstractVector"))), + priority_queue(stl.add_type>>("StdPriorityQueue")), set(stl.add_type>>("StdSet")), multiset(stl.add_type>>("StdMultiset")), unordered_set(stl.add_type>>("StdUnorderedSet")), diff --git a/src/stl_priority_queue.cpp b/src/stl_priority_queue.cpp new file mode 100644 index 0000000..c72c492 --- /dev/null +++ b/src/stl_priority_queue.cpp @@ -0,0 +1,16 @@ +#include "jlcxx/stl.hpp" + +namespace jlcxx +{ + +namespace stl +{ + +void apply_priority_queue(TypeWrapper1& priority_queue) +{ + priority_queue.apply_combination(stl::WrapPriorityQueue()); +} + +} + +} \ No newline at end of file From 39ceb66b73d2d69065a3b5b7fa56fb139d50e0ba Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Sat, 15 Jun 2024 13:03:58 +0200 Subject: [PATCH 3/8] Make an exception for bool types in priority_queue --- include/jlcxx/stl.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/jlcxx/stl.hpp b/include/jlcxx/stl.hpp index 25b33d8..80f5c40 100644 --- a/include/jlcxx/stl.hpp +++ b/include/jlcxx/stl.hpp @@ -269,7 +269,14 @@ struct WrapPriorityQueue wrapped.method("cppsize", &WrappedT::size); wrapped.method("pq_push!", [] (WrappedT& v, const T& val) { v.push(val); }); wrapped.method("pq_pop!", [] (WrappedT& v) { v.pop(); }); - wrapped.method("pq_top", [] (WrappedT& v) { return v.top(); }); + if constexpr(std::is_same::value) + { + wrapped.method("pq_top", [] (WrappedT& v) { return bool(v.top()); }); + } + else + { + wrapped.method("pq_top", [] (WrappedT& v) { return v.top(); }); + } wrapped.method("pq_isempty", [] (WrappedT& v) { return v.empty(); }); wrapped.module().unset_override_module(); } From b89ad888b34fd42d7fe49dd5333ab0852d5e0187 Mon Sep 17 00:00:00 2001 From: PraneethJain Date: Fri, 14 Jun 2024 00:39:58 +0530 Subject: [PATCH 4/8] fix: check if std::pair has less than --- include/jlcxx/stl.hpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/jlcxx/stl.hpp b/include/jlcxx/stl.hpp index 80f5c40..595929a 100644 --- a/include/jlcxx/stl.hpp +++ b/include/jlcxx/stl.hpp @@ -339,19 +339,32 @@ struct is_container : std::false_type {}; template struct is_container> : std::true_type {}; +template +struct is_pair : std::false_type {}; + +template +struct is_pair> : std::true_type {}; + template struct container_has_less_than_operator : std::false_type {}; template struct container_has_less_than_operator::value>> : std::conditional_t< - has_less_than_operator::value || container_has_less_than_operator::value, - std::true_type, + std::true_type, + std::false_type> {}; + +template +struct container_has_less_than_operator::value>> + : std::conditional_t< + container_has_less_than_operator::value && + container_has_less_than_operator::value, + std::true_type, std::false_type> {}; template -struct container_has_less_than_operator::value>> +struct container_has_less_than_operator::value && !is_pair::value>> : has_less_than_operator {}; template From 6071314830ea46ceee6368a2fe2aac5cbf1f6af8 Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Sun, 16 Jun 2024 10:40:32 +0200 Subject: [PATCH 5/8] Add test for pair comparison Also: * adds the JLCXX_FORCE_RANGES_OFF compile flag * suppresses warnings when compiling without ranges * bumps version to v0.13.2 --- include/jlcxx/jlcxx_config.hpp | 4 ++-- include/jlcxx/stl.hpp | 2 +- test/CMakeLists.txt | 3 ++- test/test_module.cpp | 5 +++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/jlcxx/jlcxx_config.hpp b/include/jlcxx/jlcxx_config.hpp index 70ae063..613dbfe 100644 --- a/include/jlcxx/jlcxx_config.hpp +++ b/include/jlcxx/jlcxx_config.hpp @@ -16,14 +16,14 @@ #define JLCXX_VERSION_MAJOR 0 #define JLCXX_VERSION_MINOR 13 -#define JLCXX_VERSION_PATCH 0 +#define JLCXX_VERSION_PATCH 2 // From https://stackoverflow.com/questions/5459868/concatenate-int-to-string-using-c-preprocessor #define __JLCXX_STR_HELPER(x) #x #define __JLCXX_STR(x) __JLCXX_STR_HELPER(x) #define JLCXX_VERSION_STRING __JLCXX_STR(JLCXX_VERSION_MAJOR) "." __JLCXX_STR(JLCXX_VERSION_MINOR) "." __JLCXX_STR(JLCXX_VERSION_PATCH) -#if defined(__has_include) && !defined(__FreeBSD__) +#if defined(__has_include) && !defined(__FreeBSD__) && !defined(JLCXX_FORCE_RANGES_OFF) # if __has_include () # define JLCXX_HAS_RANGES # endif diff --git a/include/jlcxx/stl.hpp b/include/jlcxx/stl.hpp index 595929a..9632d34 100644 --- a/include/jlcxx/stl.hpp +++ b/include/jlcxx/stl.hpp @@ -97,7 +97,7 @@ using stltypes = remove_duplicates, fundamental_int_types>, fixed_int_types>>; template -void wrap_range_based_algorithms(TypeWrapperT& wrapped) +void wrap_range_based_algorithms([[maybe_unused]] TypeWrapperT& wrapped) { #ifdef JLCXX_HAS_RANGES using WrappedT = typename TypeWrapperT::type; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f100613..2bcfb66 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,8 @@ include_directories(${CMAKE_SOURCE_DIR}/include) add_executable(test_module test_module.cpp) -target_link_libraries(test_module ${JLCXX_TARGET} ${Julia_LIBRARY}) +set_property(TARGET test_module PROPERTY COMPILE_FLAGS "-std=c++17") +target_link_libraries(test_module ${JLCXX_TARGET} ${JLCXX_STL_TARGET} ${Julia_LIBRARY}) add_test(NAME test_module COMMAND test_module) add_executable(test_type_init test_type_init.cpp) diff --git a/test/test_module.cpp b/test/test_module.cpp index 3b7b559..af5e2a5 100644 --- a/test/test_module.cpp +++ b/test/test_module.cpp @@ -1,5 +1,7 @@ +#define JLCXX_FORCE_RANGES_OFF #include #include +#include namespace test_module { @@ -42,6 +44,9 @@ JLCXX_MODULE register_test_module(jlcxx::Module& mod) mod.add_type("Foo") .method("getx", &Foo::getx); + mod.method("vectortest", [] (std::vector) {}); + mod.method("pairtest", [] (std::vector>) {}); + using namespace jlcxx; mod.add_type, TypeVar<2>, TypeVar<3>>>("ManyParams") From 33e60e9ba505c38395621a8daf55f5c775bb0dd7 Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Sun, 16 Jun 2024 13:00:31 +0200 Subject: [PATCH 6/8] Fix undefined type for pair in test_module --- test/test_module.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_module.cpp b/test/test_module.cpp index af5e2a5..26cdcdf 100644 --- a/test/test_module.cpp +++ b/test/test_module.cpp @@ -44,6 +44,8 @@ JLCXX_MODULE register_test_module(jlcxx::Module& mod) mod.add_type("Foo") .method("getx", &Foo::getx); + mod.add_type>("FooPair"); + mod.method("vectortest", [] (std::vector) {}); mod.method("pairtest", [] (std::vector>) {}); From 96f7608c18c3c5527ec076514ce4edb86a1544eb Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Sun, 16 Jun 2024 15:44:11 +0200 Subject: [PATCH 7/8] Fix link problem on FreeBSD for test_module --- test/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2bcfb66..4216607 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,6 +2,9 @@ include_directories(${CMAKE_SOURCE_DIR}/include) add_executable(test_module test_module.cpp) set_property(TARGET test_module PROPERTY COMPILE_FLAGS "-std=c++17") +if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + set_property(TARGET test_module PROPERTY LINK_OPTIONS "-pthread") +endif() target_link_libraries(test_module ${JLCXX_TARGET} ${JLCXX_STL_TARGET} ${Julia_LIBRARY}) add_test(NAME test_module COMMAND test_module) From d54c038f40a017f63450754f20a6c6c228776ba9 Mon Sep 17 00:00:00 2001 From: mind6 Date: Sun, 16 Jun 2024 11:45:25 -0400 Subject: [PATCH 8/8] fixes Overrides.toml issues on Windows and when using nested CMake projects. --- CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8c58fc..b6b4e0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,10 +244,11 @@ if(WIN32) DEPENDS install WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/.. ) + set(ENV{HOME} $ENV{USERPROFILE}) #on windows the home directory is in USERPROFILE, but libcxxwrap-julia doesn't know this and uses HOME instead. endif() set(OVERRIDES_PATH "$ENV{HOME}/.julia/artifacts/Overrides.toml" CACHE FILEPATH "Path to the Overrides file") -set(OVERRIDE_ROOT "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "Path to the installation or build directory to use") +set(OVERRIDE_ROOT "${CMAKE_BINARY_DIR}" CACHE PATH "Path to the installation or build directory to use") #DLLs are output to CMAKE_BINARY_DIR not CMAKE_CURRENT_BINARY_DIR option(APPEND_OVERRIDES_TOML "Append an entry to the Overrides.toml file to make Julia use the libcxxwrap in the current dir" OFF) if(APPEND_OVERRIDES_TOML) @@ -255,4 +256,11 @@ if(APPEND_OVERRIDES_TOML) [3eaa8342-bff7-56a5-9981-c04077f7cee7] libcxxwrap_julia = \"${OVERRIDE_ROOT}\" " APPEND) + message("Entry added to ${OVERRIDES_PATH}: CxxWrap will use ${OVERRIDE_ROOT}") endif() + +set(JlCxx_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) #this allows find_package(JlCxx) to work from the top level CMake file + +# include(CMakePrintHelpers) +# cmake_print_variables(CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR OVERRIDE_ROOT) +# cmake_print_properties(TARGETS cxxwrap_julia cxxwrap_julia_stl PROPERTIES BINARY_DIR INCLUDE_DIRECTORIES LINK_LIBRARIES)