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

Upgrade the C++ standard to C++20; Replace gsl::span with std::span. #39

Merged
merged 5 commits into from
Nov 29, 2023
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
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ IncludeCategories:
# Third-party headers. Update when adding new third-party library
- Regex: '^<(clp)'
Priority: 3
- Regex: '<(gsl)'
Priority: 3
- Regex: '<(json)'
Priority: 3
# C headers
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "src/clp"]
path = src/clp
url = https://github.com/y-scope/clp.git
[submodule "src/GSL"]
path = src/GSL
url = https://github.com/microsoft/GSL.git
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ recursive-include clp_ffi_py *.pyi
recursive-include clp_ffi_py py.typed
include setup.cfg
include src/clp/components/core/submodules/json/single_include/nlohmann/json.hpp
include src/GSL/include/gsl/*
recursive-include tests *
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ color = true
preview = true

[tool.cibuildwheel]
# Use `musllinux_1_2` to support C++20 compilation
musllinux-aarch64-image = "musllinux_1_2"
LinZhihao-723 marked this conversation as resolved.
Show resolved Hide resolved
musllinux-i686-image = "musllinux_1_2"
musllinux-ppc64le-image = "musllinux_1_2"
musllinux-s390x-image = "musllinux_1_2"
musllinux-x86_64-image = "musllinux_1_2"

skip = "pp*"

test-command = [
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
language="c++",
include_dirs=[
"src",
"src/GSL/include",
"src/clp/components/core/submodules",
],
sources=[
Expand All @@ -37,7 +36,7 @@
"src/clp_ffi_py/utils.cpp",
],
extra_compile_args=[
"-std=c++17",
"-std=c++20",
"-O3",
],
define_macros=[("SOURCE_PATH_SIZE", str(len(os.path.abspath("./src/clp/components/core"))))],
Expand Down
1 change: 0 additions & 1 deletion src/GSL
Submodule GSL deleted from 430030
5 changes: 3 additions & 2 deletions src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <algorithm>
#include <random>
#include <span>

#include <clp_ffi_py/error_messages.hpp>
#include <clp_ffi_py/ir/native/error_messages.hpp>
Expand Down Expand Up @@ -220,7 +221,7 @@ auto PyDecoderBuffer::init(PyObject* input_stream, Py_ssize_t buf_capacity) -> b
PyErr_NoMemory();
return false;
}
m_read_buffer = gsl::span<int8_t>(m_read_buffer_mem_owner, buf_capacity);
m_read_buffer = std::span<int8_t>{m_read_buffer_mem_owner, static_cast<size_t>(buf_capacity)};
m_input_ir_stream = input_stream;
Py_INCREF(m_input_ir_stream);
return true;
Expand All @@ -241,7 +242,7 @@ auto PyDecoderBuffer::populate_read_buffer(Py_ssize_t& num_bytes_read) -> bool {
PyErr_NoMemory();
return false;
}
auto new_read_buffer{gsl::span<int8_t>(new_buf, new_capacity)};
std::span<int8_t> const new_read_buffer{new_buf, static_cast<size_t>(new_capacity)};
std::copy(
unconsumed_bytes_in_curr_read_buffer.begin(),
unconsumed_bytes_in_curr_read_buffer.end(),
Expand Down
7 changes: 4 additions & 3 deletions src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <clp_ffi_py/Python.hpp> // Must always be included before any other header files

#include <span>

#include <clp/components/core/src/ffi/ir_stream/decoding_methods.hpp>
#include <gsl/span>

#include <clp_ffi_py/ir/native/PyMetadata.hpp>
#include <clp_ffi_py/PyObjectUtils.hpp>
Expand Down Expand Up @@ -102,7 +103,7 @@ class PyDecoderBuffer {
/**
* @return A span containing unconsumed bytes.
*/
[[nodiscard]] auto get_unconsumed_bytes() const -> gsl::span<int8_t> {
[[nodiscard]] auto get_unconsumed_bytes() const -> std::span<int8_t> {
return m_read_buffer.subspan(m_num_current_bytes_consumed, get_num_unconsumed_bytes());
}

Expand Down Expand Up @@ -214,7 +215,7 @@ class PyDecoderBuffer {
PyObject* m_input_ir_stream;
PyMetadata* m_metadata;
int8_t* m_read_buffer_mem_owner;
gsl::span<int8_t> m_read_buffer;
std::span<int8_t> m_read_buffer;
ffi::epoch_time_ms_t m_ref_timestamp;
Py_ssize_t m_buffer_size;
Py_ssize_t m_num_current_bytes_consumed;
Expand Down
8 changes: 5 additions & 3 deletions src/clp_ffi_py/ir/native/decoding_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include "decoding_methods.hpp"

#include <span>

#include <clp/components/core/src/BufferReader.hpp>
#include <clp/components/core/src/ffi/ir_stream/decoding_methods.hpp>
#include <clp/components/core/src/ffi/ir_stream/protocol_constants.hpp>
#include <clp/components/core/src/type_utils.hpp>
#include <gsl/span>
#include <json/single_include/nlohmann/json.hpp>

#include <clp_ffi_py/error_messages.hpp>
Expand Down Expand Up @@ -191,8 +192,9 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
nlohmann::json const metadata_json(
nlohmann::json::parse(metadata_buffer.begin(), metadata_buffer.end())
);
std::string const version{metadata_json.at(ffi::ir_stream::cProtocol::Metadata::VersionKey)
};
std::string const version{metadata_json.at(
static_cast<char const*>(ffi::ir_stream::cProtocol::Metadata::VersionKey)
)};
auto const error_code{ffi::ir_stream::validate_protocol_version(version)};
if (ffi::ir_stream::IRProtocolErrorCode_Supported != error_code) {
switch (error_code) {
Expand Down
Loading