3
// This file is part of Bombono DVD project.
5
// Copyright (c) 2007-2010 Ilya Murav'jov
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program; if not, write to the Free Software
19
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#ifndef __MLIB_TECH_H__
23
#define __MLIB_TECH_H__
28
#include <boost/current_function.hpp> // для BOOST_CURRENT_FUNCTION
29
#include <boost/detail/endian.hpp> // для BOOST_XXX_ENDIAN
31
// для С-шного кода в С++
32
#if defined(__cplusplus) || defined(c_plusplus)
33
#define C_LINKAGE extern "C"
34
#define C_LINKAGE_BEGIN extern "C" {
35
#define C_LINKAGE_END }
38
#define C_LINKAGE_BEGIN
42
// посчитать размер C-массива (T arr[] = {...}; )
43
#define ARR_SIZE(arr) ( sizeof(arr)/sizeof(arr[0]) )
45
// используем конструкцию наподобие
47
// struct packed_data { ... };
49
// , чтобы у аттрибутов packed_data не было выравнивания;
50
// другой вариант - __attribute__ ((packed)), но он есть только у gcc
52
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__COMO__) || defined(_MSC_VER)
53
# define HAS_PACK_STACK
56
#define PACK_ON <mlib/pack_on.h>
57
#define PACK_OFF <mlib/pack_off.h>
59
// ASSERT(), ASSERT_RTL()
60
#define ASSERT_IMPL(expr) ((expr) ? ((void)0) : AssertImpl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
64
#define ASSERT(expr) ((void)0)
66
#define ASSERT(expr) ASSERT_IMPL(expr)
69
#define ASSERT_RTL(expr) ASSERT_IMPL(expr)
71
// ErrorMsg(), Error()
72
void ErrorMsg(const char* str);
73
void Error(const char* str);
76
void AssertImpl(const char* assertion, const char* file,
77
long line, const char* function);
80
#if defined(BOOST_BIG_ENDIAN)
81
# define HAS_BIG_ENDIAN
82
#elif defined(BOOST_LITTLE_ENDIAN)
83
# define HAS_LITTLE_ENDIAN
85
# error mlib/tech.h: unknown endianness (legacy PDP arch?)
88
// gcc 4.4 вываливает кучу предупреждений о strict-alias rules
89
// (только при >= -O2), но чувствую, что неправильно
91
#if defined(NDEBUG) && defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4)
92
#define __GNUC_INCORRECT_SAR__
95
// помечаем так переменные, чтобы убрать warning: unused variable;
96
// которые тем не менее используются, но не всегда, см. ASSERT()
97
#define UNUSED_VAR(x) ((void)(x))
99
#define ASSERT_OR_UNUSED(expr) UNUSED_VAR(expr)
100
#define ASSERT_OR_UNUSED_VAR(expr, x) UNUSED_VAR(x)
102
#define ASSERT_OR_UNUSED(expr) ASSERT(expr)
103
#define ASSERT_OR_UNUSED_VAR(expr, x) ASSERT(expr)
106
// тоже самое, но для функций (только gcc)
108
#define UNUSED_FUNCTION __attribute__((unused))
110
#define UNUSED_FUNCTION
113
#endif // #ifndef __MLIB_TECH_H__