Skip to content

Commit

Permalink
Upgrading to C++20 with std::span replacing gsl::span
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 committed Nov 29, 2023
1 parent 3521c73 commit 72f7876
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ color = true
preview = true

[tool.cibuildwheel]
musllinux-aarch64-image = "musllinux_1_2"
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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
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, 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)};
auto new_read_buffer{std::span<int8_t>(new_buf, 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

0 comments on commit 72f7876

Please sign in to comment.