1/* lzo_init.c -- initialization of the LZO library 2 3 This file is part of the LZO real-time data compression library. 4 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 18 All Rights Reserved. 19 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. 24 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. 29 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. 34 35 Markus F.X.J. Oberhumer 36 <markus@oberhumer.com> 37 http://www.oberhumer.com/opensource/lzo/ 38 */ 39 40 41#include "lzo_conf.h" 42 43 44/*********************************************************************** 45// Runtime check of the assumptions about the size of builtin types, 46// memory model, byte order and other low-level constructs. 47// 48// We are really paranoid here - LZO should either fail 49// at startup or not at all. 50// 51// Because of inlining much of these functions evaluates to nothing. 52// 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************************************************************************/ 56 57#if !defined(__LZO_IN_MINILZO) 58 59#define ACC_WANT_ACC_CHK_CH 1 60#undef ACCCHK_ASSERT 61#include "miniacc.h" 62 63 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) 64 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) 65 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) 70 71#if !defined(__LZO_UINTPTR_T_IS_POINTER) 72 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) 73#endif 74 ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) 75 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)) 80 81#endif 82#undef ACCCHK_ASSERT 83 84 85/*********************************************************************** 86// 87************************************************************************/ 88 89LZO_PUBLIC(int) 90_lzo_config_check(void) 91{ 92 lzo_bool r = 1; 93 union { unsigned char c[2*sizeof(lzo_xint)]; lzo_xint l[2]; } u; 94 lzo_uintptr_t p; 95 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; 99 r &= (u.l[0] == 128); 100#endif 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); 104#endif 105#if defined(LZO_UNALIGNED_OK_2) 106 p = (lzo_uintptr_t) (const lzo_voidp) &u.c[0]; 107 u.l[0] = u.l[1] = 0; 108 r &= ((* (const lzo_ushortp) (p+1)) == 0); 109#endif 110#if defined(LZO_UNALIGNED_OK_4) 111 p = (lzo_uintptr_t) (const lzo_voidp) &u.c[0]; 112 u.l[0] = u.l[1] = 0; 113 r &= ((* (const lzo_uint32p) (p+1)) == 0); 114#endif 115#endif 116 117 LZO_UNUSED(u); LZO_UNUSED(p); 118 return r == 1 ? LZO_E_OK : LZO_E_ERROR; 119} 120 121 122/*********************************************************************** 123// 124************************************************************************/ 125 126int __lzo_init_done = 0; 127 128LZO_PUBLIC(int) 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) 131{ 132 int r; 133 134#if defined(__LZO_IN_MINILZO) 135#elif (LZO_CC_MSC && ((_MSC_VER) < 700)) 136#else 137#define ACC_WANT_ACC_CHK_CH 1 138#undef ACCCHK_ASSERT 139#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) 140#include "miniacc.h" 141#endif 142#undef ACCCHK_ASSERT 143 144 __lzo_init_done = 1; 145 146 if (v == 0) 147 return LZO_E_ERROR; 148 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)); 158 if (!r) 159 return LZO_E_ERROR; 160 161 r = _lzo_config_check(); 162 if (r != LZO_E_OK) 163 return r; 164 165 return r; 166} 167 168 169#if !defined(__LZO_IN_MINILZO) 170#include "lzo_dll.ch" 171#endif 172 173 174/* 175vi:ts=4:et 176*/ 177