Skip to content

Commit 258d4ca

Browse files
iahsfacebook-github-bot
authored andcommitted
Use correct DefinitionKey length
Summary: We need to provide the length of the final string, which is the same as the length of the string before escaping, rather than the length of the escaped string. Also avoid recomputing the string by exposing the size directly. Reviewed By: yoney Differential Revision: D67982408 fbshipit-source-id: 3b671f6358748de2ecb29ee56bbfcfd7cbc0538d
1 parent 1692969 commit 258d4ca

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

third-party/thrift/src/thrift/compiler/generate/t_mstch_cpp2_generator.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,7 @@ class cpp_mstch_service : public mstch_service {
913913
return escape_binary_string(s.identify_definition(*service_));
914914
}
915915
mstch::node definition_key_length() {
916-
schematizer s(*service_->program()->scope(), sm_, {});
917-
return escape_binary_string(s.identify_definition(*service_)).length();
916+
return schematizer::definition_identifier_length();
918917
}
919918

920919
private:

third-party/thrift/src/thrift/compiler/sema/schematizer.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,10 @@ std::string_view schematizer::program_checksum(const t_program& program) {
949949
std::string(reinterpret_cast<const char*>(hash), sizeof(hash)));
950950
}
951951

952+
size_t schematizer::definition_identifier_length() {
953+
return 16;
954+
}
955+
952956
std::string schematizer::identify_definition(const t_named& node) {
953957
// @lint-ignore CLANGTIDY facebook-hte-CArray
954958
unsigned char hash[SHA256_DIGEST_LENGTH];
@@ -958,8 +962,8 @@ std::string schematizer::identify_definition(const t_named& node) {
958962
node.program()->path(),
959963
node.name());
960964
SHA256(reinterpret_cast<const unsigned char*>(val.c_str()), val.size(), hash);
961-
constexpr size_t num_bytes = 16;
962-
return std::string(reinterpret_cast<const char*>(hash), num_bytes);
965+
return std::string(
966+
reinterpret_cast<const char*>(hash), definition_identifier_length());
963967
}
964968

965969
int64_t schematizer::identify_program(const t_program& node) {

third-party/thrift/src/thrift/compiler/sema/schematizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class schematizer {
8686
// across runs on different including programs.
8787
std::string identify_definition(const t_named& node);
8888
int64_t identify_program(const t_program& node);
89+
static size_t definition_identifier_length();
8990

9091
// Get the name of the program's schema const.
9192
static std::string name_schema(source_manager& sm, const t_program& node);

third-party/thrift/src/thrift/compiler/test/fixtures/service-schema/out/cpp2/gen-cpp2/PrimitivesService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::CreateMethodMetadataR
2323
std::optional<apache::thrift::schema::DefinitionsSchema> apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::getServiceSchema() {
2424
std::optional<apache::thrift::schema::DefinitionsSchema> ret = schema::DefinitionsSchema{};
2525
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::cpp2::module_constants::_fbthrift_schema_b747839c13cb3aa5_includes());
26-
ret->definitions = { {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe", 64} };
26+
ret->definitions = { {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe", 16} };
2727
return ret;
2828
}
2929
#endif

third-party/thrift/src/thrift/compiler/test/fixtures/service-schema/out/cpp2_sinit/gen-cpp2/PrimitivesService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::CreateMethodMetadataR
2323
std::optional<apache::thrift::schema::DefinitionsSchema> apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::getServiceSchema() {
2424
std::optional<apache::thrift::schema::DefinitionsSchema> ret = schema::DefinitionsSchema{};
2525
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::cpp2::module_constants::_fbthrift_schema_b747839c13cb3aa5_includes());
26-
ret->definitions = { {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe", 64} };
26+
ret->definitions = { {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe", 16} };
2727
return ret;
2828
}
2929
#endif

0 commit comments

Comments
 (0)