Skip to content

Commit 934f353

Browse files
yoneyfacebook-github-bot
authored andcommitted
Fix for Python 3.14
Summary: Use `offsetof()` to find the offset of the `PyTupleObject`'s `ob_item` member, since upstream CPython could [add more fields](python/cpython#131529) in the future. Reviewed By: prakashgayasen, islamismailov Differential Revision: D83114258 fbshipit-source-id: f30225b70d07638c5092e2e022d11eb278a7c3ee
1 parent 8e211fa commit 934f353

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

thrift/lib/python/types.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
// To access Cython C APIs, such as create_IOBuf(). See `types.pxd`.
2020
#include <thrift/lib/python/types_api.h> // @manual
2121

22+
#include <cstddef>
23+
2224
#include <folly/Indestructible.h>
2325
#include <folly/Range.h>
2426
#include <folly/container/F14Map.h>
@@ -29,7 +31,7 @@
2931

3032
namespace apache::thrift::python {
3133

32-
constexpr const size_t kHeadOffset = sizeof(PyVarObject);
34+
constexpr const size_t kHeadOffset = offsetof(PyTupleObject, ob_item);
3335
constexpr const size_t kFieldOffset = sizeof(PyObject*);
3436

3537
/**
@@ -1789,6 +1791,8 @@ void DynamicStructInfo::addFieldInfo(
17891791
// | HEADER |
17901792
// +-----------------------------------+
17911793
// | size (number of items) |
1794+
// +-----------------------------------+
1795+
// | ... |
17921796
// +-----------------------------------+ -> kHeadOffset
17931797
// | item[0] (PyObject*)(isset flags) |
17941798
// +-----------------------------------+
@@ -1799,6 +1803,9 @@ void DynamicStructInfo::addFieldInfo(
17991803
// | item[n-1] (PyObject*) |
18001804
// +-----------------------------------+
18011805
//
1806+
// CPython could add more fields before the "item" array; for example,
1807+
// CPython 3.14 added the 'ob_hash' field.
1808+
//
18021809
// When passing a PyTupleObject to TableBasedSerializer, fields are expected
18031810
// to be identified by their offset from the start address of the struct.
18041811
// The following calculates the offset:

0 commit comments

Comments
 (0)