162 Commits
1.1.0 ... net

Author SHA1 Message Date
a411b1084c Add WSA initializer to handle winderp 2015-10-27 08:51:38 -07:00
7c4d0bb6fd Implement base Socket class
Fix derp in IPAddress::resolve
2015-10-27 08:47:07 -07:00
9e7733eb02 Initial networking 2015-10-27 06:49:25 -07:00
Jack Andersen
f46edcd4b8 Merge branch 'master' of https://github.com/libAthena/Athena 2015-10-23 12:23:46 -10:00
Jack Andersen
21724766ba added file handle accessor for file reader/writer 2015-10-23 12:23:04 -10:00
1601abcc7a Enable C++14 2015-10-19 18:12:32 -07:00
Jack Andersen
e861691480 Merge pull request #38 from libAthena/binary-size
Added binarySize method for DNA
2015-10-17 18:16:51 -10:00
Jack Andersen
7f5abb6849 Branch tweak 2015-10-17 18:15:42 -10:00
Jack Andersen
8221d6e25a Added binarySize method for DNA 2015-10-17 18:05:35 -10:00
8124d219d9 Fix utility::vsprintf
Fix operator>> (I'm a derp)
2015-10-16 17:25:36 -07:00
1b67cce607 Fix fno-exceptions 2015-10-16 16:42:23 -07:00
b9d79a9581 Remove exmaple from CMakeLists.txt 2015-10-16 13:20:05 -07:00
1ee7c82d8b Fix GC/Wii linker error
Add example program (Currently only targets wii)
2015-10-16 02:46:18 -07:00
8e8135370e Fix largefilewrapper for GC/Wii 2015-10-16 01:17:22 -07:00
1c0c44938e Fix gc/wii build 2015-10-16 01:07:54 -07:00
340588db62 Merge branch 'master' of https://github.com/libAthena/Athena 2015-10-16 00:17:47 -07:00
Jack Andersen
ffca1f1897 writeVal not a template function 2015-10-15 17:06:12 -10:00
25de226e65 Merge pull request #37 from libAthena/atdna-atvec
Implement atVec*d for atdna
2015-10-15 15:44:58 -07:00
Phillip Stephens
a753c2e38a Add operator>> to IStreamWriter.hpp 2015-10-15 15:20:50 -07:00
Phillip Stephens
069840a77e Implement atVec*d for atdna 2015-10-15 14:54:42 -07:00
Jack Andersen
418f3e763f OS X fixes 2015-10-11 19:17:39 -10:00
Jack Andersen
e6dedd0e6c Added double vector types 2015-10-07 13:50:50 -10:00
Jack Andersen
f4716070dd Added built-in DNAType field for YAML classification 2015-09-30 14:37:54 -10:00
Jack Andersen
a999744ab6 removed implementation-reliant use of emplace_back 2015-09-27 11:17:11 -10:00
Jack Andersen
4eae909848 Extended bool with endian readers/writers 2015-09-24 14:57:37 -10:00
3d90c14795 Fix subrecord arrays 2015-09-24 00:43:59 -07:00
0762a3bdcc FreeBSD Fixes 2015-09-12 10:25:58 -08:00
Jack Andersen
574038a826 Merge commit '9535' 2015-09-11 13:28:23 -10:00
Jack Andersen
9535778932 added Little/Big suffix method for at[U]Int8 types for consistency 2015-09-11 13:27:28 -10:00
Jack Andersen
89fa92308f Doc updates 2015-09-07 17:02:58 -10:00
1e1adeb2fb Merge pull request #36 from libAthena/gplremoval
Remove GPL comments from Athena codebase
2015-09-03 13:31:56 -07:00
c241158c7b Remove GPL comments from Athena codebase 2015-09-03 13:05:08 -07:00
4c7280e024 Remove GPL comments from Athena codebase 2015-09-03 12:37:45 -07:00
Jack Andersen
4ffce2dbc3 forced lzo to link statically on OS X 2015-09-02 18:27:12 -10:00
Jack Andersen
a16fd79838 OS X support for atdna macro; dependency resolution fix 2015-09-02 08:49:23 -10:00
Jack Andersen
4a4962424d Corrected a windows-specific API warning 2015-08-31 11:49:33 -10:00
Jack Andersen
bca146dbfc stripped-down utf8proc added 2015-08-31 11:11:42 -10:00
Jack Andersen
9c44d5f4de Merge pull request #32 from libAthena/utf8-windows
windows fixes and proper UTF-8 conversion
2015-08-30 19:32:32 -10:00
0de254e846 Fix remaining MESSAGE enums 2015-08-30 22:15:06 -07:00
Jack Andersen
e52e9f8dc4 Win32 Macro fixes 2015-08-30 22:13:07 -07:00
Jack Andersen
9b6fea36e3 windows fixes and proper UTF-8 conversion 2015-08-30 22:13:07 -07:00
1de67f30b8 * Removal of remaining exceptions 2015-08-29 01:34:22 -07:00
Jack Andersen
4d13caeaab Merge pull request #31 from libAthena/codecvt-removal
removed codecvt headers
2015-08-24 20:53:43 -10:00
Jack Andersen
66cb6c982e removed codecvt headers 2015-08-24 20:48:53 -10:00
Jack Andersen
92898661cc Merge pull request #28 from libAthena/ownership-flag
Added ownership flag for memory reader
2015-08-23 13:55:22 -10:00
Jack Andersen
a145f337c0 Added ownership flag for memory reader 2015-08-23 13:52:01 -10:00
Jack Andersen
b664c7df8f added casts for proper enum conversion 2015-08-20 12:23:19 -10:00
Jack Andersen
9655cb41d1 Added support for enums in Value<> 2015-08-20 11:57:20 -10:00
7464c8e5eb add optional mask parameter to crc32 2015-08-17 02:32:03 -07:00
Jack Andersen
d9b7151487 remade PKGBUILD as PKGBUILD.in (configured by CMake) 2015-08-13 17:21:49 -10:00
Jack Andersen
776d52e4e5 Merge pull request #27 from libAthena/explicit-endian
Added explicit Big/Little method suffix
2015-08-13 17:10:56 -10:00
Jack Andersen
13d545c3fd Added explicit Big/Little method suffix 2015-08-13 16:58:04 -10:00
Jack Andersen
dac1dde468 accumulator type change 2015-08-11 13:32:57 -10:00
Jack Andersen
f49a6a6e82 Added YAML child node finder 2015-08-08 18:15:07 -10:00
Jack Andersen
2e240520e1 Merge pull request #26 from libAthena/sfinae
Added some SFINAE parameters for smart IO templates
2015-08-08 13:44:14 -10:00
Jack Andersen
9f0cb1327b Added some SFINAE parameters for smart IO templates 2015-08-08 13:25:18 -10:00
Jack Andersen
9ed090b126 Merge pull request #25 from libAthena/smart-ptrs
Refactored readBytes() and readUBytes() to return std::unique_ptr
2015-08-05 12:58:32 -10:00
Jack Andersen
02e7bb3fc6 Refactored readBytes() and readUBytes() to return std::unique_ptr 2015-08-05 12:41:06 -10:00
Jack Andersen
f06afb429c Windows build fixes 2015-08-03 17:42:44 -10:00
Jack Andersen
3d220841c0 version macro fix 2015-08-02 15:47:09 -10:00
Jack Andersen
7a90a0f6d0 Embedded atdna in Athena 2015-08-02 15:42:47 -10:00
Jack Andersen
3edc800e10 Bumped version to 2.3.0 2015-08-02 18:29:39 -07:00
Jack Andersen
84591d4260 Added YAML serialization DNA subclass 2015-08-02 18:29:39 -07:00
Jack Andersen
43c317529c AES optimization and aligned SSE allocators 2015-08-02 18:29:39 -07:00
Jack Andersen
b38d7533c5 Exception args should be passed as c-string
(it's a compiled literal after-all)
2015-08-02 18:29:39 -07:00
Jack Andersen
b7d4c51979 more precise MSVC specification 2015-08-02 18:29:38 -07:00
Jack Andersen
ac36bb4f4a added support for wchar_t file paths and more stable windows builds 2015-08-02 18:29:38 -07:00
Jack Andersen
8e5e4d7603 Bumped CMake package to 2.2.0 2015-08-02 18:29:38 -07:00
d9c4d3b79b Add error state 2015-08-02 18:29:38 -07:00
8ea5071e0f Remove and replace exceptions 2015-08-02 18:29:38 -07:00
Jack Andersen
602f6b6e15 bumped version to 2.1.0 2015-07-21 09:32:11 -10:00
Jack Andersen
78286b0f67 corrected type mismatch 2015-07-21 09:26:02 -10:00
Jack Andersen
c6a6d3b9c4 renamed read/writeUnicode methods to be more reflective of functionality 2015-07-21 09:04:25 -10:00
Jack Andersen
6405bffdd2 Un-derpified major derp 2015-07-19 17:48:44 -10:00
Jack Andersen
7442d618e7 Added virtual destructor to IAES 2015-07-15 16:01:37 -10:00
Jack Andersen
f3ba8819a4 fixed incomplete-type warnings involving recursively-derived DNA types 2015-07-14 12:57:42 -10:00
Jack Andersen
24fedff58e specified release build for PKGBUILD 2015-07-14 10:47:00 -10:00
Jack Andersen
87306a18d8 minor AES optimization 2015-07-13 16:23:36 -10:00
Jack Andersen
09e3d33ff2 spelling corrections 2015-07-13 14:39:51 -10:00
Jack Andersen
11331e068e restored c++ abi to system default 2015-07-12 08:06:07 -10:00
Jack Andersen
7ec5a5971a compile-time system endian check 2015-07-12 06:51:04 -10:00
Jack Andersen
7ef451c86a Merge branch 'master' of https://github.com/libAthena/Athena 2015-07-11 20:05:37 -10:00
Jack Andersen
ece50c6968 forced c++ abi to c++11 2015-07-11 20:05:16 -10:00
4bc6004a6a Prevent CMake from failing if an empty atdna directory exists 2015-07-11 16:01:01 -07:00
Jack Andersen
55adeec69c windows packaging and CMake adjustments 2015-07-10 16:14:06 -10:00
4f8df65a3d * add atVec2f 2015-07-10 18:45:26 -07:00
8d3524b1f6 Fix sign bug
Prevent blockSize from exceeding file's length
2015-07-09 20:47:56 -07:00
a7c180db00 * Add support for cached reads 2015-07-09 20:32:55 -07:00
Jack Andersen
a19dcad876 corrected include path for CMake export 2015-07-08 16:09:57 -10:00
Jack Andersen
3ce2062686 removed unnecessary header glob 2015-07-08 15:50:16 -10:00
Jack Andersen
f874dfff31 removed qt files 2015-07-08 15:41:51 -10:00
Jack Andersen
e45679ffba PKGBUILD fix 2015-07-08 15:29:08 -10:00
Jack Andersen
1e55ce5138 Merge branch 'copy-streamers' 2015-07-08 15:15:56 -10:00
Jack Andersen
35a5736c35 Merge branch 'master' of https://github.com/libAthena/Athena 2015-07-08 15:15:48 -10:00
Jack Andersen
b7ba46b995 MemoryCopy streamers and CMake features 2015-07-08 15:14:02 -10:00
Jack Andersen
c65ef591f5 significant virtual-method refactor to streaming interface 2015-07-08 15:13:14 -10:00
Jack Andersen
1b40613c05 Update README.md 2015-07-08 15:12:24 -10:00
Jack Andersen
dde7164651 Updated PKGBUILD 2015-07-08 15:08:29 -10:00
Jack Andersen
916515f0d7 OS X build fixes 2015-07-08 14:57:51 -10:00
Jack Andersen
e1f46b824f added pkgconfig install to CMake 2015-07-08 14:01:05 -10:00
Jack Andersen
c49ec5c13d CMake package exports 2015-07-08 13:53:40 -10:00
Jack Andersen
8ca702785c added icons; updated PKGBUILD for CMake 2015-07-08 10:21:50 -10:00
Jack Andersen
44e25e09ca updated MemoryCopyWriter 2015-07-07 20:34:59 -10:00
Jack Andersen
ec38ba088e added buffer-copying subclass to MemoryReader/Writer 2015-07-07 20:03:08 -10:00
Jack Andersen
108a3aa6c1 Update README.md 2015-07-07 18:36:29 -10:00
Jack Andersen
8a397a1622 Merge pull request #18 from libAthena/new-streams
significant virtual-method refactor to streaming interface
2015-07-07 21:16:04 -07:00
Jack Andersen
97dfabb265 significant virtual-method refactor to streaming interface 2015-07-07 18:01:13 -10:00
Jack Andersen
ce917d4aca Added CMakeLists.txt 2015-07-06 17:23:37 -10:00
Jack Andersen
6ac88b37f4 Merge pull request #17 from libAthena/opt
Various Header Optimizations
2015-07-02 16:43:53 -07:00
Jack Andersen
a63da8db2f header-based read/write optimizations 2015-07-02 13:36:17 -10:00
Jack Andersen
2b37765eff nested type ordering fix 2015-06-30 21:50:58 -07:00
Jack Andersen
fa016115c2 const buffer pointer for write[U]Bytes 2015-06-30 17:01:04 -10:00
a76a3c584a * Revert swapFloat/Double "fixes" 2015-06-30 19:09:35 -07:00
Jack Andersen
bfa08ce52b Merge pull request #16 from libAthena/dna-templates
Made String and Buffer types templates with DNA base
2015-06-26 14:38:33 -07:00
Jack Andersen
7524b1f063 made string and buffer types templates with DNA base; may now be used in Vector 2015-06-25 09:37:31 -10:00
Jack Andersen
49937cba50 Update README.md 2015-06-22 14:46:45 -10:00
Jack Andersen
3ff34ec749 removed atdna from Athena's travis 2015-06-22 14:28:29 -10:00
Jack Andersen
0bb90ff2e0 spun off atdna into separate repo 2015-06-22 14:26:43 -10:00
Jack Andersen
071d91a671 more stable atdna type canonicalization; recursive DNA subclassing 2015-06-22 12:52:09 -10:00
Jack Andersen
490c6d53f5 Merge pull request #15 from Antidote/msvc
Fixed variadic macros for MSVC
2015-06-20 11:13:25 -07:00
Jack Andersen
a0f0690719 confirmed linux build working; solved signing warnings 2015-06-20 08:07:11 -10:00
Jack Andersen
5a0f2e8ed4 MSVC build fixes 2015-06-19 21:40:15 -07:00
Jack Andersen
687a7eef64 fixed length string read refinement 2015-06-19 10:54:21 -10:00
Jack Andersen
2d8aeb70e8 updated doxy comments 2015-06-19 10:44:01 -10:00
Jack Andersen
e641dbbe4b added seek directive to fixed-length string reads 2015-06-19 10:40:59 -10:00
Jack Andersen
3dfb001f3d added fixed-length string writing 2015-06-19 10:12:25 -10:00
Jack Andersen
242a06915b diagnostic duplicates no longer raised 2015-06-19 08:25:08 -10:00
Jack Andersen
fd3db3e1db fix for vector readers 2015-06-18 19:33:46 -10:00
Jack Andersen
7b1b027192 Merge pull request #14 from Antidote/travis-fix
Adjusting travis config to support atdna
2015-06-18 19:27:22 -10:00
Jack Andersen
7cdfcab55a lots of new 'atdna' types; travis update 2015-06-18 19:18:39 -10:00
Jack Andersen
1aa3a705af added commenting to output 2015-06-17 21:57:53 -10:00
Jack Andersen
d6a489753d generator fix 2015-06-17 21:37:04 -10:00
Jack Andersen
c08695709e Minor argument tweak 2015-06-17 21:34:36 -10:00
Jack Andersen
6c7f5ebd29 Updated with Vector support for DNA subtypes 2015-06-17 21:32:11 -10:00
Jack Andersen
2c63768ec4 Added DNA.hpp warning 2015-06-16 16:50:12 -10:00
Jack Andersen
791a355ace Merge pull request #13 from Antidote/atdna
Added `atdna` tool to Athena
2015-06-16 16:25:15 -10:00
Jack Andersen
9ebdb37b85 removed unneeded libs 2015-06-16 16:20:38 -10:00
Jack Andersen
3071db8f61 hard-path comments 2015-06-16 16:02:35 -10:00
Jack Andersen
0bf9815fc0 Restored master branch for PKGBUILDs 2015-06-16 15:43:35 -10:00
Jack Andersen
647f9c4dec Another tweak 2015-06-16 15:20:31 -10:00
Jack Andersen
ec4ac688f4 hopefully the last tweak 2015-06-16 15:08:39 -10:00
Jack Andersen
7fccd416f3 even more tweaks 2015-06-16 15:05:43 -10:00
Jack Andersen
b195c194f7 futher adjustments 2015-06-16 15:02:58 -10:00
Jack Andersen
96ed8a2ce2 more build system tweaks 2015-06-16 14:57:06 -10:00
Jack Andersen
2bb60ab152 build system tweaks 2015-06-16 14:33:04 -10:00
Jack Andersen
fb722a9f5b further updates to atdna 2015-06-16 14:25:48 -10:00
Jack Andersen
775b51fd00 minor tweak 2015-06-15 21:15:00 -10:00
Jack Andersen
0452e34150 initial working reader/writer values 2015-06-15 21:11:56 -10:00
Jack Andersen
c09f06b436 working release build of atdna 2015-06-15 16:29:53 -10:00
Jack Andersen
dde8ac1a1c initial atdna commit 2015-06-14 16:49:02 -10:00
1ea07c20fb Add MIT license 2015-05-28 18:43:50 -07:00
7785983093 Merge pull request #10 from Antidote/file-dir-api
File and Dir API
2015-05-20 22:54:27 -07:00
6a611ef2cc * Fix last commit 2015-05-20 22:41:29 -07:00
d5ccf159f7 * Fix Wii/GC Compiling
* Initial FileInfo/Dir APIs
* Get rid of type punning warnings
2015-05-20 22:35:26 -07:00
Jack Andersen
3223d3faa6 Merge branch 'file-dir-api' of https://github.com/Antidote/Athena into file-dir-api 2015-05-20 19:16:28 -10:00
Jack Andersen
92d86a2673 More portable 'utimes' 2015-05-20 19:14:44 -10:00
47dafe3251 * struct stat64 -> stat64_t 2015-05-20 22:04:35 -07:00
011496db8b * Fix Wii/GC Compiling
* Finish initial FileInfo/Dir APIs
* Get rid of type punning warnings
2015-05-20 21:58:21 -07:00
29a203522d * Fix merge 2015-05-18 20:36:45 -07:00
6ee11b9a08 * Fix styling 2015-05-18 20:24:56 -07:00
423a9a37d2 Reimplement Exceptions. 2015-05-18 16:38:02 -07:00
01f989c21c Initial API implementation 2015-05-18 14:03:13 -07:00
269 changed files with 37518 additions and 12950 deletions

View File

@@ -1,17 +0,0 @@
compiler:
- gcc-4.8
before_install:
- sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa
- sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install -qq g++-4.8
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
- sudo update-alternatives --config gcc
script:
- qmake Athena.pro
- make
notifications:
irc: "irc.wiiking2.com#wiiking2"

BIN
Athena.icns Normal file

Binary file not shown.

BIN
Athena.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

@@ -1,4 +0,0 @@
include(AthenaCore.pri)
include(AthenaZelda.pri)
include(AthenaWiiSave.pri)
include(AthenaSakura.pri)

View File

@@ -1,63 +0,0 @@
CONFIG += staticlib c++11
QMAKE_CXXFLAGS += -std=c++11
TEMPLATE= lib
DESTDIR = ./lib
INCLUDEPATH += $$PWD/include
# Uncomment this if you wish to use Qt with libAthena
#DEFINES += ATHENA_USE_QT
contains(DEFINES, ATHENA_USE_QT){
QT += qt core
} else {
QT =
}
CONFIG(debug, debug|release): {
DEFINES += DEBUG
TARGET=Athena-d
# We don't want the objects,
# in the project directory, so tell qmake
# where to put them
OBJECTS_DIR = obj/debug
}
CONFIG(release, release|debug): {
DEFINES -= DEBUG
TARGET=Athena
# We don't want the objects,
# in the project directory, so tell qmake
# where to put them
OBJECTS_DIR = obj/release
}
ATHENA_PRO=true
include(Athena.pri)
OTHER_FILES += \
.travis.yml
unix {
isEmpty(PREFIX) {
PREFIX = /usr/local
}
libFiles.path = $$PREFIX/lib
libFiles.files = $$PWD/lib/*
headerFiles.files = $$PWD/include/*
headerFiles.path = $$PREFIX/include/Athena
INSTALLS += libFiles headerFiles
}
win32 {
isEmpty(PREFIX) {
PREFIX = $$PWD/pkg
}
libFiles.path = $$PREFIX/lib
libFiles.files = $$PWD/lib/*
headerFiles.path = $$PREFIX/include/Athena
headerFiles.files = $$PWD/include/*
INSTALLS += libFiles headerFiles
}

22
AthenaConfig.cmake.in Normal file
View File

@@ -0,0 +1,22 @@
# - Config file for the Athena package
# It defines the following variables
# ATHENA_INCLUDE_DIR - include directory for Athena
# ATHENA_LIBRARIES - libraries to link against
# ATHENA_ICON - path to Athena.ico
# Compute paths
get_filename_component(ATHENA_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(ATHENA_INCLUDE_DIR "@CONF_INCLUDE_DIR@")
# Our library dependencies (contains definitions for IMPORTED targets)
if(NOT TARGET AthenaCore AND NOT Athena_BINARY_DIR)
include("${ATHENA_CMAKE_DIR}/AthenaTargets.cmake")
endif()
# These are IMPORTED targets created by AthenaTargets.cmake
set(ATHENA_LIBRARIES AthenaCore AthenaSakura AthenaZelda AthenaWiiSave)
# Set icon location if on windows
if(WIN32 AND NOT CYGWIN)
set(ATHENA_ICON "@CONF_ICON_DIR@")
endif()

View File

@@ -0,0 +1,11 @@
set(PACKAGE_VERSION "@ATHENA_VERSION@")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

View File

@@ -1,66 +0,0 @@
!contains(ATHENA_PRO, true): {
INCLUDEPATH += $$PWD/include
!contains(CONFIG, c++11):CONFIG += c++11
mac:QMAKE_CXXFLAGS += -stdlib=libc++
}
include(extern/lzo/lzo.pri)
include(extern/zlib/zlib.pri)
ATHENA_CORE=true
SOURCES += \
$$PWD/src/Athena/Utility.cpp \
$$PWD/src/Athena/FileReader.cpp \
$$PWD/src/Athena/FileWriter.cpp \
$$PWD/src/Athena/MemoryReader.cpp \
$$PWD/src/Athena/MemoryWriter.cpp \
$$PWD/src/Athena/Global.cpp \
$$PWD/src/Athena/Checksums.cpp \
$$PWD/src/Athena/Compression.cpp \
$$PWD/src/LZ77/LZLookupTable.cpp \
$$PWD/src/LZ77/LZType10.cpp \
$$PWD/src/LZ77/LZType11.cpp \
$$PWD/src/LZ77/LZBase.cpp
win32:SOURCES += \
$$PWD/src/win32_largefilewrapper.c
mac:SOURCES += \
$$PWD/src/osx_largefilewrapper.c
HEADERS += \
$$PWD/include/Athena/IStream.hpp \
$$PWD/include/Athena/IStreamReader.hpp \
$$PWD/include/Athena/IStreamWriter.hpp \
$$PWD/include/Athena/Types.hpp \
$$PWD/include/Athena/Utility.hpp \
$$PWD/include/Athena/Global.hpp \
$$PWD/include/Athena/Exception.hpp \
$$PWD/include/Athena/FileNotFoundException.hpp \
$$PWD/include/Athena/IOException.hpp \
$$PWD/include/Athena/InvalidDataException.hpp \
$$PWD/include/Athena/InvalidOperationException.hpp \
$$PWD/include/Athena/FileReader.hpp \
$$PWD/include/Athena/FileWriter.hpp \
$$PWD/include/Athena/MemoryReader.hpp \
$$PWD/include/Athena/MemoryWriter.hpp \
$$PWD/include/Athena/NotImplementedException.hpp \
$$PWD/include/Athena/Checksums.hpp \
$$PWD/include/Athena/Compression.hpp \
$$PWD/include/LZ77/LZBase.hpp \
$$PWD/include/LZ77/LZLookupTable.hpp \
$$PWD/include/LZ77/LZType10.hpp \
$$PWD/include/LZ77/LZType11.hpp \
$$PWD/include/utf8.h \
$$PWD/include/utf8/checked.h \
$$PWD/include/utf8/core.h \
$$PWD/include/utf8/unchecked.h
win32:HEADERS += \
$$PWD/include/win32_largefilewrapper.h
mac:HEADERS += \
$$PWD/include/osx_largefilewrapper.h

BIN
AthenaNSIS.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -1,20 +0,0 @@
!contains(ATHENA_CORE, true): {
message("including core")
include(AthenaCore.pri)
}
SOURCES += \
$$PWD/src/Athena/Sprite.cpp \
$$PWD/src/Athena/SpriteFile.cpp \
$$PWD/src/Athena/SpriteFileReader.cpp \
$$PWD/src/Athena/SpriteFileWriter.cpp \
$$PWD/src/Athena/SpriteFrame.cpp \
$$PWD/src/Athena/SpritePart.cpp
HEADERS += \
$$PWD/include/Athena/Sprite.hpp \
$$PWD/include/Athena/SpriteFile.hpp \
$$PWD/include/Athena/SpriteFileReader.hpp \
$$PWD/include/Athena/SpriteFileWriter.hpp \
$$PWD/include/Athena/SpriteFrame.hpp \
$$PWD/include/Athena/SpritePart.hpp

View File

@@ -1,30 +0,0 @@
!contains(ATHENA_CORE, true): {
message("including core")
include(AthenaCore.pri)
}
SOURCES += \
$$PWD/src/Athena/WiiBanner.cpp \
$$PWD/src/Athena/WiiFile.cpp \
$$PWD/src/Athena/WiiImage.cpp \
$$PWD/src/Athena/WiiSave.cpp \
$$PWD/src/Athena/WiiSaveReader.cpp \
$$PWD/src/Athena/WiiSaveWriter.cpp \
$$PWD/src/bn.cpp \
$$PWD/src/ec.cpp \
$$PWD/src/md5.cpp \
$$PWD/src/sha1.cpp \
$$PWD/src/aes.c
HEADERS += \
$$PWD/include/Athena/WiiBanner.hpp \
$$PWD/include/Athena/WiiFile.hpp \
$$PWD/include/Athena/WiiImage.hpp \
$$PWD/include/Athena/WiiSave.hpp \
$$PWD/include/Athena/WiiSaveReader.hpp \
$$PWD/include/Athena/WiiSaveWriter.hpp \
$$PWD/include/aes.h \
$$PWD/include/bn.h \
$$PWD/include/ec.h \
$$PWD/include/md5.h \
$$PWD/include/sha1.h

View File

@@ -1,36 +0,0 @@
!contains(ATHENA_CORE, true): {
message("including core")
include(AthenaCore.pri)
}
SOURCES += \
$$PWD/src/Athena/ALTTPFile.cpp \
$$PWD/src/Athena/ALTTPFileReader.cpp \
$$PWD/src/Athena/ALTTPFileWriter.cpp \
$$PWD/src/Athena/ALTTPQuest.cpp \
$$PWD/src/Athena/MCFile.cpp \
$$PWD/src/Athena/MCFileReader.cpp \
$$PWD/src/Athena/MCFileWriter.cpp \
$$PWD/src/Athena/MCSlot.cpp \
$$PWD/src/Athena/SkywardSwordFile.cpp \
$$PWD/src/Athena/SkywardSwordFileReader.cpp \
$$PWD/src/Athena/SkywardSwordFileWriter.cpp \
$$PWD/src/Athena/SkywardSwordQuest.cpp \
$$PWD/src/Athena/ZQuestFile.cpp \
$$PWD/src/Athena/ZQuestFileReader.cpp \
$$PWD/src/Athena/ZQuestFileWriter.cpp
HEADERS += \
$$PWD/include/Athena/ALTTPEnums.hpp \
$$PWD/include/Athena/ALTTPFile.hpp \
$$PWD/include/Athena/ALTTPFileReader.hpp \
$$PWD/include/Athena/ALTTPFileWriter.hpp \
$$PWD/include/Athena/ALTTPQuest.hpp \
$$PWD/include/Athena/ALTTPStructs.hpp \
$$PWD/include/Athena/MCFile.hpp \
$$PWD/include/Athena/MCFileReader.hpp \
$$PWD/include/Athena/MCFileWriter.hpp \
$$PWD/include/Athena/SkywardSwordFile.hpp \
$$PWD/include/Athena/SkywardSwordFileReader.hpp \
$$PWD/include/Athena/SkywardSwordFileWriter.hpp \
$$PWD/include/Athena/SkywardSwordQuest.hpp

272
CMakeLists.txt Normal file
View File

@@ -0,0 +1,272 @@
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.0)
project(Athena)
endif()
##################
# Athena Version #
##################
set(ATHENA_MAJOR_VERSION 2)
set(ATHENA_MINOR_VERSION 3)
set(ATHENA_PATCH_VERSION 0)
set(ATHENA_VERSION
${ATHENA_MAJOR_VERSION}.${ATHENA_MINOR_VERSION}.${ATHENA_PATCH_VERSION})
################
# Athena Build #
################
add_subdirectory(extern)
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()
if(WIN32)
list(APPEND CORE_EXTRA src/win32_largefilewrapper.c include/win32_largefilewrapper.h)
elseif(APPLE OR GEKKO)
list(APPEND CORE_EXTRA src/osx_largefilewrapper.c include/osx_largefilewrapper.h)
if(GEKKO)
list(APPEND CORE_EXTRA src/gekko_support.c include/gekko_support.h)
endif()
endif()
add_library(AthenaCore
src/Athena/Utility.cpp
src/Athena/FileReader.cpp
src/Athena/FileWriter.cpp
src/Athena/MemoryReader.cpp
src/Athena/MemoryWriter.cpp
src/Athena/Global.cpp
src/Athena/Checksums.cpp
src/Athena/Compression.cpp
src/LZ77/LZLookupTable.cpp
src/LZ77/LZType10.cpp
src/LZ77/LZType11.cpp
src/LZ77/LZBase.cpp
src/Athena/FileInfo.cpp
src/Athena/Dir.cpp
src/Athena/DNAYaml.cpp
${CORE_EXTRA}
include/Athena/IStream.hpp
include/Athena/IStreamReader.hpp
include/Athena/IStreamWriter.hpp
include/Athena/Types.hpp
include/Athena/Utility.hpp
include/Athena/Global.hpp
include/Athena/FileReader.hpp
include/Athena/FileWriter.hpp
include/Athena/MemoryReader.hpp
include/Athena/MemoryWriter.hpp
include/Athena/Checksums.hpp
include/Athena/Compression.hpp
include/LZ77/LZBase.hpp
include/LZ77/LZLookupTable.hpp
include/LZ77/LZType10.hpp
include/LZ77/LZType11.hpp
include/Athena/FileInfo.hpp
include/Athena/Dir.hpp
include/Athena/DNA.hpp
include/Athena/DNAYaml.hpp
include/yaml.h
include/utf8proc.h
)
add_library(AthenaSakura EXCLUDE_FROM_ALL
src/Athena/Sprite.cpp
src/Athena/SpriteFile.cpp
src/Athena/SpriteFileReader.cpp
src/Athena/SpriteFileWriter.cpp
src/Athena/SpriteFrame.cpp
src/Athena/SpritePart.cpp
include/Athena/SakuraGlobal.hpp
include/Athena/Sprite.hpp
include/Athena/SpriteFile.hpp
include/Athena/SpriteFileReader.hpp
include/Athena/SpriteFileWriter.hpp
include/Athena/SpriteFrame.hpp
include/Athena/SpritePart.hpp
)
add_library(AthenaWiiSave EXCLUDE_FROM_ALL
src/Athena/WiiBanner.cpp
src/Athena/WiiFile.cpp
src/Athena/WiiImage.cpp
src/Athena/WiiSave.cpp
src/Athena/WiiSaveReader.cpp
src/Athena/WiiSaveWriter.cpp
src/bn.cpp
src/ec.cpp
src/md5.cpp
src/sha1.cpp
src/aes.cpp
include/Athena/WiiBanner.hpp
include/Athena/WiiFile.hpp
include/Athena/WiiImage.hpp
include/Athena/WiiSave.hpp
include/Athena/WiiSaveReader.hpp
include/Athena/WiiSaveWriter.hpp
include/aes.hpp
include/bn.h
include/ec.h
include/md5.h
include/sha1.h
)
if(NOT MSVC AND NOT GEKKO)
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
endif()
add_library(AthenaZelda EXCLUDE_FROM_ALL
src/Athena/ALTTPFile.cpp
src/Athena/ALTTPFileReader.cpp
src/Athena/ALTTPFileWriter.cpp
src/Athena/ALTTPQuest.cpp
src/Athena/MCFile.cpp
src/Athena/MCFileReader.cpp
src/Athena/MCFileWriter.cpp
src/Athena/MCSlot.cpp
src/Athena/SkywardSwordFile.cpp
src/Athena/SkywardSwordFileReader.cpp
src/Athena/SkywardSwordFileWriter.cpp
src/Athena/SkywardSwordQuest.cpp
src/Athena/ZQuestFile.cpp
src/Athena/ZQuestFileReader.cpp
src/Athena/ZQuestFileWriter.cpp
include/Athena/ALTTPEnums.hpp
include/Athena/ALTTPFile.hpp
include/Athena/ALTTPFileReader.hpp
include/Athena/ALTTPFileWriter.hpp
include/Athena/ALTTPQuest.hpp
include/Athena/ALTTPStructs.hpp
include/Athena/MCFile.hpp
include/Athena/MCFileReader.hpp
include/Athena/MCFileWriter.hpp
include/Athena/SkywardSwordFile.hpp
include/Athena/SkywardSwordFileReader.hpp
include/Athena/SkywardSwordFileWriter.hpp
include/Athena/SkywardSwordQuest.hpp
)
add_library(AthenaNet
src/sockwrap.c
src/Athena/Socket.cpp
src/Athena/OAuth.cpp
src/Athena/IPAddress.cpp
include/sockwrap.h
include/Athena/Socket.hpp
include/Athena/OAuth.hpp
include/Athena/IPAddress.hpp)
# Icon
set(ATHENA_ICO ${CMAKE_CURRENT_SOURCE_DIR}/Athena.ico)
# Offer the user the choice of overriding the installation directories
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
if(WIN32 AND NOT CYGWIN)
set(INSTALL_CMAKE_DIR cmake)
else()
set(INSTALL_CMAKE_DIR lib/cmake/Athena)
endif()
# Make relative paths absolute (needed later on)
foreach(p LIB INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(ABS_${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
else()
set(ABS_${var} "${${var}}")
endif()
endforeach()
# Define installs
install(DIRECTORY include/ DESTINATION ${INSTALL_INCLUDE_DIR}/Athena COMPONENT Athena)
install(TARGETS AthenaCore
DESTINATION ${INSTALL_LIB_DIR} EXPORT AthenaTargets COMPONENT Athena)
if(WIN32 AND NOT CYGWIN)
install(FILES Athena.ico DESTINATION ${INSTALL_LIB_DIR} COMPONENT Athena)
elseif(UNIX)
configure_file(libAthena.pc.in libAthena.pc @ONLY)
configure_file(PKGBUILD.in ${CMAKE_CURRENT_SOURCE_DIR}/PKGBUILD @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/libAthena.pc
DESTINATION ${INSTALL_LIB_DIR}/pkgconfig COMPONENT Athena)
endif()
##################
# Package Export #
##################
# Add all targets to the build-tree export set
export(TARGETS AthenaCore
FILE "${PROJECT_BINARY_DIR}/AthenaTargets.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE Athena)
# Create the AthenaConfig.cmake
# ... for the build tree
set(CONF_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include/Athena")
set(CONF_ICON_DIR "${PROJECT_SOURCE_DIR}/Athena.ico")
configure_file(AthenaConfig.cmake.in "${PROJECT_BINARY_DIR}/AthenaConfig.cmake" @ONLY)
# ... for the install tree
file(RELATIVE_PATH REL_INCLUDE_DIR "${ABS_INSTALL_CMAKE_DIR}" "${ABS_INSTALL_INCLUDE_DIR}")
file(RELATIVE_PATH REL_ICON_DIR "${ABS_INSTALL_CMAKE_DIR}" "${ABS_INSTALL_LIB_DIR}/Athena.ico")
set(CONF_INCLUDE_DIR "\${ATHENA_CMAKE_DIR}/${REL_INCLUDE_DIR}/Athena")
set(CONF_ICON_DIR "\${ATHENA_CMAKE_DIR}/${REL_ICON_DIR}")
configure_file(AthenaConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/AthenaConfig.cmake" @ONLY)
# ... for both
configure_file(AthenaConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/AthenaConfigVersion.cmake" @ONLY)
# Install AthenaConfig.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/AthenaConfig.cmake"
"${PROJECT_BINARY_DIR}/AthenaConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT Athena)
# Install the export set for use with the install-tree
install(EXPORT AthenaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT Athena)
################
# atdna import #
################
if(NOT GEKKO)
add_subdirectory(atdna)
endif()
#########
# CPack #
#########
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Athena")
set(CPACK_PACKAGE_VENDOR "Antidote / Jackoalan")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR ${ATHENA_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${ATHENA_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${ATHENA_PATCH_VERSION})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Athena")
if(WIN32 AND NOT UNIX)
# There is a bug in NSI that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "Athena")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\AthenaNSIS.bmp")
set(CPACK_NSIS_MODIFY_PATH ON)
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\Athena.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\Athena.ico")
set(CPACK_NSIS_INSTALLED_ICON_NAME "Uninstall.exe")
set(CPACK_NSIS_DISPLAY_NAME "Athena")
set(CPACK_NSIS_URL_INFO_ABOUT "http://libathena.github.io")
set(CPACK_NSIS_CONTACT "antidote.crk@gmail.com")
endif()
include(CPack)

2413
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

17
Example/CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.0)
project(Example)
endif()
include_directories(${ATHENA_INCLUDE_DIR})
add_executable(Example
main.cpp)
if(GEKKO)
include_directories(${LIBOGCDIR}/include)
link_directories(${LIGOGCDIR}/lib/wii)
target_link_libraries(Example AthenaCore z wiiuse bte ogc m)
else()
#TODO: add normal link libraries
endif()

58
Example/main.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include <iostream>
#if GEKKO
#include <gccore.h>
#if HW_RVL
#include <wiiuse/wpad.h>
#endif
static void *xfb = nullptr;
static GXRModeObj* rmode = nullptr;
#endif
#include <Athena/MemoryReader.hpp>
int main()
{
#if GEKKO
VIDEO_Init();
#if HW_RVL
WPAD_Init();
#endif
PAD_Init();
rmode = VIDEO_GetPreferredMode(nullptr);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
CON_Init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
CON_EnableGecko(CARD_SLOTB, true);
VIDEO_Configure(rmode);
VIDEO_SetBlack(false);
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
Athena::io::MemoryCopyReader test("sd:/test.dat");
while(true)
{
#if HW_RVL
WPAD_ScanPads();
#endif
PAD_ScanPads();
if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
break;
#if HW_RVL
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
break;
#endif
VIDEO_WaitVSync();
}
#endif
return 0;
}

20
LICENSE Normal file
View File

@@ -0,0 +1,20 @@
Copyright (c) 2011-2015 Phillip "Antidote" Stephens, Jack Andersen, et al.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,14 +1,14 @@
# PKGBUILD for libAthena # PKGBUILD for libAthena
_pkgname=libathena _pkgname=libathena
pkgname=$_pkgname-git pkgname=$_pkgname-git
pkgver=v1.0.0 pkgver=@ATHENA_VERSION@
pkgrel=1 pkgrel=1
pkgdesc="Basic cross platform IO library" pkgdesc="Basic cross platform IO library"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')
source=("${pkgname%-*}::git+https://github.com/Antidote/Athena.git") source=("${pkgname%-*}::git+https://github.com/libAthena/Athena.git")
options=(staticlibs) options=(staticlibs)
license="GPL3" license="MIT"
makedepends=('git qt5-base sed') makedepends=('git cmake sed')
md5sums=('SKIP') md5sums=('SKIP')
sha256sums=('SKIP') sha256sums=('SKIP')
@@ -19,11 +19,14 @@ pkgver() {
build() { build() {
cd "$srcdir/$_pkgname" cd "$srcdir/$_pkgname"
qmake && make mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$pkgdir/usr" ..
make
} }
package() { package() {
cd "$srcdir/$_pkgname" cd "$srcdir/$_pkgname/build"
qmake PREFIX="$pkgdir/usr" && make install make install
} }

View File

@@ -1,2 +1 @@
# Athena # Athena
[![Build Status](https://travis-ci.org/Antidote/Athena.svg?branch=master)](https://travis-ci.org/Antidote/Athena)

179
atdna/CMakeLists.txt Normal file
View File

@@ -0,0 +1,179 @@
###############
# ATDNA Build #
###############
# Force this binary to Release flags (to make MSVC happy)
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
endif()
# Find dependencies
include(FindLLVM.cmake)
if(NOT LLVM_FOUND)
message("-- Unable to locate LLVM installation; skipping atdna")
else()
list(APPEND LLVM_LIBS
clangFrontend
clangTooling
clangDriver
clangSerialization
clangParse
clangSema
clangAnalysis
clangEdit
clangAST
clangLex
clangBasic
LLVMOption
LLVMMCParser
LLVMBitReader
LLVMMC
LLVMSupport)
set(CLANG_INCLUDE_DIR ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_STRING}/include
CACHE PATH "Clang include dir" FORCE)
if(UNIX)
list(APPEND PLAT_LIBS z pthread curses)
if (APPLE)
list(APPEND PLAT_LIBS dl)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND PLAT_LIBS dl)
endif()
endif()
# Offer the user the choice of overriding the installation directories
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
if(WIN32 AND NOT CYGWIN)
set(INSTALL_CMAKE_DIR cmake)
else()
set(INSTALL_CMAKE_DIR lib/cmake/atdna)
endif()
# Make relative paths absolute (needed later on)
foreach(p BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(ABS_${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
else()
set(ABS_${var} "${${var}}")
endif()
endforeach()
# Windows resource
if(WIN32)
configure_file(main.rc.in main.rc @ONLY)
set(PLAT_SRCS ${CMAKE_CURRENT_BINARY_DIR}/main.rc)
endif()
# ATDNA target
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_executable(atdna main.cpp test.hpp ${PLAT_SRCS})
target_link_libraries(atdna ${LLVM_LIBS} ${PLAT_LIBS})
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS
"INSTALL_PREFIX=${ABS_INSTALL_BIN_DIR};__STDC_LIMIT_MACROS=1;__STDC_CONSTANT_MACROS=1")
if(MSVC)
set_target_properties(atdna PROPERTIES
COMPILE_FLAGS "/GR-")
else()
set_target_properties(atdna PROPERTIES
COMPILE_FLAGS "-std=c++11 -fno-rtti -Wno-unused-parameter"
LINK_FLAGS -std=c++11)
endif()
# Define installs
install(TARGETS atdna DESTINATION ${INSTALL_BIN_DIR} EXPORT atdnaTargets COMPONENT atdna)
install(DIRECTORY ${CLANG_INCLUDE_DIR}/ DESTINATION ${INSTALL_INCLUDE_DIR}/Athena/clang COMPONENT atdna)
##################
# Package Export #
##################
# Add all targets to the build-tree export set
export(TARGETS atdna FILE "${PROJECT_BINARY_DIR}/atdnaTargets.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE atdna)
# Create the atdnaConfig.cmake
# ... for the build tree
set(CONF_CLANG_INCLUDE_DIR "${CLANG_INCLUDE_DIR}")
configure_file(atdnaConfig.cmake.in "${PROJECT_BINARY_DIR}/atdnaConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_CLANG_INCLUDE_DIR "\${ATHENA_INCLUDE_DIR}/clang")
configure_file(atdnaConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/atdnaConfig.cmake" @ONLY)
# ... for both
configure_file(atdnaConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/atdnaConfigVersion.cmake" @ONLY)
# Install atdnaConfig.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/atdnaConfig.cmake"
"${PROJECT_BINARY_DIR}/atdnaConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT atdna)
# Install the export set for use with the install-tree
install(EXPORT atdnaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT atdna)
#########
# CTest #
#########
enable_testing()
add_test(NAME test-dna COMMAND $<TARGET_FILE:atdna> -o test.cpp
"-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}"
${CMAKE_SOURCE_DIR}/test.hpp)
endif()
#######################
# In-tree atdna macro #
#######################
# Super handy macro for adding atdna target
macro(atdna out)
# Make input files source-relative
set(ins "")
foreach(arg ${ARGN})
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
endforeach()
# Get local include directories for atdna
get_property(incdirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
set(inccli "")
foreach(dir ${incdirs})
list(APPEND inccli "-I${dir}")
endforeach()
# Get local defines for atdna
get_property(cdefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
set(cdefcli "")
foreach(def ${cdefs})
list(APPEND cdefcli "-D${def}")
endforeach()
# MS extra
unset(extraargs)
if(MSVC)
list(APPEND extraargs -fms-compatibility -fexceptions)
if(MSVC_VERSION EQUAL 1800)
list(APPEND extraargs -fms-compatibility-version=18.00)
elseif(MSVC_VERSION EQUAL 1900)
list(APPEND extraargs -fms-compatibility-version=19.00)
endif()
# OSX Extra
elseif(APPLE)
list(APPEND extraargs -isysroot ${CMAKE_OSX_SYSROOT} -isysroot
${CMAKE_OSX_SYSROOT}/../../../../../Toolchains/XcodeDefault.xctoolchain)
endif()
# Make target
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}"
-isystem "${CLANG_INCLUDE_DIR}" ${ins}
DEPENDS ${ins} COMMENT "Generating DNA ${out}")
endmacro()

205
atdna/FindLLVM.cmake Normal file
View File

@@ -0,0 +1,205 @@
# - Find LLVM headers and libraries.
# This module locates LLVM and adapts the llvm-config output for use with
# CMake.
#
# A given list of COMPONENTS is passed to llvm-config.
#
# The following variables are defined:
# LLVM_FOUND - true if LLVM was found
# LLVM_CXXFLAGS - C++ compiler flags for files that include LLVM headers.
# LLVM_HOST_TARGET - Target triple used to configure LLVM.
# LLVM_INCLUDE_DIRS - Directory containing LLVM include files.
# LLVM_LDFLAGS - Linker flags to add when linking against LLVM
# (includes -LLLVM_LIBRARY_DIRS).
# LLVM_LIBRARIES - Full paths to the library files to link against.
# LLVM_LIBRARY_DIRS - Directory containing LLVM libraries.
# LLVM_ROOT_DIR - The root directory of the LLVM installation.
# llvm-config is searched for in ${LLVM_ROOT_DIR}/bin.
# LLVM_VERSION_MAJOR - Major version of LLVM.
# LLVM_VERSION_MINOR - Minor version of LLVM.
# LLVM_VERSION_STRING - Full LLVM version string (e.g. 2.9).
#
# Note: The variable names were chosen in conformance with the offical CMake
# guidelines, see ${CMAKE_ROOT}/Modules/readme.txt.
# Try suffixed versions to pick up the newest LLVM install available on Debian
# derivatives.
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the
# system default locations such as /usr/local/bin. Executing find_program()
# multiples times is the approach recommended in the docs.
set(LLVM_FIND_COMPONENTS "")
if(WIN32)
get_filename_component(LLVM_ROOT_DIR [HKEY_LOCAL_MACHINE\\Software\\LLVM\\LLVM] ABSOLUTE)
endif()
set(llvm_config_names llvm-config-3.7 llvm-config37
llvm-config-3.6 llvm-config36
llvm-config-3.5 llvm-config35
llvm-config-3.4 llvm-config34
llvm-config-3.3 llvm-config33
llvm-config-3.2 llvm-config32
llvm-config-3.1 llvm-config31 llvm-config)
find_program(LLVM_CONFIG
NAMES ${llvm_config_names}
PATHS ${LLVM_ROOT_DIR}/bin NO_DEFAULT_PATH
DOC "Path to llvm-config tool.")
find_program(LLVM_CONFIG NAMES ${llvm_config_names})
if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
if (WIN32)
# A bit of a sanity check:
if( NOT EXISTS ${LLVM_ROOT_DIR}/include/llvm )
message(FATAL_ERROR "LLVM_ROOT_DIR (${LLVM_ROOT_DIR}) is not a valid LLVM install")
endif()
# We incorporate the CMake features provided by LLVM:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT_DIR}/share/llvm/cmake")
include(LLVMConfig)
# Set properties
set(LLVM_HOST_TARGET ${TARGET_TRIPLE})
set(LLVM_VERSION_STRING ${LLVM_PACKAGE_VERSION})
set(LLVM_CXXFLAGS ${LLVM_DEFINITIONS})
set(LLVM_LDFLAGS "")
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "all-targets" index)
list(APPEND LLVM_FIND_COMPONENTS ${LLVM_TARGETS_TO_BUILD})
# Work around LLVM bug 21016
list(FIND LLVM_TARGETS_TO_BUILD "X86" TARGET_X86)
if(TARGET_X86 GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS x86utils)
endif()
# Similar to the work around above, but for AArch64
list(FIND LLVM_TARGETS_TO_BUILD "AArch64" TARGET_AArch64)
if(TARGET_AArch64 GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS AArch64Utils)
endif()
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "backend" index)
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-2][\\.0-9A-Za-z]*")
# Versions below 3.3 do not support components objcarcopts, option
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "objcarcopts" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "option" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
# Versions below 3.5 do not support components lto, profiledata
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "lto" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "profiledata" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support components debuginfodwarf
# Only debuginfo is available
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
llvm_map_components_to_libraries(tmplibs ${LLVM_FIND_COMPONENTS})
else()
llvm_map_components_to_libnames(tmplibs ${LLVM_FIND_COMPONENTS})
endif()
if(MSVC)
foreach(lib ${tmplibs})
list(APPEND LLVM_LIBRARIES "${LLVM_LIBRARY_DIRS}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}")
endforeach()
else()
# Rely on the library search path being set correctly via -L on
# MinGW and others, as the library list returned by
# llvm_map_components_to_libraries also includes imagehlp and psapi.
set(LLVM_LDFLAGS "-L${LLVM_LIBRARY_DIRS}")
set(LLVM_LIBRARIES ${tmplibs})
endif()
# When using the CMake LLVM module, LLVM_DEFINITIONS is a list
# instead of a string. Later, the list seperators would entirely
# disappear, replace them by spaces instead. A better fix would be
# to switch to add_definitions() instead of throwing strings around.
string(REPLACE ";" " " LLVM_CXXFLAGS "${LLVM_CXXFLAGS}")
else()
if (NOT FIND_LLVM_QUIETLY)
message(WARNING "Could not find llvm-config. Try manually setting LLVM_ROOT_DIR to the prebuilt LLVM prefix to use.")
endif()
endif()
else()
macro(llvm_set var flag)
if(LLVM_FIND_QUIETLY)
set(_quiet_arg ERROR_QUIET)
endif()
execute_process(
COMMAND ${LLVM_CONFIG} --${flag}
OUTPUT_VARIABLE LLVM_${var}
OUTPUT_STRIP_TRAILING_WHITESPACE
${_quiet_arg}
)
if(${ARGV2})
file(TO_CMAKE_PATH "${LLVM_${var}}" LLVM_${var})
endif()
endmacro()
macro(llvm_set_libs var flag prefix)
if(LLVM_FIND_QUIETLY)
set(_quiet_arg ERROR_QUIET)
endif()
execute_process(
COMMAND ${LLVM_CONFIG} --${flag} ${LLVM_FIND_COMPONENTS}
OUTPUT_VARIABLE tmplibs
OUTPUT_STRIP_TRAILING_WHITESPACE
${_quiet_arg}
)
file(TO_CMAKE_PATH "${tmplibs}" tmplibs)
string(REGEX REPLACE "([$^.[|*+?()]|])" "\\\\\\1" pattern "${prefix}/")
string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_${var} ${tmplibs})
endmacro()
llvm_set(VERSION_STRING version)
llvm_set(CXXFLAGS cxxflags)
llvm_set(HOST_TARGET host-target)
llvm_set(INCLUDE_DIRS includedir true)
llvm_set(ROOT_DIR prefix true)
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-2][\\.0-9A-Za-z]*")
# Versions below 3.3 do not support components objcarcopts, option
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "objcarcopts" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "option" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
# Versions below 3.5 do not support components lto, profiledata
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "lto" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "profiledata" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support components debuginfodwarf
# Only debuginfo is available
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
llvm_set(LDFLAGS ldflags)
if(NOT ${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
# In LLVM 3.5+, the system library dependencies (e.g. "-lz") are accessed
# using the separate "--system-libs" flag.
llvm_set(SYSTEM_LIBS system-libs)
string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")
endif()
llvm_set(LIBRARY_DIRS libdir true)
llvm_set_libs(LIBRARIES libfiles "${LLVM_LIBRARY_DIRS}")
endif()
# On CMake builds of LLVM, the output of llvm-config --cxxflags does not
# include -fno-rtti, leading to linker errors. Be sure to add it.
if(CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
if(NOT ${LLVM_CXXFLAGS} MATCHES "-fno-rtti")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-rtti")
endif()
endif()
string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" )
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" )
# Use the default CMake facilities for handling QUIET/REQUIRED.
include(FindPackageHandleStandardArgs)
if(${CMAKE_VERSION} VERSION_LESS "2.8.4")
# The VERSION_VAR argument is not supported on pre-2.8.4, work around this.
set(VERSION_VAR dummy)
endif()
find_package_handle_standard_args(LLVM
REQUIRED_VARS LLVM_ROOT_DIR LLVM_HOST_TARGET
VERSION_VAR LLVM_VERSION_STRING)

3
atdna/README.md Normal file
View File

@@ -0,0 +1,3 @@
# atdna
[User Overview](http://libAthena.github.io/doc/atdna.html)
[DNA Record Reference](http://libAthena.github.io/doc/atdna-ref.html)

View File

@@ -0,0 +1,58 @@
# - Config file for the atdna package
# Compute paths
get_filename_component(ATHENA_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
# Our library dependencies (contains definitions for IMPORTED targets)
if(NOT TARGET atdna AND NOT atdna_BINARY_DIR)
include("${ATHENA_CMAKE_DIR}/atdnaTargets.cmake")
endif()
# Find Athena
find_package(Athena REQUIRED)
# Super handy macro for adding atdna target
macro(atdna out)
# Make input files source-relative
set(ins "")
foreach(arg ${ARGN})
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
endforeach()
# Get local include directories for atdna
get_property(incdirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
set(inccli "")
foreach(dir ${incdirs})
list(APPEND inccli "-I${dir}")
endforeach()
# Get local defines for atdna
get_property(cdefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
set(cdefcli "")
foreach(def ${cdefs})
list(APPEND cdefcli "-D${def}")
endforeach()
# MS extra
unset(extraargs)
if(MSVC)
list(APPEND extraargs -fms-compatibility -fexceptions)
if(MSVC_VERSION EQUAL 1800)
list(APPEND extraargs -fms-compatibility-version=18.00)
elseif(MSVC_VERSION EQUAL 1900)
list(APPEND extraargs -fms-compatibility-version=19.00)
endif()
# OSX Extra
elseif(APPLE)
list(APPEND extraargs -isysroot ${CMAKE_OSX_SYSROOT} -isysroot
${CMAKE_OSX_SYSROOT}/../../../../../Toolchains/XcodeDefault.xctoolchain)
endif()
# Make target
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}"
-isystem "@CONF_CLANG_INCLUDE_DIR@" ${ins}
DEPENDS ${ins} COMMENT "Generating DNA ${out}")
endmacro()

View File

@@ -0,0 +1,12 @@
set(PACKAGE_VERSION "@ATHENA_VERSION@")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

2276
atdna/main.cpp Normal file

File diff suppressed because it is too large Load Diff

32
atdna/main.rc.in Normal file
View File

@@ -0,0 +1,32 @@
#include "winver.h"
IDI_ICON1 ICON DISCARDABLE "@ATHENA_ICO@"
VS_VERSION_INFO VERSIONINFO
FILEVERSION @ATHENA_MAJOR_VERSION@,@ATHENA_MINOR_VERSION@,@ATHENA_PATCH_VERSION@,0
PRODUCTVERSION @ATHENA_MAJOR_VERSION@,@ATHENA_MINOR_VERSION@,@ATHENA_PATCH_VERSION@,0
FILEFLAGS 0x0L
FILEFLAGSMASK 0x3fL
FILEOS 0x00040004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "CompanyName", "Jackoalan / Antidote"
VALUE "FileDescription", "ATDNA"
VALUE "FileVersion", "@ATHENA_MAJOR_VERSION@.@ATHENA_MINOR_VERSION@.@ATHENA_PATCH_VERSION@"
VALUE "LegalCopyright", "Copyright (C) 2015 Jackoalan / Antidote"
VALUE "InternalName", "atdna"
VALUE "OriginalFilename", "atdna.exe"
VALUE "ProductName", "ATDNA"
VALUE "ProductVersion", "@ATHENA_MAJOR_VERSION@.@ATHENA_MINOR_VERSION@.@ATHENA_PATCH_VERSION@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END

78
atdna/test.hpp Normal file
View File

@@ -0,0 +1,78 @@
#include <Athena/DNAYaml.hpp>
using namespace Athena;
typedef io::DNAYaml<BigEndian> BigDNA;
struct TESTSubFile : public BigDNA
{
DECL_YAML
enum ETest : atUint8
{
ZERO,
ONE,
TWO,
THREE
};
Value<ETest> varE;
Value<atUint32> sub1;
Value<atUint32> sub2;
};
struct TESTSubClassFile : public TESTSubFile
{
DECL_YAML
Value<atUint32> sub3;
Value<atUint32> sub4;
};
struct TESTSubSubClassFile : public TESTSubClassFile
{
DECL_YAML
Value<atUint32> sub5;
Value<atUint32> sub6;
};
struct TESTFile : public BigDNA
{
DECL_YAML
Value<bool> varBool;
Value<atUint32> var32;
Value<atUint16> var16;
Value<atVec3f> vec3;
Value<atVec4f> vec4;
struct TESTNestedSubFile : public BigDNA
{
DECL_YAML
Value<atUint32> nestSub1;
Value<atUint32> nestSub2;
} nestedSubFile;
using TESTSubFileUsing = TESTSubFile;
TESTSubFileUsing subFile;
Align<4> align;
struct TESTExplicitSubFile : public BigDNA
{
DECL_YAML
Value<atUint32> explSub1;
Value<atUint32> explSub2;
} explSubFile;
Value<atUint32, LittleEndian> arrCount[2];
Vector<atUint32, DNA_COUNT(arrCount[0])> array;
Seek<21, Current> seek;
Value<atUint32> arrCount2;
Vector<TESTSubFile, DNA_COUNT(arrCount[1] + arrCount2)> array2;
Value<atUint32> bufSz;
Buffer<DNA_COUNT(bufSz)> buf;
String<32> str;
WString<64> wstr;
WStringAsString<> utf8str[5];
};

3
extern/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,3 @@
add_subdirectory(lzo)
add_subdirectory(zlib)
add_subdirectory(yaml)

88
extern/lzo/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,88 @@
if(NOT WIN32 AND NOT APPLE)
find_library(LZO_LIB lzo2)
endif()
if(WIN32 OR APPLE OR LZO_LIB STREQUAL LZO_LIB-NOTFOUND)
include_directories(include)
message("-- Using Athena's built-in lzo")
add_library(lzo2
src/lzo1.c
src/lzo1_99.c
src/lzo1a.c
src/lzo1a_99.c
src/lzo1b_1.c
src/lzo1b_2.c
src/lzo1b_3.c
src/lzo1b_4.c
src/lzo1b_5.c
src/lzo1b_6.c
src/lzo1b_7.c
src/lzo1b_8.c
src/lzo1b_9.c
src/lzo1b_99.c
src/lzo1b_9x.c
src/lzo1b_cc.c
src/lzo1b_d1.c
src/lzo1b_d2.c
src/lzo1b_rr.c
src/lzo1b_xx.c
src/lzo1c_1.c
src/lzo1c_2.c
src/lzo1c_3.c
src/lzo1c_4.c
src/lzo1c_5.c
src/lzo1c_6.c
src/lzo1c_7.c
src/lzo1c_8.c
src/lzo1c_9.c
src/lzo1c_99.c
src/lzo1c_9x.c
src/lzo1c_cc.c
src/lzo1c_d1.c
src/lzo1c_d2.c
src/lzo1c_rr.c
src/lzo1c_xx.c
src/lzo1f_1.c
src/lzo1f_9x.c
src/lzo1f_d1.c
src/lzo1f_d2.c
src/lzo1x_1.c
src/lzo1x_1k.c
src/lzo1x_1l.c
src/lzo1x_1o.c
src/lzo1x_9x.c
src/lzo1x_d1.c
src/lzo1x_d2.c
src/lzo1x_d3.c
src/lzo1x_o.c
src/lzo1y_1.c
src/lzo1y_9x.c
src/lzo1y_d1.c
src/lzo1y_d2.c
src/lzo1y_d3.c
src/lzo1y_o.c
src/lzo1z_9x.c
src/lzo1z_d1.c
src/lzo1z_d2.c
src/lzo1z_d3.c
src/lzo2a_9x.c
src/lzo2a_d1.c
src/lzo2a_d2.c
src/lzo_crc.c
src/lzo_init.c
src/lzo_ptr.c
src/lzo_str.c
src/lzo_util.c
include/lzo/lzo1.h
include/lzo/lzo1x.h
include/lzo/lzoconf.h
include/lzo/lzodefs.h
include/lzo/lzoutil.h)
if(WIN32 AND NOT UNIX)
install(DIRECTORY include/lzo DESTINATION include COMPONENT lzo2)
install(TARGETS lzo2 DESTINATION lib COMPONENT lzo2)
endif()
set(LZO_LIB lzo2 CACHE PATH "LZO library" FORCE)
set(LZO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "LZO include path" FORCE)
else()
find_path(LZO_INCLUDE_DIR lzo/lzo1x.h)
endif()

View File

@@ -366,9 +366,18 @@ LZO_EXTERN(const lzo_uint32_tp)
/* misc. */ /* misc. */
LZO_EXTERN(int) _lzo_config_check(void); LZO_EXTERN(int) _lzo_config_check(void);
typedef union { typedef union
lzo_voidp a00; lzo_bytep a01; lzo_uint a02; lzo_xint a03; lzo_uintptr_t a04; {
void *a05; unsigned char *a06; unsigned long a07; size_t a08; ptrdiff_t a09; lzo_voidp a00;
lzo_bytep a01;
lzo_uint a02;
lzo_xint a03;
lzo_uintptr_t a04;
void* a05;
unsigned char* a06;
unsigned long a07;
size_t a08;
ptrdiff_t a09;
#if defined(lzo_int64_t) #if defined(lzo_int64_t)
lzo_uint64_t a10; lzo_uint64_t a10;
#endif #endif

78
extern/lzo/lzo.pri vendored
View File

@@ -1,78 +0,0 @@
SOURCES += \
$$PWD/src/lzo1.c \
$$PWD/src/lzo1_99.c \
$$PWD/src/lzo1a.c \
$$PWD/src/lzo1a_99.c \
$$PWD/src/lzo1b_1.c \
$$PWD/src/lzo1b_2.c \
$$PWD/src/lzo1b_3.c \
$$PWD/src/lzo1b_4.c \
$$PWD/src/lzo1b_5.c \
$$PWD/src/lzo1b_6.c \
$$PWD/src/lzo1b_7.c \
$$PWD/src/lzo1b_8.c \
$$PWD/src/lzo1b_9.c \
$$PWD/src/lzo1b_99.c \
$$PWD/src/lzo1b_9x.c \
$$PWD/src/lzo1b_cc.c \
$$PWD/src/lzo1b_d1.c \
$$PWD/src/lzo1b_d2.c \
$$PWD/src/lzo1b_rr.c \
$$PWD/src/lzo1b_xx.c \
$$PWD/src/lzo1c_1.c \
$$PWD/src/lzo1c_2.c \
$$PWD/src/lzo1c_3.c \
$$PWD/src/lzo1c_4.c \
$$PWD/src/lzo1c_5.c \
$$PWD/src/lzo1c_6.c \
$$PWD/src/lzo1c_7.c \
$$PWD/src/lzo1c_8.c \
$$PWD/src/lzo1c_9.c \
$$PWD/src/lzo1c_99.c \
$$PWD/src/lzo1c_9x.c \
$$PWD/src/lzo1c_cc.c \
$$PWD/src/lzo1c_d1.c \
$$PWD/src/lzo1c_d2.c \
$$PWD/src/lzo1c_rr.c \
$$PWD/src/lzo1c_xx.c \
$$PWD/src/lzo1f_1.c \
$$PWD/src/lzo1f_9x.c \
$$PWD/src/lzo1f_d1.c \
$$PWD/src/lzo1f_d2.c \
$$PWD/src/lzo1x_1.c \
$$PWD/src/lzo1x_1k.c \
$$PWD/src/lzo1x_1l.c \
$$PWD/src/lzo1x_1o.c \
$$PWD/src/lzo1x_9x.c \
$$PWD/src/lzo1x_d1.c \
$$PWD/src/lzo1x_d2.c \
$$PWD/src/lzo1x_d3.c \
$$PWD/src/lzo1x_o.c \
$$PWD/src/lzo1y_1.c \
$$PWD/src/lzo1y_9x.c \
$$PWD/src/lzo1y_d1.c \
$$PWD/src/lzo1y_d2.c \
$$PWD/src/lzo1y_d3.c \
$$PWD/src/lzo1y_o.c \
$$PWD/src/lzo1z_9x.c \
$$PWD/src/lzo1z_d1.c \
$$PWD/src/lzo1z_d2.c \
$$PWD/src/lzo1z_d3.c \
$$PWD/src/lzo2a_9x.c \
$$PWD/src/lzo2a_d1.c \
$$PWD/src/lzo2a_d2.c \
$$PWD/src/lzo_crc.c \
$$PWD/src/lzo_init.c \
$$PWD/src/lzo_ptr.c \
$$PWD/src/lzo_str.c \
$$PWD/src/lzo_util.c
HEADERS += \
$$PWD/include/lzo/lzo1.h \
$$PWD/include/lzo/lzo1x.h \
$$PWD/include/lzo/lzoconf.h \
$$PWD/include/lzo/lzodefs.h \
$$PWD/include/lzo/lzoutil.h
INCLUDEPATH += $$PWD/include

68
extern/lzo/src/lzo1.c vendored
View File

@@ -160,8 +160,10 @@ lzo1_info ( int *rbits, int *clevel )
{ {
if (rbits) if (rbits)
*rbits = RBITS; *rbits = RBITS;
if (clevel) if (clevel)
*clevel = CLEVEL; *clevel = CLEVEL;
return D_SIZE * lzo_sizeof(lzo_bytep); return D_SIZE * lzo_sizeof(lzo_bytep);
} }
@@ -203,6 +205,7 @@ lzo1_decompress ( const lzo_bytep in , lzo_uint in_len,
op = out; op = out;
ip = in; ip = in;
while (ip < ip_end) while (ip < ip_end)
{ {
t = *ip++; /* get marker */ t = *ip++; /* get marker */
@@ -212,9 +215,11 @@ lzo1_decompress ( const lzo_bytep in , lzo_uint in_len,
if (t == 0) /* a R0 literal run */ if (t == 0) /* a R0 literal run */
{ {
t = *ip++; t = *ip++;
if (t >= R0FAST - R0MIN) /* a long R0 run */ if (t >= R0FAST - R0MIN) /* a long R0 run */
{ {
t -= R0FAST - R0MIN; t -= R0FAST - R0MIN;
if (t == 0) if (t == 0)
t = R0FAST; t = R0FAST;
else else
@@ -224,15 +229,22 @@ lzo1_decompress ( const lzo_bytep in , lzo_uint in_len,
#else #else
/* help the optimizer */ /* help the optimizer */
lzo_uint tt = 256; lzo_uint tt = 256;
do tt <<= 1; while (--t > 0);
do tt <<= 1;
while (--t > 0);
t = tt; t = tt;
#endif #endif
} }
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
continue; continue;
} }
t += R0MIN; t += R0MIN;
} }
MEMCPY_DS(op, ip, t); MEMCPY_DS(op, ip, t);
} }
else /* a match */ else /* a match */
@@ -282,26 +294,33 @@ store_run(lzo_bytep op, const lzo_bytep ii, lzo_uint r_len)
if (r_len >= 512) if (r_len >= 512)
{ {
unsigned r_bits = 7; /* 256 << 7 == 32768 */ unsigned r_bits = 7; /* 256 << 7 == 32768 */
do {
do
{
while (r_len >= (256u << r_bits)) while (r_len >= (256u << r_bits))
{ {
r_len -= (256u << r_bits); r_len -= (256u << r_bits);
*op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits); *op++ = 0;
*op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
MEMCPY8_DS(op, ii, (256u << r_bits)); MEMCPY8_DS(op, ii, (256u << r_bits));
} }
} while (--r_bits > 0);
} }
while (--r_bits > 0);
}
while (r_len >= R0FAST) while (r_len >= R0FAST)
{ {
r_len -= R0FAST; r_len -= R0FAST;
*op++ = 0; *op++ = R0FAST - R0MIN; *op++ = 0;
*op++ = R0FAST - R0MIN;
MEMCPY8_DS(op, ii, R0FAST); MEMCPY8_DS(op, ii, R0FAST);
} }
if (r_len >= R0MIN) if (r_len >= R0MIN)
{ {
/* code a short R0 run */ /* code a short R0 run */
*op++ = 0; *op++ = LZO_BYTE(r_len - R0MIN); *op++ = 0;
*op++ = LZO_BYTE(r_len - R0MIN);
MEMCPY_DS(op, ii, r_len); MEMCPY_DS(op, ii, r_len);
} }
else if (r_len > 0) else if (r_len > 0)
@@ -348,6 +367,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len,
op = out; op = out;
ip = in; ip = in;
ii = ip; /* point to start of literal run */ ii = ip; /* point to start of literal run */
if (in_len <= MIN_MATCH_LONG + DVAL_LEN + 1) if (in_len <= MIN_MATCH_LONG + DVAL_LEN + 1)
goto the_end; goto the_end;
@@ -361,29 +381,38 @@ do_compress ( const lzo_bytep in , lzo_uint in_len,
ip++; ip++;
DVAL_NEXT(dv, ip); DVAL_NEXT(dv, ip);
do { do
{
LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0); LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
lzo_uint dindex; lzo_uint dindex;
DINDEX1(dindex, ip); DINDEX1(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS(m_pos, m_off, in, ip, MAX_OFFSET)) if (LZO_CHECK_MPOS(m_pos, m_off, in, ip, MAX_OFFSET))
goto literal; goto literal;
if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2]) if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2])
goto match; goto match;
DINDEX2(dindex, ip); DINDEX2(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS(m_pos, m_off, in, ip, MAX_OFFSET)) if (LZO_CHECK_MPOS(m_pos, m_off, in, ip, MAX_OFFSET))
goto literal; goto literal;
if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2]) if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2])
goto match; goto match;
goto literal; goto literal;
literal: literal:
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
if (++ip >= ip_end) if (++ip >= ip_end)
break; break;
continue; continue;
match: match:
@@ -397,11 +426,13 @@ match:
#if !defined(NDEBUG) && !(LZO_DICT_USE_PTR) #if !defined(NDEBUG) && !(LZO_DICT_USE_PTR)
assert((m_pos_sav = ip - m_off) == (m_pos - 3)); assert((m_pos_sav = ip - m_off) == (m_pos - 3));
#endif #endif
/* 1) store the current literal run */ /* 1) store the current literal run */
if (pd(ip, ii) > 0) if (pd(ip, ii) > 0)
{ {
lzo_uint t = pd(ip, ii); lzo_uint t = pd(ip, ii);
#if 1 #if 1
/* OPTIMIZED: inline the copying of a short run */ /* OPTIMIZED: inline the copying of a short run */
if (t < R0MIN) if (t < R0MIN)
{ {
@@ -427,6 +458,7 @@ match:
#define PS *m_pos++ != *ip++ #define PS *m_pos++ != *ip++
#if (MIN_MATCH_LONG - MIN_MATCH == 2) /* MBITS == 2 */ #if (MIN_MATCH_LONG - MIN_MATCH == 2) /* MBITS == 2 */
if (PS || PS) if (PS || PS)
#elif (MIN_MATCH_LONG - MIN_MATCH == 6) /* MBITS == 3 */ #elif (MIN_MATCH_LONG - MIN_MATCH == 6) /* MBITS == 3 */
if (PS || PS || PS || PS || PS || PS) if (PS || PS || PS || PS || PS || PS)
@@ -471,10 +503,14 @@ match:
#if (CLEVEL == 9) || (CLEVEL >= 7 && MBITS <= 4) || (CLEVEL >= 5 && MBITS <= 3) #if (CLEVEL == 9) || (CLEVEL >= 7 && MBITS <= 4) || (CLEVEL >= 5 && MBITS <= 3)
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
UPDATE_D(dict, 0, dv, ii, in); UPDATE_D(dict, 0, dv, ii, in);
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);
@@ -506,6 +542,7 @@ match:
while (ip < end && *m_pos == *ip) while (ip < end && *m_pos == *ip)
m_pos++, ip++; m_pos++, ip++;
assert(ip <= in_end); assert(ip <= in_end);
/* 2b) code the long match */ /* 2b) code the long match */
@@ -531,10 +568,14 @@ match:
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
/* This is not recommended because it is slow. */ /* This is not recommended because it is slow. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
UPDATE_D(dict, 0, dv, ii, in); UPDATE_D(dict, 0, dv, ii, in);
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);
@@ -560,7 +601,8 @@ match:
/* ii now points to the start of next literal run */ /* ii now points to the start of next literal run */
assert(ii == ip); assert(ii == ip);
} }
} while (ip < ip_end); }
while (ip < ip_end);
@@ -569,6 +611,7 @@ the_end:
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE) #if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
/* return -1 if op == out to indicate that we /* return -1 if op == out to indicate that we
* couldn't compress and didn't copy anything. * couldn't compress and didn't copy anything.
*/ */
@@ -577,6 +620,7 @@ the_end:
*out_len = 0; *out_len = 0;
return LZO_E_NOT_COMPRESSIBLE; return LZO_E_NOT_COMPRESSIBLE;
} }
#endif #endif

View File

@@ -108,8 +108,10 @@ lzo1a_info ( int *rbits, int *clevel )
{ {
if (rbits) if (rbits)
*rbits = RBITS; *rbits = RBITS;
if (clevel) if (clevel)
*clevel = CLEVEL; *clevel = CLEVEL;
return D_SIZE * lzo_sizeof(lzo_bytep); return D_SIZE * lzo_sizeof(lzo_bytep);
} }
@@ -135,6 +137,7 @@ lzo1a_decompress ( const lzo_bytep in , lzo_uint in_len,
op = out; op = out;
ip = in; ip = in;
while (ip < ip_end) while (ip < ip_end)
{ {
t = *ip++; /* get marker */ t = *ip++; /* get marker */
@@ -143,9 +146,11 @@ lzo1a_decompress ( const lzo_bytep in , lzo_uint in_len,
if (t == 0) /* a R0 literal run */ if (t == 0) /* a R0 literal run */
{ {
t = *ip++; t = *ip++;
if (t >= R0FAST - R0MIN) /* a long R0 run */ if (t >= R0FAST - R0MIN) /* a long R0 run */
{ {
t -= R0FAST - R0MIN; t -= R0FAST - R0MIN;
if (t == 0) if (t == 0)
t = R0FAST; t = R0FAST;
else else
@@ -155,13 +160,19 @@ lzo1a_decompress ( const lzo_bytep in , lzo_uint in_len,
#else #else
/* help the optimizer */ /* help the optimizer */
lzo_uint tt = 256; lzo_uint tt = 256;
do tt <<= 1; while (--t > 0);
do tt <<= 1;
while (--t > 0);
t = tt; t = tt;
#endif #endif
} }
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
continue; continue;
} }
t += R0MIN; t += R0MIN;
goto literal; goto literal;
} }
@@ -174,6 +185,7 @@ literal:
while (ip < ip_end) while (ip < ip_end)
{ {
t = *ip++; /* get R1 marker */ t = *ip++; /* get R1 marker */
if (t >= R0MIN) if (t >= R0MIN)
goto match; goto match;
@@ -181,7 +193,8 @@ literal:
assert((t & OMASK) == t); assert((t & OMASK) == t);
m_pos = op - MIN_OFFSET; m_pos = op - MIN_OFFSET;
m_pos -= t | (((lzo_uint) * ip++) << OBITS); m_pos -= t | (((lzo_uint) * ip++) << OBITS);
assert(m_pos >= out); assert(m_pos < op); assert(m_pos >= out);
assert(m_pos < op);
*op++ = m_pos[0]; *op++ = m_pos[0];
*op++ = m_pos[1]; *op++ = m_pos[1];
*op++ = m_pos[2]; *op++ = m_pos[2];
@@ -194,7 +207,8 @@ match:
/* get match offset */ /* get match offset */
m_pos = op - MIN_OFFSET; m_pos = op - MIN_OFFSET;
m_pos -= (t & OMASK) | (((lzo_uint) * ip++) << OBITS); m_pos -= (t & OMASK) | (((lzo_uint) * ip++) << OBITS);
assert(m_pos >= out); assert(m_pos < op); assert(m_pos >= out);
assert(m_pos < op);
/* get match len */ /* get match len */
if (t < ((MSIZE - 1) << OBITS)) /* a short match */ if (t < ((MSIZE - 1) << OBITS)) /* a short match */
@@ -217,9 +231,12 @@ match:
#if (LBITS < 8) #if (LBITS < 8)
/* a very short literal following a long match */ /* a very short literal following a long match */
t = ip[-1] >> LBITS; t = ip[-1] >> LBITS;
if (t) do if (t) do
*op++ = *ip++; *op++ = *ip++;
while (--t); while (--t);
#endif #endif
} }
} }
@@ -275,31 +292,42 @@ do_compress ( const lzo_bytep in , lzo_uint in_len,
BZERO8_PTR(wrkmem, sizeof(lzo_dict_t), D_SIZE); BZERO8_PTR(wrkmem, sizeof(lzo_dict_t), D_SIZE);
#endif #endif
DVAL_FIRST(dv,ip); UPDATE_D(dict,0,dv,ip,in); ip++; DVAL_FIRST(dv, ip);
UPDATE_D(dict, 0, dv, ip, in);
ip++;
DVAL_NEXT(dv, ip); DVAL_NEXT(dv, ip);
do { do
{
LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0); LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
lzo_uint dindex; lzo_uint dindex;
DINDEX1(dindex, ip); DINDEX1(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, MAX_OFFSET))
goto literal; goto literal;
if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2]) if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2])
goto match; goto match;
DINDEX2(dindex, ip); DINDEX2(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, MAX_OFFSET))
goto literal; goto literal;
if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2]) if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2])
goto match; goto match;
goto literal; goto literal;
literal: literal:
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
if (++ip >= ip_end) if (++ip >= ip_end)
break; break;
continue; continue;
match: match:
@@ -376,13 +404,15 @@ match:
{ {
/* inline the copying of a short R0 run */ /* inline the copying of a short R0 run */
LZO_STATS(lzo_stats->r0short_runs++); LZO_STATS(lzo_stats->r0short_runs++);
*op++ = 0; *op++ = LZO_BYTE(t - R0MIN); *op++ = 0;
*op++ = LZO_BYTE(t - R0MIN);
MEMCPY_DS(op, ii, t); MEMCPY_DS(op, ii, t);
r1 = ip; /* set new R1 pointer */ r1 = ip; /* set new R1 pointer */
} }
else else
op = store_run(op, ii, t); op = store_run(op, ii, t);
} }
#if (LBITS < 8) #if (LBITS < 8)
im = ip; im = ip;
#endif #endif
@@ -402,6 +432,7 @@ match:
#define PS *m_pos++ != *ip++ #define PS *m_pos++ != *ip++
#if (MIN_MATCH_LONG - MIN_MATCH == 2) /* MBITS == 2 */ #if (MIN_MATCH_LONG - MIN_MATCH == 2) /* MBITS == 2 */
if (PS || PS) if (PS || PS)
#elif (MIN_MATCH_LONG - MIN_MATCH == 6) /* MBITS == 3 */ #elif (MIN_MATCH_LONG - MIN_MATCH == 6) /* MBITS == 3 */
if (PS || PS || PS || PS || PS || PS) if (PS || PS || PS || PS || PS || PS)
@@ -443,12 +474,16 @@ match:
#if (LZO_COLLECT_STATS) #if (LZO_COLLECT_STATS)
lzo_stats->short_matches++; lzo_stats->short_matches++;
lzo_stats->short_match[m_len]++; lzo_stats->short_match[m_len]++;
if (m_off < OSIZE) if (m_off < OSIZE)
lzo_stats->short_match_offset_osize[m_len]++; lzo_stats->short_match_offset_osize[m_len]++;
if (m_off < 256) if (m_off < 256)
lzo_stats->short_match_offset_256[m_len]++; lzo_stats->short_match_offset_256[m_len]++;
if (m_off < 1024) if (m_off < 1024)
lzo_stats->short_match_offset_1024[m_len]++; lzo_stats->short_match_offset_1024[m_len]++;
#endif #endif
@@ -461,10 +496,14 @@ match:
#if (CLEVEL == 9) || (CLEVEL >= 7 && MBITS <= 4) || (CLEVEL >= 5 && MBITS <= 3) #if (CLEVEL == 9) || (CLEVEL >= 7 && MBITS <= 4) || (CLEVEL >= 5 && MBITS <= 3)
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
UPDATE_D(dict, 0, dv, ii, in); UPDATE_D(dict, 0, dv, ii, in);
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);
@@ -496,6 +535,7 @@ match:
while (ip < end && *m_pos == *ip) while (ip < end && *m_pos == *ip)
m_pos++, ip++; m_pos++, ip++;
assert(ip <= in_end); assert(ip <= in_end);
/* 2a) compute match parameters */ /* 2a) compute match parameters */
@@ -529,10 +569,14 @@ match:
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
/* This is not recommended because it is slow. */ /* This is not recommended because it is slow. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
UPDATE_D(dict, 0, dv, ii, in); UPDATE_D(dict, 0, dv, ii, in);
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);
@@ -559,12 +603,14 @@ match:
assert(ii == ip); assert(ii == ip);
} }
} while (ip < ip_end); }
while (ip < ip_end);
assert(ip <= in_end); assert(ip <= in_end);
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE) #if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
/* return -1 if op == out to indicate that we /* return -1 if op == out to indicate that we
* couldn't compress and didn't copy anything. * couldn't compress and didn't copy anything.
*/ */
@@ -573,6 +619,7 @@ match:
*out_len = 0; *out_len = 0;
return LZO_E_NOT_COMPRESSIBLE; return LZO_E_NOT_COMPRESSIBLE;
} }
#endif #endif
/* store the final literal run */ /* store the final literal run */

View File

@@ -108,7 +108,9 @@
#if (CLEVEL == 9) || (CLEVEL >= 7 && M2L_BITS <= 4) || (CLEVEL >= 5 && M2L_BITS <= 3) #if (CLEVEL == 9) || (CLEVEL >= 7 && M2L_BITS <= 4) || (CLEVEL >= 5 && M2L_BITS <= 3)
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
#if 0 #if 0
UPDATE_D(dict, drun, dv, ii, in); UPDATE_D(dict, drun, dv, ii, in);
@@ -116,7 +118,9 @@
dict[ DINDEX(dv, ii) ] = DENTRY(ii, in); dict[ DINDEX(dv, ii) ] = DENTRY(ii, in);
#endif #endif
MI MI
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);
@@ -155,6 +159,7 @@
while (ip < end && *m_pos == *ip) while (ip < end && *m_pos == *ip)
m_pos++, ip++; m_pos++, ip++;
assert(ip <= in_end); assert(ip <= in_end);
/* 2a) compute match parameters */ /* 2a) compute match parameters */
@@ -190,7 +195,9 @@
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
/* This is not recommended because it can be slow. */ /* This is not recommended because it can be slow. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
#if 0 #if 0
UPDATE_D(dict, drun, dv, ii, in); UPDATE_D(dict, drun, dv, ii, in);
@@ -198,7 +205,9 @@
dict[ DINDEX(dv, ii) ] = DENTRY(ii, in); dict[ DINDEX(dv, ii) ] = DENTRY(ii, in);
#endif #endif
MI MI
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);

View File

@@ -60,37 +60,48 @@ store_run(lzo_bytep const oo, const lzo_bytep const ii, lzo_uint r_len)
while (r_len >= (t = tt)) while (r_len >= (t = tt))
{ {
r_len -= t; r_len -= t;
*op++ = 0; *op++ = (R0MAX - R0MIN); *op++ = 0;
*op++ = (R0MAX - R0MIN);
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
LZO_STATS(lzo_stats->r0long_runs++); LZO_STATS(lzo_stats->r0long_runs++);
} }
tt >>= 1; tt >>= 1;
do {
do
{
if (r_len >= (t = tt)) if (r_len >= (t = tt))
{ {
r_len -= t; r_len -= t;
*op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits); *op++ = 0;
*op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
LZO_STATS(lzo_stats->r0long_runs++); LZO_STATS(lzo_stats->r0long_runs++);
} }
tt >>= 1; tt >>= 1;
} while (--r_bits > 0);
} }
while (--r_bits > 0);
}
assert(r_len < 512); assert(r_len < 512);
while (r_len >= (t = R0FAST)) while (r_len >= (t = R0FAST))
{ {
r_len -= t; r_len -= t;
*op++ = 0; *op++ = (R0FAST - R0MIN); *op++ = 0;
*op++ = (R0FAST - R0MIN);
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
LZO_STATS(lzo_stats->r0fast_runs++); LZO_STATS(lzo_stats->r0fast_runs++);
} }
t = r_len; t = r_len;
if (t >= R0MIN) if (t >= R0MIN)
{ {
/* code a short R0 run */ /* code a short R0 run */
*op++ = 0; *op++ = LZO_BYTE(t - R0MIN); *op++ = 0;
*op++ = LZO_BYTE(t - R0MIN);
MEMCPY_DS(op, ip, t); MEMCPY_DS(op, ip, t);
LZO_STATS(lzo_stats->r0short_runs++); LZO_STATS(lzo_stats->r0short_runs++);
} }

View File

@@ -71,6 +71,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
assert(m_off <= M3_MAX_OFFSET); assert(m_off <= M3_MAX_OFFSET);
m_off -= M3_MIN_OFFSET - M3_EOF_OFFSET; m_off -= M3_MIN_OFFSET - M3_EOF_OFFSET;
/* code match len */ /* code match len */
if (m_len <= M3_MAX_LEN) if (m_len <= M3_MAX_LEN)
*op++ = LZO_BYTE(M3_MARKER | (m_len - (M3_MIN_LEN - 1))); *op++ = LZO_BYTE(M3_MARKER | (m_len - (M3_MIN_LEN - 1)));
@@ -81,14 +82,17 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
*op++ = M4_MARKER; *op++ = M4_MARKER;
/* code match len */ /* code match len */
m_len -= M4_MIN_LEN - 1; m_len -= M4_MIN_LEN - 1;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
*op++ = 0; *op++ = 0;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
/* code low offset bits */ /* code low offset bits */
*op++ = LZO_BYTE(m_off & M3O_MASK); *op++ = LZO_BYTE(m_off & M3O_MASK);
/* code high offset bits */ /* code high offset bits */
@@ -97,6 +101,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
c->r1_m_len = 0; c->r1_m_len = 0;
c->m3_m++; c->m3_m++;
} }
return op; return op;
} }
@@ -143,14 +148,18 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
c->r1_m_len = 0; c->r1_m_len = 0;
r = init_match(c, swd, NULL, 0, 0); r = init_match(c, swd, NULL, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
if (max_chain > 0) if (max_chain > 0)
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, 0, 0); r = find_match(c, swd, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
while (c->look > 0) while (c->look > 0)
{ {
int lazy_match_min_gain = -1; int lazy_match_min_gain = -1;
@@ -165,8 +174,10 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
#endif #endif
assert(c->ip - c->look >= in); assert(c->ip - c->look >= in);
if (lit == 0) if (lit == 0)
ii = c->ip - c->look; ii = c->ip - c->look;
assert(ii + lit == c->ip - c->look); assert(ii + lit == c->ip - c->look);
assert(swd->b_char == *(c->ip - c->look)); assert(swd->b_char == *(c->ip - c->look));
@@ -192,20 +203,24 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
lazy_match_min_gain = 1; lazy_match_min_gain = 1;
#if (M2_MIN_LEN == 2) #if (M2_MIN_LEN == 2)
if (m_len == 2) if (m_len == 2)
{ {
/* don't code a match of len 2 if we have to /* don't code a match of len 2 if we have to
code a literal run. Code a literal instead. */ code a literal run. Code a literal instead. */
m_len = 0; m_len = 0;
} }
#endif #endif
#if (M2_MIN_LEN == M3_MIN_LEN) #if (M2_MIN_LEN == M3_MIN_LEN)
if (m_len == M2_MIN_LEN && m_off > M2_MAX_OFFSET) if (m_len == M2_MIN_LEN && m_off > M2_MAX_OFFSET)
{ {
/* don't code a M3 match of len 3 if we have to /* don't code a M3 match of len 3 if we have to
code a literal run. Code a literal instead. */ code a literal run. Code a literal instead. */
m_len = 0; m_len = 0;
} }
#endif #endif
} }
else else
@@ -223,12 +238,14 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* try a lazy match */ /* try a lazy match */
if (m_len == 0) if (m_len == 0)
lazy_match_min_gain = -1; lazy_match_min_gain = -1;
if (lazy_match_min_gain >= 0 && c->look > m_len) if (lazy_match_min_gain >= 0 && c->look > m_len)
{ {
assert(m_len > 0); assert(m_len > 0);
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
assert(c->look > 0); assert(c->look > 0);
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET && if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET &&
@@ -253,8 +270,10 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
ahead = 1; ahead = 1;
assert(ii + lit + 1 == c->ip - c->look); assert(ii + lit + 1 == c->ip - c->look);
} }
assert(m_len > 0); assert(m_len > 0);
} }
assert(ii + lit + ahead == c->ip - c->look); assert(ii + lit + ahead == c->ip - c->look);
@@ -263,7 +282,8 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* a literal */ /* a literal */
lit++; lit++;
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
else else
{ {
@@ -286,10 +306,12 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
{ {
op = STORE_RUN(op, ii, lit); op = STORE_RUN(op, ii, lit);
} }
if (lit < R0FAST) if (lit < R0FAST)
c->r1_m_len = m_len; c->r1_m_len = m_len;
else else
c->r1_m_len = 0; c->r1_m_len = 0;
lit = 0; lit = 0;
} }
else else
@@ -298,7 +320,8 @@ lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* 2 - code match */ /* 2 - code match */
op = code_match(c, op, m_len, m_off); op = code_match(c, op, m_len, m_off);
r = find_match(c, swd, m_len, 1 + ahead); r = find_match(c, swd, m_len, 1 + ahead);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
c->codesize = pd(op, out); c->codesize = pd(op, out);

View File

@@ -120,6 +120,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len,
#endif #endif
assert(ip < ip_end); assert(ip < ip_end);
for (;;) for (;;)
{ {
const lzo_bytep m_pos; const lzo_bytep m_pos;
@@ -162,8 +163,10 @@ literal:
#if (DD_BITS == 0) #if (DD_BITS == 0)
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
#endif #endif
if (++ip >= ip_end) if (++ip >= ip_end)
break; break;
#if (DD_BITS > 0) #if (DD_BITS > 0)
DVAL_NEXT(dv, ip); DVAL_NEXT(dv, ip);
#endif #endif
@@ -224,9 +227,11 @@ match:
for (i = 0; i < D_SIZE; i++) for (i = 0; i < D_SIZE; i++)
{ {
p = dict[i]; p = dict[i];
if (BOUNDS_CHECKING_OFF_IN_EXPR(p == NULL || p < in || p > in_end)) if (BOUNDS_CHECKING_OFF_IN_EXPR(p == NULL || p < in || p > in_end))
lzo_stats->unused_dict_entries++; lzo_stats->unused_dict_entries++;
} }
lzo_stats->unused_dict_entries_percent = lzo_stats->unused_dict_entries_percent =
100.0 * lzo_stats->unused_dict_entries / D_SIZE; 100.0 * lzo_stats->unused_dict_entries / D_SIZE;
} }
@@ -234,6 +239,7 @@ match:
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE) #if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
/* return if op == out to indicate that we /* return if op == out to indicate that we
* couldn't compress and didn't copy anything. * couldn't compress and didn't copy anything.
*/ */
@@ -242,6 +248,7 @@ match:
*out_len = 0; *out_len = 0;
return LZO_E_NOT_COMPRESSIBLE; return LZO_E_NOT_COMPRESSIBLE;
} }
#endif #endif
/* store the final literal run */ /* store the final literal run */

View File

@@ -74,9 +74,12 @@ _lzo1b_do_compress ( const lzo_bytep in, lzo_uint in_len,
#if defined(LZO_EOF_CODE) #if defined(LZO_EOF_CODE)
#if defined(LZO_TEST_COMPRESS_OVERRUN) #if defined(LZO_TEST_COMPRESS_OVERRUN)
if (r == LZO_E_OK && avail_out - *out_len < 3) if (r == LZO_E_OK && avail_out - *out_len < 3)
r = LZO_E_COMPRESS_OVERRUN; r = LZO_E_COMPRESS_OVERRUN;
#endif #endif
if (r == LZO_E_OK) if (r == LZO_E_OK)
{ {
lzo_bytep op = out + *out_len; lzo_bytep op = out + *out_len;
@@ -85,6 +88,7 @@ _lzo1b_do_compress ( const lzo_bytep in, lzo_uint in_len,
op[2] = 0; op[2] = 0;
*out_len += 3; *out_len += 3;
} }
#endif #endif

View File

@@ -86,6 +86,7 @@
/* 2b) code the match */ /* 2b) code the match */
#if (_M2_MAX_OFFSET != _M3_MAX_OFFSET) #if (_M2_MAX_OFFSET != _M3_MAX_OFFSET)
if (m_off <= M2_MAX_OFFSET) if (m_off <= M2_MAX_OFFSET)
{ {
#else #else
@@ -122,6 +123,7 @@
m3 = op; /* set M3 pointer */ m3 = op; /* set M3 pointer */
#endif #endif
} }
#endif /* (_M2_MAX_OFFSET != _M3_MAX_OFFSET) */ #endif /* (_M2_MAX_OFFSET != _M3_MAX_OFFSET) */
@@ -137,7 +139,9 @@
#if (CLEVEL == 9) || (CLEVEL >= 7 && M2L_BITS <= 4) || (CLEVEL >= 5 && M2L_BITS <= 3) #if (CLEVEL == 9) || (CLEVEL >= 7 && M2L_BITS <= 4) || (CLEVEL >= 5 && M2L_BITS <= 3)
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
#if 0 #if 0
UPDATE_D(dict, drun, dv, ii, in); UPDATE_D(dict, drun, dv, ii, in);
@@ -145,7 +149,9 @@
dict[ DINDEX(dv, ii) ] = DENTRY(ii, in); dict[ DINDEX(dv, ii) ] = DENTRY(ii, in);
#endif #endif
MI MI
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);
@@ -176,8 +182,10 @@
{ {
const lzo_bytep end; const lzo_bytep end;
end = in_end; end = in_end;
while (ip < end && *m_pos == *ip) while (ip < end && *m_pos == *ip)
m_pos++, ip++; m_pos++, ip++;
assert(ip <= in_end); assert(ip <= in_end);
m_len = pd(ip, ii); m_len = pd(ip, ii);
} }
@@ -209,11 +217,13 @@
*op++ = M4_MARKER; *op++ = M4_MARKER;
/* code match len */ /* code match len */
m_len -= M4_MIN_LEN - 1; m_len -= M4_MIN_LEN - 1;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
*op++ = 0; *op++ = 0;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
LZO_STATS(lzo_stats->m4_matches++); LZO_STATS(lzo_stats->m4_matches++);
@@ -242,7 +252,9 @@
/* Insert the whole match (ii+1)..(ip-1) into dictionary. */ /* Insert the whole match (ii+1)..(ip-1) into dictionary. */
/* This is not recommended because it can be slow. */ /* This is not recommended because it can be slow. */
++ii; ++ii;
do {
do
{
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
#if 0 #if 0
UPDATE_D(dict, drun, dv, ii, in); UPDATE_D(dict, drun, dv, ii, in);
@@ -250,7 +262,9 @@
dict[ DINDEX(dv, ii) ] = DENTRY(ii, in); dict[ DINDEX(dv, ii) ] = DENTRY(ii, in);
#endif #endif
MI MI
} while (++ii < ip); }
while (++ii < ip);
DVAL_NEXT(dv, ii); DVAL_NEXT(dv, ii);
assert(ii == ip); assert(ii == ip);
DVAL_ASSERT(dv, ip); DVAL_ASSERT(dv, ip);

View File

@@ -38,11 +38,13 @@
************************************************************************/ ************************************************************************/
assert(ip < ip_end); assert(ip < ip_end);
if (pd(ip, ii) > 0) if (pd(ip, ii) > 0)
{ {
lzo_uint t = pd(ip, ii); lzo_uint t = pd(ip, ii);
#if defined(LZO_HAVE_R1) #if defined(LZO_HAVE_R1)
if (ip == r1) if (ip == r1)
{ {
/* Code a context sensitive R1 match. */ /* Code a context sensitive R1 match. */
@@ -66,6 +68,7 @@
LZO_STATS(lzo_stats->lit_runs++); LZO_STATS(lzo_stats->lit_runs++);
LZO_STATS(lzo_stats->lit_run[t]++); LZO_STATS(lzo_stats->lit_run[t]++);
#if defined(LZO_HAVE_M3) #if defined(LZO_HAVE_M3)
if (t < LZO_SIZE(8 - M3O_BITS) && op == m3) if (t < LZO_SIZE(8 - M3O_BITS) && op == m3)
{ {
/* Code a very short literal run into the low offset bits /* Code a very short literal run into the low offset bits
@@ -81,6 +84,7 @@
{ {
*op++ = LZO_BYTE(t); *op++ = LZO_BYTE(t);
} }
MEMCPY_DS(op, ii, t); MEMCPY_DS(op, ii, t);
#if defined(LZO_HAVE_R1) #if defined(LZO_HAVE_R1)
r1 = ip + (M2_MIN_LEN + 1); /* set new R1 pointer */ r1 = ip + (M2_MIN_LEN + 1); /* set new R1 pointer */
@@ -91,7 +95,8 @@
/* inline the copying of a short R0 run */ /* inline the copying of a short R0 run */
LZO_STATS(lzo_stats->literals += t); LZO_STATS(lzo_stats->literals += t);
LZO_STATS(lzo_stats->r0short_runs++); LZO_STATS(lzo_stats->r0short_runs++);
*op++ = 0; *op++ = LZO_BYTE(t - R0MIN); *op++ = 0;
*op++ = LZO_BYTE(t - R0MIN);
MEMCPY_DS(op, ii, t); MEMCPY_DS(op, ii, t);
#if defined(LZO_HAVE_R1) #if defined(LZO_HAVE_R1)
r1 = ip + (M2_MIN_LEN + 1); /* set new R1 pointer */ r1 = ip + (M2_MIN_LEN + 1); /* set new R1 pointer */

View File

@@ -63,9 +63,11 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
{ {
NEED_IP(1); NEED_IP(1);
t = *ip++; t = *ip++;
if (t >= R0FAST - R0MIN) /* a long R0 run */ if (t >= R0FAST - R0MIN) /* a long R0 run */
{ {
t -= R0FAST - R0MIN; t -= R0FAST - R0MIN;
if (t == 0) if (t == 0)
t = R0FAST; t = R0FAST;
else else
@@ -75,37 +77,57 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
#else #else
/* help the optimizer */ /* help the optimizer */
lzo_uint tt = 256; lzo_uint tt = 256;
do tt <<= 1; while (--t > 0);
do tt <<= 1;
while (--t > 0);
t = tt; t = tt;
#endif #endif
} }
NEED_IP(t); NEED_OP(t); NEED_IP(t);
NEED_OP(t);
#if 1 && (LZO_OPT_UNALIGNED32) #if 1 && (LZO_OPT_UNALIGNED32)
do {
do
{
UA_COPY4(op + 0, ip + 0); UA_COPY4(op + 0, ip + 0);
UA_COPY4(op + 4, ip + 4); UA_COPY4(op + 4, ip + 4);
op += 8; ip += 8; op += 8;
ip += 8;
t -= 8; t -= 8;
} while (t > 0); }
while (t > 0);
#else #else
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
#endif #endif
continue; continue;
} }
t += R0MIN; /* a short R0 run */ t += R0MIN; /* a short R0 run */
} }
NEED_IP(t); NEED_OP(t); NEED_IP(t);
NEED_OP(t);
/* copy literal run */ /* copy literal run */
#if 1 && (LZO_OPT_UNALIGNED32) #if 1 && (LZO_OPT_UNALIGNED32)
if (t >= 4) if (t >= 4)
{ {
do { do
{
UA_COPY4(op, ip); UA_COPY4(op, ip);
op += 4; ip += 4; t -= 4; op += 4;
} while (t >= 4); ip += 4;
if (t > 0) do *op++ = *ip++; while (--t > 0); t -= 4;
}
while (t >= 4);
if (t > 0) do* op++ = *ip++;
while (--t > 0);
} }
else else
#endif #endif
@@ -113,7 +135,10 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
#if (M3O_BITS < 7) #if (M3O_BITS < 7)
literal1: literal1:
#endif #endif
do *op++ = *ip++; while (--t > 0);
do* op++ = *ip++;
while (--t > 0);
} }
#if (M3O_BITS == 7) #if (M3O_BITS == 7)
@@ -124,16 +149,19 @@ literal2:
while (TEST_IP_AND_TEST_OP) while (TEST_IP_AND_TEST_OP)
{ {
t = *ip++; /* get R1 marker */ t = *ip++; /* get R1 marker */
if (t >= R0MIN) if (t >= R0MIN)
goto match; goto match;
NEED_IP(2); NEED_OP(M2_MIN_LEN + 1); NEED_IP(2);
NEED_OP(M2_MIN_LEN + 1);
/* R1 match - a M2_MIN_LEN match + 1 byte literal */ /* R1 match - a M2_MIN_LEN match + 1 byte literal */
assert((t & M2O_MASK) == t); assert((t & M2O_MASK) == t);
m_pos = op - M2_MIN_OFFSET; m_pos = op - M2_MIN_OFFSET;
m_pos -= t | (((lzo_uint) * ip++) << M2O_BITS); m_pos -= t | (((lzo_uint) * ip++) << M2O_BITS);
assert(m_pos >= out); assert(m_pos < op); assert(m_pos >= out);
assert(m_pos < op);
TEST_LB(m_pos); TEST_LB(m_pos);
COPY_M2; COPY_M2;
*op++ = *ip++; *op++ = *ip++;
@@ -152,7 +180,8 @@ match:
NEED_IP(1); NEED_IP(1);
m_pos = op - M2_MIN_OFFSET; m_pos = op - M2_MIN_OFFSET;
m_pos -= (t & M2O_MASK) | (((lzo_uint) * ip++) << M2O_BITS); m_pos -= (t & M2O_MASK) | (((lzo_uint) * ip++) << M2O_BITS);
assert(m_pos >= out); assert(m_pos < op); assert(m_pos >= out);
assert(m_pos < op);
TEST_LB(m_pos); TEST_LB(m_pos);
/* get match len */ /* get match len */
@@ -165,9 +194,11 @@ match:
{ {
/* get match len */ /* get match len */
t &= M3L_MASK; t &= M3L_MASK;
if (t == 0) /* a M4 match */ if (t == 0) /* a M4 match */
{ {
NEED_IP(1); NEED_IP(1);
while (*ip == 0) while (*ip == 0)
{ {
t += 255; t += 255;
@@ -175,6 +206,7 @@ match:
TEST_OV(t); TEST_OV(t);
NEED_IP(1); NEED_IP(1);
} }
t += (M4_MIN_LEN - M3_MIN_LEN) + *ip++; t += (M4_MIN_LEN - M3_MIN_LEN) + *ip++;
} }
@@ -184,23 +216,38 @@ match:
m_pos -= *ip++ & M3O_MASK; m_pos -= *ip++ & M3O_MASK;
m_pos -= (lzo_uint)(*ip++) << M3O_BITS; m_pos -= (lzo_uint)(*ip++) << M3O_BITS;
#if defined(LZO_EOF_CODE) #if defined(LZO_EOF_CODE)
if (m_pos == op) if (m_pos == op)
goto eof_found; goto eof_found;
#endif #endif
/* copy match */ /* copy match */
assert(m_pos >= out); assert(m_pos < op); assert(m_pos >= out);
TEST_LB(m_pos); NEED_OP(t + M3_MIN_LEN - 1); assert(m_pos < op);
TEST_LB(m_pos);
NEED_OP(t + M3_MIN_LEN - 1);
#if (LZO_OPT_UNALIGNED32) #if (LZO_OPT_UNALIGNED32)
if (t >= 2 * 4 - (M3_MIN_LEN - 1) && (op - m_pos) >= 4) if (t >= 2 * 4 - (M3_MIN_LEN - 1) && (op - m_pos) >= 4)
{ {
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4 - (M3_MIN_LEN - 1); op += 4;
do { m_pos += 4;
t -= 4 - (M3_MIN_LEN - 1);
do
{
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4; op += 4;
} while (t >= 4); m_pos += 4;
if (t > 0) do *op++ = *m_pos++; while (--t > 0); t -= 4;
}
while (t >= 4);
if (t > 0) do* op++ = *m_pos++;
while (--t > 0);
} }
else else
#endif #endif
@@ -212,19 +259,25 @@ match:
#if (M3O_BITS < 7) #if (M3O_BITS < 7)
t = ip[-2] >> M3O_BITS; t = ip[-2] >> M3O_BITS;
if (t) if (t)
{ {
NEED_IP(t); NEED_OP(t); NEED_IP(t);
NEED_OP(t);
goto literal1; goto literal1;
} }
#elif (M3O_BITS == 7) #elif (M3O_BITS == 7)
/* optimized version */ /* optimized version */
if (ip[-2] & (1 << M3O_BITS)) if (ip[-2] & (1 << M3O_BITS))
{ {
NEED_IP(1); NEED_OP(1); NEED_IP(1);
NEED_OP(1);
*op++ = *ip++; *op++ = *ip++;
goto literal2; goto literal2;
} }
#endif #endif
} }
} }

View File

@@ -52,37 +52,48 @@ STORE_RUN ( lzo_bytep const oo, const lzo_bytep const ii, lzo_uint r_len)
while (r_len >= (t = tt)) while (r_len >= (t = tt))
{ {
r_len -= t; r_len -= t;
*op++ = 0; *op++ = (R0FAST - R0MIN) + 7; *op++ = 0;
*op++ = (R0FAST - R0MIN) + 7;
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
LZO_STATS(lzo_stats->r0long_runs++); LZO_STATS(lzo_stats->r0long_runs++);
} }
tt >>= 1; tt >>= 1;
do {
do
{
if (r_len >= (t = tt)) if (r_len >= (t = tt))
{ {
r_len -= t; r_len -= t;
*op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits); *op++ = 0;
*op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
LZO_STATS(lzo_stats->r0long_runs++); LZO_STATS(lzo_stats->r0long_runs++);
} }
tt >>= 1; tt >>= 1;
} while (--r_bits > 0);
} }
while (--r_bits > 0);
}
assert(r_len < 512); assert(r_len < 512);
while (r_len >= (t = R0FAST)) while (r_len >= (t = R0FAST))
{ {
r_len -= t; r_len -= t;
*op++ = 0; *op++ = (R0FAST - R0MIN); *op++ = 0;
*op++ = (R0FAST - R0MIN);
MEMCPY8_DS(op, ip, t); MEMCPY8_DS(op, ip, t);
LZO_STATS(lzo_stats->r0fast_runs++); LZO_STATS(lzo_stats->r0fast_runs++);
} }
t = r_len; t = r_len;
if (t >= R0MIN) if (t >= R0MIN)
{ {
/* code a short R0 run */ /* code a short R0 run */
*op++ = 0; *op++ = LZO_BYTE(t - R0MIN); *op++ = 0;
*op++ = LZO_BYTE(t - R0MIN);
MEMCPY_DS(op, ip, t); MEMCPY_DS(op, ip, t);
LZO_STATS(lzo_stats->r0short_runs++); LZO_STATS(lzo_stats->r0short_runs++);
} }

View File

@@ -42,18 +42,25 @@
/* search ip in the dictionary */ /* search ip in the dictionary */
DINDEX1(dindex, ip); DINDEX1(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET))
goto literal; goto literal;
#if 1 #if 1
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match; goto try_match;
DINDEX2(dindex, ip); DINDEX2(dindex, ip);
#endif #endif
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET))
goto literal; goto literal;
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match; goto try_match;
goto literal; goto literal;
@@ -73,7 +80,9 @@
ip_sav = ip; ip_sav = ip;
m_len = 0; m_len = 0;
do {
do
{
#if !defined(NDEBUG) #if !defined(NDEBUG)
const lzo_bytep z_pos = NULL; const lzo_bytep z_pos = NULL;
#endif #endif
@@ -92,6 +101,7 @@
if (LZO_CHECK_MPOS(m_pos, x_off, in, ip, MAX_OFFSET)) if (LZO_CHECK_MPOS(m_pos, x_off, in, ip, MAX_OFFSET))
#if (CLEVEL == 9) #if (CLEVEL == 9)
*d = DENTRY(ip, in); *d = DENTRY(ip, in);
#else #else
((void)(0)); ((void)(0));
#endif #endif
@@ -102,16 +112,19 @@
#if !(LZO_DICT_USE_PTR) #if !(LZO_DICT_USE_PTR)
assert((z_pos = ip - 3 - x_off) == (m_pos - 3)); assert((z_pos = ip - 3 - x_off) == (m_pos - 3));
#endif #endif
/* a match */ /* a match */
if (MATCH_M2) if (MATCH_M2)
{ {
x_len = pd((ip - 1), ip_sav); x_len = pd((ip - 1), ip_sav);
if (x_len > m_len) if (x_len > m_len)
{ {
m_len = x_len; m_len = x_len;
m_off = x_off; m_off = x_off;
assert((m_pos_sav = z_pos) != NULL); assert((m_pos_sav = z_pos) != NULL);
} }
#if (CLEVEL == 9) #if (CLEVEL == 9)
/* try to find a closer match */ /* try to find a closer match */
else if (x_len == m_len && x_off < m_off) else if (x_len == m_len && x_off < m_off)
@@ -119,6 +132,7 @@
m_off = x_off; m_off = x_off;
assert((m_pos_sav = z_pos) != NULL); assert((m_pos_sav = z_pos) != NULL);
} }
#endif #endif
} }
else else
@@ -129,16 +143,20 @@
{ {
const lzo_bytep end; const lzo_bytep end;
end = MATCH_IP_END; end = MATCH_IP_END;
while (ip < end && *m_pos == *ip) while (ip < end && *m_pos == *ip)
m_pos++, ip++; m_pos++, ip++;
assert(ip <= in_end); assert(ip <= in_end);
x_len = pd(ip, ip_sav); x_len = pd(ip, ip_sav);
} }
if (x_len > m_len) if (x_len > m_len)
{ {
m_len = x_len; m_len = x_len;
m_off = x_off; m_off = x_off;
assert((m_pos_sav = z_pos) != NULL); assert((m_pos_sav = z_pos) != NULL);
if (ip >= MATCH_IP_END) if (ip >= MATCH_IP_END)
{ {
ip = ip_sav; ip = ip_sav;
@@ -156,7 +174,9 @@
m_off = x_off; m_off = x_off;
assert((m_pos_sav = z_pos) != NULL); assert((m_pos_sav = z_pos) != NULL);
} }
#else #else
/* try to find a closer match */ /* try to find a closer match */
if (m_len < M2_MAX_LEN + 1 || x_off < m_off) if (m_len < M2_MAX_LEN + 1 || x_off < m_off)
{ {
@@ -164,6 +184,7 @@
m_off = x_off; m_off = x_off;
assert((m_pos_sav = z_pos) != NULL); assert((m_pos_sav = z_pos) != NULL);
} }
#endif #endif
#else #else
/* don't search for a longer/closer match */ /* don't search for a longer/closer match */
@@ -177,12 +198,16 @@
goto match; goto match;
#endif #endif
} }
ip = ip_sav; ip = ip_sav;
} }
else else
ip = ip_sav; ip = ip_sav;
d++; d++;
} while (--j > 0); }
while (--j > 0);
assert(ip == ip_sav); assert(ip == ip_sav);
d -= DD_SIZE; d -= DD_SIZE;

View File

@@ -48,6 +48,7 @@ try_match:
#endif #endif
m_pos_sav = m_pos; m_pos_sav = m_pos;
#endif #endif
if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2]) if (m_pos[0] == ip[0] && m_pos[1] == ip[1] && m_pos[2] == ip[2])
{ {
m_pos += 3; m_pos += 3;
@@ -62,19 +63,25 @@ try_match:
if (m_len > M2_MIN_LEN) if (m_len > M2_MIN_LEN)
goto match; goto match;
if (m_len == M2_MIN_LEN) if (m_len == M2_MIN_LEN)
{ {
#if (_MAX_OFFSET == _M2_MAX_OFFSET) #if (_MAX_OFFSET == _M2_MAX_OFFSET)
goto match; goto match;
#else #else
if (m_off <= M2_MAX_OFFSET) if (m_off <= M2_MAX_OFFSET)
goto match; goto match;
#if 0 && (M3_MIN_LEN == M2_MIN_LEN) #if 0 && (M3_MIN_LEN == M2_MIN_LEN)
if (ip == ii) if (ip == ii)
goto match; goto match;
#endif #endif
#endif #endif
} }
goto literal; goto literal;

View File

@@ -58,6 +58,7 @@ static lzo_compress_t lzo1b_get_compress_func(int clevel)
else else
return (lzo_compress_t) 0; return (lzo_compress_t) 0;
} }
f = c_funcs[clevel - 1]; f = c_funcs[clevel - 1];
assert(f && *f); assert(f && *f);
return *f; return *f;
@@ -73,8 +74,10 @@ lzo1b_compress ( const lzo_bytep src, lzo_uint src_len,
lzo_compress_t f; lzo_compress_t f;
f = lzo1b_get_compress_func(clevel); f = lzo1b_get_compress_func(clevel);
if (!f) if (!f)
return LZO_E_ERROR; return LZO_E_ERROR;
return _lzo1b_do_compress(src, src_len, dst, dst_len, wrkmem, f); return _lzo1b_do_compress(src, src_len, dst, dst_len, wrkmem, f);
} }

View File

@@ -71,6 +71,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
assert(m_off <= M3_MAX_OFFSET); assert(m_off <= M3_MAX_OFFSET);
m_off -= M3_MIN_OFFSET - M3_EOF_OFFSET; m_off -= M3_MIN_OFFSET - M3_EOF_OFFSET;
/* code match len */ /* code match len */
if (m_len <= M3_MAX_LEN) if (m_len <= M3_MAX_LEN)
*op++ = LZO_BYTE(M3_MARKER | (m_len - (M3_MIN_LEN - 1))); *op++ = LZO_BYTE(M3_MARKER | (m_len - (M3_MIN_LEN - 1)));
@@ -81,14 +82,17 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
*op++ = M4_MARKER; *op++ = M4_MARKER;
/* code match len */ /* code match len */
m_len -= M4_MIN_LEN - 1; m_len -= M4_MIN_LEN - 1;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
*op++ = 0; *op++ = 0;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
/* code low offset bits */ /* code low offset bits */
*op++ = LZO_BYTE(m_off & M3O_MASK); *op++ = LZO_BYTE(m_off & M3O_MASK);
/* code high offset bits */ /* code high offset bits */
@@ -98,6 +102,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
c->m3 = op; c->m3 = op;
c->m3_m++; c->m3_m++;
} }
return op; return op;
} }
@@ -145,14 +150,18 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
c->m3 = out + 1; /* pointer after last m3/m4 match */ c->m3 = out + 1; /* pointer after last m3/m4 match */
r = init_match(c, swd, NULL, 0, 0); r = init_match(c, swd, NULL, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
if (max_chain > 0) if (max_chain > 0)
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, 0, 0); r = find_match(c, swd, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
while (c->look > 0) while (c->look > 0)
{ {
int lazy_match_min_gain = -1; int lazy_match_min_gain = -1;
@@ -167,8 +176,10 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
#endif #endif
assert(c->ip - c->look >= in); assert(c->ip - c->look >= in);
if (lit == 0) if (lit == 0)
ii = c->ip - c->look; ii = c->ip - c->look;
assert(ii + lit == c->ip - c->look); assert(ii + lit == c->ip - c->look);
assert(swd->b_char == *(c->ip - c->look)); assert(swd->b_char == *(c->ip - c->look));
@@ -198,20 +209,24 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
lazy_match_min_gain = 1; lazy_match_min_gain = 1;
#if (M2_MIN_LEN == 2) #if (M2_MIN_LEN == 2)
if (m_len == 2) if (m_len == 2)
{ {
/* don't code a match of len 2 if we have to /* don't code a match of len 2 if we have to
code a literal run. Code a literal instead. */ code a literal run. Code a literal instead. */
m_len = 0; m_len = 0;
} }
#endif #endif
#if (M2_MIN_LEN == M3_MIN_LEN) #if (M2_MIN_LEN == M3_MIN_LEN)
if (m_len == M2_MIN_LEN && m_off > M2_MAX_OFFSET) if (m_len == M2_MIN_LEN && m_off > M2_MAX_OFFSET)
{ {
/* don't code a M3 match of len 3 if we have to /* don't code a M3 match of len 3 if we have to
code a literal run. Code a literal instead. */ code a literal run. Code a literal instead. */
m_len = 0; m_len = 0;
} }
#endif #endif
} }
else else
@@ -229,12 +244,14 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* try a lazy match */ /* try a lazy match */
if (m_len == 0) if (m_len == 0)
lazy_match_min_gain = -1; lazy_match_min_gain = -1;
if (lazy_match_min_gain >= 0 && c->look > m_len) if (lazy_match_min_gain >= 0 && c->look > m_len)
{ {
assert(m_len > 0); assert(m_len > 0);
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
assert(c->look > 0); assert(c->look > 0);
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET && if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET &&
@@ -259,8 +276,10 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
ahead = 1; ahead = 1;
assert(ii + lit + 1 == c->ip - c->look); assert(ii + lit + 1 == c->ip - c->look);
} }
assert(m_len > 0); assert(m_len > 0);
} }
assert(ii + lit + ahead == c->ip - c->look); assert(ii + lit + ahead == c->ip - c->look);
@@ -269,7 +288,8 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* a literal */ /* a literal */
lit++; lit++;
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
else else
{ {
@@ -300,10 +320,12 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
{ {
op = STORE_RUN(op, ii, lit); op = STORE_RUN(op, ii, lit);
} }
if (lit < R0FAST) if (lit < R0FAST)
c->r1_m_len = m_len; c->r1_m_len = m_len;
else else
c->r1_m_len = 0; c->r1_m_len = 0;
lit = 0; lit = 0;
} }
else else
@@ -312,7 +334,8 @@ lzo1c_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* 2 - code match */ /* 2 - code match */
op = code_match(c, op, m_len, m_off); op = code_match(c, op, m_len, m_off);
r = find_match(c, swd, m_len, 1 + ahead); r = find_match(c, swd, m_len, 1 + ahead);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
c->codesize = pd(op, out); c->codesize = pd(op, out);

View File

@@ -74,9 +74,12 @@ _lzo1c_do_compress ( const lzo_bytep in, lzo_uint in_len,
#if defined(LZO_EOF_CODE) #if defined(LZO_EOF_CODE)
#if defined(LZO_TEST_COMPRESS_OVERRUN) #if defined(LZO_TEST_COMPRESS_OVERRUN)
if (r == LZO_E_OK && avail_out - *out_len < 3) if (r == LZO_E_OK && avail_out - *out_len < 3)
r = LZO_E_COMPRESS_OVERRUN; r = LZO_E_COMPRESS_OVERRUN;
#endif #endif
if (r == LZO_E_OK) if (r == LZO_E_OK)
{ {
lzo_bytep op = out + *out_len; lzo_bytep op = out + *out_len;
@@ -85,6 +88,7 @@ _lzo1c_do_compress ( const lzo_bytep in, lzo_uint in_len,
op[2] = 0; op[2] = 0;
*out_len += 3; *out_len += 3;
} }
#endif #endif

View File

@@ -58,6 +58,7 @@ static lzo_compress_t lzo1c_get_compress_func(int clevel)
else else
return (lzo_compress_t) 0; return (lzo_compress_t) 0;
} }
f = c_funcs[clevel - 1]; f = c_funcs[clevel - 1];
assert(f && *f); assert(f && *f);
return *f; return *f;
@@ -73,8 +74,10 @@ lzo1c_compress ( const lzo_bytep src, lzo_uint src_len,
lzo_compress_t f; lzo_compress_t f;
f = lzo1c_get_compress_func(clevel); f = lzo1c_get_compress_func(clevel);
if (!f) if (!f)
return LZO_E_ERROR; return LZO_E_ERROR;
return _lzo1c_do_compress(src, src_len, dst, dst_len, wrkmem, f); return _lzo1c_do_compress(src, src_len, dst, dst_len, wrkmem, f);
} }

View File

@@ -69,6 +69,7 @@ int do_compress ( const lzo_bytep in , lzo_uint in_len,
ii = ip; ii = ip;
ip++; ip++;
for (;;) for (;;)
{ {
const lzo_bytep m_pos; const lzo_bytep m_pos;
@@ -79,23 +80,31 @@ int do_compress ( const lzo_bytep in , lzo_uint in_len,
DINDEX1(dindex, ip); DINDEX1(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET))
goto literal; goto literal;
#if 1 #if 1
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match; goto try_match;
DINDEX2(dindex, ip); DINDEX2(dindex, ip);
#endif #endif
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M3_MAX_OFFSET))
goto literal; goto literal;
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match; goto try_match;
goto literal; goto literal;
try_match: try_match:
#if 0 && (LZO_OPT_UNALIGNED16) #if 0 && (LZO_OPT_UNALIGNED16)
if (UA_GET_NE16(m_pos) != UA_GET_NE16(ip)) if (UA_GET_NE16(m_pos) != UA_GET_NE16(ip))
#else #else
if (m_pos[0] != ip[0] || m_pos[1] != ip[1]) if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
@@ -108,16 +117,23 @@ try_match:
{ {
m_pos += 3; m_pos += 3;
#if 0 #if 0
if (m_off <= M2_MAX_OFFSET) if (m_off <= M2_MAX_OFFSET)
goto match; goto match;
if (lit <= 3) if (lit <= 3)
goto match; goto match;
if (lit == 3) /* better compression, but slower */ if (lit == 3) /* better compression, but slower */
{ {
assert(op - 2 > out); op[-2] |= LZO_BYTE(3); assert(op - 2 > out);
*op++ = *ii++; *op++ = *ii++; *op++ = *ii++; op[-2] |= LZO_BYTE(3);
*op++ = *ii++;
*op++ = *ii++;
*op++ = *ii++;
goto code_match; goto code_match;
} }
if (*m_pos == ip[3]) if (*m_pos == ip[3])
#endif #endif
goto match; goto match;
@@ -128,8 +144,10 @@ try_match:
/* a literal */ /* a literal */
literal: literal:
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
if (++ip >= ip_end) if (++ip >= ip_end)
break; break;
continue; continue;
@@ -138,6 +156,7 @@ match:
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
/* store current literal run */ /* store current literal run */
lit = pd(ip, ii); lit = pd(ip, ii);
if (lit > 0) if (lit > 0)
{ {
lzo_uint t = lit; lzo_uint t = lit;
@@ -151,28 +170,36 @@ match:
lzo_uint tt = t - 31; lzo_uint tt = t - 31;
*op++ = 0; *op++ = 0;
while (tt > 255) while (tt > 255)
{ {
tt -= 255; tt -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
assert(tt > 0); assert(tt > 0);
*op++ = LZO_BYTE(tt); *op++ = LZO_BYTE(tt);
} }
do *op++ = *ii++; while (--t > 0);
do* op++ = *ii++;
while (--t > 0);
} }
assert(ii == ip); assert(ii == ip);
/* code the match */ /* code the match */
ip += 3; ip += 3;
if (*m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++ || if (*m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++ ||
*m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++) *m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++)
{ {
--ip; --ip;
m_len = pd(ip, ii); m_len = pd(ip, ii);
assert(m_len >= 3); assert(m_len <= 8); assert(m_len >= 3);
assert(m_len <= 8);
if (m_off <= M2_MAX_OFFSET) if (m_off <= M2_MAX_OFFSET)
{ {
@@ -199,8 +226,10 @@ match:
{ {
const lzo_bytep end; const lzo_bytep end;
end = in_end; end = in_end;
while (ip < end && *m_pos == *ip) while (ip < end && *m_pos == *ip)
m_pos++, ip++; m_pos++, ip++;
m_len = pd(ip, ii); m_len = pd(ip, ii);
} }
assert(m_len >= 3); assert(m_len >= 3);
@@ -211,20 +240,24 @@ match:
{ {
m_len -= 33; m_len -= 33;
*op++ = M3_MARKER | 0; *op++ = M3_MARKER | 0;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
*op++ = LZO_BYTE((m_off & 63) << 2); *op++ = LZO_BYTE((m_off & 63) << 2);
*op++ = LZO_BYTE(m_off >> 6); *op++ = LZO_BYTE(m_off >> 6);
} }
ii = ip; ii = ip;
if (ip >= ip_end) if (ip >= ip_end)
break; break;
} }
@@ -244,15 +277,18 @@ match:
lzo_uint tt = t - 31; lzo_uint tt = t - 31;
*op++ = 0; *op++ = 0;
while (tt > 255) while (tt > 255)
{ {
tt -= 255; tt -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
assert(tt > 0); assert(tt > 0);
*op++ = LZO_BYTE(tt); *op++ = LZO_BYTE(tt);
} }
UA_COPYN(op, ii, t); UA_COPYN(op, ii, t);
op += t; op += t;
} }
@@ -279,7 +315,11 @@ lzo1f_1_compress ( const lzo_bytep in , lzo_uint in_len,
else if (in_len <= 10) else if (in_len <= 10)
{ {
*op++ = LZO_BYTE(in_len); *op++ = LZO_BYTE(in_len);
do *op++ = *in++; while (--in_len > 0);
do* op++ = *in++;
while (--in_len > 0);
*out_len = pd(op, out); *out_len = pd(op, out);
} }
else else

View File

@@ -76,14 +76,17 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
{ {
m_len -= M3_MAX_LEN; m_len -= M3_MAX_LEN;
*op++ = M3_MARKER | 0; *op++ = M3_MARKER | 0;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
*op++ = 0; *op++ = 0;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
*op++ = LZO_BYTE((m_off & 63) << 2); *op++ = LZO_BYTE((m_off & 63) << 2);
*op++ = LZO_BYTE(m_off >> 6); *op++ = LZO_BYTE(m_off >> 6);
c->m3_m++; c->m3_m++;
@@ -105,15 +108,20 @@ STORE_RUN ( lzo_bytep op, const lzo_bytep ii, lzo_uint t, lzo_bytep out )
lzo_uint tt = t - 31; lzo_uint tt = t - 31;
*op++ = 0; *op++ = 0;
while (tt > 255) while (tt > 255)
{ {
tt -= 255; tt -= 255;
*op++ = 0; *op++ = 0;
} }
assert(tt > 0); assert(tt > 0);
*op++ = LZO_BYTE(tt); *op++ = LZO_BYTE(tt);
} }
do *op++ = *ii++; while (--t > 0);
do* op++ = *ii++;
while (--t > 0);
return op; return op;
} }
@@ -161,14 +169,18 @@ lzo1f_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
c->r1_lit = c->r1_m_len = 0; c->r1_lit = c->r1_m_len = 0;
r = init_match(c, swd, NULL, 0, 0); r = init_match(c, swd, NULL, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
if (max_chain > 0) if (max_chain > 0)
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, 0, 0); r = find_match(c, swd, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
while (c->look > 0) while (c->look > 0)
{ {
int lazy_match_min_gain = -1; int lazy_match_min_gain = -1;
@@ -178,8 +190,10 @@ lzo1f_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
m_off = c->m_off; m_off = c->m_off;
assert(c->ip - c->look >= in); assert(c->ip - c->look >= in);
if (lit == 0) if (lit == 0)
ii = c->ip - c->look; ii = c->ip - c->look;
assert(ii + lit == c->ip - c->look); assert(ii + lit == c->ip - c->look);
assert(swd->b_char == *(c->ip - c->look)); assert(swd->b_char == *(c->ip - c->look));
@@ -209,7 +223,8 @@ lzo1f_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
if (m_len > 0 && lazy_match_min_gain >= 0 && c->look > m_len) if (m_len > 0 && lazy_match_min_gain >= 0 && c->look > m_len)
{ {
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
assert(c->look > 0); assert(c->look > 0);
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET && if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET &&
@@ -250,8 +265,10 @@ lzo1f_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
ahead = 1; ahead = 1;
assert(ii + lit + 1 == c->ip - c->look); assert(ii + lit + 1 == c->ip - c->look);
} }
assert(m_len > 0); assert(m_len > 0);
} }
assert(ii + lit + ahead == c->ip - c->look); assert(ii + lit + ahead == c->ip - c->look);
@@ -260,7 +277,8 @@ lzo1f_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* a literal */ /* a literal */
lit++; lit++;
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
else else
{ {
@@ -278,7 +296,8 @@ lzo1f_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* 2 - code match */ /* 2 - code match */
op = code_match(c, op, m_len, m_off); op = code_match(c, op, m_len, m_off);
r = find_match(c, swd, m_len, 1 + ahead); r = find_match(c, swd, m_len, 1 + ahead);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
c->codesize = pd(op, out); c->codesize = pd(op, out);

View File

@@ -58,6 +58,7 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
while (TEST_IP_AND_TEST_OP) while (TEST_IP_AND_TEST_OP)
{ {
t = *ip++; t = *ip++;
if (t > 31) if (t > 31)
goto match; goto match;
@@ -65,6 +66,7 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
if (t == 0) if (t == 0)
{ {
NEED_IP(1); NEED_IP(1);
while (*ip == 0) while (*ip == 0)
{ {
t += 255; t += 255;
@@ -72,22 +74,36 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
TEST_IV(t); TEST_IV(t);
NEED_IP(1); NEED_IP(1);
} }
t += 31 + *ip++; t += 31 + *ip++;
} }
/* copy literals */ /* copy literals */
assert(t > 0); NEED_OP(t); NEED_IP(t+1); assert(t > 0);
NEED_OP(t);
NEED_IP(t + 1);
#if (LZO_OPT_UNALIGNED32) #if (LZO_OPT_UNALIGNED32)
if (t >= 4) if (t >= 4)
{ {
do { do
{
UA_COPY4(op, ip); UA_COPY4(op, ip);
op += 4; ip += 4; t -= 4; op += 4;
} while (t >= 4); ip += 4;
if (t > 0) do *op++ = *ip++; while (--t > 0); t -= 4;
}
while (t >= 4);
if (t > 0) do* op++ = *ip++;
while (--t > 0);
} }
else else
#endif #endif
do *op++ = *ip++; while (--t > 0); do* op++ = *ip++;
while (--t > 0);
t = *ip++; t = *ip++;
@@ -99,27 +115,35 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
m_pos = op - 1 - 0x800; m_pos = op - 1 - 0x800;
m_pos -= (t >> 2) & 7; m_pos -= (t >> 2) & 7;
m_pos -= *ip++ << 3; m_pos -= *ip++ << 3;
TEST_LB(m_pos); NEED_OP(3); TEST_LB(m_pos);
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++; NEED_OP(3);
*op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos++;
} }
else else
{ {
match: match:
if (t < M3_MARKER) if (t < M3_MARKER)
{ {
m_pos = op - 1; m_pos = op - 1;
m_pos -= (t >> 2) & 7; m_pos -= (t >> 2) & 7;
m_pos -= *ip++ << 3; m_pos -= *ip++ << 3;
t >>= 5; t >>= 5;
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); TEST_LB(m_pos);
assert(t > 0);
NEED_OP(t + 3 - 1);
goto copy_match; goto copy_match;
} }
else else
{ {
t &= 31; t &= 31;
if (t == 0) if (t == 0)
{ {
NEED_IP(1); NEED_IP(1);
while (*ip == 0) while (*ip == 0)
{ {
t += 255; t += 255;
@@ -127,8 +151,10 @@ match:
TEST_OV(t); TEST_OV(t);
NEED_IP(1); NEED_IP(1);
} }
t += 31 + *ip++; t += 31 + *ip++;
} }
NEED_IP(2); NEED_IP(2);
m_pos = op; m_pos = op;
#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) #if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN)
@@ -138,38 +164,64 @@ match:
m_pos -= *ip++ >> 2; m_pos -= *ip++ >> 2;
m_pos -= *ip++ << 6; m_pos -= *ip++ << 6;
#endif #endif
if (m_pos == op) if (m_pos == op)
goto eof_found; goto eof_found;
} }
/* copy match */ /* copy match */
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); TEST_LB(m_pos);
assert(t > 0);
NEED_OP(t + 3 - 1);
#if (LZO_OPT_UNALIGNED32) #if (LZO_OPT_UNALIGNED32)
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
{ {
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4 - (3 - 1); op += 4;
do { m_pos += 4;
t -= 4 - (3 - 1);
do
{
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4; op += 4;
} while (t >= 4); m_pos += 4;
if (t > 0) do *op++ = *m_pos++; while (--t > 0); t -= 4;
}
while (t >= 4);
if (t > 0) do* op++ = *m_pos++;
while (--t > 0);
} }
else else
#endif #endif
{ {
copy_match: copy_match:
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
do *op++ = *m_pos++; while (--t > 0); *op++ = *m_pos++;
do* op++ = *m_pos++;
while (--t > 0);
} }
} }
t = ip[-2] & 3; t = ip[-2] & 3;
if (t == 0) if (t == 0)
break; break;
/* copy literals */ /* copy literals */
assert(t > 0); NEED_OP(t); NEED_IP(t+1); assert(t > 0);
do *op++ = *ip++; while (--t > 0); NEED_OP(t);
NEED_IP(t + 1);
do* op++ = *ip++;
while (--t > 0);
t = *ip++; t = *ip++;
} }
} }

View File

@@ -140,10 +140,12 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
#endif #endif
assert(op > c->out); assert(op > c->out);
if (m_len == 2) if (m_len == 2)
{ {
assert(m_off <= M1_MAX_OFFSET); assert(m_off <= M1_MAX_OFFSET);
assert(c->r1_lit > 0); assert(c->r1_lit < 4); assert(c->r1_lit > 0);
assert(c->r1_lit < 4);
m_off -= 1; m_off -= 1;
#if defined(LZO1Z) #if defined(LZO1Z)
*op++ = LZO_BYTE(M1_MARKER | (m_off >> 6)); *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
@@ -154,6 +156,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
#endif #endif
c->m1a_m++; c->m1a_m++;
} }
#if defined(LZO1Z) #if defined(LZO1Z)
else if (m_len <= M2_MAX_LEN && (m_off <= M2_MAX_OFFSET || m_off == c->last_m_off)) else if (m_len <= M2_MAX_LEN && (m_off <= M2_MAX_OFFSET || m_off == c->last_m_off))
#else #else
@@ -172,6 +175,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
*op++ = LZO_BYTE(m_off >> 2); *op++ = LZO_BYTE(m_off >> 2);
assert(op[-2] >= M2_MARKER); assert(op[-2] >= M2_MARKER);
#elif defined(LZO1Z) #elif defined(LZO1Z)
if (m_off == c->last_m_off) if (m_off == c->last_m_off)
*op++ = LZO_BYTE(((m_len - 1) << 5) | (0x700 >> 6)); *op++ = LZO_BYTE(((m_len - 1) << 5) | (0x700 >> 6));
else else
@@ -180,6 +184,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
*op++ = LZO_BYTE(((m_len - 1) << 5) | (m_off >> 6)); *op++ = LZO_BYTE(((m_len - 1) << 5) | (m_off >> 6));
*op++ = LZO_BYTE(m_off << 2); *op++ = LZO_BYTE(m_off << 2);
} }
#endif #endif
c->m2_m++; c->m2_m++;
} }
@@ -201,20 +206,24 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
{ {
assert(m_len >= 3); assert(m_len >= 3);
m_off -= 1; m_off -= 1;
if (m_len <= M3_MAX_LEN) if (m_len <= M3_MAX_LEN)
*op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
else else
{ {
m_len -= M3_MAX_LEN; m_len -= M3_MAX_LEN;
*op++ = M3_MARKER | 0; *op++ = M3_MARKER | 0;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
*op++ = 0; *op++ = 0;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
#if defined(LZO1Z) #if defined(LZO1Z)
*op++ = LZO_BYTE(m_off >> 6); *op++ = LZO_BYTE(m_off >> 6);
*op++ = LZO_BYTE(m_off << 2); *op++ = LZO_BYTE(m_off << 2);
@@ -229,23 +238,28 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
lzo_uint k; lzo_uint k;
assert(m_len >= 3); assert(m_len >= 3);
assert(m_off > 0x4000); assert(m_off <= 0xbfff); assert(m_off > 0x4000);
assert(m_off <= 0xbfff);
m_off -= 0x4000; m_off -= 0x4000;
k = (m_off & 0x4000) >> 11; k = (m_off & 0x4000) >> 11;
if (m_len <= M4_MAX_LEN) if (m_len <= M4_MAX_LEN)
*op++ = LZO_BYTE(M4_MARKER | k | (m_len - 2)); *op++ = LZO_BYTE(M4_MARKER | k | (m_len - 2));
else else
{ {
m_len -= M4_MAX_LEN; m_len -= M4_MAX_LEN;
*op++ = LZO_BYTE(M4_MARKER | k | 0); *op++ = LZO_BYTE(M4_MARKER | k | 0);
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
*op++ = 0; *op++ = 0;
} }
assert(m_len > 0); assert(m_len > 0);
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
#if defined(LZO1Z) #if defined(LZO1Z)
*op++ = LZO_BYTE(m_off >> 6); *op++ = LZO_BYTE(m_off >> 6);
*op++ = LZO_BYTE(m_off << 2); *op++ = LZO_BYTE(m_off << 2);
@@ -290,16 +304,21 @@ STORE_RUN ( LZO_COMPRESS_T *c, lzo_bytep op, const lzo_bytep ii, lzo_uint t )
lzo_uint tt = t - 18; lzo_uint tt = t - 18;
*op++ = 0; *op++ = 0;
while (tt > 255) while (tt > 255)
{ {
tt -= 255; tt -= 255;
*op++ = 0; *op++ = 0;
} }
assert(tt > 0); assert(tt > 0);
*op++ = LZO_BYTE(tt); *op++ = LZO_BYTE(tt);
c->lit3_r++; c->lit3_r++;
} }
do *op++ = *ii++; while (--t > 0);
do* op++ = *ii++;
while (--t > 0);
return op; return op;
} }
@@ -338,36 +357,48 @@ len_of_coded_match ( lzo_uint m_len, lzo_uint m_off, lzo_uint lit )
if (m_len < 2) if (m_len < 2)
return 0; return 0;
if (m_len == 2) if (m_len == 2)
return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0; return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0;
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
return 2; return 2;
if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4) if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
return 2; return 2;
if (m_off <= M3_MAX_OFFSET) if (m_off <= M3_MAX_OFFSET)
{ {
if (m_len <= M3_MAX_LEN) if (m_len <= M3_MAX_LEN)
return 3; return 3;
m_len -= M3_MAX_LEN; m_len -= M3_MAX_LEN;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
n++; n++;
} }
return n; return n;
} }
if (m_off <= M4_MAX_OFFSET) if (m_off <= M4_MAX_OFFSET)
{ {
if (m_len <= M4_MAX_LEN) if (m_len <= M4_MAX_LEN)
return 3; return 3;
m_len -= M4_MAX_LEN; m_len -= M4_MAX_LEN;
while (m_len > 255) while (m_len > 255)
{ {
m_len -= 255; m_len -= 255;
n++; n++;
} }
return n; return n;
} }
return 0; return 0;
} }
@@ -381,8 +412,10 @@ min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, lzo_uint l1, lzo_uint l2,
lazy_match_min_gain = ahead; lazy_match_min_gain = ahead;
#if 0 #if 0
if (l3) if (l3)
lit2 -= ahead; lit2 -= ahead;
#endif #endif
if (lit1 <= 3) if (lit1 <= 3)
@@ -391,6 +424,7 @@ min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, lzo_uint l1, lzo_uint l2,
lazy_match_min_gain += (lit2 <= 18) ? 0 : 1; lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
lazy_match_min_gain += (l2 - l1) * 2; lazy_match_min_gain += (l2 - l1) * 2;
if (l3) if (l3)
lazy_match_min_gain -= (ahead - l3) * 2; lazy_match_min_gain -= (ahead - l3) * 2;
@@ -398,9 +432,11 @@ min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, lzo_uint l1, lzo_uint l2,
lazy_match_min_gain = 0; lazy_match_min_gain = 0;
#if 0 #if 0
if (l1 == 2) if (l1 == 2)
if (lazy_match_min_gain == 0) if (lazy_match_min_gain == 0)
lazy_match_min_gain = 1; lazy_match_min_gain = 1;
#endif #endif
return lazy_match_min_gain; return lazy_match_min_gain;
@@ -419,6 +455,7 @@ void assert_match( const lzo_swd_p swd, lzo_uint m_len, lzo_uint m_off )
lzo_uint d_off; lzo_uint d_off;
assert(m_len >= 2); assert(m_len >= 2);
if (m_off <= (lzo_uint)(c->bp - c->in)) if (m_off <= (lzo_uint)(c->bp - c->in))
{ {
assert(c->bp - m_off + m_len < c->ip); assert(c->bp - m_off + m_len < c->ip);
@@ -429,6 +466,7 @@ void assert_match( const lzo_swd_p swd, lzo_uint m_len, lzo_uint m_off )
assert(swd->dict != NULL); assert(swd->dict != NULL);
d_off = m_off - (lzo_uint)(c->bp - c->in); d_off = m_off - (lzo_uint)(c->bp - c->in);
assert(d_off <= swd->dict_len); assert(d_off <= swd->dict_len);
if (m_len > d_off) if (m_len > d_off)
{ {
assert(lzo_memcmp(c->bp, swd->dict_end - d_off, d_off) == 0); assert(lzo_memcmp(c->bp, swd->dict_end - d_off, d_off) == 0);
@@ -457,10 +495,14 @@ better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
if (*m_len <= M2_MIN_LEN) if (*m_len <= M2_MIN_LEN)
return; return;
#if defined(LZO1Z) #if defined(LZO1Z)
if (*m_off == c->last_m_off && *m_len <= M2_MAX_LEN) if (*m_off == c->last_m_off && *m_len <= M2_MAX_LEN)
return; return;
#if 1 #if 1
if (*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 && if (*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
c->last_m_off && swd->best_off[*m_len - 1] == c->last_m_off) c->last_m_off && swd->best_off[*m_len - 1] == c->last_m_off)
{ {
@@ -468,6 +510,7 @@ better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
*m_off = swd->best_off[*m_len]; *m_off = swd->best_off[*m_len];
return; return;
} }
#endif #endif
#endif #endif
@@ -475,6 +518,7 @@ better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
return; return;
#if 1 #if 1
/* M3/M4 -> M2 */ /* M3/M4 -> M2 */
if (*m_off > M2_MAX_OFFSET && if (*m_off > M2_MAX_OFFSET &&
*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 && *m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
@@ -484,9 +528,11 @@ better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
*m_off = swd->best_off[*m_len]; *m_off = swd->best_off[*m_len];
return; return;
} }
#endif #endif
#if 1 #if 1
/* M4 -> M2 */ /* M4 -> M2 */
if (*m_off > M3_MAX_OFFSET && if (*m_off > M3_MAX_OFFSET &&
*m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 && *m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
@@ -496,9 +542,11 @@ better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
*m_off = swd->best_off[*m_len]; *m_off = swd->best_off[*m_len];
return; return;
} }
#endif #endif
#if 1 #if 1
/* M4 -> M3 */ /* M4 -> M3 */
if (*m_off > M3_MAX_OFFSET && if (*m_off > M3_MAX_OFFSET &&
*m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 && *m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
@@ -507,6 +555,7 @@ better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
*m_len = *m_len - 1; *m_len = *m_len - 1;
*m_off = swd->best_off[*m_len]; *m_off = swd->best_off[*m_len];
} }
#endif #endif
} }
@@ -554,17 +603,22 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
/* setup parameter defaults */ /* setup parameter defaults */
/* number of lazy match tries */ /* number of lazy match tries */
try_lazy = (lzo_uint) try_lazy_parm; try_lazy = (lzo_uint) try_lazy_parm;
if (try_lazy_parm < 0) if (try_lazy_parm < 0)
try_lazy = 1; try_lazy = 1;
/* reduce lazy match search if we already have a match with this length */ /* reduce lazy match search if we already have a match with this length */
if (good_length == 0) if (good_length == 0)
good_length = 32; good_length = 32;
/* do not try a lazy match if we already have a match with this length */ /* do not try a lazy match if we already have a match with this length */
if (max_lazy == 0) if (max_lazy == 0)
max_lazy = 32; max_lazy = 32;
/* stop searching for longer matches than this one */ /* stop searching for longer matches than this one */
if (nice_length == 0) if (nice_length == 0)
nice_length = 0; nice_length = 0;
/* don't search more positions than this */ /* don't search more positions than this */
if (max_chain == 0) if (max_chain == 0)
max_chain = SWD_MAX_CHAIN; max_chain = SWD_MAX_CHAIN;
@@ -583,16 +637,21 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
c->r1_lit = c->r1_m_len = 0; c->r1_lit = c->r1_m_len = 0;
r = init_match(c, swd, dict, dict_len, flags); r = init_match(c, swd, dict, dict_len, flags);
if (r != 0) if (r != 0)
return r; return r;
if (max_chain > 0) if (max_chain > 0)
swd->max_chain = max_chain; swd->max_chain = max_chain;
if (nice_length > 0) if (nice_length > 0)
swd->nice_length = nice_length; swd->nice_length = nice_length;
r = find_match(c, swd, 0, 0); r = find_match(c, swd, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
while (c->look > 0) while (c->look > 0)
{ {
lzo_uint ahead; lzo_uint ahead;
@@ -606,8 +665,10 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
assert(c->bp == c->ip - c->look); assert(c->bp == c->ip - c->look);
assert(c->bp >= in); assert(c->bp >= in);
if (lit == 0) if (lit == 0)
ii = c->bp; ii = c->bp;
assert(ii + lit == c->bp); assert(ii + lit == c->bp);
assert(swd->b_char == *(c->bp)); assert(swd->b_char == *(c->bp));
@@ -638,20 +699,24 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
lit++; lit++;
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
continue; continue;
} }
/* a match */ /* a match */
#if defined(SWD_BEST_OFF) #if defined(SWD_BEST_OFF)
if (swd->use_best_off) if (swd->use_best_off)
better_match(swd, &m_len, &m_off); better_match(swd, &m_len, &m_off);
#endif #endif
assert_match(swd, m_len, m_off); assert_match(swd, m_len, m_off);
/* shall we try a lazy match ? */ /* shall we try a lazy match ? */
ahead = 0; ahead = 0;
if (try_lazy == 0 || m_len >= max_lazy) if (try_lazy == 0 || m_len >= max_lazy)
{ {
/* no */ /* no */
@@ -679,34 +744,48 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
swd->max_chain = max_chain >> 2; swd->max_chain = max_chain >> 2;
else else
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
ahead++; ahead++;
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
assert(c->look > 0); assert(c->look > 0);
assert(ii + lit + ahead == c->bp); assert(ii + lit + ahead == c->bp);
#if defined(LZO1Z) #if defined(LZO1Z)
if (m_off == c->last_m_off && c->m_off != c->last_m_off) if (m_off == c->last_m_off && c->m_off != c->last_m_off)
if (m_len >= M2_MIN_LEN && m_len <= M2_MAX_LEN) if (m_len >= M2_MIN_LEN && m_len <= M2_MAX_LEN)
c->m_len = 0; c->m_len = 0;
#endif #endif
if (c->m_len < m_len) if (c->m_len < m_len)
continue; continue;
#if 1 #if 1
if (c->m_len == m_len && c->m_off >= m_off) if (c->m_len == m_len && c->m_off >= m_off)
continue; continue;
#endif #endif
#if defined(SWD_BEST_OFF) #if defined(SWD_BEST_OFF)
if (swd->use_best_off) if (swd->use_best_off)
better_match(swd, &c->m_len, &c->m_off); better_match(swd, &c->m_len, &c->m_off);
#endif #endif
l2 = len_of_coded_match(c->m_len, c->m_off, lit + ahead); l2 = len_of_coded_match(c->m_len, c->m_off, lit + ahead);
if (l2 == 0) if (l2 == 0)
continue; continue;
#if 0 #if 0
if (c->m_len == m_len && l2 >= l1) if (c->m_len == m_len && l2 >= l1)
continue; continue;
#endif #endif
@@ -718,6 +797,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
#endif #endif
lazy_match_min_gain = min_gain(ahead, lit, lit + ahead, l1, l2, l3); lazy_match_min_gain = min_gain(ahead, lit, lit + ahead, l1, l2, l3);
if (c->m_len >= m_len + lazy_match_min_gain) if (c->m_len >= m_len + lazy_match_min_gain)
{ {
c->lazy++; c->lazy++;
@@ -736,6 +816,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
lit += ahead; lit += ahead;
assert(ii + lit == c->bp); assert(ii + lit == c->bp);
} }
goto lazy_match_done; goto lazy_match_done;
} }
} }
@@ -751,9 +832,11 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
op = code_match(c, op, m_len, m_off); op = code_match(c, op, m_len, m_off);
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, m_len, 1 + ahead); r = find_match(c, swd, m_len, 1 + ahead);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
lazy_match_done: ; lazy_match_done:
;
} }
@@ -807,7 +890,8 @@ lzo1x_999_compress_level ( const lzo_bytep in , lzo_uint in_len,
lzo_uint nice_length; lzo_uint nice_length;
lzo_uint max_chain; lzo_uint max_chain;
lzo_uint32_t flags; lzo_uint32_t flags;
} c[9] = { } c[9] =
{
/* faster compression */ /* faster compression */
{ 0, 0, 0, 8, 4, 0 }, { 0, 0, 0, 8, 4, 0 },
{ 0, 0, 0, 16, 8, 0 }, { 0, 0, 0, 16, 8, 0 },

View File

@@ -54,6 +54,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len,
ii = ip; ii = ip;
ip += ti < 4 ? 4 - ti : 0; ip += ti < 4 ? 4 - ti : 0;
for (;;) for (;;)
{ {
const lzo_bytep m_pos; const lzo_bytep m_pos;
@@ -62,26 +63,36 @@ do_compress ( const lzo_bytep in , lzo_uint in_len,
lzo_uint m_len; lzo_uint m_len;
lzo_uint dindex; lzo_uint dindex;
next: next:
if __lzo_unlikely(ip >= ip_end) if __lzo_unlikely(ip >= ip_end)
break; break;
DINDEX1(dindex, ip); DINDEX1(dindex, ip);
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M4_MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M4_MAX_OFFSET))
goto literal; goto literal;
#if 1 #if 1
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match; goto try_match;
DINDEX2(dindex, ip); DINDEX2(dindex, ip);
#endif #endif
GINDEX(m_pos, m_off, dict, dindex, in); GINDEX(m_pos, m_off, dict, dindex, in);
if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M4_MAX_OFFSET)) if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M4_MAX_OFFSET))
goto literal; goto literal;
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match; goto try_match;
goto literal; goto literal;
try_match: try_match:
#if (LZO_OPT_UNALIGNED32) #if (LZO_OPT_UNALIGNED32)
if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip)) if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
#else #else
if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
@@ -93,6 +104,7 @@ literal:
ip += 1 + ((ip - ii) >> 5); ip += 1 + ((ip - ii) >> 5);
continue; continue;
} }
/*match:*/ /*match:*/
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
#else #else
@@ -104,12 +116,15 @@ literal:
literal: literal:
ip += 1 + ((ip - ii) >> 5); ip += 1 + ((ip - ii) >> 5);
next: next:
if __lzo_unlikely(ip >= ip_end) if __lzo_unlikely(ip >= ip_end)
break; break;
dv = UA_GET_LE32(ip); dv = UA_GET_LE32(ip);
dindex = DINDEX(dv, ip); dindex = DINDEX(dv, ip);
GINDEX(m_off, m_pos, in + dict, dindex, in); GINDEX(m_off, m_pos, in + dict, dindex, in);
UPDATE_I(dict, 0, dindex, ip, in); UPDATE_I(dict, 0, dindex, ip, in);
if __lzo_unlikely(dv != UA_GET_LE32(m_pos)) if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
goto literal; goto literal;
} }
@@ -117,9 +132,11 @@ next:
/* a match */ /* a match */
ii -= ti; ti = 0; ii -= ti;
ti = 0;
{ {
lzo_uint t = pd(ip, ii); lzo_uint t = pd(ip, ii);
if (t != 0) if (t != 0)
{ {
if (t <= 3) if (t <= 3)
@@ -132,6 +149,7 @@ next:
{ do* op++ = *ii++; while (--t > 0); } { do* op++ = *ii++; while (--t > 0); }
#endif #endif
} }
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) #if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
else if (t <= 16) else if (t <= 16)
{ {
@@ -140,6 +158,7 @@ next:
UA_COPY8(op + 8, ii + 8); UA_COPY8(op + 8, ii + 8);
op += t; op += t;
} }
#endif #endif
else else
{ {
@@ -149,21 +168,31 @@ next:
{ {
lzo_uint tt = t - 18; lzo_uint tt = t - 18;
*op++ = 0; *op++ = 0;
while __lzo_unlikely(tt > 255) while __lzo_unlikely(tt > 255)
{ {
tt -= 255; tt -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
assert(tt > 0); assert(tt > 0);
*op++ = LZO_BYTE(tt); *op++ = LZO_BYTE(tt);
} }
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) #if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
do {
do
{
UA_COPY8(op, ii); UA_COPY8(op, ii);
UA_COPY8(op + 8, ii + 8); UA_COPY8(op + 8, ii + 8);
op += 16; ii += 16; t -= 16; op += 16;
} while (t >= 16); if (t > 0) ii += 16;
t -= 16;
}
while (t >= 16);
if (t > 0)
#endif #endif
{ do* op++ = *ii++; while (--t > 0); } { do* op++ = *ii++; while (--t > 0); }
} }
@@ -174,102 +203,161 @@ next:
#if (LZO_OPT_UNALIGNED64) #if (LZO_OPT_UNALIGNED64)
lzo_uint64_t v; lzo_uint64_t v;
v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
if __lzo_unlikely(v == 0) {
do { if __lzo_unlikely(v == 0)
{
do
{
m_len += 8; m_len += 8;
v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
if __lzo_unlikely(ip + m_len >= ip_end) if __lzo_unlikely(ip + m_len >= ip_end)
goto m_len_done; goto m_len_done;
} while (v == 0);
} }
while (v == 0);
}
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64) #if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
m_len += lzo_bitops_ctlz64(v) / CHAR_BIT; m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
#elif (LZO_ABI_BIG_ENDIAN) #elif (LZO_ABI_BIG_ENDIAN)
if ((v >> (64 - CHAR_BIT)) == 0) do {
if ((v >> (64 - CHAR_BIT)) == 0) do
{
v <<= CHAR_BIT; v <<= CHAR_BIT;
m_len += 1; m_len += 1;
} while ((v >> (64 - CHAR_BIT)) == 0); }
while ((v >> (64 - CHAR_BIT)) == 0);
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64) #elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
m_len += lzo_bitops_cttz64(v) / CHAR_BIT; m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
#elif (LZO_ABI_LITTLE_ENDIAN) #elif (LZO_ABI_LITTLE_ENDIAN)
if ((v & UCHAR_MAX) == 0) do {
if ((v & UCHAR_MAX) == 0) do
{
v >>= CHAR_BIT; v >>= CHAR_BIT;
m_len += 1; m_len += 1;
} while ((v & UCHAR_MAX) == 0); }
while ((v & UCHAR_MAX) == 0);
#else #else
if (ip[m_len] == m_pos[m_len]) do {
if (ip[m_len] == m_pos[m_len]) do
{
m_len += 1; m_len += 1;
} while (ip[m_len] == m_pos[m_len]); }
while (ip[m_len] == m_pos[m_len]);
#endif #endif
#elif (LZO_OPT_UNALIGNED32) #elif (LZO_OPT_UNALIGNED32)
lzo_uint32_t v; lzo_uint32_t v;
v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
if __lzo_unlikely(v == 0) {
do { if __lzo_unlikely(v == 0)
{
do
{
m_len += 4; m_len += 4;
v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
if (v != 0) if (v != 0)
break; break;
m_len += 4; m_len += 4;
v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
if __lzo_unlikely(ip + m_len >= ip_end) if __lzo_unlikely(ip + m_len >= ip_end)
goto m_len_done; goto m_len_done;
} while (v == 0);
} }
while (v == 0);
}
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32) #if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
m_len += lzo_bitops_ctlz32(v) / CHAR_BIT; m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
#elif (LZO_ABI_BIG_ENDIAN) #elif (LZO_ABI_BIG_ENDIAN)
if ((v >> (32 - CHAR_BIT)) == 0) do {
if ((v >> (32 - CHAR_BIT)) == 0) do
{
v <<= CHAR_BIT; v <<= CHAR_BIT;
m_len += 1; m_len += 1;
} while ((v >> (32 - CHAR_BIT)) == 0); }
while ((v >> (32 - CHAR_BIT)) == 0);
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32) #elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
m_len += lzo_bitops_cttz32(v) / CHAR_BIT; m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
#elif (LZO_ABI_LITTLE_ENDIAN) #elif (LZO_ABI_LITTLE_ENDIAN)
if ((v & UCHAR_MAX) == 0) do {
if ((v & UCHAR_MAX) == 0) do
{
v >>= CHAR_BIT; v >>= CHAR_BIT;
m_len += 1; m_len += 1;
} while ((v & UCHAR_MAX) == 0); }
while ((v & UCHAR_MAX) == 0);
#else #else
if (ip[m_len] == m_pos[m_len]) do {
if (ip[m_len] == m_pos[m_len]) do
{
m_len += 1; m_len += 1;
} while (ip[m_len] == m_pos[m_len]); }
while (ip[m_len] == m_pos[m_len]);
#endif #endif
#else #else
if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
do { if __lzo_unlikely(ip[m_len] == m_pos[m_len])
{
do
{
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if (ip[m_len] != m_pos[m_len]) if (ip[m_len] != m_pos[m_len])
break; break;
m_len += 1; m_len += 1;
if __lzo_unlikely(ip + m_len >= ip_end) if __lzo_unlikely(ip + m_len >= ip_end)
goto m_len_done; goto m_len_done;
} while (ip[m_len] == m_pos[m_len]);
} }
while (ip[m_len] == m_pos[m_len]);
}
#endif #endif
} }
m_len_done: m_len_done:
m_off = pd(ip, m_pos); m_off = pd(ip, m_pos);
ip += m_len; ip += m_len;
ii = ip; ii = ip;
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
{ {
m_off -= 1; m_off -= 1;
@@ -284,43 +372,52 @@ m_len_done:
else if (m_off <= M3_MAX_OFFSET) else if (m_off <= M3_MAX_OFFSET)
{ {
m_off -= 1; m_off -= 1;
if (m_len <= M3_MAX_LEN) if (m_len <= M3_MAX_LEN)
*op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
else else
{ {
m_len -= M3_MAX_LEN; m_len -= M3_MAX_LEN;
*op++ = M3_MARKER | 0; *op++ = M3_MARKER | 0;
while __lzo_unlikely(m_len > 255) while __lzo_unlikely(m_len > 255)
{ {
m_len -= 255; m_len -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
*op++ = LZO_BYTE(m_off << 2); *op++ = LZO_BYTE(m_off << 2);
*op++ = LZO_BYTE(m_off >> 6); *op++ = LZO_BYTE(m_off >> 6);
} }
else else
{ {
m_off -= 0x4000; m_off -= 0x4000;
if (m_len <= M4_MAX_LEN) if (m_len <= M4_MAX_LEN)
*op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2)); *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
else else
{ {
m_len -= M4_MAX_LEN; m_len -= M4_MAX_LEN;
*op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8)); *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
while __lzo_unlikely(m_len > 255) while __lzo_unlikely(m_len > 255)
{ {
m_len -= 255; m_len -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
*op++ = LZO_BYTE(m_len); *op++ = LZO_BYTE(m_len);
} }
*op++ = LZO_BYTE(m_off << 2); *op++ = LZO_BYTE(m_off << 2);
*op++ = LZO_BYTE(m_off >> 6); *op++ = LZO_BYTE(m_off >> 6);
} }
goto next; goto next;
} }
@@ -351,8 +448,10 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len,
ll = LZO_MIN(ll, 49152); ll = LZO_MIN(ll, 49152);
#endif #endif
ll_end = (lzo_uintptr_t)ip + ll; ll_end = (lzo_uintptr_t)ip + ll;
if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll) if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
break; break;
#if (LZO_DETERMINISTIC) #if (LZO_DETERMINISTIC)
lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t)); lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
#endif #endif
@@ -361,6 +460,7 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len,
op += *out_len; op += *out_len;
l -= ll; l -= ll;
} }
t += l; t += l;
if (t > 0) if (t > 0)
@@ -378,15 +478,18 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len,
lzo_uint tt = t - 18; lzo_uint tt = t - 18;
*op++ = 0; *op++ = 0;
while (tt > 255) while (tt > 255)
{ {
tt -= 255; tt -= 255;
UA_SET1(op, 0); UA_SET1(op, 0);
op++; op++;
} }
assert(tt > 0); assert(tt > 0);
*op++ = LZO_BYTE(tt); *op++ = LZO_BYTE(tt);
} }
UA_COPYN(op, ii, t); UA_COPYN(op, ii, t);
op += t; op += t;
} }

View File

@@ -61,6 +61,7 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
LZO_UNUSED(wrkmem); LZO_UNUSED(wrkmem);
#if defined(COPY_DICT) #if defined(COPY_DICT)
if (dict) if (dict)
{ {
if (dict_len > M4_MAX_OFFSET) if (dict_len > M4_MAX_OFFSET)
@@ -68,6 +69,7 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
dict += dict_len - M4_MAX_OFFSET; dict += dict_len - M4_MAX_OFFSET;
dict_len = M4_MAX_OFFSET; dict_len = M4_MAX_OFFSET;
} }
dict_end = dict + dict_len; dict_end = dict + dict_len;
} }
else else
@@ -75,6 +77,7 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
dict_len = 0; dict_len = 0;
dict_end = NULL; dict_end = NULL;
} }
#endif /* COPY_DICT */ #endif /* COPY_DICT */
*out_len = 0; *out_len = 0;
@@ -83,13 +86,22 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
ip = in; ip = in;
NEED_IP(1); NEED_IP(1);
if (*ip > 17) if (*ip > 17)
{ {
t = *ip++ - 17; t = *ip++ - 17;
if (t < 4) if (t < 4)
goto match_next; goto match_next;
assert(t > 0); NEED_OP(t); NEED_IP(t+3);
do *op++ = *ip++; while (--t > 0); assert(t > 0);
NEED_OP(t);
NEED_IP(t + 3);
do* op++ = *ip++;
while (--t > 0);
goto first_literal_run; goto first_literal_run;
} }
@@ -97,8 +109,10 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
{ {
NEED_IP(3); NEED_IP(3);
t = *ip++; t = *ip++;
if (t >= 16) if (t >= 16)
goto match; goto match;
/* a literal run */ /* a literal run */
if (t == 0) if (t == 0)
{ {
@@ -109,47 +123,74 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
TEST_IV(t); TEST_IV(t);
NEED_IP(1); NEED_IP(1);
} }
t += 15 + *ip++; t += 15 + *ip++;
} }
/* copy literals */ /* copy literals */
assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); assert(t > 0);
NEED_OP(t + 3);
NEED_IP(t + 6);
#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) #if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32)
t += 3; t += 3;
if (t >= 8) do if (t >= 8) do
{ {
UA_COPY8(op, ip); UA_COPY8(op, ip);
op += 8; ip += 8; t -= 8; op += 8;
} while (t >= 8); ip += 8;
t -= 8;
}
while (t >= 8);
if (t >= 4) if (t >= 4)
{ {
UA_COPY4(op, ip); UA_COPY4(op, ip);
op += 4; ip += 4; t -= 4; op += 4;
ip += 4;
t -= 4;
} }
if (t > 0) if (t > 0)
{ {
*op++ = *ip++; *op++ = *ip++;
if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
} }
#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) #elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4)
#if !(LZO_OPT_UNALIGNED32) #if !(LZO_OPT_UNALIGNED32)
if (PTR_ALIGNED2_4(op, ip)) if (PTR_ALIGNED2_4(op, ip))
{ {
#endif #endif
UA_COPY4(op, ip); UA_COPY4(op, ip);
op += 4; ip += 4; op += 4;
ip += 4;
if (--t > 0) if (--t > 0)
{ {
if (t >= 4) if (t >= 4)
{ {
do { do
{
UA_COPY4(op, ip); UA_COPY4(op, ip);
op += 4; ip += 4; t -= 4; op += 4;
} while (t >= 4); ip += 4;
if (t > 0) do *op++ = *ip++; while (--t > 0); t -= 4;
}
while (t >= 4);
if (t > 0) do* op++ = *ip++;
while (--t > 0);
} }
else else
do *op++ = *ip++; while (--t > 0); do* op++ = *ip++;
while (--t > 0);
} }
#if !(LZO_OPT_UNALIGNED32) #if !(LZO_OPT_UNALIGNED32)
} }
else else
@@ -157,9 +198,15 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
#endif #endif
#if !(LZO_OPT_UNALIGNED32) #if !(LZO_OPT_UNALIGNED32)
{ {
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
do *op++ = *ip++; while (--t > 0); *op++ = *ip++;
*op++ = *ip++;
do* op++ = *ip++;
while (--t > 0);
} }
#endif #endif
@@ -167,8 +214,10 @@ first_literal_run:
t = *ip++; t = *ip++;
if (t >= 16) if (t >= 16)
goto match; goto match;
#if defined(COPY_DICT) #if defined(COPY_DICT)
#if defined(LZO1Z) #if defined(LZO1Z)
m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
@@ -177,7 +226,8 @@ first_literal_run:
m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
#endif #endif
NEED_OP(3); NEED_OP(3);
t = 3; COPY_DICT(t,m_off) t = 3;
COPY_DICT(t, m_off)
#else /* !COPY_DICT */ #else /* !COPY_DICT */
#if defined(LZO1Z) #if defined(LZO1Z)
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
@@ -188,15 +238,20 @@ first_literal_run:
m_pos -= t >> 2; m_pos -= t >> 2;
m_pos -= *ip++ << 2; m_pos -= *ip++ << 2;
#endif #endif
TEST_LB(m_pos); NEED_OP(3); TEST_LB(m_pos);
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; NEED_OP(3);
*op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos;
#endif /* COPY_DICT */ #endif /* COPY_DICT */
goto match_done; goto match_done;
/* handle matches */ /* handle matches */
for (;;) { for (;;)
{
match: match:
if (t >= 64) /* a M2 match */ if (t >= 64) /* a M2 match */
{ {
#if defined(COPY_DICT) #if defined(COPY_DICT)
@@ -208,6 +263,7 @@ match:
t = (t >> 4) - 3; t = (t >> 4) - 3;
#elif defined(LZO1Z) #elif defined(LZO1Z)
m_off = t & 0x1f; m_off = t & 0x1f;
if (m_off >= 0x1c) if (m_off >= 0x1c)
m_off = last_m_off; m_off = last_m_off;
else else
@@ -215,6 +271,7 @@ match:
m_off = 1 + (m_off << 6) + (*ip++ >> 2); m_off = 1 + (m_off << 6) + (*ip++ >> 2);
last_m_off = m_off; last_m_off = m_off;
} }
t = (t >> 5) - 1; t = (t >> 5) - 1;
#endif #endif
#else /* !COPY_DICT */ #else /* !COPY_DICT */
@@ -232,6 +289,7 @@ match:
{ {
lzo_uint off = t & 0x1f; lzo_uint off = t & 0x1f;
m_pos = op; m_pos = op;
if (off >= 0x1c) if (off >= 0x1c)
{ {
assert(last_m_off > 0); assert(last_m_off > 0);
@@ -246,13 +304,16 @@ match:
} }
t = (t >> 5) - 1; t = (t >> 5) - 1;
#endif #endif
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); TEST_LB(m_pos);
assert(t > 0);
NEED_OP(t + 3 - 1);
goto copy_match; goto copy_match;
#endif /* COPY_DICT */ #endif /* COPY_DICT */
} }
else if (t >= 32) /* a M3 match */ else if (t >= 32) /* a M3 match */
{ {
t &= 31; t &= 31;
if (t == 0) if (t == 0)
{ {
while (*ip == 0) while (*ip == 0)
@@ -262,9 +323,11 @@ match:
TEST_OV(t); TEST_OV(t);
NEED_IP(1); NEED_IP(1);
} }
t += 31 + *ip++; t += 31 + *ip++;
NEED_IP(2); NEED_IP(2);
} }
#if defined(COPY_DICT) #if defined(COPY_DICT)
#if defined(LZO1Z) #if defined(LZO1Z)
m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
@@ -298,6 +361,7 @@ match:
m_pos -= (t & 8) << 11; m_pos -= (t & 8) << 11;
#endif /* COPY_DICT */ #endif /* COPY_DICT */
t &= 7; t &= 7;
if (t == 0) if (t == 0)
{ {
while (*ip == 0) while (*ip == 0)
@@ -307,9 +371,11 @@ match:
TEST_OV(t); TEST_OV(t);
NEED_IP(1); NEED_IP(1);
} }
t += 7 + *ip++; t += 7 + *ip++;
NEED_IP(2); NEED_IP(2);
} }
#if defined(COPY_DICT) #if defined(COPY_DICT)
#if defined(LZO1Z) #if defined(LZO1Z)
m_off += (ip[0] << 6) + (ip[1] >> 2); m_off += (ip[0] << 6) + (ip[1] >> 2);
@@ -317,8 +383,10 @@ match:
m_off += (ip[0] >> 2) + (ip[1] << 6); m_off += (ip[0] >> 2) + (ip[1] << 6);
#endif #endif
ip += 2; ip += 2;
if (m_off == 0) if (m_off == 0)
goto eof_found; goto eof_found;
m_off += 0x4000; m_off += 0x4000;
#if defined(LZO1Z) #if defined(LZO1Z)
last_m_off = m_off; last_m_off = m_off;
@@ -332,8 +400,10 @@ match:
m_pos -= (ip[0] >> 2) + (ip[1] << 6); m_pos -= (ip[0] >> 2) + (ip[1] << 6);
#endif #endif
ip += 2; ip += 2;
if (m_pos == op) if (m_pos == op)
goto eof_found; goto eof_found;
m_pos -= 0x4000; m_pos -= 0x4000;
#if defined(LZO1Z) #if defined(LZO1Z)
last_m_off = pd((const lzo_bytep)op, m_pos); last_m_off = pd((const lzo_bytep)op, m_pos);
@@ -350,7 +420,8 @@ match:
m_off = 1 + (t >> 2) + (*ip++ << 2); m_off = 1 + (t >> 2) + (*ip++ << 2);
#endif #endif
NEED_OP(2); NEED_OP(2);
t = 2; COPY_DICT(t,m_off) t = 2;
COPY_DICT(t, m_off)
#else /* !COPY_DICT */ #else /* !COPY_DICT */
#if defined(LZO1Z) #if defined(LZO1Z)
t = 1 + (t << 6) + (*ip++ >> 2); t = 1 + (t << 6) + (*ip++ >> 2);
@@ -361,8 +432,10 @@ match:
m_pos -= t >> 2; m_pos -= t >> 2;
m_pos -= *ip++ << 2; m_pos -= *ip++ << 2;
#endif #endif
TEST_LB(m_pos); NEED_OP(2); TEST_LB(m_pos);
*op++ = *m_pos++; *op++ = *m_pos; NEED_OP(2);
*op++ = *m_pos++;
*op++ = *m_pos;
#endif /* COPY_DICT */ #endif /* COPY_DICT */
goto match_done; goto match_done;
} }
@@ -371,28 +444,41 @@ match:
#if defined(COPY_DICT) #if defined(COPY_DICT)
NEED_OP(t + 3 - 1); NEED_OP(t + 3 - 1);
t += 3-1; COPY_DICT(t,m_off) t += 3 - 1;
COPY_DICT(t, m_off)
#else /* !COPY_DICT */ #else /* !COPY_DICT */
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); TEST_LB(m_pos);
assert(t > 0);
NEED_OP(t + 3 - 1);
#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) #if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32)
if (op - m_pos >= 8) if (op - m_pos >= 8)
{ {
t += (3 - 1); t += (3 - 1);
if (t >= 8) do if (t >= 8) do
{ {
UA_COPY8(op, m_pos); UA_COPY8(op, m_pos);
op += 8; m_pos += 8; t -= 8; op += 8;
} while (t >= 8); m_pos += 8;
t -= 8;
}
while (t >= 8);
if (t >= 4) if (t >= 4)
{ {
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4; op += 4;
m_pos += 4;
t -= 4;
} }
if (t > 0) if (t > 0)
{ {
*op++ = m_pos[0]; *op++ = m_pos[0];
if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
} }
} }
@@ -403,23 +489,38 @@ match:
{ {
assert((op - m_pos) >= 4); /* both pointers are aligned */ assert((op - m_pos) >= 4); /* both pointers are aligned */
#else #else
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
{ {
#endif #endif
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4 - (3 - 1); op += 4;
do { m_pos += 4;
t -= 4 - (3 - 1);
do
{
UA_COPY4(op, m_pos); UA_COPY4(op, m_pos);
op += 4; m_pos += 4; t -= 4; op += 4;
} while (t >= 4); m_pos += 4;
if (t > 0) do *op++ = *m_pos++; while (--t > 0); t -= 4;
}
while (t >= 4);
if (t > 0) do* op++ = *m_pos++;
while (--t > 0);
} }
else else
#endif #endif
{ {
copy_match: copy_match:
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
do *op++ = *m_pos++; while (--t > 0); *op++ = *m_pos++;
do* op++ = *m_pos++;
while (--t > 0);
} }
#endif /* COPY_DICT */ #endif /* COPY_DICT */
@@ -430,17 +531,27 @@ match_done:
#else #else
t = ip[-2] & 3; t = ip[-2] & 3;
#endif #endif
if (t == 0) if (t == 0)
break; break;
/* copy literals */ /* copy literals */
match_next: match_next:
assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); assert(t > 0);
assert(t < 4);
NEED_OP(t);
NEED_IP(t + 3);
#if 0 #if 0
do *op++ = *ip++; while (--t > 0);
do* op++ = *ip++;
while (--t > 0);
#else #else
*op++ = *ip++; *op++ = *ip++;
if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
#endif #endif
t = *ip++; t = *ip++;
} }

View File

@@ -41,6 +41,7 @@ static void copy2(lzo_bytep ip, const lzo_bytep m_pos, lzo_uint off)
{ {
assert(off > 0); assert(off > 0);
ip[0] = m_pos[0]; ip[0] = m_pos[0];
if (off == 1) if (off == 1)
ip[1] = m_pos[0]; ip[1] = m_pos[0];
else else
@@ -52,6 +53,7 @@ static void copy3(lzo_bytep ip, const lzo_bytep m_pos, lzo_uint off)
{ {
assert(off > 0); assert(off > 0);
ip[0] = m_pos[0]; ip[0] = m_pos[0];
if (off == 1) if (off == 1)
{ {
ip[2] = ip[1] = m_pos[0]; ip[2] = ip[1] = m_pos[0];
@@ -98,41 +100,57 @@ DO_OPTIMIZE ( lzo_bytep in , lzo_uint in_len,
ip = in; ip = in;
assert(in_len >= 3); assert(in_len >= 3);
if (*ip > 17) if (*ip > 17)
{ {
t = *ip++ - 17; t = *ip++ - 17;
if (t < 4) if (t < 4)
goto match_next; goto match_next;
goto first_literal_run; goto first_literal_run;
} }
assert(*ip < 16 || (*ip == 17 && in_len == 3)); assert(*ip < 16 || (*ip == 17 && in_len == 3));
while (TEST_IP_AND_TEST_OP) while (TEST_IP_AND_TEST_OP)
{ {
t = *ip++; t = *ip++;
if (t >= 16) if (t >= 16)
goto match; goto match;
/* a literal run */ /* a literal run */
litp = ip - 1; litp = ip - 1;
if (t == 0) if (t == 0)
{ {
t = 15; t = 15;
while (*ip == 0) while (*ip == 0)
t += 255, ip++; t += 255, ip++;
t += *ip++; t += *ip++;
} }
lit = t + 3; lit = t + 3;
/* copy literals */ /* copy literals */
copy_literal_run: copy_literal_run:
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
*op++ = *ip++;
*op++ = *ip++;
first_literal_run: first_literal_run:
do *op++ = *ip++; while (--t > 0);
do* op++ = *ip++;
while (--t > 0);
t = *ip++; t = *ip++;
if (t >= 16) if (t >= 16)
goto match; goto match;
#if defined(LZO1X) #if defined(LZO1X)
m_pos = op - 1 - 0x800; m_pos = op - 1 - 0x800;
#elif defined(LZO1Y) #elif defined(LZO1Y)
@@ -140,13 +158,16 @@ first_literal_run:
#endif #endif
m_pos -= t >> 2; m_pos -= t >> 2;
m_pos -= *ip++ << 2; m_pos -= *ip++ << 2;
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos++;
lit = 0; lit = 0;
goto match_done; goto match_done;
/* handle matches */ /* handle matches */
do { do
{
if (t < 16) /* a M1 match */ if (t < 16) /* a M1 match */
{ {
m_pos = op - 1; m_pos = op - 1;
@@ -161,6 +182,7 @@ first_literal_run:
assert(litp == ip - 2 - lit - 2); assert(litp == ip - 2 - lit - 2);
assert((lzo_uint)(*litp & 3) == lit); assert((lzo_uint)(*litp & 3) == lit);
nl = ip[-2] & 3; nl = ip[-2] & 3;
/* test if a match follows */ /* test if a match follows */
if (nl == 0 && lit == 1 && ip[0] >= 16) if (nl == 0 && lit == 1 && ip[0] >= 16)
{ {
@@ -183,22 +205,29 @@ first_literal_run:
copy2(ip - 3 + 1, m_pos, pd(op, m_pos)); copy2(ip - 3 + 1, m_pos, pd(op, m_pos));
/* move literals 1 byte ahead */ /* move literals 1 byte ahead */
litp += 2; litp += 2;
if (lit > 0) if (lit > 0)
lzo_memmove(litp + 1, litp, lit); lzo_memmove(litp + 1, litp, lit);
/* insert new length of long literal run */ /* insert new length of long literal run */
lit += 2 + t + 3; assert(lit <= 18); lit += 2 + t + 3;
assert(lit <= 18);
*litp = LZO_BYTE(lit - 3); *litp = LZO_BYTE(lit - 3);
o_m1_b++; o_m1_b++;
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
*op++ = *m_pos++;
goto copy_literal_run; goto copy_literal_run;
} }
copy_m1: copy_m1:
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
*op++ = *m_pos++;
} }
else else
{ {
match: match:
if (t >= 64) /* a M2 match */ if (t >= 64) /* a M2 match */
{ {
m_pos = op - 1; m_pos = op - 1;
@@ -211,10 +240,12 @@ match:
m_pos -= *ip++ << 2; m_pos -= *ip++ << 2;
t = (t >> 4) - 3; t = (t >> 4) - 3;
#endif #endif
if (litp == NULL) if (litp == NULL)
goto copy_m; goto copy_m;
nl = ip[-2] & 3; nl = ip[-2] & 3;
/* test if in beetween two long literal runs */ /* test if in beetween two long literal runs */
if (t == 1 && lit > 3 && nl == 0 && if (t == 1 && lit > 3 && nl == 0 &&
ip[0] < 16 && ip[0] != 0 && (lit + 3 + ip[0] < 16)) ip[0] < 16 && ip[0] != 0 && (lit + 3 + ip[0] < 16))
@@ -224,10 +255,13 @@ match:
/* copy over the 3 literals that replace the match */ /* copy over the 3 literals that replace the match */
copy3(ip - 1 - 2, m_pos, pd(op, m_pos)); copy3(ip - 1 - 2, m_pos, pd(op, m_pos));
/* set new length of previous literal run */ /* set new length of previous literal run */
lit += 3 + t + 3; assert(lit <= 18); lit += 3 + t + 3;
assert(lit <= 18);
*litp = LZO_BYTE(lit - 3); *litp = LZO_BYTE(lit - 3);
o_m2++; o_m2++;
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos++;
goto copy_literal_run; goto copy_literal_run;
} }
} }
@@ -236,13 +270,17 @@ match:
if (t >= 32) /* a M3 match */ if (t >= 32) /* a M3 match */
{ {
t &= 31; t &= 31;
if (t == 0) if (t == 0)
{ {
t = 31; t = 31;
while (*ip == 0) while (*ip == 0)
t += 255, ip++; t += 255, ip++;
t += *ip++; t += *ip++;
} }
m_pos = op - 1; m_pos = op - 1;
m_pos -= *ip++ >> 2; m_pos -= *ip++ >> 2;
m_pos -= *ip++ << 6; m_pos -= *ip++ << 6;
@@ -252,23 +290,31 @@ match:
m_pos = op; m_pos = op;
m_pos -= (t & 8) << 11; m_pos -= (t & 8) << 11;
t &= 7; t &= 7;
if (t == 0) if (t == 0)
{ {
t = 7; t = 7;
while (*ip == 0) while (*ip == 0)
t += 255, ip++; t += 255, ip++;
t += *ip++; t += *ip++;
} }
m_pos -= *ip++ >> 2; m_pos -= *ip++ >> 2;
m_pos -= *ip++ << 6; m_pos -= *ip++ << 6;
if (m_pos == op) if (m_pos == op)
goto eof_found; goto eof_found;
m_pos -= 0x4000; m_pos -= 0x4000;
} }
if (litp == NULL) if (litp == NULL)
goto copy_m; goto copy_m;
nl = ip[-2] & 3; nl = ip[-2] & 3;
/* test if in beetween two matches */ /* test if in beetween two matches */
if (t == 1 && lit == 0 && nl == 0 && ip[0] >= 16) if (t == 1 && lit == 0 && nl == 0 && ip[0] >= 16)
{ {
@@ -295,23 +341,34 @@ match:
copy3(ip - 4 + 1, m_pos, pd(op, m_pos)); copy3(ip - 4 + 1, m_pos, pd(op, m_pos));
/* move literals 1 byte ahead */ /* move literals 1 byte ahead */
litp += 2; litp += 2;
if (lit > 0) if (lit > 0)
lzo_memmove(litp + 1, litp, lit); lzo_memmove(litp + 1, litp, lit);
/* insert new length of long literal run */ /* insert new length of long literal run */
lit += 3 + t + 3; assert(lit <= 18); lit += 3 + t + 3;
assert(lit <= 18);
*litp = LZO_BYTE(lit - 3); *litp = LZO_BYTE(lit - 3);
o_m3_b++; o_m3_b++;
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos++;
goto copy_literal_run; goto copy_literal_run;
} }
} }
copy_m: copy_m:
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
do *op++ = *m_pos++; while (--t > 0); *op++ = *m_pos++;
do* op++ = *m_pos++;
while (--t > 0);
} }
match_done: match_done:
if (next_lit == NO_LIT) if (next_lit == NO_LIT)
{ {
t = ip[-2] & 3; t = ip[-2] & 3;
@@ -320,15 +377,23 @@ match_done:
} }
else else
t = next_lit; t = next_lit;
assert(t <= 3); assert(t <= 3);
next_lit = NO_LIT; next_lit = NO_LIT;
if (t == 0) if (t == 0)
break; break;
/* copy literals */ /* copy literals */
match_next: match_next:
do *op++ = *ip++; while (--t > 0);
do* op++ = *ip++;
while (--t > 0);
t = *ip++; t = *ip++;
} while (TEST_IP_AND_TEST_OP); }
while (TEST_IP_AND_TEST_OP);
} }
/* no EOF code was found */ /* no EOF code was found */
@@ -341,8 +406,11 @@ eof_found:
printf("optimize: %5lu %5lu %5lu %5lu %5lu\n", printf("optimize: %5lu %5lu %5lu %5lu %5lu\n",
o_m1_a, o_m1_b, o_m2, o_m3_a, o_m3_b); o_m1_a, o_m1_b, o_m2, o_m3_a, o_m3_b);
#endif #endif
LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2); LZO_UNUSED(o_m1_a);
LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b); LZO_UNUSED(o_m1_b);
LZO_UNUSED(o_m2);
LZO_UNUSED(o_m3_a);
LZO_UNUSED(o_m3_b);
*out_len = pd(op, out); *out_len = pd(op, out);
return (ip == ip_end ? LZO_E_OK : return (ip == ip_end ? LZO_E_OK :
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));

View File

@@ -108,14 +108,18 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
op = out; op = out;
r = init_match(c, swd, NULL, 0, 0); r = init_match(c, swd, NULL, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
if (max_chain > 0) if (max_chain > 0)
swd->max_chain = max_chain; swd->max_chain = max_chain;
r = find_match(c, swd, 0, 0); r = find_match(c, swd, 0, 0);
if (r != 0) if (r != 0)
return r; return r;
while (c->look > 0) while (c->look > 0)
{ {
lzo_uint lazy_match_min_gain = 0; lzo_uint lazy_match_min_gain = 0;
@@ -129,6 +133,7 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
m_off = c->m_off; m_off = c->m_off;
#if (SWD_N >= 8192) #if (SWD_N >= 8192)
if (m_off >= 8192) if (m_off >= 8192)
{ {
if (m_len < M3_MIN_LEN) if (m_len < M3_MIN_LEN)
@@ -165,10 +170,12 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
unsigned char lit = LZO_BYTE(swd->b_char); unsigned char lit = LZO_BYTE(swd->b_char);
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
assert(c->look > 0); assert(c->look > 0);
#if (SWD_N >= 8192) #if (SWD_N >= 8192)
if (m_off < 8192 && c->m_off >= 8192) if (m_off < 8192 && c->m_off >= 8192)
lazy_match_min_gain += extra1; lazy_match_min_gain += extra1;
else else
@@ -179,6 +186,7 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
c->m_len <= M1_MAX_LEN && c->m_off <= 256)) c->m_len <= M1_MAX_LEN && c->m_off <= 256))
lazy_match_min_gain += extra2; lazy_match_min_gain += extra2;
} }
if (c->m_len >= M1_MIN_LEN && if (c->m_len >= M1_MIN_LEN &&
c->m_len <= M1_MAX_LEN && c->m_off <= 256) c->m_len <= M1_MAX_LEN && c->m_off <= 256)
{ {
@@ -206,6 +214,7 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
} }
else else
ahead = 1; ahead = 1;
assert(m_len > 0); assert(m_len > 0);
} }
@@ -217,7 +226,8 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
putbyte(swd->b_char); putbyte(swd->b_char);
c->lit_bytes++; c->lit_bytes++;
r = find_match(c, swd, 1, 0); r = find_match(c, swd, 1, 0);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
else else
{ {
@@ -234,6 +244,7 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
putbyte(m_off - 1); putbyte(m_off - 1);
c->m1++; c->m1++;
} }
#if (SWD_N >= 8192) #if (SWD_N >= 8192)
else if (m_off >= 8192) else if (m_off >= 8192)
{ {
@@ -245,14 +256,17 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
putbyte(m_off >> 5); putbyte(m_off >> 5);
putbit(1); putbit(1);
len -= M3_MIN_LEN - 1; len -= M3_MIN_LEN - 1;
while (len > 255) while (len > 255)
{ {
len -= 255; len -= 255;
putbyte(0); putbyte(0);
} }
putbyte(len); putbyte(len);
c->m4++; c->m4++;
} }
#endif #endif
else else
{ {
@@ -260,6 +274,7 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
putbit(1); putbit(1);
putbit(1); putbit(1);
if (m_len <= 9) if (m_len <= 9)
{ {
putbyte(((m_len - 2) << 5) | (m_off & 31)); putbyte(((m_len - 2) << 5) | (m_off & 31));
@@ -275,17 +290,21 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
putbit(0); putbit(0);
#endif #endif
len -= 10 - 1; len -= 10 - 1;
while (len > 255) while (len > 255)
{ {
len -= 255; len -= 255;
putbyte(0); putbyte(0);
} }
putbyte(len); putbyte(len);
c->m3++; c->m3++;
} }
} }
r = find_match(c, swd, m_len, 1 + ahead); r = find_match(c, swd, m_len, 1 + ahead);
assert(r == 0); LZO_UNUSED(r); assert(r == 0);
LZO_UNUSED(r);
} }
c->codesize = pd(op, out); c->codesize = pd(op, out);
@@ -301,6 +320,7 @@ lzo2a_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
/* flush remaining bits */ /* flush remaining bits */
assert(k < CHAR_BIT); assert(k < CHAR_BIT);
if (k > 0) if (k > 0)
{ {
assert(b == MASKBITS(k)); assert(b == MASKBITS(k));

View File

@@ -62,17 +62,21 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
while (TEST_IP_AND_TEST_OP) while (TEST_IP_AND_TEST_OP)
{ {
NEEDBITS(1); NEEDBITS(1);
if (MASKBITS(1) == 0) if (MASKBITS(1) == 0)
{ {
DUMPBITS(1); DUMPBITS(1);
/* a literal */ /* a literal */
NEED_IP(1); NEED_OP(1); NEED_IP(1);
NEED_OP(1);
*op++ = *ip++; *op++ = *ip++;
continue; continue;
} }
DUMPBITS(1); DUMPBITS(1);
NEEDBITS(1); NEEDBITS(1);
if (MASKBITS(1) == 0) if (MASKBITS(1) == 0)
{ {
DUMPBITS(1); DUMPBITS(1);
@@ -80,13 +84,16 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
NEEDBITS(2); NEEDBITS(2);
t = M1_MIN_LEN + (lzo_uint) MASKBITS(2); t = M1_MIN_LEN + (lzo_uint) MASKBITS(2);
DUMPBITS(2); DUMPBITS(2);
NEED_IP(1); NEED_OP(t); NEED_IP(1);
NEED_OP(t);
m_pos = op - 1 - *ip++; m_pos = op - 1 - *ip++;
assert(m_pos >= out); assert(m_pos < op); assert(m_pos >= out);
assert(m_pos < op);
TEST_LB(m_pos); TEST_LB(m_pos);
MEMCPY_DS(op, m_pos, t); MEMCPY_DS(op, m_pos, t);
continue; continue;
} }
DUMPBITS(1); DUMPBITS(1);
NEED_IP(2); NEED_IP(2);
@@ -94,12 +101,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
m_pos = op; m_pos = op;
m_pos -= (t & 31) | (((lzo_uint) * ip++) << 5); m_pos -= (t & 31) | (((lzo_uint) * ip++) << 5);
t >>= 5; t >>= 5;
if (t == 0) if (t == 0)
{ {
#if (SWD_N >= 8192) #if (SWD_N >= 8192)
NEEDBITS(1); NEEDBITS(1);
t = MASKBITS(1); t = MASKBITS(1);
DUMPBITS(1); DUMPBITS(1);
if (t == 0) if (t == 0)
t = 10 - 1; t = 10 - 1;
else else
@@ -108,10 +117,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
m_pos -= 8192; /* t << 13 */ m_pos -= 8192; /* t << 13 */
t = M3_MIN_LEN - 1; t = M3_MIN_LEN - 1;
} }
#else #else
t = 10 - 1; t = 10 - 1;
#endif #endif
NEED_IP(1); NEED_IP(1);
while (*ip == 0) while (*ip == 0)
{ {
t += 255; t += 255;
@@ -119,17 +130,22 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
TEST_OV(t); TEST_OV(t);
NEED_IP(1); NEED_IP(1);
} }
t += *ip++; t += *ip++;
} }
else else
{ {
#if defined(LZO_EOF_CODE) #if defined(LZO_EOF_CODE)
if (m_pos == op) if (m_pos == op)
goto eof_found; goto eof_found;
#endif #endif
t += 2; t += 2;
} }
assert(m_pos >= out); assert(m_pos < op);
assert(m_pos >= out);
assert(m_pos < op);
TEST_LB(m_pos); TEST_LB(m_pos);
NEED_OP(t); NEED_OP(t);
MEMCPY_DS(op, m_pos, t); MEMCPY_DS(op, m_pos, t);

View File

@@ -35,7 +35,8 @@
// see http://www.zlib.org/ // see http://www.zlib.org/
************************************************************************/ ************************************************************************/
static const lzo_uint32_t lzo_crc32_table[256] = { static const lzo_uint32_t lzo_crc32_table[256] =
{
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
@@ -126,18 +127,22 @@ lzo_crc32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len)
return 0; return 0;
crc = (c & LZO_UINT32_C(0xffffffff)) ^ LZO_UINT32_C(0xffffffff); crc = (c & LZO_UINT32_C(0xffffffff)) ^ LZO_UINT32_C(0xffffffff);
if (len >= 16) do if (len >= 16) do
{ {
LZO_DO16(buf, 0); LZO_DO16(buf, 0);
buf += 16; buf += 16;
len -= 16; len -= 16;
} while (len >= 16); }
while (len >= 16);
if (len != 0) do if (len != 0) do
{ {
LZO_DO1(buf, 0); LZO_DO1(buf, 0);
buf += 1; buf += 1;
len -= 1; len -= 1;
} while (len > 0); }
while (len > 0);
return crc ^ LZO_UINT32_C(0xffffffff); return crc ^ LZO_UINT32_C(0xffffffff);
#undef table #undef table

View File

@@ -40,7 +40,10 @@ BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment,
int __far __pascal LibMain(int a, short b, short c, long d) int __far __pascal LibMain(int a, short b, short c, long d)
#endif #endif
{ {
LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d); LZO_UNUSED(a);
LZO_UNUSED(b);
LZO_UNUSED(c);
LZO_UNUSED(d);
return 1; return 1;
} }

View File

@@ -64,7 +64,9 @@
__lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v) __lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v)
{ {
#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) #if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386)
unsigned long r; (void) _BitScanReverse(&r, v); return (unsigned) r ^ 31; unsigned long r;
(void) _BitScanReverse(&r, v);
return (unsigned) r ^ 31;
#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) #define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v)
#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) #elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC)
lzo_uint32_t r; lzo_uint32_t r;
@@ -72,13 +74,18 @@ __lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v)
return (unsigned) r ^ 31; return (unsigned) r ^ 31;
#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) #define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v)
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT == 4) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT == 4)
unsigned r; r = (unsigned) __builtin_clz(v); return r; unsigned r;
r = (unsigned) __builtin_clz(v);
return r;
#define lzo_bitops_ctlz32(v) ((unsigned) __builtin_clz(v)) #define lzo_bitops_ctlz32(v) ((unsigned) __builtin_clz(v))
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8)
unsigned r; r = (unsigned) __builtin_clzl(v); return r ^ 32; unsigned r;
r = (unsigned) __builtin_clzl(v);
return r ^ 32;
#define lzo_bitops_ctlz32(v) (((unsigned) __builtin_clzl(v)) ^ 32) #define lzo_bitops_ctlz32(v) (((unsigned) __builtin_clzl(v)) ^ 32)
#else #else
LZO_UNUSED(v); return 0; LZO_UNUSED(v);
return 0;
#endif #endif
} }
@@ -86,7 +93,9 @@ __lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v)
__lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v) __lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v)
{ {
#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) #if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64)
unsigned long r; (void) _BitScanReverse64(&r, v); return (unsigned) r ^ 63; unsigned long r;
(void) _BitScanReverse64(&r, v);
return (unsigned) r ^ 63;
#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) #define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v)
#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) #elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC)
lzo_uint64_t r; lzo_uint64_t r;
@@ -94,13 +103,18 @@ __lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v)
return (unsigned) r ^ 63; return (unsigned) r ^ 63;
#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) #define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v)
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8)
unsigned r; r = (unsigned) __builtin_clzl(v); return r; unsigned r;
r = (unsigned) __builtin_clzl(v);
return r;
#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzl(v)) #define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzl(v))
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG == 8) && (LZO_WORDSIZE >= 8) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG == 8) && (LZO_WORDSIZE >= 8)
unsigned r; r = (unsigned) __builtin_clzll(v); return r; unsigned r;
r = (unsigned) __builtin_clzll(v);
return r;
#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzll(v)) #define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzll(v))
#else #else
LZO_UNUSED(v); return 0; LZO_UNUSED(v);
return 0;
#endif #endif
} }
#endif #endif
@@ -108,7 +122,9 @@ __lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v)
__lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v) __lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v)
{ {
#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) #if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386)
unsigned long r; (void) _BitScanForward(&r, v); return (unsigned) r; unsigned long r;
(void) _BitScanForward(&r, v);
return (unsigned) r;
#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) #define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v)
#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) #elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC)
lzo_uint32_t r; lzo_uint32_t r;
@@ -116,10 +132,13 @@ __lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v)
return (unsigned) r; return (unsigned) r;
#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) #define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v)
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT >= 4) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT >= 4)
unsigned r; r = (unsigned) __builtin_ctz(v); return r; unsigned r;
r = (unsigned) __builtin_ctz(v);
return r;
#define lzo_bitops_cttz32(v) ((unsigned) __builtin_ctz(v)) #define lzo_bitops_cttz32(v) ((unsigned) __builtin_ctz(v))
#else #else
LZO_UNUSED(v); return 0; LZO_UNUSED(v);
return 0;
#endif #endif
} }
@@ -127,7 +146,9 @@ __lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v)
__lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v) __lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v)
{ {
#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) #if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64)
unsigned long r; (void) _BitScanForward64(&r, v); return (unsigned) r; unsigned long r;
(void) _BitScanForward64(&r, v);
return (unsigned) r;
#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) #define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v)
#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) #elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC)
lzo_uint64_t r; lzo_uint64_t r;
@@ -135,13 +156,18 @@ __lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v)
return (unsigned) r; return (unsigned) r;
#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) #define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v)
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG >= 8) && (LZO_WORDSIZE >= 8) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG >= 8) && (LZO_WORDSIZE >= 8)
unsigned r; r = (unsigned) __builtin_ctzl(v); return r; unsigned r;
r = (unsigned) __builtin_ctzl(v);
return r;
#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzl(v)) #define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzl(v))
#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG >= 8) && (LZO_WORDSIZE >= 8) #elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG >= 8) && (LZO_WORDSIZE >= 8)
unsigned r; r = (unsigned) __builtin_ctzll(v); return r; unsigned r;
r = (unsigned) __builtin_ctzll(v);
return r;
#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzll(v)) #define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzll(v))
#else #else
LZO_UNUSED(v); return 0; LZO_UNUSED(v);
return 0;
#endif #endif
} }
#endif #endif

View File

@@ -65,7 +65,8 @@
// //
************************************************************************/ ************************************************************************/
union lzo_config_check_union { union lzo_config_check_union
{
lzo_uint a[2]; lzo_uint a[2];
unsigned char b[2 * LZO_MAX(8, sizeof(lzo_uint))]; unsigned char b[2 * LZO_MAX(8, sizeof(lzo_uint))];
#if defined(lzo_uint64_t) #if defined(lzo_uint64_t)
@@ -102,17 +103,20 @@ _lzo_config_check(void)
r &= ((* (lzo_bytep) p) == 0); r &= ((* (lzo_bytep) p) == 0);
#if !(LZO_CFG_NO_CONFIG_CHECK) #if !(LZO_CFG_NO_CONFIG_CHECK)
#if (LZO_ABI_BIG_ENDIAN) #if (LZO_ABI_BIG_ENDIAN)
u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; u.a[0] = u.a[1] = 0;
u.b[sizeof(lzo_uint) - 1] = 128;
p = u2p(&u, 0); p = u2p(&u, 0);
r &= ((* (lzo_uintp) p) == 128); r &= ((* (lzo_uintp) p) == 128);
#endif #endif
#if (LZO_ABI_LITTLE_ENDIAN) #if (LZO_ABI_LITTLE_ENDIAN)
u.a[0] = u.a[1] = 0; u.b[0] = 128; u.a[0] = u.a[1] = 0;
u.b[0] = 128;
p = u2p(&u, 0); p = u2p(&u, 0);
r &= ((* (lzo_uintp) p) == 128); r &= ((* (lzo_uintp) p) == 128);
#endif #endif
u.a[0] = u.a[1] = 0; u.a[0] = u.a[1] = 0;
u.b[0] = 1; u.b[3] = 2; u.b[0] = 1;
u.b[3] = 2;
p = u2p(&u, 1); p = u2p(&u, 1);
r &= UA_GET_NE16(p) == 0; r &= UA_GET_NE16(p) == 0;
r &= UA_GET_LE16(p) == 0; r &= UA_GET_LE16(p) == 0;
@@ -127,13 +131,16 @@ _lzo_config_check(void)
r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8180); r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8180);
#endif #endif
u.a[0] = u.a[1] = 0; u.a[0] = u.a[1] = 0;
u.b[0] = 3; u.b[5] = 4; u.b[0] = 3;
u.b[5] = 4;
p = u2p(&u, 1); p = u2p(&u, 1);
r &= UA_GET_NE32(p) == 0; r &= UA_GET_NE32(p) == 0;
r &= UA_GET_LE32(p) == 0; r &= UA_GET_LE32(p) == 0;
u.b[1] = 128; u.b[1] = 128;
r &= UA_GET_LE32(p) == 128; r &= UA_GET_LE32(p) == 128;
u.b[2] = 129; u.b[3] = 130; u.b[4] = 131; u.b[2] = 129;
u.b[3] = 130;
u.b[4] = 131;
r &= UA_GET_LE32(p) == LZO_UINT32_C(0x83828180); r &= UA_GET_LE32(p) == LZO_UINT32_C(0x83828180);
#if (LZO_ABI_BIG_ENDIAN) #if (LZO_ABI_BIG_ENDIAN)
r &= UA_GET_NE32(p) == LZO_UINT32_C(0x80818283); r &= UA_GET_NE32(p) == LZO_UINT32_C(0x80818283);
@@ -143,7 +150,8 @@ _lzo_config_check(void)
#endif #endif
#if defined(UA_GET_NE64) #if defined(UA_GET_NE64)
u.c[0] = u.c[1] = 0; u.c[0] = u.c[1] = 0;
u.b[0] = 5; u.b[9] = 6; u.b[0] = 5;
u.b[9] = 6;
p = u2p(&u, 1); p = u2p(&u, 1);
u.c[0] = u.c[1] = 0; u.c[0] = u.c[1] = 0;
r &= UA_GET_NE64(p) == 0; r &= UA_GET_NE64(p) == 0;
@@ -154,32 +162,52 @@ _lzo_config_check(void)
#endif #endif
#endif #endif
#if defined(lzo_bitops_ctlz32) #if defined(lzo_bitops_ctlz32)
{ unsigned i = 0; lzo_uint32_t v; {
for (v = 1; v != 0 && r == 1; v <<= 1, i++) { unsigned i = 0;
lzo_uint32_t v;
for (v = 1; v != 0 && r == 1; v <<= 1, i++)
{
r &= lzo_bitops_ctlz32(v) == 31 - i; r &= lzo_bitops_ctlz32(v) == 31 - i;
r &= lzo_bitops_ctlz32_func(v) == 31 - i; r &= lzo_bitops_ctlz32_func(v) == 31 - i;
}} }
}
#endif #endif
#if defined(lzo_bitops_ctlz64) #if defined(lzo_bitops_ctlz64)
{ unsigned i = 0; lzo_uint64_t v; {
for (v = 1; v != 0 && r == 1; v <<= 1, i++) { unsigned i = 0;
lzo_uint64_t v;
for (v = 1; v != 0 && r == 1; v <<= 1, i++)
{
r &= lzo_bitops_ctlz64(v) == 63 - i; r &= lzo_bitops_ctlz64(v) == 63 - i;
r &= lzo_bitops_ctlz64_func(v) == 63 - i; r &= lzo_bitops_ctlz64_func(v) == 63 - i;
}} }
}
#endif #endif
#if defined(lzo_bitops_cttz32) #if defined(lzo_bitops_cttz32)
{ unsigned i = 0; lzo_uint32_t v; {
for (v = 1; v != 0 && r == 1; v <<= 1, i++) { unsigned i = 0;
lzo_uint32_t v;
for (v = 1; v != 0 && r == 1; v <<= 1, i++)
{
r &= lzo_bitops_cttz32(v) == i; r &= lzo_bitops_cttz32(v) == i;
r &= lzo_bitops_cttz32_func(v) == i; r &= lzo_bitops_cttz32_func(v) == i;
}} }
}
#endif #endif
#if defined(lzo_bitops_cttz64) #if defined(lzo_bitops_cttz64)
{ unsigned i = 0; lzo_uint64_t v; {
for (v = 1; v != 0 && r == 1; v <<= 1, i++) { unsigned i = 0;
lzo_uint64_t v;
for (v = 1; v != 0 && r == 1; v <<= 1, i++)
{
r &= lzo_bitops_cttz64(v) == i; r &= lzo_bitops_cttz64(v) == i;
r &= lzo_bitops_cttz64_func(v) == i; r &= lzo_bitops_cttz64_func(v) == i;
}} }
}
#endif #endif
#endif #endif
LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); LZO_UNUSED_FUNC(lzo_bitops_unused_funcs);
@@ -220,10 +248,12 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5,
(s7 == -1 || s7 == (int) sizeof(char*)) && (s7 == -1 || s7 == (int) sizeof(char*)) &&
(s8 == -1 || s8 == (int) sizeof(lzo_voidp)) && (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
(s9 == -1 || s9 == (int) sizeof(lzo_callback_t)); (s9 == -1 || s9 == (int) sizeof(lzo_callback_t));
if (!r) if (!r)
return LZO_E_ERROR; return LZO_E_ERROR;
r = _lzo_config_check(); r = _lzo_config_check();
if (r != LZO_E_OK) if (r != LZO_E_OK)
return r; return r;

View File

@@ -128,6 +128,7 @@ init_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
c->lazy = 0; c->lazy = 0;
r = swd_init(s, dict, dict_len); r = swd_init(s, dict, dict_len);
if (r != LZO_E_OK) if (r != LZO_E_OK)
{ {
swd_exit(s); swd_exit(s);
@@ -164,8 +165,10 @@ find_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
s->m_len = SWD_THRESHOLD; s->m_len = SWD_THRESHOLD;
s->m_off = 0; s->m_off = 0;
#ifdef SWD_BEST_OFF #ifdef SWD_BEST_OFF
if (s->use_best_off) if (s->use_best_off)
lzo_memset(s->best_pos, 0, sizeof(s->best_pos)); lzo_memset(s->best_pos, 0, sizeof(s->best_pos));
#endif #endif
swd_findbest(s); swd_findbest(s);
c->m_len = s->m_len; c->m_len = s->m_len;
@@ -183,9 +186,11 @@ find_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
{ {
c->look = s->look + 1; c->look = s->look + 1;
} }
c->bp = c->ip - c->look; c->bp = c->ip - c->look;
#if 0 #if 0
/* brute force match search */ /* brute force match search */
if (c->m_len > SWD_THRESHOLD && c->m_len + 1 <= c->look) if (c->m_len > SWD_THRESHOLD && c->m_len + 1 <= c->look)
{ {
@@ -195,18 +200,23 @@ find_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
if (ip - in > s->swd_n) if (ip - in > s->swd_n)
in = ip - s->swd_n; in = ip - s->swd_n;
for (;;) for (;;)
{ {
while (*in != *ip) while (*in != *ip)
in++; in++;
if (in == ip) if (in == ip)
break; break;
if (in != m) if (in != m)
if (lzo_memcmp(in, ip, c->m_len + 1) == 0) if (lzo_memcmp(in, ip, c->m_len + 1) == 0)
printf("%p %p %p %5d\n", in, ip, m, c->m_len); printf("%p %p %p %5d\n", in, ip, m, c->m_len);
in++; in++;
} }
} }
#endif #endif
if (c->cb && c->cb->nprogress && c->textsize > c->printcount) if (c->cb && c->cb->nprogress && c->textsize > c->printcount)

View File

@@ -61,14 +61,19 @@ __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" #error "__LZO_UINTPTR_T_IS_POINTER is unsupported"
#else #else
lzo_uintptr_t p, n; lzo_uintptr_t p, n;
if (size < 2) return 0; if (size < 2) return 0;
p = __lzo_ptr_linear(ptr); p = __lzo_ptr_linear(ptr);
#if 0 #if 0
n = (((p + size - 1) / size) * size) - p; n = (((p + size - 1) / size) * size) - p;
#else #else
if ((size & (size - 1)) != 0) if ((size & (size - 1)) != 0)
return 0; return 0;
n = size; n = ((p + n - 1) & ~(n - 1)) - p;
n = size;
n = ((p + n - 1) & ~(n - 1)) - p;
#endif #endif
#endif #endif
assert((long)n >= 0); assert((long)n >= 0);

File diff suppressed because it is too large Load Diff

View File

@@ -189,6 +189,7 @@ void swd_initdict(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
if (!dict || dict_len == 0) if (!dict || dict_len == 0)
return; return;
if (dict_len > s->swd_n) if (dict_len > s->swd_n)
{ {
dict += dict_len - s->swd_n; dict += dict_len - s->swd_n;
@@ -221,7 +222,8 @@ void swd_insertdict(lzo_swd_p s, lzo_uint node, lzo_uint len)
assert(s_llen3(s)[key] <= s->swd_n); assert(s_llen3(s)[key] <= s->swd_n);
#ifdef HEAD2 #ifdef HEAD2
IF_HEAD2(s) { IF_HEAD2(s)
{
key = HEAD2(s_b(s), node); key = HEAD2(s_b(s), node);
s_head2(s)[key] = SWD_UINT(node); s_head2(s)[key] = SWD_UINT(node);
} }
@@ -255,15 +257,19 @@ int swd_init(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
r &= s->best3 != NULL; r &= s->best3 != NULL;
r &= s->llen3 != NULL; r &= s->llen3 != NULL;
#ifdef HEAD2 #ifdef HEAD2
IF_HEAD2(s) { IF_HEAD2(s)
{
s->head2 = (swd_uintp) malloc(sizeof(swd_uint) * 65536L); s->head2 = (swd_uintp) malloc(sizeof(swd_uint) * 65536L);
r &= s->head2 != NULL; r &= s->head2 != NULL;
} }
#endif #endif
if (r != 1) {
if (r != 1)
{
swd_exit(s); swd_exit(s);
return LZO_E_OUT_OF_MEMORY; return LZO_E_OUT_OF_MEMORY;
} }
#endif #endif
s->m_len = 0; s->m_len = 0;
@@ -271,6 +277,7 @@ int swd_init(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
#if defined(SWD_BEST_OFF) #if defined(SWD_BEST_OFF)
{ {
unsigned i; unsigned i;
for (i = 0; i < SWD_BEST_OFF; i++) for (i = 0; i < SWD_BEST_OFF; i++)
s->best_off[i] = s->best_pos[i] = 0; s->best_off[i] = s->best_pos[i] = 0;
} }
@@ -288,8 +295,10 @@ int swd_init(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
s->b_size = s->swd_n + s->swd_f; s->b_size = s->swd_n + s->swd_f;
#if 0 #if 0
if (2 * s->swd_f >= s->swd_n || s->b_size + s->swd_f >= SWD_UINT_MAX) if (2 * s->swd_f >= s->swd_n || s->b_size + s->swd_f >= SWD_UINT_MAX)
return LZO_E_ERROR; return LZO_E_ERROR;
#else #else
LZO_COMPILE_TIME_ASSERT(!(0ul + 2 * SWD_F >= SWD_N)) LZO_COMPILE_TIME_ASSERT(!(0ul + 2 * SWD_F >= SWD_N))
LZO_COMPILE_TIME_ASSERT(!(0ul + SWD_N + SWD_F + SWD_F >= SWD_UINT_MAX)) LZO_COMPILE_TIME_ASSERT(!(0ul + SWD_N + SWD_F + SWD_F >= SWD_UINT_MAX))
@@ -299,14 +308,17 @@ int swd_init(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
lzo_memset(s_llen3(s), 0, (lzo_uint)sizeof(s_llen3(s)[0]) * (lzo_uint)SWD_HSIZE); lzo_memset(s_llen3(s), 0, (lzo_uint)sizeof(s_llen3(s)[0]) * (lzo_uint)SWD_HSIZE);
#ifdef HEAD2 #ifdef HEAD2
IF_HEAD2(s) { IF_HEAD2(s)
{
#if 1 #if 1
lzo_memset(s_head2(s), 0xff, (lzo_uint)sizeof(s_head2(s)[0]) * 65536L); lzo_memset(s_head2(s), 0xff, (lzo_uint)sizeof(s_head2(s)[0]) * 65536L);
assert(s_head2(s)[0] == NIL2); assert(s_head2(s)[0] == NIL2);
#else #else
lzo_xint i; lzo_xint i;
for (i = 0; i < 65536L; i++) for (i = 0; i < 65536L; i++)
s_head2(s)[i] = NIL2; s_head2(s)[i] = NIL2;
#endif #endif
} }
#endif #endif
@@ -319,26 +331,34 @@ int swd_init(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
assert(s->ip + s->swd_f <= s->b_size); assert(s->ip + s->swd_f <= s->b_size);
#if 1 #if 1
s->look = (lzo_uint)(s->c->in_end - s->c->ip); s->look = (lzo_uint)(s->c->in_end - s->c->ip);
if (s->look > 0) if (s->look > 0)
{ {
if (s->look > s->swd_f) if (s->look > s->swd_f)
s->look = s->swd_f; s->look = s->swd_f;
lzo_memcpy(&s_b(s)[s->ip], s->c->ip, s->look); lzo_memcpy(&s_b(s)[s->ip], s->c->ip, s->look);
s->c->ip += s->look; s->c->ip += s->look;
s->ip += s->look; s->ip += s->look;
} }
#else #else
s->look = 0; s->look = 0;
while (s->look < s->swd_f) while (s->look < s->swd_f)
{ {
int c; int c;
if ((c = getbyte(*(s->c))) < 0) if ((c = getbyte(*(s->c))) < 0)
break; break;
s_b(s)[s->ip] = LZO_BYTE(c); s_b(s)[s->ip] = LZO_BYTE(c);
s->ip++; s->ip++;
s->look++; s->look++;
} }
#endif #endif
if (s->ip == s->b_size) if (s->ip == s->b_size)
s->ip = 0; s->ip = 0;
@@ -346,18 +366,22 @@ int swd_init(lzo_swd_p s, const lzo_bytep dict, lzo_uint dict_len)
swd_insertdict(s, 0, s->dict_len); swd_insertdict(s, 0, s->dict_len);
s->rp = s->first_rp; s->rp = s->first_rp;
if (s->rp >= s->node_count) if (s->rp >= s->node_count)
s->rp -= s->node_count; s->rp -= s->node_count;
else else
s->rp += s->b_size - s->node_count; s->rp += s->b_size - s->node_count;
#if 1 || defined(__LZO_CHECKER) #if 1 || defined(__LZO_CHECKER)
/* initialize memory for the first few HEAD3 (if s->ip is not far /* initialize memory for the first few HEAD3 (if s->ip is not far
* enough ahead to do this job for us). The value doesn't matter. */ * enough ahead to do this job for us). The value doesn't matter. */
if (s->look < 3) { if (s->look < 3)
{
lzo_bytep p = &s_b(s)[s->bp + s->look]; lzo_bytep p = &s_b(s)[s->bp + s->look];
p[0] = p[1] = p[2] = 0; p[0] = p[1] = p[2] = 0;
} }
#endif #endif
return LZO_E_OK; return LZO_E_OK;
@@ -370,13 +394,19 @@ void swd_exit(lzo_swd_p s)
#if defined(__LZO_CHECKER) #if defined(__LZO_CHECKER)
/* free in reverse order of allocations */ /* free in reverse order of allocations */
#ifdef HEAD2 #ifdef HEAD2
free(s->head2); s->head2 = NULL; free(s->head2);
s->head2 = NULL;
#endif #endif
free(s->llen3); s->llen3 = NULL; free(s->llen3);
free(s->best3); s->best3 = NULL; s->llen3 = NULL;
free(s->succ3); s->succ3 = NULL; free(s->best3);
free(s->head3); s->head3 = NULL; s->best3 = NULL;
free(s->b); s->b = NULL; free(s->succ3);
s->succ3 = NULL;
free(s->head3);
s->head3 = NULL;
free(s->b);
s->b = NULL;
#else #else
LZO_UNUSED(s); LZO_UNUSED(s);
#endif #endif
@@ -400,23 +430,30 @@ void swd_getbyte(lzo_swd_p s)
{ {
if (s->look > 0) if (s->look > 0)
--s->look; --s->look;
#if 1 || defined(__LZO_CHECKER) #if 1 || defined(__LZO_CHECKER)
/* initialize memory - value doesn't matter */ /* initialize memory - value doesn't matter */
s_b(s)[s->ip] = 0; s_b(s)[s->ip] = 0;
if (s->ip < s->swd_f) if (s->ip < s->swd_f)
s->b_wrap[s->ip] = 0; s->b_wrap[s->ip] = 0;
#endif #endif
} }
else else
{ {
s_b(s)[s->ip] = LZO_BYTE(c); s_b(s)[s->ip] = LZO_BYTE(c);
if (s->ip < s->swd_f) if (s->ip < s->swd_f)
s->b_wrap[s->ip] = LZO_BYTE(c); s->b_wrap[s->ip] = LZO_BYTE(c);
} }
if (++s->ip == s->b_size) if (++s->ip == s->b_size)
s->ip = 0; s->ip = 0;
if (++s->bp == s->b_size) if (++s->bp == s->b_size)
s->bp = 0; s->bp = 0;
if (++s->rp == s->b_size) if (++s->rp == s->b_size)
s->rp = 0; s->rp = 0;
} }
@@ -434,6 +471,7 @@ void swd_remove_node(lzo_swd_p s, lzo_uint node)
lzo_uint key; lzo_uint key;
#ifdef LZO_DEBUG #ifdef LZO_DEBUG
if (s->first_rp != LZO_UINT_MAX) if (s->first_rp != LZO_UINT_MAX)
{ {
if (node != s->first_rp) if (node != s->first_rp)
@@ -441,9 +479,11 @@ void swd_remove_node(lzo_swd_p s, lzo_uint node)
(long)node, (long)s->rp, (long)s->ip, (long)s->bp, (long)node, (long)s->rp, (long)s->ip, (long)s->bp,
(long)s->first_rp, (long)(s->ip - node), (long)s->first_rp, (long)(s->ip - node),
(long)(s->ip - s->bp)); (long)(s->ip - s->bp));
assert(node == s->first_rp); assert(node == s->first_rp);
s->first_rp = LZO_UINT_MAX; s->first_rp = LZO_UINT_MAX;
} }
#endif #endif
key = HEAD3(s_b(s), node); key = HEAD3(s_b(s), node);
@@ -451,9 +491,11 @@ void swd_remove_node(lzo_swd_p s, lzo_uint node)
--s_llen3(s)[key]; --s_llen3(s)[key];
#ifdef HEAD2 #ifdef HEAD2
IF_HEAD2(s) { IF_HEAD2(s)
{
key = HEAD2(s_b(s), node); key = HEAD2(s_b(s), node);
assert(s_head2(s)[key] != NIL2); assert(s_head2(s)[key] != NIL2);
if ((lzo_uint) s_head2(s)[key] == node) if ((lzo_uint) s_head2(s)[key] == node)
s_head2(s)[key] = NIL2; s_head2(s)[key] = NIL2;
} }
@@ -489,14 +531,16 @@ void swd_accept(lzo_swd_p s, lzo_uint n)
#ifdef HEAD2 #ifdef HEAD2
/* add bp into HEAD2 */ /* add bp into HEAD2 */
IF_HEAD2(s) { IF_HEAD2(s)
{
key = HEAD2(s_b(s), s->bp); key = HEAD2(s_b(s), s->bp);
s_head2(s)[key] = SWD_UINT(s->bp); s_head2(s)[key] = SWD_UINT(s->bp);
} }
#endif #endif
swd_getbyte(s); swd_getbyte(s);
} while (--n != 0); }
while (--n != 0);
} }
@@ -519,6 +563,7 @@ void swd_search(lzo_swd_p s, lzo_uint node, lzo_uint cnt)
assert(s->m_len > 0); assert(s->m_len > 0);
scan_end1 = bp[m_len - 1]; scan_end1 = bp[m_len - 1];
for (; cnt-- > 0; node = s_succ3(s)[node]) for (; cnt-- > 0; node = s_succ3(s)[node])
{ {
p1 = bp; p1 = bp;
@@ -539,42 +584,59 @@ void swd_search(lzo_swd_p s, lzo_uint node, lzo_uint cnt)
assert(lzo_memcmp(bp, &b[node], 3) == 0); assert(lzo_memcmp(bp, &b[node], 3) == 0);
#if 0 && (LZO_OPT_UNALIGNED32) #if 0 && (LZO_OPT_UNALIGNED32)
p1 += 3; p2 += 3; p1 += 3;
p2 += 3;
while (p1 + 4 <= px && UA_GET_NE32(p1) == UA_GET_NE32(p2)) while (p1 + 4 <= px && UA_GET_NE32(p1) == UA_GET_NE32(p2))
p1 += 4, p2 += 4; p1 += 4, p2 += 4;
while (p1 < px && *p1 == *p2) while (p1 < px && *p1 == *p2)
p1 += 1, p2 += 1; p1 += 1, p2 += 1;
#else #else
p1 += 2; p2 += 2; p1 += 2;
do {} while (++p1 < px && *p1 == *++p2); p2 += 2;
do {}
while (++p1 < px && *p1 == *++p2);
#endif #endif
i = pd(p1, bp); i = pd(p1, bp);
#ifdef LZO_DEBUG #ifdef LZO_DEBUG
if (lzo_memcmp(bp, &b[node], i) != 0) if (lzo_memcmp(bp, &b[node], i) != 0)
printf("%5ld %5ld %5ld %02x/%02x %02x/%02x\n", printf("%5ld %5ld %5ld %02x/%02x %02x/%02x\n",
(long)s->bp, (long) node, (long) i, (long)s->bp, (long) node, (long) i,
bp[0], bp[1], b[node], b[node + 1]); bp[0], bp[1], b[node], b[node + 1]);
#endif #endif
assert(lzo_memcmp(bp, &b[node], i) == 0); assert(lzo_memcmp(bp, &b[node], i) == 0);
#if defined(SWD_BEST_OFF) #if defined(SWD_BEST_OFF)
if (i < SWD_BEST_OFF) if (i < SWD_BEST_OFF)
{ {
if (s->best_pos[i] == 0) if (s->best_pos[i] == 0)
s->best_pos[i] = node + 1; s->best_pos[i] = node + 1;
} }
#endif #endif
if (i > m_len) if (i > m_len)
{ {
s->m_len = m_len = i; s->m_len = m_len = i;
s->m_pos = node; s->m_pos = node;
if (m_len == s->look) if (m_len == s->look)
return; return;
if (m_len >= s->nice_length) if (m_len >= s->nice_length)
return; return;
if (m_len > (lzo_uint) s_best3(s)[node]) if (m_len > (lzo_uint) s_best3(s)[node])
return; return;
scan_end1 = bp[m_len - 1]; scan_end1 = bp[m_len - 1];
} }
} }
@@ -597,17 +659,23 @@ lzo_bool swd_search2(lzo_swd_p s)
assert(s->m_len > 0); assert(s->m_len > 0);
key = s_head2(s)[ HEAD2(s_b(s), s->bp) ]; key = s_head2(s)[ HEAD2(s_b(s), s->bp) ];
if (key == NIL2) if (key == NIL2)
return 0; return 0;
#ifdef LZO_DEBUG #ifdef LZO_DEBUG
if (lzo_memcmp(&s_b(s)[s->bp], &s_b(s)[key], 2) != 0) if (lzo_memcmp(&s_b(s)[s->bp], &s_b(s)[key], 2) != 0)
printf("%5ld %5ld %02x/%02x %02x/%02x\n", (long)s->bp, (long)key, printf("%5ld %5ld %02x/%02x %02x/%02x\n", (long)s->bp, (long)key,
s_b(s)[s->bp], s_b(s)[s->bp + 1], s_b(s)[key], s_b(s)[key + 1]); s_b(s)[s->bp], s_b(s)[s->bp + 1], s_b(s)[key], s_b(s)[key + 1]);
#endif #endif
assert(lzo_memcmp(&s_b(s)[s->bp], &s_b(s)[key], 2) == 0); assert(lzo_memcmp(&s_b(s)[s->bp], &s_b(s)[key], 2) == 0);
#if defined(SWD_BEST_OFF) #if defined(SWD_BEST_OFF)
if (s->best_pos[2] == 0) if (s->best_pos[2] == 0)
s->best_pos[2] = key + 1; s->best_pos[2] = key + 1;
#endif #endif
if (s->m_len < 2) if (s->m_len < 2)
@@ -615,6 +683,7 @@ lzo_bool swd_search2(lzo_swd_p s)
s->m_len = 2; s->m_len = 2;
s->m_pos = key; s->m_pos = key;
} }
return 1; return 1;
} }
@@ -639,42 +708,55 @@ void swd_findbest(lzo_swd_p s)
node = s_succ3(s)[s->bp] = s_get_head3(s, key); node = s_succ3(s)[s->bp] = s_get_head3(s, key);
cnt = s_llen3(s)[key]++; cnt = s_llen3(s)[key]++;
assert(s_llen3(s)[key] <= s->swd_n + s->swd_f); assert(s_llen3(s)[key] <= s->swd_n + s->swd_f);
if (cnt > s->max_chain && s->max_chain > 0) if (cnt > s->max_chain && s->max_chain > 0)
cnt = s->max_chain; cnt = s->max_chain;
s_head3(s)[key] = SWD_UINT(s->bp); s_head3(s)[key] = SWD_UINT(s->bp);
s->b_char = s_b(s)[s->bp]; s->b_char = s_b(s)[s->bp];
len = s->m_len; len = s->m_len;
if (s->m_len >= s->look) if (s->m_len >= s->look)
{ {
if (s->look == 0) if (s->look == 0)
s->b_char = -1; s->b_char = -1;
s->m_off = 0; s->m_off = 0;
s_best3(s)[s->bp] = SWD_UINT(s->swd_f + 1); s_best3(s)[s->bp] = SWD_UINT(s->swd_f + 1);
} }
else else
{ {
#if defined(HEAD2) #if defined(HEAD2)
if (swd_search2(s) && s->look >= 3) if (swd_search2(s) && s->look >= 3)
swd_search(s, node, cnt); swd_search(s, node, cnt);
#else #else
if (s->look >= 3) if (s->look >= 3)
swd_search(s, node, cnt); swd_search(s, node, cnt);
#endif #endif
if (s->m_len > len) if (s->m_len > len)
s->m_off = swd_pos2off(s, s->m_pos); s->m_off = swd_pos2off(s, s->m_pos);
s_best3(s)[s->bp] = SWD_UINT(s->m_len); s_best3(s)[s->bp] = SWD_UINT(s->m_len);
#if defined(SWD_BEST_OFF) #if defined(SWD_BEST_OFF)
if (s->use_best_off) if (s->use_best_off)
{ {
unsigned i; unsigned i;
for (i = 2; i < SWD_BEST_OFF; i++) for (i = 2; i < SWD_BEST_OFF; i++)
if (s->best_pos[i] > 0) if (s->best_pos[i] > 0)
s->best_off[i] = swd_pos2off(s, s->best_pos[i] - 1); s->best_off[i] = swd_pos2off(s, s->best_pos[i] - 1);
else else
s->best_off[i] = 0; s->best_off[i] = 0;
} }
#endif #endif
} }
@@ -682,7 +764,8 @@ void swd_findbest(lzo_swd_p s)
#ifdef HEAD2 #ifdef HEAD2
/* add bp into HEAD2 */ /* add bp into HEAD2 */
IF_HEAD2(s) { IF_HEAD2(s)
{
key = HEAD2(s_b(s), s->bp); key = HEAD2(s_b(s), s->bp);
s_head2(s)[key] = SWD_UINT(s->bp); s_head2(s)[key] = SWD_UINT(s->bp);
} }

View File

@@ -121,20 +121,26 @@ lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len)
{ {
k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX; k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
len -= k; len -= k;
if (k >= 16) do if (k >= 16) do
{ {
LZO_DO16(buf, 0); LZO_DO16(buf, 0);
buf += 16; buf += 16;
k -= 16; k -= 16;
} while (k >= 16); }
while (k >= 16);
if (k != 0) do if (k != 0) do
{ {
s1 += *buf++; s1 += *buf++;
s2 += s1; s2 += s1;
} while (--k > 0); }
while (--k > 0);
s1 %= LZO_BASE; s1 %= LZO_BASE;
s2 %= LZO_BASE; s2 %= LZO_BASE;
} }
return (s2 << 16) | s1; return (s2 << 16) | s1;
} }

View File

@@ -57,7 +57,8 @@ extern "C" {
// //
************************************************************************/ ************************************************************************/
typedef struct { typedef struct
{
/* configuration */ /* configuration */
unsigned rbits; unsigned rbits;

11
extern/yaml/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,11 @@
set(YAML_VERSION_MAJOR 0)
set(YAML_VERSION_MINOR 1)
set(YAML_VERSION_PATCH 6)
set(YAML_VERSION_STRING "${YAML_VERSION_MAJOR}.${YAML_VERSION_MINOR}.${YAML_VERSION_PATCH}")
file(GLOB SRC src/*.c)
include_directories(../../include)
add_library(AthenaLibYaml STATIC ${SRC})
install(TARGETS AthenaLibYaml DESTINATION lib COMPONENT yaml)

19
extern/yaml/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2006 Kirill Simonov
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

27
extern/yaml/README vendored Normal file
View File

@@ -0,0 +1,27 @@
LibYAML - A C library for parsing and emitting YAML.
To build and install the library, run:
$ ./configure
$ make
# make install
If you checked the source code from the Subversion repository, run
$ ./bootstrap
$ ./configure
$ make
# make install
For more information, check the LibYAML homepage:
'http://pyyaml.org/wiki/LibYAML'.
Post your questions and opinions to the YAML-Core mailing list:
'http://lists.sourceforge.net/lists/listinfo/yaml-core'.
Submit bug reports and feature requests to the LibYAML bug tracker:
'http://pyyaml.org/newticket?component=libyaml'.
LibYAML is written by Kirill Simonov <xi@resolvent.net>. It is released
under the MIT license. See the file LICENSE for more details.
This project is developed for Python Software Foundation as a part of
Google Summer of Code under the mentorship of Clark Evans.

28
extern/yaml/announcement.msg vendored Normal file
View File

@@ -0,0 +1,28 @@
From: Kirill Simonov <xi@resolvent.net>
To: yaml-core@lists.sourceforge.net
Subject: LibYAML-0.1.4: A minor bugfix release
This is a minor bugfix release of LibYAML, a YAML parser and emitter
written in C:
* Fixed a bug that prevented an empty mapping being used as a simple key
(thank to spitzak(at)rhythm(dot)com).
* Fixed pointer overflow when calculating the position of a potential
simple key (thank to ppelletier(at)oblong(dot)com).
* Fixed yaml.dll not exporting any symbols
(thank to pxn11432(at)nifty(dot)com).
* Added pkg-config support (thank to rainwoodman(at)gmail(dot)com).
LibYAML homepage: http://pyyaml.org/wiki/LibYAML
TAR.GZ package: http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
SVN repository: http://svn.pyyaml.org/libyaml/branches/stable
Bug tracker: http://pyyaml.org/newticket?component=libyaml
The library is functionally complete, but the documentation is scarce
and the API may change. For more information, you may check the project
homepage, the doxygen-generated documentation in the `doc` directory of
the source distribution, and examples in the `tests` directory.
LibYAML is written by Kirill Simonov <xi@resolvent.net> and released
under the MIT license; see the file LICENSE for more details.

1396
extern/yaml/src/api.c vendored Normal file

File diff suppressed because it is too large Load Diff

4
extern/yaml/src/config.h vendored Normal file
View File

@@ -0,0 +1,4 @@
#define YAML_VERSION_MAJOR 0
#define YAML_VERSION_MINOR 1
#define YAML_VERSION_PATCH 6
#define YAML_VERSION_STRING "0.1.6"

394
extern/yaml/src/dumper.c vendored Normal file
View File

@@ -0,0 +1,394 @@
#include "yaml_private.h"
/*
* API functions.
*/
YAML_DECLARE(int)
yaml_emitter_open(yaml_emitter_t *emitter);
YAML_DECLARE(int)
yaml_emitter_close(yaml_emitter_t *emitter);
YAML_DECLARE(int)
yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document);
/*
* Clean up functions.
*/
static void
yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter);
/*
* Anchor functions.
*/
static void
yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index);
static yaml_char_t *
yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id);
/*
* Serialize functions.
*/
static int
yaml_emitter_dump_node(yaml_emitter_t *emitter, int index);
static int
yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor);
static int
yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node,
yaml_char_t *anchor);
static int
yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node,
yaml_char_t *anchor);
static int
yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node,
yaml_char_t *anchor);
/*
* Issue a STREAM-START event.
*/
YAML_DECLARE(int)
yaml_emitter_open(yaml_emitter_t *emitter)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
assert(emitter); /* Non-NULL emitter object is required. */
assert(!emitter->opened); /* Emitter should not be opened yet. */
STREAM_START_EVENT_INIT(event, YAML_ANY_ENCODING, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) {
return 0;
}
emitter->opened = 1;
return 1;
}
/*
* Issue a STREAM-END event.
*/
YAML_DECLARE(int)
yaml_emitter_close(yaml_emitter_t *emitter)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
assert(emitter); /* Non-NULL emitter object is required. */
assert(emitter->opened); /* Emitter should be opened. */
if (emitter->closed) return 1;
STREAM_END_EVENT_INIT(event, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) {
return 0;
}
emitter->closed = 1;
return 1;
}
/*
* Dump a YAML document.
*/
YAML_DECLARE(int)
yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
assert(emitter); /* Non-NULL emitter object is required. */
assert(document); /* Non-NULL emitter object is expected. */
emitter->document = document;
if (!emitter->opened) {
if (!yaml_emitter_open(emitter)) goto error;
}
if (STACK_EMPTY(emitter, document->nodes)) {
if (!yaml_emitter_close(emitter)) goto error;
yaml_emitter_delete_document_and_anchors(emitter);
return 1;
}
assert(emitter->opened); /* Emitter should be opened. */
emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
* (document->nodes.top - document->nodes.start));
if (!emitter->anchors) goto error;
memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
* (document->nodes.top - document->nodes.start));
DOCUMENT_START_EVENT_INIT(event, document->version_directive,
document->tag_directives.start, document->tag_directives.end,
document->start_implicit, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) goto error;
yaml_emitter_anchor_node(emitter, 1);
if (!yaml_emitter_dump_node(emitter, 1)) goto error;
DOCUMENT_END_EVENT_INIT(event, document->end_implicit, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) goto error;
yaml_emitter_delete_document_and_anchors(emitter);
return 1;
error:
yaml_emitter_delete_document_and_anchors(emitter);
return 0;
}
/*
* Clean up the emitter object after a document is dumped.
*/
static void
yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter)
{
int index;
if (!emitter->anchors) {
yaml_document_delete(emitter->document);
emitter->document = NULL;
return;
}
for (index = 0; emitter->document->nodes.start + index
< emitter->document->nodes.top; index ++) {
yaml_node_t node = emitter->document->nodes.start[index];
if (!emitter->anchors[index].serialized) {
yaml_free(node.tag);
if (node.type == YAML_SCALAR_NODE) {
yaml_free(node.data.scalar.value);
}
}
if (node.type == YAML_SEQUENCE_NODE) {
STACK_DEL(emitter, node.data.sequence.items);
}
if (node.type == YAML_MAPPING_NODE) {
STACK_DEL(emitter, node.data.mapping.pairs);
}
}
STACK_DEL(emitter, emitter->document->nodes);
yaml_free(emitter->anchors);
emitter->anchors = NULL;
emitter->last_anchor_id = 0;
emitter->document = NULL;
}
/*
* Check the references of a node and assign the anchor id if needed.
*/
static void
yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index)
{
yaml_node_t *node = emitter->document->nodes.start + index - 1;
yaml_node_item_t *item;
yaml_node_pair_t *pair;
emitter->anchors[index-1].references ++;
if (emitter->anchors[index-1].references == 1) {
switch (node->type) {
case YAML_SEQUENCE_NODE:
for (item = node->data.sequence.items.start;
item < node->data.sequence.items.top; item ++) {
yaml_emitter_anchor_node(emitter, *item);
}
break;
case YAML_MAPPING_NODE:
for (pair = node->data.mapping.pairs.start;
pair < node->data.mapping.pairs.top; pair ++) {
yaml_emitter_anchor_node(emitter, pair->key);
yaml_emitter_anchor_node(emitter, pair->value);
}
break;
default:
break;
}
}
else if (emitter->anchors[index-1].references == 2) {
emitter->anchors[index-1].anchor = (++ emitter->last_anchor_id);
}
}
/*
* Generate a textual representation for an anchor.
*/
#define ANCHOR_TEMPLATE "id%03d"
#define ANCHOR_TEMPLATE_LENGTH 16
static yaml_char_t *
yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id)
{
yaml_char_t *anchor = yaml_malloc(ANCHOR_TEMPLATE_LENGTH);
if (!anchor) return NULL;
sprintf((char *)anchor, ANCHOR_TEMPLATE, anchor_id);
return anchor;
}
/*
* Serialize a node.
*/
static int
yaml_emitter_dump_node(yaml_emitter_t *emitter, int index)
{
yaml_node_t *node = emitter->document->nodes.start + index - 1;
int anchor_id = emitter->anchors[index-1].anchor;
yaml_char_t *anchor = NULL;
if (anchor_id) {
anchor = yaml_emitter_generate_anchor(emitter, anchor_id);
if (!anchor) return 0;
}
if (emitter->anchors[index-1].serialized) {
return yaml_emitter_dump_alias(emitter, anchor);
}
emitter->anchors[index-1].serialized = 1;
switch (node->type) {
case YAML_SCALAR_NODE:
return yaml_emitter_dump_scalar(emitter, node, anchor);
case YAML_SEQUENCE_NODE:
return yaml_emitter_dump_sequence(emitter, node, anchor);
case YAML_MAPPING_NODE:
return yaml_emitter_dump_mapping(emitter, node, anchor);
default:
assert(0); /* Could not happen. */
break;
}
return 0; /* Could not happen. */
}
/*
* Serialize an alias.
*/
static int
yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
ALIAS_EVENT_INIT(event, anchor, mark, mark);
return yaml_emitter_emit(emitter, &event);
}
/*
* Serialize a scalar.
*/
static int
yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node,
yaml_char_t *anchor)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
int plain_implicit = (strcmp((char *)node->tag,
YAML_DEFAULT_SCALAR_TAG) == 0);
int quoted_implicit = (strcmp((char *)node->tag,
YAML_DEFAULT_SCALAR_TAG) == 0);
SCALAR_EVENT_INIT(event, anchor, node->tag, node->data.scalar.value,
node->data.scalar.length, plain_implicit, quoted_implicit,
node->data.scalar.style, mark, mark);
return yaml_emitter_emit(emitter, &event);
}
/*
* Serialize a sequence.
*/
static int
yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node,
yaml_char_t *anchor)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_SEQUENCE_TAG) == 0);
yaml_node_item_t *item;
SEQUENCE_START_EVENT_INIT(event, anchor, node->tag, implicit,
node->data.sequence.style, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) return 0;
for (item = node->data.sequence.items.start;
item < node->data.sequence.items.top; item ++) {
if (!yaml_emitter_dump_node(emitter, *item)) return 0;
}
SEQUENCE_END_EVENT_INIT(event, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) return 0;
return 1;
}
/*
* Serialize a mapping.
*/
static int
yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node,
yaml_char_t *anchor)
{
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };
int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_MAPPING_TAG) == 0);
yaml_node_pair_t *pair;
MAPPING_START_EVENT_INIT(event, anchor, node->tag, implicit,
node->data.mapping.style, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) return 0;
for (pair = node->data.mapping.pairs.start;
pair < node->data.mapping.pairs.top; pair ++) {
if (!yaml_emitter_dump_node(emitter, pair->key)) return 0;
if (!yaml_emitter_dump_node(emitter, pair->value)) return 0;
}
MAPPING_END_EVENT_INIT(event, mark, mark);
if (!yaml_emitter_emit(emitter, &event)) return 0;
return 1;
}

2329
extern/yaml/src/emitter.c vendored Normal file

File diff suppressed because it is too large Load Diff

444
extern/yaml/src/loader.c vendored Normal file
View File

@@ -0,0 +1,444 @@
#include "yaml_private.h"
/*
* API functions.
*/
YAML_DECLARE(int)
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
/*
* Error handling.
*/
static int
yaml_parser_set_composer_error(yaml_parser_t *parser,
const char *problem, yaml_mark_t problem_mark);
static int
yaml_parser_set_composer_error_context(yaml_parser_t *parser,
const char *context, yaml_mark_t context_mark,
const char *problem, yaml_mark_t problem_mark);
/*
* Alias handling.
*/
static int
yaml_parser_register_anchor(yaml_parser_t *parser,
int index, yaml_char_t *anchor);
/*
* Clean up functions.
*/
static void
yaml_parser_delete_aliases(yaml_parser_t *parser);
/*
* Composer functions.
*/
static int
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event);
/*
* Load the next document of the stream.
*/
YAML_DECLARE(int)
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
{
yaml_event_t event;
assert(parser); /* Non-NULL parser object is expected. */
assert(document); /* Non-NULL document object is expected. */
memset(document, 0, sizeof(yaml_document_t));
if (!STACK_INIT(parser, document->nodes, INITIAL_STACK_SIZE))
goto error;
if (!parser->stream_start_produced) {
if (!yaml_parser_parse(parser, &event)) goto error;
assert(event.type == YAML_STREAM_START_EVENT);
/* STREAM-START is expected. */
}
if (parser->stream_end_produced) {
return 1;
}
if (!yaml_parser_parse(parser, &event)) goto error;
if (event.type == YAML_STREAM_END_EVENT) {
return 1;
}
if (!STACK_INIT(parser, parser->aliases, INITIAL_STACK_SIZE))
goto error;
parser->document = document;
if (!yaml_parser_load_document(parser, &event)) goto error;
yaml_parser_delete_aliases(parser);
parser->document = NULL;
return 1;
error:
yaml_parser_delete_aliases(parser);
yaml_document_delete(document);
parser->document = NULL;
return 0;
}
/*
* Set composer error.
*/
static int
yaml_parser_set_composer_error(yaml_parser_t *parser,
const char *problem, yaml_mark_t problem_mark)
{
parser->error = YAML_COMPOSER_ERROR;
parser->problem = problem;
parser->problem_mark = problem_mark;
return 0;
}
/*
* Set composer error with context.
*/
static int
yaml_parser_set_composer_error_context(yaml_parser_t *parser,
const char *context, yaml_mark_t context_mark,
const char *problem, yaml_mark_t problem_mark)
{
parser->error = YAML_COMPOSER_ERROR;
parser->context = context;
parser->context_mark = context_mark;
parser->problem = problem;
parser->problem_mark = problem_mark;
return 0;
}
/*
* Delete the stack of aliases.
*/
static void
yaml_parser_delete_aliases(yaml_parser_t *parser)
{
while (!STACK_EMPTY(parser, parser->aliases)) {
yaml_free(POP(parser, parser->aliases).anchor);
}
STACK_DEL(parser, parser->aliases);
}
/*
* Compose a document object.
*/
static int
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_event_t event;
assert(first_event->type == YAML_DOCUMENT_START_EVENT);
/* DOCUMENT-START is expected. */
parser->document->version_directive
= first_event->data.document_start.version_directive;
parser->document->tag_directives.start
= first_event->data.document_start.tag_directives.start;
parser->document->tag_directives.end
= first_event->data.document_start.tag_directives.end;
parser->document->start_implicit
= first_event->data.document_start.implicit;
parser->document->start_mark = first_event->start_mark;
if (!yaml_parser_parse(parser, &event)) return 0;
if (!yaml_parser_load_node(parser, &event)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
assert(event.type == YAML_DOCUMENT_END_EVENT);
/* DOCUMENT-END is expected. */
parser->document->end_implicit = event.data.document_end.implicit;
parser->document->end_mark = event.end_mark;
return 1;
}
/*
* Compose a node.
*/
static int
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event)
{
switch (first_event->type) {
case YAML_ALIAS_EVENT:
return yaml_parser_load_alias(parser, first_event);
case YAML_SCALAR_EVENT:
return yaml_parser_load_scalar(parser, first_event);
case YAML_SEQUENCE_START_EVENT:
return yaml_parser_load_sequence(parser, first_event);
case YAML_MAPPING_START_EVENT:
return yaml_parser_load_mapping(parser, first_event);
default:
assert(0); /* Could not happen. */
return 0;
}
return 0;
}
/*
* Add an anchor.
*/
static int
yaml_parser_register_anchor(yaml_parser_t *parser,
int index, yaml_char_t *anchor)
{
yaml_alias_data_t data;
yaml_alias_data_t *alias_data;
if (!anchor) return 1;
data.anchor = anchor;
data.index = index;
data.mark = parser->document->nodes.start[index-1].start_mark;
for (alias_data = parser->aliases.start;
alias_data != parser->aliases.top; alias_data ++) {
if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
yaml_free(anchor);
return yaml_parser_set_composer_error_context(parser,
"found duplicate anchor; first occurence",
alias_data->mark, "second occurence", data.mark);
}
}
if (!PUSH(parser, parser->aliases, data)) {
yaml_free(anchor);
return 0;
}
return 1;
}
/*
* Compose a node corresponding to an alias.
*/
static int
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_char_t *anchor = first_event->data.alias.anchor;
yaml_alias_data_t *alias_data;
for (alias_data = parser->aliases.start;
alias_data != parser->aliases.top; alias_data ++) {
if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
yaml_free(anchor);
return alias_data->index;
}
}
yaml_free(anchor);
return yaml_parser_set_composer_error(parser, "found undefined alias",
first_event->start_mark);
}
/*
* Compose a scalar node.
*/
static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_node_t node;
int index;
yaml_char_t *tag = first_event->data.scalar.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
if (!tag || strcmp((char *)tag, "!") == 0) {
yaml_free(tag);
tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SCALAR_TAG);
if (!tag) goto error;
}
SCALAR_NODE_INIT(node, tag, first_event->data.scalar.value,
first_event->data.scalar.length, first_event->data.scalar.style,
first_event->start_mark, first_event->end_mark);
if (!PUSH(parser, parser->document->nodes, node)) goto error;
index = parser->document->nodes.top - parser->document->nodes.start;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.scalar.anchor)) return 0;
return index;
error:
yaml_free(tag);
yaml_free(first_event->data.scalar.anchor);
yaml_free(first_event->data.scalar.value);
return 0;
}
/*
* Compose a sequence node.
*/
static int
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_event_t event;
yaml_node_t node;
struct {
yaml_node_item_t *start;
yaml_node_item_t *end;
yaml_node_item_t *top;
} items = { NULL, NULL, NULL };
int index, item_index;
yaml_char_t *tag = first_event->data.sequence_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
if (!tag || strcmp((char *)tag, "!") == 0) {
yaml_free(tag);
tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG);
if (!tag) goto error;
}
if (!STACK_INIT(parser, items, INITIAL_STACK_SIZE)) goto error;
SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
first_event->data.sequence_start.style,
first_event->start_mark, first_event->end_mark);
if (!PUSH(parser, parser->document->nodes, node)) goto error;
index = parser->document->nodes.top - parser->document->nodes.start;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.sequence_start.anchor)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
while (event.type != YAML_SEQUENCE_END_EVENT) {
if (!STACK_LIMIT(parser,
parser->document->nodes.start[index-1].data.sequence.items,
INT_MAX-1)) return 0;
item_index = yaml_parser_load_node(parser, &event);
if (!item_index) return 0;
if (!PUSH(parser,
parser->document->nodes.start[index-1].data.sequence.items,
item_index)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
}
parser->document->nodes.start[index-1].end_mark = event.end_mark;
return index;
error:
yaml_free(tag);
yaml_free(first_event->data.sequence_start.anchor);
return 0;
}
/*
* Compose a mapping node.
*/
static int
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_event_t event;
yaml_node_t node;
struct {
yaml_node_pair_t *start;
yaml_node_pair_t *end;
yaml_node_pair_t *top;
} pairs = { NULL, NULL, NULL };
int index;
yaml_node_pair_t pair;
yaml_char_t *tag = first_event->data.mapping_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
if (!tag || strcmp((char *)tag, "!") == 0) {
yaml_free(tag);
tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG);
if (!tag) goto error;
}
if (!STACK_INIT(parser, pairs, INITIAL_STACK_SIZE)) goto error;
MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
first_event->data.mapping_start.style,
first_event->start_mark, first_event->end_mark);
if (!PUSH(parser, parser->document->nodes, node)) goto error;
index = parser->document->nodes.top - parser->document->nodes.start;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.mapping_start.anchor)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
while (event.type != YAML_MAPPING_END_EVENT) {
if (!STACK_LIMIT(parser,
parser->document->nodes.start[index-1].data.mapping.pairs,
INT_MAX-1)) return 0;
pair.key = yaml_parser_load_node(parser, &event);
if (!pair.key) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
pair.value = yaml_parser_load_node(parser, &event);
if (!pair.value) return 0;
if (!PUSH(parser,
parser->document->nodes.start[index-1].data.mapping.pairs,
pair)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
}
parser->document->nodes.start[index-1].end_mark = event.end_mark;
return index;
error:
yaml_free(tag);
yaml_free(first_event->data.mapping_start.anchor);
return 0;
}

1374
extern/yaml/src/parser.c vendored Normal file

File diff suppressed because it is too large Load Diff

469
extern/yaml/src/reader.c vendored Normal file
View File

@@ -0,0 +1,469 @@
#include "yaml_private.h"
/*
* Declarations.
*/
static int
yaml_parser_set_reader_error(yaml_parser_t *parser, const char *problem,
size_t offset, int value);
static int
yaml_parser_update_raw_buffer(yaml_parser_t *parser);
static int
yaml_parser_determine_encoding(yaml_parser_t *parser);
YAML_DECLARE(int)
yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
/*
* Set the reader error and return 0.
*/
static int
yaml_parser_set_reader_error(yaml_parser_t *parser, const char *problem,
size_t offset, int value)
{
parser->error = YAML_READER_ERROR;
parser->problem = problem;
parser->problem_offset = offset;
parser->problem_value = value;
return 0;
}
/*
* Byte order marks.
*/
#define BOM_UTF8 "\xef\xbb\xbf"
#define BOM_UTF16LE "\xff\xfe"
#define BOM_UTF16BE "\xfe\xff"
/*
* Determine the input stream encoding by checking the BOM symbol. If no BOM is
* found, the UTF-8 encoding is assumed. Return 1 on success, 0 on failure.
*/
static int
yaml_parser_determine_encoding(yaml_parser_t *parser)
{
/* Ensure that we had enough bytes in the raw buffer. */
while (!parser->eof
&& parser->raw_buffer.last - parser->raw_buffer.pointer < 3) {
if (!yaml_parser_update_raw_buffer(parser)) {
return 0;
}
}
/* Determine the encoding. */
if (parser->raw_buffer.last - parser->raw_buffer.pointer >= 2
&& !memcmp(parser->raw_buffer.pointer, BOM_UTF16LE, 2)) {
parser->encoding = YAML_UTF16LE_ENCODING;
parser->raw_buffer.pointer += 2;
parser->offset += 2;
}
else if (parser->raw_buffer.last - parser->raw_buffer.pointer >= 2
&& !memcmp(parser->raw_buffer.pointer, BOM_UTF16BE, 2)) {
parser->encoding = YAML_UTF16BE_ENCODING;
parser->raw_buffer.pointer += 2;
parser->offset += 2;
}
else if (parser->raw_buffer.last - parser->raw_buffer.pointer >= 3
&& !memcmp(parser->raw_buffer.pointer, BOM_UTF8, 3)) {
parser->encoding = YAML_UTF8_ENCODING;
parser->raw_buffer.pointer += 3;
parser->offset += 3;
}
else {
parser->encoding = YAML_UTF8_ENCODING;
}
return 1;
}
/*
* Update the raw buffer.
*/
static int
yaml_parser_update_raw_buffer(yaml_parser_t *parser)
{
size_t size_read = 0;
/* Return if the raw buffer is full. */
if (parser->raw_buffer.start == parser->raw_buffer.pointer
&& parser->raw_buffer.last == parser->raw_buffer.end)
return 1;
/* Return on EOF. */
if (parser->eof) return 1;
/* Move the remaining bytes in the raw buffer to the beginning. */
if (parser->raw_buffer.start < parser->raw_buffer.pointer
&& parser->raw_buffer.pointer < parser->raw_buffer.last) {
memmove(parser->raw_buffer.start, parser->raw_buffer.pointer,
parser->raw_buffer.last - parser->raw_buffer.pointer);
}
parser->raw_buffer.last -=
parser->raw_buffer.pointer - parser->raw_buffer.start;
parser->raw_buffer.pointer = parser->raw_buffer.start;
/* Call the read handler to fill the buffer. */
if (!parser->read_handler(parser->read_handler_data, parser->raw_buffer.last,
parser->raw_buffer.end - parser->raw_buffer.last, &size_read)) {
return yaml_parser_set_reader_error(parser, "input error",
parser->offset, -1);
}
parser->raw_buffer.last += size_read;
if (!size_read) {
parser->eof = 1;
}
return 1;
}
/*
* Ensure that the buffer contains at least `length` characters.
* Return 1 on success, 0 on failure.
*
* The length is supposed to be significantly less that the buffer size.
*/
YAML_DECLARE(int)
yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)
{
int first = 1;
assert(parser->read_handler); /* Read handler must be set. */
/* If the EOF flag is set and the raw buffer is empty, do nothing. */
if (parser->eof && parser->raw_buffer.pointer == parser->raw_buffer.last)
return 1;
/* Return if the buffer contains enough characters. */
if (parser->unread >= length)
return 1;
/* Determine the input encoding if it is not known yet. */
if (!parser->encoding) {
if (!yaml_parser_determine_encoding(parser))
return 0;
}
/* Move the unread characters to the beginning of the buffer. */
if (parser->buffer.start < parser->buffer.pointer
&& parser->buffer.pointer < parser->buffer.last) {
size_t size = parser->buffer.last - parser->buffer.pointer;
memmove(parser->buffer.start, parser->buffer.pointer, size);
parser->buffer.pointer = parser->buffer.start;
parser->buffer.last = parser->buffer.start + size;
}
else if (parser->buffer.pointer == parser->buffer.last) {
parser->buffer.pointer = parser->buffer.start;
parser->buffer.last = parser->buffer.start;
}
/* Fill the buffer until it has enough characters. */
while (parser->unread < length)
{
/* Fill the raw buffer if necessary. */
if (!first || parser->raw_buffer.pointer == parser->raw_buffer.last) {
if (!yaml_parser_update_raw_buffer(parser)) return 0;
}
first = 0;
/* Decode the raw buffer. */
while (parser->raw_buffer.pointer != parser->raw_buffer.last)
{
unsigned int value = 0, value2 = 0;
int incomplete = 0;
unsigned char octet;
unsigned int width = 0;
int low, high;
size_t k;
size_t raw_unread = parser->raw_buffer.last - parser->raw_buffer.pointer;
/* Decode the next character. */
switch (parser->encoding)
{
case YAML_UTF8_ENCODING:
/*
* Decode a UTF-8 character. Check RFC 3629
* (http://www.ietf.org/rfc/rfc3629.txt) for more details.
*
* The following table (taken from the RFC) is used for
* decoding.
*
* Char. number range | UTF-8 octet sequence
* (hexadecimal) | (binary)
* --------------------+------------------------------------
* 0000 0000-0000 007F | 0xxxxxxx
* 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
* 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
* 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
*
* Additionally, the characters in the range 0xD800-0xDFFF
* are prohibited as they are reserved for use with UTF-16
* surrogate pairs.
*/
/* Determine the length of the UTF-8 sequence. */
octet = parser->raw_buffer.pointer[0];
width = (octet & 0x80) == 0x00 ? 1 :
(octet & 0xE0) == 0xC0 ? 2 :
(octet & 0xF0) == 0xE0 ? 3 :
(octet & 0xF8) == 0xF0 ? 4 : 0;
/* Check if the leading octet is valid. */
if (!width)
return yaml_parser_set_reader_error(parser,
"invalid leading UTF-8 octet",
parser->offset, octet);
/* Check if the raw buffer contains an incomplete character. */
if (width > raw_unread) {
if (parser->eof) {
return yaml_parser_set_reader_error(parser,
"incomplete UTF-8 octet sequence",
parser->offset, -1);
}
incomplete = 1;
break;
}
/* Decode the leading octet. */
value = (octet & 0x80) == 0x00 ? octet & 0x7F :
(octet & 0xE0) == 0xC0 ? octet & 0x1F :
(octet & 0xF0) == 0xE0 ? octet & 0x0F :
(octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
/* Check and decode the trailing octets. */
for (k = 1; k < width; k ++)
{
octet = parser->raw_buffer.pointer[k];
/* Check if the octet is valid. */
if ((octet & 0xC0) != 0x80)
return yaml_parser_set_reader_error(parser,
"invalid trailing UTF-8 octet",
parser->offset+k, octet);
/* Decode the octet. */
value = (value << 6) + (octet & 0x3F);
}
/* Check the length of the sequence against the value. */
if (!((width == 1) ||
(width == 2 && value >= 0x80) ||
(width == 3 && value >= 0x800) ||
(width == 4 && value >= 0x10000)))
return yaml_parser_set_reader_error(parser,
"invalid length of a UTF-8 sequence",
parser->offset, -1);
/* Check the range of the value. */
if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF)
return yaml_parser_set_reader_error(parser,
"invalid Unicode character",
parser->offset, value);
break;
case YAML_UTF16LE_ENCODING:
case YAML_UTF16BE_ENCODING:
low = (parser->encoding == YAML_UTF16LE_ENCODING ? 0 : 1);
high = (parser->encoding == YAML_UTF16LE_ENCODING ? 1 : 0);
/*
* The UTF-16 encoding is not as simple as one might
* naively think. Check RFC 2781
* (http://www.ietf.org/rfc/rfc2781.txt).
*
* Normally, two subsequent bytes describe a Unicode
* character. However a special technique (called a
* surrogate pair) is used for specifying character
* values larger than 0xFFFF.
*
* A surrogate pair consists of two pseudo-characters:
* high surrogate area (0xD800-0xDBFF)
* low surrogate area (0xDC00-0xDFFF)
*
* The following formulas are used for decoding
* and encoding characters using surrogate pairs:
*
* U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF)
* U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF)
* W1 = 110110yyyyyyyyyy
* W2 = 110111xxxxxxxxxx
*
* where U is the character value, W1 is the high surrogate
* area, W2 is the low surrogate area.
*/
/* Check for incomplete UTF-16 character. */
if (raw_unread < 2) {
if (parser->eof) {
return yaml_parser_set_reader_error(parser,
"incomplete UTF-16 character",
parser->offset, -1);
}
incomplete = 1;
break;
}
/* Get the character. */
value = parser->raw_buffer.pointer[low]
+ (parser->raw_buffer.pointer[high] << 8);
/* Check for unexpected low surrogate area. */
if ((value & 0xFC00) == 0xDC00)
return yaml_parser_set_reader_error(parser,
"unexpected low surrogate area",
parser->offset, value);
/* Check for a high surrogate area. */
if ((value & 0xFC00) == 0xD800) {
width = 4;
/* Check for incomplete surrogate pair. */
if (raw_unread < 4) {
if (parser->eof) {
return yaml_parser_set_reader_error(parser,
"incomplete UTF-16 surrogate pair",
parser->offset, -1);
}
incomplete = 1;
break;
}
/* Get the next character. */
value2 = parser->raw_buffer.pointer[low+2]
+ (parser->raw_buffer.pointer[high+2] << 8);
/* Check for a low surrogate area. */
if ((value2 & 0xFC00) != 0xDC00)
return yaml_parser_set_reader_error(parser,
"expected low surrogate area",
parser->offset+2, value2);
/* Generate the value of the surrogate pair. */
value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF);
}
else {
width = 2;
}
break;
default:
assert(1); /* Impossible. */
}
/* Check if the raw buffer contains enough bytes to form a character. */
if (incomplete) break;
/*
* Check if the character is in the allowed range:
* #x9 | #xA | #xD | [#x20-#x7E] (8 bit)
* | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] (16 bit)
* | [#x10000-#x10FFFF] (32 bit)
*/
if (! (value == 0x09 || value == 0x0A || value == 0x0D
|| (value >= 0x20 && value <= 0x7E)
|| (value == 0x85) || (value >= 0xA0 && value <= 0xD7FF)
|| (value >= 0xE000 && value <= 0xFFFD)
|| (value >= 0x10000 && value <= 0x10FFFF)))
return yaml_parser_set_reader_error(parser,
"control characters are not allowed",
parser->offset, value);
/* Move the raw pointers. */
parser->raw_buffer.pointer += width;
parser->offset += width;
/* Finally put the character into the buffer. */
/* 0000 0000-0000 007F -> 0xxxxxxx */
if (value <= 0x7F) {
*(parser->buffer.last++) = value;
}
/* 0000 0080-0000 07FF -> 110xxxxx 10xxxxxx */
else if (value <= 0x7FF) {
*(parser->buffer.last++) = 0xC0 + (value >> 6);
*(parser->buffer.last++) = 0x80 + (value & 0x3F);
}
/* 0000 0800-0000 FFFF -> 1110xxxx 10xxxxxx 10xxxxxx */
else if (value <= 0xFFFF) {
*(parser->buffer.last++) = 0xE0 + (value >> 12);
*(parser->buffer.last++) = 0x80 + ((value >> 6) & 0x3F);
*(parser->buffer.last++) = 0x80 + (value & 0x3F);
}
/* 0001 0000-0010 FFFF -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
else {
*(parser->buffer.last++) = 0xF0 + (value >> 18);
*(parser->buffer.last++) = 0x80 + ((value >> 12) & 0x3F);
*(parser->buffer.last++) = 0x80 + ((value >> 6) & 0x3F);
*(parser->buffer.last++) = 0x80 + (value & 0x3F);
}
parser->unread ++;
}
/* On EOF, put NUL into the buffer and return. */
if (parser->eof) {
*(parser->buffer.last++) = '\0';
parser->unread ++;
return 1;
}
}
if (parser->offset >= PTRDIFF_MAX)
return yaml_parser_set_reader_error(parser, "input is too long",
PTRDIFF_MAX, -1);
return 1;
}

3585
extern/yaml/src/scanner.c vendored Normal file

File diff suppressed because it is too large Load Diff

141
extern/yaml/src/writer.c vendored Normal file
View File

@@ -0,0 +1,141 @@
#include "yaml_private.h"
/*
* Declarations.
*/
static int
yaml_emitter_set_writer_error(yaml_emitter_t *emitter, const char *problem);
YAML_DECLARE(int)
yaml_emitter_flush(yaml_emitter_t *emitter);
/*
* Set the writer error and return 0.
*/
static int
yaml_emitter_set_writer_error(yaml_emitter_t *emitter, const char *problem)
{
emitter->error = YAML_WRITER_ERROR;
emitter->problem = problem;
return 0;
}
/*
* Flush the output buffer.
*/
YAML_DECLARE(int)
yaml_emitter_flush(yaml_emitter_t *emitter)
{
int low, high;
assert(emitter); /* Non-NULL emitter object is expected. */
assert(emitter->write_handler); /* Write handler must be set. */
assert(emitter->encoding); /* Output encoding must be set. */
emitter->buffer.last = emitter->buffer.pointer;
emitter->buffer.pointer = emitter->buffer.start;
/* Check if the buffer is empty. */
if (emitter->buffer.start == emitter->buffer.last) {
return 1;
}
/* If the output encoding is UTF-8, we don't need to recode the buffer. */
if (emitter->encoding == YAML_UTF8_ENCODING)
{
if (emitter->write_handler(emitter->write_handler_data,
emitter->buffer.start,
emitter->buffer.last - emitter->buffer.start)) {
emitter->buffer.last = emitter->buffer.start;
emitter->buffer.pointer = emitter->buffer.start;
return 1;
}
else {
return yaml_emitter_set_writer_error(emitter, "write error");
}
}
/* Recode the buffer into the raw buffer. */
low = (emitter->encoding == YAML_UTF16LE_ENCODING ? 0 : 1);
high = (emitter->encoding == YAML_UTF16LE_ENCODING ? 1 : 0);
while (emitter->buffer.pointer != emitter->buffer.last)
{
unsigned char octet;
unsigned int width;
unsigned int value;
size_t k;
/*
* See the "reader.c" code for more details on UTF-8 encoding. Note
* that we assume that the buffer contains a valid UTF-8 sequence.
*/
/* Read the next UTF-8 character. */
octet = emitter->buffer.pointer[0];
width = (octet & 0x80) == 0x00 ? 1 :
(octet & 0xE0) == 0xC0 ? 2 :
(octet & 0xF0) == 0xE0 ? 3 :
(octet & 0xF8) == 0xF0 ? 4 : 0;
value = (octet & 0x80) == 0x00 ? octet & 0x7F :
(octet & 0xE0) == 0xC0 ? octet & 0x1F :
(octet & 0xF0) == 0xE0 ? octet & 0x0F :
(octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
for (k = 1; k < width; k ++) {
octet = emitter->buffer.pointer[k];
value = (value << 6) + (octet & 0x3F);
}
emitter->buffer.pointer += width;
/* Write the character. */
if (value < 0x10000)
{
emitter->raw_buffer.last[high] = value >> 8;
emitter->raw_buffer.last[low] = value & 0xFF;
emitter->raw_buffer.last += 2;
}
else
{
/* Write the character using a surrogate pair (check "reader.c"). */
value -= 0x10000;
emitter->raw_buffer.last[high] = 0xD8 + (value >> 18);
emitter->raw_buffer.last[low] = (value >> 10) & 0xFF;
emitter->raw_buffer.last[high+2] = 0xDC + ((value >> 8) & 0xFF);
emitter->raw_buffer.last[low+2] = value & 0xFF;
emitter->raw_buffer.last += 4;
}
}
/* Write the raw buffer. */
if (emitter->write_handler(emitter->write_handler_data,
emitter->raw_buffer.start,
emitter->raw_buffer.last - emitter->raw_buffer.start)) {
emitter->buffer.last = emitter->buffer.start;
emitter->buffer.pointer = emitter->buffer.start;
emitter->raw_buffer.last = emitter->raw_buffer.start;
emitter->raw_buffer.pointer = emitter->raw_buffer.start;
return 1;
}
else {
return yaml_emitter_set_writer_error(emitter, "write error");
}
}

658
extern/yaml/src/yaml_private.h vendored Normal file
View File

@@ -0,0 +1,658 @@
#include "config.h"
#include <yaml.h>
#include <assert.h>
#include <limits.h>
#include <stddef.h>
#ifndef _MSC_VER
#include <stdint.h>
#else
#ifdef _WIN64
#define PTRDIFF_MAX _I64_MAX
#else
#define PTRDIFF_MAX INT_MAX
#endif
#endif
/*
* Memory management.
*/
YAML_DECLARE(void *)
yaml_malloc(size_t size);
YAML_DECLARE(void *)
yaml_realloc(void *ptr, size_t size);
YAML_DECLARE(void)
yaml_free(void *ptr);
YAML_DECLARE(yaml_char_t *)
yaml_strdup(const yaml_char_t *);
/*
* Reader: Ensure that the buffer contains at least `length` characters.
*/
YAML_DECLARE(int)
yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
/*
* Scanner: Ensure that the token stack contains at least one token ready.
*/
YAML_DECLARE(int)
yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
/*
* The size of the input raw buffer.
*/
#define INPUT_RAW_BUFFER_SIZE 16384
/*
* The size of the input buffer.
*
* It should be possible to decode the whole raw buffer.
*/
#define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3)
/*
* The size of the output buffer.
*/
#define OUTPUT_BUFFER_SIZE 16384
/*
* The size of the output raw buffer.
*
* It should be possible to encode the whole output buffer.
*/
#define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2)
/*
* The size of other stacks and queues.
*/
#define INITIAL_STACK_SIZE 16
#define INITIAL_QUEUE_SIZE 16
#define INITIAL_STRING_SIZE 16
/*
* Buffer management.
*/
#define BUFFER_INIT(context,buffer,size) \
(((buffer).start = yaml_malloc(size)) ? \
((buffer).last = (buffer).pointer = (buffer).start, \
(buffer).end = (buffer).start+(size), \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define BUFFER_DEL(context,buffer) \
(yaml_free((buffer).start), \
(buffer).start = (buffer).pointer = (buffer).end = 0)
/*
* String management.
*/
typedef struct {
yaml_char_t *start;
yaml_char_t *end;
yaml_char_t *pointer;
} yaml_string_t;
YAML_DECLARE(int)
yaml_string_extend(yaml_char_t **start,
yaml_char_t **pointer, yaml_char_t **end);
YAML_DECLARE(int)
yaml_string_join(
yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
#define NULL_STRING { NULL, NULL, NULL }
#define STRING(string,length) { (string), (string)+(length), (string) }
#define STRING_ASSIGN(value,string,length) \
((value).start = (string), \
(value).end = (string)+(length), \
(value).pointer = (string))
#define STRING_INIT(context,string,size) \
(((string).start = yaml_malloc(size)) ? \
((string).pointer = (string).start, \
(string).end = (string).start+(size), \
memset((string).start, 0, (size)), \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define STRING_DEL(context,string) \
(yaml_free((string).start), \
(string).start = (string).pointer = (string).end = 0)
#define STRING_EXTEND(context,string) \
((((string).pointer+5 < (string).end) \
|| yaml_string_extend(&(string).start, \
&(string).pointer, &(string).end)) ? \
1 : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define CLEAR(context,string) \
((string).pointer = (string).start, \
memset((string).start, 0, (string).end-(string).start))
#define JOIN(context,string_a,string_b) \
((yaml_string_join(&(string_a).start, &(string_a).pointer, \
&(string_a).end, &(string_b).start, \
&(string_b).pointer, &(string_b).end)) ? \
((string_b).pointer = (string_b).start, \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
/*
* String check operations.
*/
/*
* Check the octet at the specified position.
*/
#define CHECK_AT(string,octet,offset) \
((string).pointer[offset] == (yaml_char_t)(octet))
/*
* Check the current octet in the buffer.
*/
#define CHECK(string,octet) CHECK_AT((string),(octet),0)
/*
* Check if the character at the specified position is an alphabetical
* character, a digit, '_', or '-'.
*/
#define IS_ALPHA_AT(string,offset) \
(((string).pointer[offset] >= (yaml_char_t) '0' && \
(string).pointer[offset] <= (yaml_char_t) '9') || \
((string).pointer[offset] >= (yaml_char_t) 'A' && \
(string).pointer[offset] <= (yaml_char_t) 'Z') || \
((string).pointer[offset] >= (yaml_char_t) 'a' && \
(string).pointer[offset] <= (yaml_char_t) 'z') || \
(string).pointer[offset] == '_' || \
(string).pointer[offset] == '-')
#define IS_ALPHA(string) IS_ALPHA_AT((string),0)
/*
* Check if the character at the specified position is a digit.
*/
#define IS_DIGIT_AT(string,offset) \
(((string).pointer[offset] >= (yaml_char_t) '0' && \
(string).pointer[offset] <= (yaml_char_t) '9'))
#define IS_DIGIT(string) IS_DIGIT_AT((string),0)
/*
* Get the value of a digit.
*/
#define AS_DIGIT_AT(string,offset) \
((string).pointer[offset] - (yaml_char_t) '0')
#define AS_DIGIT(string) AS_DIGIT_AT((string),0)
/*
* Check if the character at the specified position is a hex-digit.
*/
#define IS_HEX_AT(string,offset) \
(((string).pointer[offset] >= (yaml_char_t) '0' && \
(string).pointer[offset] <= (yaml_char_t) '9') || \
((string).pointer[offset] >= (yaml_char_t) 'A' && \
(string).pointer[offset] <= (yaml_char_t) 'F') || \
((string).pointer[offset] >= (yaml_char_t) 'a' && \
(string).pointer[offset] <= (yaml_char_t) 'f'))
#define IS_HEX(string) IS_HEX_AT((string),0)
/*
* Get the value of a hex-digit.
*/
#define AS_HEX_AT(string,offset) \
(((string).pointer[offset] >= (yaml_char_t) 'A' && \
(string).pointer[offset] <= (yaml_char_t) 'F') ? \
((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \
((string).pointer[offset] >= (yaml_char_t) 'a' && \
(string).pointer[offset] <= (yaml_char_t) 'f') ? \
((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \
((string).pointer[offset] - (yaml_char_t) '0'))
#define AS_HEX(string) AS_HEX_AT((string),0)
/*
* Check if the character is ASCII.
*/
#define IS_ASCII_AT(string,offset) \
((string).pointer[offset] <= (yaml_char_t) '\x7F')
#define IS_ASCII(string) IS_ASCII_AT((string),0)
/*
* Check if the character can be printed unescaped.
*/
#define IS_PRINTABLE_AT(string,offset) \
(((string).pointer[offset] == 0x0A) /* . == #x0A */ \
|| ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \
&& (string).pointer[offset] <= 0x7E) \
|| ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \
&& (string).pointer[offset+1] >= 0xA0) \
|| ((string).pointer[offset] > 0xC2 \
&& (string).pointer[offset] < 0xED) \
|| ((string).pointer[offset] == 0xED \
&& (string).pointer[offset+1] < 0xA0) \
|| ((string).pointer[offset] == 0xEE) \
|| ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \
&& !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \
&& (string).pointer[offset+2] == 0xBF) \
&& !((string).pointer[offset+1] == 0xBF \
&& ((string).pointer[offset+2] == 0xBE \
|| (string).pointer[offset+2] == 0xBF))))
#define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0)
/*
* Check if the character at the specified position is NUL.
*/
#define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset))
#define IS_Z(string) IS_Z_AT((string),0)
/*
* Check if the character at the specified position is BOM.
*/
#define IS_BOM_AT(string,offset) \
(CHECK_AT((string),'\xEF',(offset)) \
&& CHECK_AT((string),'\xBB',(offset)+1) \
&& CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */
#define IS_BOM(string) IS_BOM_AT(string,0)
/*
* Check if the character at the specified position is space.
*/
#define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset))
#define IS_SPACE(string) IS_SPACE_AT((string),0)
/*
* Check if the character at the specified position is tab.
*/
#define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset))
#define IS_TAB(string) IS_TAB_AT((string),0)
/*
* Check if the character at the specified position is blank (space or tab).
*/
#define IS_BLANK_AT(string,offset) \
(IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
#define IS_BLANK(string) IS_BLANK_AT((string),0)
/*
* Check if the character at the specified position is a line break.
*/
#define IS_BREAK_AT(string,offset) \
(CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \
|| CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \
|| (CHECK_AT((string),'\xC2',(offset)) \
&& CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \
|| (CHECK_AT((string),'\xE2',(offset)) \
&& CHECK_AT((string),'\x80',(offset)+1) \
&& CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \
|| (CHECK_AT((string),'\xE2',(offset)) \
&& CHECK_AT((string),'\x80',(offset)+1) \
&& CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */
#define IS_BREAK(string) IS_BREAK_AT((string),0)
#define IS_CRLF_AT(string,offset) \
(CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
#define IS_CRLF(string) IS_CRLF_AT((string),0)
/*
* Check if the character is a line break or NUL.
*/
#define IS_BREAKZ_AT(string,offset) \
(IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
#define IS_BREAKZ(string) IS_BREAKZ_AT((string),0)
/*
* Check if the character is a line break, space, or NUL.
*/
#define IS_SPACEZ_AT(string,offset) \
(IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
#define IS_SPACEZ(string) IS_SPACEZ_AT((string),0)
/*
* Check if the character is a line break, space, tab, or NUL.
*/
#define IS_BLANKZ_AT(string,offset) \
(IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
#define IS_BLANKZ(string) IS_BLANKZ_AT((string),0)
/*
* Determine the width of the character.
*/
#define WIDTH_AT(string,offset) \
(((string).pointer[offset] & 0x80) == 0x00 ? 1 : \
((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \
((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \
((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
#define WIDTH(string) WIDTH_AT((string),0)
/*
* Move the string pointer to the next character.
*/
#define MOVE(string) ((string).pointer += WIDTH((string)))
/*
* Copy a character and move the pointers of both strings.
*/
#define COPY(string_a,string_b) \
((*(string_b).pointer & 0x80) == 0x00 ? \
(*((string_a).pointer++) = *((string_b).pointer++)) : \
(*(string_b).pointer & 0xE0) == 0xC0 ? \
(*((string_a).pointer++) = *((string_b).pointer++), \
*((string_a).pointer++) = *((string_b).pointer++)) : \
(*(string_b).pointer & 0xF0) == 0xE0 ? \
(*((string_a).pointer++) = *((string_b).pointer++), \
*((string_a).pointer++) = *((string_b).pointer++), \
*((string_a).pointer++) = *((string_b).pointer++)) : \
(*(string_b).pointer & 0xF8) == 0xF0 ? \
(*((string_a).pointer++) = *((string_b).pointer++), \
*((string_a).pointer++) = *((string_b).pointer++), \
*((string_a).pointer++) = *((string_b).pointer++), \
*((string_a).pointer++) = *((string_b).pointer++)) : 0)
/*
* Stack and queue management.
*/
YAML_DECLARE(int)
yaml_stack_extend(void **start, void **top, void **end);
YAML_DECLARE(int)
yaml_queue_extend(void **start, void **head, void **tail, void **end);
#define STACK_INIT(context,stack,size) \
(((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \
((stack).top = (stack).start, \
(stack).end = (stack).start+(size), \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define STACK_DEL(context,stack) \
(yaml_free((stack).start), \
(stack).start = (stack).top = (stack).end = 0)
#define STACK_EMPTY(context,stack) \
((stack).start == (stack).top)
#define STACK_LIMIT(context,stack,size) \
((stack).top - (stack).start < (size) ? \
1 : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define PUSH(context,stack,value) \
(((stack).top != (stack).end \
|| yaml_stack_extend((void **)&(stack).start, \
(void **)&(stack).top, (void **)&(stack).end)) ? \
(*((stack).top++) = value, \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define POP(context,stack) \
(*(--(stack).top))
#define QUEUE_INIT(context,queue,size) \
(((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ? \
((queue).head = (queue).tail = (queue).start, \
(queue).end = (queue).start+(size), \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define QUEUE_DEL(context,queue) \
(yaml_free((queue).start), \
(queue).start = (queue).head = (queue).tail = (queue).end = 0)
#define QUEUE_EMPTY(context,queue) \
((queue).head == (queue).tail)
#define ENQUEUE(context,queue,value) \
(((queue).tail != (queue).end \
|| yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
(void **)&(queue).tail, (void **)&(queue).end)) ? \
(*((queue).tail++) = value, \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
#define DEQUEUE(context,queue) \
(*((queue).head++))
#define QUEUE_INSERT(context,queue,index,value) \
(((queue).tail != (queue).end \
|| yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
(void **)&(queue).tail, (void **)&(queue).end)) ? \
(memmove((queue).head+(index)+1,(queue).head+(index), \
((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \
*((queue).head+(index)) = value, \
(queue).tail++, \
1) : \
((context)->error = YAML_MEMORY_ERROR, \
0))
/*
* Token initializers.
*/
#define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark) \
(memset(&(token), 0, sizeof(yaml_token_t)), \
(token).type = (token_type), \
(token).start_mark = (token_start_mark), \
(token).end_mark = (token_end_mark))
#define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)), \
(token).data.stream_start.encoding = (token_encoding))
#define STREAM_END_TOKEN_INIT(token,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))
#define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)), \
(token).data.alias.value = (token_value))
#define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)), \
(token).data.anchor.value = (token_value))
#define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)), \
(token).data.tag.handle = (token_handle), \
(token).data.tag.suffix = (token_suffix))
#define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)), \
(token).data.scalar.value = (token_value), \
(token).data.scalar.length = (token_length), \
(token).data.scalar.style = (token_style))
#define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
(token).data.version_directive.major = (token_major), \
(token).data.version_directive.minor = (token_minor))
#define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark) \
(TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
(token).data.tag_directive.handle = (token_handle), \
(token).data.tag_directive.prefix = (token_prefix))
/*
* Event initializers.
*/
#define EVENT_INIT(event,event_type,event_start_mark,event_end_mark) \
(memset(&(event), 0, sizeof(yaml_event_t)), \
(event).type = (event_type), \
(event).start_mark = (event_start_mark), \
(event).end_mark = (event_end_mark))
#define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark) \
(EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)), \
(event).data.stream_start.encoding = (event_encoding))
#define STREAM_END_EVENT_INIT(event,start_mark,end_mark) \
(EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark)))
#define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \
event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
(EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \
(event).data.document_start.version_directive = (event_version_directive), \
(event).data.document_start.tag_directives.start = (event_tag_directives_start), \
(event).data.document_start.tag_directives.end = (event_tag_directives_end), \
(event).data.document_start.implicit = (event_implicit))
#define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark) \
(EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \
(event).data.document_end.implicit = (event_implicit))
#define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \
(EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)), \
(event).data.alias.anchor = (event_anchor))
#define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length, \
event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark) \
(EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \
(event).data.scalar.anchor = (event_anchor), \
(event).data.scalar.tag = (event_tag), \
(event).data.scalar.value = (event_value), \
(event).data.scalar.length = (event_length), \
(event).data.scalar.plain_implicit = (event_plain_implicit), \
(event).data.scalar.quoted_implicit = (event_quoted_implicit), \
(event).data.scalar.style = (event_style))
#define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \
event_implicit,event_style,start_mark,end_mark) \
(EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \
(event).data.sequence_start.anchor = (event_anchor), \
(event).data.sequence_start.tag = (event_tag), \
(event).data.sequence_start.implicit = (event_implicit), \
(event).data.sequence_start.style = (event_style))
#define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark) \
(EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
#define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \
event_implicit,event_style,start_mark,end_mark) \
(EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \
(event).data.mapping_start.anchor = (event_anchor), \
(event).data.mapping_start.tag = (event_tag), \
(event).data.mapping_start.implicit = (event_implicit), \
(event).data.mapping_start.style = (event_style))
#define MAPPING_END_EVENT_INIT(event,start_mark,end_mark) \
(EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark)))
/*
* Document initializer.
*/
#define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end, \
document_version_directive,document_tag_directives_start, \
document_tag_directives_end,document_start_implicit, \
document_end_implicit,document_start_mark,document_end_mark) \
(memset(&(document), 0, sizeof(yaml_document_t)), \
(document).nodes.start = (document_nodes_start), \
(document).nodes.end = (document_nodes_end), \
(document).nodes.top = (document_nodes_start), \
(document).version_directive = (document_version_directive), \
(document).tag_directives.start = (document_tag_directives_start), \
(document).tag_directives.end = (document_tag_directives_end), \
(document).start_implicit = (document_start_implicit), \
(document).end_implicit = (document_end_implicit), \
(document).start_mark = (document_start_mark), \
(document).end_mark = (document_end_mark))
/*
* Node initializers.
*/
#define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark) \
(memset(&(node), 0, sizeof(yaml_node_t)), \
(node).type = (node_type), \
(node).tag = (node_tag), \
(node).start_mark = (node_start_mark), \
(node).end_mark = (node_end_mark))
#define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \
node_style,start_mark,end_mark) \
(NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)), \
(node).data.scalar.value = (node_value), \
(node).data.scalar.length = (node_length), \
(node).data.scalar.style = (node_style))
#define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \
node_style,start_mark,end_mark) \
(NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)), \
(node).data.sequence.items.start = (node_items_start), \
(node).data.sequence.items.end = (node_items_end), \
(node).data.sequence.items.top = (node_items_start), \
(node).data.sequence.style = (node_style))
#define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \
node_style,start_mark,end_mark) \
(NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)), \
(node).data.mapping.pairs.start = (node_pairs_start), \
(node).data.mapping.pairs.end = (node_pairs_end), \
(node).data.mapping.pairs.top = (node_pairs_start), \
(node).data.mapping.style = (node_style))

38
extern/zlib/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,38 @@
if(NOT WIN32)
find_package(ZLIB)
endif()
if(WIN32 OR NOT ZLIB_FOUND)
message("-- Using Athena's built-in zlib")
add_library(z
adler32.c
compress.c
crc32.c
deflate.c
infback.c
inffast.c
inflate.c
inftrees.c
trees.c
uncompr.c
zutil.c
crc32.h
deflate.h
gzguts.h
inffast.h
inffixed.h
inflate.h
inftrees.h
trees.h
zconf.h
zlib.h
zutil.h)
if(WIN32 AND NOT UNIX)
install(FILES zconf.h zlib.h DESTINATION include COMPONENT zlib)
install(TARGETS z DESTINATION lib COMPONENT zlib)
endif()
set(ZLIB_LIBRARIES z CACHE PATH "Zlib libraries" FORCE)
set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Zlib include path" FORCE)
else()
set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} CACHE PATH "Zlib libraries" FORCE)
find_path(ZLIB_INCLUDE_DIR zlib.h)
endif()

42
extern/zlib/adler32.c vendored
View File

@@ -79,13 +79,18 @@ uLong ZEXPORT adler32(adler, buf, len)
adler &= 0xffff; adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */ /* in case user likes doing a byte at a time, keep it fast */
if (len == 1) { if (len == 1)
{
adler += buf[0]; adler += buf[0];
if (adler >= BASE) if (adler >= BASE)
adler -= BASE; adler -= BASE;
sum2 += adler; sum2 += adler;
if (sum2 >= BASE) if (sum2 >= BASE)
sum2 -= BASE; sum2 -= BASE;
return adler | (sum2 << 16); return adler | (sum2 << 16);
} }
@@ -94,40 +99,54 @@ uLong ZEXPORT adler32(adler, buf, len)
return 1L; return 1L;
/* in case short lengths are provided, keep it somewhat fast */ /* in case short lengths are provided, keep it somewhat fast */
if (len < 16) { if (len < 16)
while (len--) { {
while (len--)
{
adler += *buf++; adler += *buf++;
sum2 += adler; sum2 += adler;
} }
if (adler >= BASE) if (adler >= BASE)
adler -= BASE; adler -= BASE;
MOD28(sum2); /* only added so many BASE's */ MOD28(sum2); /* only added so many BASE's */
return adler | (sum2 << 16); return adler | (sum2 << 16);
} }
/* do length NMAX blocks -- requires just one modulo operation */ /* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) { while (len >= NMAX)
{
len -= NMAX; len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */ n = NMAX / 16; /* NMAX is divisible by 16 */
do {
do
{
DO16(buf); /* 16 sums unrolled */ DO16(buf); /* 16 sums unrolled */
buf += 16; buf += 16;
} while (--n); }
while (--n);
MOD(adler); MOD(adler);
MOD(sum2); MOD(sum2);
} }
/* do remaining bytes (less than NMAX, still just one modulo) */ /* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */ if (len) /* avoid modulos if none remaining */
while (len >= 16) { {
while (len >= 16)
{
len -= 16; len -= 16;
DO16(buf); DO16(buf);
buf += 16; buf += 16;
} }
while (len--) {
while (len--)
{
adler += *buf++; adler += *buf++;
sum2 += adler; sum2 += adler;
} }
MOD(adler); MOD(adler);
MOD(sum2); MOD(sum2);
} }
@@ -162,10 +181,15 @@ local uLong adler32_combine_(adler1, adler2, len2)
MOD(sum2); MOD(sum2);
sum1 += (adler2 & 0xffff) + BASE - 1; sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE;
if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE;
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
if (sum2 >= BASE) sum2 -= BASE; if (sum2 >= BASE) sum2 -= BASE;
return sum1 | (sum2 << 16); return sum1 | (sum2 << 16);
} }

View File

@@ -36,11 +36,14 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
stream.next_in = (Bytef*)source; stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K #ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */ /* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif #endif
stream.next_out = dest; stream.next_out = dest;
stream.avail_out = (uInt) * destLen; stream.avail_out = (uInt) * destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
@@ -48,13 +51,17 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
stream.opaque = (voidpf)0; stream.opaque = (voidpf)0;
err = deflateInit(&stream, level); err = deflateInit(&stream, level);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH); err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
if (err != Z_STREAM_END)
{
deflateEnd(&stream); deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err; return err == Z_OK ? Z_BUF_ERROR : err;
} }
*destLen = stream.total_out; *destLen = stream.total_out;
err = deflateEnd(&stream); err = deflateEnd(&stream);

114
extern/zlib/crc32.c vendored
View File

@@ -99,39 +99,50 @@ local void make_crc_table()
/* See if another task is already doing this (not thread-safe, but better /* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in than nothing -- significantly reduces duration of vulnerability in
case the advice about DYNAMIC_CRC_TABLE is ignored) */ case the advice about DYNAMIC_CRC_TABLE is ignored) */
if (first) { if (first)
{
first = 0; first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */ /* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly = 0; poly = 0;
for (n = 0; n < (int)(sizeof(p) / sizeof(unsigned char)); n++) for (n = 0; n < (int)(sizeof(p) / sizeof(unsigned char)); n++)
poly |= (z_crc_t)1 << (31 - p[n]); poly |= (z_crc_t)1 << (31 - p[n]);
/* generate a crc for every 8-bit value */ /* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++)
{
c = (z_crc_t)n; c = (z_crc_t)n;
for (k = 0; k < 8; k++) for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1; c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c; crc_table[0][n] = c;
} }
#ifdef BYFOUR #ifdef BYFOUR
/* generate crc for each value followed by one, two, and three zeros, /* generate crc for each value followed by one, two, and three zeros,
and then the byte reversal of those as well as the first table */ and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++)
{
c = crc_table[0][n]; c = crc_table[0][n];
crc_table[4][n] = ZSWAP32(c); crc_table[4][n] = ZSWAP32(c);
for (k = 1; k < 4; k++) {
for (k = 1; k < 4; k++)
{
c = crc_table[0][c & 0xff] ^ (c >> 8); c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c; crc_table[k][n] = c;
crc_table[k + 4][n] = ZSWAP32(c); crc_table[k + 4][n] = ZSWAP32(c);
} }
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
crc_table_empty = 0; crc_table_empty = 0;
} }
else { /* not first */ else /* not first */
{
/* wait for the other guy to finish (not efficient, but rare) */ /* wait for the other guy to finish (not efficient, but rare) */
while (crc_table_empty) while (crc_table_empty)
; ;
@@ -143,7 +154,9 @@ local void make_crc_table()
FILE* out; FILE* out;
out = fopen("crc32.h", "w"); out = fopen("crc32.h", "w");
if (out == NULL) return; if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
fprintf(out, "local const z_crc_t FAR "); fprintf(out, "local const z_crc_t FAR ");
@@ -151,10 +164,13 @@ local void make_crc_table()
write_table(out, crc_table[0]); write_table(out, crc_table[0]);
# ifdef BYFOUR # ifdef BYFOUR
fprintf(out, "#ifdef BYFOUR\n"); fprintf(out, "#ifdef BYFOUR\n");
for (k = 1; k < 8; k++) {
for (k = 1; k < 8; k++)
{
fprintf(out, " },\n {\n"); fprintf(out, " },\n {\n");
write_table(out, crc_table[k]); write_table(out, crc_table[k]);
} }
fprintf(out, "#endif\n"); fprintf(out, "#endif\n");
# endif /* BYFOUR */ # endif /* BYFOUR */
fprintf(out, " }\n};\n"); fprintf(out, " }\n};\n");
@@ -190,8 +206,10 @@ local void write_table(out, table)
const z_crc_t FAR* ZEXPORT get_crc_table() const z_crc_t FAR* ZEXPORT get_crc_table()
{ {
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) if (crc_table_empty)
make_crc_table(); make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
return (const z_crc_t FAR*)crc_table; return (const z_crc_t FAR*)crc_table;
} }
@@ -213,34 +231,48 @@ unsigned long ZEXPORT crc32(crc, buf, len)
if (buf == Z_NULL) return 0UL; if (buf == Z_NULL) return 0UL;
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) if (crc_table_empty)
make_crc_table(); make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
#ifdef BYFOUR #ifdef BYFOUR
#ifdef WIN32 #ifdef WIN32
int size_match = (sizeof(void*) == sizeof(ptrdiff_t)); int size_match = (sizeof(void*) == sizeof(ptrdiff_t));
if (size_match) {
if (size_match)
{
#else #else
if (sizeof(void *) == sizeof(ptrdiff_t)) {
if (sizeof(void*) == sizeof(ptrdiff_t))
{
#endif /* WIN32 */ #endif /* WIN32 */
z_crc_t endian; z_crc_t endian;
endian = 1; endian = 1;
if (*((unsigned char*)(&endian))) if (*((unsigned char*)(&endian)))
return crc32_little(crc, buf, len); return crc32_little(crc, buf, len);
else else
return crc32_big(crc, buf, len); return crc32_big(crc, buf, len);
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
crc = crc ^ 0xffffffffUL; crc = crc ^ 0xffffffffUL;
while (len >= 8) {
while (len >= 8)
{
DO8; DO8;
len -= 8; len -= 8;
} }
if (len) do {
if (len) do
{
DO1; DO1;
} while (--len); }
while (--len);
return crc ^ 0xffffffffUL; return crc ^ 0xffffffffUL;
} }
@@ -267,25 +299,35 @@ local unsigned long crc32_little(crc, buf, len)
c = (z_crc_t)crc; c = (z_crc_t)crc;
c = ~c; c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
while (len && ((ptrdiff_t)buf & 3))
{
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--; len--;
} }
buf4 = (const z_crc_t FAR*)(const void FAR*)buf; buf4 = (const z_crc_t FAR*)(const void FAR*)buf;
while (len >= 32) {
while (len >= 32)
{
DOLIT32; DOLIT32;
len -= 32; len -= 32;
} }
while (len >= 4) {
while (len >= 4)
{
DOLIT4; DOLIT4;
len -= 4; len -= 4;
} }
buf = (const unsigned char FAR*)buf4; buf = (const unsigned char FAR*)buf4;
if (len) do { if (len) do
{
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
} while (--len); }
while (--len);
c = ~c; c = ~c;
return (unsigned long)c; return (unsigned long)c;
} }
@@ -311,27 +353,37 @@ local unsigned long crc32_big(crc, buf, len)
c = ZSWAP32((z_crc_t)crc); c = ZSWAP32((z_crc_t)crc);
c = ~c; c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
while (len && ((ptrdiff_t)buf & 3))
{
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--; len--;
} }
buf4 = (const z_crc_t FAR*)(const void FAR*)buf; buf4 = (const z_crc_t FAR*)(const void FAR*)buf;
buf4--; buf4--;
while (len >= 32) {
while (len >= 32)
{
DOBIG32; DOBIG32;
len -= 32; len -= 32;
} }
while (len >= 4) {
while (len >= 4)
{
DOBIG4; DOBIG4;
len -= 4; len -= 4;
} }
buf4++; buf4++;
buf = (const unsigned char FAR*)buf4; buf = (const unsigned char FAR*)buf4;
if (len) do { if (len) do
{
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len); }
while (--len);
c = ~c; c = ~c;
return (unsigned long)(ZSWAP32(c)); return (unsigned long)(ZSWAP32(c));
} }
@@ -352,12 +404,16 @@ local unsigned long gf2_matrix_times(mat, vec)
unsigned long sum; unsigned long sum;
sum = 0; sum = 0;
while (vec) {
while (vec)
{
if (vec & 1) if (vec & 1)
sum ^= *mat; sum ^= *mat;
vec >>= 1; vec >>= 1;
mat++; mat++;
} }
return sum; return sum;
} }
@@ -398,7 +454,9 @@ local uLong crc32_combine_(crc1, crc2, len2)
/* put operator for one zero bit in odd */ /* put operator for one zero bit in odd */
odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
row = 1; row = 1;
for (n = 1; n < GF2_DIM; n++) {
for (n = 1; n < GF2_DIM; n++)
{
odd[n] = row; odd[n] = row;
row <<= 1; row <<= 1;
} }
@@ -411,11 +469,14 @@ local uLong crc32_combine_(crc1, crc2, len2)
/* apply len2 zeros to crc1 (first square will put the operator for one /* apply len2 zeros to crc1 (first square will put the operator for one
zero byte, eight zero bits, in even) */ zero byte, eight zero bits, in even) */
do { do
{
/* apply zeros operator for this bit of len2 */ /* apply zeros operator for this bit of len2 */
gf2_matrix_square(even, odd); gf2_matrix_square(even, odd);
if (len2 & 1) if (len2 & 1)
crc1 = gf2_matrix_times(even, crc1); crc1 = gf2_matrix_times(even, crc1);
len2 >>= 1; len2 >>= 1;
/* if no more bits set, then done */ /* if no more bits set, then done */
@@ -424,12 +485,15 @@ local uLong crc32_combine_(crc1, crc2, len2)
/* another iteration of the loop with odd and even swapped */ /* another iteration of the loop with odd and even swapped */
gf2_matrix_square(odd, even); gf2_matrix_square(odd, even);
if (len2 & 1) if (len2 & 1)
crc1 = gf2_matrix_times(odd, crc1); crc1 = gf2_matrix_times(odd, crc1);
len2 >>= 1; len2 >>= 1;
/* if no more bits set, then done */ /* if no more bits set, then done */
} while (len2 != 0); }
while (len2 != 0);
/* return combined crc */ /* return combined crc */
crc1 ^= crc2; crc1 ^= crc2;

676
extern/zlib/deflate.c vendored

File diff suppressed because it is too large Load Diff

15
extern/zlib/deflate.h vendored
View File

@@ -62,12 +62,15 @@
/* Data structure describing a single value and its code string. */ /* Data structure describing a single value and its code string. */
typedef struct ct_data_s { typedef struct ct_data_s
union { {
union
{
ush freq; /* frequency count */ ush freq; /* frequency count */
ush code; /* bit string */ ush code; /* bit string */
} fc; } fc;
union { union
{
ush dad; /* father node in Huffman tree */ ush dad; /* father node in Huffman tree */
ush len; /* length of bit string */ ush len; /* length of bit string */
} dl; } dl;
@@ -80,7 +83,8 @@ typedef struct ct_data_s {
typedef struct static_tree_desc_s static_tree_desc; typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s { typedef struct tree_desc_s
{
ct_data* dyn_tree; /* the dynamic tree */ ct_data* dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */ int max_code; /* largest code with non zero frequency */
static_tree_desc* stat_desc; /* the corresponding static tree */ static_tree_desc* stat_desc; /* the corresponding static tree */
@@ -94,7 +98,8 @@ typedef unsigned IPos;
* save space in the various tables. IPos is used only for parameter passing. * save space in the various tables. IPos is used only for parameter passing.
*/ */
typedef struct internal_state { typedef struct internal_state
{
z_streamp strm; /* pointer back to this zlib stream */ z_streamp strm; /* pointer back to this zlib stream */
int status; /* as the name implies */ int status; /* as the name implies */
Bytef* pending_buf; /* output still pending */ Bytef* pending_buf; /* output still pending */

View File

@@ -20,6 +20,7 @@ int ZEXPORT gzclose(file)
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);

View File

@@ -147,7 +147,8 @@
#define GZIP 2 /* decompress a gzip stream */ #define GZIP 2 /* decompress a gzip stream */
/* internal gzip file state data structure */ /* internal gzip file state data structure */
typedef struct { typedef struct
{
/* exposed contents for gzgetc() macro */ /* exposed contents for gzgetc() macro */
struct gzFile_s x; /* "x" for exposed */ struct gzFile_s x; /* "x" for exposed */
/* x.have: number of bytes available at x.next */ /* x.have: number of bytes available at x.next */

136
extern/zlib/gzlib.c vendored
View File

@@ -45,15 +45,19 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
(LPVOID)&msgbuf, (LPVOID)&msgbuf,
0, 0,
NULL); NULL);
if (chars != 0) {
if (chars != 0)
{
/* If there is an \r\n appended, zap it. */ /* If there is an \r\n appended, zap it. */
if (chars >= 2 if (chars >= 2
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n')
{
chars -= 2; chars -= 2;
msgbuf[chars] = 0; msgbuf[chars] = 0;
} }
if (chars > sizeof (buf) - 1) { if (chars > sizeof(buf) - 1)
{
chars = sizeof(buf) - 1; chars = sizeof(buf) - 1;
msgbuf[chars] = 0; msgbuf[chars] = 0;
} }
@@ -61,7 +65,8 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
wcstombs(buf, msgbuf, chars + 1); wcstombs(buf, msgbuf, chars + 1);
LocalFree(msgbuf); LocalFree(msgbuf);
} }
else { else
{
sprintf(buf, "unknown win32 error (%ld)", error); sprintf(buf, "unknown win32 error (%ld)", error);
} }
@@ -80,11 +85,14 @@ local void gz_reset(state)
#endif #endif
{ {
state->x.have = 0; /* no output data available */ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */
if (state->mode == GZ_READ) /* for reading ... */
{
state->eof = 0; /* not at end of file */ state->eof = 0; /* not at end of file */
state->past = 0; /* have not read past end yet */ state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */ state->how = LOOK; /* look for gzip header */
} }
state->seek = 0; /* no seek request pending */ state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */ gz_error(state, Z_OK, NULL); /* clear error */
state->x.pos = 0; /* no uncompressed data yet */ state->x.pos = 0; /* no uncompressed data yet */
@@ -117,8 +125,10 @@ local gzFile gz_open(path, fd, mode)
/* allocate gzFile structure to return */ /* allocate gzFile structure to return */
state = malloc(sizeof(gz_state)); state = malloc(sizeof(gz_state));
if (state == NULL) if (state == NULL)
return NULL; return NULL;
state->size = 0; /* no buffers allocated yet */ state->size = 0; /* no buffers allocated yet */
state->want = GZBUFSIZE; /* requested buffer size */ state->want = GZBUFSIZE; /* requested buffer size */
state->msg = NULL; /* no error message yet */ state->msg = NULL; /* no error message yet */
@@ -128,87 +138,115 @@ local gzFile gz_open(path, fd, mode)
state->level = Z_DEFAULT_COMPRESSION; state->level = Z_DEFAULT_COMPRESSION;
state->strategy = Z_DEFAULT_STRATEGY; state->strategy = Z_DEFAULT_STRATEGY;
state->direct = 0; state->direct = 0;
while (*mode) {
while (*mode)
{
if (*mode >= '0' && *mode <= '9') if (*mode >= '0' && *mode <= '9')
state->level = *mode - '0'; state->level = *mode - '0';
else else
switch (*mode) { switch (*mode)
{
case 'r': case 'r':
state->mode = GZ_READ; state->mode = GZ_READ;
break; break;
#ifndef NO_GZCOMPRESS #ifndef NO_GZCOMPRESS
case 'w': case 'w':
state->mode = GZ_WRITE; state->mode = GZ_WRITE;
break; break;
case 'a': case 'a':
state->mode = GZ_APPEND; state->mode = GZ_APPEND;
break; break;
#endif #endif
case '+': /* can't read and write at the same time */ case '+': /* can't read and write at the same time */
free(state); free(state);
return NULL; return NULL;
case 'b': /* ignore -- will request binary anyway */ case 'b': /* ignore -- will request binary anyway */
break; break;
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
case 'e': case 'e':
cloexec = 1; cloexec = 1;
break; break;
#endif #endif
#ifdef O_EXCL #ifdef O_EXCL
case 'x': case 'x':
exclusive = 1; exclusive = 1;
break; break;
#endif #endif
case 'f': case 'f':
state->strategy = Z_FILTERED; state->strategy = Z_FILTERED;
break; break;
case 'h': case 'h':
state->strategy = Z_HUFFMAN_ONLY; state->strategy = Z_HUFFMAN_ONLY;
break; break;
case 'R': case 'R':
state->strategy = Z_RLE; state->strategy = Z_RLE;
break; break;
case 'F': case 'F':
state->strategy = Z_FIXED; state->strategy = Z_FIXED;
case 'T': case 'T':
state->direct = 1; state->direct = 1;
default: /* could consider as an error, but just ignore */ default: /* could consider as an error, but just ignore */
; ;
} }
mode++; mode++;
} }
/* must provide an "r", "w", or "a" */ /* must provide an "r", "w", or "a" */
if (state->mode == GZ_NONE) { if (state->mode == GZ_NONE)
{
free(state); free(state);
return NULL; return NULL;
} }
/* can't force transparent read */ /* can't force transparent read */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ)
if (state->direct) { {
if (state->direct)
{
free(state); free(state);
return NULL; return NULL;
} }
state->direct = 1; /* for empty file */ state->direct = 1; /* for empty file */
} }
/* save the path name for error messages */ /* save the path name for error messages */
#ifdef _WIN32 #ifdef _WIN32
if (fd == -2) {
if (fd == -2)
{
len = wcstombs(NULL, path, 0); len = wcstombs(NULL, path, 0);
if (len == (size_t) - 1) if (len == (size_t) - 1)
len = 0; len = 0;
} }
else else
#endif #endif
len = strlen(path); len = strlen(path);
state->path = malloc(len + 1); state->path = malloc(len + 1);
if (state->path == NULL) {
if (state->path == NULL)
{
free(state); free(state);
return NULL; return NULL;
} }
#ifdef _WIN32 #ifdef _WIN32
if (fd == -2) if (fd == -2)
if (len) if (len)
wcstombs(state->path, path, len + 1); wcstombs(state->path, path, len + 1);
@@ -245,17 +283,22 @@ local gzFile gz_open(path, fd, mode)
fd == -2 ? _wopen(path, oflag, 0666) : fd == -2 ? _wopen(path, oflag, 0666) :
#endif #endif
open(path, oflag, 0666)); open(path, oflag, 0666));
if (state->fd == -1) {
if (state->fd == -1)
{
free(state->path); free(state->path);
free(state); free(state);
return NULL; return NULL;
} }
if (state->mode == GZ_APPEND) if (state->mode == GZ_APPEND)
state->mode = GZ_WRITE; /* simplify later checks */ state->mode = GZ_WRITE; /* simplify later checks */
/* save the current position for rewinding (only if reading) */ /* save the current position for rewinding (only if reading) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ)
{
state->start = LSEEK(state->fd, 0, SEEK_CUR); state->start = LSEEK(state->fd, 0, SEEK_CUR);
if (state->start == -1) state->start = 0; if (state->start == -1) state->start = 0;
} }
@@ -304,6 +347,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL)
return NULL; return NULL;
sprintf(path, "<fd:%d>", fd); /* for debugging */ sprintf(path, "<fd:%d>", fd); /* for debugging */
gz = gz_open(path, fd, mode); gz = gz_open(path, fd, mode);
free(path); free(path);
@@ -336,7 +380,9 @@ int ZEXPORT gzbuffer(file, size)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1; return -1;
@@ -347,6 +393,7 @@ int ZEXPORT gzbuffer(file, size)
/* check and set requested size */ /* check and set requested size */
if (size < 2) if (size < 2)
size = 2; /* need two bytes to check magic header */ size = 2; /* need two bytes to check magic header */
state->want = size; state->want = size;
return 0; return 0;
} }
@@ -364,6 +411,7 @@ int ZEXPORT gzrewind(file)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're reading and that there's no error */ /* check that we're reading and that there's no error */
@@ -374,6 +422,7 @@ int ZEXPORT gzrewind(file)
/* back up and start over */ /* back up and start over */
if (LSEEK(state->fd, state->start, SEEK_SET) == -1) if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
return -1; return -1;
gz_reset(state); gz_reset(state);
return 0; return 0;
} }
@@ -395,7 +444,9 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1; return -1;
@@ -412,14 +463,18 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
offset -= state->x.pos; offset -= state->x.pos;
else if (state->seek) else if (state->seek)
offset += state->skip; offset += state->skip;
state->seek = 0; state->seek = 0;
/* if within raw area while reading, just go there */ /* if within raw area while reading, just go there */
if (state->mode == GZ_READ && state->how == COPY && if (state->mode == GZ_READ && state->how == COPY &&
state->x.pos + offset >= 0) { state->x.pos + offset >= 0)
{
ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
if (ret == -1) if (ret == -1)
return -1; return -1;
state->x.have = 0; state->x.have = 0;
state->eof = 0; state->eof = 0;
state->past = 0; state->past = 0;
@@ -431,18 +486,23 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
} }
/* calculate skip amount, rewinding if needed for back seek when reading */ /* calculate skip amount, rewinding if needed for back seek when reading */
if (offset < 0) { if (offset < 0)
{
if (state->mode != GZ_READ) /* writing -- can't go backwards */ if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1; return -1;
offset += state->x.pos; offset += state->x.pos;
if (offset < 0) /* before start of file! */ if (offset < 0) /* before start of file! */
return -1; return -1;
if (gzrewind(file) == -1) /* rewind, then skip to offset */ if (gzrewind(file) == -1) /* rewind, then skip to offset */
return -1; return -1;
} }
/* if reading, skip what's in output buffer (one less gzgetc() check) */ /* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ)
{
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
(unsigned)offset : state->x.have; (unsigned)offset : state->x.have;
state->x.have -= n; state->x.have -= n;
@@ -452,10 +512,12 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
} }
/* request skip (if not zero) */ /* request skip (if not zero) */
if (offset) { if (offset)
{
state->seek = 1; state->seek = 1;
state->skip = offset; state->skip = offset;
} }
return state->x.pos + offset; return state->x.pos + offset;
} }
@@ -488,7 +550,9 @@ z_off64_t ZEXPORT gztell64(file)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1; return -1;
@@ -524,16 +588,21 @@ z_off64_t ZEXPORT gzoffset64(file)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1; return -1;
/* compute and return effective offset in file */ /* compute and return effective offset in file */
offset = LSEEK(state->fd, 0, SEEK_CUR); offset = LSEEK(state->fd, 0, SEEK_CUR);
if (offset == -1) if (offset == -1)
return -1; return -1;
if (state->mode == GZ_READ) /* reading */ if (state->mode == GZ_READ) /* reading */
offset -= state->strm.avail_in; /* don't count buffered input */ offset -= state->strm.avail_in; /* don't count buffered input */
return offset; return offset;
} }
@@ -564,7 +633,9 @@ int ZEXPORT gzeof(file)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return 0; return 0;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return 0; return 0;
@@ -586,13 +657,16 @@ const char * ZEXPORT gzerror(file, errnum)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return NULL; return NULL;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return NULL; return NULL;
/* return error information */ /* return error information */
if (errnum != NULL) if (errnum != NULL)
*errnum = state->err; *errnum = state->err;
return state->msg == NULL ? "" : state->msg; return state->msg == NULL ? "" : state->msg;
} }
@@ -609,15 +683,19 @@ void ZEXPORT gzclearerr(file)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return; return;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return; return;
/* clear error and end-of-file */ /* clear error and end-of-file */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ)
{
state->eof = 0; state->eof = 0;
state->past = 0; state->past = 0;
} }
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
} }
@@ -637,9 +715,11 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
#endif #endif
{ {
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL)
{
if (state->err != Z_MEM_ERROR) if (state->err != Z_MEM_ERROR)
free(state->msg); free(state->msg);
state->msg = NULL; state->msg = NULL;
} }
@@ -649,21 +729,25 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
/* set error code, and if no message, then done */ /* set error code, and if no message, then done */
state->err = err; state->err = err;
if (msg == NULL) if (msg == NULL)
return; return;
/* for an out of memory error, save as static string */ /* for an out of memory error, save as static string */
if (err == Z_MEM_ERROR) { if (err == Z_MEM_ERROR)
{
state->msg = (char*)msg; state->msg = (char*)msg;
return; return;
} }
/* construct error message with path */ /* construct error message with path */
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL)
{
state->err = Z_MEM_ERROR; state->err = Z_MEM_ERROR;
state->msg = (char*)"out of memory"; state->msg = (char*)"out of memory";
return; return;
} }
strcpy(state->msg, state->path); strcpy(state->msg, state->path);
strcat(state->msg, ": "); strcat(state->msg, ": ");
strcat(state->msg, msg); strcat(state->msg, msg);
@@ -680,11 +764,15 @@ unsigned ZLIB_INTERNAL gz_intmax()
unsigned p, q; unsigned p, q;
p = 1; p = 1;
do {
do
{
q = p; q = p;
p <<= 1; p <<= 1;
p++; p++;
} while (p > q); }
while (p > q);
return q >> 1; return q >> 1;
} }
#endif #endif

186
extern/zlib/gzread.c vendored
View File

@@ -30,18 +30,27 @@ local int gz_load(state, buf, len, have)
int ret; int ret;
*have = 0; *have = 0;
do {
do
{
ret = read(state->fd, buf + *have, len - *have); ret = read(state->fd, buf + *have, len - *have);
if (ret <= 0) if (ret <= 0)
break; break;
*have += ret; *have += ret;
} while (*have < len); }
if (ret < 0) { while (*have < len);
if (ret < 0)
{
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
return -1; return -1;
} }
if (ret == 0) if (ret == 0)
state->eof = 1; state->eof = 1;
return 0; return 0;
} }
@@ -64,20 +73,29 @@ local int gz_avail(state)
if (state->err != Z_OK && state->err != Z_BUF_ERROR) if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1; return -1;
if (state->eof == 0) {
if (strm->avail_in) { /* copy what's there to the start */ if (state->eof == 0)
{
if (strm->avail_in) /* copy what's there to the start */
{
unsigned char* p = state->in, *q = strm->next_in; unsigned char* p = state->in, *q = strm->next_in;
unsigned n = strm->avail_in; unsigned n = strm->avail_in;
do {
do
{
*p++ = *q++; *p++ = *q++;
} while (--n);
} }
while (--n);
}
if (gz_load(state, state->in + strm->avail_in, if (gz_load(state, state->in + strm->avail_in,
state->size - strm->avail_in, &got) == -1) state->size - strm->avail_in, &got) == -1)
return -1; return -1;
strm->avail_in += got; strm->avail_in += got;
strm->next_in = state->in; strm->next_in = state->in;
} }
return 0; return 0;
} }
@@ -100,18 +118,24 @@ local int gz_look(state)
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate read buffers and inflate memory */ /* allocate read buffers and inflate memory */
if (state->size == 0) { if (state->size == 0)
{
/* allocate buffers */ /* allocate buffers */
state->in = malloc(state->want); state->in = malloc(state->want);
state->out = malloc(state->want << 1); state->out = malloc(state->want << 1);
if (state->in == NULL || state->out == NULL) {
if (state->in == NULL || state->out == NULL)
{
if (state->out != NULL) if (state->out != NULL)
free(state->out); free(state->out);
if (state->in != NULL) if (state->in != NULL)
free(state->in); free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
} }
state->size = state->want; state->size = state->want;
/* allocate inflate memory */ /* allocate inflate memory */
@@ -120,7 +144,9 @@ local int gz_look(state)
state->strm.opaque = Z_NULL; state->strm.opaque = Z_NULL;
state->strm.avail_in = 0; state->strm.avail_in = 0;
state->strm.next_in = Z_NULL; state->strm.next_in = Z_NULL;
if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) /* gunzip */
{
free(state->out); free(state->out);
free(state->in); free(state->in);
state->size = 0; state->size = 0;
@@ -130,9 +156,11 @@ local int gz_look(state)
} }
/* get at least the magic bytes in the input buffer */ /* get at least the magic bytes in the input buffer */
if (strm->avail_in < 2) { if (strm->avail_in < 2)
{
if (gz_avail(state) == -1) if (gz_avail(state) == -1)
return -1; return -1;
if (strm->avail_in == 0) if (strm->avail_in == 0)
return 0; return 0;
} }
@@ -145,7 +173,8 @@ local int gz_look(state)
the header will be written in a single operation, so that reading a the header will be written in a single operation, so that reading a
single byte is sufficient indication that it is not a gzip file) */ single byte is sufficient indication that it is not a gzip file) */
if (strm->avail_in > 1 && if (strm->avail_in > 1 &&
strm->next_in[0] == 31 && strm->next_in[1] == 139) { strm->next_in[0] == 31 && strm->next_in[1] == 139)
{
inflateReset(strm); inflateReset(strm);
state->how = GZIP; state->how = GZIP;
state->direct = 0; state->direct = 0;
@@ -154,7 +183,8 @@ local int gz_look(state)
/* no gzip header -- if we were decoding gzip before, then this is trailing /* no gzip header -- if we were decoding gzip before, then this is trailing
garbage. Ignore the trailing garbage and finish. */ garbage. Ignore the trailing garbage and finish. */
if (state->direct == 0) { if (state->direct == 0)
{
strm->avail_in = 0; strm->avail_in = 0;
state->eof = 1; state->eof = 1;
state->x.have = 0; state->x.have = 0;
@@ -165,11 +195,14 @@ local int gz_look(state)
the output buffer is larger than the input buffer, which also assures the output buffer is larger than the input buffer, which also assures
space for gzungetc() */ space for gzungetc() */
state->x.next = state->out; state->x.next = state->out;
if (strm->avail_in) {
if (strm->avail_in)
{
memcpy(state->x.next, strm->next_in, strm->avail_in); memcpy(state->x.next, strm->next_in, strm->avail_in);
state->x.have = strm->avail_in; state->x.have = strm->avail_in;
strm->avail_in = 0; strm->avail_in = 0;
} }
state->how = COPY; state->how = COPY;
state->direct = 1; state->direct = 1;
return 0; return 0;
@@ -193,32 +226,43 @@ local int gz_decomp(state)
/* fill output buffer up to end of deflate stream */ /* fill output buffer up to end of deflate stream */
had = strm->avail_out; had = strm->avail_out;
do {
do
{
/* get more input for inflate() */ /* get more input for inflate() */
if (strm->avail_in == 0 && gz_avail(state) == -1) if (strm->avail_in == 0 && gz_avail(state) == -1)
return -1; return -1;
if (strm->avail_in == 0) {
if (strm->avail_in == 0)
{
gz_error(state, Z_BUF_ERROR, "unexpected end of file"); gz_error(state, Z_BUF_ERROR, "unexpected end of file");
break; break;
} }
/* decompress and handle errors */ /* decompress and handle errors */
ret = inflate(strm, Z_NO_FLUSH); ret = inflate(strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT)
{
gz_error(state, Z_STREAM_ERROR, gz_error(state, Z_STREAM_ERROR,
"internal error: inflate stream corrupt"); "internal error: inflate stream corrupt");
return -1; return -1;
} }
if (ret == Z_MEM_ERROR) {
if (ret == Z_MEM_ERROR)
{
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
} }
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
if (ret == Z_DATA_ERROR) /* deflate stream invalid */
{
gz_error(state, Z_DATA_ERROR, gz_error(state, Z_DATA_ERROR,
strm->msg == NULL ? "compressed data error" : strm->msg); strm->msg == NULL ? "compressed data error" : strm->msg);
return -1; return -1;
} }
} while (strm->avail_out && ret != Z_STREAM_END); }
while (strm->avail_out && ret != Z_STREAM_END);
/* update available output */ /* update available output */
state->x.have = had - strm->avail_out; state->x.have = had - strm->avail_out;
@@ -247,27 +291,37 @@ local int gz_fetch(state)
{ {
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
do { do
switch(state->how) { {
switch (state->how)
{
case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
if (gz_look(state) == -1) if (gz_look(state) == -1)
return -1; return -1;
if (state->how == LOOK) if (state->how == LOOK)
return 0; return 0;
break; break;
case COPY: /* -> COPY */ case COPY: /* -> COPY */
if (gz_load(state, state->out, state->size << 1, &(state->x.have)) if (gz_load(state, state->out, state->size << 1, &(state->x.have))
== -1) == -1)
return -1; return -1;
state->x.next = state->out; state->x.next = state->out;
return 0; return 0;
case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */
strm->avail_out = state->size << 1; strm->avail_out = state->size << 1;
strm->next_out = state->out; strm->next_out = state->out;
if (gz_decomp(state) == -1) if (gz_decomp(state) == -1)
return -1; return -1;
} }
} while (state->x.have == 0 && (!state->eof || strm->avail_in)); }
while (state->x.have == 0 && (!state->eof || strm->avail_in));
return 0; return 0;
} }
@@ -284,8 +338,10 @@ local int gz_skip(state, len)
/* skip over len bytes or reach end-of-file, whichever comes first */ /* skip over len bytes or reach end-of-file, whichever comes first */
while (len) while (len)
/* skip over whatever is in output buffer */ /* skip over whatever is in output buffer */
if (state->x.have) { if (state->x.have)
{
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
(unsigned)len : state->x.have; (unsigned)len : state->x.have;
state->x.have -= n; state->x.have -= n;
@@ -299,11 +355,13 @@ local int gz_skip(state, len)
break; break;
/* need more data to skip -- load up output buffer */ /* need more data to skip -- load up output buffer */
else { else
{
/* get more output, looking for header if required */ /* get more output, looking for header if required */
if (gz_fetch(state) == -1) if (gz_fetch(state) == -1)
return -1; return -1;
} }
return 0; return 0;
} }
@@ -324,6 +382,7 @@ int ZEXPORT gzread(file, buf, len)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
@@ -334,7 +393,8 @@ int ZEXPORT gzread(file, buf, len)
/* since an int is returned, make sure len fits in one, otherwise return /* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */ with an error (this avoids the flaw in the interface) */
if ((int)len < 0) { if ((int)len < 0)
{
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return -1; return -1;
} }
@@ -344,17 +404,22 @@ int ZEXPORT gzread(file, buf, len)
return 0; return 0;
/* process a skip request */ /* process a skip request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_skip(state, state->skip) == -1) if (gz_skip(state, state->skip) == -1)
return -1; return -1;
} }
/* get len bytes to buf, or less than len if at the end */ /* get len bytes to buf, or less than len if at the end */
got = 0; got = 0;
do {
do
{
/* first just try copying data from the output buffer */ /* first just try copying data from the output buffer */
if (state->x.have) { if (state->x.have)
{
n = state->x.have > len ? len : state->x.have; n = state->x.have > len ? len : state->x.have;
memcpy(buf, state->x.next, n); memcpy(buf, state->x.next, n);
state->x.next += n; state->x.next += n;
@@ -362,34 +427,41 @@ int ZEXPORT gzread(file, buf, len)
} }
/* output buffer empty -- return if we're at the end of the input */ /* output buffer empty -- return if we're at the end of the input */
else if (state->eof && strm->avail_in == 0) { else if (state->eof && strm->avail_in == 0)
{
state->past = 1; /* tried to read past end */ state->past = 1; /* tried to read past end */
break; break;
} }
/* need output data -- for small len or new stream load up our output /* need output data -- for small len or new stream load up our output
buffer */ buffer */
else if (state->how == LOOK || len < (state->size << 1)) { else if (state->how == LOOK || len < (state->size << 1))
{
/* get more output, looking for header if required */ /* get more output, looking for header if required */
if (gz_fetch(state) == -1) if (gz_fetch(state) == -1)
return -1; return -1;
continue; /* no progress yet -- go back to copy above */ continue; /* no progress yet -- go back to copy above */
/* the copy above assures that we will leave with space in the /* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */ output buffer, allowing at least one gzungetc() to succeed */
} }
/* large len -- read directly into user buffer */ /* large len -- read directly into user buffer */
else if (state->how == COPY) { /* read directly */ else if (state->how == COPY) /* read directly */
{
if (gz_load(state, buf, len, &n) == -1) if (gz_load(state, buf, len, &n) == -1)
return -1; return -1;
} }
/* large len -- decompress directly into user buffer */ /* large len -- decompress directly into user buffer */
else { /* state->how == GZIP */ else /* state->how == GZIP */
{
strm->avail_out = len; strm->avail_out = len;
strm->next_out = buf; strm->next_out = buf;
if (gz_decomp(state) == -1) if (gz_decomp(state) == -1)
return -1; return -1;
n = state->x.have; n = state->x.have;
state->x.have = 0; state->x.have = 0;
} }
@@ -399,7 +471,8 @@ int ZEXPORT gzread(file, buf, len)
buf = (char*)buf + n; buf = (char*)buf + n;
got += n; got += n;
state->x.pos += n; state->x.pos += n;
} while (len); }
while (len);
/* return number of bytes read into user buffer (will fit in int) */ /* return number of bytes read into user buffer (will fit in int) */
return (int)got; return (int)got;
@@ -421,6 +494,7 @@ int ZEXPORT gzgetc(file)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */ /* check that we're reading and that there's no (serious) error */
@@ -429,7 +503,8 @@ int ZEXPORT gzgetc(file)
return -1; return -1;
/* try output buffer (no need to check for skip request) */ /* try output buffer (no need to check for skip request) */
if (state->x.have) { if (state->x.have)
{
state->x.have--; state->x.have--;
state->x.pos++; state->x.pos++;
return *(state->x.next)++; return *(state->x.next)++;
@@ -464,6 +539,7 @@ int ZEXPORT gzungetc(c, file)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */ /* check that we're reading and that there's no (serious) error */
@@ -472,8 +548,10 @@ int ZEXPORT gzungetc(c, file)
return -1; return -1;
/* process a skip request */ /* process a skip request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_skip(state, state->skip) == -1) if (gz_skip(state, state->skip) == -1)
return -1; return -1;
} }
@@ -483,7 +561,8 @@ int ZEXPORT gzungetc(c, file)
return -1; return -1;
/* if output buffer empty, put byte at end (allows more pushing) */ /* if output buffer empty, put byte at end (allows more pushing) */
if (state->x.have == 0) { if (state->x.have == 0)
{
state->x.have = 1; state->x.have = 1;
state->x.next = state->out + (state->size << 1) - 1; state->x.next = state->out + (state->size << 1) - 1;
state->x.next[0] = c; state->x.next[0] = c;
@@ -493,19 +572,24 @@ int ZEXPORT gzungetc(c, file)
} }
/* if no room, give up (must have already done a gzungetc()) */ /* if no room, give up (must have already done a gzungetc()) */
if (state->x.have == (state->size << 1)) { if (state->x.have == (state->size << 1))
{
gz_error(state, Z_DATA_ERROR, "out of room to push characters"); gz_error(state, Z_DATA_ERROR, "out of room to push characters");
return -1; return -1;
} }
/* slide output data if needed and insert byte before existing data */ /* slide output data if needed and insert byte before existing data */
if (state->x.next == state->out) { if (state->x.next == state->out)
{
unsigned char* src = state->out + state->x.have; unsigned char* src = state->out + state->x.have;
unsigned char* dest = state->out + (state->size << 1); unsigned char* dest = state->out + (state->size << 1);
while (src > state->out) while (src > state->out)
*--dest = *--src; *--dest = *--src;
state->x.next = dest; state->x.next = dest;
} }
state->x.have++; state->x.have++;
state->x.next--; state->x.next--;
state->x.next[0] = c; state->x.next[0] = c;
@@ -532,6 +616,7 @@ char * ZEXPORT gzgets(file, buf, len)
/* check parameters and get internal structure */ /* check parameters and get internal structure */
if (file == NULL || buf == NULL || len < 1) if (file == NULL || buf == NULL || len < 1)
return NULL; return NULL;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */ /* check that we're reading and that there's no (serious) error */
@@ -540,8 +625,10 @@ char * ZEXPORT gzgets(file, buf, len)
return NULL; return NULL;
/* process a skip request */ /* process a skip request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_skip(state, state->skip) == -1) if (gz_skip(state, state->skip) == -1)
return NULL; return NULL;
} }
@@ -551,11 +638,15 @@ char * ZEXPORT gzgets(file, buf, len)
the contents, let the user worry about that) */ the contents, let the user worry about that) */
str = buf; str = buf;
left = (unsigned)len - 1; left = (unsigned)len - 1;
if (left) do {
if (left) do
{
/* assure that something is in the output buffer */ /* assure that something is in the output buffer */
if (state->x.have == 0 && gz_fetch(state) == -1) if (state->x.have == 0 && gz_fetch(state) == -1)
return NULL; /* error */ return NULL; /* error */
if (state->x.have == 0) { /* end of file */
if (state->x.have == 0) /* end of file */
{
state->past = 1; /* read past end */ state->past = 1; /* read past end */
break; /* return what we have */ break; /* return what we have */
} }
@@ -563,6 +654,7 @@ char * ZEXPORT gzgets(file, buf, len)
/* look for end-of-line in current output buffer */ /* look for end-of-line in current output buffer */
n = state->x.have > left ? left : state->x.have; n = state->x.have > left ? left : state->x.have;
eol = memchr(state->x.next, '\n', n); eol = memchr(state->x.next, '\n', n);
if (eol != NULL) if (eol != NULL)
n = (unsigned)(eol - state->x.next) + 1; n = (unsigned)(eol - state->x.next) + 1;
@@ -573,11 +665,13 @@ char * ZEXPORT gzgets(file, buf, len)
state->x.pos += n; state->x.pos += n;
left -= n; left -= n;
buf += n; buf += n;
} while (left && eol == NULL); }
while (left && eol == NULL);
/* return terminated string, or if nothing, end of file */ /* return terminated string, or if nothing, end of file */
if (buf == str) if (buf == str)
return NULL; return NULL;
buf[0] = 0; buf[0] = 0;
return str; return str;
} }
@@ -595,6 +689,7 @@ int ZEXPORT gzdirect(file)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return 0; return 0;
state = (gz_statep)file; state = (gz_statep)file;
/* if the state is not known, but we can find out, then do so (this is /* if the state is not known, but we can find out, then do so (this is
@@ -620,6 +715,7 @@ int ZEXPORT gzclose_r(file)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're reading */ /* check that we're reading */
@@ -627,11 +723,13 @@ int ZEXPORT gzclose_r(file)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* free memory and close file */ /* free memory and close file */
if (state->size) { if (state->size)
{
inflateEnd(&(state->strm)); inflateEnd(&(state->strm));
free(state->out); free(state->out);
free(state->in); free(state->in);
} }
err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
free(state->path); free(state->path);

144
extern/zlib/gzwrite.c vendored
View File

@@ -24,16 +24,21 @@ local int gz_init(state)
/* allocate input buffer */ /* allocate input buffer */
state->in = malloc(state->want); state->in = malloc(state->want);
if (state->in == NULL) {
if (state->in == NULL)
{
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
} }
/* only need output buffer and deflate state if compressing */ /* only need output buffer and deflate state if compressing */
if (!state->direct) { if (!state->direct)
{
/* allocate output buffer */ /* allocate output buffer */
state->out = malloc(state->want); state->out = malloc(state->want);
if (state->out == NULL) {
if (state->out == NULL)
{
free(state->in); free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
@@ -45,7 +50,9 @@ local int gz_init(state)
strm->opaque = Z_NULL; strm->opaque = Z_NULL;
ret = deflateInit2(strm, state->level, Z_DEFLATED, ret = deflateInit2(strm, state->level, Z_DEFLATED,
MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy); MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
if (ret != Z_OK) {
if (ret != Z_OK)
{
free(state->out); free(state->out);
free(state->in); free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
@@ -57,11 +64,13 @@ local int gz_init(state)
state->size = state->want; state->size = state->want;
/* initialize write buffer if compressing */ /* initialize write buffer if compressing */
if (!state->direct) { if (!state->direct)
{
strm->avail_out = state->size; strm->avail_out = state->size;
strm->next_out = state->out; strm->next_out = state->out;
state->x.next = strm->next_out; state->x.next = strm->next_out;
} }
return 0; return 0;
} }
@@ -88,46 +97,62 @@ local int gz_comp(state, flush)
return -1; return -1;
/* write directly if requested */ /* write directly if requested */
if (state->direct) { if (state->direct)
{
got = write(state->fd, strm->next_in, strm->avail_in); got = write(state->fd, strm->next_in, strm->avail_in);
if (got < 0 || (unsigned)got != strm->avail_in) {
if (got < 0 || (unsigned)got != strm->avail_in)
{
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
return -1; return -1;
} }
strm->avail_in = 0; strm->avail_in = 0;
return 0; return 0;
} }
/* run deflate() on provided input until it produces no more output */ /* run deflate() on provided input until it produces no more output */
ret = Z_OK; ret = Z_OK;
do {
do
{
/* write out current buffer contents if full, or if flushing, but if /* write out current buffer contents if full, or if flushing, but if
doing Z_FINISH then don't write until we get to Z_STREAM_END */ doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) { (flush != Z_FINISH || ret == Z_STREAM_END)))
{
have = (unsigned)(strm->next_out - state->x.next); have = (unsigned)(strm->next_out - state->x.next);
if (have && ((got = write(state->fd, state->x.next, have)) < 0 || if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
(unsigned)got != have)) { (unsigned)got != have))
{
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
return -1; return -1;
} }
if (strm->avail_out == 0) {
if (strm->avail_out == 0)
{
strm->avail_out = state->size; strm->avail_out = state->size;
strm->next_out = state->out; strm->next_out = state->out;
} }
state->x.next = strm->next_out; state->x.next = strm->next_out;
} }
/* compress */ /* compress */
have = strm->avail_out; have = strm->avail_out;
ret = deflate(strm, flush); ret = deflate(strm, flush);
if (ret == Z_STREAM_ERROR) {
if (ret == Z_STREAM_ERROR)
{
gz_error(state, Z_STREAM_ERROR, gz_error(state, Z_STREAM_ERROR,
"internal error: deflate stream corrupt"); "internal error: deflate stream corrupt");
return -1; return -1;
} }
have -= strm->avail_out; have -= strm->avail_out;
} while (have); }
while (have);
/* if that completed a deflate stream, allow another to start */ /* if that completed a deflate stream, allow another to start */
if (flush == Z_FINISH) if (flush == Z_FINISH)
@@ -156,20 +181,28 @@ local int gz_zero(state, len)
/* compress len zeros (len guaranteed > 0) */ /* compress len zeros (len guaranteed > 0) */
first = 1; first = 1;
while (len) {
while (len)
{
n = GT_OFF(state->size) || (z_off64_t)state->size > len ? n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
(unsigned)len : state->size; (unsigned)len : state->size;
if (first) {
if (first)
{
memset(state->in, 0, n); memset(state->in, 0, n);
first = 0; first = 0;
} }
strm->avail_in = n; strm->avail_in = n;
strm->next_in = state->in; strm->next_in = state->in;
state->x.pos += n; state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (gz_comp(state, Z_NO_FLUSH) == -1)
return -1; return -1;
len -= n; len -= n;
} }
return 0; return 0;
} }
@@ -191,6 +224,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return 0; return 0;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
@@ -200,7 +234,8 @@ int ZEXPORT gzwrite(file, buf, len)
/* since an int is returned, make sure len fits in one, otherwise return /* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */ with an error (this avoids the flaw in the interface) */
if ((int)len < 0) { if ((int)len < 0)
{
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0; return 0;
} }
@@ -214,31 +249,41 @@ int ZEXPORT gzwrite(file, buf, len)
return 0; return 0;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return 0; return 0;
} }
/* for small len, copy to input buffer, otherwise compress directly */ /* for small len, copy to input buffer, otherwise compress directly */
if (len < state->size) { if (len < state->size)
{
/* copy to input buffer, compress when full */ /* copy to input buffer, compress when full */
do { do
{
if (strm->avail_in == 0) if (strm->avail_in == 0)
strm->next_in = state->in; strm->next_in = state->in;
n = state->size - strm->avail_in; n = state->size - strm->avail_in;
if (n > len) if (n > len)
n = len; n = len;
memcpy(strm->next_in + strm->avail_in, buf, n); memcpy(strm->next_in + strm->avail_in, buf, n);
strm->avail_in += n; strm->avail_in += n;
state->x.pos += n; state->x.pos += n;
buf = (char*)buf + n; buf = (char*)buf + n;
len -= n; len -= n;
if (len && gz_comp(state, Z_NO_FLUSH) == -1) if (len && gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
} while (len);
} }
else { while (len);
}
else
{
/* consume whatever's left in the input buffer */ /* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
@@ -247,6 +292,7 @@ int ZEXPORT gzwrite(file, buf, len)
strm->avail_in = len; strm->avail_in = len;
strm->next_in = (voidp)buf; strm->next_in = (voidp)buf;
state->x.pos += len; state->x.pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
} }
@@ -271,6 +317,7 @@ int ZEXPORT gzputc(file, c)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
@@ -279,17 +326,21 @@ int ZEXPORT gzputc(file, c)
return -1; return -1;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return -1; return -1;
} }
/* try writing to input buffer for speed (state->size == 0 if buffer not /* try writing to input buffer for speed (state->size == 0 if buffer not
initialized) */ initialized) */
if (strm->avail_in < state->size) { if (strm->avail_in < state->size)
{
if (strm->avail_in == 0) if (strm->avail_in == 0)
strm->next_in = state->in; strm->next_in = state->in;
strm->next_in[strm->avail_in++] = c; strm->next_in[strm->avail_in++] = c;
state->x.pos++; state->x.pos++;
return c & 0xff; return c & 0xff;
@@ -297,8 +348,10 @@ int ZEXPORT gzputc(file, c)
/* no room in buffer or not initialized, use gz_write() */ /* no room in buffer or not initialized, use gz_write() */
buf[0] = c; buf[0] = c;
if (gzwrite(file, buf, 1) != 1) if (gzwrite(file, buf, 1) != 1)
return -1; return -1;
return c & 0xff; return c & 0xff;
} }
@@ -334,6 +387,7 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
@@ -346,8 +400,10 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
return 0; return 0;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return 0; return 0;
} }
@@ -364,8 +420,10 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
# ifdef HAS_vsprintf_void # ifdef HAS_vsprintf_void
(void)vsprintf((char*)(state->in), format, va); (void)vsprintf((char*)(state->in), format, va);
va_end(va); va_end(va);
for (len = 0; len < size; len++) for (len = 0; len < size; len++)
if (state->in[len] == 0) break; if (state->in[len] == 0) break;
# else # else
len = vsprintf((char*)(state->in), format, va); len = vsprintf((char*)(state->in), format, va);
va_end(va); va_end(va);
@@ -409,6 +467,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
@@ -425,8 +484,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
return 0; return 0;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return 0; return 0;
} }
@@ -442,8 +503,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
# ifdef HAS_sprintf_void # ifdef HAS_sprintf_void
sprintf((char*)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, sprintf((char*)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
for (len = 0; len < size; len++) for (len = 0; len < size; len++)
if (state->in[len] == 0) break; if (state->in[len] == 0) break;
# else # else
len = sprintf((char*)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, len = sprintf((char*)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
@@ -487,6 +550,7 @@ int ZEXPORT gzflush(file, flush)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
@@ -498,8 +562,10 @@ int ZEXPORT gzflush(file, flush)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return -1; return -1;
} }
@@ -525,6 +591,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
@@ -537,19 +604,24 @@ int ZEXPORT gzsetparams(file, level, strategy)
return Z_OK; return Z_OK;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return -1; return -1;
} }
/* change compression parameters for subsequent input */ /* change compression parameters for subsequent input */
if (state->size) { if (state->size)
{
/* flush previous input with previous parameters before changing */ /* flush previous input with previous parameters before changing */
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
return state->err; return state->err;
deflateParams(strm, level, strategy); deflateParams(strm, level, strategy);
} }
state->level = level; state->level = level;
state->strategy = strategy; state->strategy = strategy;
return Z_OK; return Z_OK;
@@ -569,6 +641,7 @@ int ZEXPORT gzclose_w(file)
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're writing */ /* check that we're writing */
@@ -576,26 +649,35 @@ int ZEXPORT gzclose_w(file)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek)
{
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
ret = state->err; ret = state->err;
} }
/* flush, free memory, and close file */ /* flush, free memory, and close file */
if (state->size) { if (state->size)
{
if (gz_comp(state, Z_FINISH) == -1) if (gz_comp(state, Z_FINISH) == -1)
ret = state->err; ret = state->err;
if (!state->direct) {
if (!state->direct)
{
(void)deflateEnd(&(state->strm)); (void)deflateEnd(&(state->strm));
free(state->out); free(state->out);
} }
free(state->in); free(state->in);
} }
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
free(state->path); free(state->path);
if (close(state->fd) == -1) if (close(state->fd) == -1)
ret = Z_ERRNO; ret = Z_ERRNO;
free(state); free(state);
return ret; return ret;
} }

211
extern/zlib/infback.c vendored
View File

@@ -58,11 +58,15 @@ int stream_size;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != (int)(sizeof(z_stream))) stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR; return Z_VERSION_ERROR;
if (strm == Z_NULL || window == Z_NULL || if (strm == Z_NULL || window == Z_NULL ||
windowBits < 8 || windowBits > 15) windowBits < 8 || windowBits > 15)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */ strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
if (strm->zalloc == (alloc_func)0)
{
#ifdef Z_SOLO #ifdef Z_SOLO
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
#else #else
@@ -70,15 +74,19 @@ int stream_size;
strm->opaque = (voidpf)0; strm->opaque = (voidpf)0;
#endif #endif
} }
if (strm->zfree == (free_func)0) if (strm->zfree == (free_func)0)
#ifdef Z_SOLO #ifdef Z_SOLO
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
#else #else
strm->zfree = zcfree; strm->zfree = zcfree;
#endif #endif
state = (struct inflate_state FAR*)ZALLOC(strm, 1, state = (struct inflate_state FAR*)ZALLOC(strm, 1,
sizeof(struct inflate_state)); sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR; if (state == Z_NULL) return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n")); Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR*)state; strm->state = (struct internal_state FAR*)state;
state->dmax = 32768U; state->dmax = 32768U;
@@ -113,16 +121,22 @@ struct inflate_state FAR *state;
static code fixed[544]; static code fixed[544];
/* build fixed huffman tables if first call (may not be thread safe) */ /* build fixed huffman tables if first call (may not be thread safe) */
if (virgin) { if (virgin)
{
unsigned sym, bits; unsigned sym, bits;
static code* next; static code* next;
/* literal/length table */ /* literal/length table */
sym = 0; sym = 0;
while (sym < 144) state->lens[sym++] = 8; while (sym < 144) state->lens[sym++] = 8;
while (sym < 256) state->lens[sym++] = 9; while (sym < 256) state->lens[sym++] = 9;
while (sym < 280) state->lens[sym++] = 7; while (sym < 280) state->lens[sym++] = 7;
while (sym < 288) state->lens[sym++] = 8; while (sym < 288) state->lens[sym++] = 8;
next = fixed; next = fixed;
lenfix = next; lenfix = next;
bits = 9; bits = 9;
@@ -130,7 +144,9 @@ struct inflate_state FAR *state;
/* distance table */ /* distance table */
sym = 0; sym = 0;
while (sym < 32) state->lens[sym++] = 5; while (sym < 32) state->lens[sym++] = 5;
distfix = next; distfix = next;
bits = 5; bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
@@ -138,6 +154,7 @@ struct inflate_state FAR *state;
/* do this just once */ /* do this just once */
virgin = 0; virgin = 0;
} }
#else /* !BUILDFIXED */ #else /* !BUILDFIXED */
# include "inffixed.h" # include "inffixed.h"
#endif /* BUILDFIXED */ #endif /* BUILDFIXED */
@@ -301,6 +318,7 @@ void FAR *out_desc;
/* Check that the strm exists and that the state was initialized */ /* Check that the strm exists and that the state was initialized */
if (strm == Z_NULL || strm->state == Z_NULL) if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (struct inflate_state FAR*)strm->state; state = (struct inflate_state FAR*)strm->state;
/* Reset the state */ /* Reset the state */
@@ -317,38 +335,48 @@ void FAR *out_desc;
/* Inflate until end of block marked as last */ /* Inflate until end of block marked as last */
for (;;) for (;;)
switch (state->mode) { switch (state->mode)
{
case TYPE: case TYPE:
/* determine and dispatch block type */ /* determine and dispatch block type */
if (state->last) { if (state->last)
{
BYTEBITS(); BYTEBITS();
state->mode = DONE; state->mode = DONE;
break; break;
} }
NEEDBITS(3); NEEDBITS(3);
state->last = BITS(1); state->last = BITS(1);
DROPBITS(1); DROPBITS(1);
switch (BITS(2)) {
switch (BITS(2))
{
case 0: /* stored block */ case 0: /* stored block */
Tracev((stderr, "inflate: stored block%s\n", Tracev((stderr, "inflate: stored block%s\n",
state->last ? " (last)" : "")); state->last ? " (last)" : ""));
state->mode = STORED; state->mode = STORED;
break; break;
case 1: /* fixed block */ case 1: /* fixed block */
fixedtables(state); fixedtables(state);
Tracev((stderr, "inflate: fixed codes block%s\n", Tracev((stderr, "inflate: fixed codes block%s\n",
state->last ? " (last)" : "")); state->last ? " (last)" : ""));
state->mode = LEN; /* decode codes */ state->mode = LEN; /* decode codes */
break; break;
case 2: /* dynamic block */ case 2: /* dynamic block */
Tracev((stderr, "inflate: dynamic codes block%s\n", Tracev((stderr, "inflate: dynamic codes block%s\n",
state->last ? " (last)" : "")); state->last ? " (last)" : ""));
state->mode = TABLE; state->mode = TABLE;
break; break;
case 3: case 3:
strm->msg = (char*)"invalid block type"; strm->msg = (char*)"invalid block type";
state->mode = BAD; state->mode = BAD;
} }
DROPBITS(2); DROPBITS(2);
break; break;
@@ -356,23 +384,30 @@ void FAR *out_desc;
/* get and verify stored block length */ /* get and verify stored block length */
BYTEBITS(); /* go to byte boundary */ BYTEBITS(); /* go to byte boundary */
NEEDBITS(32); NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff))
{
strm->msg = (char*)"invalid stored block lengths"; strm->msg = (char*)"invalid stored block lengths";
state->mode = BAD; state->mode = BAD;
break; break;
} }
state->length = (unsigned)hold & 0xffff; state->length = (unsigned)hold & 0xffff;
Tracev((stderr, "inflate: stored length %u\n", Tracev((stderr, "inflate: stored length %u\n",
state->length)); state->length));
INITBITS(); INITBITS();
/* copy stored block from input to output */ /* copy stored block from input to output */
while (state->length != 0) { while (state->length != 0)
{
copy = state->length; copy = state->length;
PULL(); PULL();
ROOM(); ROOM();
if (copy > have) copy = have; if (copy > have) copy = have;
if (copy > left) copy = left; if (copy > left) copy = left;
zmemcpy(put, next, copy); zmemcpy(put, next, copy);
have -= copy; have -= copy;
next += copy; next += copy;
@@ -380,6 +415,7 @@ void FAR *out_desc;
put += copy; put += copy;
state->length -= copy; state->length -= copy;
} }
Tracev((stderr, "inflate: stored end\n")); Tracev((stderr, "inflate: stored end\n"));
state->mode = TYPE; state->mode = TYPE;
break; break;
@@ -394,79 +430,106 @@ void FAR *out_desc;
state->ncode = BITS(4) + 4; state->ncode = BITS(4) + 4;
DROPBITS(4); DROPBITS(4);
#ifndef PKZIP_BUG_WORKAROUND #ifndef PKZIP_BUG_WORKAROUND
if (state->nlen > 286 || state->ndist > 30) {
if (state->nlen > 286 || state->ndist > 30)
{
strm->msg = (char*)"too many length or distance symbols"; strm->msg = (char*)"too many length or distance symbols";
state->mode = BAD; state->mode = BAD;
break; break;
} }
#endif #endif
Tracev((stderr, "inflate: table sizes ok\n")); Tracev((stderr, "inflate: table sizes ok\n"));
/* get code length code lengths (not a typo) */ /* get code length code lengths (not a typo) */
state->have = 0; state->have = 0;
while (state->have < state->ncode) {
while (state->have < state->ncode)
{
NEEDBITS(3); NEEDBITS(3);
state->lens[order[state->have++]] = (unsigned short)BITS(3); state->lens[order[state->have++]] = (unsigned short)BITS(3);
DROPBITS(3); DROPBITS(3);
} }
while (state->have < 19) while (state->have < 19)
state->lens[order[state->have++]] = 0; state->lens[order[state->have++]] = 0;
state->next = state->codes; state->next = state->codes;
state->lencode = (code const FAR*)(state->next); state->lencode = (code const FAR*)(state->next);
state->lenbits = 7; state->lenbits = 7;
ret = inflate_table(CODES, state->lens, 19, &(state->next), ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
if (ret) {
if (ret)
{
strm->msg = (char*)"invalid code lengths set"; strm->msg = (char*)"invalid code lengths set";
state->mode = BAD; state->mode = BAD;
break; break;
} }
Tracev((stderr, "inflate: code lengths ok\n")); Tracev((stderr, "inflate: code lengths ok\n"));
/* get length and distance code code lengths */ /* get length and distance code code lengths */
state->have = 0; state->have = 0;
while (state->have < state->nlen + state->ndist) {
for (;;) { while (state->have < state->nlen + state->ndist)
{
for (;;)
{
here = state->lencode[BITS(state->lenbits)]; here = state->lencode[BITS(state->lenbits)];
if ((unsigned)(here.bits) <= bits) break; if ((unsigned)(here.bits) <= bits) break;
PULLBYTE(); PULLBYTE();
} }
if (here.val < 16) {
if (here.val < 16)
{
DROPBITS(here.bits); DROPBITS(here.bits);
state->lens[state->have++] = here.val; state->lens[state->have++] = here.val;
} }
else { else
if (here.val == 16) { {
if (here.val == 16)
{
NEEDBITS(here.bits + 2); NEEDBITS(here.bits + 2);
DROPBITS(here.bits); DROPBITS(here.bits);
if (state->have == 0) {
if (state->have == 0)
{
strm->msg = (char*)"invalid bit length repeat"; strm->msg = (char*)"invalid bit length repeat";
state->mode = BAD; state->mode = BAD;
break; break;
} }
len = (unsigned)(state->lens[state->have - 1]); len = (unsigned)(state->lens[state->have - 1]);
copy = 3 + BITS(2); copy = 3 + BITS(2);
DROPBITS(2); DROPBITS(2);
} }
else if (here.val == 17) { else if (here.val == 17)
{
NEEDBITS(here.bits + 3); NEEDBITS(here.bits + 3);
DROPBITS(here.bits); DROPBITS(here.bits);
len = 0; len = 0;
copy = 3 + BITS(3); copy = 3 + BITS(3);
DROPBITS(3); DROPBITS(3);
} }
else { else
{
NEEDBITS(here.bits + 7); NEEDBITS(here.bits + 7);
DROPBITS(here.bits); DROPBITS(here.bits);
len = 0; len = 0;
copy = 11 + BITS(7); copy = 11 + BITS(7);
DROPBITS(7); DROPBITS(7);
} }
if (state->have + copy > state->nlen + state->ndist) {
if (state->have + copy > state->nlen + state->ndist)
{
strm->msg = (char*)"invalid bit length repeat"; strm->msg = (char*)"invalid bit length repeat";
state->mode = BAD; state->mode = BAD;
break; break;
} }
while (copy--) while (copy--)
state->lens[state->have++] = (unsigned short)len; state->lens[state->have++] = (unsigned short)len;
} }
@@ -476,7 +539,8 @@ void FAR *out_desc;
if (state->mode == BAD) break; if (state->mode == BAD) break;
/* check for end-of-block code (better have one) */ /* check for end-of-block code (better have one) */
if (state->lens[256] == 0) { if (state->lens[256] == 0)
{
strm->msg = (char*)"invalid code -- missing end-of-block"; strm->msg = (char*)"invalid code -- missing end-of-block";
state->mode = BAD; state->mode = BAD;
break; break;
@@ -490,55 +554,77 @@ void FAR *out_desc;
state->lenbits = 9; state->lenbits = 9;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
if (ret) {
if (ret)
{
strm->msg = (char*)"invalid literal/lengths set"; strm->msg = (char*)"invalid literal/lengths set";
state->mode = BAD; state->mode = BAD;
break; break;
} }
state->distcode = (code const FAR*)(state->next); state->distcode = (code const FAR*)(state->next);
state->distbits = 6; state->distbits = 6;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work); &(state->next), &(state->distbits), state->work);
if (ret) {
if (ret)
{
strm->msg = (char*)"invalid distances set"; strm->msg = (char*)"invalid distances set";
state->mode = BAD; state->mode = BAD;
break; break;
} }
Tracev((stderr, "inflate: codes ok\n")); Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN; state->mode = LEN;
case LEN: case LEN:
/* use inflate_fast() if we have enough input and output */ /* use inflate_fast() if we have enough input and output */
if (have >= 6 && left >= 258) { if (have >= 6 && left >= 258)
{
RESTORE(); RESTORE();
if (state->whave < state->wsize) if (state->whave < state->wsize)
state->whave = state->wsize - left; state->whave = state->wsize - left;
inflate_fast(strm, state->wsize); inflate_fast(strm, state->wsize);
LOAD(); LOAD();
break; break;
} }
/* get a literal, length, or end-of-block code */ /* get a literal, length, or end-of-block code */
for (;;) { for (;;)
{
here = state->lencode[BITS(state->lenbits)]; here = state->lencode[BITS(state->lenbits)];
if ((unsigned)(here.bits) <= bits) break; if ((unsigned)(here.bits) <= bits) break;
PULLBYTE(); PULLBYTE();
} }
if (here.op && (here.op & 0xf0) == 0) {
if (here.op && (here.op & 0xf0) == 0)
{
last = here; last = here;
for (;;) {
for (;;)
{
here = state->lencode[last.val + here = state->lencode[last.val +
(BITS(last.bits + last.op) >> last.bits)]; (BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)(last.bits + here.bits) <= bits) break; if ((unsigned)(last.bits + here.bits) <= bits) break;
PULLBYTE(); PULLBYTE();
} }
DROPBITS(last.bits); DROPBITS(last.bits);
} }
DROPBITS(here.bits); DROPBITS(here.bits);
state->length = (unsigned)here.val; state->length = (unsigned)here.val;
/* process literal */ /* process literal */
if (here.op == 0) { if (here.op == 0)
{
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val)); "inflate: literal 0x%02x\n", here.val));
@@ -550,14 +636,16 @@ void FAR *out_desc;
} }
/* process end of block */ /* process end of block */
if (here.op & 32) { if (here.op & 32)
{
Tracevv((stderr, "inflate: end of block\n")); Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE; state->mode = TYPE;
break; break;
} }
/* invalid code */ /* invalid code */
if (here.op & 64) { if (here.op & 64)
{
strm->msg = (char*)"invalid literal/length code"; strm->msg = (char*)"invalid literal/length code";
state->mode = BAD; state->mode = BAD;
break; break;
@@ -565,80 +653,116 @@ void FAR *out_desc;
/* length code -- get extra bits, if any */ /* length code -- get extra bits, if any */
state->extra = (unsigned)(here.op) & 15; state->extra = (unsigned)(here.op) & 15;
if (state->extra != 0) {
if (state->extra != 0)
{
NEEDBITS(state->extra); NEEDBITS(state->extra);
state->length += BITS(state->extra); state->length += BITS(state->extra);
DROPBITS(state->extra); DROPBITS(state->extra);
} }
Tracevv((stderr, "inflate: length %u\n", state->length)); Tracevv((stderr, "inflate: length %u\n", state->length));
/* get distance code */ /* get distance code */
for (;;) { for (;;)
{
here = state->distcode[BITS(state->distbits)]; here = state->distcode[BITS(state->distbits)];
if ((unsigned)(here.bits) <= bits) break; if ((unsigned)(here.bits) <= bits) break;
PULLBYTE(); PULLBYTE();
} }
if ((here.op & 0xf0) == 0) {
if ((here.op & 0xf0) == 0)
{
last = here; last = here;
for (;;) {
for (;;)
{
here = state->distcode[last.val + here = state->distcode[last.val +
(BITS(last.bits + last.op) >> last.bits)]; (BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)(last.bits + here.bits) <= bits) break; if ((unsigned)(last.bits + here.bits) <= bits) break;
PULLBYTE(); PULLBYTE();
} }
DROPBITS(last.bits); DROPBITS(last.bits);
} }
DROPBITS(here.bits); DROPBITS(here.bits);
if (here.op & 64) {
if (here.op & 64)
{
strm->msg = (char*)"invalid distance code"; strm->msg = (char*)"invalid distance code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
state->offset = (unsigned)here.val; state->offset = (unsigned)here.val;
/* get distance extra bits, if any */ /* get distance extra bits, if any */
state->extra = (unsigned)(here.op) & 15; state->extra = (unsigned)(here.op) & 15;
if (state->extra != 0) {
if (state->extra != 0)
{
NEEDBITS(state->extra); NEEDBITS(state->extra);
state->offset += BITS(state->extra); state->offset += BITS(state->extra);
DROPBITS(state->extra); DROPBITS(state->extra);
} }
if (state->offset > state->wsize - (state->whave < state->wsize ? if (state->offset > state->wsize - (state->whave < state->wsize ?
left : 0)) { left : 0))
{
strm->msg = (char*)"invalid distance too far back"; strm->msg = (char*)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
Tracevv((stderr, "inflate: distance %u\n", state->offset)); Tracevv((stderr, "inflate: distance %u\n", state->offset));
/* copy match from window to output */ /* copy match from window to output */
do { do
{
ROOM(); ROOM();
copy = state->wsize - state->offset; copy = state->wsize - state->offset;
if (copy < left) {
if (copy < left)
{
from = put + copy; from = put + copy;
copy = left - copy; copy = left - copy;
} }
else { else
{
from = put - state->offset; from = put - state->offset;
copy = left; copy = left;
} }
if (copy > state->length) copy = state->length; if (copy > state->length) copy = state->length;
state->length -= copy; state->length -= copy;
left -= copy; left -= copy;
do {
do
{
*put++ = *from++; *put++ = *from++;
} while (--copy); }
} while (state->length != 0); while (--copy);
}
while (state->length != 0);
break; break;
case DONE: case DONE:
/* inflate stream terminated properly -- write leftover output */ /* inflate stream terminated properly -- write leftover output */
ret = Z_STREAM_END; ret = Z_STREAM_END;
if (left < state->wsize) {
if (left < state->wsize)
{
if (out(out_desc, state->window, state->wsize - left)) if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR; ret = Z_BUF_ERROR;
} }
goto inf_leave; goto inf_leave;
case BAD: case BAD:
@@ -666,6 +790,7 @@ z_streamp strm;
{ {
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
ZFREE(strm, strm->state); ZFREE(strm, strm->state);
strm->state = Z_NULL; strm->state = Z_NULL;
Tracev((stderr, "inflate: end\n")); Tracev((stderr, "inflate: end\n"));

191
extern/zlib/inffast.c vendored
View File

@@ -121,194 +121,287 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
/* decode literals and length/distances until end-of-block or not enough /* decode literals and length/distances until end-of-block or not enough
input data or output space */ input data or output space */
do { do
if (bits < 15) { {
if (bits < 15)
{
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
here = lcode[hold & lmask]; here = lcode[hold & lmask];
dolen: dolen:
op = (unsigned)(here.bits); op = (unsigned)(here.bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here.op);
if (op == 0) { /* literal */
if (op == 0) /* literal */
{
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val)); "inflate: literal 0x%02x\n", here.val));
PUP(out) = (unsigned char)(here.val); PUP(out) = (unsigned char)(here.val);
} }
else if (op & 16) { /* length base */ else if (op & 16) /* length base */
{
len = (unsigned)(here.val); len = (unsigned)(here.val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) {
if (bits < op) { if (op)
{
if (bits < op)
{
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
len += (unsigned)hold & ((1U << op) - 1); len += (unsigned)hold & ((1U << op) - 1);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
} }
Tracevv((stderr, "inflate: length %u\n", len)); Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) {
if (bits < 15)
{
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
here = dcode[hold & dmask]; here = dcode[hold & dmask];
dodist: dodist:
op = (unsigned)(here.bits); op = (unsigned)(here.bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here.op);
if (op & 16) { /* distance base */
if (op & 16) /* distance base */
{
dist = (unsigned)(here.val); dist = (unsigned)(here.val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (bits < op) {
if (bits < op)
{
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
if (bits < op) {
if (bits < op)
{
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
} }
dist += (unsigned)hold & ((1U << op) - 1); dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
if (dist > dmax) {
if (dist > dmax)
{
strm->msg = (char*)"invalid distance too far back"; strm->msg = (char*)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
#endif #endif
hold >>= op; hold >>= op;
bits -= op; bits -= op;
Tracevv((stderr, "inflate: distance %u\n", dist)); Tracevv((stderr, "inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */ op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */
if (dist > op) /* see if copy from window */
{
op = dist - op; /* distance back in window */ op = dist - op; /* distance back in window */
if (op > whave) {
if (state->sane) { if (op > whave)
{
if (state->sane)
{
strm->msg = strm->msg =
(char*)"invalid distance too far back"; (char*)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
if (len <= op - whave) {
do { if (len <= op - whave)
{
do
{
PUP(out) = 0; PUP(out) = 0;
} while (--len); }
while (--len);
continue; continue;
} }
len -= op - whave; len -= op - whave;
do {
do
{
PUP(out) = 0; PUP(out) = 0;
} while (--op > whave); }
if (op == 0) { while (--op > whave);
if (op == 0)
{
from = out - dist; from = out - dist;
do {
do
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--len); }
while (--len);
continue; continue;
} }
#endif #endif
} }
from = window - OFF; from = window - OFF;
if (wnext == 0) { /* very common case */
if (wnext == 0) /* very common case */
{
from += wsize - op; from += wsize - op;
if (op < len) { /* some from window */
if (op < len) /* some from window */
{
len -= op; len -= op;
do {
do
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); }
while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
else if (wnext < op) { /* wrap around window */ else if (wnext < op) /* wrap around window */
{
from += wsize + wnext - op; from += wsize + wnext - op;
op -= wnext; op -= wnext;
if (op < len) { /* some from end of window */
if (op < len) /* some from end of window */
{
len -= op; len -= op;
do {
do
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); }
while (--op);
from = window - OFF; from = window - OFF;
if (wnext < len) { /* some from start of window */
if (wnext < len) /* some from start of window */
{
op = wnext; op = wnext;
len -= op; len -= op;
do {
do
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); }
while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
} }
else { /* contiguous in window */ else /* contiguous in window */
{
from += wnext - op; from += wnext - op;
if (op < len) { /* some from window */
if (op < len) /* some from window */
{
len -= op; len -= op;
do {
do
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); }
while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
while (len > 2) {
while (len > 2)
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
len -= 3; len -= 3;
} }
if (len) {
if (len)
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
if (len > 1) if (len > 1)
PUP(out) = PUP(from); PUP(out) = PUP(from);
} }
} }
else { else
{
from = out - dist; /* copy direct from output */ from = out - dist; /* copy direct from output */
do { /* minimum length is three */
do /* minimum length is three */
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
len -= 3; len -= 3;
} while (len > 2); }
if (len) { while (len > 2);
if (len)
{
PUP(out) = PUP(from); PUP(out) = PUP(from);
if (len > 1) if (len > 1)
PUP(out) = PUP(from); PUP(out) = PUP(from);
} }
} }
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else if ((op & 64) == 0) /* 2nd level distance code */
{
here = dcode[here.val + (hold & ((1U << op) - 1))]; here = dcode[here.val + (hold & ((1U << op) - 1))];
goto dodist; goto dodist;
} }
else { else
{
strm->msg = (char*)"invalid distance code"; strm->msg = (char*)"invalid distance code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} }
else if ((op & 64) == 0) { /* 2nd level length code */ else if ((op & 64) == 0) /* 2nd level length code */
{
here = lcode[here.val + (hold & ((1U << op) - 1))]; here = lcode[here.val + (hold & ((1U << op) - 1))];
goto dolen; goto dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) /* end-of-block */
{
Tracevv((stderr, "inflate: end of block\n")); Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE; state->mode = TYPE;
break; break;
} }
else { else
{
strm->msg = (char*)"invalid literal/length code"; strm->msg = (char*)"invalid literal/length code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} while (in < last && out < end); }
while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3; len = bits >> 3;

View File

@@ -7,7 +7,8 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
static const code lenfix[512] = { static const code lenfix[512] =
{
{96, 7, 0}, {0, 8, 80}, {0, 8, 16}, {20, 8, 115}, {18, 7, 31}, {0, 8, 112}, {0, 8, 48}, {96, 7, 0}, {0, 8, 80}, {0, 8, 16}, {20, 8, 115}, {18, 7, 31}, {0, 8, 112}, {0, 8, 48},
{0, 9, 192}, {16, 7, 10}, {0, 8, 96}, {0, 8, 32}, {0, 9, 160}, {0, 8, 0}, {0, 8, 128}, {0, 9, 192}, {16, 7, 10}, {0, 8, 96}, {0, 8, 32}, {0, 9, 160}, {0, 8, 0}, {0, 8, 128},
{0, 8, 64}, {0, 9, 224}, {16, 7, 6}, {0, 8, 88}, {0, 8, 24}, {0, 9, 144}, {19, 7, 59}, {0, 8, 64}, {0, 9, 224}, {16, 7, 6}, {0, 8, 88}, {0, 8, 24}, {0, 9, 144}, {19, 7, 59},
@@ -84,7 +85,8 @@
{0, 9, 255} {0, 9, 255}
}; };
static const code distfix[32] = { static const code distfix[32] =
{
{16, 5, 1}, {23, 5, 257}, {19, 5, 17}, {27, 5, 4097}, {17, 5, 5}, {25, 5, 1025}, {16, 5, 1}, {23, 5, 257}, {19, 5, 17}, {27, 5, 4097}, {17, 5, 5}, {25, 5, 1025},
{21, 5, 65}, {29, 5, 16385}, {16, 5, 3}, {24, 5, 513}, {20, 5, 33}, {28, 5, 8193}, {21, 5, 65}, {29, 5, 16385}, {16, 5, 3}, {24, 5, 513}, {20, 5, 33}, {28, 5, 8193},
{18, 5, 9}, {26, 5, 2049}, {22, 5, 129}, {64, 5, 0}, {16, 5, 2}, {23, 5, 385}, {18, 5, 9}, {26, 5, 2049}, {22, 5, 129}, {64, 5, 0}, {16, 5, 2}, {23, 5, 385},

474
extern/zlib/inflate.c vendored

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,8 @@
#endif #endif
/* Possible inflate modes between inflate() calls */ /* Possible inflate modes between inflate() calls */
typedef enum { typedef enum
{
HEAD, /* i: waiting for magic header */ HEAD, /* i: waiting for magic header */
FLAGS, /* i: waiting for method and flags (gzip) */ FLAGS, /* i: waiting for method and flags (gzip) */
TIME, /* i: waiting for modification time (gzip) */ TIME, /* i: waiting for modification time (gzip) */
@@ -78,7 +79,8 @@ typedef enum {
*/ */
/* state maintained between inflate() calls. Approximately 10K bytes. */ /* state maintained between inflate() calls. Approximately 10K bytes. */
struct inflate_state { struct inflate_state
{
inflate_mode mode; /* current inflate mode */ inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */ int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */

View File

@@ -74,20 +74,28 @@ unsigned short FAR *work;
int end; /* use base and extra for symbol > end */ int end; /* use base and extra for symbol > end */
unsigned short count[MAXBITS + 1]; /* number of codes of each length */ unsigned short count[MAXBITS + 1]; /* number of codes of each length */
unsigned short offs[MAXBITS + 1]; /* offsets in table for each length */ unsigned short offs[MAXBITS + 1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ static const unsigned short lbase[31] = /* Length codes 257..285 base */
{
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ };
static const unsigned short lext[31] = /* Length codes 257..285 extra */
{
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ };
static const unsigned short dbase[32] = /* Distance codes 0..29 base */
{
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577, 0, 0}; 8193, 12289, 16385, 24577, 0, 0
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ };
static const unsigned short dext[32] = /* Distance codes 0..29 extra */
{
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
28, 28, 29, 29, 64, 64}; 28, 28, 29, 29, 64, 64
};
/* /*
Process a set of code lengths to create a canonical Huffman code. The Process a set of code lengths to create a canonical Huffman code. The
@@ -123,15 +131,20 @@ unsigned short FAR *work;
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
for (len = 0; len <= MAXBITS; len++) for (len = 0; len <= MAXBITS; len++)
count[len] = 0; count[len] = 0;
for (sym = 0; sym < codes; sym++) for (sym = 0; sym < codes; sym++)
count[lens[sym]]++; count[lens[sym]]++;
/* bound code lengths, force root to be within code lengths */ /* bound code lengths, force root to be within code lengths */
root = *bits; root = *bits;
for (max = MAXBITS; max >= 1; max--) for (max = MAXBITS; max >= 1; max--)
if (count[max] != 0) break; if (count[max] != 0) break;
if (root > max) root = max; if (root > max) root = max;
if (max == 0) { /* no symbols to code at all */
if (max == 0) /* no symbols to code at all */
{
here.op = (unsigned char)64; /* invalid code marker */ here.op = (unsigned char)64; /* invalid code marker */
here.bits = (unsigned char)1; here.bits = (unsigned char)1;
here.val = (unsigned short)0; here.val = (unsigned short)0;
@@ -140,22 +153,29 @@ unsigned short FAR *work;
*bits = 1; *bits = 1;
return 0; /* no symbols, but wait for decoding to report error */ return 0; /* no symbols, but wait for decoding to report error */
} }
for (min = 1; min < max; min++) for (min = 1; min < max; min++)
if (count[min] != 0) break; if (count[min] != 0) break;
if (root < min) root = min; if (root < min) root = min;
/* check for an over-subscribed or incomplete set of lengths */ /* check for an over-subscribed or incomplete set of lengths */
left = 1; left = 1;
for (len = 1; len <= MAXBITS; len++) {
for (len = 1; len <= MAXBITS; len++)
{
left <<= 1; left <<= 1;
left -= count[len]; left -= count[len];
if (left < 0) return -1; /* over-subscribed */ if (left < 0) return -1; /* over-subscribed */
} }
if (left > 0 && (type == CODES || max != 1)) if (left > 0 && (type == CODES || max != 1))
return -1; /* incomplete set */ return -1; /* incomplete set */
/* generate offsets into symbol table for each length for sorting */ /* generate offsets into symbol table for each length for sorting */
offs[1] = 0; offs[1] = 0;
for (len = 1; len < MAXBITS; len++) for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + count[len]; offs[len + 1] = offs[len] + count[len];
@@ -195,11 +215,13 @@ unsigned short FAR *work;
*/ */
/* set up for code type */ /* set up for code type */
switch (type) { switch (type)
{
case CODES: case CODES:
base = extra = work; /* dummy value--not used */ base = extra = work; /* dummy value--not used */
end = 19; end = 19;
break; break;
case LENS: case LENS:
base = lbase; base = lbase;
base -= 257; base -= 257;
@@ -207,6 +229,7 @@ unsigned short FAR *work;
extra -= 257; extra -= 257;
end = 256; end = 256;
break; break;
default: /* DISTS */ default: /* DISTS */
base = dbase; base = dbase;
extra = dext; extra = dext;
@@ -230,18 +253,23 @@ unsigned short FAR *work;
return 1; return 1;
/* process all codes and make table entries */ /* process all codes and make table entries */
for (;;) { for (;;)
{
/* create table entry */ /* create table entry */
here.bits = (unsigned char)(len - drop); here.bits = (unsigned char)(len - drop);
if ((int)(work[sym]) < end) {
if ((int)(work[sym]) < end)
{
here.op = (unsigned char)0; here.op = (unsigned char)0;
here.val = work[sym]; here.val = work[sym];
} }
else if ((int)(work[sym]) > end) { else if ((int)(work[sym]) > end)
{
here.op = (unsigned char)(extra[work[sym]]); here.op = (unsigned char)(extra[work[sym]]);
here.val = base[work[sym]]; here.val = base[work[sym]];
} }
else { else
{
here.op = (unsigned char)(32 + 64); /* end of block */ here.op = (unsigned char)(32 + 64); /* end of block */
here.val = 0; here.val = 0;
} }
@@ -250,16 +278,22 @@ unsigned short FAR *work;
incr = 1U << (len - drop); incr = 1U << (len - drop);
fill = 1U << curr; fill = 1U << curr;
min = fill; /* save offset to next table */ min = fill; /* save offset to next table */
do {
do
{
fill -= incr; fill -= incr;
next[(huff >> drop) + fill] = here; next[(huff >> drop) + fill] = here;
} while (fill != 0); }
while (fill != 0);
/* backwards increment the len-bit code huff */ /* backwards increment the len-bit code huff */
incr = 1U << (len - 1); incr = 1U << (len - 1);
while (huff & incr) while (huff & incr)
incr >>= 1; incr >>= 1;
if (incr != 0) {
if (incr != 0)
{
huff &= incr - 1; huff &= incr - 1;
huff += incr; huff += incr;
} }
@@ -268,13 +302,17 @@ unsigned short FAR *work;
/* go to next symbol, update count, len */ /* go to next symbol, update count, len */
sym++; sym++;
if (--(count[len]) == 0) {
if (--(count[len]) == 0)
{
if (len == max) break; if (len == max) break;
len = lens[work[sym]]; len = lens[work[sym]];
} }
/* create new sub-table if needed */ /* create new sub-table if needed */
if (len > root && (huff & mask) != low) { if (len > root && (huff & mask) != low)
{
/* if first time, transition to sub-tables */ /* if first time, transition to sub-tables */
if (drop == 0) if (drop == 0)
drop = root; drop = root;
@@ -285,15 +323,20 @@ unsigned short FAR *work;
/* determine length of next table */ /* determine length of next table */
curr = len - drop; curr = len - drop;
left = (int)(1 << curr); left = (int)(1 << curr);
while (curr + drop < max) {
while (curr + drop < max)
{
left -= count[curr + drop]; left -= count[curr + drop];
if (left <= 0) break; if (left <= 0) break;
curr++; curr++;
left <<= 1; left <<= 1;
} }
/* check for enough space */ /* check for enough space */
used += 1U << curr; used += 1U << curr;
if ((type == LENS && used >= ENOUGH_LENS) || if ((type == LENS && used >= ENOUGH_LENS) ||
(type == DISTS && used >= ENOUGH_DISTS)) (type == DISTS && used >= ENOUGH_DISTS))
return 1; return 1;
@@ -309,7 +352,8 @@ unsigned short FAR *work;
/* fill in remaining table entry if code is incomplete (guaranteed to have /* fill in remaining table entry if code is incomplete (guaranteed to have
at most one remaining entry, since if the code is incomplete, the at most one remaining entry, since if the code is incomplete, the
maximum code length that was allowed to get this far is one bit) */ maximum code length that was allowed to get this far is one bit) */
if (huff != 0) { if (huff != 0)
{
here.op = (unsigned char)64; /* invalid code marker */ here.op = (unsigned char)64; /* invalid code marker */
here.bits = (unsigned char)(len - drop); here.bits = (unsigned char)(len - drop);
here.val = (unsigned short)0; here.val = (unsigned short)0;

View File

@@ -21,7 +21,8 @@
of the bit buffer. val is the actual byte to output in the case of the bit buffer. val is the actual byte to output in the case
of a literal, the base length or distance, or the offset from of a literal, the base length or distance, or the offset from
the current table to the next table. Each entry is four bytes. */ the current table to the next table. Each entry is four bytes. */
typedef struct { typedef struct
{
unsigned char op; /* operation, extra bits, table bits */ unsigned char op; /* operation, extra bits, table bits */
unsigned char bits; /* bits in this part of the code */ unsigned char bits; /* bits in this part of the code */
unsigned short val; /* offset in table or code value */ unsigned short val; /* offset in table or code value */
@@ -51,7 +52,8 @@ typedef struct {
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
/* Type of code to build for inflate_table() */ /* Type of code to build for inflate_table() */
typedef enum { typedef enum
{
CODES, CODES,
LENS, LENS,
DISTS DISTS

View File

@@ -100,10 +100,13 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
err = uncompress(uncompr, &uncomprLen, compr, comprLen); err = uncompress(uncompr, &uncomprLen, compr, comprLen);
CHECK_ERR(err, "uncompress"); CHECK_ERR(err, "uncompress");
if (strcmp((char*)uncompr, hello)) { if (strcmp((char*)uncompr, hello))
{
fprintf(stderr, "bad uncompress\n"); fprintf(stderr, "bad uncompress\n");
exit(1); exit(1);
} else { }
else
{
printf("uncompress(): %s\n", (char*)uncompr); printf("uncompress(): %s\n", (char*)uncompr);
} }
} }
@@ -125,66 +128,92 @@ void test_gzio(fname, uncompr, uncomprLen)
z_off_t pos; z_off_t pos;
file = gzopen(fname, "wb"); file = gzopen(fname, "wb");
if (file == NULL) {
if (file == NULL)
{
fprintf(stderr, "gzopen error\n"); fprintf(stderr, "gzopen error\n");
exit(1); exit(1);
} }
gzputc(file, 'h'); gzputc(file, 'h');
if (gzputs(file, "ello") != 4) {
if (gzputs(file, "ello") != 4)
{
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
exit(1); exit(1);
} }
if (gzprintf(file, ", %s!", "hello") != 8) {
if (gzprintf(file, ", %s!", "hello") != 8)
{
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
exit(1); exit(1);
} }
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
gzclose(file); gzclose(file);
file = gzopen(fname, "rb"); file = gzopen(fname, "rb");
if (file == NULL) {
if (file == NULL)
{
fprintf(stderr, "gzopen error\n"); fprintf(stderr, "gzopen error\n");
exit(1); exit(1);
} }
strcpy((char*)uncompr, "garbage"); strcpy((char*)uncompr, "garbage");
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) { if (gzread(file, uncompr, (unsigned)uncomprLen) != len)
{
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
exit(1); exit(1);
} }
if (strcmp((char*)uncompr, hello)) {
if (strcmp((char*)uncompr, hello))
{
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
exit(1); exit(1);
} else { }
else
{
printf("gzread(): %s\n", (char*)uncompr); printf("gzread(): %s\n", (char*)uncompr);
} }
pos = gzseek(file, -8L, SEEK_CUR); pos = gzseek(file, -8L, SEEK_CUR);
if (pos != 6 || gztell(file) != pos) {
if (pos != 6 || gztell(file) != pos)
{
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
(long)pos, (long)gztell(file)); (long)pos, (long)gztell(file));
exit(1); exit(1);
} }
if (gzgetc(file) != ' ') { if (gzgetc(file) != ' ')
{
fprintf(stderr, "gzgetc error\n"); fprintf(stderr, "gzgetc error\n");
exit(1); exit(1);
} }
if (gzungetc(' ', file) != ' ') { if (gzungetc(' ', file) != ' ')
{
fprintf(stderr, "gzungetc error\n"); fprintf(stderr, "gzungetc error\n");
exit(1); exit(1);
} }
gzgets(file, (char*)uncompr, (int)uncomprLen); gzgets(file, (char*)uncompr, (int)uncomprLen);
if (strlen((char*)uncompr) != 7) { /* " hello!" */
if (strlen((char*)uncompr) != 7) /* " hello!" */
{
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
exit(1); exit(1);
} }
if (strcmp((char*)uncompr, hello + 6)) {
if (strcmp((char*)uncompr, hello + 6))
{
fprintf(stderr, "bad gzgets after gzseek\n"); fprintf(stderr, "bad gzgets after gzseek\n");
exit(1); exit(1);
} else { }
else
{
printf("gzgets() after gzseek: %s\n", (char*)uncompr); printf("gzgets() after gzseek: %s\n", (char*)uncompr);
} }
@@ -215,16 +244,21 @@ void test_deflate(compr, comprLen)
c_stream.next_in = (Bytef*)hello; c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr; c_stream.next_out = compr;
while (c_stream.total_in != len && c_stream.total_out < comprLen) { while (c_stream.total_in != len && c_stream.total_out < comprLen)
{
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
err = deflate(&c_stream, Z_NO_FLUSH); err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate"); CHECK_ERR(err, "deflate");
} }
/* Finish the stream, still forcing small buffers: */ /* Finish the stream, still forcing small buffers: */
for (;;) { for (;;)
{
c_stream.avail_out = 1; c_stream.avail_out = 1;
err = deflate(&c_stream, Z_FINISH); err = deflate(&c_stream, Z_FINISH);
if (err == Z_STREAM_END) break; if (err == Z_STREAM_END) break;
CHECK_ERR(err, "deflate"); CHECK_ERR(err, "deflate");
} }
@@ -255,20 +289,26 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
err = inflateInit(&d_stream); err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit"); CHECK_ERR(err, "inflateInit");
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
{
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
err = inflate(&d_stream, Z_NO_FLUSH); err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break; if (err == Z_STREAM_END) break;
CHECK_ERR(err, "inflate"); CHECK_ERR(err, "inflate");
} }
err = inflateEnd(&d_stream); err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd"); CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) { if (strcmp((char*)uncompr, hello))
{
fprintf(stderr, "bad inflate\n"); fprintf(stderr, "bad inflate\n");
exit(1); exit(1);
} else { }
else
{
printf("inflate(): %s\n", (char*)uncompr); printf("inflate(): %s\n", (char*)uncompr);
} }
} }
@@ -300,7 +340,9 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
c_stream.avail_in = (uInt)uncomprLen; c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH); err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate"); CHECK_ERR(err, "deflate");
if (c_stream.avail_in != 0) {
if (c_stream.avail_in != 0)
{
fprintf(stderr, "deflate not greedy\n"); fprintf(stderr, "deflate not greedy\n");
exit(1); exit(1);
} }
@@ -320,10 +362,13 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
CHECK_ERR(err, "deflate"); CHECK_ERR(err, "deflate");
err = deflate(&c_stream, Z_FINISH); err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
if (err != Z_STREAM_END)
{
fprintf(stderr, "deflate should report Z_STREAM_END\n"); fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1); exit(1);
} }
err = deflateEnd(&c_stream); err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd"); CHECK_ERR(err, "deflateEnd");
} }
@@ -350,21 +395,27 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
err = inflateInit(&d_stream); err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit"); CHECK_ERR(err, "inflateInit");
for (;;) { for (;;)
{
d_stream.next_out = uncompr; /* discard the output */ d_stream.next_out = uncompr; /* discard the output */
d_stream.avail_out = (uInt)uncomprLen; d_stream.avail_out = (uInt)uncomprLen;
err = inflate(&d_stream, Z_NO_FLUSH); err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break; if (err == Z_STREAM_END) break;
CHECK_ERR(err, "large inflate"); CHECK_ERR(err, "large inflate");
} }
err = inflateEnd(&d_stream); err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd"); CHECK_ERR(err, "inflateEnd");
if (d_stream.total_out != 2*uncomprLen + comprLen/2) { if (d_stream.total_out != 2 * uncomprLen + comprLen / 2)
{
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
exit(1); exit(1);
} else { }
else
{
printf("large_inflate(): OK\n"); printf("large_inflate(): OK\n");
} }
} }
@@ -398,9 +449,12 @@ void test_flush(compr, comprLen)
c_stream.avail_in = len - 3; c_stream.avail_in = len - 3;
err = deflate(&c_stream, Z_FINISH); err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
if (err != Z_STREAM_END)
{
CHECK_ERR(err, "deflate"); CHECK_ERR(err, "deflate");
} }
err = deflateEnd(&c_stream); err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd"); CHECK_ERR(err, "deflateEnd");
@@ -440,11 +494,14 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
CHECK_ERR(err, "inflateSync"); CHECK_ERR(err, "inflateSync");
err = inflate(&d_stream, Z_FINISH); err = inflate(&d_stream, Z_FINISH);
if (err != Z_DATA_ERROR) {
if (err != Z_DATA_ERROR)
{
fprintf(stderr, "inflate should report DATA_ERROR\n"); fprintf(stderr, "inflate should report DATA_ERROR\n");
/* Because of incorrect adler32 */ /* Because of incorrect adler32 */
exit(1); exit(1);
} }
err = inflateEnd(&d_stream); err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd"); CHECK_ERR(err, "inflateEnd");
@@ -480,10 +537,13 @@ void test_dict_deflate(compr, comprLen)
c_stream.avail_in = (uInt)strlen(hello) + 1; c_stream.avail_in = (uInt)strlen(hello) + 1;
err = deflate(&c_stream, Z_FINISH); err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
if (err != Z_STREAM_END)
{
fprintf(stderr, "deflate should report Z_STREAM_END\n"); fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1); exit(1);
} }
err = deflateEnd(&c_stream); err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd"); CHECK_ERR(err, "deflateEnd");
} }
@@ -513,27 +573,37 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
d_stream.next_out = uncompr; d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen; d_stream.avail_out = (uInt)uncomprLen;
for (;;) { for (;;)
{
err = inflate(&d_stream, Z_NO_FLUSH); err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break; if (err == Z_STREAM_END) break;
if (err == Z_NEED_DICT) {
if (d_stream.adler != dictId) { if (err == Z_NEED_DICT)
{
if (d_stream.adler != dictId)
{
fprintf(stderr, "unexpected dictionary"); fprintf(stderr, "unexpected dictionary");
exit(1); exit(1);
} }
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
(int)sizeof(dictionary)); (int)sizeof(dictionary));
} }
CHECK_ERR(err, "inflate with dict"); CHECK_ERR(err, "inflate with dict");
} }
err = inflateEnd(&d_stream); err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd"); CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) { if (strcmp((char*)uncompr, hello))
{
fprintf(stderr, "bad inflate with dict\n"); fprintf(stderr, "bad inflate with dict\n");
exit(1); exit(1);
} else { }
else
{
printf("inflate with dictionary: %s\n", (char*)uncompr); printf("inflate with dictionary: %s\n", (char*)uncompr);
} }
} }
@@ -551,11 +621,14 @@ int main(argc, argv)
uLong uncomprLen = comprLen; uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION; static const char* myVersion = ZLIB_VERSION;
if (zlibVersion()[0] != myVersion[0]) { if (zlibVersion()[0] != myVersion[0])
{
fprintf(stderr, "incompatible zlib version\n"); fprintf(stderr, "incompatible zlib version\n");
exit(1); exit(1);
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { }
else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0)
{
fprintf(stderr, "warning: different zlib version\n"); fprintf(stderr, "warning: different zlib version\n");
} }
@@ -564,10 +637,12 @@ int main(argc, argv)
compr = (Byte*)calloc((uInt)comprLen, 1); compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1); uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
/* compr and uncompr are cleared to avoid reading uninitialized /* compr and uncompr are cleared to avoid reading uninitialized
* data and to ensure that uncompr compresses well. * data and to ensure that uncompr compresses well.
*/ */
if (compr == Z_NULL || uncompr == Z_NULL) { if (compr == Z_NULL || uncompr == Z_NULL)
{
printf("out of memory\n"); printf("out of memory\n");
exit(1); exit(1);
} }

Some files were not shown because too many files have changed in this diff Show More