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
df719723
Commit
df719723
authored
Sep 16, 2019
by
Mohamed Heikal
Committed by
Rafi Kamal
Nov 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify template exporting macros
parent
394f5c8c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
209 deletions
+30
-209
port_def.inc
src/google/protobuf/port_def.inc
+14
-164
port_undef.inc
src/google/protobuf/port_undef.inc
+0
-14
repeated_field.cc
src/google/protobuf/repeated_field.cc
+8
-16
repeated_field.h
src/google/protobuf/repeated_field.h
+8
-15
No files found.
src/google/protobuf/port_def.inc
View file @
df719723
...
...
@@ -343,20 +343,28 @@
#if defined(PROTOBUF_USE_DLLS)
#if defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __declspec(dllexport)
#define PROTOBUF_EXPORT __declspec(dllexport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
#else
#define PROTOBUF_EXPORT __declspec(dllimport)
#define PROTOBUF_EXPORT __declspec(dllimport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
#endif
#ifdef LIBPROTOC_EXPORTS
#define PROTOC_EXPORT __declspec(dllexport)
#define PROTOC_EXPORT __declspec(dllexport)
#else
#define PROTOC_EXPORT __declspec(dllimport)
#define PROTOC_EXPORT __declspec(dllimport)
#endif
#else // defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __attribute__((visibility("default")))
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#else
#define PROTOBUF_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#endif
#ifdef LIBPROTOC_EXPORTS
#define PROTOC_EXPORT __attribute__((visibility("default")))
...
...
@@ -367,168 +375,10 @@
#else // defined(PROTOBUF_USE_DLLS)
#define PROTOBUF_EXPORT
#define PROTOC_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#endif
// This portion provides macros for using FOO_EXPORT macros with explicit
// template instantiation declarations and definitions.
// Generally, the FOO_EXPORT macros are used at declarations,
// and GCC requires them to be used at explicit instantiation declarations,
// but MSVC requires __declspec(dllexport) to be used at the explicit
// instantiation definitions instead.
// Usage
//
// In a header file, write:
//
// extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(FOO_EXPORT) foo<bar>;
//
// In a source file, write:
//
// template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(FOO_EXPORT) foo<bar>;
//
// Where FOO_EXPORT is either PROTOBUF_EXPORT or PROTOC_EXPORT
// Implementation notes
//
// The implementation of these macros uses some subtle macro semantics to
// detect what the provided FOO_EXPORT value was defined as and then
// to dispatch to appropriate macro definitions. Unfortunately,
// MSVC's C preprocessor is rather non-compliant and requires special
// care to make it work.
//
// Issue 1.
//
// #define F(x)
// F()
//
// MSVC emits warning C4003 ("not enough actual parameters for macro
// 'F'), even though it's a valid macro invocation. This affects the
// macros below that take just an "export" parameter, because export
// may be empty.
//
// As a workaround, we can add a dummy parameter and arguments:
//
// #define F(x,_)
// F(,)
//
// Issue 2.
//
// #define F(x) G##x
// #define Gj() ok
// F(j())
//
// The correct replacement for "F(j())" is "ok", but MSVC replaces it
// with "Gj()". As a workaround, we can pass the result to an
// identity macro to force MSVC to look for replacements again. (This
// is why PROTOBUF_EXPORT_TEMPLATE_STYLE_3 exists.)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE(export) \
PROTOBUF_EXPORT_TEMPLATE_INVOKE
(
\
DECLARE
,
PROTOBUF_EXPORT_TEMPLATE_STYLE
(
export
,
),
export
)
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE(export) \
PROTOBUF_EXPORT_TEMPLATE_INVOKE
(
\
DEFINE
,
PROTOBUF_EXPORT_TEMPLATE_STYLE
(
export
,
),
export
)
// INVOKE is an internal helper macro to perform parameter replacements
// and token pasting to chain invoke another macro. E.g.,
// PROTOBUF_EXPORT_TEMPLATE_INVOKE(DECLARE, DEFAULT, FOO_EXPORT)
// will export to call
// PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT(FOO_EXPORT, )
// (but with FOO_EXPORT expanded too).
#define PROTOBUF_EXPORT_TEMPLATE_INVOKE(which, style, export) \
PROTOBUF_EXPORT_TEMPLATE_INVOKE_2
(
which
,
style
,
export
)
#define PROTOBUF_EXPORT_TEMPLATE_INVOKE_2(which, style, export) \
PROTOBUF_EXPORT_TEMPLATE_
##which##_##style(export, )
// Default style is to apply the FOO_EXPORT macro at declaration sites.
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT(export, _) export
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE_DEFAULT(export, _)
// The "MSVC hack" style is used when FOO_EXPORT is defined
// as __declspec(dllexport), which MSVC requires to be used at
// definition sites instead.
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE_MSVC_HACK(export, _)
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE_MSVC_HACK(export, _) export
// PROTOBUF_EXPORT_TEMPLATE_STYLE is an internal helper macro that identifies
// which export style needs to be used for the provided FOO_EXPORT macro
// definition. "", "__attribute__(...)", and "__declspec(dllimport)" are
// mapped to "DEFAULT"; while "__declspec(dllexport)" is mapped to "MSVC_HACK".
//
// It's implemented with token pasting to transform the __attribute__ and
// __declspec annotations into macro invocations. E.g., if FOO_EXPORT is
// defined as "__declspec(dllimport)", it undergoes the following sequence of
// macro substitutions:
// PROTOBUF_EXPORT_TEMPLATE_STYLE(FOO_EXPORT, )
// PROTOBUF_EXPORT_TEMPLATE_STYLE_2(__declspec(dllimport), )
// PROTOBUF_EXPORT_TEMPLATE_STYLE_3(
// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport))
// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport)
// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport
// DEFAULT
#define PROTOBUF_EXPORT_TEMPLATE_STYLE(export, _) \
PROTOBUF_EXPORT_TEMPLATE_STYLE_2
(
export
,
)
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_2(export, _) \
PROTOBUF_EXPORT_TEMPLATE_STYLE_3
(
\
PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA
##export)
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_3(style) style
// Internal helper macros for PROTOBUF_EXPORT_TEMPLATE_STYLE.
//
// XXX: C++ reserves all identifiers containing "__" for the implementation,
// but "__attribute__" and "__declspec" already contain "__" and the token-paste
// operator can only add characters; not remove them. To minimize the risk of
// conflict with implementations, we include "foj3FJo5StF0OvIzl7oMxA" (a random
// 128-bit string, encoded in Base64) in the macro name.
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA DEFAULT
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__(...) \
DEFAULT
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec(arg) \
PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_
##arg
// Internal helper macros for PROTOBUF_EXPORT_TEMPLATE_STYLE.
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport MSVC_HACK
#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport DEFAULT
// Sanity checks.
//
// PROTOBUF_EXPORT_TEMPLATE_TEST uses the same macro invocation pattern as
// PROTOBUF_EXPORT_TEMPLATE_DECLARE and PROTOBUF_EXPORT_TEMPLATE_DEFINE do to
// check that they're working correctly. When they're working correctly, the
// sequence of macro replacements should go something like:
//
// PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport));
//
// static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT,
// PROTOBUF_EXPORT_TEMPLATE_STYLE(__declspec(dllimport), ),
// __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT,
// DEFAULT, __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(
// __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(true, "__declspec(dllimport)");
//
// When they're not working correctly, a syntax error should occur instead.
#define PROTOBUF_EXPORT_TEMPLATE_TEST(want, export) \
static_assert
(
PROTOBUF_EXPORT_TEMPLATE_INVOKE
(
\
TEST_
##want, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), \
export
),
#export)
#define PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(...) true
#define PROTOBUF_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK(...) true
PROTOBUF_EXPORT_TEMPLATE_TEST
(
DEFAULT
,
);
PROTOBUF_EXPORT_TEMPLATE_TEST
(
DEFAULT
,
__attribute__
((
visibility
(
"default"
))));
PROTOBUF_EXPORT_TEMPLATE_TEST
(
MSVC_HACK
,
__declspec
(
dllexport
));
PROTOBUF_EXPORT_TEMPLATE_TEST
(
DEFAULT
,
__declspec
(
dllimport
));
#undef PROTOBUF_EXPORT_TEMPLATE_TEST
#undef PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT
#undef PROTOBUF_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK
// Windows declares several inconvenient macro names. We #undef them and then
// restore them in port_undef.inc.
#ifdef _MSC_VER
...
...
src/google/protobuf/port_undef.inc
View file @
df719723
...
...
@@ -68,20 +68,6 @@
#undef PROTOBUF_ASSUME
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE
#undef PROTOBUF_EXPORT_TEMPLATE_INVOKE
#undef PROTOBUF_EXPORT_TEMPLATE_INVOKE_2
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE_DEFAULT
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE_MSVC_HACK
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE_MSVC_HACK
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_2
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_3
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport
// Restore macro that may have been #undef'd in port_def.inc.
#ifdef _MSC_VER
...
...
src/google/protobuf/repeated_field.cc
View file @
df719723
...
...
@@ -123,22 +123,14 @@ MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) {
}
// namespace internal
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
bool
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
int32
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
uint32
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
int64
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
uint64
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
float
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedField
<
double
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
(
PROTOBUF_EXPORT
)
RepeatedPtrField
<
std
::
string
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
bool
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
int32
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
uint32
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
int64
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
uint64
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
float
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedField
<
double
>
;
template
class
PROTOBUF_EXPORT_TEMPLATE_DEFINE
RepeatedPtrField
<
std
::
string
>
;
}
// namespace protobuf
}
// namespace google
src/google/protobuf/repeated_field.h
View file @
df719723
...
...
@@ -2653,21 +2653,14 @@ UnsafeArenaAllocatedRepeatedPtrFieldBackInserter(
}
// Extern declarations of common instantiations to reduce libray bloat.
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
bool
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
int32
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
uint32
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
int64
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
uint64
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
float
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
RepeatedField
<
double
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
(
PROTOBUF_EXPORT
)
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
bool
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
int32
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
uint32
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
int64
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
uint64
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
float
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField
<
double
>
;
extern
template
class
PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedPtrField
<
std
::
string
>
;
}
// 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