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.
pull/13171/head
Joshua Haberman 6 years ago committed by GitHub
parent 928ef7f2c0
commit cf35baa1ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      BUILD
  2. 4
      tests/conformance_upb.c
  3. 2
      tests/json/test_json.cc
  4. 2
      tests/pb/test_decoder.cc
  5. 2
      tests/pb/test_encoder.cc
  6. 2
      tests/pb/test_varint.c
  7. 2
      tests/test_cpp.cc
  8. 11
      tests/test_table.cc
  9. 6
      tests/test_util.h
  10. 7
      tools/amalgamate.py
  11. 2
      upb/bindings/lua/msg.c
  12. 4
      upb/bindings/stdc++/string.h
  13. 2
      upb/decode.c
  14. 2
      upb/def.c
  15. 4
      upb/def.h
  16. 2
      upb/encode.c
  17. 4
      upb/generated_util.h
  18. 1
      upb/handlers.c
  19. 4
      upb/handlers.h
  20. 140
      upb/json/parser.c
  21. 2
      upb/json/parser.rl
  22. 2
      upb/json/printer.c
  23. 2
      upb/legacy_msg_reflection.c
  24. 6
      upb/legacy_msg_reflection.h
  25. 2
      upb/msg.c
  26. 2
      upb/msgfactory.c
  27. 2
      upb/pb/compile_decoder.c
  28. 2
      upb/pb/decoder.c
  29. 4
      upb/pb/decoder.int.h
  30. 1
      upb/pb/encoder.c
  31. 2
      upb/pb/textprinter.c
  32. 4
      upb/pb/varint.int.h
  33. 103
      upb/port_def.inc
  34. 14
      upb/port_undef.inc
  35. 4
      upb/sink.h
  36. 2
      upb/table.c
  37. 4
      upb/table.int.h
  38. 5
      upb/upb.c
  39. 82
      upb/upb.h
  40. 28
      upbc/generator.cc

24
BUILD

@ -20,14 +20,20 @@ exports_files([
"build_defs",
])
COPTS = [
CPPOPTS = [
# copybara:strip_for_google3_begin
"-std=c89",
"-pedantic",
"-Werror",
"-Wno-long-long",
# copybara:strip_end
]
COPTS = CPPOPTS + [
# copybara:strip_for_google3_begin
"-pedantic",
"-std=c89",
# copybara:strip_end
]
config_setting(
name = "darwin",
values = {"cpu": "darwin"},
@ -93,6 +99,7 @@ cc_library(
],
hdrs = ["upb/legacy_msg_reflection.h"],
deps = [":upb"],
copts = COPTS,
)
cc_library(
@ -178,6 +185,7 @@ cc_library(
map_dep("@com_google_protobuf//:protobuf"),
map_dep("@com_google_protobuf//:protoc_lib"),
],
copts = CPPOPTS,
)
cc_binary(
@ -187,6 +195,7 @@ cc_binary(
":upbc_generator",
map_dep("@com_google_protobuf//:protoc_lib"),
],
copts = CPPOPTS,
)
# We strip the tests and remaining rules from google3 until the upb_proto_library()
@ -206,6 +215,7 @@ cc_library(
"tests/test_util.h",
"tests/upb_test.h",
],
copts = CPPOPTS,
)
cc_test(
@ -215,6 +225,7 @@ cc_test(
":upb_pb",
":upb_test",
],
copts = COPTS,
)
proto_library(
@ -238,6 +249,7 @@ cc_test(
":upb_pb",
":upb_test",
],
copts = CPPOPTS,
)
cc_test(
@ -249,6 +261,7 @@ cc_test(
":upb_pb",
":upb_test",
],
copts = CPPOPTS,
)
proto_library(
@ -273,6 +286,7 @@ cc_test(
":upb_pb",
":upb_test",
],
copts = CPPOPTS,
)
cc_test(
@ -282,6 +296,7 @@ cc_test(
":upb",
":upb_test",
],
copts = CPPOPTS,
)
proto_library(
@ -314,6 +329,7 @@ cc_test(
":upb_json",
":upb_test",
],
copts = CPPOPTS,
)
upb_proto_library(
@ -330,7 +346,7 @@ cc_binary(
srcs = [
"tests/conformance_upb.c",
],
copts = ["-Ibazel-out/k8-fastbuild/bin"],
copts = COPTS + ["-Ibazel-out/k8-fastbuild/bin"],
deps = [
":conformance_proto_upb",
":upb",

@ -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);

@ -13,6 +13,8 @@
#include <string>
#include "upb/port_def.inc"
// Macros for readability in test case list: allows us to give TEST("...") /
// EXPECT("...") pairs.
#define TEST(x) x

@ -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__); \

@ -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);

@ -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) {

@ -19,6 +19,8 @@
#include "upb/upb.h"
#include "upb_test.h"
#include "upb/port_def.inc"
template <class T>
void AssertInsert(T* const container, const typename T::value_type& val) {
bool inserted = container->insert(val).second;

@ -6,15 +6,18 @@
#include <limits.h>
#include <string.h>
#include <sys/resource.h>
#include <ext/hash_map>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#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<uint32_t, uint32_t> m;
__gnu_cxx::hash_map<uint32_t, uint32_t> hm;
std::unordered_map<uint32_t, uint32_t> 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<uint32_t, uint32_t>(seq): ");
printf("std::unordered_map<uint32_t, uint32_t>(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<uint32_t, uint32_t>(rand): ");
printf("std::unordered_map<uint32_t, uint32_t>(rand): ");
fflush(stdout);
before = get_usertime();
for(i = 0; true; i++) {

@ -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_ */

@ -52,10 +52,7 @@ output_path = sys.argv[2]
amalgamator = Amalgamator(include_path, output_path)
for filename in sys.argv[3:]:
# Leave JIT out of the amalgamation.
if "x64" in filename or "dynasm" in filename:
continue
amalgamator.add_src(filename.strip())
if filename.endswith(".h") or filename.endswith(".inc"):
amalgamator.add_src(filename.strip())
amalgamator.finish()

@ -14,6 +14,8 @@
#include "upb/legacy_msg_reflection.h"
#include "upb/msg.h"
#include "upb/port_def.inc"
/*
* Message/Array/Map objects can be constructed in one of two ways:
*

@ -4,6 +4,8 @@
#include "upb/sink.h"
#include "upb/port_def.inc"
namespace upb {
template <class T>
@ -62,4 +64,6 @@ class StringSink {
} // namespace upb
#include "upb/port_undef.inc"
#endif // UPB_STDCPP_H_

@ -3,6 +3,8 @@
#include "upb/upb.h"
#include "upb/decode.h"
#include "upb/port_def.inc"
/* Maps descriptor type -> upb field type. */
const uint8_t upb_desctype_to_fieldtype[] = {
UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */

@ -7,6 +7,8 @@
#include <string.h>
#include "google/protobuf/descriptor.upb.h"
#include "upb/port_def.inc"
typedef struct {
size_t len;
char str[1]; /* Null-terminated string data follows. */

@ -37,6 +37,8 @@ class SymbolTable;
}
#endif
#include "upb/port_def.inc"
struct upb_enumdef;
typedef struct upb_enumdef upb_enumdef;
struct upb_fielddef;
@ -902,4 +904,6 @@ UPB_INLINE const char* upb_safecstr(const std::string& str) {
#endif /* __cplusplus */
#include "upb/port_undef.inc"
#endif /* UPB_DEF_H_ */

@ -7,6 +7,8 @@
#include "upb/msg.h"
#include "upb/upb.h"
#include "upb/port_def.inc"
#define UPB_PB_VARINT_MAX_LEN 10
#define CHK(x) do { if (!(x)) { return false; } } while(0)

@ -9,6 +9,8 @@
#include <stdint.h>
#include "upb/msg.h"
#include "upb/port_def.inc"
#define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs)
UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
@ -98,4 +100,6 @@ UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t n
#undef PTR_AT
#include "upb/port_undef.inc"
#endif /* UPB_GENERATED_UTIL_H_ */

@ -9,6 +9,7 @@
#include "upb/sink.h"
#include "upb/port_def.inc"
struct upb_handlers {
upb_handlercache *cache;

@ -22,6 +22,8 @@
#include "upb/def.h"
#include "upb/table.int.h"
#include "upb/port_def.inc"
#ifdef __cplusplus
namespace upb {
class HandlersPtr;
@ -725,4 +727,6 @@ bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
#include "upb/handlers-inl.h"
#include "upb/port_undef.inc"
#endif /* UPB_HANDLERS_H */

@ -35,6 +35,8 @@
#include "upb/json/parser.h"
#include "upb/pb/encoder.h"
#include "upb/port_def.inc"
#define UPB_JSON_MAX_DEPTH 64
/* Type of value message */
@ -2542,11 +2544,11 @@ static bool does_fieldmask_end(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */
#line 2747 "upb/json/parser.rl"
#line 2749 "upb/json/parser.rl"
#line 2550 "upb/json/parser.c"
#line 2552 "upb/json/parser.c"
static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1,
@ -2801,7 +2803,7 @@ static const int json_en_value_machine = 78;
static const int json_en_main = 1;
#line 2750 "upb/json/parser.rl"
#line 2752 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) {
@ -2824,7 +2826,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume(parser, buf);
#line 2828 "upb/json/parser.c"
#line 2830 "upb/json/parser.c"
{
int _klen;
unsigned int _trans;
@ -2899,147 +2901,147 @@ _match:
switch ( *_acts++ )
{
case 1:
#line 2555 "upb/json/parser.rl"
#line 2557 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 2:
#line 2557 "upb/json/parser.rl"
#line 2559 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 23;goto _again;} }
break;
case 3:
#line 2561 "upb/json/parser.rl"
#line 2563 "upb/json/parser.rl"
{ start_text(parser, p); }
break;
case 4:
#line 2562 "upb/json/parser.rl"
#line 2564 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); }
break;
case 5:
#line 2568 "upb/json/parser.rl"
#line 2570 "upb/json/parser.rl"
{ start_hex(parser); }
break;
case 6:
#line 2569 "upb/json/parser.rl"
#line 2571 "upb/json/parser.rl"
{ hexdigit(parser, p); }
break;
case 7:
#line 2570 "upb/json/parser.rl"
#line 2572 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); }
break;
case 8:
#line 2576 "upb/json/parser.rl"
#line 2578 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); }
break;
case 9:
#line 2582 "upb/json/parser.rl"
#line 2584 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 10:
#line 2587 "upb/json/parser.rl"
#line 2589 "upb/json/parser.rl"
{ start_year(parser, p); }
break;
case 11:
#line 2588 "upb/json/parser.rl"
#line 2590 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_year(parser, p)); }
break;
case 12:
#line 2592 "upb/json/parser.rl"
#line 2594 "upb/json/parser.rl"
{ start_month(parser, p); }
break;
case 13:
#line 2593 "upb/json/parser.rl"
#line 2595 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_month(parser, p)); }
break;
case 14:
#line 2597 "upb/json/parser.rl"
#line 2599 "upb/json/parser.rl"
{ start_day(parser, p); }
break;
case 15:
#line 2598 "upb/json/parser.rl"
#line 2600 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_day(parser, p)); }
break;
case 16:
#line 2602 "upb/json/parser.rl"
#line 2604 "upb/json/parser.rl"
{ start_hour(parser, p); }
break;
case 17:
#line 2603 "upb/json/parser.rl"
#line 2605 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hour(parser, p)); }
break;
case 18:
#line 2607 "upb/json/parser.rl"
#line 2609 "upb/json/parser.rl"
{ start_minute(parser, p); }
break;
case 19:
#line 2608 "upb/json/parser.rl"
#line 2610 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_minute(parser, p)); }
break;
case 20:
#line 2612 "upb/json/parser.rl"
#line 2614 "upb/json/parser.rl"
{ start_second(parser, p); }
break;
case 21:
#line 2613 "upb/json/parser.rl"
#line 2615 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_second(parser, p)); }
break;
case 22:
#line 2618 "upb/json/parser.rl"
#line 2620 "upb/json/parser.rl"
{ start_duration_base(parser, p); }
break;
case 23:
#line 2619 "upb/json/parser.rl"
#line 2621 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break;
case 24:
#line 2621 "upb/json/parser.rl"
#line 2623 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 25:
#line 2626 "upb/json/parser.rl"
#line 2628 "upb/json/parser.rl"
{ start_timestamp_base(parser); }
break;
case 26:
#line 2628 "upb/json/parser.rl"
#line 2630 "upb/json/parser.rl"
{ start_timestamp_fraction(parser, p); }
break;
case 27:
#line 2629 "upb/json/parser.rl"
#line 2631 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break;
case 28:
#line 2631 "upb/json/parser.rl"
#line 2633 "upb/json/parser.rl"
{ start_timestamp_zone(parser, p); }
break;
case 29:
#line 2632 "upb/json/parser.rl"
#line 2634 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break;
case 30:
#line 2634 "upb/json/parser.rl"
#line 2636 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 31:
#line 2639 "upb/json/parser.rl"
#line 2641 "upb/json/parser.rl"
{ start_fieldmask_path_text(parser, p); }
break;
case 32:
#line 2640 "upb/json/parser.rl"
#line 2642 "upb/json/parser.rl"
{ end_fieldmask_path_text(parser, p); }
break;
case 33:
#line 2645 "upb/json/parser.rl"
#line 2647 "upb/json/parser.rl"
{ start_fieldmask_path(parser); }
break;
case 34:
#line 2646 "upb/json/parser.rl"
#line 2648 "upb/json/parser.rl"
{ end_fieldmask_path(parser); }
break;
case 35:
#line 2652 "upb/json/parser.rl"
#line 2654 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 36:
#line 2657 "upb/json/parser.rl"
#line 2659 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
{stack[top++] = cs; cs = 47;goto _again;}
@ -3053,11 +3055,11 @@ _match:
}
break;
case 37:
#line 2670 "upb/json/parser.rl"
#line 2672 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 78;goto _again;} }
break;
case 38:
#line 2675 "upb/json/parser.rl"
#line 2677 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_member(parser, p);
@ -3067,11 +3069,11 @@ _match:
}
break;
case 39:
#line 2682 "upb/json/parser.rl"
#line 2684 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_membername(parser)); }
break;
case 40:
#line 2685 "upb/json/parser.rl"
#line 2687 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
end_any_member(parser, p);
@ -3081,7 +3083,7 @@ _match:
}
break;
case 41:
#line 2696 "upb/json/parser.rl"
#line 2698 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_object(parser, p);
@ -3091,7 +3093,7 @@ _match:
}
break;
case 42:
#line 2705 "upb/json/parser.rl"
#line 2707 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
CHECK_RETURN_TOP(end_any_object(parser, p));
@ -3101,54 +3103,54 @@ _match:
}
break;
case 43:
#line 2717 "upb/json/parser.rl"
#line 2719 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); }
break;
case 44:
#line 2721 "upb/json/parser.rl"
#line 2723 "upb/json/parser.rl"
{ end_array(parser); }
break;
case 45:
#line 2726 "upb/json/parser.rl"
#line 2728 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_number(parser, p)); }
break;
case 46:
#line 2727 "upb/json/parser.rl"
#line 2729 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 47:
#line 2729 "upb/json/parser.rl"
#line 2731 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); }
break;
case 48:
#line 2730 "upb/json/parser.rl"
#line 2732 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_stringval(parser)); }
break;
case 49:
#line 2732 "upb/json/parser.rl"
#line 2734 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 50:
#line 2734 "upb/json/parser.rl"
#line 2736 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 51:
#line 2736 "upb/json/parser.rl"
#line 2738 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 52:
#line 2738 "upb/json/parser.rl"
#line 2740 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject_full(parser)); }
break;
case 53:
#line 2739 "upb/json/parser.rl"
#line 2741 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
case 54:
#line 2744 "upb/json/parser.rl"
#line 2746 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
#line 3152 "upb/json/parser.c"
#line 3154 "upb/json/parser.c"
}
}
@ -3165,32 +3167,32 @@ _again:
while ( __nacts-- > 0 ) {
switch ( *__acts++ ) {
case 0:
#line 2553 "upb/json/parser.rl"
#line 2555 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; if ( p == pe )
goto _test_eof;
goto _again;} }
break;
case 46:
#line 2727 "upb/json/parser.rl"
#line 2729 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 49:
#line 2732 "upb/json/parser.rl"
#line 2734 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 50:
#line 2734 "upb/json/parser.rl"
#line 2736 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 51:
#line 2736 "upb/json/parser.rl"
#line 2738 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 53:
#line 2739 "upb/json/parser.rl"
#line 2741 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
#line 3194 "upb/json/parser.c"
#line 3196 "upb/json/parser.c"
}
}
}
@ -3198,7 +3200,7 @@ goto _again;} }
_out: {}
}
#line 2772 "upb/json/parser.rl"
#line 2774 "upb/json/parser.rl"
if (p != pe) {
upb_status_seterrf(parser->status, "Parse error at '%.*s'\n", pe - p, p);
@ -3241,13 +3243,13 @@ static void json_parser_reset(upb_json_parser *p) {
/* Emit Ragel initialization of the parser. */
#line 3245 "upb/json/parser.c"
#line 3247 "upb/json/parser.c"
{
cs = json_start;
top = 0;
}
#line 2814 "upb/json/parser.rl"
#line 2816 "upb/json/parser.rl"
p->current_state = cs;
p->parser_top = top;
accumulate_clear(p);

@ -33,6 +33,8 @@
#include "upb/json/parser.h"
#include "upb/pb/encoder.h"
#include "upb/port_def.inc"
#define UPB_JSON_MAX_DEPTH 64
/* Type of value message */

@ -10,6 +10,8 @@
#include <string.h>
#include <time.h>
#include "upb/port_def.inc"
struct upb_json_printer {
upb_sink input_;
/* BytesSink closure. */

@ -5,6 +5,8 @@
#include "upb/table.int.h"
#include "upb/msg.h"
#include "upb/port_def.inc"
bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) {
return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 ||
type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 ||

@ -5,6 +5,8 @@
#include "upb/upb.h"
#include "upb/msg.h"
#include "upb/port_def.inc"
struct upb_map;
typedef struct upb_map upb_map;
@ -183,4 +185,6 @@ upb_msgval upb_mapiter_value(const upb_mapiter *i);
void upb_mapiter_setdone(upb_mapiter *i);
bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2);
#endif // UPB_LEGACY_MSG_REFLECTION_H_
#include "upb/port_undef.inc"
#endif /* UPB_LEGACY_MSG_REFLECTION_H_ */

@ -3,6 +3,8 @@
#include "upb/table.int.h"
#include "upb/port_def.inc"
#define VOIDPTR_AT(msg, ofs) (void*)((char*)msg + ofs)
/* Internal members of a upb_msg. We can change this without breaking binary

@ -1,6 +1,8 @@
#include "upb/msgfactory.h"
#include "upb/port_def.inc"
static bool is_power_of_two(size_t val) {
return (val & (val - 1)) == 0;
}

@ -15,6 +15,8 @@
#include <stdio.h>
#endif
#include "upb/port_def.inc"
#define MAXLABEL 5
#define EMPTYLABEL -1

@ -22,6 +22,8 @@
#include <stdio.h>
#endif
#include "upb/port_def.inc"
#define CHECK_SUSPEND(x) if (!(x)) return upb_pbdecoder_suspend(d);
/* Error messages that are shared between the bytecode and JIT decoders. */

@ -11,6 +11,8 @@
#include "upb/sink.h"
#include "upb/table.int.h"
#include "upb/port_def.inc"
/* Opcode definitions. The canonical meaning of each opcode is its
* implementation in the interpreter (the JIT is written to match this).
*
@ -303,4 +305,6 @@ UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
#define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
#include "upb/port_undef.inc"
#endif /* UPB_DECODER_INT_H_ */

@ -57,6 +57,7 @@
#include "upb/pb/encoder.h"
#include "upb/pb/varint.int.h"
#include "upb/port_def.inc"
/* The output buffer is divided into segments; a segment is a string of data
* that is "ready to go" -- it does not need any varint lengths inserted into

@ -16,6 +16,8 @@
#include "upb/sink.h"
#include "upb/port_def.inc"
struct upb_textprinter {
upb_sink input_;
upb_bytessink output_;

@ -11,6 +11,8 @@
#include <string.h>
#include "upb/upb.h"
#include "upb/port_def.inc"
#ifdef __cplusplus
extern "C" {
#endif
@ -153,4 +155,6 @@ UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
} /* extern "C" */
#endif
#include "upb/port_undef.inc"
#endif /* UPB_VARINT_DECODER_H_ */

@ -1,4 +1,25 @@
/*
* This is where we define macros used across upb.
*
* All of these macros are undef'd in port_undef.inc to avoid leaking them to
* users.
*
* The correct usage is:
*
* #include "upb/foobar.h"
* #include "upb/baz.h"
*
* // MUST be last included header.
* #include "upb/port_def.inc"
*
* // Code for this file.
* // <...>
*
* // Can be omitted for .c files, required for .h.
* #include "upb/port_undef.inc"
*
* This file is private and must not be included by users!
*/
#ifndef UINTPTR_MAX
#error must include stdint.h first
#endif
@ -20,3 +41,83 @@
#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
UPB_FIELD_AT(msg, int, case_offset) = case_val; \
UPB_FIELD_AT(msg, fieldtype, offset) = value;
/* UPB_INLINE: inline if possible, emit standalone code if required. */
#ifdef __cplusplus
#define UPB_INLINE inline
#elif defined (__GNUC__)
#define UPB_INLINE static __inline__
#else
#define UPB_INLINE static
#endif
/* Hints to the compiler about likely/unlikely branches. */
#define UPB_LIKELY(x) __builtin_expect((x),1)
/* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
* doesn't provide these preprocessor symbols. */
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define UPB_BIG_ENDIAN
#endif
/* Macros for function attributes on compilers that support them. */
#ifdef __GNUC__
#define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
#define UPB_NOINLINE __attribute__((noinline))
#define UPB_NORETURN __attribute__((__noreturn__))
#else /* !defined(__GNUC__) */
#define UPB_FORCEINLINE
#define UPB_NOINLINE
#define UPB_NORETURN
#endif
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
/* C99/C++11 versions. */
#include <stdio.h>
#define _upb_snprintf snprintf
#define _upb_vsnprintf vsnprintf
#define _upb_va_copy(a, b) va_copy(a, b)
#elif defined __GNUC__
/* A few hacky workarounds for functions not in C89.
* For internal use only!
* TODO(haberman): fix these by including our own implementations, or finding
* another workaround.
*/
#define _upb_snprintf __builtin_snprintf
#define _upb_vsnprintf __builtin_vsnprintf
#define _upb_va_copy(a, b) __va_copy(a, b)
#else
#error Need implementations of [v]snprintf and va_copy
#endif
#ifdef __cplusplus
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
(defined(_MSC_VER) && _MSC_VER >= 1900)
// C++11 is present
#else
#error upb requires C++11 for C++ support
#endif
#endif
#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
#define UPB_UNUSED(var) (void)var
/* UPB_ASSERT(): in release mode, we use the expression without letting it be
* evaluated. This prevents "unused variable" warnings. */
#ifdef NDEBUG
#define UPB_ASSERT(expr) do {} while (false && (expr))
#else
#define UPB_ASSERT(expr) assert(expr)
#endif
/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
* exist in debug mode. This turns into regular assert. */
#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
#ifdef __GNUC__
#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
#else
#define UPB_UNREACHABLE() do { assert(0); } while(0)
#endif

@ -1,5 +1,19 @@
/* See port_def.inc. This should #undef all macros #defined there. */
#undef UPB_SIZE
#undef UPB_FIELD_AT
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_INLINE
#undef UPB_FORCEINLINE
#undef UPB_NOINLINE
#undef UPB_NORETURN
#undef UPB_MAX
#undef UPB_MIN
#undef UPB_UNUSED
#undef UPB_ASSERT
#undef UPB_ASSERT_DEBUGVAR
#undef UPB_UNREACHABLE
#undef _upb_snprintf
#undef _upb_vsnprintf
#undef _upb_va_copy

@ -20,6 +20,8 @@
#include "upb/handlers.h"
#include "upb/port_def.inc"
#ifdef __cplusplus
namespace upb {
class BytesSink;
@ -509,4 +511,6 @@ template <class T> bool PutBuffer(const T& str, BytesSink sink) {
#endif /* __cplusplus */
#include "upb/port_undef.inc"
#endif

@ -8,6 +8,8 @@
#include <string.h>
#include "upb/port_def.inc"
#define UPB_MAXARRSIZE 16 /* 64k. */
/* From Chromium. */

@ -24,6 +24,8 @@
#include <string.h>
#include "upb/upb.h"
#include "upb/port_def.inc"
#ifdef __cplusplus
extern "C" {
#endif
@ -500,4 +502,6 @@ bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
} /* extern "C" */
#endif
#include "upb/port_undef.inc"
#endif /* UPB_TABLE_H_ */

@ -1,4 +1,6 @@
#include "upb/upb.h"
#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
@ -6,7 +8,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "upb/upb.h"
#include "upb/port_def.inc"
/* Guarantee null-termination and provide ellipsis truncation.
* It may be tempting to "optimize" this by initializing these final

@ -24,85 +24,7 @@ template <int N> class InlinedArena;
}
#endif
/* UPB_INLINE: inline if possible, emit standalone code if required. */
#ifdef __cplusplus
#define UPB_INLINE inline
#elif defined (__GNUC__)
#define UPB_INLINE static __inline__
#else
#define UPB_INLINE static
#endif
/* Hints to the compiler about likely/unlikely branches. */
#define UPB_LIKELY(x) __builtin_expect((x),1)
/* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
* doesn't provide these preprocessor symbols. */
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define UPB_BIG_ENDIAN
#endif
/* Macros for function attributes on compilers that support them. */
#ifdef __GNUC__
#define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
#define UPB_NOINLINE __attribute__((noinline))
#define UPB_NORETURN __attribute__((__noreturn__))
#else /* !defined(__GNUC__) */
#define UPB_FORCEINLINE
#define UPB_NOINLINE
#define UPB_NORETURN
#endif
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
/* C99/C++11 versions. */
#include <stdio.h>
#define _upb_snprintf snprintf
#define _upb_vsnprintf vsnprintf
#define _upb_va_copy(a, b) va_copy(a, b)
#elif defined __GNUC__
/* A few hacky workarounds for functions not in C89.
* For internal use only!
* TODO(haberman): fix these by including our own implementations, or finding
* another workaround.
*/
#define _upb_snprintf __builtin_snprintf
#define _upb_vsnprintf __builtin_vsnprintf
#define _upb_va_copy(a, b) __va_copy(a, b)
#else
#error Need implementations of [v]snprintf and va_copy
#endif
#ifdef __cplusplus
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
(defined(_MSC_VER) && _MSC_VER >= 1900)
// C++11 is present
#else
#error upb requires C++11 for C++ support
#endif
#endif
#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
#define UPB_UNUSED(var) (void)var
/* UPB_ASSERT(): in release mode, we use the expression without letting it be
* evaluated. This prevents "unused variable" warnings. */
#ifdef NDEBUG
#define UPB_ASSERT(expr) do {} while (false && (expr))
#else
#define UPB_ASSERT(expr) assert(expr)
#endif
/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
* exist in debug mode. This turns into regular assert. */
#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
#ifdef __GNUC__
#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
#else
#define UPB_UNREACHABLE() do { assert(0); } while(0)
#endif
#include "upb/port_def.inc"
/* upb_status *****************************************************************/
@ -429,4 +351,6 @@ typedef enum {
extern const uint8_t upb_desctype_to_fieldtype[];
#include "upb/port_undef.inc"
#endif /* UPB_H_ */

@ -352,12 +352,12 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
const protobuf::OneofDescriptor* oneof = message->oneof_decl(i);
std::string fullname = ToCIdent(oneof->full_name());
output("typedef enum {\n");
for (int i = 0; i < oneof->field_count(); i++) {
const protobuf::FieldDescriptor* field = oneof->field(i);
for (int j = 0; j < oneof->field_count(); j++) {
const protobuf::FieldDescriptor* field = oneof->field(j);
output(" $0_$1 = $2,\n", fullname, field->name(), field->number());
}
output(
" $0_NOT_SET = 0,\n"
" $0_NOT_SET = 0\n"
"} $0_oneofcases;\n",
fullname);
output(
@ -689,8 +689,20 @@ void GenerateMessageDefAccessor(const protobuf::Descriptor* d, Output& output) {
void WriteDefHeader(const protobuf::FileDescriptor* file, Output& output) {
EmitFileWarning(file, output);
output(
"#ifndef $0_UPBDEFS_H_\n"
"#define $0_UPBDEFS_H_\n\n"
"#include \"upb/def.h\"\n"
"#include \"upb/port_def.inc\"\n"
"#ifdef __cplusplus\n"
"extern \"C\" {\n"
"#endif\n\n",
ToPreproc(file->name()));
output("#include \"upb/def.h\"\n");
output("\n");
output("#include \"upb/port_def.inc\"\n");
output("\n");
output("extern upb_def_init $0;\n", DefInitSymbol(file));
output("\n");
@ -698,6 +710,16 @@ void WriteDefHeader(const protobuf::FileDescriptor* file, Output& output) {
for (int i = 0; i < file->message_type_count(); i++) {
GenerateMessageDefAccessor(file->message_type(i), output);
}
output(
"#ifdef __cplusplus\n"
"} /* extern \"C\" */\n"
"#endif\n"
"\n"
"#include \"upb/port_undef.inc\"\n"
"\n"
"#endif /* $0_UPBDEFS_H_ */\n",
ToPreproc(file->name()));
}
// Escape C++ trigraphs by escaping question marks to \?

Loading…
Cancel
Save