Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
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
brpc
Commits
5f90bc47
Commit
5f90bc47
authored
Aug 22, 2017
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support clang 3.5-3.9
Change-Id: Ibcd6f03e67d05607abb809616ac6e50c61d7daed
parent
38c5fe34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
17 deletions
+54
-17
macros.h
src/base/macros.h
+53
-16
ts.cpp
src/brpc/ts.cpp
+1
-1
No files found.
src/base/macros.h
View file @
5f90bc47
...
...
@@ -348,32 +348,69 @@ enum LinkerInitialized { LINKER_INITIALIZED };
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
// Same effect as `Tp name[size]' if size <= maxsize, otherwise `name' is
// allocated on heap and will be deleted when escaping current scope.
// A 'size_t name##_size' is defined as well whose value is `size'.
// NOTE: NEVER use ARRAY_SIZE(name) which is always 1.
// DEFINE_SMALL_ARRAY(MyType, my_array, size, 64);
// my_array is typed `MyType*' and as long as `size'. If `size' is not
// greater than 64, the array is allocated on stack.
//
// NOTE: NEVER use ARRAY_SIZE(my_array) which is always 1.
#if defined(__cplusplus)
namespace
base
{
namespace
internal
{
template
<
typename
T
>
struct
ArrayDeleter
{
ArrayDeleter
()
:
arr
(
0
)
{}
~
ArrayDeleter
()
{
delete
[]
arr
;
}
T
*
arr
;
};
}}
// Many versions of clang does not support variable-length array with non-pod
// types, have to implement the macro differently.
#if !defined(__clang__)
# define DEFINE_SMALL_ARRAY(Tp, name, size, maxsize) \
Tp* name = 0; \
const
size_t name##_size = (size);
\
const
size_t name##_maxsize = (maxsize);
\
Tp name##_stack_array[name##_s
ize <= name##_maxsize ? name##_size : 0];
\
::base::
ArrayDeleter<Tp> name##_array_deleter;
\
if (name##_s
ize <= name##_maxsize) {
\
const
unsigned name##_size = (size);
\
const
unsigned name##_stack_array_size = (name##_size <= (maxsize) ? name##_size : 0);
\
Tp name##_stack_array[name##_s
tack_array_size];
\
::base::
internal::ArrayDeleter<Tp> name##_array_deleter;
\
if (name##_s
tack_array_size) {
\
name = name##_stack_array; \
} else { \
name = new (::std::nothrow) Tp[name##_size]; \
name##_array_deleter.arr = name; \
}
#else
// This implementation works for GCC as well, however it needs extra 16 bytes
// for ArrayCtorDtor.
namespace
base
{
template
<
typename
T
>
struct
ArrayDeleter
{
ArrayDeleter
()
:
arr
(
0
)
{}
~
ArrayDeleter
()
{
delete
[]
arr
;
}
T
*
arr
;
namespace
internal
{
template
<
typename
T
>
struct
ArrayCtorDtor
{
ArrayCtorDtor
(
void
*
arr
,
unsigned
size
)
:
_arr
((
T
*
)
arr
),
_size
(
size
)
{
for
(
unsigned
i
=
0
;
i
<
size
;
++
i
)
{
new
(
_arr
+
i
)
T
;
}
}
~
ArrayCtorDtor
()
{
for
(
unsigned
i
=
0
;
i
<
_size
;
++
i
)
{
_arr
[
i
].
~
T
();
}
}
private
:
T
*
_arr
;
unsigned
_size
;
};
}
#endif
}}
# define DEFINE_SMALL_ARRAY(Tp, name, size, maxsize) \
Tp* name = 0; \
const unsigned name##_size = (size); \
const unsigned name##_stack_array_size = (name##_size <= (maxsize) ? name##_size : 0); \
char name##_stack_array[sizeof(Tp) * name##_stack_array_size]; \
::base::internal::ArrayDeleter<char> name##_array_deleter; \
if (name##_stack_array_size) { \
name = (Tp*)name##_stack_array; \
} else { \
name = (Tp*)new (::std::nothrow) char[sizeof(Tp) * name##_size];\
name##_array_deleter.arr = (char*)name; \
} \
const ::base::internal::ArrayCtorDtor<Tp> name##_array_ctor_dtor(name, name##_size);
#endif // !defined(__clang__)
#endif // defined(__cplusplus)
// Put following code somewhere global to run it before main():
//
...
...
src/brpc/ts.cpp
View file @
5f90bc47
...
...
@@ -675,7 +675,7 @@ int TsPayloadPES::Encode(void* data) const {
encode_33bits_dts_pts
(
&
p
,
0x03
,
pts
);
encode_33bits_dts_pts
(
&
p
,
0x01
,
dts
);
// the diff of dts and pts should never be greater than 1s.
if
(
abs
(
dts
-
pts
)
>
90000
)
{
if
(
l
abs
(
dts
-
pts
)
>
90000
)
{
LOG
(
WARNING
)
<<
"Diff between dts="
<<
dts
<<
" and pts="
<<
pts
<<
" is greater than 1 second"
;
}
...
...
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