cvs: pecl /lzf lzf.h lzfP.h lzf_c.c lzf_d.c

From: Date: Fri, 13 Aug 2004 22:45:21 +0000
Subject: cvs: pecl /lzf lzf.h lzfP.h lzf_c.c lzf_d.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1654@lists.php.net to get a copy of this message
mg Fri Aug 13 18:45:21 2004 EDT Modified files: /pecl/lzf lzf.h lzfP.h lzf_c.c lzf_d.c Log: Upgrade bundled liblzf to the latest version.

http://cvs.php.net/diff.php/pecl/lzf/lzf.h?r1=1.1&r2=1.2&ty=u Index: pecl/lzf/lzf.h diff -u pecl/lzf/lzf.h:1.1 pecl/lzf/lzf.h:1.2 --- pecl/lzf/lzf.h:1.1 Tue Oct 14 15:39:45 2003 +++ pecl/lzf/lzf.h Fri Aug 13 18:45:21 2004 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002 Marc Alexander Lehmann <pcg@goof.com> + * Copyright (c) 2000-2003 Marc Alexander Lehmann <pcg@goof.com> * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -24,6 +24,16 @@ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. */ #ifndef LZF_H @@ -56,6 +66,9 @@ * * The buffers must not be overlapping. * + * If the option LZF_STATE_ARG is enabled, an extra argument must be + * supplied which is not reflected in this header file. Refer to lzf_c.c. + * */ unsigned int lzf_compress (const void *const in_data, unsigned int in_len, @@ -66,7 +79,7 @@ * function and stored at location in_data and length in_len. The result * will be stored at out_data up to a maximum of out_len characters. * - * If * the output buffer is not large enough to hold the decompressed + * If the output buffer is not large enough to hold the decompressed * data, a 0 is returned and errno is set to E2BIG. Otherwise the number * of decompressed bytes (i.e. the original length of the data) is * returned. http://cvs.php.net/diff.php/pecl/lzf/lzfP.h?r1=1.4&r2=1.5&ty=u Index: pecl/lzf/lzfP.h diff -u pecl/lzf/lzfP.h:1.4 pecl/lzf/lzfP.h:1.5 --- pecl/lzf/lzfP.h:1.4 Sun Oct 26 15:32:32 2003 +++ pecl/lzf/lzfP.h Fri Aug 13 18:45:21 2004 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002 Marc Alexander Lehmann <pcg@goof.com> + * Copyright (c) 2000-2003 Marc Alexander Lehmann <pcg@goof.com> * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -24,6 +24,16 @@ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. */ #ifndef LZFP_h @@ -89,11 +99,31 @@ # define INIT_HTAB 1 #endif +/* + * avoid assigning values to errno variable? for some embedding purposes + * (linux kernel for example), this is neccessary. NOTE: this breaks + * the documentation in lzf.h. + */ +#ifndef AVOID_ERRNO +# define AVOID_ERRNO 0 +#endif + +/* + * Wether to pass the LZF_STATE variable as argument, or allocate it + * on the stack. For small-stack environments, define this to 1. + * NOTE: this breaks the prototype in lzf.h. + */ +#ifndef LZF_STATE_ARG +# define LZF_STATE_ARG 0 +#endif + /*****************************************************************************/ /* nothing should be changed below */ typedef unsigned char u8; +typedef const u8 *LZF_STATE[1 << (HLOG)]; + #if !STRICT_ALIGN /* for unaligned accesses we need a 16 bit datatype. */ # include <limits.h> @@ -102,7 +132,6 @@ # elif UINT_MAX == 65535 typedef unsigned int u16; # else -# warn need 16 bit datatype when STRICT_ALIGN == 0, this is non-fatal # undef STRICT_ALIGN # define STRICT_ALIGN 1 # endif http://cvs.php.net/diff.php/pecl/lzf/lzf_c.c?r1=1.2&r2=1.3&ty=u Index: pecl/lzf/lzf_c.c diff -u pecl/lzf/lzf_c.c:1.2 pecl/lzf/lzf_c.c:1.3 --- pecl/lzf/lzf_c.c:1.2 Sun Oct 26 15:32:32 2003 +++ pecl/lzf/lzf_c.c Fri Aug 13 18:45:21 2004 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002 Marc Alexander Lehmann <pcg@goof.com> + * Copyright (c) 2000-2003 Marc Alexander Lehmann <pcg@goof.com> * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -24,6 +24,16 @@ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. */ #include "lzfP.h" @@ -68,12 +78,18 @@ unsigned int lzf_compress (const void *const in_data, unsigned int in_len, - void *out_data, unsigned int out_len) + void *out_data, unsigned int out_len +#if LZF_STATE_ARG + , LZF_STATE *htab +#endif + ) { - const u8 *htab[HSIZE]; +#if !LZF_STATE_ARG + LZF_STATE htab; +#endif const u8 **hslot; - const u8 *ip = in_data; - u8 *op = out_data; + const u8 *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; const u8 *in_end = ip + in_len; u8 *out_end = op + out_len; const u8 *ref; @@ -91,107 +107,111 @@ # endif #endif - do + for (;;) { - hval = NEXT (hval, ip); - hslot = htab + IDX (hval); - ref = *hslot; *hslot = ip; + if (ip < in_end - 2) + { + hval = NEXT (hval, ip); + hslot = htab + IDX (hval); + ref = *hslot; *hslot = ip; - if (1 + if (1 #if INIT_HTAB && !USE_MEMCPY - && ref < ip /* the next test will actually take care of this, but it is faster */ + && ref < ip /* the next test will actually take care of this, but this is faster */ #endif - && (off = ip - ref - 1) < MAX_OFF - && ip + 4 < in_end - && ref > (u8 *)in_data + && (off = ip - ref - 1) < MAX_OFF + && ip + 4 < in_end + && ref > (u8 *)in_data #if STRICT_ALIGN - && ref[0] == ip[0] - && ref[1] == ip[1] - && ref[2] == ip[2] + && ref[0] == ip[0] + && ref[1] == ip[1] + && ref[2] == ip[2] #else - && *(u16 *)ref == *(u16 *)ip - && ref[2] == ip[2] + && *(u16 *)ref == *(u16 *)ip + && ref[2] == ip[2] #endif - ) - { - /* match found at *ref++ */ - unsigned int len = 2; - unsigned int maxlen = in_end - ip - len; - maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; - - do - len++; - while (len < maxlen && ref[len] == ip[len]); - - if (op + lit + 1 + 3 >= out_end) - return 0; - - if (lit) - { - *op++ = lit - 1; - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); - } - - len -= 2; - ip++; - - if (len < 7) - { - *op++ = (off >> 8) + (len << 5); - } - else - { - *op++ = (off >> 8) + ( 7 << 5); - *op++ = len - 7; - } + ) + { + /* match found at *ref++ */ + unsigned int len = 2; + unsigned int maxlen = in_end - ip - len; + maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; + + do + len++; + while (len < maxlen && ref[len] == ip[len]); + + if (op + lit + 1 + 3 >= out_end) + return 0; + + if (lit) + { + *op++ = lit - 1; + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); + } + + len -= 2; + ip++; + + if (len < 7) + { + *op++ = (off >> 8) + (len << 5); + } + else + { + *op++ = (off >> 8) + ( 7 << 5); + *op++ = len - 7; + } - *op++ = off; + *op++ = off; #if PHP_LZF_ULTRA_FAST - ip += len; - hval = FRST (ip); - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; + + ip += len; + hval = FRST (ip); + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; #else - do - { - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; - } - while (len--); -#endif - } - else - { - /* one more literal byte we must copy */ - lit++; - ip++; - - if (lit == MAX_LIT) - { - if (op + 1 + MAX_LIT >= out_end) - return 0; + do + { + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; + } + while (len--); +#endif + continue; + } + } + else if (ip == in_end) + break; + + /* one more literal byte we must copy */ + lit++; + ip++; + + if (lit == MAX_LIT) + { + if (op + 1 + MAX_LIT >= out_end) + return 0; - *op++ = MAX_LIT - 1; + *op++ = MAX_LIT - 1; #if USE_MEMCPY - memcpy (op, ip - MAX_LIT, MAX_LIT); - op += MAX_LIT; - lit = 0; + memcpy (op, ip - MAX_LIT, MAX_LIT); + op += MAX_LIT; + lit = 0; #else - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); #endif - } - } + } } - while (ip < in_end); if (lit) { http://cvs.php.net/diff.php/pecl/lzf/lzf_d.c?r1=1.1&r2=1.2&ty=u Index: pecl/lzf/lzf_d.c diff -u pecl/lzf/lzf_d.c:1.1 pecl/lzf/lzf_d.c:1.2 --- pecl/lzf/lzf_d.c:1.1 Tue Oct 14 15:39:45 2003 +++ pecl/lzf/lzf_d.c Fri Aug 13 18:45:21 2004 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002 Marc Alexander Lehmann <pcg@goof.com> + * Copyright (c) 2000-2003 Marc Alexander Lehmann <pcg@goof.com> * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -24,18 +24,33 @@ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. */ -#include <errno.h> - #include "lzfP.h" +#if AVOID_ERRNO +# define SET_ERRNO(n) +#else +# include <errno.h> +# define SET_ERRNO(n) errno = (n) +#endif + unsigned int lzf_decompress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len) { - u8 const *ip = in_data; - u8 *op = out_data; + u8 const *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; u8 const *const in_end = ip + in_len; u8 *const out_end = op + out_len; @@ -49,7 +64,7 @@ if (op + ctrl > out_end) { - errno = E2BIG; + SET_ERRNO (E2BIG); return 0; } @@ -76,13 +91,13 @@ if (op + len + 2 > out_end) { - errno = E2BIG; + SET_ERRNO (E2BIG); return 0; } if (ref < (u8 *)out_data) { - errno = EINVAL; + SET_ERRNO (EINVAL); return 0; }
« previous php.pecl.cvs (#1654) next »