From nobody Tue Jun 18 04:08:15 2024 X-Original-To: dev-commits-ports-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W3CsX0ddXz5N8QP; Tue, 18 Jun 2024 04:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W3CsW4td2z47lC; Tue, 18 Jun 2024 04:08:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718683695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z+jEGR/qb/hZ0K7Cj5OAqokoUy+1hFY0UQeg5znUTpc=; b=NC5q+7sur54gfvGlfytBsChpWNxy62iZTjO06JfvHbBa3W0aerBHu8daOzzzwgfc303VSF dcQMthOIUm16OrvvGRB4dDVU+EVUfyADh+3TzLGlZ/7M/MdSg1iXHXpllzHG4Cn7C0EQ4V aOUlscK4wgQ/tXO8nstUVQQdniV7d/Mhfw1c5kwdE7AaOTqi9yTfu6Ct3d0PdEDqNdvUPn qy6JweTMmQh3hY0JX1dOAdkSKW3FvTAdqTuiJcRdawEtM354v1L7+2x4vQ86MY0qLpaEW5 MZhTBQ4u37yS4seQE8vM7zS9tocbnSTXLY/S9z6jP22WaLab4Xz57c108KPXBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718683695; a=rsa-sha256; cv=none; b=a6m/WSoSI9kR7EvkNpCG4/Hv3rzv4r/o1n2IsAUjrCs0LV1mtl8FDwu073OfM9X0vpTFBI 4SbjT1IUh91qyW9VgquGlZo3lwoiDmL/8uzHRHb9D7DhNHWP/QLFYmJbOlkPoyk7ENEx21 zQY68d/bDThYELgcavm9CpuhXbWPsw9EyttxRJi6O6aB5vQ0PDSOXrtEmGSyfj5cJId4lS cQ32+jFRAq4iraRvAWzd4uMxKEX658wJSX4ALJdPBvIoLbeg3KStK2l+xOthecp94Uf/Pw k7LzID9F1GiKca1cnp/M52B+1CoDkFH9eifcXnDIHHBYKqxMCgSShCZ1aKquZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718683695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z+jEGR/qb/hZ0K7Cj5OAqokoUy+1hFY0UQeg5znUTpc=; b=SPLMGOvU05abY4J9IQp4fTzOjefg6Hpw7Dh9M7jaMXH1KfkZR0FKaokz4+ur5jmo5G8zxQ d2+tb4WWN0w9XWYUTumin5GDBw+PyMdwDbF1I3hmYAe86zsbTLhrVKkBh+3N3k348pH3nG M3Ls0BEGp4EjezPXuQVhP/GtinbhHoqxABsqNyX0vyqO+7ng5H7fu+Ma4RoFE2O0PjzoWo MWMlGi9CS/eOYFCThQZ21foTNVkpfcSQ0vlFbK+QwcZbPEUlO4ib5jCtaRMTWZXZ4WjEsd w5495F4eTo2MtiP/pb7YHiVk/gcfzHdXA3eoQgzYEklsByeJ1I4R9BivJtFNkQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4W3CsW4TtlzkJk; Tue, 18 Jun 2024 04:08:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45I48FfN077309; Tue, 18 Jun 2024 04:08:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45I48FMX077306; Tue, 18 Jun 2024 04:08:15 GMT (envelope-from git) Date: Tue, 18 Jun 2024 04:08:15 GMT Message-Id: <202406180408.45I48FMX077306@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Po-Chuan Hsieh Subject: git: 97dea13acee5 - main - devel/py-optree: Fix build with 32-bit architectures (e.g., i386) List-Id: Commit messages for all branches of the ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-ports-all@freebsd.org Sender: owner-dev-commits-ports-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sunpoet X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 97dea13acee55a5c5ab4cd6ac1294c3ef3f42e1f Auto-Submitted: auto-generated The branch main has been updated by sunpoet: URL: https://cgit.FreeBSD.org/ports/commit/?id=97dea13acee55a5c5ab4cd6ac1294c3ef3f42e1f commit 97dea13acee55a5c5ab4cd6ac1294c3ef3f42e1f Author: Po-Chuan Hsieh AuthorDate: 2024-06-18 03:59:59 +0000 Commit: Po-Chuan Hsieh CommitDate: 2024-06-18 03:59:59 +0000 devel/py-optree: Fix build with 32-bit architectures (e.g., i386) - Bump PORTREVISION for package change Obtained from: https://github.com/metaopt/optree/commit/9a613a705ee18e18784ba3a16b2786f56f9c74d2 (based on) --- devel/py-optree/Makefile | 1 + devel/py-optree/files/patch-i386 | 397 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 398 insertions(+) diff --git a/devel/py-optree/Makefile b/devel/py-optree/Makefile index 6a480a634f0d..f0002928bf47 100644 --- a/devel/py-optree/Makefile +++ b/devel/py-optree/Makefile @@ -1,5 +1,6 @@ PORTNAME= optree PORTVERSION= 0.11.0 +PORTREVISION= 1 CATEGORIES= devel python MASTER_SITES= PYPI PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} diff --git a/devel/py-optree/files/patch-i386 b/devel/py-optree/files/patch-i386 new file mode 100644 index 000000000000..3bb59348376e --- /dev/null +++ b/devel/py-optree/files/patch-i386 @@ -0,0 +1,397 @@ +Obtained from: https://github.com/metaopt/optree/commit/9a613a705ee18e18784ba3a16b2786f56f9c74d2 (based on) + +--- include/treespec.h.orig 2024-03-25 18:01:43 UTC ++++ include/treespec.h +@@ -19,6 +19,7 @@ limitations under the License. + + #include + ++#include // std::min + #include // std::unique_ptr + #include // std::optional, std::nullopt + #include // std::string +@@ -38,7 +39,10 @@ using ssize_t = py::ssize_t; + using ssize_t = py::ssize_t; + + // The maximum depth of a pytree. +-constexpr ssize_t MAX_RECURSION_DEPTH = 1000; ++#ifndef Py_C_RECURSION_LIMIT ++#define Py_C_RECURSION_LIMIT 1000 ++#endif ++constexpr ssize_t MAX_RECURSION_DEPTH = std::min(1000, Py_C_RECURSION_LIMIT); + + // Test whether the given object is a leaf node. + bool IsLeaf(const py::object &object, +--- include/utils.h.orig 2024-03-25 18:01:43 UTC ++++ include/utils.h +@@ -208,6 +208,9 @@ inline ssize_t GET_SIZE(const py::handle& si + inline ssize_t GET_SIZE(const py::handle& sized) { + return PyList_GET_SIZE(sized.ptr()); + } ++#ifndef PyDict_GET_SIZE ++#define PyDict_GET_SIZE PyDict_GetSize ++#endif + template <> + inline ssize_t GET_SIZE(const py::handle& sized) { + return PyDict_GET_SIZE(sized.ptr()); +@@ -222,91 +225,35 @@ template <> + return PyTuple_GET_ITEM(container.ptr(), item); + } + template <> +-inline py::handle GET_ITEM_HANDLE(const py::handle& container, const py::size_t& item) { +- return PyTuple_GET_ITEM(container.ptr(), py::ssize_t_cast(item)); +-} +-template <> +-inline py::handle GET_ITEM_HANDLE(const py::handle& container, const int& item) { +- return PyTuple_GET_ITEM(container.ptr(), py::ssize_t_cast(item)); +-} +-template <> + inline py::handle GET_ITEM_HANDLE(const py::handle& container, const py::ssize_t& item) { + return PyList_GET_ITEM(container.ptr(), item); + } +-template <> +-inline py::handle GET_ITEM_HANDLE(const py::handle& container, const py::size_t& item) { +- return PyList_GET_ITEM(container.ptr(), py::ssize_t_cast(item)); +-} +-template <> +-inline py::handle GET_ITEM_HANDLE(const py::handle& container, const int& item) { +- return PyList_GET_ITEM(container.ptr(), py::ssize_t_cast(item)); +-} + + template + inline py::object GET_ITEM_BORROW(const py::handle& container, const Item& item) { +- return container[item]; ++ return py::reinterpret_borrow(container[item]); + } + template <> + inline py::object GET_ITEM_BORROW(const py::handle& container, const py::ssize_t& item) { + return py::reinterpret_borrow(PyTuple_GET_ITEM(container.ptr(), item)); + } + template <> +-inline py::object GET_ITEM_BORROW(const py::handle& container, const py::size_t& item) { +- return py::reinterpret_borrow( +- PyTuple_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} +-template <> +-inline py::object GET_ITEM_BORROW(const py::handle& container, const int& item) { +- return py::reinterpret_borrow( +- PyTuple_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} +-template <> + inline py::object GET_ITEM_BORROW(const py::handle& container, const py::ssize_t& item) { + return py::reinterpret_borrow(PyList_GET_ITEM(container.ptr(), item)); + } +-template <> +-inline py::object GET_ITEM_BORROW(const py::handle& container, const py::size_t& item) { +- return py::reinterpret_borrow( +- PyList_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} +-template <> +-inline py::object GET_ITEM_BORROW(const py::handle& container, const int& item) { +- return py::reinterpret_borrow( +- PyList_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} + + template + inline py::object GET_ITEM_STEAL(const py::handle& container, const Item& item) { +- return container[item]; ++ return py::reinterpret_steal(container[item]); + } + template <> + inline py::object GET_ITEM_STEAL(const py::handle& container, const py::ssize_t& item) { + return py::reinterpret_steal(PyTuple_GET_ITEM(container.ptr(), item)); + } + template <> +-inline py::object GET_ITEM_STEAL(const py::handle& container, const py::size_t& item) { +- return py::reinterpret_steal( +- PyTuple_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} +-template <> +-inline py::object GET_ITEM_STEAL(const py::handle& container, const int& item) { +- return py::reinterpret_steal( +- PyTuple_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} +-template <> + inline py::object GET_ITEM_STEAL(const py::handle& container, const py::ssize_t& item) { + return py::reinterpret_steal(PyList_GET_ITEM(container.ptr(), item)); + } +-template <> +-inline py::object GET_ITEM_STEAL(const py::handle& container, const py::size_t& item) { +- return py::reinterpret_steal( +- PyList_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} +-template <> +-inline py::object GET_ITEM_STEAL(const py::handle& container, const int& item) { +- return py::reinterpret_steal( +- PyList_GET_ITEM(container.ptr(), py::ssize_t_cast(item))); +-} + + template + inline void SET_ITEM(const py::handle& container, const Item& item, const py::handle& value) { +@@ -314,39 +261,15 @@ inline void SET_ITEM(const py::handle& cont + } + template <> + inline void SET_ITEM(const py::handle& container, +- const ssize_t& item, ++ const py::ssize_t& item, + const py::handle& value) { + PyTuple_SET_ITEM(container.ptr(), item, value.inc_ref().ptr()); + } + template <> +-inline void SET_ITEM(const py::handle& container, +- const py::size_t& item, +- const py::handle& value) { +- PyTuple_SET_ITEM(container.ptr(), py::ssize_t_cast(item), value.inc_ref().ptr()); +-} +-template <> +-inline void SET_ITEM(const py::handle& container, +- const int& item, +- const py::handle& value) { +- PyTuple_SET_ITEM(container.ptr(), py::ssize_t_cast(item), value.inc_ref().ptr()); +-} +-template <> + inline void SET_ITEM(const py::handle& container, +- const ssize_t& item, ++ const py::ssize_t& item, + const py::handle& value) { + PyList_SET_ITEM(container.ptr(), item, value.inc_ref().ptr()); +-} +-template <> +-inline void SET_ITEM(const py::handle& container, +- const py::size_t& item, +- const py::handle& value) { +- PyList_SET_ITEM(container.ptr(), py::ssize_t_cast(item), value.inc_ref().ptr()); +-} +-template <> +-inline void SET_ITEM(const py::handle& container, +- const int& item, +- const py::handle& value) { +- PyList_SET_ITEM(container.ptr(), py::ssize_t_cast(item), value.inc_ref().ptr()); + } + + inline std::string PyRepr(const py::handle& object) { +--- src/treespec/constructor.cpp.orig 2024-03-25 18:01:43 UTC ++++ src/treespec/constructor.cpp +@@ -78,7 +78,7 @@ template + std::vector& treespecs, + std::string& register_namespace) { + for (const py::object& child : children) { +- if (!py::isinstance(child)) { ++ if (!py::isinstance(child)) [[unlikely]] { + std::ostringstream oss{}; + oss << "Expected a(n) " << NodeKindToString(node) << " of PyTreeSpec(s), got " + << PyRepr(handle) << "."; +@@ -213,15 +213,15 @@ template + throw std::runtime_error(oss.str()); + } + node.arity = 0; +- node.node_data = GET_ITEM_BORROW(out, 1); ++ node.node_data = GET_ITEM_BORROW(out, ssize_t(1)); + for (const py::handle& child : +- py::cast(GET_ITEM_BORROW(out, 0))) { ++ py::cast(GET_ITEM_BORROW(out, ssize_t(0)))) { + ++node.arity; + children.emplace_back(py::reinterpret_borrow(child)); + } + verify_children(children, treespecs, registry_namespace); + if (num_out == 3) [[likely]] { +- py::object node_entries = GET_ITEM_BORROW(out, 2); ++ py::object node_entries = GET_ITEM_BORROW(out, ssize_t(2)); + if (!node_entries.is_none()) [[likely]] { + node.node_entries = py::cast(std::move(node_entries)); + const ssize_t num_entries = GET_SIZE(node.node_entries); +--- src/treespec/flatten.cpp.orig 2024-03-25 18:01:43 UTC ++++ src/treespec/flatten.cpp +@@ -144,14 +144,14 @@ bool PyTreeSpec::FlattenIntoImpl(const py::handle& han + throw std::runtime_error(oss.str()); + } + node.arity = 0; +- node.node_data = GET_ITEM_BORROW(out, 1); ++ node.node_data = GET_ITEM_BORROW(out, ssize_t(1)); + for (const py::handle& child : +- py::cast(GET_ITEM_BORROW(out, 0))) { ++ py::cast(GET_ITEM_BORROW(out, ssize_t(0)))) { + ++node.arity; + recurse(child); + } + if (num_out == 3) [[likely]] { +- py::object node_entries = GET_ITEM_BORROW(out, 2); ++ py::object node_entries = GET_ITEM_BORROW(out, ssize_t(2)); + if (!node_entries.is_none()) [[likely]] { + node.node_entries = py::cast(std::move(node_entries)); + const ssize_t num_entries = GET_SIZE(node.node_entries); +@@ -338,16 +338,16 @@ bool PyTreeSpec::FlattenIntoWithPathImpl(const py::han + throw std::runtime_error(oss.str()); + } + node.arity = 0; +- node.node_data = GET_ITEM_BORROW(out, 1); ++ node.node_data = GET_ITEM_BORROW(out, ssize_t(1)); + py::object node_entries; + if (num_out == 3) [[likely]] { +- node_entries = GET_ITEM_BORROW(out, 2); ++ node_entries = GET_ITEM_BORROW(out, ssize_t(2)); + } else [[unlikely]] { + node_entries = py::none(); + } + if (node_entries.is_none()) [[unlikely]] { + for (const py::handle& child : +- py::cast(GET_ITEM_BORROW(out, 0))) { ++ py::cast(GET_ITEM_BORROW(out, ssize_t(0)))) { + recurse(child, py::int_(node.arity++)); + } + } else [[likely]] { +@@ -355,7 +355,7 @@ bool PyTreeSpec::FlattenIntoWithPathImpl(const py::han + node.arity = GET_SIZE(node.node_entries); + ssize_t num_children = 0; + for (const py::handle& child : +- py::cast(GET_ITEM_BORROW(out, 0))) { ++ py::cast(GET_ITEM_BORROW(out, ssize_t(0)))) { + if (num_children >= node.arity) [[unlikely]] { + throw std::runtime_error( + "PyTree custom flatten function for type " + +@@ -500,9 +500,10 @@ py::list PyTreeSpec::FlattenUpTo(const py::object& ful + case PyTreeKind::DefaultDict: { + AssertExactStandardDict(object); + auto dict = py::reinterpret_borrow(object); +- py::list expected_keys = (node.kind != PyTreeKind::DefaultDict +- ? node.node_data +- : GET_ITEM_BORROW(node.node_data, 1)); ++ py::list expected_keys = ++ (node.kind != PyTreeKind::DefaultDict ++ ? node.node_data ++ : GET_ITEM_BORROW(node.node_data, ssize_t(1))); + if (!DictKeysEqual(expected_keys, dict)) [[unlikely]] { + py::list keys = SortedDictKeys(dict); + auto [missing_keys, extra_keys] = DictKeysDifference(expected_keys, dict); +@@ -619,7 +620,7 @@ py::list PyTreeSpec::FlattenUpTo(const py::object& ful + << " should return a 2- or 3-tuple, got " << num_out << "."; + throw std::runtime_error(oss.str()); + } +- py::object node_data = GET_ITEM_BORROW(out, 1); ++ py::object node_data = GET_ITEM_BORROW(out, ssize_t(1)); + if (node.node_data.not_equal(node_data)) [[unlikely]] { + std::ostringstream oss{}; + oss << "Mismatch custom node data; expected: " << PyRepr(node.node_data) +@@ -628,7 +629,7 @@ py::list PyTreeSpec::FlattenUpTo(const py::object& ful + } + ssize_t arity = 0; + for (const py::handle& child : +- py::cast(GET_ITEM_BORROW(out, 0))) { ++ py::cast(GET_ITEM_BORROW(out, ssize_t(0)))) { + ++arity; + agenda.emplace_back(py::reinterpret_borrow(child)); + } +--- src/treespec/traversal.cpp.orig 2024-03-25 18:01:43 UTC ++++ src/treespec/traversal.cpp +@@ -123,10 +123,10 @@ py::object PyTreeIter::NextImpl() { + << " should return a 2- or 3-tuple, got " << num_out << "."; + throw std::runtime_error(oss.str()); + } +- auto children = py::cast(GET_ITEM_BORROW(out, 0)); ++ auto children = py::cast(GET_ITEM_BORROW(out, ssize_t(0))); + ssize_t arity = GET_SIZE(children); + if (num_out == 3) [[likely]] { +- py::object node_entries = GET_ITEM_BORROW(out, 2); ++ py::object node_entries = GET_ITEM_BORROW(out, ssize_t(2)); + if (!node_entries.is_none()) [[likely]] { + const ssize_t num_entries = + GET_SIZE(py::cast(std::move(node_entries))); +--- src/treespec/treespec.cpp.orig 2024-03-25 18:01:43 UTC ++++ src/treespec/treespec.cpp +@@ -138,8 +138,8 @@ namespace optree { + + case PyTreeKind::DefaultDict: { + py::dict dict{}; +- py::object default_factory = GET_ITEM_BORROW(node.node_data, 0); +- py::list keys = GET_ITEM_BORROW(node.node_data, 1); ++ py::object default_factory = GET_ITEM_BORROW(node.node_data, ssize_t(0)); ++ py::list keys = GET_ITEM_BORROW(node.node_data, ssize_t(1)); + if (node.original_keys) [[unlikely]] { + for (ssize_t i = 0; i < node.arity; ++i) { + dict[GET_ITEM_HANDLE(node.original_keys, i)] = py::none(); +@@ -254,11 +254,11 @@ namespace optree { + auto expected_keys = py::reinterpret_borrow( + root.kind != PyTreeKind::DefaultDict + ? root.node_data +- : GET_ITEM_BORROW(root.node_data, 1)); ++ : GET_ITEM_BORROW(root.node_data, ssize_t(1))); + auto other_keys = py::reinterpret_borrow( + other_root.kind != PyTreeKind::DefaultDict + ? other_root.node_data +- : GET_ITEM_BORROW(other_root.node_data, 1)); ++ : GET_ITEM_BORROW(other_root.node_data, ssize_t(1))); + py::dict dict{}; + for (ssize_t i = 0; i < other_root.arity; ++i) { + dict[GET_ITEM_HANDLE(other_keys, i)] = py::int_(i); +@@ -530,7 +530,7 @@ ssize_t PyTreeSpec::PathsImpl(Span& paths, + auto keys = py::reinterpret_borrow( + root.kind != PyTreeKind::DefaultDict + ? root.node_data +- : GET_ITEM_BORROW(root.node_data, 1)); ++ : GET_ITEM_BORROW(root.node_data, ssize_t(1))); + for (ssize_t i = root.arity - 1; i >= 0; --i) { + cur -= recurse(cur, GET_ITEM_HANDLE(keys, i)); + } +@@ -595,7 +595,8 @@ py::list PyTreeSpec::Entries() const { + return py::getattr(root.node_data, Py_Get_ID(copy))(); + } + case PyTreeKind::DefaultDict: { +- return py::getattr(GET_ITEM_BORROW(root.node_data, 1), Py_Get_ID(copy))(); ++ return py::getattr(GET_ITEM_BORROW(root.node_data, ssize_t(1)), ++ Py_Get_ID(copy))(); + } + + default: +@@ -631,7 +632,8 @@ py::object PyTreeSpec::Entry(ssize_t index) const { + return GET_ITEM_BORROW(root.node_data, index); + } + case PyTreeKind::DefaultDict: { +- return GET_ITEM_BORROW(GET_ITEM_BORROW(root.node_data, 1), index); ++ return GET_ITEM_BORROW(GET_ITEM_BORROW(root.node_data, ssize_t(1)), ++ index); + } + + case PyTreeKind::None: +@@ -804,11 +806,11 @@ bool PyTreeSpec::IsPrefix(const PyTreeSpec& other, con + auto expected_keys = py::reinterpret_borrow( + a->kind != PyTreeKind::DefaultDict + ? a->node_data +- : GET_ITEM_BORROW(a->node_data, 1)); ++ : GET_ITEM_BORROW(a->node_data, ssize_t(1))); + auto other_keys = py::reinterpret_borrow( + b->kind != PyTreeKind::DefaultDict + ? b->node_data +- : GET_ITEM_BORROW(b->node_data, 1)); ++ : GET_ITEM_BORROW(b->node_data, ssize_t(1))); + py::dict dict{}; + for (ssize_t i = 0; i < b->arity; ++i) { + dict[GET_ITEM_HANDLE(other_keys, i)] = py::int_(i); +@@ -1023,9 +1025,9 @@ std::string PyTreeSpec::ToStringImpl() const { + case PyTreeKind::DefaultDict: { + EXPECT_EQ( + GET_SIZE(node.node_data), 2, "Number of auxiliary data mismatch."); +- py::object default_factory = GET_ITEM_BORROW(node.node_data, 0); +- auto keys = +- py::reinterpret_borrow(GET_ITEM_BORROW(node.node_data, 1)); ++ py::object default_factory = GET_ITEM_BORROW(node.node_data, ssize_t(0)); ++ auto keys = py::reinterpret_borrow( ++ GET_ITEM_BORROW(node.node_data, ssize_t(1))); + EXPECT_EQ(GET_SIZE(keys), + node.arity, + "Number of keys and entries does not match."); +@@ -1146,13 +1148,13 @@ std::string PyTreeSpec::ToString() const { + if (node.kind == PyTreeKind::DefaultDict) [[unlikely]] { + EXPECT_EQ( + GET_SIZE(node.node_data), 2, "Number of auxiliary data mismatch."); +- py::object default_factory = GET_ITEM_BORROW(node.node_data, 0); ++ py::object default_factory = GET_ITEM_BORROW(node.node_data, ssize_t(0)); + data_hash = py::hash(default_factory); + } + auto keys = py::reinterpret_borrow( + node.kind != PyTreeKind::DefaultDict + ? node.node_data +- : GET_ITEM_BORROW(node.node_data, 1)); ++ : GET_ITEM_BORROW(node.node_data, ssize_t(1))); + EXPECT_EQ( + GET_SIZE(keys), node.arity, "Number of keys and entries does not match."); + for (const py::handle& key : keys) {