1 /* lzo_init.c -- initialization of the LZO library
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
20 The LZO library is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation; either version 2 of
23 the License, or (at your option) any later version.
25 The LZO library is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with the LZO library; see the file COPYING.
32 If not, write to the Free Software Foundation, Inc.,
33 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 Markus F.X.J. Oberhumer
36 <markus@oberhumer.com>
37 http://www.oberhumer.com/opensource/lzo/
44 /***********************************************************************
45 // Runtime check of the assumptions about the size of builtin types,
46 // memory model, byte order and other low-level constructs.
48 // We are really paranoid here - LZO should either fail
49 // at startup or not at all.
51 // Because of inlining much of these functions evaluates to nothing.
53 // And while many of the tests seem highly obvious and redundant they are
54 // here to catch compiler/optimizer bugs. Yes, these do exist.
55 ************************************************************************/
57 #if !defined(__LZO_IN_MINILZO)
59 #define ACC_WANT_ACC_CHK_CH 1
63 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int
)
64 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint
)
66 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32
)
67 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32
)
68 ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0)
69 ACCCHK_ASSERT(sizeof(lzo_uint32
) >= 4)
71 #if !defined(__LZO_UINTPTR_T_IS_POINTER)
72 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t
)
74 ACCCHK_ASSERT(sizeof(lzo_uintptr_t
) >= sizeof(lzo_voidp
))
76 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint
)
77 ACCCHK_ASSERT(sizeof(lzo_xint
) >= sizeof(lzo_uint32
))
78 ACCCHK_ASSERT(sizeof(lzo_xint
) >= sizeof(lzo_uint
))
79 ACCCHK_ASSERT(sizeof(lzo_xint
) == sizeof(lzo_uint32
) || sizeof(lzo_xint
) == sizeof(lzo_uint
))
85 /***********************************************************************
87 ************************************************************************/
90 _lzo_config_check(void)
93 union { unsigned char c
[2*sizeof(lzo_xint
)]; lzo_xint l
[2]; } u
;
96 #if !defined(LZO_CFG_NO_CONFIG_CHECK)
97 #if defined(LZO_ABI_BIG_ENDIAN)
98 u
.l
[0] = u
.l
[1] = 0; u
.c
[sizeof(lzo_xint
) - 1] = 128;
101 #if defined(LZO_ABI_LITTLE_ENDIAN)
102 u
.l
[0] = u
.l
[1] = 0; u
.c
[0] = 128;
103 r
&= (u
.l
[0] == 128);
105 #if defined(LZO_UNALIGNED_OK_2)
106 p
= (lzo_uintptr_t
) (const lzo_voidp
) &u
.c
[0];
108 r
&= ((* (const lzo_ushortp
) (p
+1)) == 0);
110 #if defined(LZO_UNALIGNED_OK_4)
111 p
= (lzo_uintptr_t
) (const lzo_voidp
) &u
.c
[0];
113 r
&= ((* (const lzo_uint32p
) (p
+1)) == 0);
117 LZO_UNUSED(u
); LZO_UNUSED(p
);
118 return r
== 1 ? LZO_E_OK
: LZO_E_ERROR
;
122 /***********************************************************************
124 ************************************************************************/
126 int __lzo_init_done
= 0;
129 __lzo_init_v2(unsigned v
, int s1
, int s2
, int s3
, int s4
, int s5
,
130 int s6
, int s7
, int s8
, int s9
)
134 #if defined(__LZO_IN_MINILZO)
135 #elif (LZO_CC_MSC && ((_MSC_VER) < 700))
137 #define ACC_WANT_ACC_CHK_CH 1
139 #define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr)
149 r
= (s1
== -1 || s1
== (int) sizeof(short)) &&
150 (s2
== -1 || s2
== (int) sizeof(int)) &&
151 (s3
== -1 || s3
== (int) sizeof(long)) &&
152 (s4
== -1 || s4
== (int) sizeof(lzo_uint32
)) &&
153 (s5
== -1 || s5
== (int) sizeof(lzo_uint
)) &&
154 (s6
== -1 || s6
== (int) lzo_sizeof_dict_t
) &&
155 (s7
== -1 || s7
== (int) sizeof(char *)) &&
156 (s8
== -1 || s8
== (int) sizeof(lzo_voidp
)) &&
157 (s9
== -1 || s9
== (int) sizeof(lzo_callback_t
));
161 r
= _lzo_config_check();
169 #if !defined(__LZO_IN_MINILZO)
170 #include "lzo_dll.ch"