mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -88,11 +88,11 @@ includedir = [
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_array_type_caster.h"
|
||||
types = ["wpi::array"]
|
||||
types = ["wpi::util::array"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_json_type_caster.h"
|
||||
types = ["wpi::json"]
|
||||
types = ["wpi::util::json"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_span_type_caster.h"
|
||||
@@ -100,23 +100,23 @@ types = ["std::span"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_smallset_type_caster.h"
|
||||
types = ["wpi::SmallSet"]
|
||||
types = ["wpi::util::SmallSet"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_smallvector_type_caster.h"
|
||||
types = ["wpi::SmallVector"]
|
||||
types = ["wpi::util::SmallVector"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_smallvectorimpl_type_caster.h"
|
||||
types = ["wpi::SmallVectorImpl"]
|
||||
types = ["wpi::util::SmallVectorImpl"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_string_map_caster.h"
|
||||
types = ["wpi::StringMap"]
|
||||
types = ["wpi::util::StringMap"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpi_ct_string_type_caster.h"
|
||||
types = ["wpi::ct_string"]
|
||||
types = ["wpi::util::ct_string"]
|
||||
|
||||
[[tool.semiwrap.export_type_casters.wpiutil-casters.headers]]
|
||||
header = "wpystruct.h"
|
||||
|
||||
@@ -2,7 +2,7 @@ extra_includes:
|
||||
- wpi/util/sendable/SendableBuilder.hpp
|
||||
|
||||
classes:
|
||||
wpi::Sendable:
|
||||
wpi::util::Sendable:
|
||||
methods:
|
||||
InitSendable:
|
||||
virtual_xform: |-
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
classes:
|
||||
wpi::SendableBuilder:
|
||||
wpi::util::SendableBuilder:
|
||||
enums:
|
||||
BackendKind:
|
||||
methods:
|
||||
|
||||
@@ -3,7 +3,7 @@ extra_includes:
|
||||
- wpi/util/sendable/SendableBuilder.hpp
|
||||
|
||||
classes:
|
||||
wpi::SendableRegistry:
|
||||
wpi::util::SendableRegistry:
|
||||
nodelete: true
|
||||
methods:
|
||||
Add:
|
||||
|
||||
@@ -30,7 +30,7 @@ functions:
|
||||
[](std::span<const WPI_Handle> handles) {
|
||||
py::gil_scoped_release release;
|
||||
std::vector<WPI_Handle> signaled(handles.size());
|
||||
auto result = wpi::WaitForObjects(handles, signaled);
|
||||
auto result = wpi::util::WaitForObjects(handles, signaled);
|
||||
signaled.resize(result.size());
|
||||
return signaled;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ functions:
|
||||
py::gil_scoped_release release;
|
||||
std::vector<WPI_Handle> signaled(handles.size());
|
||||
bool timedOut = false;
|
||||
auto result = wpi::WaitForObjects(handles, signaled, timeout, &timedOut);
|
||||
auto result = wpi::util::WaitForObjects(handles, signaled, timeout, &timedOut);
|
||||
signaled.resize(result.size());
|
||||
return std::make_tuple(signaled, timedOut);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ void cleanup_safethread_gil();
|
||||
|
||||
#ifndef __FRC_SYSTEMCORE__
|
||||
|
||||
namespace wpi::impl {
|
||||
namespace wpi::util::impl {
|
||||
void ResetSendableRegistry();
|
||||
} // namespace wpi::impl
|
||||
} // namespace wpi::util::impl
|
||||
|
||||
void cleanup_sendable_registry() {
|
||||
py::gil_scoped_release unlock;
|
||||
wpi::impl::ResetSendableRegistry();
|
||||
wpi::util::impl::ResetSendableRegistry();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
using OnThreadStartFn = void *(*)();
|
||||
using OnThreadEndFn = void (*)(void *);
|
||||
|
||||
namespace wpi::impl {
|
||||
namespace wpi::util::impl {
|
||||
void SetSafeThreadNotifiers(OnThreadStartFn OnStart, OnThreadEndFn OnEnd);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void setup_safethread_gil() {
|
||||
atexit.attr("register")(
|
||||
py::cpp_function([]() { g_gilstate_managed = false; }));
|
||||
|
||||
wpi::impl::SetSafeThreadNotifiers(on_safe_thread_start, on_safe_thread_end);
|
||||
wpi::util::impl::SetSafeThreadNotifiers(on_safe_thread_start, on_safe_thread_end);
|
||||
}
|
||||
|
||||
void cleanup_safethread_gil() { g_gilstate_managed = false; }
|
||||
|
||||
@@ -9,7 +9,7 @@ py::object &get_hook_ref() {
|
||||
|
||||
std::string final_py_stack_trace_hook(int offset) {
|
||||
std::string msg = "\tat <python stack trace not available due to interpreter shutdown>\n";
|
||||
msg += wpi::GetStackTraceDefault(offset);
|
||||
msg += wpi::util::GetStackTraceDefault(offset);
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ std::string py_stack_trace_hook(int offset) {
|
||||
e.discard_as_unraisable("wpiutil._stacktrace._stack_trace_hook");
|
||||
}
|
||||
|
||||
return wpi::GetStackTraceDefault(offset);
|
||||
return wpi::util::GetStackTraceDefault(offset);
|
||||
}
|
||||
|
||||
void setup_stack_trace_hook(py::object fn) {
|
||||
get_hook_ref() = fn;
|
||||
wpi::SetGetStackTraceImpl(py_stack_trace_hook);
|
||||
wpi::util::SetGetStackTraceImpl(py_stack_trace_hook);
|
||||
}
|
||||
|
||||
void cleanup_stack_trace_hook() {
|
||||
wpi::SetGetStackTraceImpl(final_py_stack_trace_hook);
|
||||
wpi::util::SetGetStackTraceImpl(final_py_stack_trace_hook);
|
||||
|
||||
// release the function during interpreter shutdown
|
||||
auto &hook = get_hook_ref();
|
||||
|
||||
@@ -24,15 +24,15 @@ struct wpi_array_name_maker<1> {
|
||||
};
|
||||
|
||||
template <typename Type, size_t Size>
|
||||
struct type_caster<wpi::array<Type, Size>> {
|
||||
struct type_caster<wpi::util::array<Type, Size>> {
|
||||
using value_conv = make_caster<Type>;
|
||||
|
||||
// Have to copy/paste PYBIND11_TYPE_CASTER implementation because wpi::array
|
||||
// Have to copy/paste PYBIND11_TYPE_CASTER implementation because wpi::util::array
|
||||
// is not default constructable
|
||||
//
|
||||
// begin PYBIND11_TYPE_CASTER
|
||||
protected:
|
||||
wpi::array<Type, Size> value{wpi::empty_array_t{}};
|
||||
wpi::util::array<Type, Size> value{wpi::util::empty_array_t{}};
|
||||
|
||||
// An empty tuple is pretty useless
|
||||
static_assert(Size > 0, "empty array not supported");
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
static constexpr auto name = const_name("Tuple[") + wpi_array_name_maker<Size>::make(value_conv::name) + const_name("]");
|
||||
template <
|
||||
typename T_,
|
||||
enable_if_t<std::is_same<wpi::array<Type, Size>, remove_cv_t<T_>>::value,
|
||||
enable_if_t<std::is_same<wpi::util::array<Type, Size>, remove_cv_t<T_>>::value,
|
||||
int> = 0>
|
||||
static handle cast(T_ *src, return_value_policy policy, handle parent) {
|
||||
if (!src)
|
||||
@@ -54,9 +54,9 @@ public:
|
||||
return cast(*src, policy, parent);
|
||||
}
|
||||
}
|
||||
operator wpi::array<Type, Size> *() { return &value; }
|
||||
operator wpi::array<Type, Size> &() { return value; }
|
||||
operator wpi::array<Type, Size> &&() && { return std::move(value); }
|
||||
operator wpi::util::array<Type, Size> *() { return &value; }
|
||||
operator wpi::util::array<Type, Size> &() { return value; }
|
||||
operator wpi::util::array<Type, Size> &&() && { return std::move(value); }
|
||||
template <typename T_>
|
||||
using cast_op_type = pybind11::detail::movable_cast_op_type<T_>;
|
||||
// end PYBIND11_TYPE_CASTER
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace pybind11 {
|
||||
namespace detail {
|
||||
|
||||
template <typename CharT, typename Traits, size_t N>
|
||||
struct type_caster<wpi::ct_string<CharT, Traits, N>> {
|
||||
using str_type = wpi::ct_string<CharT, Traits, N>;
|
||||
struct type_caster<wpi::util::ct_string<CharT, Traits, N>> {
|
||||
using str_type = wpi::util::ct_string<CharT, Traits, N>;
|
||||
PYBIND11_TYPE_CASTER(str_type, const_name(PYBIND11_STRING_NAME));
|
||||
|
||||
// TODO
|
||||
@@ -54,8 +54,8 @@ struct type_caster<wpi::ct_string<CharT, Traits, N>> {
|
||||
};
|
||||
|
||||
// template <typename Char, typename Traits, size_t N>
|
||||
// struct type_caster<wpi::ct_string<Char, Traits, N>>
|
||||
// : string_caster<wpi::ct_string<Char, Traits, N>, false> {};
|
||||
// struct type_caster<wpi::util::ct_string<Char, Traits, N>>
|
||||
// : string_caster<wpi::util::ct_string<Char, Traits, N>, false> {};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace pybind11
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace pyjson
|
||||
using number_unsigned_t = uint64_t;
|
||||
using number_integer_t = int64_t;
|
||||
|
||||
inline py::object from_json(const wpi::json& j)
|
||||
inline py::object from_json(const wpi::util::json& j)
|
||||
{
|
||||
if (j.is_null())
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace pyjson
|
||||
else // Object
|
||||
{
|
||||
py::dict obj;
|
||||
for (wpi::json::const_iterator it = j.cbegin(); it != j.cend(); ++it)
|
||||
for (wpi::util::json::const_iterator it = j.cbegin(); it != j.cend(); ++it)
|
||||
{
|
||||
obj[py::str(it.key())] = from_json(it.value());
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace pyjson
|
||||
}
|
||||
}
|
||||
|
||||
inline wpi::json to_json(const py::handle& obj)
|
||||
inline wpi::util::json to_json(const py::handle& obj)
|
||||
{
|
||||
if (obj.ptr() == nullptr || obj.is_none())
|
||||
{
|
||||
@@ -144,7 +144,7 @@ namespace pyjson
|
||||
}
|
||||
if (py::isinstance<py::tuple>(obj) || py::isinstance<py::list>(obj))
|
||||
{
|
||||
auto out = wpi::json::array();
|
||||
auto out = wpi::util::json::array();
|
||||
for (const py::handle value : obj)
|
||||
{
|
||||
out.push_back(to_json(value));
|
||||
@@ -153,7 +153,7 @@ namespace pyjson
|
||||
}
|
||||
if (py::isinstance<py::dict>(obj))
|
||||
{
|
||||
auto out = wpi::json::object();
|
||||
auto out = wpi::util::json::object();
|
||||
for (const py::handle key : obj)
|
||||
{
|
||||
if (py::isinstance<py::str>(key)) {
|
||||
@@ -174,7 +174,7 @@ namespace pyjson
|
||||
}
|
||||
|
||||
// nlohmann_json serializers
|
||||
namespace wpi
|
||||
namespace wpi::util
|
||||
{
|
||||
#define MAKE_NLJSON_SERIALIZER_DESERIALIZER(T) \
|
||||
template <> \
|
||||
@@ -229,10 +229,10 @@ namespace pybind11
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <> struct type_caster<wpi::json>
|
||||
template <> struct type_caster<wpi::util::json>
|
||||
{
|
||||
public:
|
||||
PYBIND11_TYPE_CASTER(wpi::json, _("wpiutil.json"));
|
||||
PYBIND11_TYPE_CASTER(wpi::util::json, _("wpiutil.json"));
|
||||
|
||||
bool load(handle src, bool convert)
|
||||
{
|
||||
@@ -249,7 +249,7 @@ namespace pybind11
|
||||
// }
|
||||
}
|
||||
|
||||
static handle cast(wpi::json src, return_value_policy /* policy */, handle /* parent */)
|
||||
static handle cast(wpi::util::json src, return_value_policy /* policy */, handle /* parent */)
|
||||
{
|
||||
object obj = pyjson::from_json(src);
|
||||
return obj.release();
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace pybind11
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename Type, unsigned Size> struct type_caster<wpi::SmallSet<Type, Size>>
|
||||
: set_caster<wpi::SmallSet<Type, Size>, Type> { };
|
||||
template <typename Type, unsigned Size> struct type_caster<wpi::util::SmallSet<Type, Size>>
|
||||
: set_caster<wpi::util::SmallSet<Type, Size>, Type> { };
|
||||
|
||||
} // namespace detail
|
||||
} // namespace pybind11
|
||||
@@ -11,8 +11,8 @@ namespace pybind11
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename Type, unsigned Size> struct type_caster<wpi::SmallVector<Type, Size>>
|
||||
: list_caster<wpi::SmallVector<Type, Size>, Type> { };
|
||||
template <typename Type, unsigned Size> struct type_caster<wpi::util::SmallVector<Type, Size>>
|
||||
: list_caster<wpi::util::SmallVector<Type, Size>, Type> { };
|
||||
|
||||
} // namespace detail
|
||||
} // namespace pybind11
|
||||
@@ -11,7 +11,7 @@ namespace detail
|
||||
{
|
||||
|
||||
|
||||
template <typename Type> struct type_caster<wpi::SmallVectorImpl<Type>> {
|
||||
template <typename Type> struct type_caster<wpi::util::SmallVectorImpl<Type>> {
|
||||
using value_conv = make_caster<Type>;
|
||||
|
||||
// Have to copy/paste PYBIND11_TYPE_CASTER implementation because SmallVectorImpl
|
||||
@@ -19,10 +19,10 @@ template <typename Type> struct type_caster<wpi::SmallVectorImpl<Type>> {
|
||||
//
|
||||
// begin PYBIND11_TYPE_CASTER
|
||||
protected:
|
||||
wpi::SmallVector<Type, 16> value;
|
||||
wpi::util::SmallVector<Type, 16> value;
|
||||
public:
|
||||
static constexpr auto name = _("List[") + value_conv::name + _("]");
|
||||
template <typename T_, enable_if_t<std::is_same<wpi::SmallVectorImpl<Type>, remove_cv_t<T_>>::value, int> = 0>
|
||||
template <typename T_, enable_if_t<std::is_same<wpi::util::SmallVectorImpl<Type>, remove_cv_t<T_>>::value, int> = 0>
|
||||
static handle cast(T_ *src, return_value_policy policy, handle parent) {
|
||||
if (!src) return none().release();
|
||||
if (policy == return_value_policy::take_ownership) {
|
||||
@@ -31,9 +31,9 @@ public:
|
||||
return cast(*src, policy, parent);
|
||||
}
|
||||
}
|
||||
operator wpi::SmallVectorImpl<Type>*() { return &value; }
|
||||
operator wpi::SmallVectorImpl<Type>&() { return value; }
|
||||
operator wpi::SmallVectorImpl<Type>&&() && { return std::move(value); }
|
||||
operator wpi::util::SmallVectorImpl<Type>*() { return &value; }
|
||||
operator wpi::util::SmallVectorImpl<Type>&() { return value; }
|
||||
operator wpi::util::SmallVectorImpl<Type>&&() && { return std::move(value); }
|
||||
template <typename T_> using cast_op_type = pybind11::detail::movable_cast_op_type<T_>;
|
||||
// end PYBIND11_TYPE_CASTER
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ template <typename Type> struct type_caster<std::span<Type, std::dynamic_extent>
|
||||
using value_type = typename std::remove_cv<Type>::type;
|
||||
PYBIND11_TYPE_CASTER(span_type, _("List[") + value_conv::name + _("]"));
|
||||
|
||||
wpi::SmallVector<value_type, 32> vec;
|
||||
wpi::util::SmallVector<value_type, 32> vec;
|
||||
bool load(handle src, bool convert) {
|
||||
if (!isinstance<sequence>(src) || isinstance<str>(src))
|
||||
return false;
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace detail
|
||||
{
|
||||
|
||||
template <typename Value>
|
||||
struct type_caster<wpi::StringMap<Value>>
|
||||
: map_caster<wpi::StringMap<Value>, std::string, Value> { };
|
||||
struct type_caster<wpi::util::StringMap<Value>>
|
||||
: map_caster<wpi::util::StringMap<Value>, std::string, Value> { };
|
||||
|
||||
} // namespace detail
|
||||
} // namespace pybind11
|
||||
@@ -103,38 +103,38 @@ struct WPyStructConverter {
|
||||
// static C++ converter
|
||||
template <typename T> struct WPyStructCppConverter : WPyStructConverter {
|
||||
std::string_view GetTypeName() const override {
|
||||
return wpi::Struct<T>::GetTypeName();
|
||||
return wpi::util::Struct<T>::GetTypeName();
|
||||
}
|
||||
|
||||
size_t GetSize() const override { return wpi::Struct<T>::GetSize(); }
|
||||
size_t GetSize() const override { return wpi::util::Struct<T>::GetSize(); }
|
||||
|
||||
std::string_view GetSchema() const override {
|
||||
return wpi::Struct<T>::GetSchema();
|
||||
return wpi::util::Struct<T>::GetSchema();
|
||||
}
|
||||
|
||||
void Pack(std::span<uint8_t> data, const WPyStruct &value) const override {
|
||||
py::gil_scoped_acquire gil;
|
||||
const T &v = value.py.cast<const T &>();
|
||||
wpi::Struct<T>::Pack(data, v);
|
||||
wpi::util::Struct<T>::Pack(data, v);
|
||||
}
|
||||
|
||||
WPyStruct Unpack(std::span<const uint8_t> data) const override {
|
||||
py::gil_scoped_acquire gil;
|
||||
return WPyStruct{py::cast(wpi::UnpackStruct<T>(data))};
|
||||
return WPyStruct{py::cast(wpi::util::UnpackStruct<T>(data))};
|
||||
}
|
||||
|
||||
// void UnpackInto(WPyStruct *pyv,
|
||||
// std::span<const uint8_t> data) const override {
|
||||
// py::gil_scoped_acquire gil;
|
||||
// T *v = pyv->py.cast<T *>();
|
||||
// wpi::UnpackStructInto(v, data);
|
||||
// wpi::util::UnpackStructInto(v, data);
|
||||
// }
|
||||
|
||||
void ForEachNested(
|
||||
const std::function<void(std::string_view, std::string_view)> &fn)
|
||||
const override {
|
||||
if constexpr (wpi::HasNestedStruct<T>) {
|
||||
wpi::Struct<T>::ForEachNested(fn);
|
||||
if constexpr (wpi::util::HasNestedStruct<T>) {
|
||||
wpi::util::Struct<T>::ForEachNested(fn);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -224,7 +224,7 @@ struct WPyStructPyConverter : WPyStructConverter {
|
||||
}
|
||||
};
|
||||
|
||||
// passed as I... to the wpi::Struct methods
|
||||
// passed as I... to the wpi::util::Struct methods
|
||||
struct WPyStructInfo {
|
||||
WPyStructInfo() = default;
|
||||
WPyStructInfo(const py::type &t) {
|
||||
@@ -275,7 +275,7 @@ private:
|
||||
};
|
||||
|
||||
// Leverages the converter stored in WPyStructInfo to do the actual work
|
||||
template <> struct wpi::Struct<WPyStruct, WPyStructInfo> {
|
||||
template <> struct wpi::util::Struct<WPyStruct, WPyStructInfo> {
|
||||
static std::string_view GetTypeName(const WPyStructInfo &info) {
|
||||
return info->GetTypeName();
|
||||
}
|
||||
@@ -310,8 +310,8 @@ template <> struct wpi::Struct<WPyStruct, WPyStructInfo> {
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(wpi::StructSerializable<WPyStruct, WPyStructInfo>);
|
||||
static_assert(wpi::HasNestedStruct<WPyStruct, WPyStructInfo>);
|
||||
static_assert(wpi::util::StructSerializable<WPyStruct, WPyStructInfo>);
|
||||
static_assert(wpi::util::HasNestedStruct<WPyStruct, WPyStructInfo>);
|
||||
|
||||
// This breaks on readonly structs, so we disable for now
|
||||
// static_assert(wpi::MutableStructSerializable<WPyStruct, WPyStructInfo>);
|
||||
// static_assert(wpi::util::MutableStructSerializable<WPyStruct, WPyStructInfo>);
|
||||
|
||||
@@ -5,28 +5,28 @@ void forEachNested(
|
||||
const py::type &t,
|
||||
const std::function<void(std::string_view, std::string_view)> &fn) {
|
||||
WPyStructInfo info(t);
|
||||
wpi::ForEachStructSchema<WPyStruct, WPyStructInfo>(fn, info);
|
||||
wpi::util::ForEachStructSchema<WPyStruct, WPyStructInfo>(fn, info);
|
||||
}
|
||||
|
||||
py::str getTypeName(const py::type &t) {
|
||||
WPyStructInfo info(t);
|
||||
return wpi::GetStructTypeName<WPyStruct, WPyStructInfo>(info);
|
||||
return wpi::util::GetStructTypeName<WPyStruct, WPyStructInfo>(info);
|
||||
}
|
||||
|
||||
py::str getSchema(const py::type &t) {
|
||||
WPyStructInfo info(t);
|
||||
return wpi::GetStructSchema<WPyStruct, WPyStructInfo>(info);
|
||||
return wpi::util::GetStructSchema<WPyStruct, WPyStructInfo>(info);
|
||||
}
|
||||
|
||||
size_t getSize(const py::type &t) {
|
||||
WPyStructInfo info(t);
|
||||
return wpi::GetStructSize<WPyStruct>(info);
|
||||
return wpi::util::GetStructSize<WPyStruct>(info);
|
||||
}
|
||||
|
||||
py::bytes pack(const WPyStruct &v) {
|
||||
WPyStructInfo info(v);
|
||||
|
||||
auto sz = wpi::GetStructSize<WPyStruct>(info);
|
||||
auto sz = wpi::util::GetStructSize<WPyStruct>(info);
|
||||
PyObject *b = PyBytes_FromStringAndSize(NULL, sz);
|
||||
if (b == NULL) {
|
||||
throw py::error_already_set();
|
||||
@@ -40,7 +40,7 @@ py::bytes pack(const WPyStruct &v) {
|
||||
}
|
||||
|
||||
auto s = std::span((uint8_t *)pybuf, pysz);
|
||||
wpi::PackStruct(s, v, info);
|
||||
wpi::util::PackStruct(s, v, info);
|
||||
|
||||
return py::reinterpret_steal<py::bytes>(b);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ py::bytes packArray(const py::sequence &seq) {
|
||||
}
|
||||
|
||||
WPyStructInfo info(py::type::of(seq[0]));
|
||||
auto sz = wpi::GetStructSize<WPyStruct>(info);
|
||||
auto sz = wpi::util::GetStructSize<WPyStruct>(info);
|
||||
auto total = sz*len;
|
||||
|
||||
PyObject *b = PyBytes_FromStringAndSize(NULL, total);
|
||||
@@ -72,7 +72,7 @@ py::bytes packArray(const py::sequence &seq) {
|
||||
for (const auto &v: seq) {
|
||||
WPyStruct wv(v);
|
||||
auto s = std::span((uint8_t *)pybuf, sz);
|
||||
wpi::PackStruct(s, wv, info);
|
||||
wpi::util::PackStruct(s, wv, info);
|
||||
pybuf += sz;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ py::bytes packArray(const py::sequence &seq) {
|
||||
|
||||
void packInto(const WPyStruct &v, py::buffer &b) {
|
||||
WPyStructInfo info(v);
|
||||
py::ssize_t sz = wpi::GetStructSize<WPyStruct>(info);
|
||||
py::ssize_t sz = wpi::util::GetStructSize<WPyStruct>(info);
|
||||
|
||||
auto req = b.request();
|
||||
if (req.itemsize != 1) {
|
||||
@@ -95,12 +95,12 @@ void packInto(const WPyStruct &v, py::buffer &b) {
|
||||
}
|
||||
|
||||
auto s = std::span((uint8_t *)req.ptr, req.size);
|
||||
wpi::PackStruct(s, v, info);
|
||||
wpi::util::PackStruct(s, v, info);
|
||||
}
|
||||
|
||||
WPyStruct unpack(const py::type &t, const py::buffer &b) {
|
||||
WPyStructInfo info(t);
|
||||
py::ssize_t sz = wpi::GetStructSize<WPyStruct>(info);
|
||||
py::ssize_t sz = wpi::util::GetStructSize<WPyStruct>(info);
|
||||
|
||||
auto req = b.request();
|
||||
if (req.itemsize != 1) {
|
||||
@@ -114,12 +114,12 @@ WPyStruct unpack(const py::type &t, const py::buffer &b) {
|
||||
}
|
||||
|
||||
auto s = std::span((const uint8_t *)req.ptr, req.size);
|
||||
return wpi::UnpackStruct<WPyStruct, WPyStructInfo>(s, info);
|
||||
return wpi::util::UnpackStruct<WPyStruct, WPyStructInfo>(s, info);
|
||||
}
|
||||
|
||||
py::typing::List<WPyStruct> unpackArray(const py::type &t, const py::buffer &b) {
|
||||
WPyStructInfo info(t);
|
||||
py::ssize_t sz = wpi::GetStructSize<WPyStruct>(info);
|
||||
py::ssize_t sz = wpi::util::GetStructSize<WPyStruct>(info);
|
||||
|
||||
auto req = b.request();
|
||||
if (req.itemsize != 1) {
|
||||
@@ -137,7 +137,7 @@ py::typing::List<WPyStruct> unpackArray(const py::type &t, const py::buffer &b)
|
||||
const uint8_t *ptr = (const uint8_t *)req.ptr;
|
||||
for (py::ssize_t i = 0; i < items; i++) {
|
||||
auto s = std::span(ptr, sz);
|
||||
auto v = wpi::UnpackStruct<WPyStruct, WPyStructInfo>(s, info);
|
||||
auto v = wpi::util::UnpackStruct<WPyStruct, WPyStructInfo>(s, info);
|
||||
// steals a reference
|
||||
PyList_SET_ITEM(a.ptr(), i, v.py.inc_ref().ptr());
|
||||
ptr += sz;
|
||||
@@ -148,7 +148,7 @@ py::typing::List<WPyStruct> unpackArray(const py::type &t, const py::buffer &b)
|
||||
|
||||
// void unpackInto(const py::buffer &b, WPyStruct *v) {
|
||||
// WPyStructInfo info(*v);
|
||||
// py::ssize_t sz = wpi::GetStructSize<WPyStruct>(info);
|
||||
// py::ssize_t sz = wpi::util::GetStructSize<WPyStruct>(info);
|
||||
|
||||
// auto req = b.request();
|
||||
// if (req.itemsize != 1) {
|
||||
@@ -162,5 +162,5 @@ py::typing::List<WPyStruct> unpackArray(const py::type &t, const py::buffer &b)
|
||||
// }
|
||||
|
||||
// auto s = std::span((const uint8_t *)req.ptr, req.size);
|
||||
// wpi::UnpackStructInto<WPyStruct, WPyStructInfo>(v, s, info);
|
||||
// wpi::util::UnpackStructInto<WPyStruct, WPyStructInfo>(v, s, info);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user