Skip to content

Commit

Permalink
Update to the latest clp submodule commit. (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 authored Apr 15, 2024
1 parent 5ad578b commit 5d09598
Show file tree
Hide file tree
Showing 22 changed files with 177 additions and 157 deletions.
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
recursive-include src/clp/components/core/src *.h
recursive-include src/clp/components/core/src *.hpp
recursive-include src/clp/components/core/src *.inc
recursive-include src/clp/components/core/src/clp *.h
recursive-include src/clp/components/core/src/clp *.hpp
recursive-include src/clp/components/core/src/clp *.inc
recursive-include src/clp_ffi_py *.hpp
recursive-include src/clp_ffi_py *.inc
recursive-include clp_ffi_py *.py
Expand Down
52 changes: 29 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,41 @@
from setuptools import setup, Extension
from typing import List, Optional, Tuple

cpp_src_root: str = "src"
clp_src_root: str = f"{cpp_src_root}/clp/components/core/src/clp"
clp_submodule_root: str = f"{cpp_src_root}/clp/components/core/submodules"
clp_ffi_py_src_root: str = f"{cpp_src_root}/clp_ffi_py"

ir_native: Extension = Extension(
name="clp_ffi_py.ir.native",
language="c++",
include_dirs=[
"src",
"src/clp/components/core/submodules",
cpp_src_root,
clp_src_root,
clp_submodule_root,
],
sources=[
"src/clp/components/core/src/BufferReader.cpp",
"src/clp/components/core/src/ffi/ir_stream/decoding_methods.cpp",
"src/clp/components/core/src/ffi/ir_stream/encoding_methods.cpp",
"src/clp/components/core/src/ffi/encoding_methods.cpp",
"src/clp/components/core/src/ir/parsing.cpp",
"src/clp/components/core/src/ReaderInterface.cpp",
"src/clp/components/core/src/string_utils.cpp",
"src/clp/components/core/src/TraceableException.cpp",
"src/clp_ffi_py/ir/native/decoding_methods.cpp",
"src/clp_ffi_py/ir/native/encoding_methods.cpp",
"src/clp_ffi_py/ir/native/Metadata.cpp",
"src/clp_ffi_py/ir/native/PyDecoder.cpp",
"src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp",
"src/clp_ffi_py/ir/native/PyFourByteEncoder.cpp",
"src/clp_ffi_py/ir/native/PyLogEvent.cpp",
"src/clp_ffi_py/ir/native/PyMetadata.cpp",
"src/clp_ffi_py/ir/native/PyQuery.cpp",
"src/clp_ffi_py/ir/native/Query.cpp",
"src/clp_ffi_py/modules/ir_native.cpp",
"src/clp_ffi_py/Py_utils.cpp",
"src/clp_ffi_py/utils.cpp",
f"{clp_src_root}/BufferReader.cpp",
f"{clp_src_root}/ffi/ir_stream/decoding_methods.cpp",
f"{clp_src_root}/ffi/ir_stream/encoding_methods.cpp",
f"{clp_src_root}/ffi/encoding_methods.cpp",
f"{clp_src_root}/ir/parsing.cpp",
f"{clp_src_root}/ReaderInterface.cpp",
f"{clp_src_root}/string_utils/string_utils.cpp",

f"{clp_ffi_py_src_root}/ir/native/decoding_methods.cpp",
f"{clp_ffi_py_src_root}/ir/native/encoding_methods.cpp",
f"{clp_ffi_py_src_root}/ir/native/Metadata.cpp",
f"{clp_ffi_py_src_root}/ir/native/PyDecoder.cpp",
f"{clp_ffi_py_src_root}/ir/native/PyDecoderBuffer.cpp",
f"{clp_ffi_py_src_root}/ir/native/PyFourByteEncoder.cpp",
f"{clp_ffi_py_src_root}/ir/native/PyLogEvent.cpp",
f"{clp_ffi_py_src_root}/ir/native/PyMetadata.cpp",
f"{clp_ffi_py_src_root}/ir/native/PyQuery.cpp",
f"{clp_ffi_py_src_root}/ir/native/Query.cpp",
f"{clp_ffi_py_src_root}/modules/ir_native.cpp",
f"{clp_ffi_py_src_root}/Py_utils.cpp",
f"{clp_ffi_py_src_root}/utils.cpp",
],
extra_compile_args=[
"-std=c++20",
Expand Down
2 changes: 1 addition & 1 deletion src/clp
Submodule clp updated 1012 files
6 changes: 3 additions & 3 deletions src/clp_ffi_py/ExceptionFFI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

#include <string>

#include <clp/components/core/src/TraceableException.hpp>
#include <clp/components/core/src/clp/TraceableException.hpp>

namespace clp_ffi_py {
/**
* A class that represents a traceable exception during the native code
* execution. Note: for exceptions of CPython execution, please use CPython
* interface to set the exception instead.
*/
class ExceptionFFI : public TraceableException {
class ExceptionFFI : public clp::TraceableException {
public:
ExceptionFFI(
ErrorCode error_code,
clp::ErrorCode error_code,
char const* const filename,
int line_number,
std::string message
Expand Down
2 changes: 1 addition & 1 deletion src/clp_ffi_py/Py_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ auto py_utils_init() -> bool {
return true;
}

auto py_utils_get_formatted_timestamp(ffi::epoch_time_ms_t timestamp, PyObject* timezone)
auto py_utils_get_formatted_timestamp(clp::ir::epoch_time_ms_t timestamp, PyObject* timezone)
-> PyObject* {
PyObjectPtr<PyObject> const func_args_ptr{Py_BuildValue("LO", timestamp, timezone)};
auto* func_args{func_args_ptr.get()};
Expand Down
4 changes: 2 additions & 2 deletions src/clp_ffi_py/Py_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

#include <clp/components/core/src/ffi/encoding_methods.hpp>
#include <clp/components/core/src/clp/ffi/encoding_methods.hpp>

namespace clp_ffi_py {
/**
Expand All @@ -22,7 +22,7 @@ auto py_utils_init() -> bool;
* timestamp.
* @return nullptr on failure with the relevant Python exception and error set.
*/
auto py_utils_get_formatted_timestamp(ffi::epoch_time_ms_t timestamp, PyObject* timezone)
auto py_utils_get_formatted_timestamp(clp::ir::epoch_time_ms_t timestamp, PyObject* timezone)
-> PyObject*;

/**
Expand Down
10 changes: 5 additions & 5 deletions src/clp_ffi_py/ir/native/LogEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <optional>

#include <clp/components/core/src/ffi/encoding_methods.hpp>
#include <clp/components/core/src/clp/ffi/encoding_methods.hpp>

namespace clp_ffi_py::ir::native {
/**
Expand All @@ -24,7 +24,7 @@ class LogEvent {
*/
explicit LogEvent(
std::string_view log_message,
ffi::epoch_time_ms_t timestamp,
clp::ir::epoch_time_ms_t timestamp,
size_t index,
std::optional<std::string_view> formatted_timestamp = std::nullopt
)
Expand All @@ -42,7 +42,7 @@ class LogEvent {
return std::string_view{m_log_message};
}

[[nodiscard]] auto get_timestamp() const -> ffi::epoch_time_ms_t { return m_timestamp; }
[[nodiscard]] auto get_timestamp() const -> clp::ir::epoch_time_ms_t { return m_timestamp; }

[[nodiscard]] auto get_formatted_timestamp() const -> std::string {
return m_formatted_timestamp;
Expand All @@ -59,7 +59,7 @@ class LogEvent {

auto set_log_message(std::string_view log_message) -> void { m_log_message = log_message; }

auto set_timestamp(ffi::epoch_time_ms_t timestamp) -> void { m_timestamp = timestamp; }
auto set_timestamp(clp::ir::epoch_time_ms_t timestamp) -> void { m_timestamp = timestamp; }

auto set_formatted_timestamp(std::string const& formatted_timestamp) -> void {
m_formatted_timestamp = formatted_timestamp;
Expand All @@ -69,7 +69,7 @@ class LogEvent {

private:
std::string m_log_message;
ffi::epoch_time_ms_t m_timestamp;
clp::ir::epoch_time_ms_t m_timestamp;
size_t m_index;
std::string m_formatted_timestamp;
};
Expand Down
24 changes: 12 additions & 12 deletions src/clp_ffi_py/ir/native/Metadata.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Metadata.hpp"

#include <clp/components/core/src/ffi/ir_stream/protocol_constants.hpp>
#include <clp/components/core/src/clp/ffi/ir_stream/protocol_constants.hpp>

#include <clp_ffi_py/ExceptionFFI.hpp>
#include <clp_ffi_py/ir/native/error_messages.hpp>
Expand All @@ -22,38 +22,38 @@ auto is_valid_json_string_data(nlohmann::json const& json_data, char const* key)
Metadata::Metadata(nlohmann::json const& metadata, bool is_four_byte_encoding) {
if (false == is_four_byte_encoding) {
throw ExceptionFFI(
ErrorCode_Unsupported,
clp::ErrorCode_Unsupported,
__FILE__,
__LINE__,
"Eight Byte Preamble is not yet supported."
);
}
m_is_four_byte_encoding = is_four_byte_encoding;

auto const* ref_timestamp_key{
static_cast<char const*>(ffi::ir_stream::cProtocol::Metadata::ReferenceTimestampKey)
};
auto const* ref_timestamp_key{static_cast<char const*>(
clp::ffi::ir_stream::cProtocol::Metadata::ReferenceTimestampKey
)};
if (false == is_valid_json_string_data(metadata, ref_timestamp_key)) {
throw ExceptionFFI(
ErrorCode_MetadataCorrupted,
clp::ErrorCode_MetadataCorrupted,
__FILE__,
__LINE__,
"Valid Reference Timestamp cannot be found in the metadata."
);
}
try {
std::string const ref_timestamp_str{metadata[ref_timestamp_key]};
m_ref_timestamp = static_cast<ffi::epoch_time_ms_t>(std::stoull(ref_timestamp_str));
m_ref_timestamp = static_cast<clp::ir::epoch_time_ms_t>(std::stoull(ref_timestamp_str));
} catch (std::exception const& ex) {
throw ExceptionFFI(ErrorCode_Unsupported, __FILE__, __LINE__, ex.what());
throw ExceptionFFI(clp::ErrorCode_Unsupported, __FILE__, __LINE__, ex.what());
}

auto const* timestamp_format_key{
static_cast<char const*>(ffi::ir_stream::cProtocol::Metadata::TimestampPatternKey)
static_cast<char const*>(clp::ffi::ir_stream::cProtocol::Metadata::TimestampPatternKey)
};
if (false == is_valid_json_string_data(metadata, timestamp_format_key)) {
throw ExceptionFFI(
ErrorCode_MetadataCorrupted,
clp::ErrorCode_MetadataCorrupted,
__FILE__,
__LINE__,
"Valid Timestamp Format cannot be found in the metadata."
Expand All @@ -62,11 +62,11 @@ Metadata::Metadata(nlohmann::json const& metadata, bool is_four_byte_encoding) {
m_timestamp_format = metadata[timestamp_format_key];

auto const* timezone_id_key{
static_cast<char const*>(ffi::ir_stream::cProtocol::Metadata::TimeZoneIdKey)
static_cast<char const*>(clp::ffi::ir_stream::cProtocol::Metadata::TimeZoneIdKey)
};
if (false == is_valid_json_string_data(metadata, timezone_id_key)) {
throw ExceptionFFI(
ErrorCode_MetadataCorrupted,
clp::ErrorCode_MetadataCorrupted,
__FILE__,
__LINE__,
"Valid Timezone ID cannot be found in the metadata."
Expand Down
10 changes: 6 additions & 4 deletions src/clp_ffi_py/ir/native/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <utility>

#include <clp/components/core/src/ffi/encoding_methods.hpp>
#include <clp/components/core/src/clp/ffi/encoding_methods.hpp>
#include <clp/components/core/submodules/json/single_include/nlohmann/json.hpp>

namespace clp_ffi_py::ir::native {
Expand Down Expand Up @@ -34,7 +34,7 @@ class Metadata {
* timestamp from Unix epoch time.
*/
explicit Metadata(
ffi::epoch_time_ms_t ref_timestamp,
clp::ir::epoch_time_ms_t ref_timestamp,
std::string timestamp_format,
std::string timezone
)
Expand All @@ -47,7 +47,9 @@ class Metadata {
return m_is_four_byte_encoding;
}

[[nodiscard]] auto get_ref_timestamp() const -> ffi::epoch_time_ms_t { return m_ref_timestamp; }
[[nodiscard]] auto get_ref_timestamp() const -> clp::ir::epoch_time_ms_t {
return m_ref_timestamp;
}

[[nodiscard]] auto get_timestamp_format() const -> std::string const& {
return m_timestamp_format;
Expand All @@ -57,7 +59,7 @@ class Metadata {

private:
bool m_is_four_byte_encoding;
ffi::epoch_time_ms_t m_ref_timestamp;
clp::ir::epoch_time_ms_t m_ref_timestamp;
std::string m_timestamp_format;
std::string m_timezone_id;
};
Expand Down
2 changes: 1 addition & 1 deletion src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ auto PyDecoderBuffer::test_streaming(uint32_t seed) -> PyObject* {
commit_read_buffer_consumption(num_bytes_to_read);
}
return PyByteArray_FromStringAndSize(
size_checked_pointer_cast<char>(read_bytes.data()),
clp::size_checked_pointer_cast<char>(read_bytes.data()),
static_cast<Py_ssize_t>(read_bytes.size())
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <span>

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

#include <clp_ffi_py/ir/native/PyMetadata.hpp>
#include <clp_ffi_py/PyObjectUtils.hpp>
Expand Down Expand Up @@ -90,9 +90,13 @@ class PyDecoderBuffer {
return current_num_decoded_message;
}

[[nodiscard]] auto get_ref_timestamp() const -> ffi::epoch_time_ms_t { return m_ref_timestamp; }
[[nodiscard]] auto get_ref_timestamp() const -> clp::ir::epoch_time_ms_t {
return m_ref_timestamp;
}

auto set_ref_timestamp(ffi::epoch_time_ms_t timestamp) -> void { m_ref_timestamp = timestamp; }
auto set_ref_timestamp(clp::ir::epoch_time_ms_t timestamp) -> void {
m_ref_timestamp = timestamp;
}

/**
* @return Number of unconsumed bytes stored in the current read buffer.
Expand Down Expand Up @@ -217,7 +221,7 @@ class PyDecoderBuffer {
PyMetadata* m_metadata;
int8_t* m_read_buffer_mem_owner;
std::span<int8_t> m_read_buffer;
ffi::epoch_time_ms_t m_ref_timestamp;
clp::ir::epoch_time_ms_t m_ref_timestamp;
Py_ssize_t m_buffer_size;
Py_ssize_t m_num_current_bytes_consumed;
size_t m_num_decoded_message;
Expand Down
10 changes: 5 additions & 5 deletions src/clp_ffi_py/ir/native/PyLogEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ auto PyLogEvent_init(PyLogEvent* self, PyObject* args, PyObject* keywords) -> in
self->default_init();

char const* log_message{nullptr};
ffi::epoch_time_ms_t timestamp{0};
clp::ir::epoch_time_ms_t timestamp{0};
size_t index{0};
PyObject* metadata{Py_None};
if (false
Expand Down Expand Up @@ -209,8 +209,8 @@ auto PyLogEvent_setstate(PyLogEvent* self, PyObject* state) -> PyObject* {
PyErr_Format(PyExc_KeyError, clp_ffi_py::cSetstateKeyErrorTemplate, cStateTimestamp);
return nullptr;
}
ffi::epoch_time_ms_t timestamp{0};
if (false == clp_ffi_py::parse_py_int<ffi::epoch_time_ms_t>(timestamp_obj, timestamp)) {
clp::ir::epoch_time_ms_t timestamp{0};
if (false == clp_ffi_py::parse_py_int<clp::ir::epoch_time_ms_t>(timestamp_obj, timestamp)) {
return nullptr;
}

Expand Down Expand Up @@ -471,7 +471,7 @@ auto PyLogEvent::get_formatted_message(PyObject* timezone) -> PyObject* {

auto PyLogEvent::init(
std::string_view log_message,
ffi::epoch_time_ms_t timestamp,
clp::ir::epoch_time_ms_t timestamp,
size_t index,
PyMetadata* metadata,
std::optional<std::string_view> formatted_timestamp
Expand Down Expand Up @@ -504,7 +504,7 @@ auto PyLogEvent::module_level_init(PyObject* py_module) -> bool {

auto PyLogEvent::create_new_log_event(
std::string_view log_message,
ffi::epoch_time_ms_t timestamp,
clp::ir::epoch_time_ms_t timestamp,
size_t index,
PyMetadata* metadata
) -> PyLogEvent* {
Expand Down
4 changes: 2 additions & 2 deletions src/clp_ffi_py/ir/native/PyLogEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PyLogEvent {
*/
[[nodiscard]] auto init(
std::string_view log_message,
ffi::epoch_time_ms_t timestamp,
clp::ir::epoch_time_ms_t timestamp,
size_t index,
PyMetadata* metadata,
std::optional<std::string_view> formatted_timestamp = std::nullopt
Expand Down Expand Up @@ -134,7 +134,7 @@ class PyLogEvent {
*/
[[nodiscard]] static auto create_new_log_event(
std::string_view log_message,
ffi::epoch_time_ms_t timestamp,
clp::ir::epoch_time_ms_t timestamp,
size_t index,
PyMetadata* metadata
) -> PyLogEvent*;
Expand Down
4 changes: 2 additions & 2 deletions src/clp_ffi_py/ir/native/PyMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ auto PyMetadata_init(PyMetadata* self, PyObject* args, PyObject* keywords) -> in
nullptr
};

ffi::epoch_time_ms_t ref_timestamp{0};
clp::ir::epoch_time_ms_t ref_timestamp{0};
char const* input_timestamp_format{nullptr};
char const* input_timezone{nullptr};

Expand Down Expand Up @@ -220,7 +220,7 @@ PyType_Spec PyMetadata_type_spec{
} // namespace

auto PyMetadata::init(
ffi::epoch_time_ms_t ref_timestamp,
clp::ir::epoch_time_ms_t ref_timestamp,
char const* input_timestamp_format,
char const* input_timezone
) -> bool {
Expand Down
Loading

0 comments on commit 5d09598

Please sign in to comment.