Commit 5f90bc47 authored by gejun's avatar gejun

Support clang 3.5-3.9

Change-Id: Ibcd6f03e67d05607abb809616ac6e50c61d7daed
parent 38c5fe34
......@@ -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##_size <= name##_maxsize ? name##_size : 0]; \
::base::ArrayDeleter<Tp> name##_array_deleter; \
if (name##_size <= name##_maxsize) { \
const unsigned name##_size = (size); \
const unsigned name##_stack_array_size = (name##_size <= (maxsize) ? name##_size : 0); \
Tp name##_stack_array[name##_stack_array_size]; \
::base::internal::ArrayDeleter<Tp> name##_array_deleter; \
if (name##_stack_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():
//
......
......@@ -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 (labs(dts - pts) > 90000) {
LOG(WARNING) << "Diff between dts=" << dts << " and pts=" << pts
<< " is greater than 1 second";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment