Skip to content

Commit 67377e9

Browse files
ahilgermeta-codesync[bot]
authored andcommitted
Move isset data to tuple tail
Summary: Store immutable thrift-python isset bytes as a trailing tuple element instead of at index 0, so field values are always zero-based whether or not isset inspection is enabled. This removes the field-start offset from the Python and C++ runtime paths, updates the public inspection helpers to read the trailing bytes, and updates the Python CAPI codegen to emit zero-based tuple positions. It also collapses the two immutable tuple container policies into a single `TupleContainer`, making the trailing isset array an orthogonal `WithIsset` template parameter on the container-creation helpers rather than a separate type. Reviewed By: iahs Differential Revision: D110348797 fbshipit-source-id: 4293c5998c54361599a29da992c5e421748fc7a5
1 parent b68d938 commit 67377e9

7 files changed

Lines changed: 152 additions & 286 deletions

File tree

‎thrift/compiler/generate/t_mstch_python_capi_generator.cc‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,9 @@ class t_mstch_python_capi_generator : public t_whisker_generator {
576576
return true;
577577
});
578578

579-
def.property("tuple_positions", [this](const t_structured& self) {
579+
def.property("tuple_positions", [](const t_structured& self) {
580580
std::unordered_map<const t_field*, int64_t> field_tuple_indexes;
581-
// thrift-python reserves tuple element 0 for the isset byte array only
582-
// for non-exceptions that support `get_locally_set_fields`.
583-
int64_t tuple_index = enable_get_locally_set_fields(self) ? 1 : 0;
581+
int64_t tuple_index = 0;
584582
for (const t_field* f : self.fields_id_order()) {
585583
field_tuple_indexes[f] = tuple_index++;
586584
}

‎thrift/compiler/test/fixtures/py3/out/python_capi/gen-python-capi/module/thrift_types_capi.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool ensure_module_imported() {
3535
0, 1, 2, 3
3636
};
3737
static constexpr std::int16_t _fbthrift__IssetInspectionStruct__tuple_pos[3] = {
38-
1, 2, 3
38+
0, 1, 2
3939
};
4040
static constexpr std::int16_t _fbthrift__HiddenException__tuple_pos[1] = {
4141
0

‎thrift/compiler/test/fixtures/python_capi/out/python_capi_isset_deprecated_serialized_dep/gen-python-capi/serialized_dep/thrift_types_capi.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bool ensure_module_imported() {
2323
return import();
2424
}
2525
static constexpr std::int16_t _fbthrift__MarshalStruct__tuple_pos[4] = {
26-
1, 2, 3, 4
26+
0, 1, 2, 3
2727
};
2828
static constexpr std::int16_t _fbthrift__MarshalError__tuple_pos[3] = {
2929
0, 1, 2

0 commit comments

Comments
 (0)