Skip to content

Commit

Permalink
refactor: Fix clang-tidy warnings in PySerializer. (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 authored Jan 7, 2025
1 parent 8e3de0a commit ea07551
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lint-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ tasks:
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/ExceptionFFI.hpp"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/ir/native/PyKeyValuePairLogEvent.cpp"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/ir/native/PyKeyValuePairLogEvent.hpp"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/ir/native/PySerializer.cpp"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/ir/native/PySerializer.hpp"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/modules"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/Py_utils.cpp"
- "{{.CLP_FFI_PY_CPP_SRC_DIR}}/Py_utils.hpp"
Expand Down
17 changes: 12 additions & 5 deletions src/clp_ffi_py/ir/native/PySerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <utility>

#include <clp/ffi/ir_stream/protocol_constants.hpp>
#include <wrapped_facade_headers/msgpack.hpp>

#include <clp_ffi_py/api_decoration.hpp>
#include <clp_ffi_py/error_messages.hpp>
Expand Down Expand Up @@ -147,7 +148,7 @@ CLP_FFI_PY_METHOD auto PySerializer_exit(PySerializer* self, PyObject* args, PyO
*/
CLP_FFI_PY_METHOD auto PySerializer_dealloc(PySerializer* self) -> void;

// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
// NOLINTNEXTLINE(*-avoid-c-arrays, cppcoreguidelines-avoid-non-const-global-variables)
PyMethodDef PySerializer_method_table[]{
{"serialize_log_event_from_msgpack_map",
py_c_function_cast(PySerializer_serialize_log_event_from_msgpack_map),
Expand Down Expand Up @@ -182,7 +183,8 @@ PyMethodDef PySerializer_method_table[]{
{nullptr}
};

// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-pro-type-*-cast)
// NOLINTBEGIN(cppcoreguidelines-pro-type-*-cast)
// NOLINTNEXTLINE(*-avoid-c-arrays, cppcoreguidelines-avoid-non-const-global-variables)
PyType_Slot PySerializer_slots[]{
{Py_tp_alloc, reinterpret_cast<void*>(PyType_GenericAlloc)},
{Py_tp_dealloc, reinterpret_cast<void*>(PySerializer_dealloc)},
Expand All @@ -192,11 +194,12 @@ PyType_Slot PySerializer_slots[]{
{Py_tp_doc, const_cast<void*>(static_cast<void const*>(cPySerializerDoc))},
{0, nullptr}
};
// NOLINTEND(cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-pro-type-*-cast)
// NOLINTEND(cppcoreguidelines-pro-type-*-cast)

/**
* `PySerializer`'s Python type specifications.
*/
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
PyType_Spec PySerializer_type_spec{
"clp_ffi_py.ir.native.Serializer",
sizeof(PySerializer),
Expand Down Expand Up @@ -271,7 +274,7 @@ CLP_FFI_PY_METHOD auto PySerializer_init(PySerializer* self, PyObject* args, PyO
if (serializer_result.has_error()) {
PyErr_Format(
PyExc_RuntimeError,
cSerializerCreateErrorFormatStr.data(),
get_c_str_from_constexpr_string_view(cSerializerCreateErrorFormatStr),
serializer_result.error().message().c_str()
);
return -1;
Expand Down Expand Up @@ -443,8 +446,12 @@ auto PySerializer::serialize_log_event_from_msgpack_map(std::span<char const> ms
}

auto const buffer_size_before_serialization{get_ir_buf_size()};
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (false == m_serializer->serialize_msgpack_map(msgpack_obj.via.map)) {
PyErr_SetString(PyExc_RuntimeError, cSerializerSerializeMsgpackMapError.data());
PyErr_SetString(
PyExc_RuntimeError,
get_c_str_from_constexpr_string_view(cSerializerSerializeMsgpackMapError)
);
return std::nullopt;
}
auto const buffer_size_after_serialization{get_ir_buf_size()};
Expand Down
1 change: 1 addition & 0 deletions src/wrapped_facade_headers/Python.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <pyport.h>
#include <typeslots.h>
#include <unicodeobject.h>
#include <warnings.h>
// IWYU pragma: end_exports
#endif
// clang-format on

0 comments on commit ea07551

Please sign in to comment.