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

📄 lzo_init.c

📁 lzo-1.08-src.zip 高效的压缩解压代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* check that the pointer constructs work as expected */	if (r == 1)	{		unsigned k = 1;		const unsigned n = (unsigned) sizeof(lzo_uint32);		lzo_byte *p0;		lzo_byte *p1;		k += __lzo_align_gap(&x[k],n);		p0 = (lzo_bytep) &x[k];#if defined(PTR_LINEAR)		r &= __lzo_assert((PTR_LINEAR(p0) & (n-1)) == 0);#else		r &= __lzo_assert(n == 4);		r &= __lzo_assert(PTR_ALIGNED_4(p0));#endif		r &= __lzo_assert(k >= 1);		p1 = (lzo_bytep) &x[1];		r &= __lzo_assert(PTR_GE(p0,p1));		r &= __lzo_assert(k < 1+n);		p1 = (lzo_bytep) &x[1+n];		r &= __lzo_assert(PTR_LT(p0,p1));		/* now check that aligned memory access doesn't core dump */		if (r == 1)		{            lzo_uint32 v0, v1;#if 0			v0 = * (lzo_uint32 *) &x[k];			v1 = * (lzo_uint32 *) &x[k+n];#else            /* Avoid compiler warnings on architectures that             * do not allow unaligned access. */            u.a_uchar_p = &x[k];            v0 = *u.a_lzo_uint32_p;            u.a_uchar_p = &x[k+n];            v1 = *u.a_lzo_uint32_p;#endif			r &= __lzo_assert(v0 > 0);			r &= __lzo_assert(v1 > 0);		}	}	return r;}/***********************************************************************//************************************************************************/LZO_PUBLIC(int)_lzo_config_check(void){	lzo_bool r = 1;	int i;	union {		lzo_uint32 a;		unsigned short b;		lzo_uint32 aa[4];		unsigned char x[4*sizeof(lzo_full_align_t)];	} u;	/* check that the compiler correctly casts signed to unsigned */	COMPILE_TIME_ASSERT( (int) ((unsigned char) ((signed char) -1)) == 255);	/* check that the compiler correctly promotes integrals */	COMPILE_TIME_ASSERT( (((unsigned char)128) << (int)(8*sizeof(int)-8)) < 0);#if 0	/* paranoia - the following is guaranteed by definition anyway */	r &= __lzo_assert((const void *)&u == (const void *)&u.a);	r &= __lzo_assert((const void *)&u == (const void *)&u.b);	r &= __lzo_assert((const void *)&u == (const void *)&u.x[0]);	r &= __lzo_assert((const void *)&u == (const void *)&u.aa[0]);#endif	r &= basic_integral_check();	r &= basic_ptr_check();	if (r != 1)		return LZO_E_ERROR;	u.a = 0; u.b = 0;	for (i = 0; i < (int) sizeof(u.x); i++)		u.x[i] = LZO_BYTE(i);	/* check LZO_BYTE_ORDER */#if defined(LZO_BYTE_ORDER)	if (r == 1)	{#  if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)		lzo_uint32 a = (lzo_uint32) (u.a & LZO_0xffffffffL);		unsigned short b = (unsigned short) (u.b & 0xffff);		r &= __lzo_assert(a == 0x03020100L);		r &= __lzo_assert(b == 0x0100);#  elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)		lzo_uint32 a = u.a >> (8 * sizeof(u.a) - 32);		unsigned short b = u.b >> (8 * sizeof(u.b) - 16);		r &= __lzo_assert(a == 0x00010203L);		r &= __lzo_assert(b == 0x0001);#  else#    error "invalid LZO_BYTE_ORDER"#  endif	}#endif	/* check that unaligned memory access works as expected */#if defined(LZO_UNALIGNED_OK_2)	COMPILE_TIME_ASSERT(sizeof(short) == 2);	if (r == 1)	{		unsigned short b[4];        for (i = 0; i < 4; i++)            b[i] = * (const unsigned short *) &u.x[i];#  if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)		r &= __lzo_assert(b[0] == 0x0100);		r &= __lzo_assert(b[1] == 0x0201);		r &= __lzo_assert(b[2] == 0x0302);		r &= __lzo_assert(b[3] == 0x0403);#  elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)		r &= __lzo_assert(b[0] == 0x0001);		r &= __lzo_assert(b[1] == 0x0102);		r &= __lzo_assert(b[2] == 0x0203);		r &= __lzo_assert(b[3] == 0x0304);#  endif	}#endif#if defined(LZO_UNALIGNED_OK_4)	COMPILE_TIME_ASSERT(sizeof(lzo_uint32) == 4);	if (r == 1)	{		lzo_uint32 a[4];		for (i = 0; i < 4; i++)			a[i] = * (const lzo_uint32 *) &u.x[i];#  if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)		r &= __lzo_assert(a[0] == 0x03020100L);		r &= __lzo_assert(a[1] == 0x04030201L);		r &= __lzo_assert(a[2] == 0x05040302L);		r &= __lzo_assert(a[3] == 0x06050403L);#  elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)		r &= __lzo_assert(a[0] == 0x00010203L);		r &= __lzo_assert(a[1] == 0x01020304L);		r &= __lzo_assert(a[2] == 0x02030405L);		r &= __lzo_assert(a[3] == 0x03040506L);#  endif	}#endif#if defined(LZO_ALIGNED_OK_4)	COMPILE_TIME_ASSERT(sizeof(lzo_uint32) == 4);#endif	COMPILE_TIME_ASSERT(lzo_sizeof_dict_t == sizeof(lzo_dict_t));	/* save space and don't require linking in the lzo_adler32() function */#if defined(__LZO_IN_MINLZO)	/* check the lzo_adler32() function */	if (r == 1)	{		lzo_uint32 adler;		adler = lzo_adler32(0, NULL, 0);		adler = lzo_adler32(adler, lzo_copyright(), 200);		r &= __lzo_assert(adler == 0xc76f1751L);	}#endif	/* check for the gcc schedule-insns optimization bug */	if (r == 1)	{		r &= __lzo_assert(!schedule_insns_bug());	}	/* check for the gcc strength-reduce optimization bug */	if (r == 1)	{		static int x[3];		static unsigned xn = 3;		register unsigned j;		for (j = 0; j < xn; j++)			x[j] = (int)j - 3;		r &= __lzo_assert(!strength_reduce_bug(x));	}	/* now for the low-level pointer checks */	if (r == 1)	{		r &= ptr_check();	}	return r == 1 ? LZO_E_OK : LZO_E_ERROR;}static lzo_bool schedule_insns_bug(void){#if defined(__LZO_CHECKER)	/* for some reason checker complains about uninitialized memory access */	return 0;#else	const int clone[] = {1, 2, 0};	const int *q;	q = clone;	return (*q) ? 0 : 1;#endif}static lzo_bool strength_reduce_bug(int *x){	return x[0] != -3 || x[1] != -2 || x[2] != -1;}#undef COMPILE_TIME_ASSERT/***********************************************************************//************************************************************************/int __lzo_init_done = 0;LZO_PUBLIC(int)__lzo_init2(unsigned v, int s1, int s2, int s3, int s4, int s5,                        int s6, int s7, int s8, int s9){	int r;	__lzo_init_done = 1;	if (v == 0)		return LZO_E_ERROR;	r = (s1 == -1 || s1 == (int) sizeof(short)) &&	    (s2 == -1 || s2 == (int) sizeof(int)) &&	    (s3 == -1 || s3 == (int) sizeof(long)) &&	    (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&	    (s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&	    (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&	    (s7 == -1 || s7 == (int) sizeof(char *)) &&	    (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&	    (s9 == -1 || s9 == (int) sizeof(lzo_compress_t));	if (!r)		return LZO_E_ERROR;	r = _lzo_config_check();	if (r != LZO_E_OK)		return r;	return r;}/***********************************************************************// backward compatibility with v1.01************************************************************************/#if !defined(__LZO_IN_MINILZO)LZO_EXTERN(int)__lzo_init(unsigned v,int s1,int s2,int s3,int s4,int s5,int s6,int s7);LZO_PUBLIC(int)__lzo_init(unsigned v,int s1,int s2,int s3,int s4,int s5,int s6,int s7){	if (v == 0 || v > 0x1010)		return LZO_E_ERROR;	return __lzo_init2(v,s1,s2,s3,s4,s5,-1,-1,s6,s7);}#endif/*vi:ts=4:et*/

⌨️ 快捷键说明

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