]> code.delx.au - refind/blob - filesystems/minilzo.c
Clarified description of "default_selection" in configfile.html.
[refind] / filesystems / minilzo.c
1 /*
2 * this file take from grub 2.0
3 * for btrfs UEFI driver
4 */
5
6 /* minilzo.c -- mini subset of the LZO real-time data compression library
7
8 This file is part of the LZO real-time data compression library.
9
10 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
21 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
22 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
23 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
24 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
25 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
26 All Rights Reserved.
27
28 The LZO library is free software; you can redistribute it and/or
29 modify it under the terms of the GNU General Public License as
30 published by the Free Software Foundation; either version 2 of
31 the License, or (at your option) any later version.
32
33 The LZO library is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 GNU General Public License for more details.
37
38 You should have received a copy of the GNU General Public License
39 along with the LZO library; see the file COPYING.
40 If not, write to the Free Software Foundation, Inc.,
41 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
42
43 Markus F.X.J. Oberhumer
44 <markus@oberhumer.com>
45 http://www.oberhumer.com/opensource/lzo/
46 */
47
48 /*
49 * NOTE:
50 * the full LZO package can be found at
51 * http://www.oberhumer.com/opensource/lzo/
52 */
53
54 #define __LZO_IN_MINILZO 1
55
56 #if defined(LZO_CFG_FREESTANDING)
57 # undef MINILZO_HAVE_CONFIG_H
58 # define LZO_LIBC_FREESTANDING 1
59 # define LZO_OS_FREESTANDING 1
60 #endif
61
62 #ifdef MINILZO_HAVE_CONFIG_H
63 # include <config.h>
64 #endif
65 #include <limits.h>
66 #include <stddef.h>
67 #if defined(MINILZO_CFG_USE_INTERNAL_LZODEFS)
68
69 #ifndef __LZODEFS_H_INCLUDED
70 #define __LZODEFS_H_INCLUDED 1
71
72 #if defined(__CYGWIN32__) && !defined(__CYGWIN__)
73 # define __CYGWIN__ __CYGWIN32__
74 #endif
75 #if defined(__IBMCPP__) && !defined(__IBMC__)
76 # define __IBMC__ __IBMCPP__
77 #endif
78 #if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER)
79 # define __INTEL_COMPILER __ICL
80 #endif
81 #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE)
82 # define _ALL_SOURCE 1
83 #endif
84 #if defined(__mips__) && defined(__R5900__)
85 # if !defined(__LONG_MAX__)
86 # define __LONG_MAX__ 9223372036854775807L
87 # endif
88 #endif
89 #if defined(__INTEL_COMPILER) && defined(__linux__)
90 # pragma warning(disable: 193)
91 #endif
92 #if defined(__KEIL__) && defined(__C166__)
93 # pragma warning disable = 322
94 #elif 0 && defined(__C251__)
95 # pragma warning disable = 322
96 #endif
97 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__)
98 # if (_MSC_VER >= 1300)
99 # pragma warning(disable: 4668)
100 # endif
101 #endif
102 #if 0 && defined(__WATCOMC__)
103 # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060)
104 # pragma warning 203 9
105 # endif
106 #endif
107 #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__)
108 # pragma option -h
109 #endif
110 #if 0
111 #define LZO_0xffffL 0xfffful
112 #define LZO_0xffffffffL 0xfffffffful
113 #else
114 #define LZO_0xffffL 65535ul
115 #define LZO_0xffffffffL 4294967295ul
116 #endif
117 #if (LZO_0xffffL == LZO_0xffffffffL)
118 # error "your preprocessor is broken 1"
119 #endif
120 #if (16ul * 16384ul != 262144ul)
121 # error "your preprocessor is broken 2"
122 #endif
123 #if 0
124 #if (32767 >= 4294967295ul)
125 # error "your preprocessor is broken 3"
126 #endif
127 #if (65535u >= 4294967295ul)
128 # error "your preprocessor is broken 4"
129 #endif
130 #endif
131 #if (UINT_MAX == LZO_0xffffL)
132 #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__)
133 # if !defined(MSDOS)
134 # define MSDOS 1
135 # endif
136 # if !defined(_MSDOS)
137 # define _MSDOS 1
138 # endif
139 #elif 0 && defined(__VERSION) && defined(MB_LEN_MAX)
140 # if (__VERSION == 520) && (MB_LEN_MAX == 1)
141 # if !defined(__AZTEC_C__)
142 # define __AZTEC_C__ __VERSION
143 # endif
144 # if !defined(__DOS__)
145 # define __DOS__ 1
146 # endif
147 # endif
148 #endif
149 #endif
150 #if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL)
151 # define ptrdiff_t long
152 # define _PTRDIFF_T_DEFINED 1
153 #endif
154 #if (UINT_MAX == LZO_0xffffL)
155 # undef __LZO_RENAME_A
156 # undef __LZO_RENAME_B
157 # if defined(__AZTEC_C__) && defined(__DOS__)
158 # define __LZO_RENAME_A 1
159 # elif defined(_MSC_VER) && defined(MSDOS)
160 # if (_MSC_VER < 600)
161 # define __LZO_RENAME_A 1
162 # elif (_MSC_VER < 700)
163 # define __LZO_RENAME_B 1
164 # endif
165 # elif defined(__TSC__) && defined(__OS2__)
166 # define __LZO_RENAME_A 1
167 # elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410)
168 # define __LZO_RENAME_A 1
169 # elif defined(__PACIFIC__) && defined(DOS)
170 # if !defined(__far)
171 # define __far far
172 # endif
173 # if !defined(__near)
174 # define __near near
175 # endif
176 # endif
177 # if defined(__LZO_RENAME_A)
178 # if !defined(__cdecl)
179 # define __cdecl cdecl
180 # endif
181 # if !defined(__far)
182 # define __far far
183 # endif
184 # if !defined(__huge)
185 # define __huge huge
186 # endif
187 # if !defined(__near)
188 # define __near near
189 # endif
190 # if !defined(__pascal)
191 # define __pascal pascal
192 # endif
193 # if !defined(__huge)
194 # define __huge huge
195 # endif
196 # elif defined(__LZO_RENAME_B)
197 # if !defined(__cdecl)
198 # define __cdecl _cdecl
199 # endif
200 # if !defined(__far)
201 # define __far _far
202 # endif
203 # if !defined(__huge)
204 # define __huge _huge
205 # endif
206 # if !defined(__near)
207 # define __near _near
208 # endif
209 # if !defined(__pascal)
210 # define __pascal _pascal
211 # endif
212 # elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
213 # if !defined(__cdecl)
214 # define __cdecl cdecl
215 # endif
216 # if !defined(__pascal)
217 # define __pascal pascal
218 # endif
219 # endif
220 # undef __LZO_RENAME_A
221 # undef __LZO_RENAME_B
222 #endif
223 #if (UINT_MAX == LZO_0xffffL)
224 #if defined(__AZTEC_C__) && defined(__DOS__)
225 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
226 #elif defined(_MSC_VER) && defined(MSDOS)
227 # if (_MSC_VER < 600)
228 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
229 # endif
230 # if (_MSC_VER < 700)
231 # define LZO_BROKEN_INTEGRAL_PROMOTION 1
232 # define LZO_BROKEN_SIZEOF 1
233 # endif
234 #elif defined(__PACIFIC__) && defined(DOS)
235 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
236 #elif defined(__TURBOC__) && defined(__MSDOS__)
237 # if (__TURBOC__ < 0x0150)
238 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
239 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
240 # define LZO_BROKEN_INTEGRAL_PROMOTION 1
241 # endif
242 # if (__TURBOC__ < 0x0200)
243 # define LZO_BROKEN_SIZEOF 1
244 # endif
245 # if (__TURBOC__ < 0x0400) && defined(__cplusplus)
246 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
247 # endif
248 #elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
249 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
250 # define LZO_BROKEN_SIZEOF 1
251 #endif
252 #endif
253 #if defined(__WATCOMC__) && (__WATCOMC__ < 900)
254 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
255 #endif
256 #if defined(_CRAY) && defined(_CRAY1)
257 # define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1
258 #endif
259 #define LZO_PP_STRINGIZE(x) #x
260 #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x)
261 #define LZO_PP_CONCAT2(a,b) a ## b
262 #define LZO_PP_CONCAT3(a,b,c) a ## b ## c
263 #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d
264 #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
265 #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b)
266 #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c)
267 #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d)
268 #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e)
269 #if 1
270 #define LZO_CPP_STRINGIZE(x) #x
271 #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x)
272 #define LZO_CPP_CONCAT2(a,b) a ## b
273 #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c
274 #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d
275 #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
276 #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b)
277 #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c)
278 #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d)
279 #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e)
280 #endif
281 #define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o))
282 #if 1 && defined(__cplusplus)
283 # if !defined(__STDC_CONSTANT_MACROS)
284 # define __STDC_CONSTANT_MACROS 1
285 # endif
286 # if !defined(__STDC_LIMIT_MACROS)
287 # define __STDC_LIMIT_MACROS 1
288 # endif
289 #endif
290 #if defined(__cplusplus)
291 # define LZO_EXTERN_C extern "C"
292 #else
293 # define LZO_EXTERN_C extern
294 #endif
295 #if !defined(__LZO_OS_OVERRIDE)
296 #if (LZO_OS_FREESTANDING)
297 # define LZO_INFO_OS "freestanding"
298 #elif (LZO_OS_EMBEDDED)
299 # define LZO_INFO_OS "embedded"
300 #elif 1 && defined(__IAR_SYSTEMS_ICC__)
301 # define LZO_OS_EMBEDDED 1
302 # define LZO_INFO_OS "embedded"
303 #elif defined(__CYGWIN__) && defined(__GNUC__)
304 # define LZO_OS_CYGWIN 1
305 # define LZO_INFO_OS "cygwin"
306 #elif defined(__EMX__) && defined(__GNUC__)
307 # define LZO_OS_EMX 1
308 # define LZO_INFO_OS "emx"
309 #elif defined(__BEOS__)
310 # define LZO_OS_BEOS 1
311 # define LZO_INFO_OS "beos"
312 #elif defined(__Lynx__)
313 # define LZO_OS_LYNXOS 1
314 # define LZO_INFO_OS "lynxos"
315 #elif defined(__OS400__)
316 # define LZO_OS_OS400 1
317 # define LZO_INFO_OS "os400"
318 #elif defined(__QNX__)
319 # define LZO_OS_QNX 1
320 # define LZO_INFO_OS "qnx"
321 #elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460)
322 # define LZO_OS_DOS32 1
323 # define LZO_INFO_OS "dos32"
324 #elif defined(__BORLANDC__) && defined(__DPMI16__)
325 # define LZO_OS_DOS16 1
326 # define LZO_INFO_OS "dos16"
327 #elif defined(__ZTC__) && defined(DOS386)
328 # define LZO_OS_DOS32 1
329 # define LZO_INFO_OS "dos32"
330 #elif defined(__OS2__) || defined(__OS2V2__)
331 # if (UINT_MAX == LZO_0xffffL)
332 # define LZO_OS_OS216 1
333 # define LZO_INFO_OS "os216"
334 # elif (UINT_MAX == LZO_0xffffffffL)
335 # define LZO_OS_OS2 1
336 # define LZO_INFO_OS "os2"
337 # else
338 # error "check your limits.h header"
339 # endif
340 #elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64)
341 # define LZO_OS_WIN64 1
342 # define LZO_INFO_OS "win64"
343 #elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__)
344 # define LZO_OS_WIN32 1
345 # define LZO_INFO_OS "win32"
346 #elif defined(__MWERKS__) && defined(__INTEL__)
347 # define LZO_OS_WIN32 1
348 # define LZO_INFO_OS "win32"
349 #elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
350 # if (UINT_MAX == LZO_0xffffL)
351 # define LZO_OS_WIN16 1
352 # define LZO_INFO_OS "win16"
353 # elif (UINT_MAX == LZO_0xffffffffL)
354 # define LZO_OS_WIN32 1
355 # define LZO_INFO_OS "win32"
356 # else
357 # error "check your limits.h header"
358 # endif
359 #elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS))
360 # if (UINT_MAX == LZO_0xffffL)
361 # define LZO_OS_DOS16 1
362 # define LZO_INFO_OS "dos16"
363 # elif (UINT_MAX == LZO_0xffffffffL)
364 # define LZO_OS_DOS32 1
365 # define LZO_INFO_OS "dos32"
366 # else
367 # error "check your limits.h header"
368 # endif
369 #elif defined(__WATCOMC__)
370 # if defined(__NT__) && (UINT_MAX == LZO_0xffffL)
371 # define LZO_OS_DOS16 1
372 # define LZO_INFO_OS "dos16"
373 # elif defined(__NT__) && (__WATCOMC__ < 1100)
374 # define LZO_OS_WIN32 1
375 # define LZO_INFO_OS "win32"
376 # elif defined(__linux__) || defined(__LINUX__)
377 # define LZO_OS_POSIX 1
378 # define LZO_INFO_OS "posix"
379 # else
380 # error "please specify a target using the -bt compiler option"
381 # endif
382 #elif defined(__palmos__)
383 # define LZO_OS_PALMOS 1
384 # define LZO_INFO_OS "palmos"
385 #elif defined(__TOS__) || defined(__atarist__)
386 # define LZO_OS_TOS 1
387 # define LZO_INFO_OS "tos"
388 #elif defined(macintosh) && !defined(__ppc__)
389 # define LZO_OS_MACCLASSIC 1
390 # define LZO_INFO_OS "macclassic"
391 #elif defined(__VMS)
392 # define LZO_OS_VMS 1
393 # define LZO_INFO_OS "vms"
394 #elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__))
395 # define LZO_OS_CONSOLE 1
396 # define LZO_OS_CONSOLE_PS2 1
397 # define LZO_INFO_OS "console"
398 # define LZO_INFO_OS_CONSOLE "ps2"
399 #elif (defined(__mips__) && defined(__psp__))
400 # define LZO_OS_CONSOLE 1
401 # define LZO_OS_CONSOLE_PSP 1
402 # define LZO_INFO_OS "console"
403 # define LZO_INFO_OS_CONSOLE "psp"
404 #else
405 # define LZO_OS_POSIX 1
406 # define LZO_INFO_OS "posix"
407 #endif
408 #if (LZO_OS_POSIX)
409 # if defined(_AIX) || defined(__AIX__) || defined(__aix__)
410 # define LZO_OS_POSIX_AIX 1
411 # define LZO_INFO_OS_POSIX "aix"
412 # elif defined(__FreeBSD__)
413 # define LZO_OS_POSIX_FREEBSD 1
414 # define LZO_INFO_OS_POSIX "freebsd"
415 # elif defined(__hpux__) || defined(__hpux)
416 # define LZO_OS_POSIX_HPUX 1
417 # define LZO_INFO_OS_POSIX "hpux"
418 # elif defined(__INTERIX)
419 # define LZO_OS_POSIX_INTERIX 1
420 # define LZO_INFO_OS_POSIX "interix"
421 # elif defined(__IRIX__) || defined(__irix__)
422 # define LZO_OS_POSIX_IRIX 1
423 # define LZO_INFO_OS_POSIX "irix"
424 # elif defined(__linux__) || defined(__linux) || defined(__LINUX__)
425 # define LZO_OS_POSIX_LINUX 1
426 # define LZO_INFO_OS_POSIX "linux"
427 # elif defined(__APPLE__) || defined(__MACOS__)
428 # define LZO_OS_POSIX_MACOSX 1
429 # define LZO_INFO_OS_POSIX "macosx"
430 # elif defined(__minix__) || defined(__minix)
431 # define LZO_OS_POSIX_MINIX 1
432 # define LZO_INFO_OS_POSIX "minix"
433 # elif defined(__NetBSD__)
434 # define LZO_OS_POSIX_NETBSD 1
435 # define LZO_INFO_OS_POSIX "netbsd"
436 # elif defined(__OpenBSD__)
437 # define LZO_OS_POSIX_OPENBSD 1
438 # define LZO_INFO_OS_POSIX "openbsd"
439 # elif defined(__osf__)
440 # define LZO_OS_POSIX_OSF 1
441 # define LZO_INFO_OS_POSIX "osf"
442 # elif defined(__solaris__) || defined(__sun)
443 # if defined(__SVR4) || defined(__svr4__)
444 # define LZO_OS_POSIX_SOLARIS 1
445 # define LZO_INFO_OS_POSIX "solaris"
446 # else
447 # define LZO_OS_POSIX_SUNOS 1
448 # define LZO_INFO_OS_POSIX "sunos"
449 # endif
450 # elif defined(__ultrix__) || defined(__ultrix)
451 # define LZO_OS_POSIX_ULTRIX 1
452 # define LZO_INFO_OS_POSIX "ultrix"
453 # elif defined(_UNICOS)
454 # define LZO_OS_POSIX_UNICOS 1
455 # define LZO_INFO_OS_POSIX "unicos"
456 # else
457 # define LZO_OS_POSIX_UNKNOWN 1
458 # define LZO_INFO_OS_POSIX "unknown"
459 # endif
460 #endif
461 #endif
462 #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
463 # if (UINT_MAX != LZO_0xffffL)
464 # error "this should not happen"
465 # endif
466 # if (ULONG_MAX != LZO_0xffffffffL)
467 # error "this should not happen"
468 # endif
469 #endif
470 #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64)
471 # if (UINT_MAX != LZO_0xffffffffL)
472 # error "this should not happen"
473 # endif
474 # if (ULONG_MAX != LZO_0xffffffffL)
475 # error "this should not happen"
476 # endif
477 #endif
478 #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__)
479 # define LZO_CC_CILLY 1
480 # define LZO_INFO_CC "Cilly"
481 # if defined(__CILLY__)
482 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__)
483 # else
484 # define LZO_INFO_CCVER "unknown"
485 # endif
486 #elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__)
487 # define LZO_CC_SDCC 1
488 # define LZO_INFO_CC "sdcc"
489 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC)
490 #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__)
491 # define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__)
492 # define LZO_INFO_CC "Pathscale C"
493 # define LZO_INFO_CCVER __PATHSCALE__
494 #elif defined(__INTEL_COMPILER)
495 # define LZO_CC_INTELC 1
496 # define LZO_INFO_CC "Intel C"
497 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER)
498 # if defined(_WIN32) || defined(_WIN64)
499 # define LZO_CC_SYNTAX_MSC 1
500 # else
501 # define LZO_CC_SYNTAX_GNUC 1
502 # endif
503 #elif defined(__POCC__) && defined(_WIN32)
504 # define LZO_CC_PELLESC 1
505 # define LZO_INFO_CC "Pelles C"
506 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__)
507 #elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__)
508 # if defined(__GNUC_PATCHLEVEL__)
509 # define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
510 # else
511 # define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
512 # endif
513 # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__)
514 # define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__)
515 # else
516 # define LZO_CC_CLANG_CLANG 0x010000L
517 # endif
518 # define LZO_CC_CLANG LZO_CC_CLANG_GNUC
519 # define LZO_INFO_CC "clang"
520 # define LZO_INFO_CCVER __VERSION__
521 #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__)
522 # if defined(__GNUC_PATCHLEVEL__)
523 # define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
524 # else
525 # define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
526 # endif
527 # define LZO_CC_LLVM LZO_CC_LLVM_GNUC
528 # define LZO_INFO_CC "llvm-gcc"
529 # define LZO_INFO_CCVER __VERSION__
530 #elif defined(__GNUC__) && defined(__VERSION__)
531 # if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
532 # define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
533 # elif defined(__GNUC_MINOR__)
534 # define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
535 # else
536 # define LZO_CC_GNUC (__GNUC__ * 0x10000L)
537 # endif
538 # define LZO_INFO_CC "gcc"
539 # define LZO_INFO_CCVER __VERSION__
540 #elif defined(__ACK__) && defined(_ACK)
541 # define LZO_CC_ACK 1
542 # define LZO_INFO_CC "Amsterdam Compiler Kit C"
543 # define LZO_INFO_CCVER "unknown"
544 #elif defined(__AZTEC_C__)
545 # define LZO_CC_AZTECC 1
546 # define LZO_INFO_CC "Aztec C"
547 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__)
548 #elif defined(__CODEGEARC__)
549 # define LZO_CC_CODEGEARC 1
550 # define LZO_INFO_CC "CodeGear C"
551 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CODEGEARC__)
552 #elif defined(__BORLANDC__)
553 # define LZO_CC_BORLANDC 1
554 # define LZO_INFO_CC "Borland C"
555 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__)
556 #elif defined(_CRAYC) && defined(_RELEASE)
557 # define LZO_CC_CRAYC 1
558 # define LZO_INFO_CC "Cray C"
559 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE)
560 #elif defined(__DMC__) && defined(__SC__)
561 # define LZO_CC_DMC 1
562 # define LZO_INFO_CC "Digital Mars C"
563 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__)
564 #elif defined(__DECC)
565 # define LZO_CC_DECC 1
566 # define LZO_INFO_CC "DEC C"
567 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC)
568 #elif defined(__HIGHC__)
569 # define LZO_CC_HIGHC 1
570 # define LZO_INFO_CC "MetaWare High C"
571 # define LZO_INFO_CCVER "unknown"
572 #elif defined(__IAR_SYSTEMS_ICC__)
573 # define LZO_CC_IARC 1
574 # define LZO_INFO_CC "IAR C"
575 # if defined(__VER__)
576 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__)
577 # else
578 # define LZO_INFO_CCVER "unknown"
579 # endif
580 #elif defined(__IBMC__)
581 # define LZO_CC_IBMC 1
582 # define LZO_INFO_CC "IBM C"
583 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__)
584 #elif defined(__KEIL__) && defined(__C166__)
585 # define LZO_CC_KEILC 1
586 # define LZO_INFO_CC "Keil C"
587 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__)
588 #elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL)
589 # define LZO_CC_LCCWIN32 1
590 # define LZO_INFO_CC "lcc-win32"
591 # define LZO_INFO_CCVER "unknown"
592 #elif defined(__LCC__)
593 # define LZO_CC_LCC 1
594 # define LZO_INFO_CC "lcc"
595 # if defined(__LCC_VERSION__)
596 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__)
597 # else
598 # define LZO_INFO_CCVER "unknown"
599 # endif
600 #elif defined(_MSC_VER)
601 # define LZO_CC_MSC 1
602 # define LZO_INFO_CC "Microsoft C"
603 # if defined(_MSC_FULL_VER)
604 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER)
605 # else
606 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER)
607 # endif
608 #elif defined(__MWERKS__)
609 # define LZO_CC_MWERKS 1
610 # define LZO_INFO_CC "Metrowerks C"
611 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__)
612 #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386)
613 # define LZO_CC_NDPC 1
614 # define LZO_INFO_CC "Microway NDP C"
615 # define LZO_INFO_CCVER "unknown"
616 #elif defined(__PACIFIC__)
617 # define LZO_CC_PACIFICC 1
618 # define LZO_INFO_CC "Pacific C"
619 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__)
620 #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__))
621 # define LZO_CC_PGI 1
622 # define LZO_INFO_CC "Portland Group PGI C"
623 # define LZO_INFO_CCVER "unknown"
624 #elif defined(__PUREC__) && defined(__TOS__)
625 # define LZO_CC_PUREC 1
626 # define LZO_INFO_CC "Pure C"
627 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__)
628 #elif defined(__SC__) && defined(__ZTC__)
629 # define LZO_CC_SYMANTECC 1
630 # define LZO_INFO_CC "Symantec C"
631 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__)
632 #elif defined(__SUNPRO_C)
633 # define LZO_INFO_CC "SunPro C"
634 # if ((__SUNPRO_C)+0 > 0)
635 # define LZO_CC_SUNPROC __SUNPRO_C
636 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C)
637 # else
638 # define LZO_CC_SUNPROC 1
639 # define LZO_INFO_CCVER "unknown"
640 # endif
641 #elif defined(__SUNPRO_CC)
642 # define LZO_INFO_CC "SunPro C"
643 # if ((__SUNPRO_CC)+0 > 0)
644 # define LZO_CC_SUNPROC __SUNPRO_CC
645 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC)
646 # else
647 # define LZO_CC_SUNPROC 1
648 # define LZO_INFO_CCVER "unknown"
649 # endif
650 #elif defined(__TINYC__)
651 # define LZO_CC_TINYC 1
652 # define LZO_INFO_CC "Tiny C"
653 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__)
654 #elif defined(__TSC__)
655 # define LZO_CC_TOPSPEEDC 1
656 # define LZO_INFO_CC "TopSpeed C"
657 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__)
658 #elif defined(__WATCOMC__)
659 # define LZO_CC_WATCOMC 1
660 # define LZO_INFO_CC "Watcom C"
661 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__)
662 #elif defined(__TURBOC__)
663 # define LZO_CC_TURBOC 1
664 # define LZO_INFO_CC "Turbo C"
665 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__)
666 #elif defined(__ZTC__)
667 # define LZO_CC_ZORTECHC 1
668 # define LZO_INFO_CC "Zortech C"
669 # if (__ZTC__ == 0x310)
670 # define LZO_INFO_CCVER "0x310"
671 # else
672 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__)
673 # endif
674 #else
675 # define LZO_CC_UNKNOWN 1
676 # define LZO_INFO_CC "unknown"
677 # define LZO_INFO_CCVER "unknown"
678 #endif
679 #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER)
680 # error "LZO_CC_MSC: _MSC_FULL_VER is not defined"
681 #endif
682 #if !defined(__LZO_ARCH_OVERRIDE) && !(LZO_ARCH_GENERIC) && defined(_CRAY)
683 # if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY)
684 # if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E)
685 # define LZO_ARCH_CRAY_MPP 1
686 # elif defined(_CRAY1)
687 # define LZO_ARCH_CRAY_PVP 1
688 # endif
689 # endif
690 #endif
691 #if !defined(__LZO_ARCH_OVERRIDE)
692 #if (LZO_ARCH_GENERIC)
693 # define LZO_INFO_ARCH "generic"
694 #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
695 # define LZO_ARCH_I086 1
696 # define LZO_ARCH_IA16 1
697 # define LZO_INFO_ARCH "i086"
698 #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA)
699 # define LZO_ARCH_ALPHA 1
700 # define LZO_INFO_ARCH "alpha"
701 #elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E))
702 # define LZO_ARCH_ALPHA 1
703 # define LZO_INFO_ARCH "alpha"
704 #elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)
705 # define LZO_ARCH_AMD64 1
706 # define LZO_INFO_ARCH "amd64"
707 #elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB))
708 # define LZO_ARCH_ARM 1
709 # define LZO_ARCH_ARM_THUMB 1
710 # define LZO_INFO_ARCH "arm_thumb"
711 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__)
712 # define LZO_ARCH_ARM 1
713 # if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1)
714 # define LZO_ARCH_ARM_THUMB 1
715 # define LZO_INFO_ARCH "arm_thumb"
716 # elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2)
717 # define LZO_INFO_ARCH "arm"
718 # else
719 # define LZO_INFO_ARCH "arm"
720 # endif
721 #elif defined(__arm__) || defined(_M_ARM)
722 # define LZO_ARCH_ARM 1
723 # define LZO_INFO_ARCH "arm"
724 #elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__)
725 # define LZO_ARCH_AVR 1
726 # define LZO_INFO_ARCH "avr"
727 #elif defined(__avr32__) || defined(__AVR32__)
728 # define LZO_ARCH_AVR32 1
729 # define LZO_INFO_ARCH "avr32"
730 #elif defined(__bfin__)
731 # define LZO_ARCH_BLACKFIN 1
732 # define LZO_INFO_ARCH "blackfin"
733 #elif (UINT_MAX == LZO_0xffffL) && defined(__C166__)
734 # define LZO_ARCH_C166 1
735 # define LZO_INFO_ARCH "c166"
736 #elif defined(__cris__)
737 # define LZO_ARCH_CRIS 1
738 # define LZO_INFO_ARCH "cris"
739 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__)
740 # define LZO_ARCH_EZ80 1
741 # define LZO_INFO_ARCH "ez80"
742 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
743 # define LZO_ARCH_H8300 1
744 # define LZO_INFO_ARCH "h8300"
745 #elif defined(__hppa__) || defined(__hppa)
746 # define LZO_ARCH_HPPA 1
747 # define LZO_INFO_ARCH "hppa"
748 #elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
749 # define LZO_ARCH_I386 1
750 # define LZO_ARCH_IA32 1
751 # define LZO_INFO_ARCH "i386"
752 #elif (LZO_CC_ZORTECHC && defined(__I86__))
753 # define LZO_ARCH_I386 1
754 # define LZO_ARCH_IA32 1
755 # define LZO_INFO_ARCH "i386"
756 #elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386)
757 # define LZO_ARCH_I386 1
758 # define LZO_ARCH_IA32 1
759 # define LZO_INFO_ARCH "i386"
760 #elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
761 # define LZO_ARCH_IA64 1
762 # define LZO_INFO_ARCH "ia64"
763 #elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__)
764 # define LZO_ARCH_M16C 1
765 # define LZO_INFO_ARCH "m16c"
766 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__)
767 # define LZO_ARCH_M16C 1
768 # define LZO_INFO_ARCH "m16c"
769 #elif defined(__m32r__)
770 # define LZO_ARCH_M32R 1
771 # define LZO_INFO_ARCH "m32r"
772 #elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K)
773 # define LZO_ARCH_M68K 1
774 # define LZO_INFO_ARCH "m68k"
775 #elif (UINT_MAX == LZO_0xffffL) && defined(__C251__)
776 # define LZO_ARCH_MCS251 1
777 # define LZO_INFO_ARCH "mcs251"
778 #elif (UINT_MAX == LZO_0xffffL) && defined(__C51__)
779 # define LZO_ARCH_MCS51 1
780 # define LZO_INFO_ARCH "mcs51"
781 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__)
782 # define LZO_ARCH_MCS51 1
783 # define LZO_INFO_ARCH "mcs51"
784 #elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000)
785 # define LZO_ARCH_MIPS 1
786 # define LZO_INFO_ARCH "mips"
787 #elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__)
788 # define LZO_ARCH_MSP430 1
789 # define LZO_INFO_ARCH "msp430"
790 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__)
791 # define LZO_ARCH_MSP430 1
792 # define LZO_INFO_ARCH "msp430"
793 #elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR)
794 # define LZO_ARCH_POWERPC 1
795 # define LZO_INFO_ARCH "powerpc"
796 #elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x)
797 # define LZO_ARCH_S390 1
798 # define LZO_INFO_ARCH "s390"
799 #elif defined(__sh__) || defined(_M_SH)
800 # define LZO_ARCH_SH 1
801 # define LZO_INFO_ARCH "sh"
802 #elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8)
803 # define LZO_ARCH_SPARC 1
804 # define LZO_INFO_ARCH "sparc"
805 #elif defined(__SPU__)
806 # define LZO_ARCH_SPU 1
807 # define LZO_INFO_ARCH "spu"
808 #elif (UINT_MAX == LZO_0xffffL) && defined(__z80)
809 # define LZO_ARCH_Z80 1
810 # define LZO_INFO_ARCH "z80"
811 #elif (LZO_ARCH_CRAY_PVP)
812 # if defined(_CRAYSV1)
813 # define LZO_ARCH_CRAY_SV1 1
814 # define LZO_INFO_ARCH "cray_sv1"
815 # elif (_ADDR64)
816 # define LZO_ARCH_CRAY_T90 1
817 # define LZO_INFO_ARCH "cray_t90"
818 # elif (_ADDR32)
819 # define LZO_ARCH_CRAY_YMP 1
820 # define LZO_INFO_ARCH "cray_ymp"
821 # else
822 # define LZO_ARCH_CRAY_XMP 1
823 # define LZO_INFO_ARCH "cray_xmp"
824 # endif
825 #else
826 # define LZO_ARCH_UNKNOWN 1
827 # define LZO_INFO_ARCH "unknown"
828 #endif
829 #endif
830 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2)
831 # error "FIXME - missing define for CPU architecture"
832 #endif
833 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32)
834 # error "FIXME - missing WIN32 define for CPU architecture"
835 #endif
836 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64)
837 # error "FIXME - missing WIN64 define for CPU architecture"
838 #endif
839 #if (LZO_OS_OS216 || LZO_OS_WIN16)
840 # define LZO_ARCH_I086PM 1
841 # define LZO_ARCH_IA16PM 1
842 #elif 1 && (LZO_OS_DOS16 && defined(BLX286))
843 # define LZO_ARCH_I086PM 1
844 # define LZO_ARCH_IA16PM 1
845 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286))
846 # define LZO_ARCH_I086PM 1
847 # define LZO_ARCH_IA16PM 1
848 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__))
849 # define LZO_ARCH_I086PM 1
850 # define LZO_ARCH_IA16PM 1
851 #endif
852 #if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM)
853 # error "this should not happen"
854 #endif
855 #if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086)
856 # error "this should not happen"
857 #endif
858 #if (LZO_ARCH_I086)
859 # if (UINT_MAX != LZO_0xffffL)
860 # error "this should not happen"
861 # endif
862 # if (ULONG_MAX != LZO_0xffffffffL)
863 # error "this should not happen"
864 # endif
865 #endif
866 #if (LZO_ARCH_I386)
867 # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__)
868 # error "this should not happen"
869 # endif
870 # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__)
871 # error "this should not happen"
872 # endif
873 # if (ULONG_MAX != LZO_0xffffffffL)
874 # error "this should not happen"
875 # endif
876 #endif
877 #if !defined(__LZO_MM_OVERRIDE)
878 #if (LZO_ARCH_I086)
879 #if (UINT_MAX != LZO_0xffffL)
880 # error "this should not happen"
881 #endif
882 #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM)
883 # define LZO_MM_TINY 1
884 #elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM)
885 # define LZO_MM_HUGE 1
886 #elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL)
887 # define LZO_MM_SMALL 1
888 #elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM)
889 # define LZO_MM_MEDIUM 1
890 #elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM)
891 # define LZO_MM_COMPACT 1
892 #elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL)
893 # define LZO_MM_LARGE 1
894 #elif (LZO_CC_AZTECC)
895 # if defined(_LARGE_CODE) && defined(_LARGE_DATA)
896 # define LZO_MM_LARGE 1
897 # elif defined(_LARGE_CODE)
898 # define LZO_MM_MEDIUM 1
899 # elif defined(_LARGE_DATA)
900 # define LZO_MM_COMPACT 1
901 # else
902 # define LZO_MM_SMALL 1
903 # endif
904 #elif (LZO_CC_ZORTECHC && defined(__VCM__))
905 # define LZO_MM_LARGE 1
906 #else
907 # error "unknown memory model"
908 #endif
909 #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
910 #define LZO_HAVE_MM_HUGE_PTR 1
911 #define LZO_HAVE_MM_HUGE_ARRAY 1
912 #if (LZO_MM_TINY)
913 # undef LZO_HAVE_MM_HUGE_ARRAY
914 #endif
915 #if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC)
916 # undef LZO_HAVE_MM_HUGE_PTR
917 # undef LZO_HAVE_MM_HUGE_ARRAY
918 #elif (LZO_CC_DMC || LZO_CC_SYMANTECC)
919 # undef LZO_HAVE_MM_HUGE_ARRAY
920 #elif (LZO_CC_MSC && defined(_QC))
921 # undef LZO_HAVE_MM_HUGE_ARRAY
922 # if (_MSC_VER < 600)
923 # undef LZO_HAVE_MM_HUGE_PTR
924 # endif
925 #elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295))
926 # undef LZO_HAVE_MM_HUGE_ARRAY
927 #endif
928 #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR)
929 # if (LZO_OS_DOS16)
930 # error "this should not happen"
931 # elif (LZO_CC_ZORTECHC)
932 # else
933 # error "this should not happen"
934 # endif
935 #endif
936 #ifdef __cplusplus
937 extern "C" {
938 #endif
939 #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200))
940 extern void __near __cdecl _AHSHIFT(void);
941 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
942 #elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
943 extern void __near __cdecl _AHSHIFT(void);
944 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
945 #elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC)
946 extern void __near __cdecl _AHSHIFT(void);
947 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
948 #elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295))
949 extern void __near __cdecl _AHSHIFT(void);
950 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
951 #elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16)
952 # define LZO_MM_AHSHIFT 12
953 #elif (LZO_CC_WATCOMC)
954 extern unsigned char _HShift;
955 # define LZO_MM_AHSHIFT ((unsigned) _HShift)
956 #else
957 # error "FIXME - implement LZO_MM_AHSHIFT"
958 #endif
959 #ifdef __cplusplus
960 }
961 #endif
962 #endif
963 #elif (LZO_ARCH_C166)
964 #if !defined(__MODEL__)
965 # error "FIXME - C166 __MODEL__"
966 #elif ((__MODEL__) == 0)
967 # define LZO_MM_SMALL 1
968 #elif ((__MODEL__) == 1)
969 # define LZO_MM_SMALL 1
970 #elif ((__MODEL__) == 2)
971 # define LZO_MM_LARGE 1
972 #elif ((__MODEL__) == 3)
973 # define LZO_MM_TINY 1
974 #elif ((__MODEL__) == 4)
975 # define LZO_MM_XTINY 1
976 #elif ((__MODEL__) == 5)
977 # define LZO_MM_XSMALL 1
978 #else
979 # error "FIXME - C166 __MODEL__"
980 #endif
981 #elif (LZO_ARCH_MCS251)
982 #if !defined(__MODEL__)
983 # error "FIXME - MCS251 __MODEL__"
984 #elif ((__MODEL__) == 0)
985 # define LZO_MM_SMALL 1
986 #elif ((__MODEL__) == 2)
987 # define LZO_MM_LARGE 1
988 #elif ((__MODEL__) == 3)
989 # define LZO_MM_TINY 1
990 #elif ((__MODEL__) == 4)
991 # define LZO_MM_XTINY 1
992 #elif ((__MODEL__) == 5)
993 # define LZO_MM_XSMALL 1
994 #else
995 # error "FIXME - MCS251 __MODEL__"
996 #endif
997 #elif (LZO_ARCH_MCS51)
998 #if !defined(__MODEL__)
999 # error "FIXME - MCS51 __MODEL__"
1000 #elif ((__MODEL__) == 1)
1001 # define LZO_MM_SMALL 1
1002 #elif ((__MODEL__) == 2)
1003 # define LZO_MM_LARGE 1
1004 #elif ((__MODEL__) == 3)
1005 # define LZO_MM_TINY 1
1006 #elif ((__MODEL__) == 4)
1007 # define LZO_MM_XTINY 1
1008 #elif ((__MODEL__) == 5)
1009 # define LZO_MM_XSMALL 1
1010 #else
1011 # error "FIXME - MCS51 __MODEL__"
1012 #endif
1013 #elif (LZO_ARCH_CRAY_PVP)
1014 # define LZO_MM_PVP 1
1015 #else
1016 # define LZO_MM_FLAT 1
1017 #endif
1018 #if (LZO_MM_COMPACT)
1019 # define LZO_INFO_MM "compact"
1020 #elif (LZO_MM_FLAT)
1021 # define LZO_INFO_MM "flat"
1022 #elif (LZO_MM_HUGE)
1023 # define LZO_INFO_MM "huge"
1024 #elif (LZO_MM_LARGE)
1025 # define LZO_INFO_MM "large"
1026 #elif (LZO_MM_MEDIUM)
1027 # define LZO_INFO_MM "medium"
1028 #elif (LZO_MM_PVP)
1029 # define LZO_INFO_MM "pvp"
1030 #elif (LZO_MM_SMALL)
1031 # define LZO_INFO_MM "small"
1032 #elif (LZO_MM_TINY)
1033 # define LZO_INFO_MM "tiny"
1034 #else
1035 # error "unknown memory model"
1036 #endif
1037 #endif
1038 #if defined(SIZEOF_SHORT)
1039 # define LZO_SIZEOF_SHORT (SIZEOF_SHORT)
1040 #endif
1041 #if defined(SIZEOF_INT)
1042 # define LZO_SIZEOF_INT (SIZEOF_INT)
1043 #endif
1044 #if defined(SIZEOF_LONG)
1045 # define LZO_SIZEOF_LONG (SIZEOF_LONG)
1046 #endif
1047 #if defined(SIZEOF_LONG_LONG)
1048 # define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG)
1049 #endif
1050 #if defined(SIZEOF___INT16)
1051 # define LZO_SIZEOF___INT16 (SIZEOF___INT16)
1052 #endif
1053 #if defined(SIZEOF___INT32)
1054 # define LZO_SIZEOF___INT32 (SIZEOF___INT32)
1055 #endif
1056 #if defined(SIZEOF___INT64)
1057 # define LZO_SIZEOF___INT64 (SIZEOF___INT64)
1058 #endif
1059 #if defined(SIZEOF_VOID_P)
1060 # define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P)
1061 #endif
1062 #if defined(SIZEOF_SIZE_T)
1063 # define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T)
1064 #endif
1065 #if defined(SIZEOF_PTRDIFF_T)
1066 # define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T)
1067 #endif
1068 #define __LZO_LSR(x,b) (((x)+0ul) >> (b))
1069 #if !defined(LZO_SIZEOF_SHORT)
1070 # if (LZO_ARCH_CRAY_PVP)
1071 # define LZO_SIZEOF_SHORT 8
1072 # elif (USHRT_MAX == LZO_0xffffL)
1073 # define LZO_SIZEOF_SHORT 2
1074 # elif (__LZO_LSR(USHRT_MAX,7) == 1)
1075 # define LZO_SIZEOF_SHORT 1
1076 # elif (__LZO_LSR(USHRT_MAX,15) == 1)
1077 # define LZO_SIZEOF_SHORT 2
1078 # elif (__LZO_LSR(USHRT_MAX,31) == 1)
1079 # define LZO_SIZEOF_SHORT 4
1080 # elif (__LZO_LSR(USHRT_MAX,63) == 1)
1081 # define LZO_SIZEOF_SHORT 8
1082 # elif (__LZO_LSR(USHRT_MAX,127) == 1)
1083 # define LZO_SIZEOF_SHORT 16
1084 # else
1085 # error "LZO_SIZEOF_SHORT"
1086 # endif
1087 #endif
1088 #if !defined(LZO_SIZEOF_INT)
1089 # if (LZO_ARCH_CRAY_PVP)
1090 # define LZO_SIZEOF_INT 8
1091 # elif (UINT_MAX == LZO_0xffffL)
1092 # define LZO_SIZEOF_INT 2
1093 # elif (UINT_MAX == LZO_0xffffffffL)
1094 # define LZO_SIZEOF_INT 4
1095 # elif (__LZO_LSR(UINT_MAX,7) == 1)
1096 # define LZO_SIZEOF_INT 1
1097 # elif (__LZO_LSR(UINT_MAX,15) == 1)
1098 # define LZO_SIZEOF_INT 2
1099 # elif (__LZO_LSR(UINT_MAX,31) == 1)
1100 # define LZO_SIZEOF_INT 4
1101 # elif (__LZO_LSR(UINT_MAX,63) == 1)
1102 # define LZO_SIZEOF_INT 8
1103 # elif (__LZO_LSR(UINT_MAX,127) == 1)
1104 # define LZO_SIZEOF_INT 16
1105 # else
1106 # error "LZO_SIZEOF_INT"
1107 # endif
1108 #endif
1109 #if !defined(LZO_SIZEOF_LONG)
1110 # if (ULONG_MAX == LZO_0xffffffffL)
1111 # define LZO_SIZEOF_LONG 4
1112 # elif (__LZO_LSR(ULONG_MAX,7) == 1)
1113 # define LZO_SIZEOF_LONG 1
1114 # elif (__LZO_LSR(ULONG_MAX,15) == 1)
1115 # define LZO_SIZEOF_LONG 2
1116 # elif (__LZO_LSR(ULONG_MAX,31) == 1)
1117 # define LZO_SIZEOF_LONG 4
1118 # elif (__LZO_LSR(ULONG_MAX,63) == 1)
1119 # define LZO_SIZEOF_LONG 8
1120 # elif (__LZO_LSR(ULONG_MAX,127) == 1)
1121 # define LZO_SIZEOF_LONG 16
1122 # else
1123 # error "LZO_SIZEOF_LONG"
1124 # endif
1125 #endif
1126 #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64)
1127 #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8)
1128 # if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__)
1129 # if (LZO_CC_GNUC >= 0x030300ul)
1130 # if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0)
1131 # define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG
1132 # elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1)
1133 # define LZO_SIZEOF_LONG_LONG 4
1134 # endif
1135 # endif
1136 # endif
1137 #endif
1138 #endif
1139 #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64)
1140 #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8)
1141 #if (LZO_ARCH_I086 && LZO_CC_DMC)
1142 #elif (LZO_CC_CILLY) && defined(__GNUC__)
1143 # define LZO_SIZEOF_LONG_LONG 8
1144 #elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1145 # define LZO_SIZEOF_LONG_LONG 8
1146 #elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400))
1147 # define LZO_SIZEOF_LONG_LONG 8
1148 #elif (LZO_OS_WIN64 || defined(_WIN64))
1149 # define LZO_SIZEOF___INT64 8
1150 #elif (LZO_ARCH_I386 && (LZO_CC_DMC))
1151 # define LZO_SIZEOF_LONG_LONG 8
1152 #elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700)))
1153 # define LZO_SIZEOF_LONG_LONG 8
1154 #elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__)))
1155 # define LZO_SIZEOF_LONG_LONG 8
1156 #elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC))
1157 # define LZO_SIZEOF_LONG_LONG 8
1158 #elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC))
1159 # define LZO_SIZEOF___INT64 8
1160 #elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC))
1161 # define LZO_SIZEOF___INT64 8
1162 #elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520)))
1163 # define LZO_SIZEOF___INT64 8
1164 #elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100)))
1165 # define LZO_SIZEOF___INT64 8
1166 #elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64))
1167 # define LZO_SIZEOF___INT64 8
1168 #elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__)
1169 # define LZO_SIZEOF_LONG_LONG 8
1170 #elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64)
1171 # define LZO_SIZEOF_LONG_LONG 8
1172 #elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2)
1173 #elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
1174 # define LZO_SIZEOF_LONG_LONG 8
1175 #endif
1176 #endif
1177 #endif
1178 #if defined(__cplusplus) && (LZO_CC_GNUC)
1179 # if (LZO_CC_GNUC < 0x020800ul)
1180 # undef LZO_SIZEOF_LONG_LONG
1181 # endif
1182 #endif
1183 #if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG)
1184 # undef LZO_SIZEOF_LONG_LONG
1185 #endif
1186 #if !defined(LZO_SIZEOF_VOID_P)
1187 #if (LZO_ARCH_I086)
1188 # define __LZO_WORDSIZE 2
1189 # if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM)
1190 # define LZO_SIZEOF_VOID_P 2
1191 # elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE)
1192 # define LZO_SIZEOF_VOID_P 4
1193 # else
1194 # error "LZO_MM"
1195 # endif
1196 #elif (LZO_ARCH_AVR || LZO_ARCH_Z80)
1197 # define __LZO_WORDSIZE 1
1198 # define LZO_SIZEOF_VOID_P 2
1199 #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430)
1200 # define LZO_SIZEOF_VOID_P 2
1201 #elif (LZO_ARCH_H8300)
1202 # if defined(__NORMAL_MODE__)
1203 # define __LZO_WORDSIZE 4
1204 # define LZO_SIZEOF_VOID_P 2
1205 # elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
1206 # define __LZO_WORDSIZE 4
1207 # define LZO_SIZEOF_VOID_P 4
1208 # else
1209 # define __LZO_WORDSIZE 2
1210 # define LZO_SIZEOF_VOID_P 2
1211 # endif
1212 # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4)
1213 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT
1214 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT
1215 # endif
1216 #elif (LZO_ARCH_M16C)
1217 # define __LZO_WORDSIZE 2
1218 # if defined(__m32c_cpu__) || defined(__m32cm_cpu__)
1219 # define LZO_SIZEOF_VOID_P 4
1220 # else
1221 # define LZO_SIZEOF_VOID_P 2
1222 # endif
1223 #elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__))
1224 # define __LZO_WORDSIZE 8
1225 # define LZO_SIZEOF_VOID_P 4
1226 #elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64)
1227 # define __LZO_WORDSIZE 8
1228 # define LZO_SIZEOF_VOID_P 8
1229 #elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__)
1230 # define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG
1231 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG
1232 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG
1233 #elif (LZO_OS_OS400 || defined(__OS400__))
1234 # define __LZO_WORDSIZE LZO_SIZEOF_LONG
1235 # define LZO_SIZEOF_VOID_P 16
1236 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG
1237 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG
1238 #elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64)
1239 # define LZO_SIZEOF_VOID_P 8
1240 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG
1241 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG
1242 #elif (LZO_ARCH_SPU)
1243 # if 0
1244 # define __LZO_WORDSIZE 16
1245 # endif
1246 # define LZO_SIZEOF_VOID_P 4
1247 #else
1248 # define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG
1249 #endif
1250 #endif
1251 #if !defined(LZO_WORDSIZE)
1252 # if defined(__LZO_WORDSIZE)
1253 # define LZO_WORDSIZE __LZO_WORDSIZE
1254 # else
1255 # define LZO_WORDSIZE LZO_SIZEOF_VOID_P
1256 # endif
1257 #endif
1258 #if !defined(LZO_SIZEOF_SIZE_T)
1259 #if (LZO_ARCH_I086 || LZO_ARCH_M16C)
1260 # define LZO_SIZEOF_SIZE_T 2
1261 #else
1262 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P
1263 #endif
1264 #endif
1265 #if !defined(LZO_SIZEOF_PTRDIFF_T)
1266 #if (LZO_ARCH_I086)
1267 # if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE)
1268 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P
1269 # elif (LZO_MM_COMPACT || LZO_MM_LARGE)
1270 # if (LZO_CC_BORLANDC || LZO_CC_TURBOC)
1271 # define LZO_SIZEOF_PTRDIFF_T 4
1272 # else
1273 # define LZO_SIZEOF_PTRDIFF_T 2
1274 # endif
1275 # else
1276 # error "LZO_MM"
1277 # endif
1278 #else
1279 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T
1280 #endif
1281 #endif
1282 #if (LZO_ABI_NEUTRAL_ENDIAN)
1283 # undef LZO_ABI_BIG_ENDIAN
1284 # undef LZO_ABI_LITTLE_ENDIAN
1285 #elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN)
1286 #if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP)
1287 # define LZO_ABI_BIG_ENDIAN 1
1288 #elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64)
1289 # define LZO_ABI_LITTLE_ENDIAN 1
1290 #elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430)
1291 # define LZO_ABI_LITTLE_ENDIAN 1
1292 #elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390)
1293 # define LZO_ABI_BIG_ENDIAN 1
1294 #elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__)
1295 # if (__LITTLE_ENDIAN__ == 1)
1296 # define LZO_ABI_LITTLE_ENDIAN 1
1297 # else
1298 # define LZO_ABI_BIG_ENDIAN 1
1299 # endif
1300 #elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
1301 # define LZO_ABI_BIG_ENDIAN 1
1302 #elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
1303 # define LZO_ABI_LITTLE_ENDIAN 1
1304 #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__)
1305 # define LZO_ABI_BIG_ENDIAN 1
1306 #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__)
1307 # define LZO_ABI_LITTLE_ENDIAN 1
1308 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__)
1309 # define LZO_ABI_BIG_ENDIAN 1
1310 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__)
1311 # define LZO_ABI_LITTLE_ENDIAN 1
1312 #endif
1313 #endif
1314 #if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN)
1315 # error "this should not happen"
1316 #endif
1317 #if (LZO_ABI_BIG_ENDIAN)
1318 # define LZO_INFO_ABI_ENDIAN "be"
1319 #elif (LZO_ABI_LITTLE_ENDIAN)
1320 # define LZO_INFO_ABI_ENDIAN "le"
1321 #elif (LZO_ABI_NEUTRAL_ENDIAN)
1322 # define LZO_INFO_ABI_ENDIAN "neutral"
1323 #endif
1324 #if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2)
1325 # define LZO_ABI_I8LP16 1
1326 # define LZO_INFO_ABI_PM "i8lp16"
1327 #elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2)
1328 # define LZO_ABI_ILP16 1
1329 # define LZO_INFO_ABI_PM "ilp16"
1330 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4)
1331 # define LZO_ABI_ILP32 1
1332 # define LZO_INFO_ABI_PM "ilp32"
1333 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8)
1334 # define LZO_ABI_LLP64 1
1335 # define LZO_INFO_ABI_PM "llp64"
1336 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8)
1337 # define LZO_ABI_LP64 1
1338 # define LZO_INFO_ABI_PM "lp64"
1339 #elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8)
1340 # define LZO_ABI_ILP64 1
1341 # define LZO_INFO_ABI_PM "ilp64"
1342 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4)
1343 # define LZO_ABI_IP32L64 1
1344 # define LZO_INFO_ABI_PM "ip32l64"
1345 #endif
1346 #if !defined(__LZO_LIBC_OVERRIDE)
1347 #if (LZO_LIBC_NAKED)
1348 # define LZO_INFO_LIBC "naked"
1349 #elif (LZO_LIBC_FREESTANDING)
1350 # define LZO_INFO_LIBC "freestanding"
1351 #elif (LZO_LIBC_MOSTLY_FREESTANDING)
1352 # define LZO_INFO_LIBC "mfreestanding"
1353 #elif (LZO_LIBC_ISOC90)
1354 # define LZO_INFO_LIBC "isoc90"
1355 #elif (LZO_LIBC_ISOC99)
1356 # define LZO_INFO_LIBC "isoc99"
1357 #elif defined(__dietlibc__)
1358 # define LZO_LIBC_DIETLIBC 1
1359 # define LZO_INFO_LIBC "dietlibc"
1360 #elif defined(_NEWLIB_VERSION)
1361 # define LZO_LIBC_NEWLIB 1
1362 # define LZO_INFO_LIBC "newlib"
1363 #elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__)
1364 # if defined(__UCLIBC_SUBLEVEL__)
1365 # define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__)
1366 # else
1367 # define LZO_LIBC_UCLIBC 0x00090bL
1368 # endif
1369 # define LZO_INFO_LIBC "uclibc"
1370 #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__)
1371 # define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100)
1372 # define LZO_INFO_LIBC "glibc"
1373 #elif (LZO_CC_MWERKS) && defined(__MSL__)
1374 # define LZO_LIBC_MSL __MSL__
1375 # define LZO_INFO_LIBC "msl"
1376 #elif 1 && defined(__IAR_SYSTEMS_ICC__)
1377 # define LZO_LIBC_ISOC90 1
1378 # define LZO_INFO_LIBC "isoc90"
1379 #else
1380 # define LZO_LIBC_DEFAULT 1
1381 # define LZO_INFO_LIBC "default"
1382 #endif
1383 #endif
1384 #if !defined(__lzo_gnuc_extension__)
1385 #if (LZO_CC_GNUC >= 0x020800ul)
1386 # define __lzo_gnuc_extension__ __extension__
1387 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1388 # define __lzo_gnuc_extension__ __extension__
1389 #else
1390 # define __lzo_gnuc_extension__ /*empty*/
1391 #endif
1392 #endif
1393 #if !defined(__lzo_ua_volatile)
1394 # define __lzo_ua_volatile volatile
1395 #endif
1396 #if !defined(__lzo_alignof)
1397 #if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI)
1398 # define __lzo_alignof(e) __alignof__(e)
1399 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700))
1400 # define __lzo_alignof(e) __alignof__(e)
1401 #elif (LZO_CC_MSC && (_MSC_VER >= 1300))
1402 # define __lzo_alignof(e) __alignof(e)
1403 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1404 # define __lzo_alignof(e) __alignof__(e)
1405 #endif
1406 #endif
1407 #if defined(__lzo_alignof)
1408 # define __lzo_HAVE_alignof 1
1409 #endif
1410 #if !defined(__lzo_constructor)
1411 #if (LZO_CC_GNUC >= 0x030400ul)
1412 # define __lzo_constructor __attribute__((__constructor__,__used__))
1413 #elif (LZO_CC_GNUC >= 0x020700ul)
1414 # define __lzo_constructor __attribute__((__constructor__))
1415 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1416 # define __lzo_constructor __attribute__((__constructor__))
1417 #endif
1418 #endif
1419 #if defined(__lzo_constructor)
1420 # define __lzo_HAVE_constructor 1
1421 #endif
1422 #if !defined(__lzo_destructor)
1423 #if (LZO_CC_GNUC >= 0x030400ul)
1424 # define __lzo_destructor __attribute__((__destructor__,__used__))
1425 #elif (LZO_CC_GNUC >= 0x020700ul)
1426 # define __lzo_destructor __attribute__((__destructor__))
1427 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1428 # define __lzo_destructor __attribute__((__destructor__))
1429 #endif
1430 #endif
1431 #if defined(__lzo_destructor)
1432 # define __lzo_HAVE_destructor 1
1433 #endif
1434 #if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor)
1435 # error "this should not happen"
1436 #endif
1437 #if !defined(__lzo_inline)
1438 #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295))
1439 #elif defined(__cplusplus)
1440 # define __lzo_inline inline
1441 #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550))
1442 # define __lzo_inline __inline
1443 #elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI)
1444 # define __lzo_inline __inline__
1445 #elif (LZO_CC_DMC)
1446 # define __lzo_inline __inline
1447 #elif (LZO_CC_INTELC)
1448 # define __lzo_inline __inline
1449 #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405))
1450 # define __lzo_inline __inline
1451 #elif (LZO_CC_MSC && (_MSC_VER >= 900))
1452 # define __lzo_inline __inline
1453 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1454 # define __lzo_inline __inline__
1455 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
1456 # define __lzo_inline inline
1457 #endif
1458 #endif
1459 #if defined(__lzo_inline)
1460 # define __lzo_HAVE_inline 1
1461 #else
1462 # define __lzo_inline /*empty*/
1463 #endif
1464 #if !defined(__lzo_forceinline)
1465 #if (LZO_CC_GNUC >= 0x030200ul)
1466 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1467 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC)
1468 # define __lzo_forceinline __forceinline
1469 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC)
1470 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1471 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1472 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1473 #elif (LZO_CC_MSC && (_MSC_VER >= 1200))
1474 # define __lzo_forceinline __forceinline
1475 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1476 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1477 #endif
1478 #endif
1479 #if defined(__lzo_forceinline)
1480 # define __lzo_HAVE_forceinline 1
1481 #else
1482 # define __lzo_forceinline /*empty*/
1483 #endif
1484 #if !defined(__lzo_noinline)
1485 #if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul)
1486 # define __lzo_noinline __attribute__((__noinline__,__used__))
1487 #elif (LZO_CC_GNUC >= 0x030200ul)
1488 # define __lzo_noinline __attribute__((__noinline__))
1489 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC)
1490 # define __lzo_noinline __declspec(noinline)
1491 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC)
1492 # define __lzo_noinline __attribute__((__noinline__))
1493 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1494 # define __lzo_noinline __attribute__((__noinline__))
1495 #elif (LZO_CC_MSC && (_MSC_VER >= 1300))
1496 # define __lzo_noinline __declspec(noinline)
1497 #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64))
1498 # if defined(__cplusplus)
1499 # else
1500 # define __lzo_noinline __declspec(noinline)
1501 # endif
1502 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1503 # define __lzo_noinline __attribute__((__noinline__))
1504 #endif
1505 #endif
1506 #if defined(__lzo_noinline)
1507 # define __lzo_HAVE_noinline 1
1508 #else
1509 # define __lzo_noinline /*empty*/
1510 #endif
1511 #if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline)
1512 # error "this should not happen"
1513 #endif
1514 #if !defined(__lzo_noreturn)
1515 #if (LZO_CC_GNUC >= 0x020700ul)
1516 # define __lzo_noreturn __attribute__((__noreturn__))
1517 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC)
1518 # define __lzo_noreturn __declspec(noreturn)
1519 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC)
1520 # define __lzo_noreturn __attribute__((__noreturn__))
1521 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1522 # define __lzo_noreturn __attribute__((__noreturn__))
1523 #elif (LZO_CC_MSC && (_MSC_VER >= 1200))
1524 # define __lzo_noreturn __declspec(noreturn)
1525 #endif
1526 #endif
1527 #if defined(__lzo_noreturn)
1528 # define __lzo_HAVE_noreturn 1
1529 #else
1530 # define __lzo_noreturn /*empty*/
1531 #endif
1532 #if !defined(__lzo_nothrow)
1533 #if (LZO_CC_GNUC >= 0x030300ul)
1534 # define __lzo_nothrow __attribute__((__nothrow__))
1535 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus)
1536 # define __lzo_nothrow __declspec(nothrow)
1537 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC)
1538 # define __lzo_nothrow __attribute__((__nothrow__))
1539 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1540 # define __lzo_nothrow __attribute__((__nothrow__))
1541 #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus)
1542 # define __lzo_nothrow __declspec(nothrow)
1543 #endif
1544 #endif
1545 #if defined(__lzo_nothrow)
1546 # define __lzo_HAVE_nothrow 1
1547 #else
1548 # define __lzo_nothrow /*empty*/
1549 #endif
1550 #if !defined(__lzo_restrict)
1551 #if (LZO_CC_GNUC >= 0x030400ul)
1552 # define __lzo_restrict __restrict__
1553 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC)
1554 # define __lzo_restrict __restrict__
1555 #elif (LZO_CC_CLANG || LZO_CC_LLVM)
1556 # define __lzo_restrict __restrict__
1557 #elif (LZO_CC_MSC && (_MSC_VER >= 1400))
1558 # define __lzo_restrict __restrict
1559 #endif
1560 #endif
1561 #if defined(__lzo_restrict)
1562 # define __lzo_HAVE_restrict 1
1563 #else
1564 # define __lzo_restrict /*empty*/
1565 #endif
1566 #if !defined(__lzo_likely) && !defined(__lzo_unlikely)
1567 #if (LZO_CC_GNUC >= 0x030200ul)
1568 # define __lzo_likely(e) (__builtin_expect(!!(e),1))
1569 # define __lzo_unlikely(e) (__builtin_expect(!!(e),0))
1570 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800))
1571 # define __lzo_likely(e) (__builtin_expect(!!(e),1))
1572 # define __lzo_unlikely(e) (__builtin_expect(!!(e),0))
1573 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1574 # define __lzo_likely(e) (__builtin_expect(!!(e),1))
1575 # define __lzo_unlikely(e) (__builtin_expect(!!(e),0))
1576 #endif
1577 #endif
1578 #if defined(__lzo_likely)
1579 # define __lzo_HAVE_likely 1
1580 #else
1581 # define __lzo_likely(e) (e)
1582 #endif
1583 #if defined(__lzo_unlikely)
1584 # define __lzo_HAVE_unlikely 1
1585 #else
1586 # define __lzo_unlikely(e) (e)
1587 #endif
1588 #if !defined(LZO_UNUSED)
1589 # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
1590 # define LZO_UNUSED(var) ((void) &var)
1591 # elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC)
1592 # define LZO_UNUSED(var) if (&var) ; else
1593 # elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1594 # define LZO_UNUSED(var) ((void) var)
1595 # elif (LZO_CC_MSC && (_MSC_VER < 900))
1596 # define LZO_UNUSED(var) if (&var) ; else
1597 # elif (LZO_CC_KEILC)
1598 # define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];}
1599 # elif (LZO_CC_PACIFICC)
1600 # define LZO_UNUSED(var) ((void) sizeof(var))
1601 # elif (LZO_CC_WATCOMC) && defined(__cplusplus)
1602 # define LZO_UNUSED(var) ((void) var)
1603 # else
1604 # define LZO_UNUSED(var) ((void) &var)
1605 # endif
1606 #endif
1607 #if !defined(LZO_UNUSED_FUNC)
1608 # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
1609 # define LZO_UNUSED_FUNC(func) ((void) func)
1610 # elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC)
1611 # define LZO_UNUSED_FUNC(func) if (func) ; else
1612 # elif (LZO_CC_CLANG || LZO_CC_LLVM)
1613 # define LZO_UNUSED_FUNC(func) ((void) &func)
1614 # elif (LZO_CC_MSC && (_MSC_VER < 900))
1615 # define LZO_UNUSED_FUNC(func) if (func) ; else
1616 # elif (LZO_CC_MSC)
1617 # define LZO_UNUSED_FUNC(func) ((void) &func)
1618 # elif (LZO_CC_KEILC || LZO_CC_PELLESC)
1619 # define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];}
1620 # else
1621 # define LZO_UNUSED_FUNC(func) ((void) func)
1622 # endif
1623 #endif
1624 #if !defined(LZO_UNUSED_LABEL)
1625 # if (LZO_CC_WATCOMC) && defined(__cplusplus)
1626 # define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l
1627 # elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC)
1628 # define LZO_UNUSED_LABEL(l) if (0) goto l
1629 # else
1630 # define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l
1631 # endif
1632 #endif
1633 #if !defined(LZO_DEFINE_UNINITIALIZED_VAR)
1634 # if 0
1635 # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var
1636 # elif 0 && (LZO_CC_GNUC)
1637 # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var
1638 # else
1639 # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init
1640 # endif
1641 #endif
1642 #if !defined(LZO_UNCONST_CAST)
1643 # if 0 && defined(__cplusplus)
1644 # define LZO_UNCONST_CAST(t,e) (const_cast<t> (e))
1645 # elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1646 # define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e))))))
1647 # else
1648 # define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e)))))
1649 # endif
1650 #endif
1651 #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER)
1652 # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC)
1653 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)];
1654 # elif (LZO_CC_DMC || LZO_CC_SYMANTECC)
1655 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)];
1656 # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295))
1657 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)];
1658 # else
1659 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)];
1660 # endif
1661 #endif
1662 #if !defined(LZO_COMPILE_TIME_ASSERT)
1663 # if (LZO_CC_AZTECC)
1664 # define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];}
1665 # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
1666 # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
1667 # elif (LZO_CC_MSC && (_MSC_VER < 900))
1668 # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
1669 # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295))
1670 # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
1671 # else
1672 # define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];}
1673 # endif
1674 #endif
1675 #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64)
1676 # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC)
1677 # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
1678 # define __lzo_cdecl __cdecl
1679 # define __lzo_cdecl_atexit /*empty*/
1680 # define __lzo_cdecl_main __cdecl
1681 # if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC))
1682 # define __lzo_cdecl_qsort __pascal
1683 # elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC))
1684 # define __lzo_cdecl_qsort _stdcall
1685 # else
1686 # define __lzo_cdecl_qsort __cdecl
1687 # endif
1688 # elif (LZO_CC_WATCOMC)
1689 # define __lzo_cdecl __cdecl
1690 # else
1691 # define __lzo_cdecl __cdecl
1692 # define __lzo_cdecl_atexit __cdecl
1693 # define __lzo_cdecl_main __cdecl
1694 # define __lzo_cdecl_qsort __cdecl
1695 # endif
1696 # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC)
1697 # elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC))
1698 # define __lzo_cdecl_sighandler __pascal
1699 # elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC))
1700 # define __lzo_cdecl_sighandler _stdcall
1701 # elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE)
1702 # define __lzo_cdecl_sighandler __clrcall
1703 # elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700))
1704 # if defined(_DLL)
1705 # define __lzo_cdecl_sighandler _far _cdecl _loadds
1706 # elif defined(_MT)
1707 # define __lzo_cdecl_sighandler _far _cdecl
1708 # else
1709 # define __lzo_cdecl_sighandler _cdecl
1710 # endif
1711 # else
1712 # define __lzo_cdecl_sighandler __cdecl
1713 # endif
1714 #elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC)
1715 # define __lzo_cdecl __cdecl
1716 #elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC))
1717 # define __lzo_cdecl cdecl
1718 #endif
1719 #if !defined(__lzo_cdecl)
1720 # define __lzo_cdecl /*empty*/
1721 #endif
1722 #if !defined(__lzo_cdecl_atexit)
1723 # define __lzo_cdecl_atexit /*empty*/
1724 #endif
1725 #if !defined(__lzo_cdecl_main)
1726 # define __lzo_cdecl_main /*empty*/
1727 #endif
1728 #if !defined(__lzo_cdecl_qsort)
1729 # define __lzo_cdecl_qsort /*empty*/
1730 #endif
1731 #if !defined(__lzo_cdecl_sighandler)
1732 # define __lzo_cdecl_sighandler /*empty*/
1733 #endif
1734 #if !defined(__lzo_cdecl_va)
1735 # define __lzo_cdecl_va __lzo_cdecl
1736 #endif
1737 #if !(LZO_CFG_NO_WINDOWS_H)
1738 #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64)
1739 # if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000))
1740 # elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__)
1741 # elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul)))
1742 # else
1743 # define LZO_HAVE_WINDOWS_H 1
1744 # endif
1745 #endif
1746 #endif
1747 #if (LZO_ARCH_ALPHA)
1748 # define LZO_OPT_AVOID_UINT_INDEX 1
1749 # define LZO_OPT_AVOID_SHORT 1
1750 # define LZO_OPT_AVOID_USHORT 1
1751 #elif (LZO_ARCH_AMD64)
1752 # define LZO_OPT_AVOID_INT_INDEX 1
1753 # define LZO_OPT_AVOID_UINT_INDEX 1
1754 # define LZO_OPT_UNALIGNED16 1
1755 # define LZO_OPT_UNALIGNED32 1
1756 # define LZO_OPT_UNALIGNED64 1
1757 #elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB)
1758 #elif (LZO_ARCH_ARM)
1759 # define LZO_OPT_AVOID_SHORT 1
1760 # define LZO_OPT_AVOID_USHORT 1
1761 #elif (LZO_ARCH_CRIS)
1762 # define LZO_OPT_UNALIGNED16 1
1763 # define LZO_OPT_UNALIGNED32 1
1764 #elif (LZO_ARCH_I386)
1765 # define LZO_OPT_UNALIGNED16 1
1766 # define LZO_OPT_UNALIGNED32 1
1767 #elif (LZO_ARCH_IA64)
1768 # define LZO_OPT_AVOID_INT_INDEX 1
1769 # define LZO_OPT_AVOID_UINT_INDEX 1
1770 # define LZO_OPT_PREFER_POSTINC 1
1771 #elif (LZO_ARCH_M68K)
1772 # define LZO_OPT_PREFER_POSTINC 1
1773 # define LZO_OPT_PREFER_PREDEC 1
1774 # if defined(__mc68020__) && !defined(__mcoldfire__)
1775 # define LZO_OPT_UNALIGNED16 1
1776 # define LZO_OPT_UNALIGNED32 1
1777 # endif
1778 #elif (LZO_ARCH_MIPS)
1779 # define LZO_OPT_AVOID_UINT_INDEX 1
1780 #elif (LZO_ARCH_POWERPC)
1781 # define LZO_OPT_PREFER_PREINC 1
1782 # define LZO_OPT_PREFER_PREDEC 1
1783 # if (LZO_ABI_BIG_ENDIAN)
1784 # define LZO_OPT_UNALIGNED16 1
1785 # define LZO_OPT_UNALIGNED32 1
1786 # endif
1787 #elif (LZO_ARCH_S390)
1788 # define LZO_OPT_UNALIGNED16 1
1789 # define LZO_OPT_UNALIGNED32 1
1790 # if (LZO_SIZEOF_SIZE_T == 8)
1791 # define LZO_OPT_UNALIGNED64 1
1792 # endif
1793 #elif (LZO_ARCH_SH)
1794 # define LZO_OPT_PREFER_POSTINC 1
1795 # define LZO_OPT_PREFER_PREDEC 1
1796 #endif
1797 #ifndef LZO_CFG_NO_INLINE_ASM
1798 #if (LZO_CC_LLVM)
1799 # define LZO_CFG_NO_INLINE_ASM 1
1800 #endif
1801 #endif
1802 #ifndef LZO_CFG_NO_UNALIGNED
1803 #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC)
1804 # define LZO_CFG_NO_UNALIGNED 1
1805 #endif
1806 #endif
1807 #if (LZO_CFG_NO_UNALIGNED)
1808 # undef LZO_OPT_UNALIGNED16
1809 # undef LZO_OPT_UNALIGNED32
1810 # undef LZO_OPT_UNALIGNED64
1811 #endif
1812 #if (LZO_CFG_NO_INLINE_ASM)
1813 #elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC))
1814 # define LZO_ASM_SYNTAX_MSC 1
1815 #elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC))
1816 #elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul))
1817 #elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE))
1818 # define LZO_ASM_SYNTAX_GNUC 1
1819 #elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE))
1820 # define LZO_ASM_SYNTAX_GNUC 1
1821 #endif
1822 #if (LZO_ASM_SYNTAX_GNUC)
1823 #if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul))
1824 # define __LZO_ASM_CLOBBER "ax"
1825 #elif (LZO_CC_INTELC)
1826 # define __LZO_ASM_CLOBBER "memory"
1827 #else
1828 # define __LZO_ASM_CLOBBER "cc", "memory"
1829 #endif
1830 #endif
1831 #if defined(__LZO_INFOSTR_MM)
1832 #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM))
1833 # define __LZO_INFOSTR_MM ""
1834 #elif defined(LZO_INFO_MM)
1835 # define __LZO_INFOSTR_MM "." LZO_INFO_MM
1836 #else
1837 # define __LZO_INFOSTR_MM ""
1838 #endif
1839 #if defined(__LZO_INFOSTR_PM)
1840 #elif defined(LZO_INFO_ABI_PM)
1841 # define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM
1842 #else
1843 # define __LZO_INFOSTR_PM ""
1844 #endif
1845 #if defined(__LZO_INFOSTR_ENDIAN)
1846 #elif defined(LZO_INFO_ABI_ENDIAN)
1847 # define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN
1848 #else
1849 # define __LZO_INFOSTR_ENDIAN ""
1850 #endif
1851 #if defined(__LZO_INFOSTR_OSNAME)
1852 #elif defined(LZO_INFO_OS_CONSOLE)
1853 # define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE
1854 #elif defined(LZO_INFO_OS_POSIX)
1855 # define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX
1856 #else
1857 # define __LZO_INFOSTR_OSNAME LZO_INFO_OS
1858 #endif
1859 #if defined(__LZO_INFOSTR_LIBC)
1860 #elif defined(LZO_INFO_LIBC)
1861 # define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC
1862 #else
1863 # define __LZO_INFOSTR_LIBC ""
1864 #endif
1865 #if defined(__LZO_INFOSTR_CCVER)
1866 #elif defined(LZO_INFO_CCVER)
1867 # define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER
1868 #else
1869 # define __LZO_INFOSTR_CCVER ""
1870 #endif
1871 #define LZO_INFO_STRING \
1872 LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \
1873 " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER
1874
1875 #endif
1876
1877 #endif
1878
1879 #undef LZO_HAVE_CONFIG_H
1880 #include "minilzo.h"
1881
1882 #if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2050)
1883 # error "version mismatch in miniLZO source files"
1884 #endif
1885
1886 #ifdef MINILZO_HAVE_CONFIG_H
1887 # define LZO_HAVE_CONFIG_H 1
1888 #endif
1889
1890 #ifndef __LZO_CONF_H
1891 #define __LZO_CONF_H 1
1892
1893 #if !defined(__LZO_IN_MINILZO)
1894 #if (LZO_CFG_FREESTANDING)
1895 # define LZO_LIBC_FREESTANDING 1
1896 # define LZO_OS_FREESTANDING 1
1897 # define ACC_LIBC_FREESTANDING 1
1898 # define ACC_OS_FREESTANDING 1
1899 #endif
1900 #if (LZO_CFG_NO_UNALIGNED)
1901 # define ACC_CFG_NO_UNALIGNED 1
1902 #endif
1903 #if (LZO_ARCH_GENERIC)
1904 # define ACC_ARCH_GENERIC 1
1905 #endif
1906 #if (LZO_ABI_NEUTRAL_ENDIAN)
1907 # define ACC_ABI_NEUTRAL_ENDIAN 1
1908 #endif
1909 #if (LZO_HAVE_CONFIG_H)
1910 # define ACC_CONFIG_NO_HEADER 1
1911 #endif
1912 #if defined(LZO_CFG_EXTRA_CONFIG_HEADER)
1913 # include LZO_CFG_EXTRA_CONFIG_HEADER
1914 #endif
1915 #if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED)
1916 # error "include this file first"
1917 #endif
1918 #include "lzo/lzoconf.h"
1919 #endif
1920
1921 #if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED)
1922 # error "version mismatch"
1923 #endif
1924
1925 #if (LZO_CC_BORLANDC && LZO_ARCH_I086)
1926 # pragma option -h
1927 #endif
1928
1929 #if (LZO_CC_MSC && (_MSC_VER >= 1000))
1930 # pragma warning(disable: 4127 4701)
1931 #endif
1932 #if (LZO_CC_MSC && (_MSC_VER >= 1300))
1933 # pragma warning(disable: 4820)
1934 # pragma warning(disable: 4514 4710 4711)
1935 #endif
1936
1937 #if (LZO_CC_SUNPROC)
1938 #if !defined(__cplusplus)
1939 # pragma error_messages(off,E_END_OF_LOOP_CODE_NOT_REACHED)
1940 # pragma error_messages(off,E_LOOP_NOT_ENTERED_AT_TOP)
1941 # pragma error_messages(off,E_STATEMENT_NOT_REACHED)
1942 #endif
1943 #endif
1944
1945 #if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR)
1946 # error "this should not happen - check defines for __huge"
1947 #endif
1948
1949 #if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING)
1950 #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
1951 # define ACC_WANT_ACC_INCD_H 1
1952 # define ACC_WANT_ACC_INCE_H 1
1953 # define ACC_WANT_ACC_INCI_H 1
1954 #elif 1
1955 # include <string.h>
1956 #else
1957 # define ACC_WANT_ACC_INCD_H 1
1958 #endif
1959
1960 #if (LZO_ARCH_I086)
1961 # define ACC_MM_AHSHIFT LZO_MM_AHSHIFT
1962 # define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0])
1963 # define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1])
1964 # define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
1965 #endif
1966
1967 #if !defined(lzo_uintptr_t)
1968 # if defined(__LZO_MMODEL_HUGE)
1969 # define lzo_uintptr_t unsigned long
1970 # elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16)
1971 # define __LZO_UINTPTR_T_IS_POINTER 1
1972 typedef char* lzo_uintptr_t;
1973 # define lzo_uintptr_t lzo_uintptr_t
1974 # elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P)
1975 # define lzo_uintptr_t size_t
1976 # elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P)
1977 # define lzo_uintptr_t unsigned long
1978 # elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P)
1979 # define lzo_uintptr_t unsigned int
1980 # elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P)
1981 # define lzo_uintptr_t unsigned long long
1982 # else
1983 # define lzo_uintptr_t size_t
1984 # endif
1985 #endif
1986 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
1987
1988 #if 1 && !defined(LZO_CFG_FREESTANDING)
1989 #if 1 && !defined(HAVE_STRING_H)
1990 #define HAVE_STRING_H 1
1991 #endif
1992 #if 1 && !defined(HAVE_MEMCMP)
1993 #define HAVE_MEMCMP 1
1994 #endif
1995 #if 1 && !defined(HAVE_MEMCPY)
1996 #define HAVE_MEMCPY 1
1997 #endif
1998 #if 1 && !defined(HAVE_MEMMOVE)
1999 #define HAVE_MEMMOVE 1
2000 #endif
2001 #if 1 && !defined(HAVE_MEMSET)
2002 #define HAVE_MEMSET 1
2003 #endif
2004 #endif
2005
2006 #if 1 && defined(HAVE_STRING_H)
2007 #include <string.h>
2008 #endif
2009
2010 #if (LZO_CFG_FREESTANDING)
2011 # undef HAVE_MEMCMP
2012 # undef HAVE_MEMCPY
2013 # undef HAVE_MEMMOVE
2014 # undef HAVE_MEMSET
2015 #endif
2016
2017 #if !(HAVE_MEMCMP)
2018 # undef memcmp
2019 # define memcmp(a,b,c) lzo_memcmp(a,b,c)
2020 #elif !(__LZO_MMODEL_HUGE)
2021 # undef lzo_memcmp
2022 # define lzo_memcmp(a,b,c) memcmp(a,b,c)
2023 #endif
2024 #if !(HAVE_MEMCPY)
2025 # undef memcpy
2026 # define memcpy(a,b,c) lzo_memcpy(a,b,c)
2027 #elif !(__LZO_MMODEL_HUGE)
2028 # undef lzo_memcpy
2029 # define lzo_memcpy(a,b,c) memcpy(a,b,c)
2030 #endif
2031 #if !(HAVE_MEMMOVE)
2032 # undef memmove
2033 # define memmove(a,b,c) lzo_memmove(a,b,c)
2034 #elif !(__LZO_MMODEL_HUGE)
2035 # undef lzo_memmove
2036 # define lzo_memmove(a,b,c) memmove(a,b,c)
2037 #endif
2038 #if !(HAVE_MEMSET)
2039 # undef memset
2040 # define memset(a,b,c) lzo_memset(a,b,c)
2041 #elif !(__LZO_MMODEL_HUGE)
2042 # undef lzo_memset
2043 # define lzo_memset(a,b,c) memset(a,b,c)
2044 #endif
2045
2046 #undef NDEBUG
2047 #if (LZO_CFG_FREESTANDING)
2048 # undef LZO_DEBUG
2049 # define NDEBUG 1
2050 # undef assert
2051 # define assert(e) ((void)0)
2052 #else
2053 # if !defined(LZO_DEBUG)
2054 # define NDEBUG 1
2055 # endif
2056 # include <assert.h>
2057 #endif
2058
2059 #if 0 && defined(__BOUNDS_CHECKING_ON)
2060 # include <unchecked.h>
2061 #else
2062 # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
2063 # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
2064 #endif
2065
2066 #if !defined(__lzo_inline)
2067 # define __lzo_inline /*empty*/
2068 #endif
2069 #if !defined(__lzo_forceinline)
2070 # define __lzo_forceinline /*empty*/
2071 #endif
2072 #if !defined(__lzo_noinline)
2073 # define __lzo_noinline /*empty*/
2074 #endif
2075
2076 #if (LZO_CFG_PGO)
2077 # undef __acc_likely
2078 # undef __acc_unlikely
2079 # undef __lzo_likely
2080 # undef __lzo_unlikely
2081 # define __acc_likely(e) (e)
2082 # define __acc_unlikely(e) (e)
2083 # define __lzo_likely(e) (e)
2084 # define __lzo_unlikely(e) (e)
2085 #endif
2086
2087 #if 1
2088 # define LZO_BYTE(x) ((unsigned char) (x))
2089 #else
2090 # define LZO_BYTE(x) ((unsigned char) ((x) & 0xff))
2091 #endif
2092
2093 #define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
2094 #define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
2095 #define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
2096 #define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c))
2097
2098 #define lzo_sizeof(type) ((lzo_uint) (sizeof(type)))
2099
2100 #define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array))))
2101
2102 #define LZO_SIZE(bits) (1u << (bits))
2103 #define LZO_MASK(bits) (LZO_SIZE(bits) - 1)
2104
2105 #define LZO_LSIZE(bits) (1ul << (bits))
2106 #define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1)
2107
2108 #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits))
2109 #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1)
2110
2111 #if !defined(DMUL)
2112 #if 0
2113
2114 # define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b)))
2115 #else
2116 # define DMUL(a,b) ((lzo_xint) ((a) * (b)))
2117 #endif
2118 #endif
2119
2120 #if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC)
2121 # if (LZO_SIZEOF_SHORT == 2)
2122 # define LZO_UNALIGNED_OK_2 1
2123 # endif
2124 # if (LZO_SIZEOF_INT == 4)
2125 # define LZO_UNALIGNED_OK_4 1
2126 # endif
2127 #endif
2128 #if 1 && (LZO_ARCH_AMD64)
2129 # if defined(LZO_UINT64_MAX)
2130 # define LZO_UNALIGNED_OK_8 1
2131 # endif
2132 #endif
2133 #if (LZO_CFG_NO_UNALIGNED)
2134 # undef LZO_UNALIGNED_OK_2
2135 # undef LZO_UNALIGNED_OK_4
2136 # undef LZO_UNALIGNED_OK_8
2137 #endif
2138
2139 #undef UA_GET16
2140 #undef UA_SET16
2141 #undef UA_COPY16
2142 #undef UA_GET32
2143 #undef UA_SET32
2144 #undef UA_COPY32
2145 #undef UA_GET64
2146 #undef UA_SET64
2147 #undef UA_COPY64
2148 #if defined(LZO_UNALIGNED_OK_2)
2149 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2)
2150 # if 1 && defined(ACC_UA_COPY16)
2151 # define UA_GET16 ACC_UA_GET16
2152 # define UA_SET16 ACC_UA_SET16
2153 # define UA_COPY16 ACC_UA_COPY16
2154 # else
2155 # define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p))
2156 # define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v))
2157 # define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s))
2158 # endif
2159 #endif
2160 #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
2161 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4)
2162 # if 1 && defined(ACC_UA_COPY32)
2163 # define UA_GET32 ACC_UA_GET32
2164 # define UA_SET32 ACC_UA_SET32
2165 # define UA_COPY32 ACC_UA_COPY32
2166 # else
2167 # define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p))
2168 # define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v))
2169 # define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s))
2170 # endif
2171 #endif
2172 #if defined(LZO_UNALIGNED_OK_8)
2173 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8)
2174 # if 1 && defined(ACC_UA_COPY64)
2175 # define UA_GET64 ACC_UA_GET64
2176 # define UA_SET64 ACC_UA_SET64
2177 # define UA_COPY64 ACC_UA_COPY64
2178 # else
2179 # define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p))
2180 # define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v))
2181 # define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s))
2182 # endif
2183 #endif
2184
2185 #define MEMCPY8_DS(dest,src,len) \
2186 lzo_memcpy(dest,src,len); dest += len; src += len
2187
2188 #define BZERO8_PTR(s,l,n) \
2189 lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n))
2190
2191 #define MEMCPY_DS(dest,src,len) \
2192 do *dest++ = *src++; while (--len > 0)
2193
2194 LZO_EXTERN(const lzo_bytep) lzo_copyright(void);
2195
2196 #ifndef __LZO_PTR_H
2197 #define __LZO_PTR_H 1
2198
2199 #ifdef __cplusplus
2200 extern "C" {
2201 #endif
2202
2203 #if !defined(lzo_uintptr_t)
2204 # if (__LZO_MMODEL_HUGE)
2205 # define lzo_uintptr_t unsigned long
2206 # else
2207 # define lzo_uintptr_t acc_uintptr_t
2208 # ifdef __ACC_INTPTR_T_IS_POINTER
2209 # define __LZO_UINTPTR_T_IS_POINTER 1
2210 # endif
2211 # endif
2212 #endif
2213
2214 #if (LZO_ARCH_I086)
2215 #define PTR(a) ((lzo_bytep) (a))
2216 #define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0)
2217 #define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0)
2218 #elif (LZO_MM_PVP)
2219 #define PTR(a) ((lzo_bytep) (a))
2220 #define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0)
2221 #define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0)
2222 #else
2223 #define PTR(a) ((lzo_uintptr_t) (a))
2224 #define PTR_LINEAR(a) PTR(a)
2225 #define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
2226 #define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0)
2227 #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
2228 #define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
2229 #endif
2230
2231 #define PTR_LT(a,b) (PTR(a) < PTR(b))
2232 #define PTR_GE(a,b) (PTR(a) >= PTR(b))
2233 #define PTR_DIFF(a,b) (PTR(a) - PTR(b))
2234 #define pd(a,b) ((lzo_uint) ((a)-(b)))
2235
2236 LZO_EXTERN(lzo_uintptr_t)
2237 __lzo_ptr_linear(const lzo_voidp ptr);
2238
2239 typedef union
2240 {
2241 char a_char;
2242 unsigned char a_uchar;
2243 short a_short;
2244 unsigned short a_ushort;
2245 int a_int;
2246 unsigned int a_uint;
2247 long a_long;
2248 unsigned long a_ulong;
2249 lzo_int a_lzo_int;
2250 lzo_uint a_lzo_uint;
2251 lzo_int32 a_lzo_int32;
2252 lzo_uint32 a_lzo_uint32;
2253 #if defined(LZO_UINT64_MAX)
2254 lzo_int64 a_lzo_int64;
2255 lzo_uint64 a_lzo_uint64;
2256 #endif
2257 ptrdiff_t a_ptrdiff_t;
2258 lzo_uintptr_t a_lzo_uintptr_t;
2259 lzo_voidp a_lzo_voidp;
2260 void * a_void_p;
2261 lzo_bytep a_lzo_bytep;
2262 lzo_bytepp a_lzo_bytepp;
2263 lzo_uintp a_lzo_uintp;
2264 lzo_uint * a_lzo_uint_p;
2265 lzo_uint32p a_lzo_uint32p;
2266 lzo_uint32 * a_lzo_uint32_p;
2267 unsigned char * a_uchar_p;
2268 char * a_char_p;
2269 }
2270 lzo_full_align_t;
2271
2272 #ifdef __cplusplus
2273 }
2274 #endif
2275
2276 #endif
2277
2278 #ifndef LZO_DETERMINISTIC
2279 #define LZO_DETERMINISTIC 1
2280 #endif
2281
2282 #ifndef LZO_DICT_USE_PTR
2283 #define LZO_DICT_USE_PTR 1
2284 #if 0 && (LZO_ARCH_I086)
2285 # undef LZO_DICT_USE_PTR
2286 # define LZO_DICT_USE_PTR 0
2287 #endif
2288 #endif
2289
2290 #if (LZO_DICT_USE_PTR)
2291 # define lzo_dict_t const lzo_bytep
2292 # define lzo_dict_p lzo_dict_t __LZO_MMODEL *
2293 #else
2294 # define lzo_dict_t lzo_uint
2295 # define lzo_dict_p lzo_dict_t __LZO_MMODEL *
2296 #endif
2297
2298 #endif
2299
2300 #if !defined(MINILZO_CFG_SKIP_LZO_PTR)
2301
2302 LZO_PUBLIC(lzo_uintptr_t)
2303 __lzo_ptr_linear(const lzo_voidp ptr)
2304 {
2305 lzo_uintptr_t p;
2306
2307 #if (LZO_ARCH_I086)
2308 p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr));
2309 #elif (LZO_MM_PVP)
2310 p = (lzo_uintptr_t) (ptr);
2311 p = (p << 3) | (p >> 61);
2312 #else
2313 p = (lzo_uintptr_t) PTR_LINEAR(ptr);
2314 #endif
2315
2316 return p;
2317 }
2318
2319 LZO_PUBLIC(unsigned)
2320 __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
2321 {
2322 #if defined(__LZO_UINTPTR_T_IS_POINTER)
2323 size_t n = (size_t) ptr;
2324 n = (((n + size - 1) / size) * size) - n;
2325 #else
2326 lzo_uintptr_t p, n;
2327 p = __lzo_ptr_linear(ptr);
2328 n = (((p + size - 1) / size) * size) - p;
2329 #endif
2330
2331 assert(size > 0);
2332 assert((long)n >= 0);
2333 assert(n <= size);
2334 return (unsigned)n;
2335 }
2336
2337 #endif
2338 #if !defined(MINILZO_CFG_SKIP_LZO_UTIL)
2339
2340 /* If you use the LZO library in a product, I would appreciate that you
2341 * keep this copyright string in the executable of your product.
2342 */
2343
2344 static const char __lzo_copyright[] =
2345 #if !defined(__LZO_IN_MINLZO)
2346 LZO_VERSION_STRING;
2347 #else
2348 "\r\n\n"
2349 "LZO data compression library.\n"
2350 "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n"
2351 "<markus@oberhumer.com>\n"
2352 "http://www.oberhumer.com $\n\n"
2353 "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n"
2354 "$Info: " LZO_INFO_STRING " $\n";
2355 #endif
2356
2357 LZO_PUBLIC(const lzo_bytep)
2358 lzo_copyright(void)
2359 {
2360 #if (LZO_OS_DOS16 && LZO_CC_TURBOC)
2361 return (lzo_voidp) __lzo_copyright;
2362 #else
2363 return (const lzo_bytep) __lzo_copyright;
2364 #endif
2365 }
2366
2367 LZO_PUBLIC(unsigned)
2368 lzo_version(void)
2369 {
2370 return LZO_VERSION;
2371 }
2372
2373 LZO_PUBLIC(const char *)
2374 lzo_version_string(void)
2375 {
2376 return LZO_VERSION_STRING;
2377 }
2378
2379 LZO_PUBLIC(const char *)
2380 lzo_version_date(void)
2381 {
2382 return LZO_VERSION_DATE;
2383 }
2384
2385 LZO_PUBLIC(const lzo_charp)
2386 _lzo_version_string(void)
2387 {
2388 return LZO_VERSION_STRING;
2389 }
2390
2391 LZO_PUBLIC(const lzo_charp)
2392 _lzo_version_date(void)
2393 {
2394 return LZO_VERSION_DATE;
2395 }
2396
2397 #define LZO_BASE 65521u
2398 #define LZO_NMAX 5552
2399
2400 #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1
2401 #define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1);
2402 #define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2);
2403 #define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4);
2404 #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
2405
2406 LZO_PUBLIC(lzo_uint32)
2407 lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len)
2408 {
2409 lzo_uint32 s1 = adler & 0xffff;
2410 lzo_uint32 s2 = (adler >> 16) & 0xffff;
2411 unsigned k;
2412
2413 if (buf == NULL)
2414 return 1;
2415
2416 while (len > 0)
2417 {
2418 k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
2419 len -= k;
2420 if (k >= 16) do
2421 {
2422 LZO_DO16(buf,0);
2423 buf += 16;
2424 k -= 16;
2425 } while (k >= 16);
2426 if (k != 0) do
2427 {
2428 s1 += *buf++;
2429 s2 += s1;
2430 } while (--k > 0);
2431 s1 %= LZO_BASE;
2432 s2 %= LZO_BASE;
2433 }
2434 return (s2 << 16) | s1;
2435 }
2436
2437 #undef LZO_DO1
2438 #undef LZO_DO2
2439 #undef LZO_DO4
2440 #undef LZO_DO8
2441 #undef LZO_DO16
2442
2443 #endif
2444 #if !defined(MINILZO_CFG_SKIP_LZO_STRING)
2445 #undef lzo_memcmp
2446 #undef lzo_memcpy
2447 #undef lzo_memmove
2448 #undef lzo_memset
2449 #if !defined(__LZO_MMODEL_HUGE)
2450 # undef LZO_HAVE_MM_HUGE_PTR
2451 #endif
2452 #define lzo_hsize_t lzo_uint
2453 #define lzo_hvoid_p lzo_voidp
2454 #define lzo_hbyte_p lzo_bytep
2455 #define LZOLIB_PUBLIC(r,f) LZO_PUBLIC(r) f
2456 #define lzo_hmemcmp lzo_memcmp
2457 #define lzo_hmemcpy lzo_memcpy
2458 #define lzo_hmemmove lzo_memmove
2459 #define lzo_hmemset lzo_memset
2460 #define __LZOLIB_HMEMCPY_CH_INCLUDED 1
2461 #if !defined(LZOLIB_PUBLIC)
2462 # define LZOLIB_PUBLIC(r,f) r __LZOLIB_FUNCNAME(f)
2463 #endif
2464 LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len)
2465 {
2466 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP)
2467 const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1;
2468 const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2;
2469 if __lzo_likely(len > 0) do
2470 {
2471 int d = *p1 - *p2;
2472 if (d != 0)
2473 return d;
2474 p1++; p2++;
2475 } while __lzo_likely(--len > 0);
2476 return 0;
2477 #else
2478 return memcmp(s1, s2, len);
2479 #endif
2480 }
2481 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len)
2482 {
2483 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY)
2484 lzo_hbyte_p p1 = (lzo_hbyte_p) dest;
2485 const lzo_hbyte_p p2 = (const lzo_hbyte_p) src;
2486 if (!(len > 0) || p1 == p2)
2487 return dest;
2488 do
2489 *p1++ = *p2++;
2490 while __lzo_likely(--len > 0);
2491 return dest;
2492 #else
2493 return memcpy(dest, src, len);
2494 #endif
2495 }
2496 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len)
2497 {
2498 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE)
2499 lzo_hbyte_p p1 = (lzo_hbyte_p) dest;
2500 const lzo_hbyte_p p2 = (const lzo_hbyte_p) src;
2501 if (!(len > 0) || p1 == p2)
2502 return dest;
2503 if (p1 < p2)
2504 {
2505 do
2506 *p1++ = *p2++;
2507 while __lzo_likely(--len > 0);
2508 }
2509 else
2510 {
2511 p1 += len;
2512 p2 += len;
2513 do
2514 *--p1 = *--p2;
2515 while __lzo_likely(--len > 0);
2516 }
2517 return dest;
2518 #else
2519 return memmove(dest, src, len);
2520 #endif
2521 }
2522 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len)
2523 {
2524 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET)
2525 lzo_hbyte_p p = (lzo_hbyte_p) s;
2526 if __lzo_likely(len > 0) do
2527 *p++ = (unsigned char) c;
2528 while __lzo_likely(--len > 0);
2529 return s;
2530 #else
2531 return memset(s, c, len);
2532 #endif
2533 }
2534 #undef LZOLIB_PUBLIC
2535 #endif
2536 #if !defined(MINILZO_CFG_SKIP_LZO_INIT)
2537
2538 #if !defined(__LZO_IN_MINILZO)
2539
2540 #define ACC_WANT_ACC_CHK_CH 1
2541 #undef ACCCHK_ASSERT
2542
2543 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int)
2544 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint)
2545
2546 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32)
2547 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32)
2548 ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0)
2549 ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4)
2550 #if defined(LZO_UINT64_MAX)
2551 ACCCHK_ASSERT(sizeof(lzo_uint64) == 8)
2552 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64)
2553 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64)
2554 #endif
2555
2556 #if !defined(__LZO_UINTPTR_T_IS_POINTER)
2557 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t)
2558 #endif
2559 ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
2560
2561 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint)
2562 ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32))
2563 ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint))
2564 ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint))
2565
2566 #endif
2567 #undef ACCCHK_ASSERT
2568
2569 #if 0
2570 #define WANT_lzo_bitops_clz32 1
2571 #define WANT_lzo_bitops_clz64 1
2572 #endif
2573 #define WANT_lzo_bitops_ctz32 1
2574 #define WANT_lzo_bitops_ctz64 1
2575
2576 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
2577 #include <intrin.h>
2578 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
2579 #pragma intrinsic(_BitScanReverse)
2580 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
2581 {
2582 unsigned long r;
2583 (void) _BitScanReverse(&r, v);
2584 return (unsigned) r;
2585 }
2586 #define lzo_bitops_clz32 lzo_bitops_clz32
2587 #endif
2588 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
2589 #pragma intrinsic(_BitScanReverse64)
2590 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
2591 {
2592 unsigned long r;
2593 (void) _BitScanReverse64(&r, v);
2594 return (unsigned) r;
2595 }
2596 #define lzo_bitops_clz64 lzo_bitops_clz64
2597 #endif
2598 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
2599 #pragma intrinsic(_BitScanForward)
2600 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
2601 {
2602 unsigned long r;
2603 (void) _BitScanForward(&r, v);
2604 return (unsigned) r;
2605 }
2606 #define lzo_bitops_ctz32 lzo_bitops_ctz32
2607 #endif
2608 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
2609 #pragma intrinsic(_BitScanForward64)
2610 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
2611 {
2612 unsigned long r;
2613 (void) _BitScanForward64(&r, v);
2614 return (unsigned) r;
2615 }
2616 #define lzo_bitops_ctz64 lzo_bitops_ctz64
2617 #endif
2618
2619 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM)
2620 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
2621 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
2622 #endif
2623 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
2624 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
2625 #endif
2626 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
2627 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
2628 #endif
2629 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
2630 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
2631 #endif
2632 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
2633 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
2634 #endif
2635 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
2636 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))
2637 #endif
2638 #endif
2639
2640 #if 0
2641 #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off)))
2642 #else
2643 static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off)
2644 {
2645 return (lzo_voidp) ((lzo_bytep) ptr + off);
2646 }
2647 #endif
2648
2649 LZO_PUBLIC(int)
2650 _lzo_config_check(void)
2651 {
2652 lzo_bool r = 1;
2653 union {
2654 lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))];
2655 #if defined(LZO_UNALIGNED_OK_8)
2656 lzo_uint64 c[2];
2657 #endif
2658 unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2];
2659 } u;
2660 lzo_voidp p;
2661
2662 u.a[0] = u.a[1] = 0;
2663 p = u2p(&u, 0);
2664 r &= ((* (lzo_bytep) p) == 0);
2665 #if !defined(LZO_CFG_NO_CONFIG_CHECK)
2666 #if defined(LZO_ABI_BIG_ENDIAN)
2667 u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128;
2668 p = u2p(&u, 0);
2669 r &= ((* (lzo_uintp) p) == 128);
2670 #endif
2671 #if defined(LZO_ABI_LITTLE_ENDIAN)
2672 u.a[0] = u.a[1] = 0; u.b[0] = 128;
2673 p = u2p(&u, 0);
2674 r &= ((* (lzo_uintp) p) == 128);
2675 #endif
2676 #if defined(LZO_UNALIGNED_OK_2)
2677 u.a[0] = u.a[1] = 0;
2678 u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2;
2679 p = u2p(&u, 1);
2680 r &= ((* (lzo_ushortp) p) == 0);
2681 #endif
2682 #if defined(LZO_UNALIGNED_OK_4)
2683 u.a[0] = u.a[1] = 0;
2684 u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4;
2685 p = u2p(&u, 1);
2686 r &= ((* (lzo_uint32p) p) == 0);
2687 #endif
2688 #if defined(LZO_UNALIGNED_OK_8)
2689 u.c[0] = u.c[1] = 0;
2690 u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6;
2691 p = u2p(&u, 1);
2692 r &= ((* (lzo_uint64p) p) == 0);
2693 #endif
2694 #if defined(lzo_bitops_clz32)
2695 { unsigned i; lzo_uint32 v = 1;
2696 for (i = 0; i < 31; i++, v <<= 1)
2697 r &= lzo_bitops_clz32(v) == 31 - i;
2698 }
2699 #endif
2700 #if defined(lzo_bitops_clz64)
2701 { unsigned i; lzo_uint64 v = 1;
2702 for (i = 0; i < 63; i++, v <<= 1)
2703 r &= lzo_bitops_clz64(v) == 63 - i;
2704 }
2705 #endif
2706 #if defined(lzo_bitops_ctz32)
2707 { unsigned i; lzo_uint32 v = 1;
2708 for (i = 0; i < 31; i++, v <<= 1)
2709 r &= lzo_bitops_ctz32(v) == i;
2710 }
2711 #endif
2712 #if defined(lzo_bitops_ctz64)
2713 { unsigned i; lzo_uint64 v = 1;
2714 for (i = 0; i < 63; i++, v <<= 1)
2715 r &= lzo_bitops_ctz64(v) == i;
2716 }
2717 #endif
2718 #endif
2719
2720 return r == 1 ? LZO_E_OK : LZO_E_ERROR;
2721 }
2722
2723 LZO_PUBLIC(int)
2724 __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5,
2725 int s6, int s7, int s8, int s9)
2726 {
2727 int r;
2728
2729 #if defined(__LZO_IN_MINILZO)
2730 #elif (LZO_CC_MSC && ((_MSC_VER) < 700))
2731 #else
2732 #define ACC_WANT_ACC_CHK_CH 1
2733 #undef ACCCHK_ASSERT
2734 #define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr)
2735 #endif
2736 #undef ACCCHK_ASSERT
2737
2738 if (v == 0)
2739 return LZO_E_ERROR;
2740
2741 r = (s1 == -1 || s1 == (int) sizeof(short)) &&
2742 (s2 == -1 || s2 == (int) sizeof(int)) &&
2743 (s3 == -1 || s3 == (int) sizeof(long)) &&
2744 (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&
2745 (s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&
2746 (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&
2747 (s7 == -1 || s7 == (int) sizeof(char *)) &&
2748 (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
2749 (s9 == -1 || s9 == (int) sizeof(lzo_callback_t));
2750 if (!r)
2751 return LZO_E_ERROR;
2752
2753 r = _lzo_config_check();
2754 if (r != LZO_E_OK)
2755 return r;
2756
2757 return r;
2758 }
2759
2760 #if !defined(__LZO_IN_MINILZO)
2761
2762 #if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD)
2763
2764 #if 0
2765 BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment,
2766 WORD wHeapSize, LPSTR lpszCmdLine )
2767 #else
2768 int __far __pascal LibMain ( int a, short b, short c, long d )
2769 #endif
2770 {
2771 LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d);
2772 return 1;
2773 }
2774
2775 #endif
2776
2777 #endif
2778
2779 #endif
2780
2781 #define LZO1X 1
2782 #define LZO_EOF_CODE 1
2783 #define M2_MAX_OFFSET 0x0800
2784
2785 #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS)
2786
2787 #if 1 && defined(UA_GET32)
2788 #undef LZO_DICT_USE_PTR
2789 #define LZO_DICT_USE_PTR 0
2790 #undef lzo_dict_t
2791 #define lzo_dict_t unsigned short
2792 #endif
2793
2794 #define LZO_NEED_DICT_H 1
2795 #ifndef D_BITS
2796 #define D_BITS 14
2797 #endif
2798 #define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
2799 #define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
2800 #if 1
2801 #define DINDEX(dv,p) DM(((DMUL(0x1824429d,dv)) >> (32-D_BITS)))
2802 #else
2803 #define DINDEX(dv,p) DM((dv) + ((dv) >> (32-D_BITS)))
2804 #endif
2805
2806 #ifndef __LZO_CONFIG1X_H
2807 #define __LZO_CONFIG1X_H 1
2808
2809 #if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
2810 # define LZO1X 1
2811 #endif
2812
2813 #if !defined(__LZO_IN_MINILZO)
2814 #include "lzo/lzo1x.h"
2815 #endif
2816
2817 #ifndef LZO_EOF_CODE
2818 #define LZO_EOF_CODE 1
2819 #endif
2820 #undef LZO_DETERMINISTIC
2821
2822 #define M1_MAX_OFFSET 0x0400
2823 #ifndef M2_MAX_OFFSET
2824 #define M2_MAX_OFFSET 0x0800
2825 #endif
2826 #define M3_MAX_OFFSET 0x4000
2827 #define M4_MAX_OFFSET 0xbfff
2828
2829 #define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
2830
2831 #define M1_MIN_LEN 2
2832 #define M1_MAX_LEN 2
2833 #define M2_MIN_LEN 3
2834 #ifndef M2_MAX_LEN
2835 #define M2_MAX_LEN 8
2836 #endif
2837 #define M3_MIN_LEN 3
2838 #define M3_MAX_LEN 33
2839 #define M4_MIN_LEN 3
2840 #define M4_MAX_LEN 9
2841
2842 #define M1_MARKER 0
2843 #define M2_MARKER 64
2844 #define M3_MARKER 32
2845 #define M4_MARKER 16
2846
2847 #ifndef MIN_LOOKAHEAD
2848 #define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
2849 #endif
2850
2851 #if defined(LZO_NEED_DICT_H)
2852
2853 #ifndef LZO_HASH
2854 #define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B
2855 #endif
2856 #define DL_MIN_LEN M2_MIN_LEN
2857
2858 #ifndef __LZO_DICT_H
2859 #define __LZO_DICT_H 1
2860
2861 #ifdef __cplusplus
2862 extern "C" {
2863 #endif
2864
2865 #if !defined(D_BITS) && defined(DBITS)
2866 # define D_BITS DBITS
2867 #endif
2868 #if !defined(D_BITS)
2869 # error "D_BITS is not defined"
2870 #endif
2871 #if (D_BITS < 16)
2872 # define D_SIZE LZO_SIZE(D_BITS)
2873 # define D_MASK LZO_MASK(D_BITS)
2874 #else
2875 # define D_SIZE LZO_USIZE(D_BITS)
2876 # define D_MASK LZO_UMASK(D_BITS)
2877 #endif
2878 #define D_HIGH ((D_MASK >> 1) + 1)
2879
2880 #if !defined(DD_BITS)
2881 # define DD_BITS 0
2882 #endif
2883 #define DD_SIZE LZO_SIZE(DD_BITS)
2884 #define DD_MASK LZO_MASK(DD_BITS)
2885
2886 #if !defined(DL_BITS)
2887 # define DL_BITS (D_BITS - DD_BITS)
2888 #endif
2889 #if (DL_BITS < 16)
2890 # define DL_SIZE LZO_SIZE(DL_BITS)
2891 # define DL_MASK LZO_MASK(DL_BITS)
2892 #else
2893 # define DL_SIZE LZO_USIZE(DL_BITS)
2894 # define DL_MASK LZO_UMASK(DL_BITS)
2895 #endif
2896
2897 #if (D_BITS != DL_BITS + DD_BITS)
2898 # error "D_BITS does not match"
2899 #endif
2900 #if (D_BITS < 6 || D_BITS > 18)
2901 # error "invalid D_BITS"
2902 #endif
2903 #if (DL_BITS < 6 || DL_BITS > 20)
2904 # error "invalid DL_BITS"
2905 #endif
2906 #if (DD_BITS < 0 || DD_BITS > 6)
2907 # error "invalid DD_BITS"
2908 #endif
2909
2910 #if !defined(DL_MIN_LEN)
2911 # define DL_MIN_LEN 3
2912 #endif
2913 #if !defined(DL_SHIFT)
2914 # define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
2915 #endif
2916
2917 #define LZO_HASH_GZIP 1
2918 #define LZO_HASH_GZIP_INCREMENTAL 2
2919 #define LZO_HASH_LZO_INCREMENTAL_A 3
2920 #define LZO_HASH_LZO_INCREMENTAL_B 4
2921
2922 #if !defined(LZO_HASH)
2923 # error "choose a hashing strategy"
2924 #endif
2925
2926 #undef DM
2927 #undef DX
2928
2929 #if (DL_MIN_LEN == 3)
2930 # define _DV2_A(p,shift1,shift2) \
2931 (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2])
2932 # define _DV2_B(p,shift1,shift2) \
2933 (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0])
2934 # define _DV3_B(p,shift1,shift2,shift3) \
2935 ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0])
2936 #elif (DL_MIN_LEN == 2)
2937 # define _DV2_A(p,shift1,shift2) \
2938 (( (lzo_xint)(p[0]) << shift1) ^ p[1])
2939 # define _DV2_B(p,shift1,shift2) \
2940 (( (lzo_xint)(p[1]) << shift1) ^ p[2])
2941 #else
2942 # error "invalid DL_MIN_LEN"
2943 #endif
2944 #define _DV_A(p,shift) _DV2_A(p,shift,shift)
2945 #define _DV_B(p,shift) _DV2_B(p,shift,shift)
2946 #define DA2(p,s1,s2) \
2947 (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0])
2948 #define DS2(p,s1,s2) \
2949 (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0])
2950 #define DX2(p,s1,s2) \
2951 (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
2952 #define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
2953 #define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
2954 #define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
2955 #define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s)))
2956 #define DM(v) DMS(v,0)
2957
2958 #if (LZO_HASH == LZO_HASH_GZIP)
2959 # define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT))
2960
2961 #elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
2962 # define __LZO_HASH_INCREMENTAL 1
2963 # define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT)
2964 # define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2])
2965 # define _DINDEX(dv,p) (dv)
2966 # define DVAL_LOOKAHEAD DL_MIN_LEN
2967
2968 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
2969 # define __LZO_HASH_INCREMENTAL 1
2970 # define DVAL_FIRST(dv,p) dv = _DV_A((p),5)
2971 # define DVAL_NEXT(dv,p) \
2972 dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
2973 # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
2974 # define DVAL_LOOKAHEAD DL_MIN_LEN
2975
2976 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
2977 # define __LZO_HASH_INCREMENTAL 1
2978 # define DVAL_FIRST(dv,p) dv = _DV_B((p),5)
2979 # define DVAL_NEXT(dv,p) \
2980 dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5)))
2981 # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
2982 # define DVAL_LOOKAHEAD DL_MIN_LEN
2983
2984 #else
2985 # error "choose a hashing strategy"
2986 #endif
2987
2988 #ifndef DINDEX
2989 #define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
2990 #endif
2991 #if !defined(DINDEX1) && defined(D_INDEX1)
2992 #define DINDEX1 D_INDEX1
2993 #endif
2994 #if !defined(DINDEX2) && defined(D_INDEX2)
2995 #define DINDEX2 D_INDEX2
2996 #endif
2997
2998 #if !defined(__LZO_HASH_INCREMENTAL)
2999 # define DVAL_FIRST(dv,p) ((void) 0)
3000 # define DVAL_NEXT(dv,p) ((void) 0)
3001 # define DVAL_LOOKAHEAD 0
3002 #endif
3003
3004 #if !defined(DVAL_ASSERT)
3005 #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
3006 #if (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_LLVM)
3007 static void __attribute__((__unused__))
3008 #else
3009 static void
3010 #endif
3011 DVAL_ASSERT(lzo_xint dv, const lzo_bytep p)
3012 {
3013 lzo_xint df;
3014 DVAL_FIRST(df,(p));
3015 assert(DINDEX(dv,p) == DINDEX(df,p));
3016 }
3017 #else
3018 # define DVAL_ASSERT(dv,p) ((void) 0)
3019 #endif
3020 #endif
3021
3022 #if (LZO_DICT_USE_PTR)
3023 # define DENTRY(p,in) (p)
3024 # define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
3025 #else
3026 # define DENTRY(p,in) ((lzo_dict_t) pd(p, in))
3027 # define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex]
3028 #endif
3029
3030 #if (DD_BITS == 0)
3031
3032 # define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in)
3033 # define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
3034 # define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in)
3035
3036 #else
3037
3038 # define UPDATE_D(dict,drun,dv,p,in) \
3039 dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
3040 # define UPDATE_I(dict,drun,index,p,in) \
3041 dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
3042 # define UPDATE_P(ptr,drun,p,in) \
3043 (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK
3044
3045 #endif
3046
3047 #if (LZO_DICT_USE_PTR)
3048
3049 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
3050 (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset)
3051
3052 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
3053 (BOUNDS_CHECKING_OFF_IN_EXPR(( \
3054 m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \
3055 PTR_LT(m_pos,in) || \
3056 (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \
3057 m_off > max_offset )))
3058
3059 #else
3060
3061 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
3062 (m_off == 0 || \
3063 ((m_off = pd(ip, in) - m_off) > max_offset) || \
3064 (m_pos = (ip) - (m_off), 0) )
3065
3066 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
3067 (pd(ip, in) <= m_off || \
3068 ((m_off = pd(ip, in) - m_off) > max_offset) || \
3069 (m_pos = (ip) - (m_off), 0) )
3070
3071 #endif
3072
3073 #if (LZO_DETERMINISTIC)
3074 # define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET
3075 #else
3076 # define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET
3077 #endif
3078
3079 #ifdef __cplusplus
3080 }
3081 #endif
3082
3083 #endif
3084
3085 #endif
3086
3087 #endif
3088
3089 #define LZO_DETERMINISTIC !(LZO_DICT_USE_PTR)
3090
3091 #ifndef DO_COMPRESS
3092 #define DO_COMPRESS lzo1x_1_compress
3093 #endif
3094
3095 #if 1 && defined(DO_COMPRESS) && !defined(do_compress)
3096 # define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core)
3097 #endif
3098
3099 #if defined(UA_GET64)
3100 # define WANT_lzo_bitops_ctz64 1
3101 #elif defined(UA_GET32)
3102 # define WANT_lzo_bitops_ctz32 1
3103 #endif
3104
3105 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
3106 #include <intrin.h>
3107 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
3108 #pragma intrinsic(_BitScanReverse)
3109 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
3110 {
3111 unsigned long r;
3112 (void) _BitScanReverse(&r, v);
3113 return (unsigned) r;
3114 }
3115 #define lzo_bitops_clz32 lzo_bitops_clz32
3116 #endif
3117 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
3118 #pragma intrinsic(_BitScanReverse64)
3119 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
3120 {
3121 unsigned long r;
3122 (void) _BitScanReverse64(&r, v);
3123 return (unsigned) r;
3124 }
3125 #define lzo_bitops_clz64 lzo_bitops_clz64
3126 #endif
3127 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
3128 #pragma intrinsic(_BitScanForward)
3129 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
3130 {
3131 unsigned long r;
3132 (void) _BitScanForward(&r, v);
3133 return (unsigned) r;
3134 }
3135 #define lzo_bitops_ctz32 lzo_bitops_ctz32
3136 #endif
3137 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
3138 #pragma intrinsic(_BitScanForward64)
3139 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
3140 {
3141 unsigned long r;
3142 (void) _BitScanForward64(&r, v);
3143 return (unsigned) r;
3144 }
3145 #define lzo_bitops_ctz64 lzo_bitops_ctz64
3146 #endif
3147
3148 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM)
3149 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
3150 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
3151 #endif
3152 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
3153 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
3154 #endif
3155 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
3156 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
3157 #endif
3158 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
3159 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
3160 #endif
3161 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
3162 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
3163 #endif
3164 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
3165 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))
3166 #endif
3167 #endif
3168
3169 static __lzo_noinline lzo_uint
3170 do_compress ( const lzo_bytep in , lzo_uint in_len,
3171 lzo_bytep out, lzo_uintp out_len,
3172 lzo_uint ti, lzo_voidp wrkmem)
3173 {
3174 register const lzo_bytep ip;
3175 lzo_bytep op;
3176 const lzo_bytep const in_end = in + in_len;
3177 const lzo_bytep const ip_end = in + in_len - 20;
3178 const lzo_bytep ii;
3179 lzo_dict_p const dict = (lzo_dict_p) wrkmem;
3180
3181 op = out;
3182 ip = in;
3183 ii = ip - ti;
3184
3185 ip += ti < 4 ? 4 - ti : 0;
3186 for (;;)
3187 {
3188 const lzo_bytep m_pos;
3189 #if !(LZO_DETERMINISTIC)
3190 LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
3191 lzo_uint m_len;
3192 lzo_uint dindex;
3193 next:
3194 if __lzo_unlikely(ip >= ip_end)
3195 break;
3196 DINDEX1(dindex,ip);
3197 GINDEX(m_pos,m_off,dict,dindex,in);
3198 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
3199 goto literal;
3200 #if 1
3201 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
3202 goto try_match;
3203 DINDEX2(dindex,ip);
3204 #endif
3205 GINDEX(m_pos,m_off,dict,dindex,in);
3206 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
3207 goto literal;
3208 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
3209 goto try_match;
3210 goto literal;
3211
3212 try_match:
3213 #if defined(UA_GET32)
3214 if (UA_GET32(m_pos) != UA_GET32(ip))
3215 #else
3216 if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
3217 #endif
3218 {
3219 literal:
3220 UPDATE_I(dict,0,dindex,ip,in);
3221 ip += 1 + ((ip - ii) >> 5);
3222 continue;
3223 }
3224 UPDATE_I(dict,0,dindex,ip,in);
3225 #else
3226 lzo_uint m_off;
3227 lzo_uint m_len;
3228 {
3229 lzo_uint32 dv;
3230 lzo_uint dindex;
3231 literal:
3232 ip += 1 + ((ip - ii) >> 5);
3233 next:
3234 if __lzo_unlikely(ip >= ip_end)
3235 break;
3236 dv = UA_GET32(ip);
3237 dindex = DINDEX(dv,ip);
3238 GINDEX(m_off,m_pos,in+dict,dindex,in);
3239 UPDATE_I(dict,0,dindex,ip,in);
3240 if __lzo_unlikely(dv != UA_GET32(m_pos))
3241 goto literal;
3242 }
3243 #endif
3244
3245 {
3246 register lzo_uint t = pd(ip,ii);
3247 if (t != 0)
3248 {
3249 if (t <= 3)
3250 {
3251 op[-2] |= LZO_BYTE(t);
3252 #if defined(UA_COPY32)
3253 UA_COPY32(op, ii);
3254 op += t;
3255 #else
3256 { do *op++ = *ii++; while (--t > 0); }
3257 #endif
3258 }
3259 #if defined(UA_COPY32) || defined(UA_COPY64)
3260 else if (t <= 16)
3261 {
3262 *op++ = LZO_BYTE(t - 3);
3263 #if defined(UA_COPY64)
3264 UA_COPY64(op, ii);
3265 UA_COPY64(op+8, ii+8);
3266 #else
3267 UA_COPY32(op, ii);
3268 UA_COPY32(op+4, ii+4);
3269 UA_COPY32(op+8, ii+8);
3270 UA_COPY32(op+12, ii+12);
3271 #endif
3272 op += t;
3273 }
3274 #endif
3275 else
3276 {
3277 if (t <= 18)
3278 *op++ = LZO_BYTE(t - 3);
3279 else
3280 {
3281 register lzo_uint tt = t - 18;
3282 *op++ = 0;
3283 while __lzo_unlikely(tt > 255)
3284 {
3285 tt -= 255;
3286 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3287 * (volatile unsigned char *) op++ = 0;
3288 #else
3289 *op++ = 0;
3290 #endif
3291 }
3292 assert(tt > 0);
3293 *op++ = LZO_BYTE(tt);
3294 }
3295 #if defined(UA_COPY32) || defined(UA_COPY64)
3296 do {
3297 #if defined(UA_COPY64)
3298 UA_COPY64(op, ii);
3299 UA_COPY64(op+8, ii+8);
3300 #else
3301 UA_COPY32(op, ii);
3302 UA_COPY32(op+4, ii+4);
3303 UA_COPY32(op+8, ii+8);
3304 UA_COPY32(op+12, ii+12);
3305 #endif
3306 op += 16; ii += 16; t -= 16;
3307 } while (t >= 16); if (t > 0)
3308 #endif
3309 { do *op++ = *ii++; while (--t > 0); }
3310 }
3311 }
3312 }
3313 m_len = 4;
3314 {
3315 #if defined(UA_GET64)
3316 lzo_uint64 v;
3317 v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len);
3318 if __lzo_unlikely(v == 0) {
3319 do {
3320 m_len += 8;
3321 v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len);
3322 if __lzo_unlikely(ip + m_len >= ip_end)
3323 goto m_len_done;
3324 } while (v == 0);
3325 }
3326 #if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64)
3327 m_len += lzo_bitops_ctz64(v) / CHAR_BIT;
3328 #elif (LZO_ABI_LITTLE_ENDIAN)
3329 if ((v & UCHAR_MAX) == 0) do {
3330 v >>= CHAR_BIT;
3331 m_len += 1;
3332 } while ((v & UCHAR_MAX) == 0);
3333 #else
3334 if (ip[m_len] == m_pos[m_len]) do {
3335 m_len += 1;
3336 } while (ip[m_len] == m_pos[m_len]);
3337 #endif
3338 #elif defined(UA_GET32)
3339 lzo_uint32 v;
3340 v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len);
3341 if __lzo_unlikely(v == 0) {
3342 do {
3343 m_len += 4;
3344 v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len);
3345 if __lzo_unlikely(ip + m_len >= ip_end)
3346 goto m_len_done;
3347 } while (v == 0);
3348 }
3349 #if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32)
3350 m_len += lzo_bitops_ctz32(v) / CHAR_BIT;
3351 #elif (LZO_ABI_LITTLE_ENDIAN)
3352 if ((v & UCHAR_MAX) == 0) do {
3353 v >>= CHAR_BIT;
3354 m_len += 1;
3355 } while ((v & UCHAR_MAX) == 0);
3356 #else
3357 if (ip[m_len] == m_pos[m_len]) do {
3358 m_len += 1;
3359 } while (ip[m_len] == m_pos[m_len]);
3360 #endif
3361 #else
3362 if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
3363 do {
3364 m_len += 1;
3365 if __lzo_unlikely(ip + m_len >= ip_end)
3366 goto m_len_done;
3367 } while (ip[m_len] == m_pos[m_len]);
3368 }
3369 #endif
3370 }
3371 m_len_done:
3372 m_off = pd(ip,m_pos);
3373 ip += m_len;
3374 ii = ip;
3375 if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
3376 {
3377 m_off -= 1;
3378 #if defined(LZO1X)
3379 *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
3380 *op++ = LZO_BYTE(m_off >> 3);
3381 #elif defined(LZO1Y)
3382 *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
3383 *op++ = LZO_BYTE(m_off >> 2);
3384 #endif
3385 }
3386 else if (m_off <= M3_MAX_OFFSET)
3387 {
3388 m_off -= 1;
3389 if (m_len <= M3_MAX_LEN)
3390 *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
3391 else
3392 {
3393 m_len -= M3_MAX_LEN;
3394 *op++ = M3_MARKER | 0;
3395 while __lzo_unlikely(m_len > 255)
3396 {
3397 m_len -= 255;
3398 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3399 * (volatile unsigned char *) op++ = 0;
3400 #else
3401 *op++ = 0;
3402 #endif
3403 }
3404 *op++ = LZO_BYTE(m_len);
3405 }
3406 *op++ = LZO_BYTE(m_off << 2);
3407 *op++ = LZO_BYTE(m_off >> 6);
3408 }
3409 else
3410 {
3411 m_off -= 0x4000;
3412 if (m_len <= M4_MAX_LEN)
3413 *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
3414 else
3415 {
3416 m_len -= M4_MAX_LEN;
3417 *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
3418 while __lzo_unlikely(m_len > 255)
3419 {
3420 m_len -= 255;
3421 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3422 * (volatile unsigned char *) op++ = 0;
3423 #else
3424 *op++ = 0;
3425 #endif
3426 }
3427 *op++ = LZO_BYTE(m_len);
3428 }
3429 *op++ = LZO_BYTE(m_off << 2);
3430 *op++ = LZO_BYTE(m_off >> 6);
3431 }
3432 goto next;
3433 }
3434
3435 *out_len = pd(op, out);
3436 return pd(in_end,ii);
3437 }
3438
3439 LZO_PUBLIC(int)
3440 DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len,
3441 lzo_bytep out, lzo_uintp out_len,
3442 lzo_voidp wrkmem )
3443 {
3444 const lzo_bytep ip = in;
3445 lzo_bytep op = out;
3446 lzo_uint l = in_len;
3447 lzo_uint t = 0;
3448
3449 while (l > 20)
3450 {
3451 lzo_uint ll = l;
3452 lzo_uintptr_t ll_end;
3453 #if 0 || (LZO_DETERMINISTIC)
3454 ll = LZO_MIN(ll, 49152);
3455 #endif
3456 ll_end = (lzo_uintptr_t)ip + ll;
3457 if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
3458 break;
3459 #if (LZO_DETERMINISTIC)
3460 lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
3461 #endif
3462 t = do_compress(ip,ll,op,out_len,t,wrkmem);
3463 ip += ll;
3464 op += *out_len;
3465 l -= ll;
3466 }
3467 t += l;
3468
3469 if (t > 0)
3470 {
3471 const lzo_bytep ii = in + in_len - t;
3472
3473 if (op == out && t <= 238)
3474 *op++ = LZO_BYTE(17 + t);
3475 else if (t <= 3)
3476 op[-2] |= LZO_BYTE(t);
3477 else if (t <= 18)
3478 *op++ = LZO_BYTE(t - 3);
3479 else
3480 {
3481 lzo_uint tt = t - 18;
3482
3483 *op++ = 0;
3484 while (tt > 255)
3485 {
3486 tt -= 255;
3487 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3488
3489 * (volatile unsigned char *) op++ = 0;
3490 #else
3491 *op++ = 0;
3492 #endif
3493 }
3494 assert(tt > 0);
3495 *op++ = LZO_BYTE(tt);
3496 }
3497 do *op++ = *ii++; while (--t > 0);
3498 }
3499
3500 *op++ = M4_MARKER | 1;
3501 *op++ = 0;
3502 *op++ = 0;
3503
3504 *out_len = pd(op, out);
3505 return LZO_E_OK;
3506 }
3507
3508 #endif
3509
3510 #undef do_compress
3511 #undef DO_COMPRESS
3512 #undef LZO_HASH
3513
3514 #undef LZO_TEST_OVERRUN
3515 #undef DO_DECOMPRESS
3516 #define DO_DECOMPRESS lzo1x_decompress
3517
3518 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS)
3519
3520 #if defined(LZO_TEST_OVERRUN)
3521 # if !defined(LZO_TEST_OVERRUN_INPUT)
3522 # define LZO_TEST_OVERRUN_INPUT 2
3523 # endif
3524 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
3525 # define LZO_TEST_OVERRUN_OUTPUT 2
3526 # endif
3527 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3528 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
3529 # endif
3530 #endif
3531
3532 #undef TEST_IP
3533 #undef TEST_OP
3534 #undef TEST_LB
3535 #undef TEST_LBO
3536 #undef NEED_IP
3537 #undef NEED_OP
3538 #undef HAVE_TEST_IP
3539 #undef HAVE_TEST_OP
3540 #undef HAVE_NEED_IP
3541 #undef HAVE_NEED_OP
3542 #undef HAVE_ANY_IP
3543 #undef HAVE_ANY_OP
3544
3545 #if defined(LZO_TEST_OVERRUN_INPUT)
3546 # if (LZO_TEST_OVERRUN_INPUT >= 1)
3547 # define TEST_IP (ip < ip_end)
3548 # endif
3549 # if (LZO_TEST_OVERRUN_INPUT >= 2)
3550 # define NEED_IP(x) \
3551 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
3552 # endif
3553 #endif
3554
3555 #if defined(LZO_TEST_OVERRUN_OUTPUT)
3556 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
3557 # define TEST_OP (op <= op_end)
3558 # endif
3559 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
3560 # undef TEST_OP
3561 # define NEED_OP(x) \
3562 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
3563 # endif
3564 #endif
3565
3566 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3567 # define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
3568 # define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
3569 #else
3570 # define TEST_LB(m_pos) ((void) 0)
3571 # define TEST_LBO(m_pos,o) ((void) 0)
3572 #endif
3573
3574 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
3575 # define TEST_IP (ip < ip_end)
3576 #endif
3577
3578 #if defined(TEST_IP)
3579 # define HAVE_TEST_IP 1
3580 #else
3581 # define TEST_IP 1
3582 #endif
3583 #if defined(TEST_OP)
3584 # define HAVE_TEST_OP 1
3585 #else
3586 # define TEST_OP 1
3587 #endif
3588
3589 #if defined(NEED_IP)
3590 # define HAVE_NEED_IP 1
3591 #else
3592 # define NEED_IP(x) ((void) 0)
3593 #endif
3594 #if defined(NEED_OP)
3595 # define HAVE_NEED_OP 1
3596 #else
3597 # define NEED_OP(x) ((void) 0)
3598 #endif
3599
3600 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
3601 # define HAVE_ANY_IP 1
3602 #endif
3603 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
3604 # define HAVE_ANY_OP 1
3605 #endif
3606
3607 #if defined(DO_DECOMPRESS)
3608 LZO_PUBLIC(int)
3609 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
3610 lzo_bytep out, lzo_uintp out_len,
3611 lzo_voidp wrkmem )
3612 #endif
3613 {
3614 register lzo_bytep op;
3615 register const lzo_bytep ip;
3616 register lzo_uint t;
3617 #if defined(COPY_DICT)
3618 lzo_uint m_off;
3619 const lzo_bytep dict_end;
3620 #else
3621 register const lzo_bytep m_pos;
3622 #endif
3623
3624 const lzo_bytep const ip_end = in + in_len;
3625 #if defined(HAVE_ANY_OP)
3626 lzo_bytep const op_end = out + *out_len;
3627 #endif
3628 #if defined(LZO1Z)
3629 lzo_uint last_m_off = 0;
3630 #endif
3631
3632 LZO_UNUSED(wrkmem);
3633
3634 #if defined(COPY_DICT)
3635 if (dict)
3636 {
3637 if (dict_len > M4_MAX_OFFSET)
3638 {
3639 dict += dict_len - M4_MAX_OFFSET;
3640 dict_len = M4_MAX_OFFSET;
3641 }
3642 dict_end = dict + dict_len;
3643 }
3644 else
3645 {
3646 dict_len = 0;
3647 dict_end = NULL;
3648 }
3649 #endif
3650
3651 *out_len = 0;
3652
3653 op = out;
3654 ip = in;
3655
3656 if (*ip > 17)
3657 {
3658 t = *ip++ - 17;
3659 if (t < 4)
3660 goto match_next;
3661 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
3662 do *op++ = *ip++; while (--t > 0);
3663 goto first_literal_run;
3664 }
3665
3666 while (TEST_IP && TEST_OP)
3667 {
3668 t = *ip++;
3669 if (t >= 16)
3670 goto match;
3671 if (t == 0)
3672 {
3673 NEED_IP(1);
3674 while (*ip == 0)
3675 {
3676 t += 255;
3677 ip++;
3678 NEED_IP(1);
3679 }
3680 t += 15 + *ip++;
3681 }
3682 assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
3683 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
3684 t += 3;
3685 if (t >= 8) do
3686 {
3687 UA_COPY64(op,ip);
3688 op += 8; ip += 8; t -= 8;
3689 } while (t >= 8);
3690 if (t >= 4)
3691 {
3692 UA_COPY32(op,ip);
3693 op += 4; ip += 4; t -= 4;
3694 }
3695 if (t > 0)
3696 {
3697 *op++ = *ip++;
3698 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
3699 }
3700 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3701 #if !defined(LZO_UNALIGNED_OK_4)
3702 if (PTR_ALIGNED2_4(op,ip))
3703 {
3704 #endif
3705 UA_COPY32(op,ip);
3706 op += 4; ip += 4;
3707 if (--t > 0)
3708 {
3709 if (t >= 4)
3710 {
3711 do {
3712 UA_COPY32(op,ip);
3713 op += 4; ip += 4; t -= 4;
3714 } while (t >= 4);
3715 if (t > 0) do *op++ = *ip++; while (--t > 0);
3716 }
3717 else
3718 do *op++ = *ip++; while (--t > 0);
3719 }
3720 #if !defined(LZO_UNALIGNED_OK_4)
3721 }
3722 else
3723 #endif
3724 #endif
3725 #if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8)
3726 {
3727 *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
3728 do *op++ = *ip++; while (--t > 0);
3729 }
3730 #endif
3731
3732 first_literal_run:
3733
3734 t = *ip++;
3735 if (t >= 16)
3736 goto match;
3737 #if defined(COPY_DICT)
3738 #if defined(LZO1Z)
3739 m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3740 last_m_off = m_off;
3741 #else
3742 m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
3743 #endif
3744 NEED_OP(3);
3745 t = 3; COPY_DICT(t,m_off)
3746 #else
3747 #if defined(LZO1Z)
3748 t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3749 m_pos = op - t;
3750 last_m_off = t;
3751 #else
3752 m_pos = op - (1 + M2_MAX_OFFSET);
3753 m_pos -= t >> 2;
3754 m_pos -= *ip++ << 2;
3755 #endif
3756 TEST_LB(m_pos); NEED_OP(3);
3757 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
3758 #endif
3759 goto match_done;
3760
3761 do {
3762 match:
3763 if (t >= 64)
3764 {
3765 #if defined(COPY_DICT)
3766 #if defined(LZO1X)
3767 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
3768 t = (t >> 5) - 1;
3769 #elif defined(LZO1Y)
3770 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
3771 t = (t >> 4) - 3;
3772 #elif defined(LZO1Z)
3773 m_off = t & 0x1f;
3774 if (m_off >= 0x1c)
3775 m_off = last_m_off;
3776 else
3777 {
3778 m_off = 1 + (m_off << 6) + (*ip++ >> 2);
3779 last_m_off = m_off;
3780 }
3781 t = (t >> 5) - 1;
3782 #endif
3783 #else
3784 #if defined(LZO1X)
3785 m_pos = op - 1;
3786 m_pos -= (t >> 2) & 7;
3787 m_pos -= *ip++ << 3;
3788 t = (t >> 5) - 1;
3789 #elif defined(LZO1Y)
3790 m_pos = op - 1;
3791 m_pos -= (t >> 2) & 3;
3792 m_pos -= *ip++ << 2;
3793 t = (t >> 4) - 3;
3794 #elif defined(LZO1Z)
3795 {
3796 lzo_uint off = t & 0x1f;
3797 m_pos = op;
3798 if (off >= 0x1c)
3799 {
3800 assert(last_m_off > 0);
3801 m_pos -= last_m_off;
3802 }
3803 else
3804 {
3805 off = 1 + (off << 6) + (*ip++ >> 2);
3806 m_pos -= off;
3807 last_m_off = off;
3808 }
3809 }
3810 t = (t >> 5) - 1;
3811 #endif
3812 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3813 goto copy_match;
3814 #endif
3815 }
3816 else if (t >= 32)
3817 {
3818 t &= 31;
3819 if (t == 0)
3820 {
3821 NEED_IP(1);
3822 while (*ip == 0)
3823 {
3824 t += 255;
3825 ip++;
3826 NEED_IP(1);
3827 }
3828 t += 31 + *ip++;
3829 }
3830 #if defined(COPY_DICT)
3831 #if defined(LZO1Z)
3832 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3833 last_m_off = m_off;
3834 #else
3835 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
3836 #endif
3837 #else
3838 #if defined(LZO1Z)
3839 {
3840 lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3841 m_pos = op - off;
3842 last_m_off = off;
3843 }
3844 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3845 m_pos = op - 1;
3846 m_pos -= UA_GET16(ip) >> 2;
3847 #else
3848 m_pos = op - 1;
3849 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3850 #endif
3851 #endif
3852 ip += 2;
3853 }
3854 else if (t >= 16)
3855 {
3856 #if defined(COPY_DICT)
3857 m_off = (t & 8) << 11;
3858 #else
3859 m_pos = op;
3860 m_pos -= (t & 8) << 11;
3861 #endif
3862 t &= 7;
3863 if (t == 0)
3864 {
3865 NEED_IP(1);
3866 while (*ip == 0)
3867 {
3868 t += 255;
3869 ip++;
3870 NEED_IP(1);
3871 }
3872 t += 7 + *ip++;
3873 }
3874 #if defined(COPY_DICT)
3875 #if defined(LZO1Z)
3876 m_off += (ip[0] << 6) + (ip[1] >> 2);
3877 #else
3878 m_off += (ip[0] >> 2) + (ip[1] << 6);
3879 #endif
3880 ip += 2;
3881 if (m_off == 0)
3882 goto eof_found;
3883 m_off += 0x4000;
3884 #if defined(LZO1Z)
3885 last_m_off = m_off;
3886 #endif
3887 #else
3888 #if defined(LZO1Z)
3889 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
3890 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3891 m_pos -= UA_GET16(ip) >> 2;
3892 #else
3893 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3894 #endif
3895 ip += 2;
3896 if (m_pos == op)
3897 goto eof_found;
3898 m_pos -= 0x4000;
3899 #if defined(LZO1Z)
3900 last_m_off = pd((const lzo_bytep)op, m_pos);
3901 #endif
3902 #endif
3903 }
3904 else
3905 {
3906 #if defined(COPY_DICT)
3907 #if defined(LZO1Z)
3908 m_off = 1 + (t << 6) + (*ip++ >> 2);
3909 last_m_off = m_off;
3910 #else
3911 m_off = 1 + (t >> 2) + (*ip++ << 2);
3912 #endif
3913 NEED_OP(2);
3914 t = 2; COPY_DICT(t,m_off)
3915 #else
3916 #if defined(LZO1Z)
3917 t = 1 + (t << 6) + (*ip++ >> 2);
3918 m_pos = op - t;
3919 last_m_off = t;
3920 #else
3921 m_pos = op - 1;
3922 m_pos -= t >> 2;
3923 m_pos -= *ip++ << 2;
3924 #endif
3925 TEST_LB(m_pos); NEED_OP(2);
3926 *op++ = *m_pos++; *op++ = *m_pos;
3927 #endif
3928 goto match_done;
3929 }
3930
3931 #if defined(COPY_DICT)
3932
3933 NEED_OP(t+3-1);
3934 t += 3-1; COPY_DICT(t,m_off)
3935
3936 #else
3937
3938 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3939 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
3940 if (op - m_pos >= 8)
3941 {
3942 t += (3 - 1);
3943 if (t >= 8) do
3944 {
3945 UA_COPY64(op,m_pos);
3946 op += 8; m_pos += 8; t -= 8;
3947 } while (t >= 8);
3948 if (t >= 4)
3949 {
3950 UA_COPY32(op,m_pos);
3951 op += 4; m_pos += 4; t -= 4;
3952 }
3953 if (t > 0)
3954 {
3955 *op++ = m_pos[0];
3956 if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
3957 }
3958 }
3959 else
3960 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3961 #if !defined(LZO_UNALIGNED_OK_4)
3962 if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
3963 {
3964 assert((op - m_pos) >= 4);
3965 #else
3966 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
3967 {
3968 #endif
3969 UA_COPY32(op,m_pos);
3970 op += 4; m_pos += 4; t -= 4 - (3 - 1);
3971 do {
3972 UA_COPY32(op,m_pos);
3973 op += 4; m_pos += 4; t -= 4;
3974 } while (t >= 4);
3975 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
3976 }
3977 else
3978 #endif
3979 {
3980 copy_match:
3981 *op++ = *m_pos++; *op++ = *m_pos++;
3982 do *op++ = *m_pos++; while (--t > 0);
3983 }
3984
3985 #endif
3986
3987 match_done:
3988 #if defined(LZO1Z)
3989 t = ip[-1] & 3;
3990 #else
3991 t = ip[-2] & 3;
3992 #endif
3993 if (t == 0)
3994 break;
3995
3996 match_next:
3997 assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
3998 #if 0
3999 do *op++ = *ip++; while (--t > 0);
4000 #else
4001 *op++ = *ip++;
4002 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4003 #endif
4004 t = *ip++;
4005 } while (TEST_IP && TEST_OP);
4006 }
4007
4008 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
4009 *out_len = pd(op, out);
4010 return LZO_E_EOF_NOT_FOUND;
4011 #endif
4012
4013 eof_found:
4014 assert(t == 1);
4015 *out_len = pd(op, out);
4016 return (ip == ip_end ? LZO_E_OK :
4017 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
4018
4019 #if defined(HAVE_NEED_IP)
4020 input_overrun:
4021 *out_len = pd(op, out);
4022 return LZO_E_INPUT_OVERRUN;
4023 #endif
4024
4025 #if defined(HAVE_NEED_OP)
4026 output_overrun:
4027 *out_len = pd(op, out);
4028 return LZO_E_OUTPUT_OVERRUN;
4029 #endif
4030
4031 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4032 lookbehind_overrun:
4033 *out_len = pd(op, out);
4034 return LZO_E_LOOKBEHIND_OVERRUN;
4035 #endif
4036 }
4037
4038 #endif
4039
4040 #define LZO_TEST_OVERRUN 1
4041 #undef DO_DECOMPRESS
4042 #define DO_DECOMPRESS lzo1x_decompress_safe
4043
4044 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE)
4045
4046 #if defined(LZO_TEST_OVERRUN)
4047 # if !defined(LZO_TEST_OVERRUN_INPUT)
4048 # define LZO_TEST_OVERRUN_INPUT 2
4049 # endif
4050 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
4051 # define LZO_TEST_OVERRUN_OUTPUT 2
4052 # endif
4053 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4054 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
4055 # endif
4056 #endif
4057
4058 #undef TEST_IP
4059 #undef TEST_OP
4060 #undef TEST_LB
4061 #undef TEST_LBO
4062 #undef NEED_IP
4063 #undef NEED_OP
4064 #undef HAVE_TEST_IP
4065 #undef HAVE_TEST_OP
4066 #undef HAVE_NEED_IP
4067 #undef HAVE_NEED_OP
4068 #undef HAVE_ANY_IP
4069 #undef HAVE_ANY_OP
4070
4071 #if defined(LZO_TEST_OVERRUN_INPUT)
4072 # if (LZO_TEST_OVERRUN_INPUT >= 1)
4073 # define TEST_IP (ip < ip_end)
4074 # endif
4075 # if (LZO_TEST_OVERRUN_INPUT >= 2)
4076 # define NEED_IP(x) \
4077 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
4078 # endif
4079 #endif
4080
4081 #if defined(LZO_TEST_OVERRUN_OUTPUT)
4082 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
4083 # define TEST_OP (op <= op_end)
4084 # endif
4085 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
4086 # undef TEST_OP
4087 # define NEED_OP(x) \
4088 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
4089 # endif
4090 #endif
4091
4092 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4093 # define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
4094 # define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
4095 #else
4096 # define TEST_LB(m_pos) ((void) 0)
4097 # define TEST_LBO(m_pos,o) ((void) 0)
4098 #endif
4099
4100 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
4101 # define TEST_IP (ip < ip_end)
4102 #endif
4103
4104 #if defined(TEST_IP)
4105 # define HAVE_TEST_IP 1
4106 #else
4107 # define TEST_IP 1
4108 #endif
4109 #if defined(TEST_OP)
4110 # define HAVE_TEST_OP 1
4111 #else
4112 # define TEST_OP 1
4113 #endif
4114
4115 #if defined(NEED_IP)
4116 # define HAVE_NEED_IP 1
4117 #else
4118 # define NEED_IP(x) ((void) 0)
4119 #endif
4120 #if defined(NEED_OP)
4121 # define HAVE_NEED_OP 1
4122 #else
4123 # define NEED_OP(x) ((void) 0)
4124 #endif
4125
4126 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
4127 # define HAVE_ANY_IP 1
4128 #endif
4129 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
4130 # define HAVE_ANY_OP 1
4131 #endif
4132
4133 #if defined(DO_DECOMPRESS)
4134 LZO_PUBLIC(int)
4135 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
4136 lzo_bytep out, lzo_uintp out_len,
4137 lzo_voidp wrkmem )
4138 #endif
4139 {
4140 register lzo_bytep op;
4141 register const lzo_bytep ip;
4142 register lzo_uint t;
4143 #if defined(COPY_DICT)
4144 lzo_uint m_off;
4145 const lzo_bytep dict_end;
4146 #else
4147 register const lzo_bytep m_pos;
4148 #endif
4149
4150 const lzo_bytep const ip_end = in + in_len;
4151 #if defined(HAVE_ANY_OP)
4152 lzo_bytep const op_end = out + *out_len;
4153 #endif
4154 #if defined(LZO1Z)
4155 lzo_uint last_m_off = 0;
4156 #endif
4157
4158 LZO_UNUSED(wrkmem);
4159
4160 #if defined(COPY_DICT)
4161 if (dict)
4162 {
4163 if (dict_len > M4_MAX_OFFSET)
4164 {
4165 dict += dict_len - M4_MAX_OFFSET;
4166 dict_len = M4_MAX_OFFSET;
4167 }
4168 dict_end = dict + dict_len;
4169 }
4170 else
4171 {
4172 dict_len = 0;
4173 dict_end = NULL;
4174 }
4175 #endif
4176
4177 *out_len = 0;
4178
4179 op = out;
4180 ip = in;
4181
4182 if (*ip > 17)
4183 {
4184 t = *ip++ - 17;
4185 if (t < 4)
4186 goto match_next;
4187 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
4188 do *op++ = *ip++; while (--t > 0);
4189 goto first_literal_run;
4190 }
4191
4192 while (TEST_IP && TEST_OP)
4193 {
4194 t = *ip++;
4195 if (t >= 16)
4196 goto match;
4197 if (t == 0)
4198 {
4199 NEED_IP(1);
4200 while (*ip == 0)
4201 {
4202 t += 255;
4203 ip++;
4204 NEED_IP(1);
4205 }
4206 t += 15 + *ip++;
4207 }
4208 assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
4209 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
4210 t += 3;
4211 if (t >= 8) do
4212 {
4213 UA_COPY64(op,ip);
4214 op += 8; ip += 8; t -= 8;
4215 } while (t >= 8);
4216 if (t >= 4)
4217 {
4218 UA_COPY32(op,ip);
4219 op += 4; ip += 4; t -= 4;
4220 }
4221 if (t > 0)
4222 {
4223 *op++ = *ip++;
4224 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4225 }
4226 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
4227 #if !defined(LZO_UNALIGNED_OK_4)
4228 if (PTR_ALIGNED2_4(op,ip))
4229 {
4230 #endif
4231 UA_COPY32(op,ip);
4232 op += 4; ip += 4;
4233 if (--t > 0)
4234 {
4235 if (t >= 4)
4236 {
4237 do {
4238 UA_COPY32(op,ip);
4239 op += 4; ip += 4; t -= 4;
4240 } while (t >= 4);
4241 if (t > 0) do *op++ = *ip++; while (--t > 0);
4242 }
4243 else
4244 do *op++ = *ip++; while (--t > 0);
4245 }
4246 #if !defined(LZO_UNALIGNED_OK_4)
4247 }
4248 else
4249 #endif
4250 #endif
4251 #if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8)
4252 {
4253 *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
4254 do *op++ = *ip++; while (--t > 0);
4255 }
4256 #endif
4257
4258 first_literal_run:
4259
4260 t = *ip++;
4261 if (t >= 16)
4262 goto match;
4263 #if defined(COPY_DICT)
4264 #if defined(LZO1Z)
4265 m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
4266 last_m_off = m_off;
4267 #else
4268 m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
4269 #endif
4270 NEED_OP(3);
4271 t = 3; COPY_DICT(t,m_off)
4272 #else
4273 #if defined(LZO1Z)
4274 t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
4275 m_pos = op - t;
4276 last_m_off = t;
4277 #else
4278 m_pos = op - (1 + M2_MAX_OFFSET);
4279 m_pos -= t >> 2;
4280 m_pos -= *ip++ << 2;
4281 #endif
4282 TEST_LB(m_pos); NEED_OP(3);
4283 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
4284 #endif
4285 goto match_done;
4286
4287 do {
4288 match:
4289 if (t >= 64)
4290 {
4291 #if defined(COPY_DICT)
4292 #if defined(LZO1X)
4293 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
4294 t = (t >> 5) - 1;
4295 #elif defined(LZO1Y)
4296 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
4297 t = (t >> 4) - 3;
4298 #elif defined(LZO1Z)
4299 m_off = t & 0x1f;
4300 if (m_off >= 0x1c)
4301 m_off = last_m_off;
4302 else
4303 {
4304 m_off = 1 + (m_off << 6) + (*ip++ >> 2);
4305 last_m_off = m_off;
4306 }
4307 t = (t >> 5) - 1;
4308 #endif
4309 #else
4310 #if defined(LZO1X)
4311 m_pos = op - 1;
4312 m_pos -= (t >> 2) & 7;
4313 m_pos -= *ip++ << 3;
4314 t = (t >> 5) - 1;
4315 #elif defined(LZO1Y)
4316 m_pos = op - 1;
4317 m_pos -= (t >> 2) & 3;
4318 m_pos -= *ip++ << 2;
4319 t = (t >> 4) - 3;
4320 #elif defined(LZO1Z)
4321 {
4322 lzo_uint off = t & 0x1f;
4323 m_pos = op;
4324 if (off >= 0x1c)
4325 {
4326 assert(last_m_off > 0);
4327 m_pos -= last_m_off;
4328 }
4329 else
4330 {
4331 off = 1 + (off << 6) + (*ip++ >> 2);
4332 m_pos -= off;
4333 last_m_off = off;
4334 }
4335 }
4336 t = (t >> 5) - 1;
4337 #endif
4338 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
4339 goto copy_match;
4340 #endif
4341 }
4342 else if (t >= 32)
4343 {
4344 t &= 31;
4345 if (t == 0)
4346 {
4347 NEED_IP(1);
4348 while (*ip == 0)
4349 {
4350 t += 255;
4351 ip++;
4352 NEED_IP(1);
4353 }
4354 t += 31 + *ip++;
4355 }
4356 #if defined(COPY_DICT)
4357 #if defined(LZO1Z)
4358 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
4359 last_m_off = m_off;
4360 #else
4361 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
4362 #endif
4363 #else
4364 #if defined(LZO1Z)
4365 {
4366 lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
4367 m_pos = op - off;
4368 last_m_off = off;
4369 }
4370 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
4371 m_pos = op - 1;
4372 m_pos -= UA_GET16(ip) >> 2;
4373 #else
4374 m_pos = op - 1;
4375 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
4376 #endif
4377 #endif
4378 ip += 2;
4379 }
4380 else if (t >= 16)
4381 {
4382 #if defined(COPY_DICT)
4383 m_off = (t & 8) << 11;
4384 #else
4385 m_pos = op;
4386 m_pos -= (t & 8) << 11;
4387 #endif
4388 t &= 7;
4389 if (t == 0)
4390 {
4391 NEED_IP(1);
4392 while (*ip == 0)
4393 {
4394 t += 255;
4395 ip++;
4396 NEED_IP(1);
4397 }
4398 t += 7 + *ip++;
4399 }
4400 #if defined(COPY_DICT)
4401 #if defined(LZO1Z)
4402 m_off += (ip[0] << 6) + (ip[1] >> 2);
4403 #else
4404 m_off += (ip[0] >> 2) + (ip[1] << 6);
4405 #endif
4406 ip += 2;
4407 if (m_off == 0)
4408 goto eof_found;
4409 m_off += 0x4000;
4410 #if defined(LZO1Z)
4411 last_m_off = m_off;
4412 #endif
4413 #else
4414 #if defined(LZO1Z)
4415 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
4416 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
4417 m_pos -= UA_GET16(ip) >> 2;
4418 #else
4419 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
4420 #endif
4421 ip += 2;
4422 if (m_pos == op)
4423 goto eof_found;
4424 m_pos -= 0x4000;
4425 #if defined(LZO1Z)
4426 last_m_off = pd((const lzo_bytep)op, m_pos);
4427 #endif
4428 #endif
4429 }
4430 else
4431 {
4432 #if defined(COPY_DICT)
4433 #if defined(LZO1Z)
4434 m_off = 1 + (t << 6) + (*ip++ >> 2);
4435 last_m_off = m_off;
4436 #else
4437 m_off = 1 + (t >> 2) + (*ip++ << 2);
4438 #endif
4439 NEED_OP(2);
4440 t = 2; COPY_DICT(t,m_off)
4441 #else
4442 #if defined(LZO1Z)
4443 t = 1 + (t << 6) + (*ip++ >> 2);
4444 m_pos = op - t;
4445 last_m_off = t;
4446 #else
4447 m_pos = op - 1;
4448 m_pos -= t >> 2;
4449 m_pos -= *ip++ << 2;
4450 #endif
4451 TEST_LB(m_pos); NEED_OP(2);
4452 *op++ = *m_pos++; *op++ = *m_pos;
4453 #endif
4454 goto match_done;
4455 }
4456
4457 #if defined(COPY_DICT)
4458
4459 NEED_OP(t+3-1);
4460 t += 3-1; COPY_DICT(t,m_off)
4461
4462 #else
4463
4464 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
4465 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
4466 if (op - m_pos >= 8)
4467 {
4468 t += (3 - 1);
4469 if (t >= 8) do
4470 {
4471 UA_COPY64(op,m_pos);
4472 op += 8; m_pos += 8; t -= 8;
4473 } while (t >= 8);
4474 if (t >= 4)
4475 {
4476 UA_COPY32(op,m_pos);
4477 op += 4; m_pos += 4; t -= 4;
4478 }
4479 if (t > 0)
4480 {
4481 *op++ = m_pos[0];
4482 if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
4483 }
4484 }
4485 else
4486 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
4487 #if !defined(LZO_UNALIGNED_OK_4)
4488 if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
4489 {
4490 assert((op - m_pos) >= 4);
4491 #else
4492 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
4493 {
4494 #endif
4495 UA_COPY32(op,m_pos);
4496 op += 4; m_pos += 4; t -= 4 - (3 - 1);
4497 do {
4498 UA_COPY32(op,m_pos);
4499 op += 4; m_pos += 4; t -= 4;
4500 } while (t >= 4);
4501 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
4502 }
4503 else
4504 #endif
4505 {
4506 copy_match:
4507 *op++ = *m_pos++; *op++ = *m_pos++;
4508 do *op++ = *m_pos++; while (--t > 0);
4509 }
4510
4511 #endif
4512
4513 match_done:
4514 #if defined(LZO1Z)
4515 t = ip[-1] & 3;
4516 #else
4517 t = ip[-2] & 3;
4518 #endif
4519 if (t == 0)
4520 break;
4521
4522 match_next:
4523 assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
4524 #if 0
4525 do *op++ = *ip++; while (--t > 0);
4526 #else
4527 *op++ = *ip++;
4528 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4529 #endif
4530 t = *ip++;
4531 } while (TEST_IP && TEST_OP);
4532 }
4533
4534 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
4535 *out_len = pd(op, out);
4536 return LZO_E_EOF_NOT_FOUND;
4537 #endif
4538
4539 eof_found:
4540 assert(t == 1);
4541 *out_len = pd(op, out);
4542 return (ip == ip_end ? LZO_E_OK :
4543 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
4544
4545 #if defined(HAVE_NEED_IP)
4546 input_overrun:
4547 *out_len = pd(op, out);
4548 return LZO_E_INPUT_OVERRUN;
4549 #endif
4550
4551 #if defined(HAVE_NEED_OP)
4552 output_overrun:
4553 *out_len = pd(op, out);
4554 return LZO_E_OUTPUT_OVERRUN;
4555 #endif
4556
4557 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4558 lookbehind_overrun:
4559 *out_len = pd(op, out);
4560 return LZO_E_LOOKBEHIND_OVERRUN;
4561 #endif
4562 }
4563
4564 #endif
4565
4566 /***** End of minilzo.c *****/
4567