Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StdFill #147

Merged
merged 10 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/test-linux-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: test-linux-mac
on:
- push
- pull_request

defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -15,12 +15,12 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- 'nightly'
- "1.6"
- "1.10"
- "nightly"
os:
- ubuntu-latest
- macOS-latest
- macos-13
arch:
- x64
steps:
Expand Down
42 changes: 17 additions & 25 deletions .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: test-win

on:
- push
- pull_request

defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -15,9 +16,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- 'nightly'
- "1.7"
- "1.10"
- "nightly"
os:
- windows-latest
arch:
Expand All @@ -26,28 +27,19 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- name: Config 32bit
if: ${{ matrix.arch == 'x86'}}
- name: Config and Test
run: |
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A Win32 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
- name: Config 64bit
if: ${{ matrix.arch == 'x64'}}
run: |
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
- name: Test
run: |
body="${{github.event.pull_request.body}}"
package="$(echo "$body" | sed -n '1p')"
cd build
cmake --build . --config Release
julia -e "using Pkg; Pkg.Registry.add(\"General\"); Pkg.Registry.add(RegistrySpec(url = \"https://github.com/barche/CxxWrapTestRegistry.git\"))"
julia -e "using Pkg; pkg\"add ${package}\"; using CxxWrap"
ctest -j 1 -C Release -V
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
body="${{github.event.pull_request.body}}"
package="$(echo "$body" | sed -n '1p')"
cmake --build . --config Release
julia -e "using Pkg; Pkg.Registry.add(\"General\"); Pkg.Registry.add(RegistrySpec(url = \"https://github.com/barche/CxxWrapTestRegistry.git\"))"
julia -e "using Pkg; pkg\"add ${package}\"; using CxxWrap"
ctest -j 1 -C Release -V
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder -fPIC")
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

add_definitions(-DJULIA_ENABLE_THREADING)

Expand Down Expand Up @@ -169,8 +169,8 @@ set_property(TARGET ${JLCXX_TARGET} APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING ${JLCXX_TARGET}_MAJOR_VERSION
)
target_compile_definitions(${JLCXX_TARGET} PUBLIC "JULIA_ENABLE_THREADING")
target_compile_features(${JLCXX_TARGET} PUBLIC cxx_std_17)
target_compile_features(${JLCXX_STL_TARGET} PUBLIC cxx_std_17)
target_compile_features(${JLCXX_TARGET} PUBLIC cxx_std_20)
target_compile_features(${JLCXX_STL_TARGET} PUBLIC cxx_std_20)

generate_export_header(${JLCXX_TARGET})

Expand Down
6 changes: 0 additions & 6 deletions include/jlcxx/julia_headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
#ifdef _MSC_VER
#include <uv.h>
#include <windows.h>

template<typename T>
static inline T jl_atomic_load_relaxed(volatile T *obj)
{
return jl_atomic_load_acquire(obj);
}
#endif

#include <julia.h>
Expand Down
34 changes: 20 additions & 14 deletions include/jlcxx/stl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,12 @@ using stltypes = remove_duplicates<combine_parameterlists<combine_parameterlists
>, fundamental_int_types>, fixed_int_types>>;

template<typename TypeWrapperT>
void wrap_common(TypeWrapperT& wrapped)
void wrap_range_based_algorithms(TypeWrapperT& wrapped)
{
using WrappedT = typename TypeWrapperT::type;
using T = typename WrappedT::value_type;
wrapped.module().set_override_module(StlWrappers::instance().module());
wrapped.method("cppsize", &WrappedT::size);
wrapped.method("resize", [] (WrappedT& v, const cxxint_t s) { v.resize(s); });
wrapped.method("append", [] (WrappedT& v, jlcxx::ArrayRef<T> arr)
{
const std::size_t addedlen = arr.size();
v.reserve(v.size() + addedlen);
for(size_t i = 0; i != addedlen; ++i)
{
v.push_back(arr[i]);
}
});
wrapped.method("StdFill", [] (WrappedT& v, const T& val) { std::ranges::fill(v, val); });
wrapped.module().unset_override_module();
}

Expand All @@ -102,7 +92,7 @@ struct WrapVectorImpl
{
using WrappedT = std::vector<T>;

wrap_common(wrapped);
wrap_range_based_algorithms(wrapped);
wrapped.module().set_override_module(StlWrappers::instance().module());
wrapped.method("push_back", static_cast<void (WrappedT::*)(const T&)>(&WrappedT::push_back));
wrapped.method("cxxgetindex", [] (const WrappedT& v, cxxint_t i) -> typename WrappedT::const_reference { return v[i-1]; });
Expand All @@ -120,7 +110,6 @@ struct WrapVectorImpl<bool>
{
using WrappedT = std::vector<bool>;

wrap_common(wrapped);
wrapped.module().set_override_module(StlWrappers::instance().module());
wrapped.method("push_back", [] (WrappedT& v, const bool val) { v.push_back(val); });
wrapped.method("cxxgetindex", [] (const WrappedT& v, cxxint_t i) { return bool(v[i-1]); });
Expand All @@ -136,6 +125,19 @@ struct WrapVector
{
using WrappedT = typename TypeWrapperT::type;
using T = typename WrappedT::value_type;
wrapped.module().set_override_module(StlWrappers::instance().module());
wrapped.method("cppsize", &WrappedT::size);
wrapped.method("resize", [] (WrappedT& v, const cxxint_t s) { v.resize(s); });
wrapped.method("append", [] (WrappedT& v, jlcxx::ArrayRef<T> arr)
{
const std::size_t addedlen = arr.size();
v.reserve(v.size() + addedlen);
for(size_t i = 0; i != addedlen; ++i)
{
v.push_back(arr[i]);
}
});
wrapped.module().unset_override_module();
WrapVectorImpl<T>::wrap(wrapped);
}
};
Expand All @@ -147,6 +149,8 @@ struct WrapValArray
{
using WrappedT = typename TypeWrapperT::type;
using T = typename WrappedT::value_type;

wrap_range_based_algorithms(wrapped);
wrapped.template constructor<std::size_t>();
wrapped.template constructor<const T&, std::size_t>();
wrapped.template constructor<const T*, std::size_t>();
Expand All @@ -167,6 +171,8 @@ struct WrapDeque
{
using WrappedT = typename TypeWrapperT::type;
using T = typename WrappedT::value_type;

wrap_range_based_algorithms(wrapped);
wrapped.template constructor<std::size_t>();
wrapped.module().set_override_module(StlWrappers::instance().module());
wrapped.method("cppsize", &WrappedT::size);
Expand Down
Loading