|
kusano |
7d535a |
/* lzo_init.c -- initialization of the LZO library
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This file is part of the LZO real-time data compression library.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
All Rights Reserved.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The LZO library is free software; you can redistribute it and/or
|
|
kusano |
7d535a |
modify it under the terms of the GNU General Public License as
|
|
kusano |
7d535a |
published by the Free Software Foundation; either version 2 of
|
|
kusano |
7d535a |
the License, or (at your option) any later version.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The LZO library is distributed in the hope that it will be useful,
|
|
kusano |
7d535a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
kusano |
7d535a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
kusano |
7d535a |
GNU General Public License for more details.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
You should have received a copy of the GNU General Public License
|
|
kusano |
7d535a |
along with the LZO library; see the file COPYING.
|
|
kusano |
7d535a |
If not, write to the Free Software Foundation, Inc.,
|
|
kusano |
7d535a |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Markus F.X.J. Oberhumer
|
|
kusano |
7d535a |
<markus@oberhumer.com></markus@oberhumer.com>
|
|
kusano |
7d535a |
http://www.oberhumer.com/opensource/lzo/
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include "lzo_conf.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
// Runtime check of the assumptions about the size of builtin types,
|
|
kusano |
7d535a |
// memory model, byte order and other low-level constructs.
|
|
kusano |
7d535a |
//
|
|
kusano |
7d535a |
// We are really paranoid here - LZO should either fail
|
|
kusano |
7d535a |
// at startup or not at all.
|
|
kusano |
7d535a |
//
|
|
kusano |
7d535a |
// Because of inlining much of these functions evaluates to nothing.
|
|
kusano |
7d535a |
//
|
|
kusano |
7d535a |
// And while many of the tests seem highly obvious and redundant they are
|
|
kusano |
7d535a |
// here to catch compiler/optimizer bugs. Yes, these do exist.
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(__LZO_IN_MINILZO)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define ACC_WANT_ACC_CHK_CH 1
|
|
kusano |
7d535a |
#undef ACCCHK_ASSERT
|
|
kusano |
7d535a |
#include "miniacc.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
ACCCHK_ASSERT_IS_SIGNED_T(lzo_int)
|
|
kusano |
7d535a |
ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32)
|
|
kusano |
7d535a |
ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32)
|
|
kusano |
7d535a |
ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0)
|
|
kusano |
7d535a |
ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(__LZO_UINTPTR_T_IS_POINTER)
|
|
kusano |
7d535a |
ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint)
|
|
kusano |
7d535a |
ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32))
|
|
kusano |
7d535a |
ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint))
|
|
kusano |
7d535a |
ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#undef ACCCHK_ASSERT
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
//
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
LZO_PUBLIC(int)
|
|
kusano |
7d535a |
_lzo_config_check(void)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
lzo_bool r = 1;
|
|
kusano |
7d535a |
union { unsigned char c[2*sizeof(lzo_xint)]; lzo_xint l[2]; } u;
|
|
kusano |
7d535a |
lzo_uintptr_t p;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(LZO_CFG_NO_CONFIG_CHECK)
|
|
kusano |
7d535a |
#if defined(LZO_ABI_BIG_ENDIAN)
|
|
kusano |
7d535a |
u.l[0] = u.l[1] = 0; u.c[sizeof(lzo_xint) - 1] = 128;
|
|
kusano |
7d535a |
r &= (u.l[0] == 128);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if defined(LZO_ABI_LITTLE_ENDIAN)
|
|
kusano |
7d535a |
u.l[0] = u.l[1] = 0; u.c[0] = 128;
|
|
kusano |
7d535a |
r &= (u.l[0] == 128);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if defined(LZO_UNALIGNED_OK_2)
|
|
kusano |
7d535a |
p = (lzo_uintptr_t) (const lzo_voidp) &u.c[0];
|
|
kusano |
7d535a |
u.l[0] = u.l[1] = 0;
|
|
kusano |
7d535a |
r &= ((* (const lzo_ushortp) (p+1)) == 0);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if defined(LZO_UNALIGNED_OK_4)
|
|
kusano |
7d535a |
p = (lzo_uintptr_t) (const lzo_voidp) &u.c[0];
|
|
kusano |
7d535a |
u.l[0] = u.l[1] = 0;
|
|
kusano |
7d535a |
r &= ((* (const lzo_uint32p) (p+1)) == 0);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
LZO_UNUSED(u); LZO_UNUSED(p);
|
|
kusano |
7d535a |
return r == 1 ? LZO_E_OK : LZO_E_ERROR;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
//
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int __lzo_init_done = 0;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
LZO_PUBLIC(int)
|
|
kusano |
7d535a |
__lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5,
|
|
kusano |
7d535a |
int s6, int s7, int s8, int s9)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int r;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(__LZO_IN_MINILZO)
|
|
kusano |
7d535a |
#elif (LZO_CC_MSC && ((_MSC_VER) < 700))
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
#define ACC_WANT_ACC_CHK_CH 1
|
|
kusano |
7d535a |
#undef ACCCHK_ASSERT
|
|
kusano |
7d535a |
#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr)
|
|
kusano |
7d535a |
#include "miniacc.h"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#undef ACCCHK_ASSERT
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
__lzo_init_done = 1;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (v == 0)
|
|
kusano |
7d535a |
return LZO_E_ERROR;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
r = (s1 == -1 || s1 == (int) sizeof(short)) &&
|
|
kusano |
7d535a |
(s2 == -1 || s2 == (int) sizeof(int)) &&
|
|
kusano |
7d535a |
(s3 == -1 || s3 == (int) sizeof(long)) &&
|
|
kusano |
7d535a |
(s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&
|
|
kusano |
7d535a |
(s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&
|
|
kusano |
7d535a |
(s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&
|
|
kusano |
7d535a |
(s7 == -1 || s7 == (int) sizeof(char *)) &&
|
|
kusano |
7d535a |
(s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
|
|
kusano |
7d535a |
(s9 == -1 || s9 == (int) sizeof(lzo_callback_t));
|
|
kusano |
7d535a |
if (!r)
|
|
kusano |
7d535a |
return LZO_E_ERROR;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
r = _lzo_config_check();
|
|
kusano |
7d535a |
if (r != LZO_E_OK)
|
|
kusano |
7d535a |
return r;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
return r;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(__LZO_IN_MINILZO)
|
|
kusano |
7d535a |
#include "lzo_dll.ch"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
vi:ts=4:et
|
|
kusano |
7d535a |
*/
|