Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
c0871aa4
Commit
c0871aa4
authored
Mar 17, 2017
by
Feng Xiao
Committed by
GitHub
Mar 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2848 from xfxyjwf/freebsd
Fix freebsd build.
parents
44dc5558
416f9093
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
0 deletions
+63
-0
cpp_file.cc
src/google/protobuf/compiler/cpp/cpp_file.cc
+46
-0
cpp_file.h
src/google/protobuf/compiler/cpp/cpp_file.h
+9
-0
plugin.pb.h
src/google/protobuf/compiler/plugin.pb.h
+6
-0
stringpiece_unittest.cc
src/google/protobuf/stubs/stringpiece_unittest.cc
+2
-0
No files found.
src/google/protobuf/compiler/cpp/cpp_file.cc
View file @
c0871aa4
...
...
@@ -54,6 +54,39 @@ namespace google {
namespace
protobuf
{
namespace
compiler
{
namespace
cpp
{
namespace
{
// The list of names that are defined as macros on some platforms. We need to
// #undef them for the generated code to compile.
const
char
*
kMacroNames
[]
=
{
"major"
,
"minor"
};
bool
IsMacroName
(
const
string
&
name
)
{
// Just do a linear search as the number of elements is very small.
for
(
int
i
=
0
;
i
<
GOOGLE_ARRAYSIZE
(
kMacroNames
);
++
i
)
{
if
(
name
==
kMacroNames
[
i
])
return
true
;
}
return
false
;
}
void
CollectMacroNames
(
const
Descriptor
*
message
,
vector
<
string
>*
names
)
{
for
(
int
i
=
0
;
i
<
message
->
field_count
();
++
i
)
{
const
FieldDescriptor
*
field
=
message
->
field
(
i
);
if
(
IsMacroName
(
field
->
name
()))
{
names
->
push_back
(
field
->
name
());
}
}
for
(
int
i
=
0
;
i
<
message
->
nested_type_count
();
++
i
)
{
CollectMacroNames
(
message
->
nested_type
(
i
),
names
);
}
}
void
CollectMacroNames
(
const
FileDescriptor
*
file
,
vector
<
string
>*
names
)
{
for
(
int
i
=
0
;
i
<
file
->
message_type_count
();
++
i
)
{
CollectMacroNames
(
file
->
message_type
(
i
),
names
);
}
}
}
// namespace
// ===================================================================
...
...
@@ -103,10 +136,23 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
FileGenerator
::~
FileGenerator
()
{}
void
FileGenerator
::
GenerateMacroUndefs
(
io
::
Printer
*
printer
)
{
vector
<
string
>
names_to_undef
;
CollectMacroNames
(
file_
,
&
names_to_undef
);
for
(
int
i
=
0
;
i
<
names_to_undef
.
size
();
++
i
)
{
printer
->
Print
(
"#ifdef $name$
\n
"
"#undef $name$
\n
"
"#endif
\n
"
,
"name"
,
names_to_undef
[
i
]);
}
}
void
FileGenerator
::
GenerateHeader
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"// @@protoc_insertion_point(includes)
\n
"
);
GenerateMacroUndefs
(
printer
);
GenerateForwardDeclarations
(
printer
);
...
...
src/google/protobuf/compiler/cpp/cpp_file.h
View file @
c0871aa4
...
...
@@ -133,6 +133,15 @@ class FileGenerator {
void
GenerateProto2NamespaceEnumSpecializations
(
io
::
Printer
*
printer
);
// Sometimes the names we use in a .proto file happen to be defined as macros
// on some platforms (e.g., macro/minor used in plugin.proto are defined as
// macros in sys/types.h on FreeBSD and a few other platforms). To make the
// generated code compile on these platforms, we either have to undef the
// macro for these few platforms, or rename the field name for all platforms.
// Since these names are part of protobuf public API, renaming is generally
// a breaking change so we prefer the #undef approach.
void
GenerateMacroUndefs
(
io
::
Printer
*
printer
);
const
FileDescriptor
*
file_
;
const
Options
options_
;
...
...
src/google/protobuf/compiler/plugin.pb.h
View file @
c0871aa4
...
...
@@ -30,6 +30,12 @@
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/descriptor.pb.h>
// @@protoc_insertion_point(includes)
#ifdef major
#undef major
#endif
#ifdef minor
#undef minor
#endif
namespace
google
{
namespace
protobuf
{
class
DescriptorProto
;
...
...
src/google/protobuf/stubs/stringpiece_unittest.cc
View file @
c0871aa4
...
...
@@ -783,11 +783,13 @@ TEST(FindOneCharTest, EdgeCases) {
EXPECT_EQ
(
StringPiece
::
npos
,
a
.
rfind
(
'x'
));
}
#ifdef PROTOBUF_HAS_DEATH_TEST
#ifndef NDEBUG
TEST
(
NonNegativeLenTest
,
NonNegativeLen
)
{
EXPECT_DEATH
(
StringPiece
(
"xyz"
,
-
1
),
"len >= 0"
);
}
#endif // ndef DEBUG
#endif // PROTOBUF_HAS_DEATH_TEST
}
// namespace
}
// namespace protobuf
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment