From cf35baa1ad70f0dca734f93bcc2b54d8d059bcdd Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 27 Mar 2019 15:32:05 -0700 Subject: Moved macros from upb.h to port_def.inc to avoid leaking them to users. (#160) * Use port_def.inc to prevent macros from leaking to users. * Added helpful comments to port_def.inc/port_undef.inc. --- tests/conformance_upb.c | 4 ++-- tests/json/test_json.cc | 2 ++ tests/pb/test_decoder.cc | 2 ++ tests/pb/test_encoder.cc | 2 ++ tests/pb/test_varint.c | 2 ++ tests/test_cpp.cc | 2 ++ tests/test_table.cc | 11 +++++++---- tests/test_util.h | 6 +++++- 8 files changed, 24 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c index a0526d7..782346f 100644 --- a/tests/conformance_upb.c +++ b/tests/conformance_upb.c @@ -50,6 +50,8 @@ void DoTest( const conformance_ConformanceRequest* request, conformance_ConformanceResponse *response, upb_arena *arena) { + protobuf_test_messages_proto3_TestAllTypesProto3 *test_message; + if (!strview_eql(conformance_ConformanceRequest_message_type(request), proto3_msg)) { static const char msg[] = "Only proto3 for now."; @@ -58,8 +60,6 @@ void DoTest( return; } - protobuf_test_messages_proto3_TestAllTypesProto3 *test_message; - switch (conformance_ConformanceRequest_payload_case(request)) { case conformance_ConformanceRequest_payload_protobuf_payload: { upb_strview payload = conformance_ConformanceRequest_protobuf_payload(request); diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc index 3dc4a6c..3fddfb6 100644 --- a/tests/json/test_json.cc +++ b/tests/json/test_json.cc @@ -13,6 +13,8 @@ #include +#include "upb/port_def.inc" + // Macros for readability in test case list: allows us to give TEST("...") / // EXPECT("...") pairs. #define TEST(x) x diff --git a/tests/pb/test_decoder.cc b/tests/pb/test_decoder.cc index 7450445..fb69541 100644 --- a/tests/pb/test_decoder.cc +++ b/tests/pb/test_decoder.cc @@ -47,6 +47,8 @@ #include "upb/upb.h" #endif // !AMALGAMATED +#include "upb/port_def.inc" + #undef PRINT_FAILURE #define PRINT_FAILURE(expr) \ fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ diff --git a/tests/pb/test_encoder.cc b/tests/pb/test_encoder.cc index aa33370..3039767 100644 --- a/tests/pb/test_encoder.cc +++ b/tests/pb/test_encoder.cc @@ -6,6 +6,8 @@ #include "upb/pb/decoder.h" #include "upb/pb/encoder.h" +#include "upb/port_def.inc" + std::string read_string(const char *filename) { size_t len; char *str = upb_readfile(filename, &len); diff --git a/tests/pb/test_varint.c b/tests/pb/test_varint.c index 7b2fe41..ebee282 100644 --- a/tests/pb/test_varint.c +++ b/tests/pb/test_varint.c @@ -3,6 +3,8 @@ #include "upb/pb/varint.int.h" #include "tests/upb_test.h" +#include "upb/port_def.inc" + /* Test that we can round-trip from int->varint->int. */ static void test_varint_for_num(upb_decoderet (*decoder)(const char*), uint64_t num) { diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index ed8e9c4..8feb6e2 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -19,6 +19,8 @@ #include "upb/upb.h" #include "upb_test.h" +#include "upb/port_def.inc" + template void AssertInsert(T* const container, const typename T::value_type& val) { bool inserted = container->insert(val).second; diff --git a/tests/test_table.cc b/tests/test_table.cc index 96a5387..063eb68 100644 --- a/tests/test_table.cc +++ b/tests/test_table.cc @@ -6,15 +6,18 @@ #include #include #include -#include #include #include #include #include +#include #include + #include "tests/upb_test.h" #include "upb/table.int.h" +#include "upb/port_def.inc" + // Convenience interface for C++. We don't put this in upb itself because // the table is not exposed to users. @@ -397,7 +400,7 @@ void test_inttable(int32_t *keys, uint16_t num_entries, const char *desc) { Table table; uint32_t largest_key = 0; std::map m; - __gnu_cxx::hash_map hm; + std::unordered_map hm; for(size_t i = 0; i < num_entries; i++) { int32_t key = keys[i]; largest_key = UPB_MAX((int32_t)largest_key, key); @@ -546,7 +549,7 @@ void test_inttable(int32_t *keys, uint16_t num_entries, const char *desc) { total = get_usertime() - before; printf("%ld/s (%0.1f%% of upb)\n", (long)(i/total), i / upb_rand_i); - printf("__gnu_cxx::hash_map(seq): "); + printf("std::unordered_map(seq): "); fflush(stdout); before = get_usertime(); for(i = 0; true; i++) { @@ -557,7 +560,7 @@ void test_inttable(int32_t *keys, uint16_t num_entries, const char *desc) { total = get_usertime() - before; printf("%ld/s (%0.1f%% of upb)\n", (long)(i/total), i / upb_seq_i); - printf("__gnu_cxx::hash_map(rand): "); + printf("std::unordered_map(rand): "); fflush(stdout); before = get_usertime(); for(i = 0; true; i++) { diff --git a/tests/test_util.h b/tests/test_util.h index 680673d..4854100 100644 --- a/tests/test_util.h +++ b/tests/test_util.h @@ -10,6 +10,8 @@ #include "tests/upb_test.h" #include "upb/sink.h" +#include "upb/port_def.inc" + #ifdef __cplusplus upb_bufhandle global_handle; @@ -223,4 +225,6 @@ error: return NULL; } -#endif +#include "upb/port_undef.inc" + +#endif /* UPB_TEST_UTIL_H_ */ -- cgit v1.2.3