⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lzo_init.c

📁 lzo-1.08-src.zip 高效的压缩解压代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* lzo_init.c -- initialization of the LZO library   This file is part of the LZO real-time data compression library.   Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer   All Rights Reserved.   The LZO library is free software; you can redistribute it and/or   modify it under the terms of the GNU General Public License as   published by the Free Software Foundation; either version 2 of   the License, or (at your option) any later version.   The LZO library is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with the LZO library; see the file COPYING.   If not, write to the Free Software Foundation, Inc.,   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.   Markus F.X.J. Oberhumer   <markus@oberhumer.com> */#include "lzo_conf.h"#include "lzo_util.h"#if 0#  define IS_SIGNED(type)		(((type) (1ul << (8 * sizeof(type) - 1))) < 0)#  define IS_UNSIGNED(type)		(((type) (1ul << (8 * sizeof(type) - 1))) > 0)#else#  define IS_SIGNED(type)		(((type) (-1)) < ((type) 0))#  define IS_UNSIGNED(type)		(((type) (-1)) > ((type) 0))#endif#define IS_POWER_OF_2(x)		(((x) & ((x) - 1)) == 0)/***********************************************************************// Runtime check of the assumptions about the size of builtin types,// memory model, byte order and other low-level constructs.//// We are really paranoid here - LZO should either fail (or crash)// at startup or not at all.//// Because of inlining much of these functions evaluates to nothing.************************************************************************/static lzo_bool schedule_insns_bug(void);	/* avoid inlining */static lzo_bool strength_reduce_bug(int *);	/* avoid inlining */#if 0 || defined(LZO_DEBUG)#include <stdio.h>static lzo_bool __lzo_assert_fail(const char *s, unsigned line){#if defined(__palmos__)	printf("LZO assertion failed in line %u: '%s'\n",line,s);#else	fprintf(stderr,"LZO assertion failed in line %u: '%s'\n",line,s);#endif	return 0;}#  define __lzo_assert(x)	((x) ? 1 : __lzo_assert_fail(#x,__LINE__))#else#  define __lzo_assert(x)	((x) ? 1 : 0)#endif#undef COMPILE_TIME_ASSERT#if 0#  define COMPILE_TIME_ASSERT(expr)     r &= __lzo_assert(expr)#else#  define COMPILE_TIME_ASSERT(expr)     LZO_COMPILE_TIME_ASSERT(expr)#endif/***********************************************************************// The next two functions should get completely optimized out of existance.// Some assertions are redundant - but included for clarity.************************************************************************/static lzo_bool basic_integral_check(void){    lzo_bool r = 1;	/* paranoia */	COMPILE_TIME_ASSERT(CHAR_BIT == 8);	COMPILE_TIME_ASSERT(sizeof(char) == 1);	COMPILE_TIME_ASSERT(sizeof(short) >= 2);	COMPILE_TIME_ASSERT(sizeof(long) >= 4);	COMPILE_TIME_ASSERT(sizeof(int) >= sizeof(short));	COMPILE_TIME_ASSERT(sizeof(long) >= sizeof(int));	COMPILE_TIME_ASSERT(sizeof(lzo_uint) == sizeof(lzo_int));	COMPILE_TIME_ASSERT(sizeof(lzo_uint32) == sizeof(lzo_int32));    COMPILE_TIME_ASSERT(sizeof(lzo_uint32) >= 4);	COMPILE_TIME_ASSERT(sizeof(lzo_uint32) >= sizeof(unsigned));#if defined(__LZO_STRICT_16BIT)	COMPILE_TIME_ASSERT(sizeof(lzo_uint) == 2);#else	COMPILE_TIME_ASSERT(sizeof(lzo_uint) >= 4);	COMPILE_TIME_ASSERT(sizeof(lzo_uint) >= sizeof(unsigned));#endif	/* paranoia - check <limits.h> header */#if (USHRT_MAX == 65535u)	COMPILE_TIME_ASSERT(sizeof(short) == 2);#elif (USHRT_MAX == LZO_0xffffffffL)	COMPILE_TIME_ASSERT(sizeof(short) == 4);#elif (USHRT_MAX >= LZO_0xffffffffL)	COMPILE_TIME_ASSERT(sizeof(short) > 4);#endif#if (UINT_MAX == 65535u)	COMPILE_TIME_ASSERT(sizeof(int) == 2);#elif (UINT_MAX == LZO_0xffffffffL)	COMPILE_TIME_ASSERT(sizeof(int) == 4);#elif (UINT_MAX >= LZO_0xffffffffL)	COMPILE_TIME_ASSERT(sizeof(int) > 4);#endif#if (ULONG_MAX == 65535ul)	COMPILE_TIME_ASSERT(sizeof(long) == 2);#elif (ULONG_MAX == LZO_0xffffffffL)	COMPILE_TIME_ASSERT(sizeof(long) == 4);#elif (ULONG_MAX >= LZO_0xffffffffL)	COMPILE_TIME_ASSERT(sizeof(long) > 4);#endif#if defined(SIZEOF_UNSIGNED)	COMPILE_TIME_ASSERT(SIZEOF_UNSIGNED == sizeof(unsigned));#endif#if defined(SIZEOF_UNSIGNED_LONG)	COMPILE_TIME_ASSERT(SIZEOF_UNSIGNED_LONG == sizeof(unsigned long));#endif#if defined(SIZEOF_UNSIGNED_SHORT)	COMPILE_TIME_ASSERT(SIZEOF_UNSIGNED_SHORT == sizeof(unsigned short));#endif#if !defined(__LZO_IN_MINILZO)#if defined(SIZEOF_SIZE_T)	COMPILE_TIME_ASSERT(SIZEOF_SIZE_T == sizeof(size_t));#endif#endif	/* assert the signedness of our integral types */	COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned char));	COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned short));	COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned));	COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned long));	COMPILE_TIME_ASSERT(IS_SIGNED(short));	COMPILE_TIME_ASSERT(IS_SIGNED(int));	COMPILE_TIME_ASSERT(IS_SIGNED(long));	COMPILE_TIME_ASSERT(IS_UNSIGNED(lzo_uint32));	COMPILE_TIME_ASSERT(IS_UNSIGNED(lzo_uint));	COMPILE_TIME_ASSERT(IS_SIGNED(lzo_int32));	COMPILE_TIME_ASSERT(IS_SIGNED(lzo_int));	COMPILE_TIME_ASSERT(INT_MAX    == LZO_STYPE_MAX(sizeof(int)));	COMPILE_TIME_ASSERT(UINT_MAX   == LZO_UTYPE_MAX(sizeof(unsigned)));	COMPILE_TIME_ASSERT(LONG_MAX   == LZO_STYPE_MAX(sizeof(long)));	COMPILE_TIME_ASSERT(ULONG_MAX  == LZO_UTYPE_MAX(sizeof(unsigned long)));	COMPILE_TIME_ASSERT(SHRT_MAX   == LZO_STYPE_MAX(sizeof(short)));	COMPILE_TIME_ASSERT(USHRT_MAX  == LZO_UTYPE_MAX(sizeof(unsigned short)));	COMPILE_TIME_ASSERT(LZO_UINT32_MAX == LZO_UTYPE_MAX(sizeof(lzo_uint32)));	COMPILE_TIME_ASSERT(LZO_UINT_MAX   == LZO_UTYPE_MAX(sizeof(lzo_uint)));#if !defined(__LZO_IN_MINILZO)	COMPILE_TIME_ASSERT(SIZE_T_MAX     == LZO_UTYPE_MAX(sizeof(size_t)));#endif	r &= __lzo_assert(LZO_BYTE(257) == 1);	return r;}static lzo_bool basic_ptr_check(void){	lzo_bool r = 1;	COMPILE_TIME_ASSERT(sizeof(char *) >= sizeof(int));	COMPILE_TIME_ASSERT(sizeof(lzo_byte *) >= sizeof(char *));	COMPILE_TIME_ASSERT(sizeof(lzo_voidp) == sizeof(lzo_byte *));	COMPILE_TIME_ASSERT(sizeof(lzo_voidp) == sizeof(lzo_voidpp));	COMPILE_TIME_ASSERT(sizeof(lzo_voidp) == sizeof(lzo_bytepp));	COMPILE_TIME_ASSERT(sizeof(lzo_voidp) >= sizeof(lzo_uint));	COMPILE_TIME_ASSERT(sizeof(lzo_ptr_t) == sizeof(lzo_voidp));	COMPILE_TIME_ASSERT(sizeof(lzo_ptr_t) == sizeof(lzo_sptr_t));	COMPILE_TIME_ASSERT(sizeof(lzo_ptr_t) >= sizeof(lzo_uint));	COMPILE_TIME_ASSERT(sizeof(lzo_ptrdiff_t) >= 4);	COMPILE_TIME_ASSERT(sizeof(lzo_ptrdiff_t) >= sizeof(ptrdiff_t));	COMPILE_TIME_ASSERT(sizeof(ptrdiff_t) >= sizeof(size_t));	COMPILE_TIME_ASSERT(sizeof(lzo_ptrdiff_t) >= sizeof(lzo_uint));#if defined(SIZEOF_CHAR_P)	COMPILE_TIME_ASSERT(SIZEOF_CHAR_P == sizeof(char *));#endif#if defined(SIZEOF_PTRDIFF_T)	COMPILE_TIME_ASSERT(SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t));#endif	/* assert the signedness of our integral types */	COMPILE_TIME_ASSERT(IS_SIGNED(ptrdiff_t));	COMPILE_TIME_ASSERT(IS_UNSIGNED(size_t));	COMPILE_TIME_ASSERT(IS_SIGNED(lzo_ptrdiff_t));	COMPILE_TIME_ASSERT(IS_SIGNED(lzo_sptr_t));	COMPILE_TIME_ASSERT(IS_UNSIGNED(lzo_ptr_t));	COMPILE_TIME_ASSERT(IS_UNSIGNED(lzo_moff_t));	return r;}/***********************************************************************//************************************************************************/static lzo_bool ptr_check(void){	lzo_bool r = 1;	int i;	char _wrkmem[10 * sizeof(lzo_byte *) + sizeof(lzo_full_align_t)];	lzo_bytep wrkmem;	lzo_bytepp dict;	unsigned char x[4 * sizeof(lzo_full_align_t)];	long d;	lzo_full_align_t a;	lzo_full_align_t u;	for (i = 0; i < (int) sizeof(x); i++)		x[i] = LZO_BYTE(i);	wrkmem = LZO_PTR_ALIGN_UP((lzo_byte *)_wrkmem,sizeof(lzo_full_align_t));#if 0	dict = (lzo_bytepp) wrkmem;#else    /* Avoid a compiler warning on architectures that     * do not allow unaligned access. */    u.a_lzo_bytep = wrkmem; dict = u.a_lzo_bytepp;#endif	d = (long) ((const lzo_bytep) dict - (const lzo_bytep) _wrkmem);	r &= __lzo_assert(d >= 0);	r &= __lzo_assert(d < (long) sizeof(lzo_full_align_t));	memset(&a,0,sizeof(a));	r &= __lzo_assert(a.a_lzo_voidp == NULL);	memset(&a,0xff,sizeof(a));	r &= __lzo_assert(a.a_ushort == USHRT_MAX);	r &= __lzo_assert(a.a_uint == UINT_MAX);	r &= __lzo_assert(a.a_ulong == ULONG_MAX);	r &= __lzo_assert(a.a_lzo_uint == LZO_UINT_MAX);	r &= __lzo_assert(a.a_lzo_uint32 == LZO_UINT32_MAX);	/* sanity check of the memory model */	if (r == 1)	{		for (i = 0; i < 8; i++)			r &= __lzo_assert((const lzo_voidp) (&dict[i]) == (const lzo_voidp) (&wrkmem[i * sizeof(lzo_byte *)]));	}	/* check BZERO8_PTR and that NULL == 0 */	memset(&a,0,sizeof(a));	r &= __lzo_assert(a.a_char_p == NULL);	r &= __lzo_assert(a.a_lzo_bytep == NULL);	r &= __lzo_assert(NULL == (void *)0);	if (r == 1)	{		for (i = 0; i < 10; i++)			dict[i] = wrkmem;		BZERO8_PTR(dict+1,sizeof(dict[0]),8);		r &= __lzo_assert(dict[0] == wrkmem);		for (i = 1; i < 9; i++)			r &= __lzo_assert(dict[i] == NULL);		r &= __lzo_assert(dict[9] == wrkmem);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -