diff --git a/.gitignore b/.gitignore
index 7cd6ca0e0..b33f1485c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@
# Windows Compiled files
*.exe
*.pdb
+*.ilk
# Compiled Python
*.pyc
@@ -31,6 +32,8 @@ config.log
package.txt
lib
include
+build_info.cpp
+/dist.txt
# Backup files
*~
@@ -39,3 +42,15 @@ include
.ninja_deps
.ninja_log
build.ninja
+
+# VS Code files
+.vscode
+*.code-workspace
+
+# Patches, regects, origs
+*.patch
+*.rej
+*.orig
+
+# Env files
+/scons-env-options.py
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..66f2af71d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,67 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2024, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+sudo: false
+dist: bionic
+language: cpp
+compiler:
+ - gcc
+python:
+ - "3.8"
+
+cache: ccache
+
+addons:
+ apt:
+ update: true
+ packages:
+ - scons
+ - build-essential
+ - libssl-dev
+ - binutils-dev
+ - libiberty-dev
+ - libmariadb-dev-compat
+ - libleveldb-dev
+ - libsnappy-dev
+ - git
+
+jobs:
+ include:
+ - stage: Build
+ script:
+ - scons
+ - stage: Test
+ script:
+ - scons
+ - cd tests
+ - scons
+ - ./testHarness
diff --git a/CODE_TAG b/CODE_TAG
index eeda1ab93..7b3addcf6 100644
--- a/CODE_TAG
+++ b/CODE_TAG
@@ -1,7 +1,7 @@
This file is part of the C! library. A.K.A the cbang library.
- Copyright (c) 2003-2019, Cauldron Development LLC
- Copyright (c) 2003-2017, Stanford University
+ Copyright (c) 2021-2025, Cauldron Development Oy
+ Copyright (c) 2003-2021, Cauldron Development LLC
All rights reserved.
The C! library is free software: you can redistribute it and/or
diff --git a/COPYING b/COPYING
deleted file mode 100644
index e5ab03e12..000000000
--- a/COPYING
+++ /dev/null
@@ -1,502 +0,0 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- , 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 0012c4ad2..000000000
--- a/Dockerfile
+++ /dev/null
@@ -1,20 +0,0 @@
-# Build C!
-
-FROM debian:testing
-
-MAINTAINER Joseph Coffland
-
-# Get the prerequisites
-RUN apt-get update && \
- apt-get install -y scons git build-essential libssl-dev \
- libboost-iostreams-dev libboost-system-dev libboost-filesystem-dev \
- libboost-regex-dev libv8-dev
-
-# Move the source into the image
-ADD . /opt/cbang
-WORKDIR /opt/cbang
-ENV CBANG_HOME /opt/cbang
-
-# Build it
-RUN scons -j 4
-
diff --git a/README.md b/README.md
index 04921fee6..dad2b44c9 100644
--- a/README.md
+++ b/README.md
@@ -2,19 +2,21 @@ C! (a.k.a. C-Bang)
==================
The C! or cbang library is a collection of C++ utility libraries
-developed over the course of +15 years and several major C++
+developed over the course of +20 years and several major C++
application development projects. It should compile and run on
-Windows, Linux and OSX using a modern C++ compiler.
+Windows, Linux and macOS using a modern C++ compiler such as GNU C++,
+clang or MSVC.
Many of the facilities of C! are geared towards cross-platform
application development and providing basic services that most
applications need such as a configuration system, run-time build
-information, logging facilities, threads, smart pointers, simple
-embedded scripting, etc.
+information, configuration and logging facilities, and smart pointers.
C!'s philosophy is to create clean, simple, readable, modular and
-reusable code. C! also encourages exception based error handling, and
-light use of C++ templates and C preprocesor macros.
+reusable code. C! also encourages exception based error handling,
+light use of C++ templates and C preprocessor macros. Event driven
+asynchronous programming is preferred but threading is also fully
+supported.
C! "leans" on the venerable boost library but also reimplements
several boost APIs which are considered by the author to be too
@@ -25,76 +27,81 @@ be any sort of grand unifying system for C++ application development.
However, I hope you find many parts of the library useful in your C++
development projects.
-For licensing information please see the files LICENSE and COPYING.
-
+For licensing information please see ``LICENSE`` file.
# Features
- - Smart pointers, both thread safe and non, with downcasting capability.
- - Threading, mutexes, conditions & thread local storage
- - Soft exit & signal handling
+
+ - Smart pointers, both thread safe and non, with down-casting capability.
- Extensively configurable logging facilities.
- - Exception class with stack trace capability including line and file info.
+ - Stack trace capability with function, file and line. (macOS and Linux only)
- Exception throwing and catching convenience macros.
- - HTTP and HTTPS client and server.
+ - Command line parsing and configuration file configuration system.
+ - HTTP, HTTPS and Websocket client and server.
+ - Automatic ACMEv2 TLS certification acquisition.
+ - OAuth2 logins.
+ - Event driven programming via C++ wrapper for libevent.
+ - Asynchronous IP address / hostname resolution, parsing and manipulation.
+ - IPv6 support.
- Socket client and server with asynchronous capability.
- - XMacro based enum implementation.
- - PyON Python Object Notation language for serializing and deserializing data.
- - Simple scripting language for configuration and text based command server.
+ - Threading, mutexes, conditions & thread local storage
+ - Soft exit & signal handling
+ - GPU detection with OpenCL and CUDA support detection.
+ - CPU type and feature detection for x86, amd64 and aarch64.
+ - PCI bus enumeration.
+ - Embedded Javascript (ECMA) support.
+ - Dynamic library and symbol loading.
+ - Subprocess handling.
+ - Power management and system idle detection.
+ - XMacro based enumerations with automatic string parsing and printing.
- Software build information system.
- - A system for compiling in a directory tree of resources.
+ - Compile in resource trees from directory of files on disk.
- Network packet automatic byte order and string packing functionality.
- - Temporary directories, directory traversal & file operations
- - C++ style number, to and from, string conversions.
- - iostream utilities.
- - Application configuration system.
- - XML facilities.
+ - Temporary directories, directory traversal & file operations.
+ - File locking.
+ - C++ style number conversions to/from string.
+ - std::iostream and compression utilities.
+ - JSON, YAML and XML facilities.
- TAR file read and write.
- Time and timing functions.
- OpenSSL C++ interface.
- - IP address / hostname resolution, parsing and manipulation.
- URL parsing.
- Geometric primitives.
- - C++ wrapper for libevent.
- - Async MariaDB interface using libevent.
+ - Async MariaDB/MySQL client interface.
- Human readable size & time formatting.
- Many other utility classes.
- Completely contained in it's own C++ namespace.
- - Consistent and clean code formating <= 80 column width.
-
+ - Consistent and clean code formatting <= 80 column width.
+ - Platform independent API.
# Prerequisites
-## General
+## Required
- A modern C++ compiler: GNU C++, Intel C++, MSVS
- - SCons http://scons.org/
- - openssl http://www.openssl.org/ (optional)
- - ChakraCore https://github.com/Microsoft/ChakraCore/ (optional)
- - V8 https://developers.google.com/v8/ (optional)
- - mariadb https://mariadb.org/ (optional)
+ - SCons http://scons.org/
-## Debug mode only
+## Optional
+The following add optional features to C!.
- - libbfd ftp://ftp.gnu.org/old-gnu/Manuals/bfd-2.9.1/html_mono/bfd.html
- - libiberty https://gcc.gnu.org/onlinedocs/libiberty/
+ - openssl http://www.openssl.org/
+ - V8 https://developers.google.com/v8/
+ - mariadb https://mariadb.org/
+ - LevelDB https://github.com/google/leveldb
+ - Snappy http://google.github.io/snappy/
-## Windows only
- - Winsock
+## Debug mode
+Debug mode is enabled by compiling with ``debug=``.
-## OS-X only
- - IOKit
- - CoreFoundation
+Compiling with ``libbfd`` will enhance stack track output on Linux systems.
+Install ``binutils-dev`` to get ``libbfd`` on Debian.
-## POSIX/Linux only
- - pthreads
- - libbfd (For debug mode only)
+## Debian/Ubuntu install
+On most Debian based systems the prerequisites can be installed with the
+following command line:
-On Debian based systems the prerequisites can be installed with the following
-command line:
+ sudo apt-get install -y scons build-essential libssl-dev binutils-dev \
+ libiberty-dev libmariadb-dev-compat libleveldb-dev libsnappy-dev git \
+ libzstd-dev
- sudo apt-get install scons build-essential libssl-dev binutils-dev \
- libiberty-dev libmariadbclient-dev git
-
-Unfortunately, at this time, there is no ChakraCore package for Debian. See
-the build instructions below.
+The necessary library packages can very by Linux distribution type and version.
# Build
@@ -112,7 +119,7 @@ command line to scons or place in a configuration file named
- strict - Enable strict checking
- distcc - Enable distcc distributed compile system
- ccache - Enable ccache caching compile system
- - backtrace_debugger - Enable the printing backtraces
+ - backtrace_debugger - Enable the printing of stack traces
These options are enabled by setting them to 1. For example:
@@ -126,76 +133,6 @@ strict checking.
# Testing the Build
-You can testing C! by going to the *tests* directory in the root of the
-cbang source tree, building the test programs and running the test harness:
-
- cd tests
- scons
- ./testHarness
-
-# Troubleshooting
-
-This section describes some common problems and their solutions.
-
-## OpenSSL Library Less than v1.0.0
-
-If you get an error about the openssl library version being too old then you
-either need to upgrade your package or build openssl from source like this:
-
- wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz
- tar xzvf openssl-1.0.1f.tar.gz
- cd openssl-1.0.1f
- ./config
- make
- export OPENSSL_HOME=$PWD
-
-Then try building C!.
-
-## ChakraCore
-
-You can either download a prebuilt ChakraCore or build it yourself. Currently
-we require a fork of ChakraCore which includes some fixes.
-
-### Windows Binaries
-
-You can find windows binaries of ChakraCore here:
-https://github.com/CauldronDevelopmentLLC/ChakraCore/releases/tag/v2.0.0.1
-
-### Building ChakraCore
-
-ChakraCore is the Javascript engine used by the Microsoft Edge browser. It
-is fast and Open-Source. Unfortunately there currently aren't any readily
-available Debian packages for ChakraCore so you will have to build it from
-source.
-
-First make sure you have the prerequisites:
-
- sudo apt-get install -y cmake clang libunwind-dev libicu-dev
-
-You need at least cmake 3.2 and clang 3.8. If your system doesn't have these
-then you need to build them from source.
-
-
-First download the source code:
-
- git clone --depth=1 https://github.com/CauldronDevelopmentLLC/ChakraCore.git
-
-Then build it:
-
- cd ChakraCore
- ./build.sh --static -j 8
-
-Next collect the various libraries it produces in to one:
-
- mkdir tmp
- cd tmp
- for i in $(find ../Build* -name \*.a); do
- ar x $i
- done
- ar rcs ../libChakraCore.a *.o
- cd ..
- rm -rf tmp
-
-Now setup the environment so that the C! build system can find ChakraCore:
+You can testing C! by running the test suite:
- export CHAKRA_CORE_HOME=$PWD
+ scons test
diff --git a/SConstruct b/SConstruct
index 23ce75e75..b1b6b49e5 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,81 +1,126 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
+import platform
+
# Version
-version = '0.0.1'
+version = '1.7.2'
libversion = '0'
+
# Setup
env = Environment(ENV = os.environ,
TARGET_ARCH = os.environ.get('TARGET_ARCH', 'x86'))
env.Tool('config', toolpath = ['.'])
env.CBAddVariables(
+ BoolVariable('v8_compress_pointers', 'Enable pointer compression for libv8',
+ platform.machine().endswith('64')),
BoolVariable('staticlib', 'Build a static library', True),
BoolVariable('sharedlib', 'Build a shared library', False),
('soname', 'Shared library soname', 'libcbang%s.so' % libversion),
('libsuffix', 'Suffix for library path, e.g. "64" to get lib64', ''),
+ ('libpath', 'Library installation path, e.g. "/lib64"', '/lib'),
PathVariable('prefix', 'Install path prefix', '/usr/local',
PathVariable.PathAccept),
('docdir', 'Path for documentation', '${prefix}/share/doc/cbang'),
BoolVariable('with_openssl', 'Build with OpenSSL support', True),
('force_local', 'List of 3rd party libs to be built locally', ''),
('disable_local', 'List of 3rd party libs not to be built locally', ''))
-env.CBLoadTools('dist packager compiler cbang build_info resources')
+env.CBLoadTools('packager compiler cbang build_info resources')
conf = env.CBConfigure()
-# Build Info
-env.Replace(BUILD_INFO_NS = 'cb::BuildInfo')
-env.Replace(RESOURCES_NS = 'cb')
-
-
-# Dist
-if 'dist' in COMMAND_LINE_TARGETS:
- env.__setitem__('dist_build', '')
- # Only files checked in to Subversion
- lines = os.popen('svn status -v').readlines()
- lines = filter(lambda l: len(l) and l[0] in 'MA ', lines)
- files = map(lambda l: l.split()[-1], lines)
- files = list(filter(lambda f: not os.path.isdir(f), files))
-
- tar = env.TarBZ2Dist('libcbang' + libversion, files)
- Alias('dist', tar)
- Return()
+# Build Info
+author = 'Joseph Coffland '
+env.Replace(PACKAGE_VERSION = version)
+env.Replace(PACKAGE_AUTHOR = author)
+env.Replace(PACKAGE_ORG = 'Cauldron Development')
+env.Replace(PACKAGE_COPYRIGHT = 'Cauldron Development, 2003-2025')
+env.Replace(PACKAGE_HOMEPAGE = 'https://cauldrondevelopment.com/')
+env.Replace(PACKAGE_LICENSE = 'LGPL-2.1-or-later')
+env.Replace(BUILD_INFO_NS = 'cb::BuildInfo')
+env.Replace(RESOURCES_NS = 'cb')
+
+
+# Local lib control
+force_local = env.get('force_local', '')
+if hasattr(force_local, 'split'): force_local = force_local.split()
+disable_local = env.get('disable_local', '')
+if hasattr(disable_local, 'split'): disable_local = disable_local.split()
# Configure
if not env.GetOption('clean'):
conf.CBConfig('compiler')
- conf.CBConfig('cbang-deps', with_openssl = env['with_openssl'])
+ conf.CBConfig('cbang-deps', with_openssl = env['with_openssl'],
+ with_local_boost = 'boost' not in disable_local)
env.CBDefine('USING_CBANG') # Using CBANG macro namespace
- if env['PLATFORM'] != 'win32': env.AppendUnique(CCFLAGS = ['-fPIC'])
# Local includes
env.Append(CPPPATH = ['#/include', '#/src', '#/src/boost'])
+
# Build third-party libs
-force_local = env.get('force_local', '')
-if hasattr(force_local, 'split'): force_local = force_local.split()
-disable_local = env.get('disable_local', '')
-if hasattr(disable_local, 'split'): disable_local = disable_local.split()
Export('env conf')
-for lib in 'zlib bzip2 sqlite3 expat boost libevent re2 libyaml'.split():
- if lib in disable_local: continue
- if not env.CBConfigEnabled(lib) or lib in force_local:
- Default(SConscript('src/%s/SConscript' % lib,
- variant_dir = 'build/' + lib))
+resources_excludes = []
+for lib in 'ZLib bzip2 lz4 sqlite3 expat boost libevent re2 libyaml'.split():
+ if lib in disable_local: resources_excludes.append('licenses/%s\\.txt' % lib)
+ elif not env.CBConfigEnabled(lib) or lib in force_local:
+ Default(SConscript(
+ 'src/%s/SConscript' % lib, variant_dir = 'build/' + lib))
+env.Append(RESOURCES_EXCLUDES = resources_excludes)
+
+if 'boost' not in disable_local: env.CBConfigDef('HAVE_LOCAL_BOOST')
+
# Source
-subdirs = [
- '', 'script', 'xml', 'util', 'debug', 'config', 'pyon', 'os', 'http',
- 'struct', 'log', 'iostream', 'time', 'enum', 'packet', 'net', 'buffer',
- 'socket', 'tar', 'io', 'geom', 'parse', 'json', 'db',
- 'auth', 'js', 'gpu', 'pci']
+subdirs = [''] + '''
+ oauth2 boost comp config db debug dns enum event geom http hw io js json log
+ net os parse thread time util ws xml json/schema
+'''.split()
if env.CBConfigEnabled('openssl'): subdirs += ['openssl', 'acmev2']
-if env.CBConfigEnabled('chakra'): subdirs.append('js/chakra')
if env.CBConfigEnabled('v8'): subdirs.append('js/v8')
-if env.CBConfigEnabled('mariadb'): subdirs.append('db/maria')
-if not 'libevent' in disable_local: subdirs.append('event')
+if env.CBConfigEnabled('mariadb'):
+ subdirs += ['db/maria']
+
+ if env.CBConfigEnabled('leveldb'):
+ subdirs += ['api', 'api/arg', 'api/handler', 'api/ws']
+
+if env['PLATFORM'] == 'win32': subdirs.append('os/win')
+elif env['PLATFORM'] == 'darwin': subdirs.append('os/osx')
+else: subdirs.append('os/lin')
src = []
for dir in subdirs:
@@ -86,6 +131,11 @@ for dir in subdirs:
conf.Finish()
+
+# Create config header
+if not COMMAND_LINE_TARGETS: env.CBWriteConfigDef('include/cbang/config.h')
+
+
# Build in 'build'
import re
VariantDir('build', 'src', duplicate = False)
@@ -99,39 +149,45 @@ src.append(res)
# Build Info
info = env.BuildInfo('build/build_info.cpp', [])
-AlwaysBuild(info)
+if not COMMAND_LINE_TARGETS: AlwaysBuild(info)
src.append(info)
# Build
libs = []
+install = []
+prefix = env.get('prefix')
+libsuffix = env.get('libsuffix')
+libpath = env.get('libpath')
if env.get('staticlib'):
libs.append(env.StaticLibrary('lib/cbang', src))
+ install.append(env.Install(dir = '%s/%s%s' % (prefix, libpath, libsuffix),
+ source = libs))
if env.get('sharedlib'):
- env.Append(SHLIBSUFFIX = '.' + version)
- env.Append(SHLINKFLAGS = '-Wl,-soname -Wl,${soname}')
- libs.append(env.SharedLibrary('lib/cbang' + libversion, src))
+ shlib = env.SharedLibrary(
+ 'lib/cbang' + libversion, src, SHLIBVERSION = version,
+ SONAME = env.get('soname'))
+ libdir = '%s/%s%s' % (prefix, libpath, libsuffix)
+ install.append(InstallVersionedLib(dir = libdir, source = shlib))
+ libs.append(shlib)
for lib in libs: Default(lib)
+
# Clean
Clean(libs, 'build lib include config.log cbang-config.pyc package.txt'
.split() + Glob('config/*.pyc'))
# Install
-prefix = env.get('prefix')
-libsuffix = env.get('libsuffix')
-install = [env.Install(dir = prefix + '/lib' + libsuffix, source = libs)]
-
for dir in subdirs:
files = Glob('src/cbang/%s/*.h' % dir)
files += Glob('src/cbang/%s/*.def' % dir)
- install.append(env.Install(dir = prefix + '/include/cbang/' + dir,
- source = files))
+ dir = prefix + '/include/cbang/' + dir
+ install.append(env.Install(dir = dir, source = files))
-docs = ['README.md', 'COPYING']
+docs = ['README.md', 'LICENSE']
docdir = env.get('docdir').replace('${prefix}', prefix)
install.append(env.Install(dir = docdir, source = docs))
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index 45e32f646..000000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-version: 1.0.{build}
-install:
-- nuget install WGETWindows
-- nuget install openssl
-- nuget install boost
-build: off
diff --git a/config/XML/__init__.py b/config/XML/__init__.py
index 78e3b7e53..32afb0ae0 100644
--- a/config/XML/__init__.py
+++ b/config/XML/__init__.py
@@ -1,21 +1,40 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import sys
from SCons.Script import *
-def configure(conf):
- env = conf.env
-
- # libexpat
- if conf.CBConfig('expat'): return True
-
- else: # Glib 2.0
- env.ParseConfig('pkg-config --cflags --libs glib-2.0')
- env.ParseConfig('pkg-config --cflags --libs gthread-2.0')
- if conf.CBCheckHeader('glib.h'):
- env.CBDefine('HAVE_GLIB')
- return True
-
- return False
+def configure(conf): return conf.CBConfig('expat')
def generate(env):
@@ -23,5 +42,4 @@ def generate(env):
env.CBLoadTool('expat')
-def exists():
- return 1
+def exists(): return 1
diff --git a/config/ZLib/__init__.py b/config/ZLib/__init__.py
new file mode 100644
index 000000000..9acc25974
--- /dev/null
+++ b/config/ZLib/__init__.py
@@ -0,0 +1,48 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+from SCons.Script import *
+
+
+def configure(conf):
+ conf.CBCheckHome('zlib', lib_suffix = ['', '/lib'],
+ inc_suffix = ['/src', '/include'])
+ conf.CBRequireHeader('zlib.h')
+ conf.CBRequireLib('z')
+
+
+def generate(env):
+ env.CBAddConfigTest('ZLib', configure)
+
+
+def exists():
+ return 1
diff --git a/config/__init__.py b/config/__init__.py
index 8fcbe2e19..c98da361c 100644
--- a/config/__init__.py
+++ b/config/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from __future__ import print_function
import os
@@ -7,6 +39,7 @@
import inspect
import types
import re
+import shlex
def CBCheckEnv(ctx, name, require = False):
@@ -96,6 +129,7 @@ def CBCheckLib(ctx, lib, unique = False, append = False, **kwargs):
if libname: lib = libname
if ctx.sconf.CheckLib(lib, autoadd = 0, **kwargs):
+ if '/' in lib or '\\' in lib: lib = File(lib)
if unique: ctx.env.PrependUnique(LIBS = [lib])
else: ctx.env.Prepend(LIBS = [lib])
@@ -247,6 +281,27 @@ def CBDefine(env, defs):
env.AppendUnique(CPPDEFINES = defs)
+def CBConfigDef(env, defs):
+ if not type(defs) in (list, tuple): defs = [defs]
+ env.cb_config_defs.update(defs)
+
+
+def CBWriteConfigDef(env, path):
+ if not os.path.exists(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+
+ with open(path, 'w') as f:
+ f.write('// Autogenerated file\n')
+ f.write('#pragma once\n\n')
+
+ for var in sorted(env.cb_config_defs):
+ if '=' in var:
+ name, value = var.split('=', 1)
+ f.write('#define %s %s\n' % (name, value))
+
+ else: f.write('#define %s\n' % var)
+
+
def CBAddVariables(env, *args):
env.cb_vars += args
@@ -277,16 +332,14 @@ def on_config_finish(conf):
updated_csig = set()
-def decider_hack(dep, target, prev_ni):
- from SCons.Util import MD5signature
-
- #print('%s ?= %s %s' % (dep, target, prev_ni.csig))
+def decider_hack(dep, target, prev_ni, *args, **kwargs):
+ from hashlib import sha256
ninfo = dep.get_ninfo();
# Make sure csigs get updated
if not hasattr(ninfo, 'csig') or str(dep) not in updated_csig:
- ninfo.csig = MD5signature(dep.get_contents())
+ ninfo.csig = sha256(dep.get_contents()).hexdigest()
updated_csig.add(str(dep))
# .csig may not exist, because no target was built yet...
@@ -315,19 +368,28 @@ def CBConfigure(env):
# Load config files
configs = []
- if 'SCONS_OPTIONS' in os.environ:
- options = os.environ['SCONS_OPTIONS']
- if not os.path.exists(options):
- print('options file "%s" set in SCONS_OPTIONS does not exist' %
- options)
- Exit(1)
-
- configs.append(options)
-
if os.path.exists('default-options.py'):
configs.append('default-options.py')
if os.path.exists('options.py'): configs.append('options.py')
+ if 'SCONS_OPTIONS' in os.environ:
+ options = os.environ['SCONS_OPTIONS']
+ if os.path.exists(options): configs.append(options)
+ else:
+ if '=' not in options:
+ print('options file "%s" set in SCONS_OPTIONS does not exist' %
+ options)
+ Exit(1)
+
+ env_opts = 'scons-env-options.py'
+ if os.path.exists(env_opts): os.unlink(env_opts)
+ with open(env_opts, 'w') as f:
+ for item in shlex.split(options):
+ n, v = item.split('=', 1)
+ f.write('%s="%s"\n' % (n, v))
+
+ configs.append(env_opts)
+
# Load variables
v = Variables(configs)
v.AddVariables(*env.cb_vars)
@@ -364,25 +426,18 @@ def CBDownload(env, target, url):
opener = urllib.build_opener(urllib.ProxyHandler(handlers))
urllib.install_opener(opener)
- f = None
- stream = None
- try:
- stream = urllib.urlopen(url)
- f = open(target, 'wb', 0) # Unbuffered
- while stream and f:
- data = stream.read(1024 * 1024)
- if not data: break
- f.write(data)
- sys.stdout.write('.')
- sys.stdout.flush()
+ with urllib.urlopen(url) as stream:
+ with open(target, 'wb', 0) as f: # Unbuffered
+ while stream and f:
+ data = stream.read(1024 * 1024)
+ if not data: break
+ f.write(data)
+ sys.stdout.write('.')
+ sys.stdout.flush()
sys.stdout.write('ok\n')
sys.stdout.flush()
- finally:
- if f is not None: f.close()
- if stream is not None: stream.close()
-
def CBAddConfigFinishCB(env, cb):
env.cb_finish_cbs.append(cb)
@@ -398,22 +453,41 @@ def CBBuildSetRegex(env, pats):
def generate(env):
+ def version_less(a, b):
+ return a.major < b.major or (a.major == b.major and a.minor < b.minor)
+
+
+ class objdict(object):
+ def __init__(self, **kwargs):
+ self.__dict__ = kwargs
+
+ # Check Python version
+ v2 = objdict(major = 2, minor = 7)
+ v3 = objdict(major = 3, minor = 1)
+ v = sys.version_info
+
+ if (2 < v.major and version_less(v, v3)) or version_less(v, v2):
+ raise Exception("C! requires Python %d.%d+ or %d.%d+ found %d.%d." % (
+ v2.major, v2.minor, v3.major, v3.minor, v.major, v.minor))
+
# Add member variables
env.cb_loaded = set()
env.cb_enabled = set()
env.cb_methods = {}
- env.cb_deps_methods = {}
env.cb_tests = {}
env.cb_vars = []
env.cb_paths = []
env.cb_finish_cbs = []
env.cb_configure_cbs = []
+ env.cb_config_defs = set()
# Add methods
env.AddMethod(CBTryLoadTool)
env.AddMethod(CBLoadTool)
env.AddMethod(CBLoadTools)
env.AddMethod(CBDefine)
+ env.AddMethod(CBConfigDef)
+ env.AddMethod(CBWriteConfigDef)
env.AddMethod(CBAddVariables)
env.AddMethod(CBAddTest)
env.AddMethod(CBAddConfigTest)
diff --git a/config/app/__init__.py b/config/app/__init__.py
index 700b09143..e5ec5da28 100644
--- a/config/app/__init__.py
+++ b/config/app/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
'''
Builds an OSX application bundle
'''
@@ -23,7 +55,8 @@ def build_function(target, source, env):
# Create Info.plist
import plistlib
plist_template = env.get('app_plist_template', None)
- if plist_template is not None: info = plistlib.readPlist(plist_template)
+ if plist_template is not None:
+ with open(plist_template, 'rb') as f: info = plistlib.load(f)
else: info = {}
# Info.plist keys
@@ -46,7 +79,7 @@ def build_function(target, source, env):
if other is not None: info.update(other)
info_file = os.path.join(contents_dir, 'Info.plist')
- plistlib.writePlist(info, info_file)
+ with open(info_file, 'wb') as f: plistlib.dump(info, f)
# Let 'app_programs' override 'programs'
if 'app_programs' in env: programs_key = 'app_programs'
diff --git a/config/build_info/__init__.py b/config/build_info/__init__.py
index c371513db..242f81a3d 100644
--- a/config/build_info/__init__.py
+++ b/config/build_info/__init__.py
@@ -1,165 +1,176 @@
-from __future__ import print_function
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
import textwrap
+import os
import re
import sys
+import shutil
from platform import release
import subprocess
from SCons.Script import *
+from collections import OrderedDict
-def escstr(s):
- return s.replace('\\', '\\\\').replace('"', '\\"')
+def escstr(s): return s.replace('\\', '\\\\').replace('"', '\\"')
-def which(program):
- import os
- def is_exe(fpath):
- return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+def svn_get_info():
+ svn = shutil.which('svn')
+ if not svn: return None, None
- fpath, fname = os.path.split(program)
- if fpath:
- if is_exe(program):
- return program
- else:
- for path in os.environ["PATH"].split(os.pathsep):
- path = path.strip('"')
- exe_file = os.path.join(path, program)
- if is_exe(exe_file):
- return exe_file
+ revision, branch = None, None
- return None
+ try:
+ p = subprocess.Popen(['svn', 'info'], stderr = subprocess.PIPE,
+ stdout = subprocess.PIPE)
+ out, err = p.communicate()
+ if isinstance(out, bytes): out = out.decode()
+ for line in out.splitlines():
+ if line.startswith('Revision: '): revision = line[10:].strip()
+ elif line.startswith('URL: '):
+ branch = line[5:].strip()
+ branch = re.sub(r'https?://[\w\.]+/(svn/)?', '', branch)
-def svn_get_info():
- svn = which('svn')
- if not svn: return None, None
+ except Exception as e: print(e)
- revision, branch = None, None
+ return revision, branch
- try:
- p = subprocess.Popen(['svn', 'info'], stderr = subprocess.PIPE,
- stdout = subprocess.PIPE)
- out, err = p.communicate()
- if isinstance(out, bytes): out = out.decode()
- for line in out.splitlines():
- if line.startswith('Revision: '): revision = line[10:].strip()
- elif line.startswith('URL: '):
- branch = line[5:].strip()
- branch = re.sub(r'https?://[\w\.]+/(svn/)?', '', branch)
+def git_get_info():
+ if not shutil.which('git'): return None, None
- except Exception as e: print(e)
+ revision, branch = None, None
- return revision, branch
+ try:
+ p = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
+ stderr = subprocess.PIPE, stdout = subprocess.PIPE)
+ out, err = p.communicate()
+ if isinstance(out, bytes): out = out.decode()
+ revision = out.strip()
+ except Exception as e: print(e)
-def git_get_info():
- revision, branch = None, None
+ try:
+ p = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
+ stderr = subprocess.PIPE, stdout = subprocess.PIPE)
+ out, err = p.communicate()
+ if isinstance(out, bytes): out = out.decode()
+ branch = out.strip()
- try:
- p = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
- stderr = subprocess.PIPE, stdout = subprocess.PIPE)
- out, err = p.communicate()
- if isinstance(out, bytes): out = out.decode()
- revision = out.strip()
+ except Exception as e: print(e)
- except Exception as e: print(e)
+ return revision, branch
- try:
- p = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
- stderr = subprocess.PIPE, stdout = subprocess.PIPE)
- out, err = p.communicate()
- if isinstance(out, bytes): out = out.decode()
- branch = out.strip()
- except Exception as e: print(e)
+def build_function(target, source, env):
+ items = []
- return revision, branch
+ for name in env['BUILD_INFO_PACKAGE_VARS']:
+ var = 'PACKAGE_' + name.upper()
+ if env.get(var): items.append((name, '"%s"' % env[var]))
+ items.append(('Date', '__DATE__'))
+ items.append(('Time', '__TIME__'))
-def build_function(target, source, env):
- contents = (
- ' void addBuildInfo(const char *category) {\n'
- ' Info &info = Info::instance();\n'
- '\n'
- ' info.add(category, "Version", "$PACKAGE_VERSION");\n'
- ' info.add(category, "Author", "$PACKAGE_AUTHOR");\n'
- ' info.add(category, "Org", "$PACKAGE_ORG");\n'
- ' info.add(category, "Copyright", "$PACKAGE_COPYRIGHT");\n'
- ' info.add(category, "Homepage", "$PACKAGE_HOMEPAGE");\n'
- ' info.add(category, "License", "$PACKAGE_LICENSE");\n'
- ' info.add(category, "Date", __DATE__);\n'
- ' info.add(category, "Time", __TIME__);\n')
-
- revision, branch = svn_get_info()
- if revision is None: revision, branch = git_get_info()
-
- if revision is not None:
- contents += (
- ' info.add(category, "Revision", "%s");\n'
- ' info.add(category, "Branch", "%s");\n') % (
- revision, branch)
-
- if env.get('debug', False): mode = 'Debug'
- else: mode = 'Release'
-
- contents += (
- ' info.add(category, "Compiler", COMPILER);\n'
- ' info.add(category, "Options", "%s");\n'
- ' info.add(category, "Platform", "%s");\n'
- ' info.add(category, "Bits", String(COMPILER_BITS));\n'
- ' info.add(category, "Mode", "%s");\n'
- ' }') % (
- escstr(' '.join(env['CXXFLAGS'] + env['CCFLAGS'])),
- sys.platform.lower() + ' ' + release(), mode,
- )
-
- target = str(target[0])
- f = open(target, 'w')
+ revision, branch = svn_get_info()
+ if revision is None: revision, branch = git_get_info()
+
+ if revision is not None:
+ items.append(('Revision', '"%s"' % revision))
+ items.append(('Branch', '"%s"' % branch))
+ mode = 'Debug' if env.get('debug', False) else 'Release'
+ cflags = escstr(' '.join(env['CXXFLAGS'] + env['CCFLAGS']))
+ platform = sys.platform.lower() + ' ' + release()
+
+ items.append(('Compiler', 'COMPILER'))
+ items.append(('Options', '"%s"' % cflags))
+ items.append(('Platform', '"%s"' % platform))
+ items.append(('Bits', 'String(COMPILER_BITS)'))
+ items.append(('Mode', '"%s"' % mode))
+
+ target = str(target[0])
+ with open(target, 'w') as f:
note = ('WARNING: This file was auto generated. Please do NOT '
'edit directly or check in to source control.')
f.write(
- '/' + ('*' * 75) + '\\\n ' +
- '\n '.join(textwrap.wrap(note)) + '\n' +
- '\\' + ('*' * 75) + '/\n'
- '\n'
- '#include \n'
- '#include \n'
- '#include \n\n'
- 'using namespace cb;\n\n'
- )
+ '/' + ('*' * 75) + '\\\n ' +
+ '\n '.join(textwrap.wrap(note)) + '\n' +
+ '\\' + ('*' * 75) + '/\n'
+ '\n'
+ '#include \n'
+ '#include \n'
+ '#include \n\n'
+ 'using namespace cb;\n\n'
+ )
ns = env.subst('$BUILD_INFO_NS')
if ns:
- for namespace in ns.split('::'):
- f.write(env.subst('namespace %s {\n' % namespace))
+ for namespace in ns.split('::'):
+ f.write(env.subst('namespace %s {\n' % namespace))
+
+ f.write(
+ ' void addBuildInfo(const char *category) {\n'
+ ' Info &info = Info::instance();\n'
+ ' info.add(category, true);\n'
+ )
- f.write(env.subst(contents) + '\n')
+ for name, value in items:
+ f.write(' info.add(category, "%s", %s);\n' % (name, value))
- if ns:
- parts = ns.split('::')
- parts.reverse()
- for namespace in parts:
- f.write('} // namespace %s\n' % namespace)
+ f.write(' }\n')
- f.close()
+ if ns:
+ parts = ns.split('::')
+ parts.reverse()
+ for namespace in parts:
+ f.write('} // namespace %s\n' % namespace)
- return None
+ return None
def generate(env):
- env.SetDefault(BUILD_INFO_NS = 'BuildInfo')
+ env.SetDefault(BUILD_INFO_NS = 'BuildInfo')
+ env.SetDefault(BUILD_INFO_PACKAGE_VARS =
+ 'Version Author Org Copyright Homepage License'.split())
- bld = Builder(action = build_function,
- source_factory = SCons.Node.FS.Entry,
- source_scanner = SCons.Defaults.DirScanner)
- env.Append(BUILDERS = {'BuildInfo' : bld})
+ bld = Builder(action = build_function, source_factory = SCons.Node.FS.Entry,
+ source_scanner = SCons.Defaults.DirScanner)
+ env.Append(BUILDERS = {'BuildInfo' : bld})
- return True
+ return True
-def exists(env):
- return 1
+def exists(env): return 1
diff --git a/config/bzip2/__init__.py b/config/bzip2/__init__.py
index 3d80112a6..ddd59c50a 100644
--- a/config/bzip2/__init__.py
+++ b/config/bzip2/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
diff --git a/config/cbang/__init__.py b/config/cbang/__init__.py
index 05e9fee6a..afa82bc12 100644
--- a/config/cbang/__init__.py
+++ b/config/cbang/__init__.py
@@ -1,5 +1,38 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
import inspect
+import platform
import os
@@ -8,30 +41,33 @@ def GetHome():
return os.path.dirname(os.path.abspath(path))
-def configure_deps(conf, local = True, with_openssl = True):
+def configure_deps(conf, local = True, with_openssl = True,
+ with_local_boost = True):
env = conf.env
- conf.CBConfig('zlib', not local)
+ conf.CBConfig('ZLib', not local)
conf.CBConfig('bzip2', not local)
+ conf.CBConfig('lz4', not local)
conf.CBConfig('XML', not local)
conf.CBConfig('sqlite3', not local)
- if conf.CBConfig('event', False): conf.CBConfig('re2', not local)
conf.CBConfig('libyaml', not local)
+ conf.CBConfig('leveldb', False)
- if conf.CBCheckLib('leveldb') and conf.CBCheckLib('snappy'):
- conf.CBCheckHome('leveldb')
- if conf.CBCheckCXXHeader('leveldb/db.h'):
- env.CBDefine('HAVE_LEVELDB')
-
+ env.AppendUnique(prefer_dynamic = ['mariadbclient'])
if conf.CBCheckCHeader('mysql/mysql.h') and \
(conf.CBCheckLib('mariadbclient') or
conf.CBCheckLib('mysqlclient')) and \
conf.CBCheckFunc('mysql_real_connect_start'):
- env.CBDefine('HAVE_MARIADB')
+ env.CBConfigDef('HAVE_MARIADB')
env.cb_enabled.add('mariadb')
# Boost
if env['PLATFORM'] == 'win32': env.CBDefine('BOOST_ALL_NO_LIB')
+ if not with_local_boost:
+ conf.CBRequireLib('boost_filesystem')
+ conf.CBRequireLib('boost_iostreams')
+ conf.CBRequireLib('boost_regex')
+ conf.CBRequireLib('boost_system')
# clock_gettime() needed by boost iterprocess
if env['PLATFORM'] == 'posix' and int(env.get('cross_osx', 0)) == 0 \
@@ -39,8 +75,13 @@ def configure_deps(conf, local = True, with_openssl = True):
conf.CBRequireLib('rt')
conf.CBRequireFunc('clock_gettime')
- if with_openssl: conf.CBConfig('openssl', False, version = '1.0.0')
- conf.CBConfig('chakra', False)
+ # Must be after 'rt'
+ if conf.CBConfig('event', False): conf.CBConfig('re2', not local)
+
+ # EPoll support
+ if conf.CBCheckFunc('epoll_create1'): env.CBConfigDef('HAVE_EPOLL')
+
+ if with_openssl: conf.CBConfig('openssl', False, version = '1.1.0')
conf.CBConfig('v8', False)
if env['PLATFORM'] == 'win32' or int(env.get('cross_mingw', 0)):
@@ -54,24 +95,40 @@ def configure_deps(conf, local = True, with_openssl = True):
if env['PLATFORM'] == 'darwin' or int(env.get('cross_osx', 0)):
if not (conf.CheckOSXFramework('CoreServices') and
conf.CheckOSXFramework('IOKit') and
+ conf.CheckOSXFramework('Security') and
+ conf.CheckOSXFramework('SystemConfiguration') and
conf.CheckOSXFramework('CoreFoundation')):
- raise SCons.Errors.StopError(
- 'Need CoreServices, IOKit & CoreFoundation frameworks')
+ raise SCons.Errors.StopError('Need CoreServices, IOKit, Security '
+ '& CoreFoundation frameworks')
+
+ # sd-bus
+ if (env['PLATFORM'] == 'posix' and
+ conf.CBCheckCHeader('systemd/sd-bus.h') and conf.CBCheckLib('systemd')):
+ conf.CBCheckLib('cap')
+ env.CBConfigDef('HAVE_SYSTEMD')
conf.CBConfig('valgrind', False)
# Debug
if env.get('debug', 0):
- if conf.CBCheckCHeader('execinfo.h') and \
- conf.CBCheckCHeader('bfd.h') and \
- conf.CBCheckLib('iberty') and conf.CBCheckLib('bfd'):
- env.CBDefine('HAVE_CBANG_BACKTRACE')
+ if conf.CBCheckCHeader('execinfo.h'):
+ if conf.CBCheckCHeader('bfd.h') and conf.CBCheckLib('bfd'):
+ env.CBConfigDef('HAVE_BFD')
+
+ conf.CBCheckLib('iberty')
+ conf.CBCheckLib('sframe')
+ conf.CBCheckLib('zstd')
+ env.CBConfigDef('HAVE_CBANG_BACKTRACE')
+
+ # Check bfd for API change
+ if not conf.CBCheckFunc('bfd_get_error_handler'):
+ env.CBConfigDef('HAVE_BFD_ERROR_HANDLER_VPRINTFLIKE')
elif env.get('backtrace_debugger', 0):
raise SCons.Errors.StopError(
- 'execinfo.h, bfd.h and libbfd needed for backtrace_debuger')
+ 'execinfo.h needed for backtrace_debuger')
- env.CBDefine('DEBUG_LEVEL=' + str(env.get('debug_level', 1)))
+ env.CBDefine('CBANG_DEBUG_LEVEL=' + str(env.get('debug_level', 1)))
def configure(conf):
@@ -82,11 +139,19 @@ def configure(conf):
home + '/src/boost'])
env.AppendUnique(LIBPATH = [home + '/lib'])
+ with open(home + '/include/cbang/config.h', 'r') as f:
+ config = f.read()
+ with_openssl = config.find('#define HAVE_OPENSSL') != -1
+ with_local_boost = config.find('#define HAVE_LOCAL_BOOST') != -1
+
if not env.CBConfigEnabled('cbang-deps'):
- conf.CBConfig('cbang-deps', local = False)
+ conf.CBConfig('cbang-deps', local = False, with_openssl = with_openssl,
+ with_local_boost = with_local_boost)
+
+ if with_local_boost: conf.CBRequireLib('cbang-boost')
- conf.CBRequireLib('cbang-boost')
conf.CBRequireLib('cbang')
+ if platform.system() == 'FreeBSD': conf.CBRequireLib('sysinfo')
conf.CBRequireCXXHeader('cbang/Exception.h')
env.CBDefine('HAVE_CBANG')
@@ -99,8 +164,8 @@ def generate(env):
BoolVariable('backtrace_debugger', 'Enable backtrace debugger', 0),
('debug_level', 'Set log debug level', 1))
- env.CBLoadTools('''sqlite3 openssl pthreads valgrind osx zlib bzip2
- XML chakra v8 event re2 libyaml'''.split(), GetHome() + '/..')
+ env.CBLoadTools('''sqlite3 openssl pthreads valgrind osx ZLib bzip2 lz4
+ XML v8 event re2 libyaml leveldb'''.split(), GetHome() + '/..')
def exists(env):
diff --git a/config/chakra/__init__.py b/config/chakra/__init__.py
deleted file mode 100644
index b10aac257..000000000
--- a/config/chakra/__init__.py
+++ /dev/null
@@ -1,35 +0,0 @@
-from SCons.Script import *
-import platform
-
-
-def configure(conf):
- conf.CBCheckHome('chakra_core', lib_suffix = ['/'],
- inc_suffix = ['/lib/Jsrt', '/include'])
-
- conf.CBRequireCXXHeader('ChakraCore.h')
-
- if conf.env['PLATFORM'] != 'win32':
- conf.CBRequireLib('stdc++')
- conf.CBRequireLib('m')
-
- conf.CBCheckLib('icuuc')
- conf.CBCheckLib('unwind-x86_64')
-
- if int(conf.env.get('static')) or int(conf.env.get('mostly_static')):
- conf.CBCheckLib('icudata')
- conf.CBCheckLib('unwind')
- conf.CBCheckLib('lzma')
-
- conf.CBRequireLib('ChakraCore')
-
- conf.CBRequireFunc('JsCreateRuntime')
-
- conf.env.CBDefine('HAVE_CHAKRA')
-
-
-def generate(env):
- env.CBAddConfigTest('chakra', configure)
-
-
-def exists():
- return 1
diff --git a/config/codesign/__init__.py b/config/codesign/__init__.py
new file mode 100644
index 000000000..852c5b350
--- /dev/null
+++ b/config/codesign/__init__.py
@@ -0,0 +1,188 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+''' codesign - macOS codesign/productsign functions '''
+
+import os, platform, shutil
+
+from SCons.Script import *
+from SCons.Action import CommandAction
+
+''' TODO
+Add builder Codesign(sources)
+ prog = env.Program(...)
+ sign = env.Codesign(prog)
+ Default(sign)
+ Depends(sign, prog)
+'''
+
+def UnlockKeychain(env, keychain=None, password=None):
+ if keychain is None: keychain = env.get('sign_keychain')
+ if keychain: name = keychain
+ else: name = 'default-keychain'
+ if password:
+ cmd = ['security', 'unlock-keychain', '-p', password]
+ if keychain: cmd += [keychain]
+ try:
+ sanitized_cmd = cmd[:3] + ['****']
+ if keychain: sanitized_cmd += [keychain]
+ print('@', sanitized_cmd)
+ # returns 0 if keychain already unlocked, even if pass is wrong
+ ret = CommandAction(cmd).execute(None, [], env)
+ if ret: raise Exception(
+ 'unlock-keychain failed, return code %s' % str(ret))
+ print('keychain "%s" is unlocked' % name)
+ except Exception as e:
+ print('unable to unlock keychain "%s"' % name)
+ raise e
+ else:
+ print('skipping unlock "%s"' % name + '; no password given')
+
+
+def SignExecutable(env, target):
+ if env.get('sign_disable'): return
+ keychain = env.get('sign_keychain')
+ sign = env.get('sign_id_app')
+ prefix = env.get('sign_prefix')
+ cmd = ['codesign', '-f', '--timestamp', '--options', 'runtime']
+ if keychain: cmd += ['--keychain', keychain]
+ if prefix:
+ if not prefix.endswith('.'): prefix += '.'
+ cmd += ['--prefix', prefix]
+ else:
+ raise Exception('unable to codesign %s; no sign_prefix given' % target)
+ if sign: cmd += ['--sign', sign]
+ else:
+ raise Exception('unable to codesign %s; no sign_id_app given' % target)
+ if not (os.path.isfile(target) and os.access(target, os.X_OK)):
+ raise Exception('unable to codesign %s; not an executable' % target)
+ # FIXME should not try to sign executable scripts
+ cmd += [target]
+ env.RunCommandOrRaise(cmd)
+
+
+def SignApplication(env, target):
+ if env.get('sign_disable'): return
+ keychain = env.get('sign_keychain')
+ sign = env.get('sign_id_app')
+ cmd = ['codesign', '-f', '--timestamp', '--options', 'runtime']
+ try:
+ ver = tuple([int(x) for x in platform.mac_ver()[0].split('.')])
+ # all bundles in an app must also be signed on 10.7+
+ # easy way to do this is just to codesign --deep
+ # only ok if there are no sandbox entitlements for this app
+ if ver >= (10,7): cmd += ['--deep']
+ except: pass
+ if keychain: cmd += ['--keychain', keychain]
+ if sign: cmd += ['--sign', sign]
+ else:
+ raise Exception('unable to codesign %s; no sign_id_app given' % target)
+ if not os.path.isdir(target) or not target.endswith('.app'):
+ raise Exception('unable to codesign %s; not an app' % target)
+ epath = os.path.join(target, 'Contents/Resources/entitlements.plist')
+ if os.path.isfile(epath): cmd += ['--entitlements', epath]
+ cmd += [target]
+ # sign any bundled libraries before singning app
+ # https://github.com/FoldingAtHome/fah-issues/issues/1576
+ # find libs under target dir, ignoring symlinks
+ paths = []
+ for root, dirs, files in os.walk(target):
+ for file in files:
+ e = os.path.splitext(file)[1]
+ if e in ('.so', '.dylib'):
+ path = os.path.join(root, file)
+ if not os.path.islink(path):
+ paths.append(path)
+ # sign each lib
+ for path in paths:
+ # some macports built libs are missing execute bits
+ if not os.access(path, os.X_OK):
+ print ('warning: setting execute perms on ' + path)
+ os.chmod(path, 0o755)
+ SignExecutable(env, path)
+ # finally, sign app
+ env.RunCommandOrRaise(cmd)
+
+
+def SignPackage(env, target, source):
+ # expect source 'somewhere/tmpname.pkg', target elsewhere/finalname.pkg
+ if env.get('sign_disable'): return
+ sign = env.get('sign_id_installer')
+ keychain = env.get('sign_keychain')
+ if not sign:
+ raise Exception('unable to sign; no sign_id_installer provided')
+ # FIXME should do more than this to verify flat pkg
+ x, ext = os.path.splitext(source)
+ if not (os.path.isfile(source) and ext in ('.pkg', '.mpkg')):
+ raise Exception('unable to sign; not a flat package: ' + source)
+ cmd = ['productsign','--timestamp', '--sign', sign]
+ if keychain: cmd += ['--keychain', keychain]
+ cmd += [source, target]
+ env.RunCommandOrRaise(cmd)
+
+
+def SignOrCopyPackage(env, target, source):
+ if env.get('sign_id_installer') and not env.get('sign_disable'):
+ SignPackage(env, target, source)
+ return
+ print('WARNING: NOT signing package %s; copying instead.' % source,
+ file=sys.stderr)
+ shutil.copy2(source, target)
+
+
+def generate(env):
+ if env['PLATFORM'] == 'darwin' or int(env.get('cross_osx', 0)):
+ env.CBAddVariables(
+ # put sign_* in scons_options.py (build.json)
+ # if not sign_keychain, the default (login) keychain will be used
+ # if not sign_id_installer, productsign will be skipped
+ # sign_id_app is required for sign_apps and sign_tools
+ # sign_prefix is required for sign_tools
+ # global; cannot currently be overridden per-component
+ BoolVariable('sign_disable', 'Disable codesign', 0),
+ ('sign_keychain', 'Keychain that has signatures'),
+ ('sign_id_installer', 'Installer signature name'),
+ ('sign_id_app', 'Application/Tool signature name'),
+ ('sign_prefix', 'codesign identifier prefix'),
+ )
+
+ env.AddMethod(UnlockKeychain)
+ env.AddMethod(SignExecutable)
+ env.AddMethod(SignApplication)
+ env.AddMethod(SignPackage)
+ env.AddMethod(SignOrCopyPackage)
+
+ return True
+
+
+def exists():
+ return 1
diff --git a/config/compiler/__init__.py b/config/compiler/__init__.py
index dc23cb47e..431a96dcc 100644
--- a/config/compiler/__init__.py
+++ b/config/compiler/__init__.py
@@ -1,4 +1,34 @@
-from __future__ import print_function
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
import copy
import re
@@ -29,8 +59,7 @@ def CheckRDynamic(context):
env = context.env
flags = env['LINKFLAGS']
context.env.AppendUnique(LINKFLAGS = ['-rdynamic'])
- result = context.TryLink('int main(int argc, char *argv[]) {return 0;}',
- '.c')
+ result = context.TryLink('int main() {return 0;}\n', '.c')
context.Result(result)
env['LINKFLAGS'] = flags
return result
@@ -41,68 +70,45 @@ def configure(conf, cstd = 'c99'):
if env.GetOption('clean'): return
# Get options
- cc = env.get('cc', '').strip()
- cxx = env.get('cxx', '').strip()
- ranlib = env.get('ranlib', '').strip()
- debug = int(env.get('debug'))
- optimize = int(env.get('optimize'))
+ cc = env.get('cc', '').strip()
+ cxx = env.get('cxx', '').strip()
+ ranlib = env.get('ranlib', '').strip()
+ ar = env.get('ar', '').strip()
+ strip = env.get('strip', '').strip()
+ debug = int(env.get('debug'))
+ optimize = int(env.get('optimize'))
if optimize == -1: optimize = not debug
- globalopt = int(env.get('globalopt'))
- mach = env.get('mach')
- auto_dispatch = int(env.get('auto_dispatch'))
- strict = int(env.get('strict'))
- threaded = int(env.get('threaded'))
- profile = int(env.get('profile'))
- tcmalloc = int(env.get('tcmalloc'))
- gperf = int(env.get('gperf'))
- depends = int(env.get('depends'))
- compiler = env.get('compiler')
- distcc = int(env.get('distcc'))
- ccache = int(env.get('ccache'))
- ccflags = env.get('ccflags')
- cxxflags = env.get('cxxflags')
- linkflags = env.get('linkflags')
- cxxstd = env.get('cxxstd')
- platform = env.get('platform')
- static = int(env.get('static'))
- num_jobs = env.get('num_jobs')
- osx_min_ver = env.get('osx_min_ver')
- osx_sdk_root = env.get('osx_sdk_root')
- osx_archs = env.get('osx_archs')
- win32_thread = env.get('win32_thread')
- cross_mingw = int(env.get('cross_mingw'))
-
- if cross_mingw:
- res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
- res_builder = \
- SCons.Builder.Builder(action = res_action, suffix='.o',
- source_scanner = SCons.Tool.SourceFileScanner)
- SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
-
- env['RC'] = 'windres'
- env['RCFLAGS'] = SCons.Util.CLVar('')
- env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, ' +\
- 'RCINCSUFFIX, __env__, RDirs, TARGET)} $)'
- env['RCINCPREFIX'] = '--include-dir '
- env['RCINCSUFFIX'] = ''
- env['RCCOM'] = '$RC $RCINCFLAGS $RCINCPREFIX $SOURCE.dir $RCFLAGS ' +\
- '-i $SOURCE -o $TARGET'
- env['BUILDERS']['RES'] = res_builder
- env['PROGSUFFIX'] = '.exe'
-
- env.CBDefine('WINVER=0x0600')
- env.CBDefine('_WIN32_WINNT=0x0600')
- env.CBDefine('_POSIX_SOURCE')
+ globalopt = int(env.get('globalopt'))
+ mach = env.get('mach')
+ strict = int(env.get('strict'))
+ threaded = int(env.get('threaded'))
+ profile = int(env.get('profile'))
+ tcmalloc = int(env.get('tcmalloc'))
+ gperf = int(env.get('gperf'))
+ depends = int(env.get('depends'))
+ compiler = env.get('compiler')
+ distcc = int(env.get('distcc'))
+ ccache = int(env.get('ccache'))
+ ccflags = env.get('ccflags')
+ cxxflags = env.get('cxxflags')
+ linkflags = env.get('linkflags')
+ libs = env.get('libs')
+ cxxstd = env.get('cxxstd')
+ dbgstdcxx = env.get('dbgstdcxx')
+ platform = env.get('platform')
+ static = int(env.get('static'))
+ num_jobs = env.get('num_jobs')
+ osx_min_ver = env.get('osx_min_ver')
+ osx_sdk_root = env.get('osx_sdk_root')
+ osx_archs = env.get('osx_archs')
+ win32_thread = env.get('win32_thread')
+ lto = env.get('lto')
if platform != '': env.Replace(PLATFORM = platform)
# Select compiler
compiler_mode = None
- # Prefer Intel compiler
- if compiler == 'default' and os.environ.get('INTEL_LICENSE_FILE', False):
- compiler = 'intel'
-
if compiler:
if compiler == 'gnu':
Tool('gcc')(env)
@@ -114,30 +120,6 @@ def configure(conf, cstd = 'c99'):
env.Replace(CXX = 'clang++')
compiler_mode = 'gnu'
- elif compiler == 'intel':
- Tool('intelc')(env)
- env['ENV']['INTEL_LICENSE_FILE'] = (
- os.environ.get('INTEL_LICENSE_FILE', ''))
-
- if env['PLATFORM'] == 'win32': compiler_mode = 'msvc'
- else: compiler_mode = 'gnu'
-
- if compiler_mode == 'msvc':
- env.Replace(AR = 'xilib')
-
- # Work around double CCFLAGS bug
- env.Replace(CXXFLAGS = ['/TP'])
-
- # Fix INCLUDE
- env.PrependENVPath('INCLUDE', os.environ.get('INCLUDE', ''))
-
- elif compiler == 'linux-mingw':
- env.Replace(CC = 'i586-mingw32msvc-gcc')
- env.Replace(CXX = 'i586-mingw32msvc-g++')
- env.Replace(RANLIB = 'i586-mingw32msvc-ranlib')
- env.Replace(PROGSUFFIX = '.exe')
- compiler_mode = 'gnu'
-
elif compiler == 'posix':
Tool('cc')(env)
Tool('cxx')(env)
@@ -146,16 +128,6 @@ def configure(conf, cstd = 'c99'):
Tool('as')(env)
compiler_mode = 'unknown'
- elif compiler in ['hp', 'sgi', 'sun', 'aix']:
- Tool(compiler + 'cc')(env)
- Tool(compiler + 'c++')(env)
- Tool(compiler + 'link')(env)
-
- if compiler in ['sgi', 'sun']:
- Tool(compiler + 'ar')(env)
-
- compiler_mode = 'unknown'
-
elif compiler != 'default':
Tool(compiler)(env)
@@ -169,21 +141,24 @@ def configure(conf, cstd = 'c99'):
_cc = env['CC']
if _cc == 'cl': compiler = 'msvc'
elif _cc == 'gcc': compiler = 'gnu'
- elif _cc == 'icl' or _cc == 'icc': compiler = 'intel'
if cc: env.Replace(CC = cc)
if cxx: env.Replace(CXX = cxx)
if ranlib: env.Replace(RANLIB = ranlib)
+ if ar: env.Replace(AR = ar)
+ if strip: env.Replace(STRIP = strip)
- env.__setitem__('compiler', compiler)
- env.__setitem__('compiler_mode', compiler_mode)
+ env['compiler'] = compiler
+ env['compiler_mode'] = compiler_mode
+ env['BUILD_MODE'] = 'debug' if debug else 'release'
- print(' Compiler:', env['CC'], '(%s)' % compiler)
- print(' Platform:', env['PLATFORM'])
- print(' Mode:', compiler_mode)
- print(' Arch:', env['TARGET_ARCH'])
+ print(' Compiler:', env['CC'], '(%s)' % compiler)
+ print(' Platform:', env['PLATFORM'])
+ print('Compiler Mode:', compiler_mode)
+ print(' Build Mode:', env['BUILD_MODE'])
+ print(' Arch:', env['TARGET_ARCH'])
- if compiler == 'gnu': print('GCC Version:', gcc_version_str(env))
+ if compiler == 'gnu': print(' GCC Version:', gcc_version_str(env))
# SCONS_JOBS environment variable
@@ -209,31 +184,17 @@ def configure(conf, cstd = 'c99'):
env.Replace(CC = 'ccache ' + env['CC'])
env.Replace(CXX = 'ccache ' + env['CXX'])
-
# Exceptions
if compiler_mode == 'msvc':
env.AppendUnique(CCFLAGS = ['/EHa']) # Asynchronous
# Disable troublesome warnings
- warnings = []
if compiler_mode == 'msvc':
env.CBDefine('_CRT_SECURE_NO_WARNINGS')
- warnings += [4297, 4103]
- if compiler == 'intel': warnings += [1786]
-
- if compiler == 'intel': warnings += [279]
-
- if compiler == 'intel':
- warnings = map(str, warnings)
- if compiler_mode == 'msvc':
- env.AppendUnique(CCFLAGS = ['/Qdiag-disable:' + ','.join(warnings)])
- else:
- env.AppendUnique(CCFLAGS = ['-diag-disable', ','.join(warnings)])
-
- elif compiler_mode == 'msvc':
- for warning in warnings: env.AppendUnique(CCFLAGS = ['/wd%d' % warning])
+ for warning in [4297, 4103]:
+ env.AppendUnique(CCFLAGS = ['/wd%d' % warning])
# Profiler flags
@@ -259,14 +220,15 @@ def configure(conf, cstd = 'c99'):
env.AppendUnique(prefer_dynamic = ['profiler'])
conf.CBRequireLib('profiler')
+ # Method overrides
+ if compiler == 'gnu' and strict:
+ env.AppendUnique(CXXFLAGS = ['-Wsuggest-override'])
# Debug flags
- if compiler_mode == 'msvc': env['PDB'] = '${TARGET}.pdb'
-
if debug:
if compiler_mode == 'msvc':
env.AppendUnique(CCFLAGS = ['/W1'])
- env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
+ env['PDB'] = '${TARGET}.pdb'
env.AppendUnique(LINKFLAGS = ['/DEBUG', '/MAP:${TARGET}.map'])
elif compiler_mode == 'gnu':
@@ -274,8 +236,6 @@ def configure(conf, cstd = 'c99'):
env.AppendUnique(CCFLAGS = ['-g', '-Wall'])
if conf.CheckRDynamic():
env.AppendUnique(LINKFLAGS = ['-rdynamic']) # for backtrace
- elif compiler == 'intel':
- env.AppendUnique(CCFLAGS = ['-g', '-diag-enable', 'warn'])
else: # clang and others
env.AppendUnique(CCFLAGS = ['-g', '-Wall'])
@@ -283,17 +243,14 @@ def configure(conf, cstd = 'c99'):
env.CBDefine('DEBUG')
- if not optimize and compiler == 'intel' and \
- env['TARGET_ARCH'] == 'x86':
- if compiler_mode == 'gnu':
- env.AppendUnique(CCFLAGS = ['-mia32'])
- elif compiler_mode == 'msvc':
- env.AppendUnique(CCFLAGS = ['/arch:IA32'])
+ else: # !debug
+ if compiler_mode == 'gnu': # Strip symbols
+ if compiler != 'clang': env.AppendUnique(LINKFLAGS = ['-Wl,-s'])
+ env.AppendUnique(LINKFLAGS = ['-Wl,-x'])
- else:
- if compiler_mode == 'gnu':
- # Don't add debug info and enable dead code removal
- env.AppendUnique(LINKFLAGS = ['-Wl,-S', '-Wl,-x'])
+ if lto and compiler == 'gnu': # Link time optimization
+ env.AppendUnique(LINKFLAGS = ['-flto=auto'])
+ env.AppendUnique(CCFLAGS = ['-flto=auto'])
env.CBDefine('NDEBUG')
@@ -301,87 +258,42 @@ def configure(conf, cstd = 'c99'):
# Optimizations
if optimize:
if compiler_mode == 'gnu':
- env.AppendUnique(CCFLAGS = ['-O3', '-funroll-loops'])
+ env.AppendUnique(CCFLAGS = ['-O3'])
elif compiler_mode == 'msvc':
- env.AppendUnique(CCFLAGS = ['/Ox'])
- if compiler == 'intel' and not globalopt:
- env.AppendUnique(LINKFLAGS = ['/Qnoipo'])
+ env.AppendUnique(CCFLAGS = ['/O2', '/Zc:throwingNew'])
# Whole program optimizations
if globalopt:
- if compiler == 'intel':
- if compiler_mode == 'gnu':
- env.AppendUnique(LINKFLAGS = ['-ipo'])
- env.AppendUnique(CCFLAGS = ['-ipo'])
- elif compiler_mode == 'msvc':
- env.AppendUnique(LINKFLAGS = ['/Qipo'])
- env.AppendUnique(CCFLAGS = ['/Qipo'])
-
- elif compiler == 'msvc':
+ if compiler == 'msvc':
env.AppendUnique(CCFLAGS = ['/GL'])
env.AppendUnique(LINKFLAGS = ['/LTCG'])
env.AppendUnique(ARFLAGS = ['/LTCG'])
# Instruction set optimizations
- if compiler == 'intel':
- if env['TARGET_ARCH'].lower() in ('64bit', 'x64', 'amd64'):
- opt_base, opt_auto = 'SSE2', 'SSE3,SSSE3,SSE4.1,SSE4.2'
- else: opt_base, opt_auto = 'SSE', 'SSE2,SSE3,SSSE3,SSE4.1,SSE4.2'
-
- if mach: opt_base = mach
-
- if compiler_mode == 'gnu':
- env.AppendUnique(CCFLAGS = ['-m' + opt_base.lower()])
- if auto_dispatch:
- env.AppendUnique(CCFLAGS = ['-ax' + opt_auto])
-
- elif compiler_mode == 'msvc':
- env.AppendUnique(CCFLAGS = ['/arch:' + opt_base.upper()])
- if auto_dispatch:
- env.AppendUnique(CCFLAGS = ['/Qax' + opt_auto])
-
- elif compiler == 'msvc':
+ if compiler == 'msvc':
if mach: env.AppendUnique(CCFLAGS = ['/arch:' + mach.upper()])
elif mach: env.AppendUnique(CCFLAGS = ['-m' + mach.lower()])
- # Intel threading optimizations
- if compiler == 'intel':
- if compiler_mode == 'msvc':
- env.AppendUnique(CCFLAGS = ['/Qopenmp'])
- else:
- env.AppendUnique(CCFLAGS = ['-openmp'])
-
- if compiler_mode == 'msvc': env.PrependUnique(LIBS = ['libiomp5mt'])
- else: env.PrependUnique(LIBS = ['iomp5'])
-
-
- # Pointer disambiguation
- if compiler == 'intel':
- if compiler_mode == 'gnu':
- env.AppendUnique(CCFLAGS = ['-restrict'])
- elif compiler_mode == 'msvc':
- env.AppendUnique(CCFLAGS = ['/Qrestrict'])
+ # Position independent code
+ if env['PLATFORM'] != 'win32': env.AppendUnique(CCFLAGS = ['-fPIC'])
+ if (compiler_mode == 'gnu' and (5,) <= gcc_version(env) and
+ compiler != 'clang'): env.AppendUnique(LINKFLAGS = '-no-pie')
+ # Alignment
+ if compiler_mode == 'gnu' and (7,) <= gcc_version(env):
+ if not (compiler == 'clang' and env['PLATFORM'] == 'darwin'):
+ env.AppendUnique(CXXFLAGS = ['-faligned-new'])
# Dependency files
if depends and compiler_mode == 'gnu':
env.AppendUnique(CCFLAGS = ['-MMD -MF ${TARGET}.d'])
- # No PIE with GCC 6+
- if compiler_mode == 'gnu' and (5,) <= gcc_version(env):
- env.AppendUnique(CCFLAGS = '-fno-pie')
- env.AppendUnique(LINKFLAGS = '-no-pie')
-
-
# C mode
- if cstd:
- if compiler_mode == 'gnu':
- env.AppendUnique(CFLAGS = ['-std=' + cstd])
- elif compiler_mode == 'msvc' and compiler == 'intel':
- env.AppendUnique(CFLAGS = ['/Qstd=' + cstd])
+ if cstd and compiler_mode == 'gnu':
+ env.AppendUnique(CFLAGS = ['-std=' + cstd])
# C++ mode
if cxxstd:
@@ -391,6 +303,12 @@ def configure(conf, cstd = 'c99'):
if cxxstd in ('c++14', 'c++17', 'c++20'):
env.AppendUnique(CXXFLAGS = ['/std:' + cxxstd])
+ # GNU libstdc++ debugging
+ if dbgstdcxx and compiler_mode == 'gnu':
+ env.CBDefine('_GLIBCXX_DEBUG')
+ env.CBDefine('_GLIBCXX_DEBUG_BACKTRACE')
+ conf.CBRequireLib('stdc++_libbacktrace')
+
# Threads
if threaded:
@@ -411,68 +329,65 @@ def configure(conf, cstd = 'c99'):
# Link flags
if compiler_mode == 'msvc' and not optimize:
- env.AppendUnique(LINKFLAGS = ['/INCREMENTAL'])
-
- if compiler_mode == 'msvc' or int(env.get('cross_mingw', 0)):
- if env.get('compiler_mode') == 'gnu':
- env.Append(LINKFLAGS = ['-Wl,-subsystem,${subsystem}'])
-
- elif env.get('compiler_mode') == 'msvc':
- env.Append(LINKFLAGS = [
- '/subsystem:${subsystem},${subsystem_version}'])
+ env.AppendUnique(LINKFLAGS = ['/INCREMENTAL:NO'])
+ if compiler_mode == 'msvc':
+ env.Append(LINKFLAGS = ['/subsystem:${subsystem},${subsystem_version}'])
# static
if static:
if compiler_mode == 'gnu' and env['PLATFORM'] != 'darwin':
env.AppendUnique(LINKFLAGS = ['-static'])
+ elif env.get('mostly_static', False) and compiler == 'gnu':
+ env.AppendUnique(LINKFLAGS = ['-static-libstdc++', '-static-libgcc'])
+
+
+ # Don't link unneeded dynamic libs
+ if compiler == 'gnu' and env['PLATFORM'] != 'darwin':
+ env.PrependUnique(LINKFLAGS = ['-Wl,--as-needed'])
+
+ # For windows
+ if compiler_mode == 'msvc': env.CBDefine('NOMINMAX')
# For darwin
- if env['PLATFORM'] == 'darwin' or int(env.get('cross_osx', 0)):
+ if env['PLATFORM'] == 'darwin':
env.CBDefine('__APPLE__')
- if osx_archs and compiler == 'gnu':
+
+ if osx_archs and compiler_mode == 'gnu':
# note: only apple compilers support multipe -arch options
for arch in osx_archs.split():
env.Append(CCFLAGS = ['-arch', arch])
env.Append(LINKFLAGS = ['-arch', arch])
+
if osx_min_ver:
flag = '-mmacosx-version-min=' + osx_min_ver
env.AppendUnique(LINKFLAGS = [flag])
env.AppendUnique(CCFLAGS = [flag])
+
if osx_sdk_root:
env.Append(CCFLAGS = ['-isysroot', osx_sdk_root])
- # intel linker allegedly requires -isyslibroot
- # but that seems to confuse gcc
if compiler == 'gnu':
env.Append(LINKFLAGS = ['-isysroot', osx_sdk_root])
- elif compiler == 'intel':
- # untested
- #env.Append(LINKFLAGS = ['-Wl,-isyslibroot,' + osx_sdk_root])
- pass
-
- if int(env.get('cross_osx', 0)):
- env['FRAMEWORKPATHPREFIX'] = '-F'
- env['_FRAMEWORKPATH'] = \
- '${_concat(FRAMEWORKPATHPREFIX, FRAMEWORKPATH, "", __env__)}'
- env['_FRAMEWORKS'] = \
- '${_concat("-framework ", FRAMEWORKS, "", __env__)}'
- env['LINKCOM'] = env['LINKCOM'] + \
- ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
- env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -dynamiclib')
- env['SHLINKCOM'] = env['SHLINKCOM'] + \
- ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
- env['LDMODULEPREFIX'] = ''
- env['LDMODULESUFFIX'] = ''
- env['LDMODULEFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -bundle')
- env['LDMODULECOM'] = '$LDMODULE -o ${TARGET} $LDMODULEFLAGS ' + \
- '$SOURCES $_LIBDIRFLAGS $_LIBFLAGS $_FRAMEWORKPATH ' + \
- '$_FRAMEWORKS $FRAMEWORKSFLAGS'
+
+ env.Replace(ARCOM = 'rm -f $TARGET; $AR $ARFLAGS $TARGET $SOURCES')
+
+ # Both gcc and clang treat signedness of char depending on target platform.
+ # For Intel x86 and x86_64, it's a signed type by default.
+ # For ARM (including AArch64), it's an unsigned type by default.
+ # There are several places in the code, where 'char' implicitly assumed to
+ # be a signed type. The simplest way to avoid problems in such a case is to
+ # ask the compiler to treat the 'char" as a signed type regardless of target
+ # platform.
+ if compiler_mode == 'gnu':
+ env.Append(CFLAGS = ['-fsigned-char'])
+ env.Append(CXXFLAGS = ['-fsigned-char'])
# User flags (Must be last)
if ccflags: env.Append(CCFLAGS = ccflags.split())
if cxxflags: env.Append(CXXFLAGS = cxxflags.split())
if linkflags: env.Append(LINKFLAGS = linkflags.split())
+ if libs: env.Append(LIBS = libs.split())
def get_lib_path_env(env):
@@ -551,7 +466,7 @@ def prefer_static_libs(env):
def CBConfConsole(env, entry = 'mainCRTStartup'):
- if env['PLATFORM'] == 'win32' or int(env.get('cross_mingw', 0)):
+ if env['PLATFORM'] == 'win32':
env.Replace(subsystem = 'windows')
if env.get('compiler_mode') == 'msvc':
@@ -564,18 +479,19 @@ def generate(env):
env.CBAddConfigFinishCB(prefer_static_libs)
env.AddMethod(CBConfConsole)
- env.SetDefault(PREFER_DYNAMIC = 'pthread dl'.split())
+ env.SetDefault(PREFER_DYNAMIC = 'pthread dl rt'.split())
env.SetDefault(PREFER_STATIC = [])
env.SetDefault(REQUIRE_STATIC = [])
env.CBAddVariables(
('cc', 'Set C compiler executable', ''),
('cxx', 'Set C++ compiler executable', ''),
+ ('ar', 'Set ar executable', ''),
('ranlib', 'Set ranlib executable', ''),
+ ('strip', 'Set strip executable', ''),
('optimize', 'Enable or disable optimizations', -1),
('globalopt', 'Enable or disable global optimizations', 0),
('mach', 'Set machine instruction set', ''),
- ('auto_dispatch', 'Enable auto-dispatch of optimized code paths', 1),
BoolVariable('debug', 'Enable or disable debug options',
os.getenv('DEBUG_MODE', 0)),
BoolVariable('strict', 'Enable or disable strict options', 1),
@@ -586,18 +502,20 @@ def generate(env):
BoolVariable('depends', 'Enable or disable dependency files', 0),
BoolVariable('distcc', 'Enable or disable distributed builds', 0),
BoolVariable('ccache', 'Enable or disable cached builds', 0),
+ BoolVariable('lto', 'Enable or disable link-time optimization', 0),
EnumVariable('platform', 'Override default platform', '',
- allowed_values = ('', 'win32', 'posix', 'darwin')),
+ allowed_values = ('', 'win32', 'posix', 'darwin')),
('ccflags', 'Set extra C and C++ compiler flags', None),
('cxxflags', 'Set extra C++ compiler flags', None),
('linkflags', 'Set extra linker flags', None),
- EnumVariable('cxxstd', 'Set C++ language standard', 'c++11',
- allowed_values = ('c++98', 'c++11', 'c++14', 'c++17',
- 'c++20')),
- EnumVariable('compiler', 'Select compiler', 'default',
- allowed_values = ('default', 'gnu', 'intel', 'mingw', 'msvc',
- 'linux-mingw', 'aix', 'posix', 'hp', 'sgi',
- 'sun', 'clang')),
+ ('libs', 'Set extra libs', None),
+ EnumVariable(
+ 'cxxstd', 'Set C++ language standard', 'c++17',
+ allowed_values = ('c++98', 'c++11', 'c++14', 'c++17', 'c++20')),
+ BoolVariable('dbgstdcxx', 'Enable GNU libstdc++ debugging', 0),
+ EnumVariable(
+ 'compiler', 'Select compiler', 'default',
+ allowed_values = ('default', 'gnu', 'msvc', 'posix', 'clang')),
BoolVariable('static', 'Link to static libraries', 0),
BoolVariable('mostly_static', 'Prefer static libraries', 0),
('prefer_static', 'Libraries where the static version is prefered', ''),
@@ -605,16 +523,15 @@ def generate(env):
('prefer_dynamic', 'Libraries where the dynamic version is prefered, ' +
'regardless of "mostly_static"', ''),
('num_jobs', 'Set the concurrency level.', -1),
- ('osx_min_ver', 'Set minimum support OSX version.', '10.6'),
+ ('osx_min_ver', 'Set minimum supported OSX version.', None),
('osx_sdk_root', 'Set OSX SDK root.', None),
- ('osx_archs', 'Set OSX gcc target architectures.', 'x86_64'),
- EnumVariable('win32_thread', 'Windows thread mode.', 'static',
- allowed_values = ('static', 'dynamic')),
- BoolVariable('cross_mingw', 'Enable mingw cross compile mode', 0),
- BoolVariable('cross_osx', 'Enable OSX cross compile mode', 0),
- EnumVariable('subsystem', 'Windows subsystem', 'console',
- allowed_values = ('windows', 'console', 'posix',
- 'native')),
+ ('osx_archs', 'Set OSX gcc target architectures.', None),
+ EnumVariable(
+ 'win32_thread', 'Windows thread mode.', 'static',
+ allowed_values = ('static', 'dynamic')),
+ EnumVariable(
+ 'subsystem', 'Windows subsystem', 'console',
+ allowed_values = ('windows', 'console', 'posix', 'native')),
('subsystem_version', 'Windows subsystem version', 6)
)
diff --git a/config/deb/__init__.py b/config/deb/__init__.py
index 7d18f1814..c0399c032 100644
--- a/config/deb/__init__.py
+++ b/config/deb/__init__.py
@@ -1,9 +1,42 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from __future__ import print_function
import os
import shutil
import string
import math
+import subprocess
from SCons.Script import *
from SCons.Action import CommandAction
@@ -17,36 +50,32 @@ def get_total_file_size(path):
return total
-def replace_underscore(s):
- return s.replace('_', '-')
+def replace_underscore(s): return s.replace('_', '-')
def write_control(path, env, installed_size):
- f = None
- try:
- f = open(path, 'w')
-
+ with open(path, 'w') as f:
write_var = env.WriteVariable
- write_var(env, f, 'Package', 'package_name_lower', None,
+ write_var(env, f, 'Package', 'package_name_lower', None,
replace_underscore)
- write_var(env, f, 'Version', 'version', None, replace_underscore)
+ write_var(env, f, 'Version', 'version', None, replace_underscore)
write_var(env, f, 'Standards-Version', 'deb_standards_version')
- write_var(env, f, 'Maintainer', 'maintainer')
- write_var(env, f, 'Priority', 'deb_priority')
- write_var(env, f, 'Section', 'deb_section')
- write_var(env, f, 'Bugs', 'bug_url')
- write_var(env, f, 'Homepage', 'url')
- write_var(env, f, 'Essential', 'deb_essential')
+ write_var(env, f, 'Maintainer', 'maintainer')
+ write_var(env, f, 'Priority', 'deb_priority')
+ write_var(env, f, 'Section', 'deb_section')
+ write_var(env, f, 'Bugs', 'bug_url')
+ write_var(env, f, 'Homepage', 'url')
+ write_var(env, f, 'Essential', 'deb_essential')
write_var(env, f, 'Distribution', 'deb_distribution')
- write_var(env, f, 'Depends', 'deb_depends')
- write_var(env, f, 'Pre-Depends', 'deb_pre_depends')
- write_var(env, f, 'Recommends', 'deb_recommends')
- write_var(env, f, 'Suggests', 'deb_suggests')
- write_var(env, f, 'Breaks', 'deb_breaks')
- write_var(env, f, 'Conflicts', 'deb_conflicts')
- write_var(env, f, 'Provides', 'deb_provides')
- write_var(env, f, 'Replaces', 'deb_replaces')
- write_var(env, f, 'Enhances', 'deb_enhances')
+ write_var(env, f, 'Depends', 'deb_depends')
+ write_var(env, f, 'Pre-Depends', 'deb_pre_depends')
+ write_var(env, f, 'Recommends', 'deb_recommends')
+ write_var(env, f, 'Suggests', 'deb_suggests')
+ write_var(env, f, 'Breaks', 'deb_breaks')
+ write_var(env, f, 'Conflicts', 'deb_conflicts')
+ write_var(env, f, 'Provides', 'deb_provides')
+ write_var(env, f, 'Replaces', 'deb_replaces')
+ write_var(env, f, 'Enhances', 'deb_enhances')
write_var(env, f, 'Architecture', 'package_arch', env.GetPackageArch())
f.write('Installed-Size: %d\n' % math.ceil(installed_size / 1024))
@@ -57,10 +86,6 @@ def write_control(path, env, installed_size):
f.write(' %s\n' % line)
- finally:
- if f is not None: f.close()
-
-
def install_files(env, key, target, perms = 0o644, dperms = 0o755):
if key in env: env.CopyToPackage(env.get(key), target, perms, dperms)
@@ -92,23 +117,19 @@ def build_function(target, source, env):
install_files(env, 'icons', build_dir + '/usr/share/pixmaps')
install_files(env, 'mime', build_dir + '/usr/share/mime/packages')
install_files(env, 'platform_independent', build_dir + '/usr/share/' + name)
+ install_files(env, 'misc', build_dir)
+ install_files(env, 'systemd', build_dir + '/lib/systemd/system')
# Dirs
docs_dir = build_dir + '/usr/share/doc/' + name
# Create conffiles
- filename = build_dir + '/DEBIAN/conffiles'
- f = None
- try:
- conffiles = get_files(env, 'init_d', '/etc/init.d')
- if conffiles is not None:
+ conffiles = get_files(env, 'init_d', '/etc/init.d')
+ if conffiles:
+ def opener(path, flags): return os.open(path, flags, 0o644)
+ with open(build_dir + '/DEBIAN/conffiles', 'w', opener = opener) as f:
for src, dst, mode in conffiles:
- if f is None: f = open(filename, 'w')
f.write(dst + '\n')
- finally:
- if f is not None:
- f.close()
- os.chmod(filename, 0o644)
# Debian changelog
changelog = build_dir + '/DEBIAN/changelog'
@@ -136,9 +157,33 @@ def build_function(target, source, env):
# Strip exectuables
if not int(env.get('debug')):
- for src, dst, mode in get_files(env, 'programs',
- build_dir + '/usr/bin'):
- CommandAction('strip ' + dst).execute(dst, [dst], env)
+ for src, dst, mode in get_files(
+ env, 'programs', build_dir + '/usr/bin'):
+ CommandAction(
+ env.get('STRIP', 'strip') + ' ' + dst).execute(dst, [dst], env)
+
+ # Library dependencies
+ if 'programs' in env:
+ progs = ['usr/bin/' + os.path.basename(prog) for prog in env.get('programs')]
+
+ # dummy debian/control required
+ os.makedirs(build_dir + '/debian', 0o755)
+ open(build_dir + '/debian/control', 'w').close()
+
+ proc = subprocess.run(['/usr/bin/dpkg-shlibdeps',
+ '--ignore-missing-info', '-O'] + progs,
+ stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
+ cwd=build_dir, universal_newlines=True)
+
+ if proc.stdout:
+ libdeps = proc.stdout[len('shlibs:Depends='):].strip()
+ print('library dependencies: %s' % libdeps)
+
+ # env.Append() does not appear to work with pre-existing strings
+ if env.get('deb_depends'): env['deb_depends'] += ', ' + libdeps
+ else: env.Append(deb_depends = libdeps)
+
+ shutil.rmtree(build_dir + '/debian')
# Create debian control
total_size = get_total_file_size(build_dir)
diff --git a/config/dist/__init__.py b/config/dist/__init__.py
index e889d0dd3..4efdb8312 100644
--- a/config/dist/__init__.py
+++ b/config/dist/__init__.py
@@ -1,6 +1,39 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
import sys
import tarfile
+import zipfile
import re
import platform
import time
@@ -9,14 +42,15 @@
def find_files(path, exclude = None):
if not os.path.exists(path): return []
- if exclude:
- dir, filename = os.path.split(path)
- if exclude.match(filename): return []
- if not os.path.isdir(path): return [path]
+ dir, filename = os.path.split(path)
+
+ if exclude and exclude.match(filename): return []
+ if not os.path.isdir(path): return [(path, filename)]
files = []
for f in os.listdir(path):
- files += find_files(path + '/' + f, exclude)
+ children = find_files(path + '/' + f, exclude)
+ files += [(path, filename + '/' + name) for path, name in children]
return files
@@ -24,54 +58,85 @@ def find_files(path, exclude = None):
def modify_targets(target, source, env):
if env.get('debug', False): mode = 'debug'
else: mode = 'release'
+ mode = env.get('PACKAGE_MODE', mode)
dist_ver = env.get('dist_version', env.subst('$PACKAGE_VERSION'))
vars = {
- 'machine' : platform.machine(),
- 'bits' : platform.architecture()[0],
- 'system' : platform.system(),
- 'release' : platform.release(),
- 'version' : dist_ver,
- 'date' : time.strftime('%Y%m%d'),
- 'mode' : mode,
+ 'machine': platform.machine(),
+ 'bits': platform.architecture()[0],
+ 'system': platform.system(),
+ 'release': platform.release(),
+ 'version': dist_ver,
+ 'date': time.strftime('%Y%m%d'),
+ 'mode': mode,
}
build = env.get('dist_build')
if len(build) and build[0] not in '-_': build = '_' + build
if len(dist_ver): build = '_' + dist_ver + build
- target = ((str(target[0]) + build) % vars % env._dict) + '.tar.bz2'
+ target = ((str(target[0]) + build) % vars % env._dict) + '.tar'
return [target.lower(), source]
+def modify_targets_bz2(target, source, env):
+ target, source = modify_targets(target, source, env)
+ return [target + '.bz2', source]
+
+
+def modify_targets_zip(target, source, env):
+ target, source = modify_targets(target, source, env)
+ target = target[:-3] + 'zip'
+ return [target, source]
+
+
def build_function(target, source, env):
target = str(target[0])
# Write 'dist.txt'
- f = None
- try:
- f = open('dist.txt', 'w')
- f.write(target)
- finally:
- if f is not None: f.close()
+ with open('dist.txt', 'w') as f: f.write(target)
+
+ m = re.match(r'^(.*)\.tar(\.\w+)?$', target)
+ dist_name = m.group(1)
+
+ mode = 'w:bz2' if target.endswith('.bz2') else 'w'
+
+ with tarfile.open(target, mode = mode) as tar:
+ exclude_pats = env.get('DIST_EXCLUDES')
+ exclude_re = re.compile('^((' + ')|('.join(exclude_pats) + '))$')
+
+ for src in map(str, source):
+ for path, name in find_files(src, exclude_re):
+ tar.add(path, dist_name + '/' + name)
+
+
+def build_function_zip(target, source, env):
+ target = str(target[0])
+
+ # Write 'dist.txt'
+ with open('dist.txt', 'w') as f: f.write(target)
- dist_name = os.path.splitext(os.path.splitext(target)[0])[0]
+ m = re.match(r'^(.*)\.zip$', target)
+ dist_name = m.group(1)
- tar = tarfile.open(target, mode = 'w:bz2')
+ compression = env.get('compression', zipfile.ZIP_DEFLATED)
+ if compression is None: compression = zipfile.ZIP_STORED
- exclude_pats = env.get('DIST_EXCLUDES')
- exclude_re = re.compile('^((' + ')|('.join(exclude_pats) + '))$')
+ with zipfile.ZipFile(target, mode = 'w', compression = compression) as zip:
+ exclude_pats = env.get('DIST_EXCLUDES')
+ exclude_re = re.compile('^((' + ')|('.join(exclude_pats) + '))$')
- for src in map(str, source):
- for file in find_files(src, exclude_re):
- tar.add(file, dist_name + '/' + file)
+ for src in map(str, source):
+ for path, name in find_files(src, exclude_re):
+ zip.write(path, dist_name + '/' + name)
def generate(env):
env.SetDefault(DIST_EXCLUDES = [r'\.svn', r'\.sconsign.dblite', r'.*\.obj',
- r'\.sconf_temp', r'.*~', r'.*\.o'])
+ r'\.sconf_temp', r'.*~', r'.*\.o',
+ r'\.DS_Store'])
env.CBAddVariables(
('dist_version', 'Set dist file version', None),
@@ -81,7 +146,18 @@ def generate(env):
source_factory = SCons.Node.FS.Entry,
source_scanner = SCons.Defaults.DirScanner,
emitter = modify_targets)
- env.Append(BUILDERS = {'TarBZ2Dist' : bld})
+ bld_bz2 = Builder(action = build_function,
+ source_factory = SCons.Node.FS.Entry,
+ source_scanner = SCons.Defaults.DirScanner,
+ emitter = modify_targets_bz2)
+ bld_zip = Builder(action = build_function_zip,
+ source_factory = SCons.Node.FS.Entry,
+ source_scanner = SCons.Defaults.DirScanner,
+ emitter = modify_targets_zip)
+
+ env.Append(BUILDERS = {'ZipDist' : bld_zip})
+ env.Append(BUILDERS = {'TarBZ2Dist' : bld_bz2})
+ env.Append(BUILDERS = {'TarDist' : bld})
return True
diff --git a/config/distpkg/__init__.py b/config/distpkg/__init__.py
deleted file mode 100644
index 49098fba1..000000000
--- a/config/distpkg/__init__.py
+++ /dev/null
@@ -1,155 +0,0 @@
-'''
-Builds an OSX distribution package
-'''
-
-import os
-import shutil
-
-from SCons.Script import *
-
-
-def build_function(target, source, env):
- target = str(target[0])
-
- # Create package build dir
- if target[-4:] != '.zip': raise Exception('Expected .zip in package name')
- build_dir = target[:-4] # Remove .zip
- if os.path.exists(build_dir): shutil.rmtree(build_dir)
-
- # Make dirs
- contents_dir = os.path.join(build_dir, 'Contents')
- packages_dir = os.path.join(contents_dir, 'Packages')
- resources_dir = os.path.join(contents_dir, 'Resources')
- for d in (contents_dir, packages_dir, resources_dir): os.makedirs(d, 0o775)
-
- # Load package info
- pkg_info = []
- packages = env.get('distpkg_packages', [])
- for p in packages:
- infofile = os.path.join(p, 'Contents/Info.plist')
- if os.path.exists(infofile):
- import plistlib
- pkg_info.append(plistlib.readPlist(infofile))
- else: raise Exception('Missing %s' % infofile)
-
- # Create distribution.dist
- from xml.etree.ElementTree import ElementTree, Element, SubElement
- root = Element('installer-script', {'minSpecVersion': '1.0'})
-
- if env.get('distpkg_root_volume_only', False): rootVolumeOnly = 'false'
- else: rootVolumeOnly = 'true'
- if env.get('distpkg_allow_external_scripts', False):
- allowExternalScripts = 'yes'
- else: allowExternalScripts = 'no'
-
- SubElement(root, 'options', {
- 'rootVolumeOnly': rootVolumeOnly,
- 'allow-external-scripts': allowExternalScripts,
- 'customize': env.get('distpkg_customize', 'allow'),
- })
-
- SubElement(root, 'title').text = env.get('summary')
- for key in 'conclusion license readme welcome'.split():
- if 'distpkg_' + key in env:
- SubElement(root, key, {'file': env.get('distpkg_' + key)})
-
- background = env.get('distpkg_background', None)
- if background:
- SubElement(root, 'background', {
- 'file': background,
- 'alignment': 'bottomleft',
- 'scaling': 'none',
- })
-
- pkg_target = env.get('distpkg_target', '10.5')
- pkg_arch = env.get('distpkg_arch', None)
- SubElement(root, 'installation-check', {'script': 'pm_install_check();'})
- SubElement(root, 'volume-check', {'script': 'pm_volume_check();'})
- script_text = """
-function pm_volume_check() {
- if(!(my.target.systemVersion &&
- system.compareVersions(my.target.systemVersion.ProductVersion, '""" + \
- pkg_target + """') >= 0)) {
- my.result.title = 'Unable to Install';
- my.result.message = 'OSX """ + pkg_target + """ or later is required.';
- my.result.type = 'Fatal';
- return false;
- }
- return true;
-}
-function pm_install_check() {
- if((system.sysctl('hw.cputype') == '18')) {
- my.result.title = 'Unable to Install';
- my.result.message = 'An intel-based Mac is required.';
- my.result.type = 'Fatal';
- return false;
- }"""
- if pkg_arch == 'x86_64':
- script_text += """
- if(system.sysctl('hw.optional.x86_64') == false) {
- my.result.title = 'Unable to Install';
- my.result.message = 'A 64-bit cpu is required (core 2 duo or better).';
- my.result.type = 'Fatal';
- return false;
- }"""
- script_text += """
- return true;
-}
-"""
- SubElement(root, 'script').text = script_text
-
- outline = SubElement(root, 'choices-outline')
- for i in range(len(pkg_info)):
- info = pkg_info[i]
- id = info['CFBundleIdentifier']
- choice_id = 'choice' + str(i)
- choice_title = os.path.basename(packages[i])
- SubElement(outline, 'line', {'choice': choice_id})
-
- choice = SubElement(root, 'choice', {
- 'id': choice_id,
- 'title': choice_title,
- 'description': '',
- })
-
- SubElement(choice, 'pkg-ref', {'id': id})
-
- pkg_path = 'file:./Contents/Packages/' + os.path.basename(packages[i])
- pkg_ref_info = {
- 'id': id,
- 'installKBytes': str(info['IFPkgFlagInstalledSize']),
- 'version': info['CFBundleShortVersionString'],
- }
- try:
- if info['IFPkgFlagAuthorizationAction'] == 'RootAuthorization':
- pkg_ref_info['auth'] = 'Root'
- except: pass
- SubElement(root, 'pkg-ref', pkg_ref_info).text = pkg_path
-
- tree = ElementTree(root)
- f = None
- try:
- f = open(contents_dir + '/distribution.dist', 'w')
- tree.write(f, 'utf-8')
- finally:
- if f is not None: f.close()
-
- # Install files
- env.InstallFiles('distpkg_resources', resources_dir)
- env.InstallFiles('distpkg_packages', packages_dir, perms = 0)
-
- # Zip results
- env.ZipDir(target, build_dir)
-
-
-def generate(env):
- bld = Builder(action = build_function,
- source_factory = SCons.Node.FS.Entry,
- source_scanner = SCons.Defaults.DirScanner)
- env.Append(BUILDERS = {'DistPkg' : bld})
-
- return True
-
-
-def exists():
- return 1
diff --git a/config/event/__init__.py b/config/event/__init__.py
index 1625f4f9d..bc3a26fdb 100644
--- a/config/event/__init__.py
+++ b/config/event/__init__.py
@@ -1,9 +1,41 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
def configure(conf):
conf.CBCheckHome('event', lib_suffix = ['/src'], inc_suffix = ['/include'])
- conf.CBRequireHeader('event.h')
+ conf.CBRequireHeader('event2/event.h')
conf.CBRequireLib('event')
diff --git a/config/expat/__init__.py b/config/expat/__init__.py
index 7db05bb2a..0b1ce9fb0 100644
--- a/config/expat/__init__.py
+++ b/config/expat/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
@@ -15,8 +47,6 @@ def configure(conf):
else: conf.CBRequireLib('expat')
- env.CBDefine('HAVE_EXPAT')
-
def generate(env):
env.CBAddConfigTest('expat', configure)
diff --git a/config/find_dlls/__init__.py b/config/find_dlls/__init__.py
index 37d88b981..b4266d818 100644
--- a/config/find_dlls/__init__.py
+++ b/config/find_dlls/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
import sys
import re
diff --git a/config/flatdistpkg/__init__.py b/config/flatdistpkg/__init__.py
index 63df2090b..a9326336b 100644
--- a/config/flatdistpkg/__init__.py
+++ b/config/flatdistpkg/__init__.py
@@ -1,154 +1,114 @@
-# flatdistpkg.py
-from __future__ import print_function
-
-import os, platform, shutil
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+''' flatdistpkg '''
+
+import os
+import shutil
+import glob
+import re
import config
import zipfile
+import mimetypes
+mimetypes.init()
from SCons.Script import *
-from SCons.Action import CommandAction
import glob
-try:
- import json
-except ImportError:
- import simplejson as json
-from pprint import pprint
+import json
+deps = ['codesign', 'notarize', 'compiler']
-filename_package_build_txt = 'package.txt'
-filename_package_desc_txt = 'package-description.txt'
-filename_package_info_json = 'package-parameters.json'
filename_distribution_xml = 'distribution.xml'
-build_dir = 'build'
-build_dir_tmp = build_dir + '/distpkg/tmp'
-build_dir_resources = build_dir + '/distpkg/Resources'
-build_dir_packages = build_dir + '/distpkg/Packages'
-build_dir_stage = build_dir + '/flatpkg' # appended with /package_name
+build_dir = 'build/flatdistpkg'
+build_dir_tmp = build_dir + '/tmp'
+build_dir_resources = build_dir + '/Resources'
+build_dir_packages = build_dir + '/Packages'
build_dirs = [
build_dir_tmp, build_dir_resources,
- build_dir_packages, build_dir_stage,
+ build_dir_packages,
]
# probably don't need these; info should be passed via FlatDistPackager()
default_src_resources = 'Resources'
# going to generate this from scratch, so won't need template
-default_src_distribution_xml = 'src/distribution.xml'
+default_src_distribution_xml = 'osx/distribution.xml'
build_dir_distribution_xml = \
os.path.join(build_dir_tmp, filename_distribution_xml)
-def RunCommandOrRaise(env, cmd):
- print('@', cmd)
- ret = CommandAction(cmd).execute(None, [], env)
- if ret: raise Exception('command failed, return code %s' % str(ret))
-
-
def clean_old_build(env):
# rm intermediate build stuff
- # do not rm old build products, descriptions
+ # do not rm old build products
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
-def setup_dirs(env):
- return
- # FUTURE USE
- # build/distpkg/package_name/{tmp,Resources,Packages}
- # build/flatpkg/package_name/{root,Resources,Scripts}
- # useful if a project creates multiple distpkg
- # clean_old_build would need to only rm build/distpkg/thisname
- # would also want to separate flatpkg building
- name = env['package_name']
- env['build_dir'] = 'build'
- env['build_dir_tmp'] = tmp = \
- build_dir + '/distpkg/' + name + '/tmp'
- env['build_dir_resources'] = res = \
- build_dir + '/distpkg/' + name + '/Resources'
- env['build_dir_packages'] = packs = \
- build_dir + '/distpkg/' + name + '/Packages'
- env['build_dir_stage'] = stage = build_dir + '/flatpkg'
- env['build_dirs'] = [tmp,res,packs,stage]
- env['build_dir_distribution_xml'] = \
- os.path.join(tmp, filename_distribution_xml)
-
-
def create_dirs(env):
- #setup_dirs(env)
- dirs = build_dirs #+ env.get('build_dirs',[])
- for d in dirs:
+ for d in build_dirs:
if not os.path.isdir(d):
os.makedirs(d, 0o755)
- #env.Dir(build_dir)
- # above fails with
- # scons: *** [fah-installer_7.2.12_intel.pkg.zip] TypeError :
- # Tried to lookup File 'build' as a Dir.
-def remove_cruft_from_directory(d, env):
- if not (d and os.path.isdir(d) and d.startswith('build/')):
- return
- # rm any lingering cruft (.svn .DS_Store)
- # other candidates may include
- # ._??*, resource forks, ACLs, xattrs
- # In SConstruct, should use env['package_ignores'] += ['.DS_Store']
- # FIXME NOT FULLY IMPLEMENTED
- # FIXME should probably use os.walk()
- cmd = ['find',d,'-type','f','-name','.DS_Store','-print','-delete']
- env.RunCommand(cmd)
- return
- # feels too dangerous
- cmd = ['find', d, '-type', 'd', '-name', '.svn', '-exec',
- 'rm', '-rf', '{}', ';', '-prune', '-print']
- env.RunCommand(cmd)
- # UNTESTED:
- cruft_files = ['.DS_Store']
- cruft_dirs = ['.svn']
- for root, dirs, files in os.walk(d):
- for name in cruft_files:
- if name in files:
- path = os.path.join(root, name)
- print('WOULD BE deleting ' + path)
- #os.remove(path)
- for name in cruft_dirs:
- if name in dirs:
- dirs.remove(name)
- path = os.path.join(root, name)
- print('WOULD BE deleting directory ' + path)
- #shutil.rmtree(path)
-
-
-def rename_prepostflight_scripts(scripts_dir):
- # unless PackageInfo says otherwise,
- # flat pkgs only use pre/postinstall
- pre1 = os.path.join(scripts_dir, 'preflight')
- pre2 = os.path.join(scripts_dir, 'preinstall')
- post1 = os.path.join(scripts_dir, 'postflight')
- post2 = os.path.join(scripts_dir, 'postinstall')
- if os.path.isfile(pre1) and not os.path.exists(pre2):
- print('renaming %s to %s' % (pre1, pre2))
- os.rename(pre1, pre2)
- if os.path.isfile(post1) and not os.path.exists(post2):
- print('renaming %s to %s' % (post1, post2))
- os.rename(post1, post2)
+def migrate_distpkg_keys(env):
+ # copy all distpkg_* values to pkg_*
+ # do not delete distpkg_* keys; they may be expected elsewhere
+ count = 0
+ for key in env.keys():
+ if key.startswith('distpkg_'):
+ key0 = key[4:] # pkg_
+ if key0 in env:
+ raise Exception(f'error: both {key} and {key0} exist')
+ env[key0] = env[key]
+ print(f'NOTE: copied value of key {key} to {key0}')
+ count += 1
+ if 0 < count:
+ print(f'NOTE: {count} distpkg_ keys copied; such keys are deprecated')
def build_component_pkg(info, env):
# FIXME -- possibly incomplete and makes assumptions
# build component from info using pkgbuild
- # uses globals build_dir_stage, build_dir_packages
+ # uses globals build_dir_packages
name = info.get('name')
home = info.get('home')
pkg_id = info.get('pkg_id')
- # if no comp version, use distpkg version
+ # if no component version, use package version
version = info.get('version', env.get('version'))
root = info.get('root')
- resources = info.get('resources')
- pkg_resources = info.get('pkg_resources')
- install_to = info.get('install_to', '/')
+ install_to = info.get('install_to', env.get('pkg_install_to', '/'))
pkg_nopayload = info.get('pkg_nopayload', False)
if not name:
@@ -160,73 +120,40 @@ def build_component_pkg(info, env):
if not version:
raise Exception('no version for component %s' % name)
- stage = os.path.join(build_dir_stage, name)
- stage_resources = os.path.join(stage, 'Resources')
-
target = os.path.join(build_dir_packages, name + '.pkg')
- # FIXME uses knowledge of how pkg.py works
+ # default value is for benefit of old projects (v7 installer)
if not root:
root = home + '/build/pkg/root'
- if not resources:
- resources = home + '/build/pkg/Resources'
-
- # FIXME uses knowledge of layout of most projects
- if pkg_resources is None:
- d = os.path.join(home,'osx/Resources')
- if d and os.path.isdir(d):
- pkg_resources = [[d, '.']]
- # FIXME uses knowledge of how pkg_scripts has been used
- # doesn't handle pkg_scripts as tuple list, like pkg_resources always is
+ # default value is for benefit of old projects (v7 installer)
scripts = os.path.join(home, info.get('pkg_scripts', 'osx/scripts'))
- stage_scripts = None
- if scripts:
- scripts_dir_name = os.path.basename(scripts)
- stage_scripts = os.path.join(stage, scripts_dir_name)
-
- # make needed dirs
- if not os.path.isdir(stage): os.makedirs(stage)
- # if root doesn't exist, do full build of root, same as pkg.py does
- # need package-parameters.json to do so
- # TODO
- if not os.path.isdir(root):
- pass
+ # if pkg_files exists, always copy to root, same as pkg module does
+ # Note that this creates root if it doesn't yet exist
+ pkg_files = info.get('pkg_files')
+ if pkg_files and not pkg_nopayload:
+ if os.path.exists(root):
+ shutil.rmtree(root)
+ env.CopyToPackage(pkg_files, root)
if not os.path.isdir(root) and not pkg_nopayload:
raise Exception('%s component root does not exist! %s' % (name, root))
- # try to copy scripts to our stage and use that to avoid most cruft
- # also allows renaming scripts before pkgbuild
- if scripts and os.path.isdir(scripts):
- env.CopyToPackage(scripts, stage, perms = 0o755)
-
- # copy resources to our stage for future distpkg use
- if resources and os.path.isdir(resources):
- env.CopyToPackage(resources, stage)
- elif pkg_resources:
- env.CopyToPackage(pkg_resources, stage_resources)
-
- # not needed, done later to expanded distpkg anyway
- #remove_cruft_from_directory(stage, env)
-
- rename_prepostflight_scripts(stage_scripts)
+ callback = info.get('pre_sign_callback')
+ if callback:
+ callback(info)
# if any apps/tools should be codesign'd do that now
# assumes project didn't do it when creating its distroot
# TODO clone env and add info so all sign_ vars can be overridden
- sign_apps = info.get('sign_apps', [])
- for path in sign_apps:
- if not path.startswith('/'):
- path = os.path.join(root, path)
- sign_application(path, env)
-
- sign_tools = info.get('sign_tools', [])
- for path in sign_tools:
- if not path.startswith('/'):
- path = os.path.join(root, path)
- sign_executable(path, env)
+ for pattern in info.get('sign_apps', []):
+ for path in glob.glob(os.path.join(root, pattern)):
+ env.SignApplication(path)
+
+ for pattern in info.get('sign_tools', []):
+ for path in glob.glob(os.path.join(root, pattern)):
+ env.SignExecutable(path)
cmd = ['pkgbuild',
'--install-location', install_to,
@@ -239,20 +166,19 @@ def build_component_pkg(info, env):
else:
cmd += ['--root', root]
- if stage_scripts and os.path.isdir(stage_scripts):
- cmd += ['--scripts', stage_scripts]
- elif scripts and os.path.isdir(scripts):
+ if scripts and os.path.isdir(scripts):
cmd += ['--scripts', scripts]
cmd += [target]
- RunCommandOrRaise(env, cmd)
+ env.RunCommandOrRaise(cmd)
def build_component_pkgs(env):
- components = env.get('distpkg_components', None)
+ components = env.get('pkg_components', None)
if not components:
- # in future, maybe handle as implicit pkg+distpkg if pkg_type dist
- raise Exception('no components specified')
+ # TODO: instead create components for single-pkg dist
+ # and set any needed pkg_ vars
+ raise Exception('no pkg_components specified')
# validate and fill-in any missing info
for info in components:
@@ -263,49 +189,12 @@ def build_component_pkgs(env):
raise Exception('home not provided for component ' + name)
# name and pkg_id are also required, but may be in json
- # try to load pkg info json, if exists
- # merge with components info
- # FIXME UNTESTED AND MAYBE INCOMPLETE
- if not info.get('params_json_loaded'):
- jsonfile = os.path.join(home, filename_package_info_json)
- if os.path.isfile(jsonfile):
- print('loading info from %s' % jsonfile)
- info2 = json.load(jsonfile)
- # merge
- # trust what we were passed over what json says
- # this allows distpkg to override component pkg info
- info2.update(info)
- info = info2
- info['params_json_loaded'] = True
-
name = info.get('name')
if not info.get('package_name'):
info['package_name'] = name
if not info.get('package_name_lower'):
info['package_name_lower'] = name.lower()
- # try to get description, if still none
- desc = info.get('short_description', '').strip()
- if not desc:
- desc = info.get('description', '').strip()
- if not desc:
- fname = os.path.join(home, filename_package_desc_txt)
- if os.path.isfile(fname):
- f = None
- try:
- f = open(fname, 'r')
- desc = f.read().strip()
- finally:
- if f is not None: f.close()
- if not desc:
- desc = info.get('summary', '').strip()
- if desc:
- desc = desc.replace('\n',' ')
- desc = desc.replace(' ',' ').replace(' ',' ')
- desc = desc.replace('. ','. ')
- if desc:
- info['short_description'] = desc
-
for info in components:
try:
build_component_pkg(info, env)
@@ -313,13 +202,14 @@ def build_component_pkgs(env):
print('unable to build component ' + info.get('name'))
raise e
- # replace distpkg_components with modified/created info list
- env['distpkg_components'] = components
+ # replace pkg_components with modified/created info list
+ env['pkg_components'] = components
def build_product_pkg(target, source, env):
version = env.get('version')
- pkg_id = env.get('distpkg_id')
+ if not version: raise Exception('version is not set')
+ pkg_id = env.get('pkg_id')
cmd = ['productbuild',
'--distribution', build_dir_distribution_xml,
'--package-path', build_dir_packages,
@@ -328,129 +218,27 @@ def build_product_pkg(target, source, env):
]
if pkg_id: cmd += ['--identifier', pkg_id]
cmd += [target]
- RunCommandOrRaise(env, cmd)
+ env.RunCommandOrRaise(cmd)
def expand_flat_pkg(target, source, env):
cmd = ['pkgutil', '--expand', source, target]
- RunCommandOrRaise(env, cmd)
+ env.RunCommandOrRaise(cmd)
def flatten_to_pkg(target, source, env):
cmd = ['pkgutil', '--flatten', source, target]
- RunCommandOrRaise(env, cmd)
-
-
-def unlock_keychain(env, keychain=None, password=None):
- if keychain is None: keychain = env.get('sign_keychain', None)
- if keychain: name = keychain
- else: name = 'default-keychain'
- if password is None:
- passfile = os.path.expanduser('~/.ssh/p')
- if os.path.isfile(passfile):
- f = None
- try:
- f = open(passfile, 'r')
- password = f.read().strip('\n')
- finally:
- if f is not None: f.close()
- if password:
- cmd = ['security', 'unlock-keychain', '-p', password]
- if keychain: cmd += [keychain]
- try:
- sanitized_cmd = cmd[:3] + ['xxxxxx']
- if keychain: sanitized_cmd += [keychain]
- print('@', sanitized_cmd)
- # returns 0 if keychain already unlocked, even if pass is wrong
- ret = CommandAction(cmd).execute(None, [], env)
- if ret: raise Exception(
- 'unlock-keychain failed, return code %s' % str(ret))
- except Exception as e:
- print('unable to unlock keychain "%s"' % name)
- raise e
- else:
- print('skipping unlock "%s"' % name + '; no password given')
-
-
-def sign_flat_package(target, source, env):
- # expect source 'somewhere/tmpname.pkg', target elsewhere/finalname.pkg
- sign = env.get('sign_id_installer', None)
- keychain = env.get('sign_keychain', None)
- if not sign:
- raise Exception('unable to sign; no sign_id_installer provided')
- # FIXME should do more than this
- x, ext = os.path.splitext(source)
- if not (os.path.isfile(source) and ext in ('.pkg', '.mpkg')):
- raise Exception('unable to sign; not a flat package: ' + source)
- cmd = ['productsign', '--sign', sign]
- if keychain:
- cmd += ['--keychain', keychain]
- cmd += [source, target]
- RunCommandOrRaise(env, cmd)
-
-
-def sign_or_copy_product_pkg(target, source, env):
- if env.get('sign_id_installer'):
- sign_flat_package(target, source, env)
- return
- print('NOT signing package; no sign_id_installer provided; copying '
- 'instead...')
- shutil.copy2(source, target)
-
-
-def sign_application(target, env):
- keychain = env.get('sign_keychain')
- sign = env.get('sign_id_app')
- cmd = ['codesign', '-f']
- try:
- ver = tuple([int(x) for x in platform.mac_ver()[0].split('.')])
- # all bundles in an app must also be signed on 10.7+
- # easy way to do this is just to codesign --deep
- # only ok if there are no sandbox entitlements for this app
- if ver >= (10,7): cmd += ['--deep']
- except: pass
- if keychain:
- cmd += ['--keychain', keychain]
- if sign:
- cmd += ['--sign', sign]
- else:
- raise Exception('unable to codesign %s; no sign_id_app given' % target)
- if not os.path.isdir(target) or not target.endswith('.app'):
- raise Exception('unable to codesign %s; not an app' % target)
- cmd += [target]
- RunCommandOrRaise(env, cmd)
-
-
-def sign_executable(target, env):
- keychain = env.get('sign_keychain')
- sign = env.get('sign_id_app')
- prefix = env.get('sign_prefix')
- cmd = ['codesign', '-f']
- if keychain:
- cmd += ['--keychain', keychain]
- if prefix:
- if not prefix.endswith('.'): prefix += '.'
- cmd += ['--prefix', prefix]
- else:
- raise Exception('unable to codesign %s; no sign_prefix given' % target)
- if sign:
- cmd += ['--sign', sign]
- else:
- raise Exception('unable to codesign %s; no sign_id_app given' % target)
- if not (os.path.isfile(target) and os.access(target, os.X_OK)):
- raise Exception('unable to codesign %s; not an executable' % target)
- # FIXME should not try to sign executable scripts
- cmd += [target]
- RunCommandOrRaise(env, cmd)
+ env.RunCommandOrRaise(cmd)
def build_or_copy_distribution_template(env):
+ # TODO: use env pkg_distribution if exists; escape values to insert into it
target = build_dir_distribution_xml
source = default_src_distribution_xml
build_distribution_template(env, target)
- if os.path.exists(target): return
+ if os.path.exists(target): return # assume build succeeded
print('WARNING: did not generate distribution.xml; '
'using pre-built template %s' % source)
@@ -460,6 +248,7 @@ def build_or_copy_distribution_template(env):
# sometimes after a 'scons --clean', above fails with
# scons: *** [fah-installer_7.2.12_intel.pkg.zip] TypeError :
# Tried to lookup File 'build' as a Dir.
+ # TODO: filter it, don't just copy
shutil.copy2(source, target)
@@ -469,36 +258,44 @@ def build_distribution_template(env, target=None):
print('generating ' + target)
- distpkg_target = env.get('distpkg_target', '10.5')
- distpkg_arch = env.get('distpkg_arch')
- if not distpkg_arch:
- distpkg_arch = env.get('package_arch')
- if distpkg_arch in (None, '', 'intel'):
- print('using distpkg_arch i386 instead of "%s"' % distpkg_arch)
- distpkg_arch = 'i386'
+ pkg_target = env.get('pkg_target', '10.5')
+ ver = tuple([int(x) for x in pkg_target.split('.')])
+ pkg_arch = env.get('pkg_arch')
+ if not pkg_arch:
+ pkg_arch = env.get('osx_archs')
+
+ # handle some aberrant values
+ if pkg_arch in (None, '', 'intel'):
+ print('using pkg_arch i386 instead of "%s"' % pkg_arch)
+ pkg_arch = 'i386'
+ # some projects might be passing package_arch
+ if pkg_arch == 'universal':
+ pkg_arch = 'x86_64 arm64'
+
+ hostArchitectures = ','.join(pkg_arch.split())
# generate new tree
import xml.etree.ElementTree as etree
- root = etree.Element('installer-script', {'minSpecVersion':'1'})
+ root = etree.Element('installer-gui-script', {'minSpecVersion':'2'})
tree = etree.ElementTree(root)
- etree.SubElement(root, 'title').text = \
- env.get('package_name_lower') + '_title'
+ title = env.get('summary', env.get('package_name'))
+ title = title.replace('\n',' ').replace('\t',' ')
+ version = env.get('version')
+ if version and not version in title: title += ' ' + version
+ etree.SubElement(root, 'title').text = title
# non-root pkg installs are very buggy, so this should stay True
- distpkg_root_volume_only = env.get('distpkg_root_volume_only', True)
- allow_external = env.get('distpkg_allow_external_scripts', False)
+ pkg_root_volume_only = env.get('pkg_root_volume_only', True)
+ allow_external = env.get('pkg_allow_external_scripts', False)
if allow_external: allow_external = 'yes'
else: allow_external = 'no'
- allow_ppc = distpkg_arch and 'ppc' in distpkg_arch and \
- (distpkg_target.split('.') < '10.6'.split('.'))
- if allow_ppc: hostArchitectures = 'i386,ppc'
- else: hostArchitectures = 'i386'
- if distpkg_root_volume_only: rootVolumeOnly = 'true'
+ allow_ppc = 'ppc' in pkg_arch.lower() and ver < (10,6)
+ if pkg_root_volume_only: rootVolumeOnly = 'true'
else: rootVolumeOnly = 'false'
opts = {
'allow-external-scripts': allow_external,
- 'customize': env.get('distpkg_customize', 'allow'),
+ 'customize': env.get('pkg_customize', 'allow'),
# i386 covers both 32 and 64 bit kernel, NOT cpu
# cpu 64 bit check must be done in script
'hostArchitectures': hostArchitectures,
@@ -506,13 +303,8 @@ def build_distribution_template(env, target=None):
}
etree.SubElement(root, 'options', opts)
- # WARNING domains element is buggy for anything other then root-only.
- # It also leads to support questions, because default selection must be
- # clicked before can click continue. And it gives an uninformative,
- # unhelpful message if volume check fails.
- # So, disabled for now. May need to enable in the future if
- # options rootVolumeOnly becomes unsupported.
- if False and distpkg_root_volume_only:
+ # WARNING domains element can be buggy for anything other than root-only.
+ if (10,13) <= ver and pkg_root_volume_only:
etree.SubElement(root, 'domains', {
'enable_anywhere': 'false',
'enable_currentUserHome': 'false',
@@ -520,14 +312,26 @@ def build_distribution_template(env, target=None):
})
for key in 'welcome license readme conclusion'.split():
- if 'distpkg_' + key in env:
- etree.SubElement(root, key, {'file': env.get('distpkg_' + key)})
+ if 'pkg_' + key in env:
+ etree.SubElement(root, key, {'file': env.get('pkg_' + key)})
- background = env.get('distpkg_background', None)
+ background = env.get('pkg_background', None)
if background:
+ mtype = mimetypes.guess_type(background)[0]
etree.SubElement(root, 'background', {
'alignment': 'bottomleft',
'file': background,
+ 'mime-type': mtype,
+ 'scaling': 'none',
+ })
+ # dark mode background; defaults to same image as light
+ background = env.get('pkg_background_dark', background)
+ if background:
+ mtype = mimetypes.guess_type(background)[0]
+ etree.SubElement(root, 'background-darkAqua', {
+ 'alignment': 'bottomleft',
+ 'file': background,
+ 'mime-type': mtype,
'scaling': 'none',
})
@@ -536,14 +340,15 @@ def build_distribution_template(env, target=None):
vc = etree.SubElement(root, 'volume-check', {
'script': 'volume_check();'})
- if distpkg_target:
+ if pkg_target:
e = etree.Element('allowed-os-versions')
- etree.SubElement(e, 'os-version', {'min':distpkg_target})
+ etree.SubElement(e, 'os-version', {'min':pkg_target})
vc.append(e)
# options hostArchitectures is sufficient on 10.5+, but no clear
# message is given by Installer.app, so we still want potential
# hw.cputype check in install_check
+ # allowed-os-versions req macOS 10.6.6+, so volume_check is still needed
script_text = """
function is_min_version(ver) {
if (my.target && my.target.systemVersion &&
@@ -561,9 +366,9 @@ def build_distribution_template(env, target=None):
return false;
}
function volume_check() {
- if (!is_min_version('""" + distpkg_target + """')) {
+ if (!is_min_version('""" + pkg_target + """')) {
my.result.title = 'Unable to Install';
- my.result.message = 'OSX """ + distpkg_target + \
+ my.result.message = 'macOS """ + pkg_target + \
""" or later is required.';
my.result.type = 'Fatal';
return false;
@@ -572,17 +377,16 @@ def build_distribution_template(env, target=None):
}
function install_check() {"""
- if not (distpkg_arch and 'ppc' in distpkg_arch) and \
- (distpkg_target.split('.') < '10.6'.split('.')):
+ if not allow_ppc and ver < (10,6,6):
script_text += """
if (system.sysctl('hw.cputype') == '18') {
my.result.title = 'Unable to Install';
- my.result.message = 'An Intel-based Mac is required.';
+ my.result.message = 'PowerPC Mac is not supported.';
my.result.type = 'Fatal';
return false;
}"""
- if distpkg_arch == 'x86_64':
+ if pkg_arch == 'x86_64':
script_text += """
if (have_64_bit_cpu() == false) {
my.result.title = 'Unable to Install';
@@ -598,23 +402,26 @@ def build_distribution_template(env, target=None):
outline = etree.SubElement(root, 'choices-outline')
- components = env.get('distpkg_components')
+ components = env.get('pkg_components')
pkgrefs = []
for info in components:
pkg_id = info.get('pkg_id')
name_lower = info.get('package_name_lower')
- pkg_target = info.get('distpkg_target', distpkg_target)
+ cpkg_target = info.get('pkg_target', pkg_target)
+ pkg_ver = tuple([int(x) for x in cpkg_target.split('.')])
choice_id = name_lower
# remove any dots or spaces in choice_id for 10.5 compatibility
choice_id = choice_id.replace('.','').replace(' ','')
- choice_title = info.get('package_name', info.get('summary'))
- # description is in Localizable.strings
- choice_desc = info.get('package_name_lower') + '_desc'
+ title = info.get('package_name', info.get('summary'))
+ title = title.replace('\\n','\n').replace('\\t','\t').replace('\\"','"')
+ desc = info.get('description', '')
+ desc = desc.replace('\\n','\n').replace('\\t','\t').replace('\\"','"')
+ desc = desc.replace('\r\n', '\n').replace('\n', '__CR__')
etree.SubElement(outline, 'line', {'choice':choice_id})
choice = etree.SubElement(root, 'choice', {
'id': choice_id,
- 'title': choice_title,
- 'description': choice_desc,
+ 'title': title,
+ 'description': desc,
})
etree.SubElement(choice, 'pkg-ref', {'id': pkg_id})
pkg_path = info.get('package_name') + '.pkg'
@@ -622,7 +429,7 @@ def build_distribution_template(env, target=None):
'id': pkg_id,
# version and installKBytes will be added by productbuild
}
- if distpkg_root_volume_only or info.get('pkg_root_volume_only'):
+ if pkg_root_volume_only or info.get('pkg_root_volume_only'):
pkg_ref_info['auth'] = 'Root'
ref = etree.Element('pkg-ref', pkg_ref_info)
ref.text = pkg_path
@@ -634,36 +441,39 @@ def build_distribution_template(env, target=None):
for app_id in must_close_apps:
etree.SubElement(must_close, 'app', {'id':app_id})
pkgrefs.append(r)
- # if appropriate, add start_{enabled,selected} attrs and script
- if pkg_target and pkg_target.split('.') > distpkg_target.split('.'):
- # add start_{enabled,selected} attrs to choice
- # add min version scripts to script_text
+ # if appropriate, add {enabled,selected} attrs and script
+ if pkg_ver > ver:
# TODO add arch checks if component has diff reqs than distpkg
- choice.set('start_enabled', name_lower + '_start_enabled()')
- choice.set('start_selected', name_lower + '_start_selected()')
+ munged_name = 'is_' + re.sub(r'[^A-Za-z0-9]+', '_', name_lower)
+ choice.set('enabled', munged_name + '_enabled();')
+ choice.set('selected', munged_name + '_enabled();')
script_text += """
-function """ + name_lower + """_start_enabled() {
- return is_min_version('""" + pkg_target + """');
-}
-function """ + name_lower + """_start_selected() {
- return is_min_version('""" + pkg_target + """');
+function """ + munged_name + """_enabled() {
+ return is_min_version('""" + cpkg_target + """');
}
"""
for ref in pkgrefs: root.append(ref)
- etree.SubElement(root, 'script').text = script_text
+ etree.SubElement(root, 'script').text = '__SCRIPT_TEXT__'
+ script_text = ''
# save tree to target
- f = None
- try:
- f = open(target, 'w')
- tree.write(f, encoding='utf-8')
- finally:
- if f is not None: f.close()
+ try: etree.indent(tree)
+ except: pass
+ # do NOT use 'utf-8' for ElementTree.write()
+ with open(target, 'w') as f: tree.write(f, encoding = 'unicode')
+ with open(target, 'r') as f: contents = f.read()
+ contents = contents.replace('__SCRIPT_TEXT__', script_text)
+ with open(target, 'w') as f: f.write(contents)
def patch_expanded_pkg_distribution(target, source, env):
# fixup whatever needs changing for < 10.6.6 compatibility
+ pkg_target = env.get('pkg_target', '10.5')
+ ver = tuple([int(x) for x in pkg_target.split('.')])
+ if ver >= (10,6,6):
+ return
+
fpath = os.path.join(target, 'Distribution')
# load xml
tree = None
@@ -682,12 +492,7 @@ def patch_expanded_pkg_distribution(target, source, env):
print('changing minSpecVersion from %s to 1' % minSpecVersion)
root.set('minSpecVersion', '1')
# overwrite back to fpath
- f = None
- try:
- f = open(fpath, 'w')
- tree.write(f, encoding='utf-8')
- finally:
- if f is not None: f.close()
+ with open(fpath, 'w') as f: tree.write(f, encoding = 'unicode')
# FIXME detect any failures somehow
return
# failed to load xml
@@ -695,63 +500,47 @@ def patch_expanded_pkg_distribution(target, source, env):
print('WARNING: pkg may require OSX 10.6.6 or later')
-def create_localizable_strings(env):
- print('generating Localizable.strings')
- # English only for now
- components = env.get('distpkg_components', [])
- if components is None: components = []
- lines = []
-
- # FUTURE
- # load template files into lines
- # src/Localizable.strings
- # Resources/en.lproj/Localizable.strings
- # ...
-
- # add distpkg summary aka dist package title
- summary = env.get('summary', env.get('package_name'))
- if summary:
- key = env.get('package_name_lower') + '_title'
- line = '"%s" = "%s";' % (key, summary)
- lines.append(line)
- # really should merge multiple Localizable.strings files, for mult lang
- for comp in components:
- key = comp['name'].lower() + '_desc'
- value = comp.get('short_description', comp.get('description', ''))
- line = '"%s" = "%s";' % (key, value)
- lines.append(line)
- if not value:
- print('no description found for component ' + comp['name'])
- # save it (overwrites if exists)
- d = build_dir_resources + '/en.lproj'
- if not os.path.isdir(d): os.makedirs(d, 0o755)
- fname = d + '/Localizable.strings'
- print('writing ' + fname)
- env.WriteStringToFile(fname, lines)
+def patch_expanded_pkg_distribution_cr(target, env):
+ # replace __CR__ with
in Distribution
+ fpath = os.path.join(target, 'Distribution')
+ if not os.path.isfile(fpath):
+ raise Exception('Distribution xml file does not exist:', fpath)
+ with open(fpath, 'r') as f: contents = f.read()
+ contents = str(contents).replace('__CR__', '
')
+ with open(fpath, 'w') as f: f.write(contents)
def flat_dist_pkg_build(target, source, env):
- # expect target package_name_version_arch.pkg.zip
- target_zip = str(target[0])
+ # expect target one of
+ # package_name_version_arch.pkg
+ # package_name_version_arch.mpkg.zip
+ # package_name_version_arch.pkg.zip
+ target_pkg = str(target[0])
+ target_zip = None
+ if target_pkg.endswith('.zip'):
+ target_zip = target_pkg
+ target_pkg = os.path.splitext(target_pkg)[0]
# validate target, source, env
- # tolerate .mpkg, because installer seems semi-ok with it
- # TODO allow no .zip, and no ZipDir()
- target_pkg, ext = os.path.splitext(target_zip)
- if ext != '.zip': raise Exception('Expected .zip in package name')
+ # tolerate .mpkg if also .zip
target_base, ext = os.path.splitext(target_pkg)
if not ext in ('.pkg', '.mpkg'):
raise Exception('Expected .pkg or .mpkg in package name')
+ if ext == '.mpkg' and not target_zip:
+ raise Exception('Cannot create .mpkg without .zip')
# .mpkg causes errors in log, and does not work on 10.5,
# so use .pkg for flat package, even if final target is .mpkg.zip
if ext == '.mpkg': target_pkg = target_base + '.pkg'
+ migrate_distpkg_keys(env)
+
# flat packages require OS X 10.5+
- distpkg_target = env.get('distpkg_target', '10.5')
- if distpkg_target.split('.') < '10.5'.split('.'):
+ pkg_target = env.get('pkg_target', '10.5')
+ ver = tuple([int(x) for x in pkg_target.split('.')])
+ if ver < (10,5):
raise Exception(
'incompatible configuration: flat package and osx pre-10.5 (%s)'
- % distpkg_target)
+ % pkg_target)
clean_old_build(env)
create_dirs(env)
@@ -763,27 +552,20 @@ def flat_dist_pkg_build(target, source, env):
# TODO: more validation here ...
name = env.get('package_name')
- print('Building "%s" flat, target %s' % (name, distpkg_target))
+ print('Building "%s", target %s' % (name, pkg_target))
# copy our own dist Resources
- if env.get('distpkg_resources'):
- env.InstallFiles('distpkg_resources', build_dir_resources)
- elif env.get('pkg_resources'):
+ if env.get('pkg_resources'):
env.InstallFiles('pkg_resources', build_dir_resources)
- unlock_keychain(env)
+ env.UnlockKeychain()
build_component_pkgs(env)
# probably not needed
# I think build_component_pkgs always raises on any failure
- components = env.get('distpkg_components')
- if components is None or not len(components):
- raise Exception('No distpkg_components. Cannot continue.')
-
- # create Localizable.strings with dist title, component descriptions
- # this must be done AFTER components are built
- create_localizable_strings(env)
+ if not env.get('pkg_components'):
+ raise Exception('No pkg_components. Cannot continue.')
build_or_copy_distribution_template(env)
@@ -792,36 +574,18 @@ def flat_dist_pkg_build(target, source, env):
expand_flat_pkg(target_pkg_expanded, target_pkg_tmp, env)
patch_expanded_pkg_distribution(target_pkg_expanded, [], env)
+ patch_expanded_pkg_distribution_cr(target_pkg_expanded, env)
- # if built any components using home/osx/scripts, we still need to rename
- for d in glob.glob(os.path.join(target_pkg_expanded, '*.pkg/Scripts')):
- rename_prepostflight_scripts(d)
-
- remove_cruft_from_directory(target_pkg_expanded, env)
+ cmd = ['find',target_pkg_expanded,'-type','f','-name','.DS_Store','-delete']
+ env.RunCommand(cmd)
flatten_to_pkg(target_unsigned, target_pkg_expanded, env)
- sign_or_copy_product_pkg(target_pkg, target_unsigned, env)
-
- env.ZipDir(target_zip, target_pkg)
+ env.SignOrCopyPackage(target_pkg, target_unsigned)
- # write package-description.txt
- # these are currently also generated by
- # {client,viewer}/SConstruct and control/setup.py
- # it should be done by pkg.py
- # or projects can drop a package-parameters.json so we can get all info
- desc = env.get('short_description', '').strip()
- if not desc:
- desc = env.get('description', '').strip()
- if not desc:
- desc = env.get('summary', '').strip()
- # note: desc may be '', write anyway
- print('writing ' + filename_package_desc_txt)
- env.WriteStringToFile(filename_package_desc_txt, desc)
+ env.NotarizeWaitStaple(target_pkg, timeout = 1200)
- # write package.txt
- print('writing ' + filename_package_build_txt)
- env.WriteStringToFile(filename_package_build_txt, target_zip)
+ if target_zip: env.ZipDir(target_zip, target_pkg)
def generate(env):
@@ -829,6 +593,8 @@ def generate(env):
source_factory = SCons.Node.FS.Entry,
source_scanner = SCons.Defaults.DirScanner)
env.Append(BUILDERS = {'FlatDistPkg' : bld})
+ for tool in deps:
+ env.CBLoadTool(tool)
return True
diff --git a/config/freetype2/__init__.py b/config/freetype2/__init__.py
index ff18a6fe0..904c1bfc9 100644
--- a/config/freetype2/__init__.py
+++ b/config/freetype2/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
from SCons.Script import *
@@ -10,8 +42,13 @@ def configure(conf):
if not 'FREETYPE2_INCLUDE' in os.environ:
try:
- env.ParseConfig('freetype-config --cflags')
- except OSError: pass
+ env.ParseConfig('pkg-config freetype2 --cflags')
+ except OSError:
+ try:
+ env.ParseConfig('freetype-config --cflags')
+ except OSError:
+ pass
+
if env['PLATFORM'] == 'darwin' or int(env.get('cross_osx', 0)):
if not conf.CheckOSXFramework('CoreServices'):
@@ -19,15 +56,17 @@ def configure(conf):
conf.CBRequireCHeader('ft2build.h')
conf.CBRequireLib('freetype')
- conf.CBConfig('zlib')
+ conf.CBConfig('ZLib')
conf.CBCheckLib('png')
+ conf.CBCheckLib('brotlidec')
+ conf.CBCheckLib('brotlicommon')
return True
def generate(env):
env.CBAddConfigTest('freetype2', configure)
- env.CBLoadTools('osx zlib')
+ env.CBLoadTools('osx ZLib')
def exists():
diff --git a/config/leveldb/__init__.py b/config/leveldb/__init__.py
new file mode 100644
index 000000000..965671c90
--- /dev/null
+++ b/config/leveldb/__init__.py
@@ -0,0 +1,47 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+from SCons.Script import *
+
+
+def configure(conf):
+ conf.CBCheckHome('leveldb')
+ conf.CBRequireLib('snappy')
+ conf.CBRequireLib('leveldb')
+ conf.CBRequireCXXHeader('leveldb/db.h')
+ conf.env.CBConfigDef('HAVE_LEVELDB')
+
+
+def generate(env): env.CBAddConfigTest('leveldb', configure)
+
+
+def exists(): return 1
diff --git a/config/libyaml/__init__.py b/config/libyaml/__init__.py
index b6e8f9b3b..6015cd4f9 100644
--- a/config/libyaml/__init__.py
+++ b/config/libyaml/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
diff --git a/config/lz4/__init__.py b/config/lz4/__init__.py
new file mode 100644
index 000000000..384fd9197
--- /dev/null
+++ b/config/lz4/__init__.py
@@ -0,0 +1,45 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+from SCons.Script import *
+
+
+def configure(conf):
+ conf.CBCheckHome(
+ 'lz4', lib_suffix = ['', '/lib'], inc_suffix = ['/src', '/include'])
+ conf.CBRequireHeader('lz4frame.h')
+ conf.CBRequireLib('lz4')
+ conf.CBCheckLib('xxhash')
+
+
+def generate(env): env.CBAddConfigTest('lz4', configure)
+def exists(): return 1
diff --git a/config/malloc/__init__.py b/config/malloc/__init__.py
index bb095d4c3..05f386b25 100644
--- a/config/malloc/__init__.py
+++ b/config/malloc/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
from SCons.Script import *
diff --git a/config/ninja/__init__.py b/config/ninja/__init__.py
index 71dc5bb03..03f86de1a 100644
--- a/config/ninja/__init__.py
+++ b/config/ninja/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
# Copyright (c) 2014 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -62,8 +94,8 @@ def CustomCommandPrinter(cmd, targets, source, env):
def WriteFile():
dest_temp = '%s.tmp' % dest_file
- ninja_fh = open(dest_temp, 'w')
- ninja_fh.write("""\
+ with open(dest_temp, 'w') as ninja_fh:
+ ninja_fh.write("""\
# Generated by scons_to_ninja.py
# Generic rule for handling any command.
@@ -78,28 +110,28 @@ def WriteFile():
command = rm -f $out && cp -l $in $out
""")
- for node in node_list:
- dest_path = node.get_path()
- cmds = node_map[node]
- deps = [GetRealNode(dep).get_path() for dep in node.all_children()]
-
- action = node.builder.action
- if type(action) == SCons.Action.FunctionAction:
- funcname = action.function_name()
- if funcname == 'installFunc':
- assert len(deps) == 1, len(deps)
- ninja_fh.write('\nbuild %s: install %s\n'
- % (dest_path, ' '.join(deps)))
- continue
- else:
- sys.stderr.write('Ninja build: Unknown FunctionAction, '
- '%r: skipping target %r\n'
- % (funcname, dest_path))
- continue
-
- ninja_fh.write('\nbuild %s: cmd %s\n'
- % (dest_path, ' '.join(deps)))
- ninja_fh.write(' cmd = %s\n' % ' && '.join(cmds))
+ for node in node_list:
+ dest_path = node.get_path()
+ cmds = node_map[node]
+ deps = [GetRealNode(dep).get_path() for dep in node.all_children()]
+
+ action = node.builder.action
+ if type(action) == SCons.Action.FunctionAction:
+ funcname = action.function_name()
+ if funcname == 'installFunc':
+ assert len(deps) == 1, len(deps)
+ ninja_fh.write('\nbuild %s: install %s\n'
+ % (dest_path, ' '.join(deps)))
+ continue
+ else:
+ sys.stderr.write('Ninja build: Unknown FunctionAction, '
+ '%r: skipping target %r\n'
+ % (funcname, dest_path))
+ continue
+
+ ninja_fh.write('\nbuild %s: cmd %s\n'
+ % (dest_path, ' '.join(deps)))
+ ninja_fh.write(' cmd = %s\n' % ' && '.join(cmds))
# Make the result file visible atomically.
os.rename(dest_temp, dest_file)
diff --git a/config/notarize/__init__.py b/config/notarize/__init__.py
new file mode 100644
index 000000000..d21135664
--- /dev/null
+++ b/config/notarize/__init__.py
@@ -0,0 +1,136 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+''' notarize '''
+
+import os
+import sys
+import subprocess
+import re
+import time
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
+from SCons.Script import *
+
+deps = ['codesign'] # uses some sign_ vars
+
+
+def notarize_sanity_check(env, fpath):
+ if env.get('notarize_disable'):
+ print('NOTE: notarize_disable is True', file=sys.stderr)
+ return
+ if env.get('sign_disable'):
+ env['notarize_disable'] = True
+ print('WARNING: setting notarize_disable because sign_disable is set',
+ file=sys.stderr)
+ return
+ if not os.path.isfile(fpath):
+ raise Exception('ERROR: file does not exist: \"%s\"' % fpath)
+ # if invaid config disable notarization and print warning
+ notarize_profile = env.get('notarize_profile')
+ if not notarize_profile:
+ env['notarize_disable'] = True
+ print('WARNING: notarize_profile is not set', file=sys.stderr)
+ print('WARNING: setting notarize_disable True', file=sys.stderr)
+ if not env.get('sign_prefix'):
+ print('WARNING: sign_prefix is not set', file=sys.stderr)
+
+
+def notarize_staple_file(fpath):
+ cmd = ['/usr/bin/xcrun', 'stapler', 'staple', fpath]
+ print('Stapling ' + fpath)
+ # Maybe check exit code; loop if fail until timeout
+ # Note: failure to staple may not be fatal, assuming
+ # the notarization request will be approved sometime later.
+ # Stapling just allows offline validation by Gatekeeper.
+ # It would be bad for staple to fail when status was "success".
+ ret = subprocess.call(cmd)
+ if ret != 0:
+ print('WARNING: unable to staple ' + fpath, file=sys.stderr)
+ return ret
+
+
+def NotarizeWaitStaple(env, fpath, timeout=0):
+ notarize_sanity_check(env, fpath)
+ if env.get('sign_disable'): return False
+ if env.get('notarize_disable'): return False
+ if not env.get('notarize_profile'): return False
+ if timeout < 0: timeout = 0
+ elif timeout > 3600: timeout = 3600
+ notarize_profile = env.get('notarize_profile')
+ cmd = ['/usr/bin/xcrun', 'notarytool', 'submit', '--wait']
+ if timeout: cmd += ['--timeout', str(timeout)]
+ cmd += ['-p', notarize_profile, fpath]
+ print('@', cmd)
+ ret = subprocess.call(cmd)
+ if ret != 0:
+ raise Exception('ERROR: unable to notarize \"%s\"' % fpath)
+ ret = notarize_staple_file(fpath)
+ if ret != 0:
+ print('ERROR: Stapling failed, though notarize may have succeeded',
+ file=sys.stderr)
+ print('Done notarizing.')
+ return ret == 0
+
+
+def generate(env):
+ if env['PLATFORM'] == 'darwin' or int(env.get('cross_osx', 0)):
+ env.CBAddVariables(
+ # set these vars in scons-options.py
+ # sign_prefix is prepended tp pkg filename to make identifier
+ # You should at least disable notarization for debug builds
+ # Really, only pkgs users can download need be notarized
+ BoolVariable('notarize_disable', 'Disable notarization', 0),
+ ('notarize_profile', 'The notarytool keychain item profile name'),
+ # if using notarize_profile, you do not need user, pass, asc, team
+ ('notarize_user', 'The deveoper AppleID email used to notarize.' +
+ ' Need not be same as codesign account.'),
+ # The 10-character asc and team are allegedly optional if
+ # there is only one developer in notarize_user account.
+ # If both are specified, only asc is used.
+ ('notarize_asc', 'The developer asc provider id'),
+ ('notarize_team', 'The developer team id'),
+ )
+
+ env.AddMethod(NotarizeWaitStaple)
+
+ for tool in deps:
+ env.CBLoadTool(tool)
+
+ return True
+
+
+def exists():
+ return 1
diff --git a/config/nsi/__init__.py b/config/nsi/__init__.py
index 7421c01f1..e47c103ff 100644
--- a/config/nsi/__init__.py
+++ b/config/nsi/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
from SCons.Action import CommandAction
@@ -35,16 +67,9 @@ def build_function(target, source, env):
env['PACKAGE_ARCH'] = platform.architecture()[0][:2]
tmp = nsi + '.tmp'
- input = None
- output = None
- try:
- input = open(nsi, 'r')
- output = open(tmp, 'w')
- output.write(input.read() % env)
-
- finally:
- if input is not None: input.close()
- if output is not None: output.close()
+ with open(nsi, 'r') as input:
+ with open(tmp, 'w') as output:
+ output.write(input.read() % env)
action = CommandAction('$NSISCOM $NSISOPTS ' + tmp)
ret = action.execute(target, [tmp], env)
diff --git a/config/opengl/__init__.py b/config/opengl/__init__.py
index 5e8b14f4c..3ee19364d 100644
--- a/config/opengl/__init__.py
+++ b/config/opengl/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
diff --git a/config/openssl/__init__.py b/config/openssl/__init__.py
index b4e8f6137..c433b3dc9 100644
--- a/config/openssl/__init__.py
+++ b/config/openssl/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
from SCons.Script import *
@@ -6,17 +38,19 @@ def check_version(context, version):
context.Message("Checking for openssl version >= %s..." % version)
version = version.split('.')
- src = '#include \nint main() {\nreturn ('
- src += version[0] + '<= (OPENSSL_VERSION_NUMBER >> 28)'
- if 1 < len(version):
- src += ' && ' + version[1] + \
- '<= ((OPENSSL_VERSION_NUMBER >> 20) & 0xf)'
- if 2 < len(version):
- src += ' && ' + version[2] + \
- '<= ((OPENSSL_VERSION_NUMBER >> 12) & 0xf)'
- src += ') ? 0 : 1;}\n'
-
- ret = context.TryRun(src, '.cpp')[0]
+ version += [0] * (3 - len(version))
+
+ src = '''
+ #include
+ int main() {
+ const unsigned v = (%s << 28) + (%s << 20) + (%s << 12);
+ int a[1 - 2 * (OPENSSL_VERSION_NUMBER < v)];
+ a[0] = 0;
+ return a[0];
+ }
+ ''' % tuple(version)
+
+ ret = context.TryCompile(src, '.cpp')
context.Result(ret)
return ret
@@ -29,10 +63,13 @@ def configure(conf, version = None):
lib_suffix = ['/out32', '/lib', ''])
if env['PLATFORM'] == 'posix': conf.CBCheckLib('dl')
+ conf.CBCheckLib('zstd')
if (conf.CBCheckCHeader('openssl/ssl.h') and
(conf.CBCheckLib('crypto') and
conf.CBCheckLib('ssl')) or
+ (conf.CBCheckLib('libcrypto') and
+ conf.CBCheckLib('libssl')) or
(conf.CBCheckLib('libeay32MT') and
conf.CBCheckLib('ssleay32MT')) or
(conf.CBCheckLib('libeay32') and
@@ -40,14 +77,14 @@ def configure(conf, version = None):
if env['PLATFORM'] == 'win32' or int(env.get('cross_mingw', 0)):
if not conf.CBCheckLib('ws2_32'): conf.CBRequireLib('wsock32')
- for lib in ['advapi32', 'gdi32', 'user32']:
+ for lib in ['advapi32', 'gdi32', 'user32', 'crypt32']:
conf.CBRequireLib(lib)
if version is not None:
if not conf.OpenSSLVersion(version):
raise Exception('Insufficient OpenSSL version')
- env.CBDefine('HAVE_OPENSSL')
+ env.CBConfigDef('HAVE_OPENSSL')
return True
else: raise Exception('Need openssl')
diff --git a/config/osx/__init__.py b/config/osx/__init__.py
index 10111856a..0799b174e 100644
--- a/config/osx/__init__.py
+++ b/config/osx/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import platform
from SCons.Script import *
@@ -10,7 +42,7 @@ def CheckOSXFramework(ctx, name):
save_FRAMEWORKS = env['FRAMEWORKS']
env.PrependUnique(FRAMEWORKS = [name])
result = \
- ctx.TryLink('int main(int argc, char **argv) {return 0;}', '.c')
+ ctx.TryLink('int main() {return 0;}\n', '.c')
ctx.Result(result)
if not result:
diff --git a/config/packager/__init__.py b/config/packager/__init__.py
index caf20bd44..d0c625312 100644
--- a/config/packager/__init__.py
+++ b/config/packager/__init__.py
@@ -1,4 +1,34 @@
-from __future__ import print_function
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
import os, platform, shutil, subprocess
@@ -7,7 +37,16 @@
from SCons.Script import *
from SCons.Action import CommandAction
-deps = ['nsi', 'pkg', 'distpkg', 'flatdistpkg', 'app', 'deb', 'rpm']
+deps = ['nsi', 'pkg', 'flatdistpkg', 'app', 'deb', 'rpm']
+
+
+def get_dist():
+ if os.path.exists('/etc/os-release'):
+ with open('/etc/os-release', 'r') as f:
+ for line in f:
+ if line.startswith('ID='):
+ return line[3:].strip(' \n\r"').lower()
+ return 'unknown'
# Older versions of Python don't have shutil.ignore_patterns()
@@ -21,6 +60,17 @@ def _ignore_patterns(path, names):
return _ignore_patterns
+def ignore_match(*patterns):
+ import fnmatch
+
+ def _ignore(path):
+ for pattern in patterns:
+ if fnmatch.fnmatch(path, pattern): return True
+ return False
+
+ return _ignore
+
+
def recursive_zip(path, archive, ignores):
if os.path.isdir(path): names = os.listdir(path)
else:
@@ -73,7 +123,7 @@ def _GetPackageType(env):
else: raise Exception('Invalid pkg package type "%s"' % pkg_type)
elif env['PLATFORM'] == 'posix':
- dist = platform.dist()[0].lower()
+ dist = get_dist()
if dist in ['debian', 'ubuntu']: return 'deb'
if dist in ['centos', 'redhat', 'fedora']: return 'rpm'
@@ -135,6 +185,7 @@ def GetPackageName(env, name, without_build = False, type = None):
if type == 'rpm': name += '.' + arch
else: name += seps[0] + arch # deb and others
+ if type == 'mpkg': type = 'pkg' # bundle mpkg is deprecated
name += '.' + type
if type in ('app', 'mpkg'): name += '.zip'
@@ -205,6 +256,39 @@ def ResolvePackageFileMap(env, sources, target):
return list(resolve_file_map(sources, target, ignores))
+def ReplaceVariablesInFiles(
+ env, sources, target, replace_all = False, ignore = None):
+ if ignore is None:
+ ignore = ignore_match(*env.get('PACKAGE_EXCLUDES'))
+
+ if not isinstance(sources, (list, tuple)): sources = [sources]
+
+ os.makedirs(target, exist_ok = True)
+
+ for src in sources:
+ if ignore(os.path.basename(src)): continue
+
+ replace = src.endswith('.in')
+ dst = target + '/' + os.path.basename(src[:-3] if replace else src)
+
+ if os.path.isdir(src):
+ for name in os.listdir(src):
+ env.ReplaceVariablesInFiles(
+ src + '/' + name, dst, replace_all or replace, ignore)
+
+ elif os.path.isfile(src) and (
+ (replace_all and not os.path.islink(src)) or replace):
+ print('replacing variables "%s" -> "%s"' % (src, dst))
+ with open(src, 'r') as inF:
+ with open(dst, 'w') as outF:
+ outF.write(inF.read() % env)
+
+ shutil.copymode(src, dst)
+
+ else: shutil.copy2(src, dst)
+
+
+
def CopyToPackage(env, sources, target, perms = 0o644, dperms = 0o755):
ignores = ignore_patterns(*env.get('PACKAGE_EXCLUDES'))
@@ -230,15 +314,17 @@ def RunCommand(env, cmd):
CommandAction(cmd).execute(None, [], env)
+def RunCommandOrRaise(env, cmd):
+ print('@', cmd)
+ ret = CommandAction(cmd).execute(None, [], env)
+ if ret: raise Exception('command failed, return code %s' % str(ret))
+
+
def WriteStringToFile(env, path, contents):
if not isinstance(contents, (list, tuple)): contents = [contents]
- f = None
- try:
- f = open(path, 'w')
+ with open(path, 'w') as f:
for line in contents: f.write(line + '\n')
- finally:
- if f is not None: f.close()
def Packager(env, name, **kwargs):
@@ -275,11 +361,7 @@ def Packager(env, name, **kwargs):
return (app, pkg)
- elif type == 'mpkg':
- if 'distpkg_components' in kwargs:
- return env.FlatDistPkg(target, [], **kwargs)
- else:
- return env.DistPkg(target, [], **kwargs)
+ elif type == 'mpkg':return env.FlatDistPkg(target, [], **kwargs)
elif type == 'deb': return env.Deb(target, [], **kwargs)
elif type == 'rpm': return env.RPM(target, [], **kwargs)
@@ -294,28 +376,14 @@ def generate(env):
if env['PLATFORM'] == 'darwin' or int(env.get('cross_osx', 0)):
env.CBAddVariables(
- # put sign_* in scons-options.py
- # if not sign_keychain, the default (login) keychain will be used
- # if not sign_id_installer, productsign will be skipped
- # sign_id_app is required for sign_apps and sign_tools
- # sign_prefix is required for sign_tools
- # global; cannot currently be overridden per-component
- ('sign_keychain', 'Keychain that has signatures'),
- ('sign_id_installer', 'Installer signature name'),
- ('sign_id_app', 'Application/Tool signature name'),
- ('sign_prefix', 'codesign identifier prefix'),
+ ('osx_min_ver', 'Set minimum supported OSX version.'),
)
- env.SetDefault(PACKAGE_EXCLUDES = ['.svn', '.sconsign.dblite',
+ env.SetDefault(PACKAGE_EXCLUDES = ['.DS_Store', '.svn', '.sconsign.dblite',
'.sconf_temp', '*~', '*.o', '*.obj'])
- env.CBLoadTool('nsi')
- env.CBLoadTool('pkg')
- env.CBLoadTool('distpkg')
- env.CBLoadTool('flatdistpkg')
- env.CBLoadTool('app')
- env.CBLoadTool('deb')
- env.CBLoadTool('rpm')
+ for tool in deps:
+ env.CBLoadTool(tool)
env.AddMethod(FindFiles)
env.AddMethod(WriteVariable)
@@ -325,7 +393,9 @@ def generate(env):
env.AddMethod(CopyToPackage)
env.AddMethod(InstallFiles)
env.AddMethod(RunCommand)
+ env.AddMethod(RunCommandOrRaise)
env.AddMethod(ResolvePackageFileMap)
+ env.AddMethod(ReplaceVariablesInFiles)
env.AddMethod(WriteStringToFile)
env.AddMethod(ZipDir)
env.AddMethod(Packager)
diff --git a/config/pkg/__init__.py b/config/pkg/__init__.py
index 4d10a6c4b..4b9b9e355 100644
--- a/config/pkg/__init__.py
+++ b/config/pkg/__init__.py
@@ -1,18 +1,57 @@
-from __future__ import print_function
-
-'''Builds an OSX single application package'''
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+'''Builds an OSX single component flat dist package'''
import os
import shutil
+import glob
from SCons.Script import *
-from SCons.Action import CommandAction
+
+deps = ['codesign', 'notarize']
-def RunCommandOrRaise(env, cmd):
- print('@', cmd)
- ret = CommandAction(cmd).execute(None, [], env)
- if ret: raise Exception('command failed, return code %s' % str(ret))
+# https://stackoverflow.com/a/65450788
+# fast xml escape
+xml_escape_table = str.maketrans({
+ "<": "<",
+ ">": ">",
+ "&": "&",
+ "'": "'",
+ '"': """,
+})
+def xml_escape(txt):
+ return txt.translate(xml_escape_table)
def InstallApps(env, key, target):
@@ -29,74 +68,107 @@ def InstallApps(env, key, target):
def build_function(target, source, env):
- # Create package build dir
+ # delete old package build dir
build_dir = 'build/pkg'
if os.path.exists(build_dir): shutil.rmtree(build_dir)
+ # pkg_id
+ if env.get('app_id') and not env.get('pkg_id'):
+ env.Replace(pkg_id = env.get('app_id') + '.pkg')
+ if not env.get('pkg_id'):
+ raise Exception('neither pkg_id nor app_id is set')
+
+ version = env.get('version')
+ if not version: raise Exception('version is not set')
+
# Make root dir
root_dir = os.path.join(build_dir, 'root')
- os.makedirs(root_dir, 0o775)
+ os.makedirs(root_dir, 0o755)
+
+ build_dir_packages = os.path.join(build_dir, 'Packages')
+ os.makedirs(build_dir_packages, 0o755)
+
+ build_dir_resources = os.path.join(build_dir, 'Resources')
+ os.makedirs(build_dir_resources, 0o755)
# Apps
- if 'pkg_apps' in env:
+ if env.get('pkg_apps'):
d = os.path.join(root_dir, 'Applications')
- os.makedirs(d, 0o775)
+ os.makedirs(d, 0o755)
InstallApps(env, 'pkg_apps', d)
# Other files
- if 'pkg_files' in env:
+ if env.get('pkg_files'):
env.InstallFiles('pkg_files', root_dir)
- # pkg_id
- if 'app_id' in env and not 'pkg_id' in env:
- env.Replace(pkg_id = env.get('app_id') + '.pkg')
+ pkg_resources = env.get('pkg_resources')
+ if pkg_resources:
+ if not isinstance(pkg_resources, (list, tuple)):
+ pkg_resources = [[pkg_resources, '.']]
+ env.CopyToPackage(pkg_resources, build_dir_resources)
+
+ for pattern in env.get('sign_apps', []):
+ for path in glob.glob(os.path.join(root_dir, pattern)):
+ env.SignApplication(path)
+
+ for pattern in env.get('sign_tools', []):
+ for path in glob.glob(os.path.join(root_dir, pattern)):
+ env.SignExecutable(path)
- # pkgbuild command
+ # build component pkg
cmd = ['${PKGBUILD}',
'--root', root_dir,
'--id', env.get('pkg_id'),
- '--version', env.get('version'),
+ '--version', version,
'--install-location', env.get('pkg_install_to', '/'),
]
- if 'pkg_scripts' in env: cmd += ['--scripts', env.get('pkg_scripts')]
- if 'pkg_plist' in env: cmd += ['--component-plist', env.get('pkg_plist')]
- cmd += [build_dir + '/%s.pkg' % env.get('package_name')]
+ if env.get('pkg_scripts'): cmd += ['--scripts', env.get('pkg_scripts')]
+ if env.get('pkg_plist'): cmd += ['--component-plist', env.get('pkg_plist')]
+ component_pkg = build_dir_packages + '/%s.pkg' % env.get('package_name')
+ cmd += [component_pkg]
- RunCommandOrRaise(env, cmd)
+ env.RunCommandOrRaise(cmd)
# Filter distribution.xml
dist = None
- if 'pkg_distribution' in env:
- f = open(env.get('pkg_distribution'), 'r')
- data = f.read()
- f.close()
+ if env.get('pkg_distribution'):
+ with open(env.get('pkg_distribution'), 'r') as f: data = f.read()
dist = build_dir + '/distribution.xml'
- f = open(dist, 'w')
- f.write(data % env)
- f.close()
+ # make xml escaped str values dict for distribution.xml insertion
+ xenv = {}
+ for key in env.keys():
+ value = env[key]
+ if isinstance(value, (str, bytes)):
+ xenv[key] = xml_escape(str(value))
+ with open(dist, 'w') as f: f.write(data % xenv)
+ # TODO else build distribution.xml similar to flatdistpkg
# productbuild command
- cmd = ['${PRODUCTBUILD}']
+ cmd = ['${PRODUCTBUILD}', '--version', version]
if dist:
cmd += ['--distribution', dist]
- cmd += ['--package-path', build_dir]
+ cmd += ['--package-path', build_dir_packages]
+ elif component_pkg:
+ print("WARNING: No distribution specified. Using --package.")
+ cmd += ['--package', component_pkg]
else:
- print("WARNING: No distribution specified. Attempting to build "
- "using --root. Package will not have Resources and will put "
- "wrong package id in receipts.")
+ print("WARNING: No distribution specified. Using --root.")
cmd += ['--root', root_dir, env.get('pkg_install_to', '/'),
- '--id', env.get('pkg_id'),
- '--version', env.get('version')]
- if 'pkg_scripts' in env: cmd += ['--scripts', env.get('pkg_scripts')]
- if 'pkg_resources' in env:
- cmd += ['--resources', env.get('pkg_resources')]
- if 'sign_id_installer' in env:
- cmd += ['--sign', env.get('sign_id_installer')]
- if 'sign_keychain' in env:
+ '--id', env.get('pkg_id')]
+ scripts = env.get('pkg_scripts')
+ if scripts: cmd += ['--scripts', scripts]
+
+ cmd += ['--resources', build_dir_resources]
+
+ if env.get('sign_id_installer') and not env.get('sign_disable'):
+ cmd += ['--sign', env.get('sign_id_installer'), '--timestamp']
+ if env.get('sign_keychain'):
cmd += ['--keychain', env.get('sign_keychain')]
+
cmd += [str(target[0])]
- RunCommandOrRaise(env, cmd)
+ env.RunCommandOrRaise(cmd)
+ env.NotarizeWaitStaple(str(target[0]), timeout = 1200)
def generate(env):
@@ -108,6 +180,8 @@ def generate(env):
source_scanner = SCons.Defaults.DirScanner)
env.Append(BUILDERS = {'Pkg' : bld})
+ for tool in deps: env.CBLoadTool(tool)
+
return True
diff --git a/config/pthreads/__init__.py b/config/pthreads/__init__.py
index eed35de13..45b0d5c29 100644
--- a/config/pthreads/__init__.py
+++ b/config/pthreads/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
@@ -5,7 +37,7 @@ def configure(conf):
conf.CBCheckHome('pthreads')
conf.CBRequireHeader('pthread.h')
conf.CBRequireLib('pthread')
- conf.env.CBDefine('HAVE_PTHREADS')
+ conf.env.CBConfigDef('HAVE_PTHREADS')
def generate(env):
diff --git a/config/python/__init__.py b/config/python/__init__.py
index 233dca896..52e35f414 100644
--- a/config/python/__init__.py
+++ b/config/python/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from __future__ import print_function
from SCons.Script import *
@@ -17,7 +49,7 @@ def try_config(conf, command):
if conf.CheckHeader('Python.h') and conf.CheckFunc('Py_Initialize'):
env.ParseConfig(command)
- env.CBDefine('HAVE_PYTHON');
+ env.CBConfigDef('HAVE_PYTHON');
env.Prepend(LIBS = ['util', 'm', 'dl', 'z'])
return True
diff --git a/config/python/python-config.py b/config/python/python-config.py
index 61cc48706..96674090b 100644
--- a/config/python/python-config.py
+++ b/config/python/python-config.py
@@ -1,4 +1,37 @@
#!env python
+
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from __future__ import print_function
import sys
diff --git a/config/re2/__init__.py b/config/re2/__init__.py
index 735ee84d3..ef0bbbad9 100644
--- a/config/re2/__init__.py
+++ b/config/re2/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
diff --git a/config/resources/__init__.py b/config/resources/__init__.py
index d2e08deef..91e7f8bdb 100644
--- a/config/resources/__init__.py
+++ b/config/resources/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from __future__ import print_function
import os
@@ -11,235 +43,198 @@
from SCons.Script import *
-col = 0
-
-class ResourceContext:
- def __init__(self): pass
+resource_version = 2
-def start_file(ctx, path):
- f = open(path, 'w')
+class ResourceContext:
+ def __init__(self): pass
- note = ('WARNING: This file was auto generated. Please do NOT '
- 'edit directly or check in to source control.')
- f.write(
- '/' + ('*' * 75) + '\\\n ' +
- '\n '.join(textwrap.wrap(note)) + '\n' +
- '\\' + ('*' * 75) + '/\n'
- '\n'
- '#include \n\n'
- 'using namespace cb;\n\n'
- )
+def start_file(ctx, f):
+ note = ('WARNING: This file was auto generated. Please do NOT '
+ 'edit directly or check in to source control.')
- if ctx.ns:
- for namespace in ctx.ns.split('::'):
- f.write('namespace %s {\n' % namespace)
+ f.write(
+ '/' + ('*' * 75) + '\\\n ' +
+ '\n '.join(textwrap.wrap(note)) + '\n' +
+ '\\' + ('*' * 75) + '/\n'
+ '\n'
+ '#include \n\n'
+ 'using namespace cb;\n\n')
- return f
+ if ctx.ns:
+ for namespace in ctx.ns.split('::'):
+ f.write('namespace %s {\n' % namespace)
def end_file(ctx, f):
- if ctx.ns:
- for namespace in ctx.ns.split('::'):
- f.write('} // namespace %s\n' % namespace)
-
- f.close()
+ if ctx.ns:
+ for namespace in ctx.ns.split('::'):
+ f.write('} // namespace %s\n' % namespace)
def write_string(ctx, output, s, newline = 0):
- l = len(s)
+ l = len(s)
- if newline or ctx.col + l > 80:
- output.write('\n')
- ctx.col = 0
+ if newline or ctx.col + l > 80:
+ output.write('\n')
+ ctx.col = 0
- i = s.rfind('\n')
- if i != -1: ctx.col = l - (i + 1)
- else: ctx.col += l
+ i = s.rfind('\n')
+ if i != -1: ctx.col = l - (i + 1)
+ else: ctx.col += l
- output.write(s)
+ output.write(s)
def is_excluded(exclude, path):
- return exclude != None and exclude.search(path) != None
+ return exclude != None and exclude.search(path) != None
def write_resource(ctx, output, data_dir, path, children = None,
exclude = None):
- name = os.path.basename(path)
- if is_excluded(ctx.exclude, path): return
+ name = os.path.basename(path)
+ if is_excluded(ctx.exclude, path): return
- is_dir = os.path.isdir(path)
- id = ctx.next_id
- ctx.next_id += 1
- length = 0
+ is_dir = os.path.isdir(path)
+ id = ctx.next_id
+ ctx.next_id += 1
+ length = 0
- if is_dir:
- typeStr = 'Directory'
- child_resources = []
+ if is_dir:
+ typeStr = 'Directory'
+ child_resources = []
- for filename in os.listdir(path):
- write_resource(ctx, output, data_dir, os.path.join(path, filename),
- child_resources, exclude)
+ for filename in os.listdir(path):
+ write_resource(ctx, output, data_dir, os.path.join(path, filename),
+ child_resources, exclude)
- write_string(ctx, output, 'const Resource *children%d[] = {' % id)
+ write_string(ctx, output, 'const Resource *children%d[] = {' % id)
- for res in child_resources:
- write_string(ctx, output, '&resource%d,' % res)
+ for res in child_resources:
+ write_string(ctx, output, '&resource%d,' % res)
- write_string(ctx, output, '0};\n')
+ write_string(ctx, output, '0};\n')
- else:
- out_path = '%s/data%d.cpp' % (data_dir, id)
- print('Writing resource: %s to %s' % (path, out_path))
+ else:
+ out_path = '%s/data%d.cpp' % (data_dir, id)
+ print('Writing resource: %s to %s' % (path, out_path))
- typeStr = 'File'
- f = open(path, 'rb')
+ typeStr = 'File'
+ with open(path, 'rb') as f:
+ prototype = 'extern const unsigned char data%d[]' % id
- prototype = 'extern const unsigned char data%d[]' % id
+ write_string(ctx, output, '%s;\n' % prototype)
- write_string(ctx, output, '%s;\n' % prototype)
-
- out = start_file(ctx, out_path)
+ with open(out_path, 'w') as out:
+ start_file(ctx, out)
write_string(ctx, out, prototype + ' = {')
while True:
- count = 0
- for c in f.read(102400):
- if not isinstance(c, int): c = ord(c)
- write_string(ctx, out, '%d,' % c)
- count += 1
+ count = 0
+ for c in f.read(102400):
+ if not isinstance(c, int): c = ord(c)
+ write_string(ctx, out, '%d,' % c)
+ count += 1
- if count == 0: break
- length += count
+ if count == 0: break
+ length += count
write_string(ctx, out, '0};\n')
end_file(ctx, out)
- if children != None: children.append(id)
-
- output.write('extern const %sResource resource%d("%s", ' %
- (typeStr, id, name))
-
- if is_dir: output.write('children%d' % id)
- else: output.write('(const char *)data%d, %d' % (id, length))
-
- output.write(');\n')
-
+ if children != None: children.append(id)
-def update_time(ctx, path):
- if not os.path.exists(path): return 0
- exclude = ctx.exclude
- if exclude is not None and exclude.search(path) is not None: return 0
+ output.write('extern const %sResource resource%d("%s", ' %
+ (typeStr, id, name))
- if os.path.isdir(path):
- updated = 0
+ if is_dir: output.write('children%d' % id)
+ else: output.write('(const char *)data%d, %d' % (id, length))
- for name in os.listdir(path):
- t = os.stat(path)[stat.ST_MTIME]
- if updated < t: updated = t
- t = update_time(os.path.join(path, name), exclude)
- if updated < t: updated = t
-
- return updated
-
- else: return os.stat(path)[stat.ST_MTIME]
+ output.write(');\n')
def get_exclude(env):
- pattern = None
- for ex in env.get('RESOURCES_EXCLUDES'):
- if pattern == None: pattern = ''
- else: pattern += '|'
- pattern += '(%s)' % ex
+ pattern = None
+ for ex in env.get('RESOURCES_EXCLUDES'):
+ if pattern == None: pattern = ''
+ else: pattern += '|'
+ pattern += '(%s)' % ex
- return re.compile(pattern)
+ return re.compile(pattern)
def resources_build(target, source, env):
- ctx = ResourceContext()
- ctx.env = env
- ctx.ns = env.get('RESOURCES_NS')
- ctx.exclude = get_exclude(env)
- ctx.next_id = 0
- ctx.col = 0
-
- target = str(target[0])
-
- # Check update times
- if not env.get('RESOURCES_ALWAYS_BUILD'):
- if os.path.exists(target):
- updated = False
- lastUpdate = os.stat(target)[stat.ST_MTIME]
+ ctx = ResourceContext()
+ ctx.env = env
+ ctx.ns = env.get('RESOURCES_NS')
+ ctx.exclude = get_exclude(env)
+ ctx.next_id = 0
+ ctx.col = 0
- for src in source:
- if lastUpdate < update_time(ctx, str(src)):
- updated = True
- break
+ target = str(target[0])
- if not updated: return
+ data_dir = os.path.splitext(target)[0] + ".data"
+ if os.path.exists(data_dir): shutil.rmtree(data_dir)
+ os.mkdir(data_dir)
- data_dir = os.path.splitext(target)[0] + ".data"
- if os.path.exists(data_dir): shutil.rmtree(data_dir)
- os.mkdir(data_dir)
-
- # Write resources
- f = start_file(ctx, target)
+ # Write resources
+ with open(target, 'w') as f:
+ start_file(ctx, f)
for src in source:
- write_resource(ctx, f, data_dir, str(src))
+ write_resource(ctx, f, data_dir, str(src))
+
+ nsParts = ctx.ns.lower().split('::')
+ f.write(('void loadResources() {\n'
+ ' cb::ResourceManager::instance().add("%s", &resource0);\n'
+ '}\n') % '.'.join(nsParts))
end_file(ctx, f)
def get_targets(exclude, path, data_dir, count = [0]):
- if is_excluded(exclude, path): return []
+ if is_excluded(exclude, path): return []
- id = count[0]
- count[0] += 1
+ if not os.path.exists(path):
+ raise Exception('Resource "%s" does not exist' % path)
- if os.path.isdir(path):
- targets = []
+ id = count[0]
+ count[0] += 1
- for name in os.listdir(path):
- targets += \
- get_targets(exclude, os.path.join(path, name), data_dir, count)
+ if os.path.isdir(path):
+ targets = []
- return targets
+ for name in os.listdir(path):
+ child = os.path.join(path, name)
+ targets += get_targets(exclude, child, data_dir, count)
- else:
- target = '%s/data%d.cpp' % (data_dir, id)
- return [File(target)]
+ return targets
+ return Depends(File('data%d.cpp' % id, data_dir), path)
-def modify_targets(target, source, env):
- exclude = get_exclude(env)
- name = str(target[0])
- data_dir = os.path.splitext(name)[0] + ".data"
- target += get_targets(exclude, str(source[0]), data_dir, [0])
- print(tuple(map(str, target)))
- Depends(target, FindFile('cbang/util/Resource.h', env['CPPPATH']))
- return target, source
-
-def resources_message(target, source, env):
- return 'building resource file "%s"' % str(target[0])
+def modify_targets(target, source, env):
+ exclude = get_exclude(env)
+ name = str(target[0])
+ base, ext = os.path.splitext(name)
+ data_dir = '%s.v%d.data' % (base, resource_version)
+ target = ['%s.v%d%s' % (base, resource_version, ext)]
+ count = [0]
+ for s in source: target += get_targets(exclude, str(s), data_dir, count)
+ return target, source
def generate(env):
- env.SetDefault(RESOURCES_NS = '')
- env.SetDefault(RESOURCES_EXCLUDES = [r'\.svn', r'.*~'])
- env.SetDefault(RESOURCES_ALWAYS_BUILD = True)
+ env.SetDefault(RESOURCES_NS = '')
+ env.SetDefault(RESOURCES_EXCLUDES = [r'\.svn', r'~$'])
- bld = env.Builder(action = resources_build,
- source_factory = SCons.Node.FS.Entry,
- source_scanner = SCons.Defaults.DirScanner,
- emitter = modify_targets)
- env.Append(BUILDERS = {'Resources' : bld})
+ bld = env.Builder(action = resources_build,
+ source_factory = SCons.Node.FS.Entry,
+ emitter = modify_targets)
+ env.Append(BUILDERS = {'Resources' : bld})
-def exists():
- return True
+def exists(): return True
diff --git a/config/rpm/__init__.py b/config/rpm/__init__.py
index 52ea357d0..90984073b 100644
--- a/config/rpm/__init__.py
+++ b/config/rpm/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
import os
import shutil
@@ -18,16 +50,13 @@ def write_spec_script(f, env, name, var):
if var in env:
script = env.get(var)
- input = None
- try:
- input = open(script, 'r')
- contents = input.read().strip()
-
- finally:
- if input is not None: input.close()
+ with open(script, 'r') as input: contents = input.read().strip()
f.write('%%%s\n%s\n\n' % (name, contents))
+ elif name == 'install':
+ f.write('%install\ncp -aT %{cbang_build} %{buildroot}\n\n')
+
def install_files(f, env, key, build_dir, path, prefix = None, perms = None,
dperms = 0o755):
@@ -35,53 +64,77 @@ def install_files(f, env, key, build_dir, path, prefix = None, perms = None,
if key in env:
target = build_dir + path
+ value = env.get(key)
# Copy
- env.CopyToPackage(env.get(key), target, perms, dperms)
+ env.CopyToPackage(value, target, perms, dperms)
# Write files list
- for src, dst, mode in env.ResolvePackageFileMap(env.get(key), target):
- if prefix is not None: f.write(prefix + ' ')
- f.write(dst[len(build_dir):] + '\n')
+ if key != 'documents':
+ for src, dst, mode in env.ResolvePackageFileMap(value, target):
+ if prefix is not None: f.write(prefix + ' ')
+ f.write(dst[len(build_dir):] + '\n')
+
+
+def install_dirs(f, env, key, build_dir, prefix = None, dperms = 0o755):
+ # Create dirs and write dirs list
+ for dir in env.get(key):
+ target = build_dir + '/' + dir.lstrip('/')
+ print("creating directory %s" % target)
+ os.makedirs(target, dperms)
+ if prefix: f.write(prefix + ' ')
+ else: f.write('%dir ')
+ f.write(target[len(build_dir):] + '\n')
def build_function(target, source, env):
name = env.get('package_name_lower')
# Create package build dir
- build_dir = 'build/%s-RPM' % name
+ # SPEC's %install section is responsible for populating BUILDROOT (aka
+ # %{buildroot} or $RPM_BUILD_ROOT) using our custom %{cbang_build} macro as
+ # source
+ build_dir = 'build/%s-BUILD' % name
if os.path.exists(build_dir): shutil.rmtree(build_dir)
os.makedirs(build_dir)
- # Create the SPEC file
- spec_file = 'build/%s.spec' % name
- f = None
- try:
- f = open(spec_file, 'w')
+ # Create directories needed by rpmbuild
+ for dir in ['BUILD', 'BUILDROOT', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS']:
+ dir = 'build/' + dir
+ if os.path.exists(dir): shutil.rmtree(dir)
+ os.makedirs(dir)
+ # Create the SPEC file
+ spec_file = 'build/SPECS/%s.spec' % name
+ with open(spec_file, 'w') as f:
# Create the preamble
write_var = env.WriteVariable
write_var(env, f, 'Summary', 'summary')
- write_var(env, f, 'Name', 'package_name_lower', None, replace_dash)
+ write_var(env, f, 'Name', 'package_name_lower')
write_var(env, f, 'Version', 'version', None, replace_dash)
write_var(env, f, 'Release', 'package_build', '1', replace_dash)
write_var(env, f, 'License', 'rpm_license')
write_var(env, f, 'Group', 'rpm_group')
write_var(env, f, 'URL', 'url')
+ write_var(env, f, 'BugURL', 'bug_url')
write_var(env, f, 'Vendor', 'vendor')
write_var(env, f, 'Packager', 'maintainer')
- write_var(env, f, 'Icon', 'icon')
- write_var(env, f, 'Prefix', 'prefix')
#write_var(env, f, 'BuildArch', 'package_arch', env.GetPackageArch())
write_var(env, f, 'Provides', 'rpm_provides', multi = True)
write_var(env, f, 'Conflicts', 'rpm_conflicts', multi = True)
write_var(env, f, 'Obsoletes', 'rpm_obsoletes', multi = True)
+ write_var(env, f, 'Recommends', 'rpm_recommends', multi = True)
+ write_var(env, f, 'Suggests', 'rpm_suggests', multi = True)
write_var(env, f, 'BuildRequires', 'rpm_build_requires', multi = True)
- write_var(env, f, 'Requires(pre)', 'rpm_pre_requires', multi = True)
write_var(env, f, 'Requires', 'rpm_requires', multi = True)
+ write_var(env, f, 'Requires(pre)', 'rpm_pre_requires', multi = True)
+ write_var(env, f, 'Requires(preun)', 'rpm_preun_requires', multi = True)
+ write_var(env, f, 'Requires(post)', 'rpm_post_requires', multi = True)
write_var(env, f, 'Requires(postun)', 'rpm_postun_requires',
multi = True)
+ f.write('\n')
+
# Description
write_spec_text_section(f, env, 'description', 'description')
@@ -94,44 +147,53 @@ def build_function(target, source, env):
if 'rpm_filelist' in env:
f.write('%%files -f %s\n' % env.get('rpm_filelist'))
else: f.write('%files\n')
- f.write('%defattr(- root root)\n')
+
+ # See https://bugzilla.redhat.com/show_bug.cgi?id=1113233#c3
+ if 'documents' in env:
+ f.write('/usr/share/doc/' + name + '\n')
for files in [
- ['documents', '/usr/share/doc/' + name, '%doc', None],
- ['programs', '/usr/bin', '%attr(0775 root root)', 0o755],
- ['scripts', '/usr/bin', '%attr(0775 root root)', 0o755],
+ ['documents', '/usr/share/doc/' + name, None, None],
+ ['programs', '/usr/bin', None, 0o755],
+ ['scripts', '/usr/bin', None, 0o755],
['desktop_menu', '/usr/share/applications', None, None],
- ['init_d', '/etc/init.d', '%config %attr(0775 root root)', None],
+ ['init_d', '/etc/init.d', '%config', 0o755],
['config', '/etc/' + name, '%config', None],
['icons', '/usr/share/pixmaps', None, None],
['mime', '/usr/share/mime/packages', None, None],
['platform_independent', '/usr/share/' + name, None, None],
+ ['misc', '/', None, None],
+ ['systemd', '/usr/lib/systemd/system', None, None],
]:
install_files(f, env, files[0], build_dir, files[1], files[2],
files[3])
+ install_dirs(f, env, 'rpm_client_dirs', build_dir,
+ '%attr(-,' + name + ',' + name + ') %dir')
+
# ChangeLog
write_spec_text_section(f, env, 'changelog', 'rpm_changelog')
- finally:
- if f is not None: f.close()
-
- # Create directories needed by rpmbuild
- for dir in ['BUILD', 'BUILDROOT', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS']:
- dir = 'build/' + dir
- if not os.path.exists(dir): os.makedirs(dir)
-
+ # rpmbuild strips debug information from binaries by default if %install
+ # section is present (may be empty)
+ if int(env.get('debug')):
+ # Fedora/RHEL
+ cmddebug = ' --define "__strip /usr/bin/true"'
+ # openSUSE
+ env.Append(ENV = {'NO_BRP_STRIP_DEBUG' : 'true'})
+ else: cmddebug = ''
# Build the package
- build_dir = os.path.realpath(build_dir)
- cmd = 'rpmbuild -bb --buildroot %s --define "_topdir %s/build" ' \
- '--target %s %s' % (
- build_dir, os.getcwd(), env.GetPackageArch(), spec_file)
- CommandAction(cmd).execute(target, [build_dir], env)
+ target = str(target[0])
+ cmd = 'rpmbuild -bb --define "_topdir %s/build" --define ' \
+ '"_rpmfilename %s" --define "cbang_build %s" ' \
+ '--define "__brp_mangle_shebangs %%{nil}"' '%s --target %s %s' % (
+ os.getcwd(), target, os.path.realpath(build_dir), cmddebug,
+ env.GetPackageArch(), spec_file)
+ CommandAction(cmd).execute(target, [], env)
# Move the package
- target = str(target[0])
- path = 'build/RPMS/' + env.GetPackageArch() + '/' + target
+ path = 'build/RPMS/' + target
shutil.move(path, target)
diff --git a/config/run_distutils/__init__.py b/config/run_distutils/__init__.py
index 72b4db58b..bea819bfe 100644
--- a/config/run_distutils/__init__.py
+++ b/config/run_distutils/__init__.py
@@ -1,12 +1,47 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
+import os
def generate(env):
env.SetDefault(RUN_DISTUTILS = 'python')
env.SetDefault(RUN_DISTUTILSOPTS = 'build')
- env['RUN_DISTUTILS'] = 'python'
- env['RUN_DISTUTILSOPTS'] = 'build'
+ if 'RUN_DISTUTILS' in os.environ:
+ env['RUN_DISTUTILS'] = os.environ['RUN_DISTUTILS']
+ if 'RUN_DISTUTILSOPTS' in os.environ:
+ env['RUN_DISTUTILSOPTS'] = os.environ['RUN_DISTUTILSOPTS']
bld = Builder(action = '$RUN_DISTUTILS $SOURCE $RUN_DISTUTILSOPTS')
env.Append(BUILDERS = {'RunDistUtils' : bld})
diff --git a/config/sqlite3/__init__.py b/config/sqlite3/__init__.py
index 4b8da70fd..ef2d9c241 100644
--- a/config/sqlite3/__init__.py
+++ b/config/sqlite3/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
@@ -15,7 +47,7 @@ def configure(conf):
conf.CBRequireHeader('sqlite3.h')
conf.CBRequireFunc('sqlite3_backup_init')
- env.CBDefine('HAVE_LIBSQLITE')
+ env.CBConfigDef('HAVE_LIBSQLITE')
def generate(env):
diff --git a/config/test/__init__.py b/config/test/__init__.py
index 9fdde648c..a5b76cabe 100644
--- a/config/test/__init__.py
+++ b/config/test/__init__.py
@@ -1,4 +1,37 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
+import shlex
def run_tests(env):
@@ -6,16 +39,27 @@ def run_tests(env):
import subprocess
import sys
- sys.exit(subprocess.call(shlex.split(env.get('TEST_COMMAND'))))
+ cmd = shlex.split(env.get('TEST_COMMAND'))
+ print('Executing:', cmd)
+ sys.exit(subprocess.call(cmd))
def generate(env):
import os
+ import sys
+
+ python = sys.executable
+
+ dir = os.path.dirname(os.path.realpath(__file__))
+ testHarness = dir + '/../../tests/testHarness'
- cmd = 'python tests/testHarness -C tests --diff-failed --view-failed ' \
- '--view-unfiltered --save-failed --build'
+ if env['PLATFORM'] == 'win32':
+ python = python.replace('\\', '\\\\')
+ testHarness = testHarness.replace('\\', '\\\\')
- if 'DOCKBOT_MASTER_PORT' in os.environ: cmd += ' --no-color'
+ cmd = [python, testHarness, '-C', 'tests', '--diff-failed', '--view-failed',
+ '--view-unfiltered', '--save-failed', '--build']
+ cmd = ' '.join([shlex.quote(s) for s in cmd]) # shlex.join() not in < 3.8
env.CBAddVariables(('TEST_COMMAND', '`test` target command line', cmd))
diff --git a/config/v8/__init__.py b/config/v8/__init__.py
index 74c889796..04019f1f7 100644
--- a/config/v8/__init__.py
+++ b/config/v8/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
import platform
@@ -7,14 +39,21 @@ def configure(conf):
if conf.env.get('debug', False): lib_suffix.append('/build/Release/lib')
else: lib_suffix.append('/build/Debug/lib')
+ if not 'V8_INCLUDE' in os.environ and not 'V8_HOME' in os.environ:
+ os.environ['V8_INCLUDE'] = '/usr/include/v8'
+
conf.CBCheckHome('v8', lib_suffix = lib_suffix)
if conf.env['PLATFORM'] == 'win32' or int(conf.env.get('cross_mingw', 0)):
conf.CBRequireLib('winmm')
+ conf.CBCheckLib('dbghelp')
conf.CBRequireCXXHeader('v8.h')
+ conf.CBRequireCXXHeader('libplatform/libplatform.h')
- if not conf.CBCheckLib('v8'):
+ if conf.CBCheckLib('v8_monolith'): pass
+ elif conf.CBCheckLib('v8'): conf.CBCheckLib('v8_libplatform')
+ else:
conf.CBRequireLib('v8_snapshot')
if not conf.CBCheckLib('v8_base'):
@@ -22,7 +61,10 @@ def configure(conf):
conf.CBRequireLib('v8_base.x64')
else: conf.CBRequireLib('v8_base.ia32')
- conf.env.CBDefine('HAVE_V8')
+ if conf.env.get('v8_compress_pointers'):
+ conf.env.CBConfigDef('V8_COMPRESS_POINTERS')
+
+ conf.env.CBConfigDef('HAVE_V8')
def generate(env):
diff --git a/config/valgrind/__init__.py b/config/valgrind/__init__.py
index 2b8966aa3..b05029932 100644
--- a/config/valgrind/__init__.py
+++ b/config/valgrind/__init__.py
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2025, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
from SCons.Script import *
@@ -8,7 +40,7 @@ def configure(conf):
conf.CBCheckHeader('valgrind/drd.h') and \
conf.CBCheckHeader('valgrind/helgrind.h') and \
conf.CBCheckHeader('valgrind/memcheck.h'):
- env.CBDefine('HAVE_VALGRIND')
+ env.CBConfigDef('HAVE_VALGRIND')
def generate(env):
diff --git a/config/zlib/__init__.py b/config/zlib/__init__.py
deleted file mode 100644
index 6be57f669..000000000
--- a/config/zlib/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from SCons.Script import *
-
-
-def configure(conf):
- conf.CBCheckHome('zlib', lib_suffix = ['', '/lib'],
- inc_suffix = ['/src', '/include'])
- conf.CBRequireHeader('zlib.h')
- conf.CBRequireLib('z')
-
-
-def generate(env):
- env.CBAddConfigTest('zlib', configure)
-
-
-def exists():
- return 1
diff --git a/debian/changelog b/debian/changelog
index 0dd4f7350..5ff26c03c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,5 @@
-cbang (0.0.0) UNRELEASED; urgency=low
+cbang (1.3.3-1) unstable; urgency=low
- * Initial release.
+ * Initial release. (Closes: #949344)
-- Joseph Coffland Fri, 13 Jan 2012 16:25:58 -0800
diff --git a/debian/compat b/debian/compat
index 45a4fb75d..f599e28b8 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-8
+10
diff --git a/debian/control b/debian/control
index febb878ba..5e841a799 100644
--- a/debian/control
+++ b/debian/control
@@ -2,15 +2,9 @@ Source: cbang
Maintainer: Joseph Coffland
Section: libs
Priority: optional
-Standards-Version: 3.9.2
+Standards-Version: 4.4.1
Homepage: http://cbang.org/
-Vcs-Svn: svn://cauldrondevelopment.com/svn/cbang/trunk/cbang
-Vcs-Browser: https://cauldrondevelopment.com/svn/cbang/trunk/cbang
-Build-Depends: debhelper (>= 8), cdbs, libexpat1-dev,
- libssl-dev, libsqlite3-dev, libboost-iostreams-dev (>= 1.40.0),
- libboost-filesystem-dev (>= 1.40.0), libboost-system-dev (>= 1.40.0),
- libboost-regex-dev (>= 1.40.0)
-
+Build-Depends: debhelper (>= 11), cdbs, scons, libssl-dev, libnode-dev
Package: libcbang0-dev
Provides: libcbang-dev
@@ -35,22 +29,14 @@ Description: C! development files
reusable code. C! also encourages exception based error handling,
and light use of C++ templates and C preprocesor macros.
.
- C! "leans" on the venerable boost library but also reimplements
- several boost APIs which are considered by the author to be too
- template heavy, less readable or overly complicated in boost.
- .
The code was developed on an as needed basis and was never intended to
be any sort of grand unifying system for C++ application development.
However, I hope you find many parts of the library useful in your C++
development projects.
-
Package: libcbang0
Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, libexpat1,
- libssl1.0.0, libsqlite3-0, libboost-iostreams (>= 1.40.0),
- libboost-filesystem (>= 1.40.0), libboost-system (>= 1.40.0),
- libboost-regex (>= 1.40.0)
+Depends: ${shlibs:Depends}, ${misc:Depends}, libssl1.1, libnode
Description: C! is a collection of cross-platform C++ utility libraries
C! is a collection of C++ utility libraries developed over the course
of +10 years and several major C++ application development
@@ -67,10 +53,6 @@ Description: C! is a collection of cross-platform C++ utility libraries
reusable code. C! also encourages exception based error handling,
and light use of C++ templates and C preprocesor macros.
.
- C! "leans" on the venerable boost library but also reimplements
- several boost APIs which are considered by the author to be too
- template heavy, less readable or overly complicated in boost.
- .
The code was developed on an as needed basis and was never intended to
be any sort of grand unifying system for C++ application development.
However, I hope you find many parts of the library useful in your C++
diff --git a/debian/copyright b/debian/copyright
index 09c787682..80fe1e9f5 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,11 +1,11 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
-Upstream-Name: C!
+Upstream-Name: cbang
Upstream-Contact: Joseph Coffland
-Source: https://cauldrondevelopment.com/svn/cbang/trunk/cbang
+Source: https://github.com/CauldronDevelopmentLLC/cbang
Files: *
-Copyright: 2003-2014, Cauldron Development LLC, Stanford University
-License: GPL-2+
+Copyright: 2003-2024 Cauldron Development LLC
+License: LGPL-2.1-or-later
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
@@ -23,3 +23,174 @@ License: GPL-2+
can be found at `/usr/share/common-licenses/GPL-2'.
.
A special exception to the GPL is granted for linking with openssl.
+
+Files: src/libevent/*
+Copyright: 2002-2007 Niels Provos
+ 2007-2012 Niels Provos and Nick Mathewson
+License:
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ .
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Files: src/bzip2/*
+Copyright: 1996-2010 Julian R Seward
+License: BSD-variant
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ .
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ .
+ 2. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+ .
+ 3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+ .
+ 4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Files: src/expat/*
+Copyright:
+ Copyright (C) 1998-2000 Thai Open Source Software Center Ltd and Clark Cooper
+ Copyright (C) 2001-2017 Expat maintainers
+License: MIT
+
+Files: src/libyaml/*
+Copyright: 2006, Kirill Simonov
+License: Expat
+ 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.
+
+Files: src/re2/*
+Copyright: 2002-2018, Google Inc.,
+ 2014, Samsung Electronics,
+ 2010-2016, Stefano Rivera
+License: BSD-3-google
+
+Files: src/re2/src/util/utf.h src/re2/src/util/rune.cc
+Copyright: 2002, Lucent Technologies
+License: Lucent
+ Permission to use, copy, modify, and distribute this software for any purpose
+ without fee is hereby granted, provided that this entire notice is included in
+ all copies of any software which is or includes a copy or modification of this
+ software and in all copies of the supporting documentation for such software.
+ .
+ THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
+ SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+
+Files: src/sqlite3/*
+Copyright: D. Richard Hipp
+License: public-domain
+ The files listed have been put on the public domain by the sqlite3
+ contributors.
+
+Files: src/zlib/*
+Copyright: 1995-2013 Jean-loup Gailly and Mark Adler
+License: Zlib
+
+Files: src/boost/*
+Copyright: Boost project contributors
+License: BSL-1.0
+Comment:
+ For a few files it is difficult or impossible to establish an actual
+ copyright holder; most of such files carry little to no creative
+ content, so the mere fact that they are covered by copyright
+ protection is not obvious. Most probably all such files can safely be
+ considered under the Boost Software License.
+
+Files: src/boost/libs/iostreams/*
+Copyright: Jonathan Turkanis
+License: BSL-1.0
+
+Files:
+ src/boost/libs/filesystem/*
+ src/boost/libs/system/*
+Copyright: Beman Dawes
+License: BSL-1.0
+
+Files:
+ src/boost/libs/iostreams/src/bzip2.cpp
+ src/boost/libs/iostreams/src/file_descriptor.cpp
+ src/boost/libs/iostreams/src/gzip.cpp
+ src/boost/libs/iostreams/src/zlib.cpp
+Copyright:
+ CodeRage LLC
+ Jonathan Turkanis
+License: BSL-1.0
+
+Files: src/boost/libs/iostreams/src/mapped_file.cpp
+Copyright:
+ Craig Henderson
+ Jonathan Graehl
+ Jonathan Turkanis
+ Jorge Lodos
+License: BSL-1.0
+
+Files: src/boost/libs/regex/*
+Copyright: John Maddock
+License: BSL-1.0
+
+Files: src/boost/libs/filesystem/src/utf8_codecvt_facet.cpp
+Copyright: Vladimir Prus
+License: BSL-1.0
+
+Files: src/boost/libs/filesystem/src/operations.cpp
+Copyright:
+ Beman Dawes
+ Dietmar Kuehl
+License: BSL-1.0
diff --git a/debian/rules b/debian/rules
index e78639af5..c0fe89645 100755
--- a/debian/rules
+++ b/debian/rules
@@ -9,7 +9,7 @@ include /usr/share/cdbs/1/rules/debhelper.mk
LIBPKGNAME = libcbang0
#SONAME = "$(DEB_UPSTREAM_VERSION)"
-DEB_SCONS_OPTIONS = sharedlib=1 ccache=1 -j 8
+DEB_SCONS_OPTIONS = sharedlib=1 -j8
DEB_SCONS_INSTALL_OPTIONS += prefix="$(cdbs_curdestdir)/usr"
DEB_DH_MAKESHLIBS_ARGS = -- -c4
diff --git a/debian/watch b/debian/watch
new file mode 100644
index 000000000..97854d7fb
--- /dev/null
+++ b/debian/watch
@@ -0,0 +1,4 @@
+version=4
+opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%$1.tar.gz%" \
+ https://github.com/CauldronDevelopmentLLC/cbang/tags \
+ (?:.*?/)?v?(\d[\d.]*)\.tar\.gz debian uupdate
diff --git a/docs/www/Makefile b/docs/www/Makefile
index 673c889e7..c2b0d3443 100644
--- a/docs/www/Makefile
+++ b/docs/www/Makefile
@@ -1,3 +1,35 @@
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2024, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
all: index.html
%.html: %.jade
diff --git a/docs/www/css/style.css b/docs/www/css/style.css
index e777850cb..4b0844f82 100644
--- a/docs/www/css/style.css
+++ b/docs/www/css/style.css
@@ -1,3 +1,35 @@
+/******************************************************************************\
+
+ This file is part of the C! library. A.K.A the cbang library.
+
+ Copyright (c) 2021-2024, Cauldron Development Oy
+ Copyright (c) 2003-2021, Cauldron Development LLC
+ All rights reserved.
+
+ The C! library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation, either version 2.1 of
+ the License, or (at your option) any later version.
+
+ The C! library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the C! library. If not, see
+ .
+
+ In addition, BSD licensing may be granted on a case by case basis
+ by written permission from at least one of the copyright holders.
+ You may request written permission by emailing the authors.
+
+ For information regarding this software email:
+ Joseph Coffland
+ joseph@cauldrondevelopment.com
+
+\******************************************************************************/
+
html * {
padding: 0;
margin: 0;
diff --git a/docs/www/index.jade b/docs/www/index.jade
index 06df37a5d..374d2c33a 100644
--- a/docs/www/index.jade
+++ b/docs/www/index.jade
@@ -1,3 +1,35 @@
+//-/////////////////////////////////////////////////////////////////////////////
+//- //
+//- This file is part of the C! library. A.K.A the cbang library. //
+//- //
+//- Copyright (c) 2021-2024, Cauldron Development Oy //
+//- Copyright (c) 2003-2021, Cauldron Development LLC //
+//- All rights reserved. //
+//- //
+//- The C! library is free software: you can redistribute it and/or //
+//- modify it under the terms of the GNU Lesser General Public License //
+//- as published by the Free Software Foundation, either version 2.1 of //
+//- the License, or (at your option) any later version. //
+//- //
+//- The C! library is distributed in the hope that it will be useful, //
+//- but WITHOUT ANY WARRANTY; without even the implied warranty of //
+//- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
+//- Lesser General Public License for more details. //
+//- //
+//- You should have received a copy of the GNU Lesser General Public //
+//- License along with the C! library. If not, see //
+//- . //
+//- //
+//- In addition, BSD licensing may be granted on a case by case basis //
+//- by written permission from at least one of the copyright holders. //
+//- You may request written permission by emailing the authors. //
+//- //
+//- For information regarding this software email: //
+//- Joseph Coffland //
+//- joseph@cauldrondevelopment.com //
+//- //
+//-/////////////////////////////////////////////////////////////////////////////
+
- var repoURL = 'https://github.com/CauldronDevelopmentLLC/cbang';
doctype html
diff --git a/docs/www/js/main.js b/docs/www/js/main.js
index 328b8d078..d1fac74e5 100644
--- a/docs/www/js/main.js
+++ b/docs/www/js/main.js
@@ -1,3 +1,35 @@
+/******************************************************************************\
+
+ This file is part of the C! library. A.K.A the cbang library.
+
+ Copyright (c) 2021-2024, Cauldron Development Oy
+ Copyright (c) 2003-2021, Cauldron Development LLC
+ All rights reserved.
+
+ The C! library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation, either version 2.1 of
+ the License, or (at your option) any later version.
+
+ The C! library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the C! library. If not, see
+ .
+
+ In addition, BSD licensing may be granted on a case by case basis
+ by written permission from at least one of the copyright holders.
+ You may request written permission by emailing the authors.
+
+ For information regarding this software email:
+ Joseph Coffland
+ joseph@cauldrondevelopment.com
+
+\******************************************************************************/
+
$(function () {
// Open external links in new tab
$('a').each(function (index, a) {
diff --git a/scripts/build-with-asan.sh b/scripts/build-with-asan.sh
new file mode 100755
index 000000000..1b39be3b1
--- /dev/null
+++ b/scripts/build-with-asan.sh
@@ -0,0 +1,13 @@
+#!/bin/bash -e
+
+if [ "$CBANG_HOME" == "" ]; then
+ echo CBANG_HOME not set
+ exit 1
+fi
+
+CCFLAGS=-fsanitize=address
+LDFLAGS="-fsanitize=address -static-libasan"
+
+export SCONS_OPTIONS="ccflags='$CCFLAGS' linkflags='$LDFLAGS' libs=bfd debug=1"
+
+scons -C "$CBANG_HOME" "$@"
diff --git a/scripts/update_boost.sh b/scripts/update_boost.sh
old mode 100755
new mode 100644
index 569d209cc..04c8b2849
--- a/scripts/update_boost.sh
+++ b/scripts/update_boost.sh
@@ -1,9 +1,41 @@
#!/bin/bash -e
-VERSION=1.69.0
+################################################################################
+# #
+# This file is part of the C! library. A.K.A the cbang library. #
+# #
+# Copyright (c) 2021-2024, Cauldron Development Oy #
+# Copyright (c) 2003-2021, Cauldron Development LLC #
+# All rights reserved. #
+# #
+# The C! library is free software: you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public License #
+# as published by the Free Software Foundation, either version 2.1 of #
+# the License, or (at your option) any later version. #
+# #
+# The C! library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public #
+# License along with the C! library. If not, see #
+# . #
+# #
+# In addition, BSD licensing may be granted on a case by case basis #
+# by written permission from at least one of the copyright holders. #
+# You may request written permission by emailing the authors. #
+# #
+# For information regarding this software email: #
+# Joseph Coffland #
+# joseph@cauldrondevelopment.com #
+# #
+################################################################################
+
+VERSION=1.83.0
NAME=boost_$(echo $VERSION | tr . _)
PKG=$NAME.7z
-URL=https://sf.net/projects/boost/files/boost/$VERSION/$PKG
+URL=https://boostorg.jfrog.io/artifactory/main/release/$VERSION/source/$PKG
BCP=./$NAME/dist/bin/bcp
# Get boost
@@ -27,6 +59,10 @@ $BCP --scan --boost=$NAME --unix-lines $(
# Remove uneeded files
for PATH in Jamroot libs/config libs/date_time libs/smart_ptr \
+ $(find src/boost/boost -name edg -o -name dmc \
+ -o -name no_ctps -o -name no_ttp -o -name mwcw \
+ -o -name msvc70 -o -name msvc60 -o -name bcc_pre590 \
+ -o -name bcc551 -o -name bcc) \
"libs/iostreams/src/lzma.cpp" \
"libs/iostreams/src/zstd.*"; do
/bin/rm -rf src/boost/$PATH
diff --git a/src/zlib/LICENSE b/src/ZLib/LICENSE
similarity index 100%
rename from src/zlib/LICENSE
rename to src/ZLib/LICENSE
diff --git a/src/ZLib/SConscript b/src/ZLib/SConscript
new file mode 100644
index 000000000..273779e66
--- /dev/null
+++ b/src/ZLib/SConscript
@@ -0,0 +1,15 @@
+Import('*')
+
+env = env.Clone()
+
+if env.get('compiler') == 'clang':
+ env.Append(CCFLAGS = ['-Wno-shift-negative-value',
+ '-Wno-unknown-warning-option',
+ '-Wno-deprecated-non-prototype'])
+
+lib = env.Library('#/lib/z', Glob('*.c'))
+
+hdrs = env.Install(dir = '#/include', source = ['zlib.h', 'zconf.h'])
+Depends(lib, hdrs)
+
+Return('lib')
diff --git a/src/zlib/adler32.c b/src/ZLib/adler32.c
similarity index 92%
rename from src/zlib/adler32.c
rename to src/ZLib/adler32.c
index a868f073d..d0be4380a 100644
--- a/src/zlib/adler32.c
+++ b/src/ZLib/adler32.c
@@ -1,5 +1,5 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-2011 Mark Adler
+ * Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -7,11 +7,9 @@
#include "zutil.h"
-#define local static
-
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
-#define BASE 65521 /* largest prime smaller than 65536 */
+#define BASE 65521U /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@@ -62,10 +60,10 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#endif
/* ========================================================================= */
-uLong ZEXPORT adler32(adler, buf, len)
+uLong ZEXPORT adler32_z(adler, buf, len)
uLong adler;
const Bytef *buf;
- uInt len;
+ z_size_t len;
{
unsigned long sum2;
unsigned n;
@@ -132,6 +130,15 @@ uLong ZEXPORT adler32(adler, buf, len)
return adler | (sum2 << 16);
}
+/* ========================================================================= */
+uLong ZEXPORT adler32(adler, buf, len)
+ uLong adler;
+ const Bytef *buf;
+ uInt len;
+{
+ return adler32_z(adler, buf, len);
+}
+
/* ========================================================================= */
local uLong adler32_combine_(adler1, adler2, len2)
uLong adler1;
@@ -156,7 +163,7 @@ local uLong adler32_combine_(adler1, adler2, len2)
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 >= BASE) sum1 -= BASE;
if (sum1 >= BASE) sum1 -= BASE;
- if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
+ if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
if (sum2 >= BASE) sum2 -= BASE;
return sum1 | (sum2 << 16);
}
diff --git a/src/ZLib/compress.c b/src/ZLib/compress.c
new file mode 100644
index 000000000..e2db404ab
--- /dev/null
+++ b/src/ZLib/compress.c
@@ -0,0 +1,86 @@
+/* compress.c -- compress a memory buffer
+ * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least 0.1% larger than sourceLen plus
+ 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+ int level;
+{
+ z_stream stream;
+ int err;
+ const uInt max = (uInt)-1;
+ uLong left;
+
+ left = *destLen;
+ *destLen = 0;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = deflateInit(&stream, level);
+ if (err != Z_OK) return err;
+
+ stream.next_out = dest;
+ stream.avail_out = 0;
+ stream.next_in = (z_const Bytef *)source;
+ stream.avail_in = 0;
+
+ do {
+ if (stream.avail_out == 0) {
+ stream.avail_out = left > (uLong)max ? max : (uInt)left;
+ left -= stream.avail_out;
+ }
+ if (stream.avail_in == 0) {
+ stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
+ sourceLen -= stream.avail_in;
+ }
+ err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
+ } while (err == Z_OK);
+
+ *destLen = stream.total_out;
+ deflateEnd(&stream);
+ return err == Z_STREAM_END ? Z_OK : err;
+}
+
+/* ===========================================================================
+ */
+int ZEXPORT compress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
+}
+
+/* ===========================================================================
+ If the default memLevel or windowBits for deflateInit() is changed, then
+ this function needs to be updated.
+ */
+uLong ZEXPORT compressBound (sourceLen)
+ uLong sourceLen;
+{
+ return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
+ (sourceLen >> 25) + 13;
+}
diff --git a/src/zlib/crc32.c b/src/ZLib/crc32.c
similarity index 91%
rename from src/zlib/crc32.c
rename to src/ZLib/crc32.c
index 979a7190a..9580440c0 100644
--- a/src/zlib/crc32.c
+++ b/src/ZLib/crc32.c
@@ -1,5 +1,5 @@
/* crc32.c -- compute the CRC-32 of a data stream
- * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
+ * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Thanks to Rodney Brown for his contribution of faster
@@ -30,17 +30,15 @@
#include "zutil.h" /* for STDC and FAR definitions */
-#define local static
-
/* Definitions for doing the crc four data bytes at a time. */
#if !defined(NOBYFOUR) && defined(Z_U4)
# define BYFOUR
#endif
#ifdef BYFOUR
local unsigned long crc32_little OF((unsigned long,
- const unsigned char FAR *, unsigned));
+ const unsigned char FAR *, z_size_t));
local unsigned long crc32_big OF((unsigned long,
- const unsigned char FAR *, unsigned));
+ const unsigned char FAR *, z_size_t));
# define TBLS 8
#else
# define TBLS 1
@@ -201,10 +199,10 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* ========================================================================= */
-unsigned long ZEXPORT crc32(crc, buf, len)
+unsigned long ZEXPORT crc32_z(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
- uInt len;
+ z_size_t len;
{
if (buf == Z_NULL) return 0UL;
@@ -235,8 +233,29 @@ unsigned long ZEXPORT crc32(crc, buf, len)
return crc ^ 0xffffffffUL;
}
+/* ========================================================================= */
+unsigned long ZEXPORT crc32(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ uInt len;
+{
+ return crc32_z(crc, buf, len);
+}
+
#ifdef BYFOUR
+/*
+ This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
+ integer pointer type. This violates the strict aliasing rule, where a
+ compiler can assume, for optimization purposes, that two pointers to
+ fundamentally different types won't ever point to the same memory. This can
+ manifest as a problem only if one of the pointers is written to. This code
+ only reads from those pointers. So long as this code remains isolated in
+ this compilation unit, there won't be a problem. For this reason, this code
+ should not be copied and pasted into a compilation unit in which other code
+ writes to the buffer that is passed to these routines.
+ */
+
/* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
@@ -247,7 +266,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
local unsigned long crc32_little(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
- unsigned len;
+ z_size_t len;
{
register z_crc_t c;
register const z_crc_t FAR *buf4;
@@ -278,7 +297,7 @@ local unsigned long crc32_little(crc, buf, len)
}
/* ========================================================================= */
-#define DOBIG4 c ^= *++buf4; \
+#define DOBIG4 c ^= *buf4++; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
@@ -287,7 +306,7 @@ local unsigned long crc32_little(crc, buf, len)
local unsigned long crc32_big(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
- unsigned len;
+ z_size_t len;
{
register z_crc_t c;
register const z_crc_t FAR *buf4;
@@ -300,7 +319,6 @@ local unsigned long crc32_big(crc, buf, len)
}
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
- buf4--;
while (len >= 32) {
DOBIG32;
len -= 32;
@@ -309,7 +327,6 @@ local unsigned long crc32_big(crc, buf, len)
DOBIG4;
len -= 4;
}
- buf4++;
buf = (const unsigned char FAR *)buf4;
if (len) do {
diff --git a/src/zlib/crc32.h b/src/ZLib/crc32.h
similarity index 100%
rename from src/zlib/crc32.h
rename to src/ZLib/crc32.h
diff --git a/src/zlib/deflate.c b/src/ZLib/deflate.c
similarity index 75%
rename from src/zlib/deflate.c
rename to src/ZLib/deflate.c
index 65a9644ca..1ec761448 100644
--- a/src/zlib/deflate.c
+++ b/src/ZLib/deflate.c
@@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
+ * Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -52,7 +52,7 @@
#include "deflate.h"
const char deflate_copyright[] =
- " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
+ " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -73,6 +73,8 @@ typedef enum {
typedef block_state (*compress_func) OF((deflate_state *s, int flush));
/* Compression function. Returns the block state after the call. */
+local int deflateStateCheck OF((z_streamp strm));
+local void slide_hash OF((deflate_state *s));
local void fill_window OF((deflate_state *s));
local block_state deflate_stored OF((deflate_state *s, int flush));
local block_state deflate_fast OF((deflate_state *s, int flush));
@@ -84,15 +86,16 @@ local block_state deflate_huff OF((deflate_state *s, int flush));
local void lm_init OF((deflate_state *s));
local void putShortMSB OF((deflate_state *s, uInt b));
local void flush_pending OF((z_streamp strm));
-local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
+local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
#ifdef ASMV
+# pragma message("Assembler code may have bugs -- use at your own risk")
void match_init OF((void)); /* asm code initialization */
uInt longest_match OF((deflate_state *s, IPos cur_match));
#else
local uInt longest_match OF((deflate_state *s, IPos cur_match));
#endif
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
local void check_match OF((deflate_state *s, IPos start, IPos match,
int length));
#endif
@@ -148,21 +151,14 @@ local const config configuration_table[10] = {
* meaning.
*/
-#define EQUAL 0
-/* result of memcmp for equal strings */
-
-#ifndef NO_DUMMY_DECL
-struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
-#endif
-
/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
-#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
+#define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0))
/* ===========================================================================
* Update a hash value with the given input byte
- * IN assertion: all calls to to UPDATE_HASH are made with consecutive
- * input characters, so that a running hash key can be computed from the
- * previous key instead of complete recalculation each time.
+ * IN assertion: all calls to UPDATE_HASH are made with consecutive input
+ * characters, so that a running hash key can be computed from the previous
+ * key instead of complete recalculation each time.
*/
#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask)
@@ -173,9 +169,9 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
* the previous length of the hash chain.
* If this file is compiled with -DFASTEST, the compression level is forced
* to 1, and no hash chains are maintained.
- * IN assertion: all calls to to INSERT_STRING are made with consecutive
- * input characters and the first MIN_MATCH bytes of str are valid
- * (except for the last MIN_MATCH-1 bytes of the input file).
+ * IN assertion: all calls to INSERT_STRING are made with consecutive input
+ * characters and the first MIN_MATCH bytes of str are valid (except for
+ * the last MIN_MATCH-1 bytes of the input file).
*/
#ifdef FASTEST
#define INSERT_STRING(s, str, match_head) \
@@ -197,6 +193,37 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
+/* ===========================================================================
+ * Slide the hash table when sliding the window down (could be avoided with 32
+ * bit values at the expense of memory usage). We slide even when level == 0 to
+ * keep the hash table consistent if we switch back to level > 0 later.
+ */
+local void slide_hash(s)
+ deflate_state *s;
+{
+ unsigned n, m;
+ Posf *p;
+ uInt wsize = s->w_size;
+
+ n = s->hash_size;
+ p = &s->head[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m - wsize : NIL);
+ } while (--n);
+ n = wsize;
+#ifndef FASTEST
+ p = &s->prev[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m - wsize : NIL);
+ /* If n is not on any hash chain, prev[n] is garbage but
+ * its value will never be used.
+ */
+ } while (--n);
+#endif
+}
+
/* ========================================================================= */
int ZEXPORT deflateInit_(strm, level, version, stream_size)
z_streamp strm;
@@ -270,7 +297,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
#endif
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
- strategy < 0 || strategy > Z_FIXED) {
+ strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
return Z_STREAM_ERROR;
}
if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
@@ -278,14 +305,15 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
if (s == Z_NULL) return Z_MEM_ERROR;
strm->state = (struct internal_state FAR *)s;
s->strm = strm;
+ s->status = INIT_STATE; /* to pass state test in deflateReset() */
s->wrap = wrap;
s->gzhead = Z_NULL;
- s->w_bits = windowBits;
+ s->w_bits = (uInt)windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
- s->hash_bits = memLevel + 7;
+ s->hash_bits = (uInt)memLevel + 7;
s->hash_size = 1 << s->hash_bits;
s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
@@ -319,6 +347,31 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
return deflateReset(strm);
}
+/* =========================================================================
+ * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
+ */
+local int deflateStateCheck (strm)
+ z_streamp strm;
+{
+ deflate_state *s;
+ if (strm == Z_NULL ||
+ strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
+ return 1;
+ s = strm->state;
+ if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE &&
+#ifdef GZIP
+ s->status != GZIP_STATE &&
+#endif
+ s->status != EXTRA_STATE &&
+ s->status != NAME_STATE &&
+ s->status != COMMENT_STATE &&
+ s->status != HCRC_STATE &&
+ s->status != BUSY_STATE &&
+ s->status != FINISH_STATE))
+ return 1;
+ return 0;
+}
+
/* ========================================================================= */
int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
z_streamp strm;
@@ -331,7 +384,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
unsigned avail;
z_const unsigned char *next;
- if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
+ if (deflateStateCheck(strm) || dictionary == Z_NULL)
return Z_STREAM_ERROR;
s = strm->state;
wrap = s->wrap;
@@ -388,14 +441,35 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
return Z_OK;
}
+/* ========================================================================= */
+int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength)
+ z_streamp strm;
+ Bytef *dictionary;
+ uInt *dictLength;
+{
+ deflate_state *s;
+ uInt len;
+
+ if (deflateStateCheck(strm))
+ return Z_STREAM_ERROR;
+ s = strm->state;
+ len = s->strstart + s->lookahead;
+ if (len > s->w_size)
+ len = s->w_size;
+ if (dictionary != Z_NULL && len)
+ zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len);
+ if (dictLength != Z_NULL)
+ *dictLength = len;
+ return Z_OK;
+}
+
/* ========================================================================= */
int ZEXPORT deflateResetKeep (strm)
z_streamp strm;
{
deflate_state *s;
- if (strm == Z_NULL || strm->state == Z_NULL ||
- strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
+ if (deflateStateCheck(strm)) {
return Z_STREAM_ERROR;
}
@@ -410,7 +484,11 @@ int ZEXPORT deflateResetKeep (strm)
if (s->wrap < 0) {
s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
}
- s->status = s->wrap ? INIT_STATE : BUSY_STATE;
+ s->status =
+#ifdef GZIP
+ s->wrap == 2 ? GZIP_STATE :
+#endif
+ s->wrap ? INIT_STATE : BUSY_STATE;
strm->adler =
#ifdef GZIP
s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
@@ -440,8 +518,8 @@ int ZEXPORT deflateSetHeader (strm, head)
z_streamp strm;
gz_headerp head;
{
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- if (strm->state->wrap != 2) return Z_STREAM_ERROR;
+ if (deflateStateCheck(strm) || strm->state->wrap != 2)
+ return Z_STREAM_ERROR;
strm->state->gzhead = head;
return Z_OK;
}
@@ -452,7 +530,7 @@ int ZEXPORT deflatePending (strm, pending, bits)
int *bits;
z_streamp strm;
{
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
if (pending != Z_NULL)
*pending = strm->state->pending;
if (bits != Z_NULL)
@@ -469,7 +547,7 @@ int ZEXPORT deflatePrime (strm, bits, value)
deflate_state *s;
int put;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
s = strm->state;
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
return Z_BUF_ERROR;
@@ -494,9 +572,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
{
deflate_state *s;
compress_func func;
- int err = Z_OK;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
s = strm->state;
#ifdef FASTEST
@@ -510,13 +587,22 @@ int ZEXPORT deflateParams(strm, level, strategy)
func = configuration_table[s->level].func;
if ((strategy != s->strategy || func != configuration_table[level].func) &&
- strm->total_in != 0) {
+ s->high_water) {
/* Flush the last buffer: */
- err = deflate(strm, Z_BLOCK);
- if (err == Z_BUF_ERROR && s->pending == 0)
- err = Z_OK;
+ int err = deflate(strm, Z_BLOCK);
+ if (err == Z_STREAM_ERROR)
+ return err;
+ if (strm->avail_out == 0)
+ return Z_BUF_ERROR;
}
if (s->level != level) {
+ if (s->level == 0 && s->matches != 0) {
+ if (s->matches == 1)
+ slide_hash(s);
+ else
+ CLEAR_HASH(s);
+ s->matches = 0;
+ }
s->level = level;
s->max_lazy_match = configuration_table[level].max_lazy;
s->good_match = configuration_table[level].good_length;
@@ -524,7 +610,7 @@ int ZEXPORT deflateParams(strm, level, strategy)
s->max_chain_length = configuration_table[level].max_chain;
}
s->strategy = strategy;
- return err;
+ return Z_OK;
}
/* ========================================================================= */
@@ -537,12 +623,12 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
{
deflate_state *s;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
s = strm->state;
- s->good_match = good_length;
- s->max_lazy_match = max_lazy;
+ s->good_match = (uInt)good_length;
+ s->max_lazy_match = (uInt)max_lazy;
s->nice_match = nice_length;
- s->max_chain_length = max_chain;
+ s->max_chain_length = (uInt)max_chain;
return Z_OK;
}
@@ -569,14 +655,13 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
{
deflate_state *s;
uLong complen, wraplen;
- Bytef *str;
/* conservative upper bound for compressed data */
complen = sourceLen +
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
/* if can't get parameters, return conservative bound plus zlib wrapper */
- if (strm == Z_NULL || strm->state == Z_NULL)
+ if (deflateStateCheck(strm))
return complen + 6;
/* compute wrapper length */
@@ -588,9 +673,11 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
case 1: /* zlib wrapper */
wraplen = 6 + (s->strstart ? 4 : 0);
break;
+#ifdef GZIP
case 2: /* gzip wrapper */
wraplen = 18;
if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
+ Bytef *str;
if (s->gzhead->extra != Z_NULL)
wraplen += 2 + s->gzhead->extra_len;
str = s->gzhead->name;
@@ -607,6 +694,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
wraplen += 2;
}
break;
+#endif
default: /* for compiler happiness */
wraplen = 6;
}
@@ -634,10 +722,10 @@ local void putShortMSB (s, b)
}
/* =========================================================================
- * Flush as much pending output as possible. All deflate() output goes
- * through this function so some applications may wish to modify it
- * to avoid allocating a large strm->next_out buffer and copying into it.
- * (See also read_buf()).
+ * Flush as much pending output as possible. All deflate() output, except for
+ * some deflate_stored() output, goes through this function so some
+ * applications may wish to modify it to avoid allocating a large
+ * strm->next_out buffer and copying into it. (See also read_buf()).
*/
local void flush_pending(strm)
z_streamp strm;
@@ -654,13 +742,23 @@ local void flush_pending(strm)
strm->next_out += len;
s->pending_out += len;
strm->total_out += len;
- strm->avail_out -= len;
- s->pending -= len;
+ strm->avail_out -= len;
+ s->pending -= len;
if (s->pending == 0) {
s->pending_out = s->pending_buf;
}
}
+/* ===========================================================================
+ * Update the header CRC with the bytes s->pending_buf[beg..s->pending - 1].
+ */
+#define HCRC_UPDATE(beg) \
+ do { \
+ if (s->gzhead->hcrc && s->pending > (beg)) \
+ strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
+ s->pending - (beg)); \
+ } while (0)
+
/* ========================================================================= */
int ZEXPORT deflate (strm, flush)
z_streamp strm;
@@ -669,230 +767,229 @@ int ZEXPORT deflate (strm, flush)
int old_flush; /* value of flush param for previous deflate call */
deflate_state *s;
- if (strm == Z_NULL || strm->state == Z_NULL ||
- flush > Z_BLOCK || flush < 0) {
+ if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
return Z_STREAM_ERROR;
}
s = strm->state;
if (strm->next_out == Z_NULL ||
- (strm->next_in == Z_NULL && strm->avail_in != 0) ||
+ (strm->avail_in != 0 && strm->next_in == Z_NULL) ||
(s->status == FINISH_STATE && flush != Z_FINISH)) {
ERR_RETURN(strm, Z_STREAM_ERROR);
}
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
- s->strm = strm; /* just in case */
old_flush = s->last_flush;
s->last_flush = flush;
+ /* Flush as much pending output as possible */
+ if (s->pending != 0) {
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ /* Since avail_out is 0, deflate will be called again with
+ * more output space, but possibly with both pending and
+ * avail_in equal to zero. There won't be anything to do,
+ * but this is not an error situation so make sure we
+ * return OK instead of BUF_ERROR at next call of deflate:
+ */
+ s->last_flush = -1;
+ return Z_OK;
+ }
+
+ /* Make sure there is something to do and avoid duplicate consecutive
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
+ */
+ } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
+ flush != Z_FINISH) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* User must not provide more input after the first FINISH: */
+ if (s->status == FINISH_STATE && strm->avail_in != 0) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
/* Write the header */
if (s->status == INIT_STATE) {
-#ifdef GZIP
- if (s->wrap == 2) {
- strm->adler = crc32(0L, Z_NULL, 0);
- put_byte(s, 31);
- put_byte(s, 139);
- put_byte(s, 8);
- if (s->gzhead == Z_NULL) {
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, s->level == 9 ? 2 :
- (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
- 4 : 0));
- put_byte(s, OS_CODE);
- s->status = BUSY_STATE;
- }
- else {
- put_byte(s, (s->gzhead->text ? 1 : 0) +
- (s->gzhead->hcrc ? 2 : 0) +
- (s->gzhead->extra == Z_NULL ? 0 : 4) +
- (s->gzhead->name == Z_NULL ? 0 : 8) +
- (s->gzhead->comment == Z_NULL ? 0 : 16)
- );
- put_byte(s, (Byte)(s->gzhead->time & 0xff));
- put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
- put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
- put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
- put_byte(s, s->level == 9 ? 2 :
- (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
- 4 : 0));
- put_byte(s, s->gzhead->os & 0xff);
- if (s->gzhead->extra != Z_NULL) {
- put_byte(s, s->gzhead->extra_len & 0xff);
- put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
- }
- if (s->gzhead->hcrc)
- strm->adler = crc32(strm->adler, s->pending_buf,
- s->pending);
- s->gzindex = 0;
- s->status = EXTRA_STATE;
- }
- }
+ /* zlib header */
+ uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+ uInt level_flags;
+
+ if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
+ level_flags = 0;
+ else if (s->level < 6)
+ level_flags = 1;
+ else if (s->level == 6)
+ level_flags = 2;
else
-#endif
- {
- uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
- uInt level_flags;
-
- if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
- level_flags = 0;
- else if (s->level < 6)
- level_flags = 1;
- else if (s->level == 6)
- level_flags = 2;
- else
- level_flags = 3;
- header |= (level_flags << 6);
- if (s->strstart != 0) header |= PRESET_DICT;
- header += 31 - (header % 31);
+ level_flags = 3;
+ header |= (level_flags << 6);
+ if (s->strstart != 0) header |= PRESET_DICT;
+ header += 31 - (header % 31);
+
+ putShortMSB(s, header);
+ /* Save the adler32 of the preset dictionary: */
+ if (s->strstart != 0) {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ strm->adler = adler32(0L, Z_NULL, 0);
+ s->status = BUSY_STATE;
+
+ /* Compression must start with an empty pending buffer */
+ flush_pending(strm);
+ if (s->pending != 0) {
+ s->last_flush = -1;
+ return Z_OK;
+ }
+ }
+#ifdef GZIP
+ if (s->status == GZIP_STATE) {
+ /* gzip header */
+ strm->adler = crc32(0L, Z_NULL, 0);
+ put_byte(s, 31);
+ put_byte(s, 139);
+ put_byte(s, 8);
+ if (s->gzhead == Z_NULL) {
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, OS_CODE);
s->status = BUSY_STATE;
- putShortMSB(s, header);
- /* Save the adler32 of the preset dictionary: */
- if (s->strstart != 0) {
- putShortMSB(s, (uInt)(strm->adler >> 16));
- putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ /* Compression must start with an empty pending buffer */
+ flush_pending(strm);
+ if (s->pending != 0) {
+ s->last_flush = -1;
+ return Z_OK;
+ }
+ }
+ else {
+ put_byte(s, (s->gzhead->text ? 1 : 0) +
+ (s->gzhead->hcrc ? 2 : 0) +
+ (s->gzhead->extra == Z_NULL ? 0 : 4) +
+ (s->gzhead->name == Z_NULL ? 0 : 8) +
+ (s->gzhead->comment == Z_NULL ? 0 : 16)
+ );
+ put_byte(s, (Byte)(s->gzhead->time & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, s->gzhead->os & 0xff);
+ if (s->gzhead->extra != Z_NULL) {
+ put_byte(s, s->gzhead->extra_len & 0xff);
+ put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
}
- strm->adler = adler32(0L, Z_NULL, 0);
+ if (s->gzhead->hcrc)
+ strm->adler = crc32(strm->adler, s->pending_buf,
+ s->pending);
+ s->gzindex = 0;
+ s->status = EXTRA_STATE;
}
}
-#ifdef GZIP
if (s->status == EXTRA_STATE) {
if (s->gzhead->extra != Z_NULL) {
- uInt beg = s->pending; /* start of bytes to update crc */
-
- while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
- if (s->pending == s->pending_buf_size) {
- if (s->gzhead->hcrc && s->pending > beg)
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
- s->pending - beg);
- flush_pending(strm);
- beg = s->pending;
- if (s->pending == s->pending_buf_size)
- break;
+ ulg beg = s->pending; /* start of bytes to update crc */
+ uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
+ while (s->pending + left > s->pending_buf_size) {
+ uInt copy = s->pending_buf_size - s->pending;
+ zmemcpy(s->pending_buf + s->pending,
+ s->gzhead->extra + s->gzindex, copy);
+ s->pending = s->pending_buf_size;
+ HCRC_UPDATE(beg);
+ s->gzindex += copy;
+ flush_pending(strm);
+ if (s->pending != 0) {
+ s->last_flush = -1;
+ return Z_OK;
}
- put_byte(s, s->gzhead->extra[s->gzindex]);
- s->gzindex++;
- }
- if (s->gzhead->hcrc && s->pending > beg)
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
- s->pending - beg);
- if (s->gzindex == s->gzhead->extra_len) {
- s->gzindex = 0;
- s->status = NAME_STATE;
+ beg = 0;
+ left -= copy;
}
+ zmemcpy(s->pending_buf + s->pending,
+ s->gzhead->extra + s->gzindex, left);
+ s->pending += left;
+ HCRC_UPDATE(beg);
+ s->gzindex = 0;
}
- else
- s->status = NAME_STATE;
+ s->status = NAME_STATE;
}
if (s->status == NAME_STATE) {
if (s->gzhead->name != Z_NULL) {
- uInt beg = s->pending; /* start of bytes to update crc */
+ ulg beg = s->pending; /* start of bytes to update crc */
int val;
-
do {
if (s->pending == s->pending_buf_size) {
- if (s->gzhead->hcrc && s->pending > beg)
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
- s->pending - beg);
+ HCRC_UPDATE(beg);
flush_pending(strm);
- beg = s->pending;
- if (s->pending == s->pending_buf_size) {
- val = 1;
- break;
+ if (s->pending != 0) {
+ s->last_flush = -1;
+ return Z_OK;
}
+ beg = 0;
}
val = s->gzhead->name[s->gzindex++];
put_byte(s, val);
} while (val != 0);
- if (s->gzhead->hcrc && s->pending > beg)
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
- s->pending - beg);
- if (val == 0) {
- s->gzindex = 0;
- s->status = COMMENT_STATE;
- }
+ HCRC_UPDATE(beg);
+ s->gzindex = 0;
}
- else
- s->status = COMMENT_STATE;
+ s->status = COMMENT_STATE;
}
if (s->status == COMMENT_STATE) {
if (s->gzhead->comment != Z_NULL) {
- uInt beg = s->pending; /* start of bytes to update crc */
+ ulg beg = s->pending; /* start of bytes to update crc */
int val;
-
do {
if (s->pending == s->pending_buf_size) {
- if (s->gzhead->hcrc && s->pending > beg)
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
- s->pending - beg);
+ HCRC_UPDATE(beg);
flush_pending(strm);
- beg = s->pending;
- if (s->pending == s->pending_buf_size) {
- val = 1;
- break;
+ if (s->pending != 0) {
+ s->last_flush = -1;
+ return Z_OK;
}
+ beg = 0;
}
val = s->gzhead->comment[s->gzindex++];
put_byte(s, val);
} while (val != 0);
- if (s->gzhead->hcrc && s->pending > beg)
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
- s->pending - beg);
- if (val == 0)
- s->status = HCRC_STATE;
+ HCRC_UPDATE(beg);
}
- else
- s->status = HCRC_STATE;
+ s->status = HCRC_STATE;
}
if (s->status == HCRC_STATE) {
if (s->gzhead->hcrc) {
- if (s->pending + 2 > s->pending_buf_size)
+ if (s->pending + 2 > s->pending_buf_size) {
flush_pending(strm);
- if (s->pending + 2 <= s->pending_buf_size) {
- put_byte(s, (Byte)(strm->adler & 0xff));
- put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
- strm->adler = crc32(0L, Z_NULL, 0);
- s->status = BUSY_STATE;
+ if (s->pending != 0) {
+ s->last_flush = -1;
+ return Z_OK;
+ }
}
+ put_byte(s, (Byte)(strm->adler & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+ strm->adler = crc32(0L, Z_NULL, 0);
}
- else
- s->status = BUSY_STATE;
- }
-#endif
+ s->status = BUSY_STATE;
- /* Flush as much pending output as possible */
- if (s->pending != 0) {
+ /* Compression must start with an empty pending buffer */
flush_pending(strm);
- if (strm->avail_out == 0) {
- /* Since avail_out is 0, deflate will be called again with
- * more output space, but possibly with both pending and
- * avail_in equal to zero. There won't be anything to do,
- * but this is not an error situation so make sure we
- * return OK instead of BUF_ERROR at next call of deflate:
- */
+ if (s->pending != 0) {
s->last_flush = -1;
return Z_OK;
}
-
- /* Make sure there is something to do and avoid duplicate consecutive
- * flushes. For repeated and useless calls with Z_FINISH, we keep
- * returning Z_STREAM_END instead of Z_BUF_ERROR.
- */
- } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
- flush != Z_FINISH) {
- ERR_RETURN(strm, Z_BUF_ERROR);
- }
-
- /* User must not provide more input after the first FINISH: */
- if (s->status == FINISH_STATE && strm->avail_in != 0) {
- ERR_RETURN(strm, Z_BUF_ERROR);
}
+#endif
/* Start a new block or continue the current one.
*/
@@ -900,9 +997,10 @@ int ZEXPORT deflate (strm, flush)
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
block_state bstate;
- bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
- (s->strategy == Z_RLE ? deflate_rle(s, flush) :
- (*(configuration_table[s->level].func))(s, flush));
+ bstate = s->level == 0 ? deflate_stored(s, flush) :
+ s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
+ s->strategy == Z_RLE ? deflate_rle(s, flush) :
+ (*(configuration_table[s->level].func))(s, flush);
if (bstate == finish_started || bstate == finish_done) {
s->status = FINISH_STATE;
@@ -926,7 +1024,7 @@ int ZEXPORT deflate (strm, flush)
} else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
_tr_stored_block(s, (char*)0, 0L, 0);
/* For a full flush, this empty block will be recognized
- * as a special marker by inflate_sink().
+ * as a special marker by inflate_sync().
*/
if (flush == Z_FULL_FLUSH) {
CLEAR_HASH(s); /* forget history */
@@ -944,7 +1042,6 @@ int ZEXPORT deflate (strm, flush)
}
}
}
- Assert(strm->avail_out > 0, "bug2");
if (flush != Z_FINISH) return Z_OK;
if (s->wrap <= 0) return Z_STREAM_END;
@@ -981,18 +1078,9 @@ int ZEXPORT deflateEnd (strm)
{
int status;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
status = strm->state->status;
- if (status != INIT_STATE &&
- status != EXTRA_STATE &&
- status != NAME_STATE &&
- status != COMMENT_STATE &&
- status != HCRC_STATE &&
- status != BUSY_STATE &&
- status != FINISH_STATE) {
- return Z_STREAM_ERROR;
- }
/* Deallocate in reverse order of allocations: */
TRY_FREE(strm, strm->state->pending_buf);
@@ -1023,7 +1111,7 @@ int ZEXPORT deflateCopy (dest, source)
ushf *overlay;
- if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ if (deflateStateCheck(source) || dest == Z_NULL) {
return Z_STREAM_ERROR;
}
@@ -1073,7 +1161,7 @@ int ZEXPORT deflateCopy (dest, source)
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
-local int read_buf(strm, buf, size)
+local unsigned read_buf(strm, buf, size)
z_streamp strm;
Bytef *buf;
unsigned size;
@@ -1097,7 +1185,7 @@ local int read_buf(strm, buf, size)
strm->next_in += len;
strm->total_in += len;
- return (int)len;
+ return len;
}
/* ===========================================================================
@@ -1151,9 +1239,9 @@ local uInt longest_match(s, cur_match)
{
unsigned chain_length = s->max_chain_length;/* max hash chain length */
register Bytef *scan = s->window + s->strstart; /* current string */
- register Bytef *match; /* matched string */
+ register Bytef *match; /* matched string */
register int len; /* length of current match */
- int best_len = s->prev_length; /* best match length so far */
+ int best_len = (int)s->prev_length; /* best match length so far */
int nice_match = s->nice_match; /* stop if match long enough */
IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
s->strstart - (IPos)MAX_DIST(s) : NIL;
@@ -1188,7 +1276,7 @@ local uInt longest_match(s, cur_match)
/* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic.
*/
- if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
+ if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
@@ -1349,7 +1437,11 @@ local uInt longest_match(s, cur_match)
#endif /* FASTEST */
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
+
+#define EQUAL 0
+/* result of memcmp for equal strings */
+
/* ===========================================================================
* Check that the match at match_start is indeed a match.
*/
@@ -1375,7 +1467,7 @@ local void check_match(s, start, match, length)
}
#else
# define check_match(s, start, match, length)
-#endif /* DEBUG */
+#endif /* ZLIB_DEBUG */
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
@@ -1390,8 +1482,7 @@ local void check_match(s, start, match, length)
local void fill_window(s)
deflate_state *s;
{
- register unsigned n, m;
- register Posf *p;
+ unsigned n;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
@@ -1418,35 +1509,11 @@ local void fill_window(s)
*/
if (s->strstart >= wsize+MAX_DIST(s)) {
- zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
+ zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more);
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
-
- /* Slide the hash table (could be avoided with 32 bit values
- at the expense of memory usage). We slide even when level == 0
- to keep the hash table consistent if we switch back to level > 0
- later. (Using level 0 permanently is not an optimal usage of
- zlib, so we don't care about this pathological case.)
- */
- n = s->hash_size;
- p = &s->head[n];
- do {
- m = *--p;
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
- } while (--n);
-
- n = wsize;
-#ifndef FASTEST
- p = &s->prev[n];
- do {
- m = *--p;
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
- /* If n is not on any hash chain, prev[n] is garbage but
- * its value will never be used.
- */
- } while (--n);
-#endif
+ slide_hash(s);
more += wsize;
}
if (s->strm->avail_in == 0) break;
@@ -1552,70 +1619,199 @@ local void fill_window(s)
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
}
+/* Maximum stored block length in deflate format (not including header). */
+#define MAX_STORED 65535
+
+/* Minimum of a and b. */
+#define MIN(a, b) ((a) > (b) ? (b) : (a))
+
/* ===========================================================================
* Copy without compression as much as possible from the input stream, return
* the current block state.
- * This function does not insert new strings in the dictionary since
- * uncompressible data is probably not useful. This function is used
- * only for the level=0 compression option.
- * NOTE: this function should be optimized to avoid extra copying from
- * window to pending_buf.
+ *
+ * In case deflateParams() is used to later switch to a non-zero compression
+ * level, s->matches (otherwise unused when storing) keeps track of the number
+ * of hash table slides to perform. If s->matches is 1, then one hash table
+ * slide will be done when switching. If s->matches is 2, the maximum value
+ * allowed here, then the hash table will be cleared, since two or more slides
+ * is the same as a clear.
+ *
+ * deflate_stored() is written to minimize the number of times an input byte is
+ * copied. It is most efficient with large input and output buffers, which
+ * maximizes the opportunites to have a single copy from next_in to next_out.
*/
local block_state deflate_stored(s, flush)
deflate_state *s;
int flush;
{
- /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
- * to pending_buf_size, and each stored block has a 5 byte header:
+ /* Smallest worthy block size when not flushing or finishing. By default
+ * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
+ * large input and output buffers, the stored block size will be larger.
*/
- ulg max_block_size = 0xffff;
- ulg max_start;
-
- if (max_block_size > s->pending_buf_size - 5) {
- max_block_size = s->pending_buf_size - 5;
- }
+ unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
- /* Copy as much as possible from input to output: */
- for (;;) {
- /* Fill the window as much as possible: */
- if (s->lookahead <= 1) {
-
- Assert(s->strstart < s->w_size+MAX_DIST(s) ||
- s->block_start >= (long)s->w_size, "slide too late");
+ /* Copy as many min_block or larger stored blocks directly to next_out as
+ * possible. If flushing, copy the remaining available input to next_out as
+ * stored blocks, if there is enough space.
+ */
+ unsigned len, left, have, last = 0;
+ unsigned used = s->strm->avail_in;
+ do {
+ /* Set len to the maximum size block that we can copy directly with the
+ * available input data and output space. Set left to how much of that
+ * would be copied from what's left in the window.
+ */
+ len = MAX_STORED; /* maximum deflate stored block length */
+ have = (s->bi_valid + 42) >> 3; /* number of header bytes */
+ if (s->strm->avail_out < have) /* need room for header */
+ break;
+ /* maximum stored block length that will fit in avail_out: */
+ have = s->strm->avail_out - have;
+ left = s->strstart - s->block_start; /* bytes left in window */
+ if (len > (ulg)left + s->strm->avail_in)
+ len = left + s->strm->avail_in; /* limit len to the input */
+ if (len > have)
+ len = have; /* limit len to the output */
+
+ /* If the stored block would be less than min_block in length, or if
+ * unable to copy all of the available input when flushing, then try
+ * copying to the window and the pending buffer instead. Also don't
+ * write an empty block when flushing -- deflate() does that.
+ */
+ if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
+ flush == Z_NO_FLUSH ||
+ len != left + s->strm->avail_in))
+ break;
- fill_window(s);
- if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
+ /* Make a dummy stored block in pending to get the header bytes,
+ * including any pending bits. This also updates the debugging counts.
+ */
+ last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
+ _tr_stored_block(s, (char *)0, 0L, last);
+
+ /* Replace the lengths in the dummy stored block with len. */
+ s->pending_buf[s->pending - 4] = len;
+ s->pending_buf[s->pending - 3] = len >> 8;
+ s->pending_buf[s->pending - 2] = ~len;
+ s->pending_buf[s->pending - 1] = ~len >> 8;
+
+ /* Write the stored block header bytes. */
+ flush_pending(s->strm);
+
+#ifdef ZLIB_DEBUG
+ /* Update debugging counts for the data about to be copied. */
+ s->compressed_len += len << 3;
+ s->bits_sent += len << 3;
+#endif
- if (s->lookahead == 0) break; /* flush the current block */
+ /* Copy uncompressed bytes from the window to next_out. */
+ if (left) {
+ if (left > len)
+ left = len;
+ zmemcpy(s->strm->next_out, s->window + s->block_start, left);
+ s->strm->next_out += left;
+ s->strm->avail_out -= left;
+ s->strm->total_out += left;
+ s->block_start += left;
+ len -= left;
}
- Assert(s->block_start >= 0L, "block gone");
-
- s->strstart += s->lookahead;
- s->lookahead = 0;
-
- /* Emit a stored block if pending_buf will be full: */
- max_start = s->block_start + max_block_size;
- if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
- /* strstart == 0 is possible when wraparound on 16-bit machine */
- s->lookahead = (uInt)(s->strstart - max_start);
- s->strstart = (uInt)max_start;
- FLUSH_BLOCK(s, 0);
+
+ /* Copy uncompressed bytes directly from next_in to next_out, updating
+ * the check value.
+ */
+ if (len) {
+ read_buf(s->strm, s->strm->next_out, len);
+ s->strm->next_out += len;
+ s->strm->avail_out -= len;
+ s->strm->total_out += len;
}
- /* Flush if we may have to slide, otherwise block_start may become
- * negative and the data will be gone:
+ } while (last == 0);
+
+ /* Update the sliding window with the last s->w_size bytes of the copied
+ * data, or append all of the copied data to the existing window if less
+ * than s->w_size bytes were copied. Also update the number of bytes to
+ * insert in the hash tables, in the event that deflateParams() switches to
+ * a non-zero compression level.
+ */
+ used -= s->strm->avail_in; /* number of input bytes directly copied */
+ if (used) {
+ /* If any input was used, then no unused input remains in the window,
+ * therefore s->block_start == s->strstart.
*/
- if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
- FLUSH_BLOCK(s, 0);
+ if (used >= s->w_size) { /* supplant the previous history */
+ s->matches = 2; /* clear hash */
+ zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
+ s->strstart = s->w_size;
}
+ else {
+ if (s->window_size - s->strstart <= used) {
+ /* Slide the window down. */
+ s->strstart -= s->w_size;
+ zmemcpy(s->window, s->window + s->w_size, s->strstart);
+ if (s->matches < 2)
+ s->matches++; /* add a pending slide_hash() */
+ }
+ zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
+ s->strstart += used;
+ }
+ s->block_start = s->strstart;
+ s->insert += MIN(used, s->w_size - s->insert);
}
- s->insert = 0;
- if (flush == Z_FINISH) {
- FLUSH_BLOCK(s, 1);
+ if (s->high_water < s->strstart)
+ s->high_water = s->strstart;
+
+ /* If the last block was written to next_out, then done. */
+ if (last)
return finish_done;
+
+ /* If flushing and all input has been consumed, then done. */
+ if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
+ s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
+ return block_done;
+
+ /* Fill the window with any remaining input. */
+ have = s->window_size - s->strstart - 1;
+ if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
+ /* Slide the window down. */
+ s->block_start -= s->w_size;
+ s->strstart -= s->w_size;
+ zmemcpy(s->window, s->window + s->w_size, s->strstart);
+ if (s->matches < 2)
+ s->matches++; /* add a pending slide_hash() */
+ have += s->w_size; /* more space now */
}
- if ((long)s->strstart > s->block_start)
- FLUSH_BLOCK(s, 0);
- return block_done;
+ if (have > s->strm->avail_in)
+ have = s->strm->avail_in;
+ if (have) {
+ read_buf(s->strm, s->window + s->strstart, have);
+ s->strstart += have;
+ }
+ if (s->high_water < s->strstart)
+ s->high_water = s->strstart;
+
+ /* There was not enough avail_out to write a complete worthy or flushed
+ * stored block to next_out. Write a stored block to pending instead, if we
+ * have enough input for a worthy block, or if flushing and there is enough
+ * room for the remaining input as a stored block in the pending buffer.
+ */
+ have = (s->bi_valid + 42) >> 3; /* number of header bytes */
+ /* maximum stored block length that will fit in pending: */
+ have = MIN(s->pending_buf_size - have, MAX_STORED);
+ min_block = MIN(have, s->w_size);
+ left = s->strstart - s->block_start;
+ if (left >= min_block ||
+ ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH &&
+ s->strm->avail_in == 0 && left <= have)) {
+ len = MIN(left, have);
+ last = flush == Z_FINISH && s->strm->avail_in == 0 &&
+ len == left ? 1 : 0;
+ _tr_stored_block(s, (charf *)s->window + s->block_start, len, last);
+ s->block_start += len;
+ flush_pending(s->strm);
+ }
+
+ /* We've done all we can with the available input and output. */
+ return last ? finish_started : need_more;
}
/* ===========================================================================
@@ -1892,7 +2088,7 @@ local block_state deflate_rle(s, flush)
prev == *++scan && prev == *++scan &&
prev == *++scan && prev == *++scan &&
scan < strend);
- s->match_length = MAX_MATCH - (int)(strend - scan);
+ s->match_length = MAX_MATCH - (uInt)(strend - scan);
if (s->match_length > s->lookahead)
s->match_length = s->lookahead;
}
diff --git a/src/zlib/deflate.h b/src/ZLib/deflate.h
similarity index 92%
rename from src/zlib/deflate.h
rename to src/ZLib/deflate.h
index ce0299edd..23ecdd312 100644
--- a/src/zlib/deflate.h
+++ b/src/ZLib/deflate.h
@@ -1,5 +1,5 @@
/* deflate.h -- internal compression state
- * Copyright (C) 1995-2012 Jean-loup Gailly
+ * Copyright (C) 1995-2016 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -51,13 +51,16 @@
#define Buf_size 16
/* size of bit buffer in bi_buf */
-#define INIT_STATE 42
-#define EXTRA_STATE 69
-#define NAME_STATE 73
-#define COMMENT_STATE 91
-#define HCRC_STATE 103
-#define BUSY_STATE 113
-#define FINISH_STATE 666
+#define INIT_STATE 42 /* zlib header -> BUSY_STATE */
+#ifdef GZIP
+# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
+#endif
+#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
+#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
+#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
+#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
+#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
+#define FINISH_STATE 666 /* stream complete */
/* Stream status */
@@ -83,7 +86,7 @@ typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */
- static_tree_desc *stat_desc; /* the corresponding static tree */
+ const static_tree_desc *stat_desc; /* the corresponding static tree */
} FAR tree_desc;
typedef ush Pos;
@@ -100,10 +103,10 @@ typedef struct internal_state {
Bytef *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */
Bytef *pending_out; /* next pending byte to output to the stream */
- uInt pending; /* nb of bytes in the pending buffer */
+ ulg pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */
- uInt gzindex; /* where in extra, name, or comment */
+ ulg gzindex; /* where in extra, name, or comment */
Byte method; /* can only be DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
@@ -249,7 +252,7 @@ typedef struct internal_state {
uInt matches; /* number of string matches in current block */
uInt insert; /* bytes at end of window left to insert */
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
@@ -275,7 +278,7 @@ typedef struct internal_state {
/* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf.
*/
-#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
+#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
@@ -309,7 +312,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
* used.
*/
-#ifndef DEBUG
+#ifndef ZLIB_DEBUG
/* Inline versions of _tr_tally for speed: */
#if defined(GEN_TREES_H) || !defined(STDC)
@@ -328,8 +331,8 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
flush = (s->last_lit == s->lit_bufsize-1); \
}
# define _tr_tally_dist(s, distance, length, flush) \
- { uch len = (length); \
- ush dist = (distance); \
+ { uch len = (uch)(length); \
+ ush dist = (ush)(distance); \
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \
dist--; \
diff --git a/src/zlib/gzguts.h b/src/ZLib/gzguts.h
similarity index 89%
rename from src/zlib/gzguts.h
rename to src/ZLib/gzguts.h
index d87659d03..990a4d251 100644
--- a/src/zlib/gzguts.h
+++ b/src/ZLib/gzguts.h
@@ -1,5 +1,5 @@
/* gzguts.h -- zlib internal header definitions for gz* operations
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -25,6 +25,10 @@
# include
# include
#endif
+
+#ifndef _POSIX_SOURCE
+# define _POSIX_SOURCE
+#endif
#include
#ifdef _WIN32
@@ -35,6 +39,10 @@
# include
#endif
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define WIDECHAR
+#endif
+
#ifdef WINAPI_FAMILY
# define open _open
# define read _read
@@ -95,18 +103,19 @@
# endif
#endif
-/* unlike snprintf (which is required in C99, yet still not supported by
- Microsoft more than a decade later!), _snprintf does not guarantee null
- termination of the result -- however this is only used in gzlib.c where
+/* unlike snprintf (which is required in C99), _snprintf does not guarantee
+ null termination of the result -- however this is only used in gzlib.c where
the result is assured to fit in the space provided */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && _MSC_VER < 1900
# define snprintf _snprintf
#endif
#ifndef local
# define local static
#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
+/* since "static" is used to mean two completely different things in C, we
+ define "local" for the non-static meaning of "static", for readability
+ (compile with -Dlocal if your debugger can't find static symbols) */
/* gz* functions always use library allocation functions */
#ifndef STDC
@@ -170,7 +179,7 @@ typedef struct {
char *path; /* path or fd for error messages */
unsigned size; /* buffer size, zero if not allocated yet */
unsigned want; /* requested buffer size, default is GZBUFSIZE */
- unsigned char *in; /* input buffer */
+ unsigned char *in; /* input buffer (double-sized when writing) */
unsigned char *out; /* output buffer (double-sized when reading) */
int direct; /* 0 if processing gzip, 1 if transparent */
/* just for reading */
diff --git a/src/zlib/infback.c b/src/ZLib/infback.c
similarity index 99%
rename from src/zlib/infback.c
rename to src/ZLib/infback.c
index f3833c2e4..59679ecbf 100644
--- a/src/zlib/infback.c
+++ b/src/ZLib/infback.c
@@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface
- * Copyright (C) 1995-2011 Mark Adler
+ * Copyright (C) 1995-2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -61,7 +61,7 @@ int stream_size;
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state;
state->dmax = 32768U;
- state->wbits = windowBits;
+ state->wbits = (uInt)windowBits;
state->wsize = 1U << windowBits;
state->window = window;
state->wnext = 0;
diff --git a/src/zlib/inffast.c b/src/ZLib/inffast.c
similarity index 85%
rename from src/zlib/inffast.c
rename to src/ZLib/inffast.c
index bda59ceb6..0dbd1dbc0 100644
--- a/src/zlib/inffast.c
+++ b/src/ZLib/inffast.c
@@ -1,5 +1,5 @@
/* inffast.c -- fast decoding
- * Copyright (C) 1995-2008, 2010, 2013 Mark Adler
+ * Copyright (C) 1995-2017 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -8,26 +8,9 @@
#include "inflate.h"
#include "inffast.h"
-#ifndef ASMINF
-
-/* Allow machine dependent optimization for post-increment or pre-increment.
- Based on testing to date,
- Pre-increment preferred for:
- - PowerPC G3 (Adler)
- - MIPS R5000 (Randers-Pehrson)
- Post-increment preferred for:
- - none
- No measurable difference:
- - Pentium III (Anderson)
- - M68060 (Nikl)
- */
-#ifdef POSTINC
-# define OFF 0
-# define PUP(a) *(a)++
+#ifdef ASMINF
+# pragma message("Assembler code may have bugs -- use at your own risk")
#else
-# define OFF 1
-# define PUP(a) *++(a)
-#endif
/*
Decode literal, length, and distance codes and write out the resulting
@@ -96,9 +79,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
/* copy state to local variables */
state = (struct inflate_state FAR *)strm->state;
- in = strm->next_in - OFF;
+ in = strm->next_in;
last = in + (strm->avail_in - 5);
- out = strm->next_out - OFF;
+ out = strm->next_out;
beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT
@@ -119,9 +102,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
input data or output space */
do {
if (bits < 15) {
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
here = lcode[hold & lmask];
@@ -134,14 +117,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val));
- PUP(out) = (unsigned char)(here.val);
+ *out++ = (unsigned char)(here.val);
}
else if (op & 16) { /* length base */
len = (unsigned)(here.val);
op &= 15; /* number of extra bits */
if (op) {
if (bits < op) {
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
len += (unsigned)hold & ((1U << op) - 1);
@@ -150,9 +133,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) {
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
here = dcode[hold & dmask];
@@ -165,10 +148,10 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
dist = (unsigned)(here.val);
op &= 15; /* number of extra bits */
if (bits < op) {
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
if (bits < op) {
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
}
@@ -196,30 +179,30 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
if (len <= op - whave) {
do {
- PUP(out) = 0;
+ *out++ = 0;
} while (--len);
continue;
}
len -= op - whave;
do {
- PUP(out) = 0;
+ *out++ = 0;
} while (--op > whave);
if (op == 0) {
from = out - dist;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--len);
continue;
}
#endif
}
- from = window - OFF;
+ from = window;
if (wnext == 0) { /* very common case */
from += wsize - op;
if (op < len) { /* some from window */
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
@@ -230,14 +213,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
if (op < len) { /* some from end of window */
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
- from = window - OFF;
+ from = window;
if (wnext < len) { /* some from start of window */
op = wnext;
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
@@ -248,35 +231,35 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
if (op < len) { /* some from window */
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
while (len > 2) {
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
+ *out++ = *from++;
+ *out++ = *from++;
+ *out++ = *from++;
len -= 3;
}
if (len) {
- PUP(out) = PUP(from);
+ *out++ = *from++;
if (len > 1)
- PUP(out) = PUP(from);
+ *out++ = *from++;
}
}
else {
from = out - dist; /* copy direct from output */
do { /* minimum length is three */
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
+ *out++ = *from++;
+ *out++ = *from++;
+ *out++ = *from++;
len -= 3;
} while (len > 2);
if (len) {
- PUP(out) = PUP(from);
+ *out++ = *from++;
if (len > 1)
- PUP(out) = PUP(from);
+ *out++ = *from++;
}
}
}
@@ -313,8 +296,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold &= (1U << bits) - 1;
/* update state and return */
- strm->next_in = in + OFF;
- strm->next_out = out + OFF;
+ strm->next_in = in;
+ strm->next_out = out;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end));
diff --git a/src/zlib/inffast.h b/src/ZLib/inffast.h
similarity index 100%
rename from src/zlib/inffast.h
rename to src/ZLib/inffast.h
diff --git a/src/zlib/inffixed.h b/src/ZLib/inffixed.h
similarity index 100%
rename from src/zlib/inffixed.h
rename to src/ZLib/inffixed.h
diff --git a/src/zlib/inflate.c b/src/ZLib/inflate.c
similarity index 93%
rename from src/zlib/inflate.c
rename to src/ZLib/inflate.c
index 870f89bb4..ac333e8c2 100644
--- a/src/zlib/inflate.c
+++ b/src/ZLib/inflate.c
@@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression
- * Copyright (C) 1995-2012 Mark Adler
+ * Copyright (C) 1995-2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -92,6 +92,7 @@
#endif
/* function prototypes */
+local int inflateStateCheck OF((z_streamp strm));
local void fixedtables OF((struct inflate_state FAR *state));
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
unsigned copy));
@@ -101,12 +102,26 @@ local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
unsigned len));
+local int inflateStateCheck(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+ if (strm == Z_NULL ||
+ strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
+ return 1;
+ state = (struct inflate_state FAR *)strm->state;
+ if (state == Z_NULL || state->strm != strm ||
+ state->mode < HEAD || state->mode > SYNC)
+ return 1;
+ return 0;
+}
+
int ZEXPORT inflateResetKeep(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
strm->total_in = strm->total_out = state->total = 0;
strm->msg = Z_NULL;
@@ -131,7 +146,7 @@ z_streamp strm;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
state->wsize = 0;
state->whave = 0;
@@ -147,7 +162,7 @@ int windowBits;
struct inflate_state FAR *state;
/* get the state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
/* extract wrap request from windowBits parameter */
@@ -156,7 +171,7 @@ int windowBits;
windowBits = -windowBits;
}
else {
- wrap = (windowBits >> 4) + 1;
+ wrap = (windowBits >> 4) + 5;
#ifdef GUNZIP
if (windowBits < 48)
windowBits &= 15;
@@ -210,7 +225,9 @@ int stream_size;
if (state == Z_NULL) return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state;
+ state->strm = strm;
state->window = Z_NULL;
+ state->mode = HEAD; /* to pass state test in inflateReset2() */
ret = inflateReset2(strm, windowBits);
if (ret != Z_OK) {
ZFREE(strm, state);
@@ -234,17 +251,17 @@ int value;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (bits < 0) {
state->hold = 0;
state->bits = 0;
return Z_OK;
}
- if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
+ if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
value &= (1L << bits) - 1;
- state->hold += value << state->bits;
- state->bits += bits;
+ state->hold += (unsigned)value << state->bits;
+ state->bits += (uInt)bits;
return Z_OK;
}
@@ -625,7 +642,7 @@ int flush;
static const unsigned short order[19] = /* permutation of code lengths */
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
- if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
+ if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
(strm->next_in == Z_NULL && strm->avail_in != 0))
return Z_STREAM_ERROR;
@@ -645,6 +662,8 @@ int flush;
NEEDBITS(16);
#ifdef GUNZIP
if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
+ if (state->wbits == 0)
+ state->wbits = 15;
state->check = crc32(0L, Z_NULL, 0);
CRC2(state->check, hold);
INITBITS();
@@ -672,7 +691,7 @@ int flush;
len = BITS(4) + 8;
if (state->wbits == 0)
state->wbits = len;
- else if (len > state->wbits) {
+ if (len > 15 || len > state->wbits) {
strm->msg = (char *)"invalid window size";
state->mode = BAD;
break;
@@ -699,14 +718,16 @@ int flush;
}
if (state->head != Z_NULL)
state->head->text = (int)((hold >> 8) & 1);
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC2(state->check, hold);
INITBITS();
state->mode = TIME;
case TIME:
NEEDBITS(32);
if (state->head != Z_NULL)
state->head->time = hold;
- if (state->flags & 0x0200) CRC4(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC4(state->check, hold);
INITBITS();
state->mode = OS;
case OS:
@@ -715,7 +736,8 @@ int flush;
state->head->xflags = (int)(hold & 0xff);
state->head->os = (int)(hold >> 8);
}
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC2(state->check, hold);
INITBITS();
state->mode = EXLEN;
case EXLEN:
@@ -724,7 +746,8 @@ int flush;
state->length = (unsigned)(hold);
if (state->head != Z_NULL)
state->head->extra_len = (unsigned)hold;
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC2(state->check, hold);
INITBITS();
}
else if (state->head != Z_NULL)
@@ -742,7 +765,7 @@ int flush;
len + copy > state->head->extra_max ?
state->head->extra_max - len : copy);
}
- if (state->flags & 0x0200)
+ if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
@@ -761,9 +784,9 @@ int flush;
if (state->head != Z_NULL &&
state->head->name != Z_NULL &&
state->length < state->head->name_max)
- state->head->name[state->length++] = len;
+ state->head->name[state->length++] = (Bytef)len;
} while (len && copy < have);
- if (state->flags & 0x0200)
+ if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
@@ -782,9 +805,9 @@ int flush;
if (state->head != Z_NULL &&
state->head->comment != Z_NULL &&
state->length < state->head->comm_max)
- state->head->comment[state->length++] = len;
+ state->head->comment[state->length++] = (Bytef)len;
} while (len && copy < have);
- if (state->flags & 0x0200)
+ if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
@@ -796,7 +819,7 @@ int flush;
case HCRC:
if (state->flags & 0x0200) {
NEEDBITS(16);
- if (hold != (state->check & 0xffff)) {
+ if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
strm->msg = (char *)"header crc mismatch";
state->mode = BAD;
break;
@@ -1177,11 +1200,11 @@ int flush;
out -= left;
strm->total_out += out;
state->total += out;
- if (out)
+ if ((state->wrap & 4) && out)
strm->adler = state->check =
UPDATE(state->check, put - out, out);
out = left;
- if ((
+ if ((state->wrap & 4) && (
#ifdef GUNZIP
state->flags ? hold :
#endif
@@ -1240,10 +1263,10 @@ int flush;
strm->total_in += in;
strm->total_out += out;
state->total += out;
- if (state->wrap && out)
+ if ((state->wrap & 4) && out)
strm->adler = state->check =
UPDATE(state->check, strm->next_out - out, out);
- strm->data_type = state->bits + (state->last ? 64 : 0) +
+ strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
(state->mode == TYPE ? 128 : 0) +
(state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
@@ -1255,7 +1278,7 @@ int ZEXPORT inflateEnd(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
+ if (inflateStateCheck(strm))
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (state->window != Z_NULL) ZFREE(strm, state->window);
@@ -1273,7 +1296,7 @@ uInt *dictLength;
struct inflate_state FAR *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
/* copy dictionary */
@@ -1298,7 +1321,7 @@ uInt dictLength;
int ret;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
@@ -1330,7 +1353,7 @@ gz_headerp head;
struct inflate_state FAR *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
@@ -1383,7 +1406,7 @@ z_streamp strm;
struct inflate_state FAR *state;
/* check parameters */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
@@ -1430,7 +1453,7 @@ z_streamp strm;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
return state->mode == STORED && state->bits == 0;
}
@@ -1445,8 +1468,7 @@ z_streamp source;
unsigned wsize;
/* check input */
- if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
- source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
+ if (inflateStateCheck(source) || dest == Z_NULL)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)source->state;
@@ -1467,6 +1489,7 @@ z_streamp source;
/* copy state */
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
+ copy->strm = dest;
if (state->lencode >= state->codes &&
state->lencode <= state->codes + ENOUGH - 1) {
copy->lencode = copy->codes + (state->lencode - state->codes);
@@ -1488,25 +1511,51 @@ int subvert;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
- state->sane = !subvert;
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
+ state->sane = !subvert;
return Z_OK;
#else
+ (void)subvert;
state->sane = 1;
return Z_DATA_ERROR;
#endif
}
+int ZEXPORT inflateValidate(strm, check)
+z_streamp strm;
+int check;
+{
+ struct inflate_state FAR *state;
+
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (check)
+ state->wrap |= 4;
+ else
+ state->wrap &= ~4;
+ return Z_OK;
+}
+
long ZEXPORT inflateMark(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
+ if (inflateStateCheck(strm))
+ return -(1L << 16);
state = (struct inflate_state FAR *)strm->state;
- return ((long)(state->back) << 16) +
+ return (long)(((unsigned long)((long)state->back)) << 16) +
(state->mode == COPY ? state->length :
(state->mode == MATCH ? state->was - state->length : 0));
}
+
+unsigned long ZEXPORT inflateCodesUsed(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+ if (inflateStateCheck(strm)) return (unsigned long)-1;
+ state = (struct inflate_state FAR *)strm->state;
+ return (unsigned long)(state->next - state->codes);
+}
diff --git a/src/zlib/inflate.h b/src/ZLib/inflate.h
similarity index 94%
rename from src/zlib/inflate.h
rename to src/ZLib/inflate.h
index 95f4986d4..a46cce6b6 100644
--- a/src/zlib/inflate.h
+++ b/src/ZLib/inflate.h
@@ -1,5 +1,5 @@
/* inflate.h -- internal inflate state definition
- * Copyright (C) 1995-2009 Mark Adler
+ * Copyright (C) 1995-2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -18,7 +18,7 @@
/* Possible inflate modes between inflate() calls */
typedef enum {
- HEAD, /* i: waiting for magic header */
+ HEAD = 16180, /* i: waiting for magic header */
FLAGS, /* i: waiting for method and flags (gzip) */
TIME, /* i: waiting for modification time (gzip) */
OS, /* i: waiting for extra flags and operating system (gzip) */
@@ -77,11 +77,14 @@ typedef enum {
CHECK -> LENGTH -> DONE
*/
-/* state maintained between inflate() calls. Approximately 10K bytes. */
+/* State maintained between inflate() calls -- approximately 7K bytes, not
+ including the allocated sliding window, which is up to 32K bytes. */
struct inflate_state {
+ z_streamp strm; /* pointer back to this zlib stream */
inflate_mode mode; /* current inflate mode */
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,
+ bit 2 true to validate check value */
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
diff --git a/src/zlib/inftrees.c b/src/ZLib/inftrees.c
similarity index 95%
rename from src/zlib/inftrees.c
rename to src/ZLib/inftrees.c
index 44d89cf24..2ea08fc13 100644
--- a/src/zlib/inftrees.c
+++ b/src/ZLib/inftrees.c
@@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-2013 Mark Adler
+ * Copyright (C) 1995-2017 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -9,7 +9,7 @@
#define MAXBITS 15
const char inflate_copyright[] =
- " inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
+ " inflate 1.2.11 Copyright 1995-2017 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -54,7 +54,7 @@ unsigned short FAR *work;
code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */
- int end; /* use base and extra for symbol > end */
+ unsigned match; /* use base and extra for symbol >= match */
unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
@@ -62,7 +62,7 @@ unsigned short FAR *work;
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 */
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, 72, 78};
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202};
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,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -181,19 +181,17 @@ unsigned short FAR *work;
switch (type) {
case CODES:
base = extra = work; /* dummy value--not used */
- end = 19;
+ match = 20;
break;
case LENS:
base = lbase;
- base -= 257;
extra = lext;
- extra -= 257;
- end = 256;
+ match = 257;
break;
- default: /* DISTS */
+ default: /* DISTS */
base = dbase;
extra = dext;
- end = -1;
+ match = 0;
}
/* initialize state for loop */
@@ -216,13 +214,13 @@ unsigned short FAR *work;
for (;;) {
/* create table entry */
here.bits = (unsigned char)(len - drop);
- if ((int)(work[sym]) < end) {
+ if (work[sym] + 1U < match) {
here.op = (unsigned char)0;
here.val = work[sym];
}
- else if ((int)(work[sym]) > end) {
- here.op = (unsigned char)(extra[work[sym]]);
- here.val = base[work[sym]];
+ else if (work[sym] >= match) {
+ here.op = (unsigned char)(extra[work[sym] - match]);
+ here.val = base[work[sym] - match];
}
else {
here.op = (unsigned char)(32 + 64); /* end of block */
diff --git a/src/zlib/inftrees.h b/src/ZLib/inftrees.h
similarity index 100%
rename from src/zlib/inftrees.h
rename to src/ZLib/inftrees.h
diff --git a/src/zlib/trees.c b/src/ZLib/trees.c
similarity index 95%
rename from src/zlib/trees.c
rename to src/ZLib/trees.c
index 1fd7759ef..50cf4b457 100644
--- a/src/zlib/trees.c
+++ b/src/ZLib/trees.c
@@ -1,5 +1,5 @@
/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-2012 Jean-loup Gailly
+ * Copyright (C) 1995-2017 Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -36,7 +36,7 @@
#include "deflate.h"
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
# include
#endif
@@ -122,13 +122,13 @@ struct static_tree_desc_s {
int max_length; /* max bit length for the codes */
};
-local static_tree_desc static_l_desc =
+local const static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
-local static_tree_desc static_d_desc =
+local const static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
-local static_tree_desc static_bl_desc =
+local const static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
/* ===========================================================================
@@ -152,18 +152,16 @@ local int detect_data_type OF((deflate_state *s));
local unsigned bi_reverse OF((unsigned value, int length));
local void bi_windup OF((deflate_state *s));
local void bi_flush OF((deflate_state *s));
-local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
- int header));
#ifdef GEN_TREES_H
local void gen_trees_header OF((void));
#endif
-#ifndef DEBUG
+#ifndef ZLIB_DEBUG
# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
/* Send a code of the given tree. c and tree must not have side effects */
-#else /* DEBUG */
+#else /* !ZLIB_DEBUG */
# define send_code(s, c, tree) \
{ if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
send_bits(s, tree[c].Code, tree[c].Len); }
@@ -182,7 +180,7 @@ local void gen_trees_header OF((void));
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
local void send_bits OF((deflate_state *s, int value, int length));
local void send_bits(s, value, length)
@@ -208,12 +206,12 @@ local void send_bits(s, value, length)
s->bi_valid += length;
}
}
-#else /* !DEBUG */
+#else /* !ZLIB_DEBUG */
#define send_bits(s, value, length) \
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
- int val = value;\
+ int val = (int)value;\
s->bi_buf |= (ush)val << s->bi_valid;\
put_short(s, s->bi_buf);\
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
@@ -223,7 +221,7 @@ local void send_bits(s, value, length)
s->bi_valid += len;\
}\
}
-#endif /* DEBUG */
+#endif /* ZLIB_DEBUG */
/* the arguments must not have side effects */
@@ -317,7 +315,7 @@ local void tr_static_init()
* Genererate the file trees.h describing the static trees.
*/
#ifdef GEN_TREES_H
-# ifndef DEBUG
+# ifndef ZLIB_DEBUG
# include
# endif
@@ -394,7 +392,7 @@ void ZLIB_INTERNAL _tr_init(s)
s->bi_buf = 0;
s->bi_valid = 0;
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
#endif
@@ -522,12 +520,12 @@ local void gen_bitlen(s, desc)
xbits = 0;
if (n >= base) xbits = extra[n-base];
f = tree[n].Freq;
- s->opt_len += (ulg)f * (bits + xbits);
- if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
+ s->opt_len += (ulg)f * (unsigned)(bits + xbits);
+ if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits);
}
if (overflow == 0) return;
- Trace((stderr,"\nbit length overflow\n"));
+ Tracev((stderr,"\nbit length overflow\n"));
/* This happens for example on obj2 and pic of the Calgary corpus */
/* Find the first bit length which could increase: */
@@ -554,9 +552,8 @@ local void gen_bitlen(s, desc)
m = s->heap[--h];
if (m > max_code) continue;
if ((unsigned) tree[m].Len != (unsigned) bits) {
- Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
- s->opt_len += ((long)bits - (long)tree[m].Len)
- *(long)tree[m].Freq;
+ Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
+ s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
tree[m].Len = (ush)bits;
}
n--;
@@ -578,7 +575,7 @@ local void gen_codes (tree, max_code, bl_count)
ushf *bl_count; /* number of codes at each bit length */
{
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
- ush code = 0; /* running code value */
+ unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
@@ -586,7 +583,8 @@ local void gen_codes (tree, max_code, bl_count)
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
- next_code[bits] = code = (code + bl_count[bits-1]) << 1;
+ code = (code + bl_count[bits-1]) << 1;
+ next_code[bits] = (ush)code;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
@@ -599,7 +597,7 @@ local void gen_codes (tree, max_code, bl_count)
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
- tree[n].Code = bi_reverse(next_code[len]++, len);
+ tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
@@ -821,7 +819,7 @@ local int build_bl_tree(s)
if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
}
/* Update opt_len to include the bit length tree and counts */
- s->opt_len += 3*(max_blindex+1) + 5+5+4;
+ s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
s->opt_len, s->static_len));
@@ -869,11 +867,17 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
int last; /* one if this is the last block for a file */
{
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
-#ifdef DEBUG
+ bi_windup(s); /* align on byte boundary */
+ put_short(s, (ush)stored_len);
+ put_short(s, (ush)~stored_len);
+ zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
+ s->pending += stored_len;
+#ifdef ZLIB_DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3;
+ s->bits_sent += 2*16;
+ s->bits_sent += stored_len<<3;
#endif
- copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
/* ===========================================================================
@@ -894,7 +898,7 @@ void ZLIB_INTERNAL _tr_align(s)
{
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
#endif
bi_flush(s);
@@ -902,7 +906,7 @@ void ZLIB_INTERNAL _tr_align(s)
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static
- * trees or store, and output the encoded block to the zip file.
+ * trees or store, and write out the encoded block.
*/
void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
deflate_state *s;
@@ -974,7 +978,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree);
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
s->compressed_len += 3 + s->static_len;
#endif
} else {
@@ -983,7 +987,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
max_blindex+1);
compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree);
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
s->compressed_len += 3 + s->opt_len;
#endif
}
@@ -995,7 +999,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
if (last) {
bi_windup(s);
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
s->compressed_len += 7; /* align on byte boundary */
#endif
}
@@ -1090,7 +1094,7 @@ local void compress_block(s, ltree, dtree)
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
- dist -= base_dist[code];
+ dist -= (unsigned)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
@@ -1193,34 +1197,7 @@ local void bi_windup(s)
}
s->bi_buf = 0;
s->bi_valid = 0;
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
s->bits_sent = (s->bits_sent+7) & ~7;
#endif
}
-
-/* ===========================================================================
- * Copy a stored block, storing first the length and its
- * one's complement if requested.
- */
-local void copy_block(s, buf, len, header)
- deflate_state *s;
- charf *buf; /* the input data */
- unsigned len; /* its length */
- int header; /* true if block header must be written */
-{
- bi_windup(s); /* align on byte boundary */
-
- if (header) {
- put_short(s, (ush)len);
- put_short(s, (ush)~len);
-#ifdef DEBUG
- s->bits_sent += 2*16;
-#endif
- }
-#ifdef DEBUG
- s->bits_sent += (ulg)len<<3;
-#endif
- while (len--) {
- put_byte(s, *buf++);
- }
-}
diff --git a/src/zlib/trees.h b/src/ZLib/trees.h
similarity index 100%
rename from src/zlib/trees.h
rename to src/ZLib/trees.h
diff --git a/src/ZLib/uncompr.c b/src/ZLib/uncompr.c
new file mode 100644
index 000000000..f03a1a865
--- /dev/null
+++ b/src/ZLib/uncompr.c
@@ -0,0 +1,93 @@
+/* uncompr.c -- decompress a memory buffer
+ * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+ Decompresses the source buffer into the destination buffer. *sourceLen is
+ the byte length of the source buffer. Upon entry, *destLen is the total size
+ of the destination buffer, which must be large enough to hold the entire
+ uncompressed data. (The size of the uncompressed data must have been saved
+ previously by the compressor and transmitted to the decompressor by some
+ mechanism outside the scope of this compression library.) Upon exit,
+ *destLen is the size of the decompressed data and *sourceLen is the number
+ of source bytes consumed. Upon return, source + *sourceLen points to the
+ first unused input byte.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
+ Z_DATA_ERROR if the input data was corrupted, including if the input data is
+ an incomplete zlib stream.
+*/
+int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong *sourceLen;
+{
+ z_stream stream;
+ int err;
+ const uInt max = (uInt)-1;
+ uLong len, left;
+ Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
+
+ len = *sourceLen;
+ if (*destLen) {
+ left = *destLen;
+ *destLen = 0;
+ }
+ else {
+ left = 1;
+ dest = buf;
+ }
+
+ stream.next_in = (z_const Bytef *)source;
+ stream.avail_in = 0;
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = inflateInit(&stream);
+ if (err != Z_OK) return err;
+
+ stream.next_out = dest;
+ stream.avail_out = 0;
+
+ do {
+ if (stream.avail_out == 0) {
+ stream.avail_out = left > (uLong)max ? max : (uInt)left;
+ left -= stream.avail_out;
+ }
+ if (stream.avail_in == 0) {
+ stream.avail_in = len > (uLong)max ? max : (uInt)len;
+ len -= stream.avail_in;
+ }
+ err = inflate(&stream, Z_NO_FLUSH);
+ } while (err == Z_OK);
+
+ *sourceLen -= len + stream.avail_in;
+ if (dest != buf)
+ *destLen = stream.total_out;
+ else if (stream.total_out && err == Z_BUF_ERROR)
+ left = 1;
+
+ inflateEnd(&stream);
+ return err == Z_STREAM_END ? Z_OK :
+ err == Z_NEED_DICT ? Z_DATA_ERROR :
+ err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
+ err;
+}
+
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ return uncompress2(dest, destLen, source, &sourceLen);
+}
diff --git a/src/zlib/zconf.h b/src/ZLib/zconf.h
similarity index 93%
rename from src/zlib/zconf.h
rename to src/ZLib/zconf.h
index 9987a7755..5e1d68a00 100644
--- a/src/zlib/zconf.h
+++ b/src/ZLib/zconf.h
@@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -17,7 +17,7 @@
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
# define Z_PREFIX_SET
-/* all linked symbols */
+/* all linked symbols and init macros */
# define _dist_code z__dist_code
# define _length_code z__length_code
# define _tr_align z__tr_align
@@ -29,6 +29,7 @@
# define adler32 z_adler32
# define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64
+# define adler32_z z_adler32_z
# ifndef Z_SOLO
# define compress z_compress
# define compress2 z_compress2
@@ -37,10 +38,14 @@
# define crc32 z_crc32
# define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64
+# define crc32_z z_crc32_z
# define deflate z_deflate
# define deflateBound z_deflateBound
# define deflateCopy z_deflateCopy
# define deflateEnd z_deflateEnd
+# define deflateGetDictionary z_deflateGetDictionary
+# define deflateInit z_deflateInit
+# define deflateInit2 z_deflateInit2
# define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams
@@ -67,6 +72,8 @@
# define gzeof z_gzeof
# define gzerror z_gzerror
# define gzflush z_gzflush
+# define gzfread z_gzfread
+# define gzfwrite z_gzfwrite
# define gzgetc z_gzgetc
# define gzgetc_ z_gzgetc_
# define gzgets z_gzgets
@@ -78,7 +85,6 @@
# define gzopen_w z_gzopen_w
# endif
# define gzprintf z_gzprintf
-# define gzvprintf z_gzvprintf
# define gzputc z_gzputc
# define gzputs z_gzputs
# define gzread z_gzread
@@ -89,32 +95,39 @@
# define gztell z_gztell
# define gztell64 z_gztell64
# define gzungetc z_gzungetc
+# define gzvprintf z_gzvprintf
# define gzwrite z_gzwrite
# endif
# define inflate z_inflate
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
+# define inflateBackInit z_inflateBackInit
# define inflateBackInit_ z_inflateBackInit_
+# define inflateCodesUsed z_inflateCodesUsed
# define inflateCopy z_inflateCopy
# define inflateEnd z_inflateEnd
+# define inflateGetDictionary z_inflateGetDictionary
# define inflateGetHeader z_inflateGetHeader
+# define inflateInit z_inflateInit
+# define inflateInit2 z_inflateInit2
# define inflateInit2_ z_inflateInit2_
# define inflateInit_ z_inflateInit_
# define inflateMark z_inflateMark
# define inflatePrime z_inflatePrime
# define inflateReset z_inflateReset
# define inflateReset2 z_inflateReset2
+# define inflateResetKeep z_inflateResetKeep
# define inflateSetDictionary z_inflateSetDictionary
-# define inflateGetDictionary z_inflateGetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine
-# define inflateResetKeep z_inflateResetKeep
+# define inflateValidate z_inflateValidate
# define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table
# ifndef Z_SOLO
# define uncompress z_uncompress
+# define uncompress2 z_uncompress2
# endif
# define zError z_zError
# ifndef Z_SOLO
@@ -224,9 +237,19 @@
# define z_const
#endif
-/* Some Mac compilers merge all .h files incorrectly: */
-#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
-# define NO_DUMMY_DECL
+#ifdef Z_SOLO
+ typedef unsigned long z_size_t;
+#else
+# define z_longlong long long
+# if defined(NO_SIZE_T)
+ typedef unsigned NO_SIZE_T z_size_t;
+# elif defined(STDC)
+# include
+ typedef size_t z_size_t;
+# else
+ typedef unsigned long z_size_t;
+# endif
+# undef z_longlong
#endif
/* Maximum value for memLevel in deflateInit2 */
@@ -256,7 +279,7 @@
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
for small objects.
*/
diff --git a/src/zlib/zlib.h b/src/ZLib/zlib.h
similarity index 82%
rename from src/zlib/zlib.h
rename to src/ZLib/zlib.h
index 3e0c7672a..f09cdaf1e 100644
--- a/src/zlib/zlib.h
+++ b/src/ZLib/zlib.h
@@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
- version 1.2.8, April 28th, 2013
+ version 1.2.11, January 15th, 2017
- Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
+ Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -37,11 +37,11 @@
extern "C" {
#endif
-#define ZLIB_VERSION "1.2.8"
-#define ZLIB_VERNUM 0x1280
+#define ZLIB_VERSION "1.2.11"
+#define ZLIB_VERNUM 0x12b0
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
-#define ZLIB_VER_REVISION 8
+#define ZLIB_VER_REVISION 11
#define ZLIB_VER_SUBREVISION 0
/*
@@ -65,7 +65,8 @@ extern "C" {
with "gz". The gzip format is different from the zlib format. gzip is a
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
- This library can optionally read and write gzip streams in memory as well.
+ This library can optionally read and write gzip and raw deflate streams in
+ memory as well.
The zlib format was designed to be compact and fast for use in memory
and on communications channels. The gzip format was designed for single-
@@ -74,7 +75,7 @@ extern "C" {
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never crash
- even in case of corrupted input.
+ even in the case of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
@@ -87,7 +88,7 @@ typedef struct z_stream_s {
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total number of input bytes read so far */
- Bytef *next_out; /* next output byte should be put there */
+ Bytef *next_out; /* next output byte will go here */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total number of bytes output so far */
@@ -98,8 +99,9 @@ typedef struct z_stream_s {
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
- int data_type; /* best guess about the data type: binary or text */
- uLong adler; /* adler32 value of the uncompressed data */
+ int data_type; /* best guess about the data type: binary or text
+ for deflate, or the decoding state for inflate */
+ uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
@@ -142,7 +144,9 @@ typedef gz_header FAR *gz_headerp;
zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
- thread safe.
+ thread safe. In that case, zlib is thread-safe. When zalloc and zfree are
+ Z_NULL on entry to the initialization function, they are set to internal
+ routines that use the standard library functions malloc() and free().
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this if
@@ -155,7 +159,7 @@ typedef gz_header FAR *gz_headerp;
The fields total_in and total_out can be used for statistics or progress
reports. After compression, total_in holds the total size of the
- uncompressed data and may be saved for use in the decompressor (particularly
+ uncompressed data and may be saved for use by the decompressor (particularly
if the decompressor wants to decompress everything in a single step).
*/
@@ -200,7 +204,7 @@ typedef gz_header FAR *gz_headerp;
#define Z_TEXT 1
#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2
-/* Possible values of the data_type field (though see inflate()) */
+/* Possible values of the data_type field for deflate() */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
@@ -258,11 +262,11 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
- - Provide more output starting at next_out and update next_out and avail_out
+ - Generate more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
- should be set only when necessary (in interactive applications). Some
- output may be provided even if flush is not set.
+ should be set only when necessary. Some output may be provided even if
+ flush is zero.
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming more
@@ -271,7 +275,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
output when it wants, for example when the output buffer is full (avail_out
== 0), or after each call of deflate(). If deflate returns Z_OK and with
zero avail_out, it must be called again after making room in the output
- buffer because there might be more output pending.
+ buffer because there might be more output pending. See deflatePending(),
+ which can be used if desired to determine whether or not there is more ouput
+ in that case.
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
decide how much data to accumulate before producing output, in order to
@@ -292,8 +298,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
This completes the current deflate block and follows it with an empty fixed
codes block that is 10 bits long. This assures that enough bytes are output
- in order for the decompressor to finish the block before the empty fixed code
- block.
+ in order for the decompressor to finish the block before the empty fixed
+ codes block.
If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
@@ -319,34 +325,38 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there was
- enough output space; if deflate returns with Z_OK, this function must be
- called again with Z_FINISH and more output space (updated avail_out) but no
- more input data, until it returns with Z_STREAM_END or an error. After
- deflate has returned Z_STREAM_END, the only possible operations on the stream
- are deflateReset or deflateEnd.
-
- Z_FINISH can be used immediately after deflateInit if all the compression
- is to be done in a single step. In this case, avail_out must be at least the
- value returned by deflateBound (see below). Then deflate is guaranteed to
- return Z_STREAM_END. If not enough output space is provided, deflate will
- not return Z_STREAM_END, and it must be called again as described above.
-
- deflate() sets strm->adler to the adler32 checksum of all input read
- so far (that is, total_in bytes).
+ enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this
+ function must be called again with Z_FINISH and more output space (updated
+ avail_out) but no more input data, until it returns with Z_STREAM_END or an
+ error. After deflate has returned Z_STREAM_END, the only possible operations
+ on the stream are deflateReset or deflateEnd.
+
+ Z_FINISH can be used in the first deflate call after deflateInit if all the
+ compression is to be done in a single step. In order to complete in one
+ call, avail_out must be at least the value returned by deflateBound (see
+ below). Then deflate is guaranteed to return Z_STREAM_END. If not enough
+ output space is provided, deflate will not return Z_STREAM_END, and it must
+ be called again as described above.
+
+ deflate() sets strm->adler to the Adler-32 checksum of all input read
+ so far (that is, total_in bytes). If a gzip stream is being generated, then
+ strm->adler will be the CRC-32 checksum of the input read so far. (See
+ deflateInit2 below.)
deflate() may update strm->data_type if it can make a good guess about
- the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
- binary. This field is only for information purposes and does not affect the
- compression algorithm in any manner.
+ the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is
+ considered binary. This field is only for information purposes and does not
+ affect the compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
- if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
- (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
- fatal, and deflate() can be called again with more input and more output
- space to continue compressing.
+ if next_in or next_out was Z_NULL or the state was inadvertently written over
+ by the application), or Z_BUF_ERROR if no progress is possible (for example
+ avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and
+ deflate() can be called again with more input and more output space to
+ continue compressing.
*/
@@ -369,23 +379,21 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
- the caller. If next_in is not Z_NULL and avail_in is large enough (the
- exact value depends on the compression method), inflateInit determines the
- compression method from the zlib header and allocates all data structures
- accordingly; otherwise the allocation will be deferred to the first call of
- inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
- use default allocation functions.
+ the caller. In the current version of inflate, the provided input is not
+ read or consumed. The allocation of a sliding window will be deferred to
+ the first call of inflate (if the decompression does not complete on the
+ first call). If zalloc and zfree are set to Z_NULL, inflateInit updates
+ them to use default allocation functions.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller, or Z_STREAM_ERROR if the parameters are
invalid, such as a null pointer to the structure. msg is set to null if
- there is no error message. inflateInit does not perform any decompression
- apart from possibly reading the zlib header if present: actual decompression
- will be done by inflate(). (So next_in and avail_in may be modified, but
- next_out and avail_out are unused and unchanged.) The current implementation
- of inflateInit() does not process any header information -- that is deferred
- until inflate() is called.
+ there is no error message. inflateInit does not perform any decompression.
+ Actual decompression will be done by inflate(). So next_in, and avail_in,
+ next_out, and avail_out are unused and unchanged. The current
+ implementation of inflateInit() does not process any header information --
+ that is deferred until inflate() is called.
*/
@@ -401,17 +409,20 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
- enough room in the output buffer), next_in is updated and processing will
- resume at this point for the next call of inflate().
+ enough room in the output buffer), then next_in and avail_in are updated
+ accordingly, and processing will resume at this point for the next call of
+ inflate().
- - Provide more output starting at next_out and update next_out and avail_out
+ - Generate more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there is
no more input data or no more space in the output buffer (see below about
the flush parameter).
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming more
- output, and updating the next_* and avail_* values accordingly. The
+ output, and updating the next_* and avail_* values accordingly. If the
+ caller of inflate() does not provide both available input and available
+ output space, it is possible that there will be no progress made. The
application can consume the uncompressed output when it wants, for example
when the output buffer is full (avail_out == 0), or after each call of
inflate(). If inflate returns Z_OK and with zero avail_out, it must be
@@ -428,7 +439,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
gets to the end of that block, or when it runs out of data.
The Z_BLOCK option assists in appending to or combining deflate streams.
- Also to assist in this, on return inflate() will set strm->data_type to the
+ To assist in this, on return inflate() always sets strm->data_type to the
number of unused bits in the last byte taken from strm->next_in, plus 64 if
inflate() is currently decoding the last block in the deflate stream, plus
128 if inflate() returned immediately after decoding an end-of-block code or
@@ -454,7 +465,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
this case all pending input is processed and all pending output is flushed;
avail_out must be large enough to hold all of the uncompressed data for the
operation to complete. (The size of the uncompressed data may have been
- saved by the compressor for this purpose.) The use of Z_FINISH is not
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
required to perform an inflation in one step. However it may be used to
inform inflate that a faster approach can be used for the single inflate()
call. Z_FINISH also informs inflate to not maintain a sliding window if the
@@ -476,32 +487,33 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
strm->adler to the Adler-32 checksum of all output produced so far (that is,
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
- below. At the end of the stream, inflate() checks that its computed adler32
+ below. At the end of the stream, inflate() checks that its computed Adler-32
checksum is equal to that saved by the compressor and returns Z_STREAM_END
only if the checksum is correct.
inflate() can decompress and check either zlib-wrapped or gzip-wrapped
deflate data. The header type is detected automatically, if requested when
initializing with inflateInit2(). Any information contained in the gzip
- header is not retained, so applications that need that information should
- instead use raw inflate, see inflateInit2() below, or inflateBack() and
- perform their own processing of the gzip header and trailer. When processing
+ header is not retained unless inflateGetHeader() is used. When processing
gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
- producted so far. The CRC-32 is checked against the gzip trailer.
+ produced so far. The CRC-32 is checked against the gzip trailer, as is the
+ uncompressed length, modulo 2^32.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
corrupted (input stream not conforming to the zlib format or incorrect check
- value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
- next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
- Z_BUF_ERROR if no progress is possible or if there was not enough room in the
- output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+ value, in which case strm->msg points to a string with a more specific
+ error), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+ next_in or next_out was Z_NULL, or the state was inadvertently written over
+ by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR
+ if no progress was possible or if there was not enough room in the output
+ buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
inflate() can be called again with more input and more output space to
continue decompressing. If Z_DATA_ERROR is returned, the application may
then call inflateSync() to look for a good compression block if a partial
- recovery of the data is desired.
+ recovery of the data is to be attempted.
*/
@@ -511,9 +523,8 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
This function discards any unprocessed input and does not flush any pending
output.
- inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
- was inconsistent. In the error case, msg may be set but then points to a
- static string (which must not be deallocated).
+ inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state
+ was inconsistent.
*/
@@ -544,16 +555,29 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead.
+ For the current implementation of deflate(), a windowBits value of 8 (a
+ window size of 256 bytes) is not supported. As a result, a request for 8
+ will result in 9 (a 512-byte window). In that case, providing 8 to
+ inflateInit2() will result in an error when the zlib header with 9 is
+ checked against the initialization of inflate(). The remedy is to not use 8
+ with deflateInit2() with this initialization, or at least in that case use 9
+ with inflateInit2().
+
windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
determines the window size. deflate() will then generate raw deflate data
- with no zlib header or trailer, and will not compute an adler32 check value.
+ with no zlib header or trailer, and will not compute a check value.
windowBits can also be greater than 15 for optional gzip encoding. Add
16 to windowBits to write a simple gzip header and trailer around the
compressed data instead of a zlib wrapper. The gzip header will have no
file name, no extra data, no comment, no modification time (set to zero), no
- header crc, and the operating system will be set to 255 (unknown). If a
- gzip stream is being written, strm->adler is a crc32 instead of an adler32.
+ header crc, and the operating system will be set to the appropriate value,
+ if the operating system was determined at compile time. If a gzip stream is
+ being written, strm->adler is a CRC-32 instead of an Adler-32.
+
+ For raw deflate or gzip encoding, a request for a 256-byte window is
+ rejected as invalid, since only the zlib header provides a means of
+ transmitting the window size to the decompressor.
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but is
@@ -614,12 +638,12 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
addition, the current implementation of deflate will use at most the window
size minus 262 bytes of the provided dictionary.
- Upon return of this function, strm->adler is set to the adler32 value
+ Upon return of this function, strm->adler is set to the Adler-32 value
of the dictionary; the decompressor may later use this value to determine
- which dictionary has been used by the compressor. (The adler32 value
+ which dictionary has been used by the compressor. (The Adler-32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.) If a raw deflate was requested, then the
- adler32 value is not computed and strm->adler is not set.
+ Adler-32 value is not computed and strm->adler is not set.
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
@@ -628,6 +652,28 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
not perform any compression: this will be done by deflate().
*/
+ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm,
+ Bytef *dictionary,
+ uInt *dictLength));
+/*
+ Returns the sliding dictionary being maintained by deflate. dictLength is
+ set to the number of bytes in the dictionary, and that many bytes are copied
+ to dictionary. dictionary must have enough space, where 32768 bytes is
+ always enough. If deflateGetDictionary() is called with dictionary equal to
+ Z_NULL, then only the dictionary length is returned, and nothing is copied.
+ Similary, if dictLength is Z_NULL, then it is not set.
+
+ deflateGetDictionary() may return a length less than the window size, even
+ when more than the window size in input has been provided. It may return up
+ to 258 bytes less in that case, due to how zlib's implementation of deflate
+ manages the sliding window and lookahead for matches, where matches can be
+ up to 258 bytes long. If the application needs the last window-size bytes of
+ input, then that would need to be saved by the application outside of zlib.
+
+ deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
+ stream state is inconsistent.
+*/
+
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
@@ -648,10 +694,10 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
- This function is equivalent to deflateEnd followed by deflateInit,
- but does not free and reallocate all the internal compression state. The
- stream will keep the same compression level and any other attributes that
- may have been set by deflateInit2.
+ This function is equivalent to deflateEnd followed by deflateInit, but
+ does not free and reallocate the internal compression state. The stream
+ will leave the compression level and any other attributes that may have been
+ set unchanged.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL).
@@ -662,20 +708,36 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int strategy));
/*
Dynamically update the compression level and compression strategy. The
- interpretation of level and strategy is as in deflateInit2. This can be
+ interpretation of level and strategy is as in deflateInit2(). This can be
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different strategy.
- If the compression level is changed, the input available so far is
- compressed with the old level (and may be flushed); the new level will take
- effect only at the next call of deflate().
-
- Before the call of deflateParams, the stream state must be set as for
- a call of deflate(), since the currently available input may have to be
- compressed and flushed. In particular, strm->avail_out must be non-zero.
-
- deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
- stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
- strm->avail_out was zero.
+ If the compression approach (which is a function of the level) or the
+ strategy is changed, and if any input has been consumed in a previous
+ deflate() call, then the input available so far is compressed with the old
+ level and strategy using deflate(strm, Z_BLOCK). There are three approaches
+ for the compression levels 0, 1..3, and 4..9 respectively. The new level
+ and strategy will take effect at the next call of deflate().
+
+ If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
+ not have enough output space to complete, then the parameter change will not
+ take effect. In this case, deflateParams() can be called again with the
+ same parameters and more output space to try again.
+
+ In order to assure a change in the parameters on the first try, the
+ deflate stream should be flushed using deflate() with Z_BLOCK or other flush
+ request until strm.avail_out is not zero, before calling deflateParams().
+ Then no more input data should be provided before the deflateParams() call.
+ If this is done, the old level and strategy will be applied to the data
+ compressed before deflateParams(), and the new level and strategy will be
+ applied to the the data compressed after deflateParams().
+
+ deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
+ state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
+ there was not enough output space to complete the compression of the
+ available input data before a change in the strategy or approach. Note that
+ in the case of a Z_BUF_ERROR, the parameters are not changed. A return
+ value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
+ retried with more output space.
*/
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
@@ -793,7 +855,7 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
is for use with other formats that use the deflate compressed data format
such as zip. Those formats provide their own check values. If a custom
format is developed using the raw deflate format for compressed data, it is
- recommended that a check value such as an adler32 or a crc32 be applied to
+ recommended that a check value such as an Adler-32 or a CRC-32 be applied to
the uncompressed data as is done in the zlib, gzip, and zip formats. For
most applications, the zlib format should be used as is. Note that comments
above on the use in deflateInit2() applies to the magnitude of windowBits.
@@ -802,7 +864,10 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
32 to windowBits to enable zlib and gzip decoding with automatic header
detection, or add 16 to decode only the gzip format (the zlib format will
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
- crc32 instead of an adler32.
+ CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
+ below), inflate() will not automatically decode concatenated gzip streams.
+ inflate() will return Z_STREAM_END at the end of the gzip stream. The state
+ would need to be reset to continue decoding a subsequent gzip stream.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
@@ -823,7 +888,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate,
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
- can be determined from the adler32 value returned by that call of inflate.
+ can be determined from the Adler-32 value returned by that call of inflate.
The compressor and decompressor must use exactly the same dictionary (see
deflateSetDictionary). For raw inflate, this function can be called at any
time to set the dictionary. If the provided dictionary is smaller than the
@@ -834,7 +899,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
- expected one (incorrect adler32 value). inflateSetDictionary does not
+ expected one (incorrect Adler-32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of
inflate().
*/
@@ -892,7 +957,7 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
- but does not free and reallocate all the internal decompression state. The
+ but does not free and reallocate the internal decompression state. The
stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
@@ -904,7 +969,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
/*
This function is the same as inflateReset, but it also permits changing
the wrap and window size requests. The windowBits parameter is interpreted
- the same as it is for inflateInit2.
+ the same as it is for inflateInit2. If the window size is changed, then the
+ memory allocated for the window is freed, and the window will be reallocated
+ by inflate() if needed.
inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL), or if
@@ -956,7 +1023,7 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
location in the input stream can be determined from avail_in and data_type
as noted in the description for the Z_BLOCK flush parameter for inflate.
- inflateMark returns the value noted above or -1 << 16 if the provided
+ inflateMark returns the value noted above, or -65536 if the provided
source stream state was inconsistent.
*/
@@ -1048,9 +1115,9 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
This routine would normally be used in a utility that reads zip or gzip
files and writes out uncompressed files. The utility would decode the
header and process the trailer on its own, hence this routine expects only
- the raw deflate stream to decompress. This is different from the normal
- behavior of inflate(), which expects either a zlib or gzip header and
- trailer around the deflate stream.
+ the raw deflate stream to decompress. This is different from the default
+ behavior of inflate(), which expects a zlib header and trailer around the
+ deflate stream.
inflateBack() uses two subroutines supplied by the caller that are then
called by inflateBack() for input and output. inflateBack() calls those
@@ -1059,12 +1126,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
parameters and return types are defined above in the in_func and out_func
typedefs. inflateBack() will call in(in_desc, &buf) which should return the
number of bytes of provided input, and a pointer to that input in buf. If
- there is no input available, in() must return zero--buf is ignored in that
- case--and inflateBack() will return a buffer error. inflateBack() will call
- out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
- should return zero on success, or non-zero on failure. If out() returns
- non-zero, inflateBack() will return with an error. Neither in() nor out()
- are permitted to change the contents of the window provided to
+ there is no input available, in() must return zero -- buf is ignored in that
+ case -- and inflateBack() will return a buffer error. inflateBack() will
+ call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
+ out() should return zero on success, or non-zero on failure. If out()
+ returns non-zero, inflateBack() will return with an error. Neither in() nor
+ out() are permitted to change the contents of the window provided to
inflateBackInit(), which is also the buffer that out() uses to write from.
The length written by out() will be at most the window size. Any non-zero
amount of input may be provided by in().
@@ -1092,7 +1159,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
using strm->next_in which will be Z_NULL only if in() returned an error. If
strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
non-zero. (in() will always be called before out(), so strm->next_in is
- assured to be defined if out() returns non-zero.) Note that inflateBack()
+ assured to be defined if out() returns non-zero.) Note that inflateBack()
cannot return Z_OK.
*/
@@ -1114,7 +1181,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
7.6: size of z_off_t
Compiler, assembler, and debug options:
- 8: DEBUG
+ 8: ZLIB_DEBUG
9: ASMV or ASMINF -- use ASM code
10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
11: 0 (reserved)
@@ -1164,7 +1231,8 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
the byte length of the source buffer. Upon entry, destLen is the total size
of the destination buffer, which must be at least the value returned by
compressBound(sourceLen). Upon exit, destLen is the actual size of the
- compressed buffer.
+ compressed data. compress() is equivalent to compress2() with a level
+ parameter of Z_DEFAULT_COMPRESSION.
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
@@ -1180,7 +1248,7 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least the value returned by
compressBound(sourceLen). Upon exit, destLen is the actual size of the
- compressed buffer.
+ compressed data.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
@@ -1203,7 +1271,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
uncompressed data. (The size of the uncompressed data must have been saved
previously by the compressor and transmitted to the decompressor by some
mechanism outside the scope of this compression library.) Upon exit, destLen
- is the actual size of the uncompressed buffer.
+ is the actual size of the uncompressed data.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
@@ -1212,6 +1280,14 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
buffer with the uncompressed data up to that point.
*/
+ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong *sourceLen));
+/*
+ Same as uncompress, except that sourceLen is a pointer, where the
+ length of the source is *sourceLen. On return, *sourceLen is the number of
+ source bytes consumed.
+*/
+
/* gzip file access functions */
/*
@@ -1290,10 +1366,9 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
default buffer size is 8192 bytes. This function must be called after
gzopen() or gzdopen(), and before any other calls that read or write the
file. The buffer memory allocation is always deferred to the first read or
- write. Two buffers are allocated, either both of the specified size when
- writing, or one of the specified size and the other twice that size when
- reading. A larger buffer size of, for example, 64K or 128K bytes will
- noticeably increase the speed of decompression (reading).
+ write. Three times that size in buffer space is allocated. A larger buffer
+ size of, for example, 64K or 128K bytes will noticeably increase the speed
+ of decompression (reading).
The new buffer size also affects the maximum length for gzprintf().
@@ -1304,10 +1379,12 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description
- of deflateInit2 for the meaning of these parameters.
+ of deflateInit2 for the meaning of these parameters. Previously provided
+ data is flushed before the parameter change.
- gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
- opened for writing.
+ gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
+ opened for writing, Z_ERRNO if there is an error writing the flushed data,
+ or Z_MEM_ERROR if there is a memory allocation error.
*/
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
@@ -1335,7 +1412,35 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
case.
gzread returns the number of uncompressed bytes actually read, less than
- len for end of file, or -1 for error.
+ len for end of file, or -1 for error. If len is too large to fit in an int,
+ then nothing is read, -1 is returned, and the error state is set to
+ Z_STREAM_ERROR.
+*/
+
+ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
+ gzFile file));
+/*
+ Read up to nitems items of size size from file to buf, otherwise operating
+ as gzread() does. This duplicates the interface of stdio's fread(), with
+ size_t request and return types. If the library defines size_t, then
+ z_size_t is identical to size_t. If not, then z_size_t is an unsigned
+ integer type that can contain a pointer.
+
+ gzfread() returns the number of full items read of size size, or zero if
+ the end of the file was reached and a full item could not be read, or if
+ there was an error. gzerror() must be consulted if zero is returned in
+ order to determine if there was an error. If the multiplication of size and
+ nitems overflows, i.e. the product does not fit in a z_size_t, then nothing
+ is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
+
+ In the event that the end of file is reached and only a partial item is
+ available at the end, i.e. the remaining uncompressed data length is not a
+ multiple of size, then the final partial item is nevetheless read into buf
+ and the end-of-file flag is set. The length of the partial item read is not
+ provided, but could be inferred from the result of gztell(). This behavior
+ is the same as the behavior of fread() implementations in common libraries,
+ but it prevents the direct use of gzfread() to read a concurrently written
+ file, reseting and retrying on end-of-file, when size is not 1.
*/
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
@@ -1346,19 +1451,33 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
error.
*/
+ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
+ z_size_t nitems, gzFile file));
+/*
+ gzfwrite() writes nitems items of size size from buf to file, duplicating
+ the interface of stdio's fwrite(), with size_t request and return types. If
+ the library defines size_t, then z_size_t is identical to size_t. If not,
+ then z_size_t is an unsigned integer type that can contain a pointer.
+
+ gzfwrite() returns the number of full items written of size size, or zero
+ if there was an error. If the multiplication of size and nitems overflows,
+ i.e. the product does not fit in a z_size_t, then nothing is written, zero
+ is returned, and the error state is set to Z_STREAM_ERROR.
+*/
+
ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the arguments to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
- uncompressed bytes actually written, or 0 in case of error. The number of
- uncompressed bytes written is limited to 8191, or one less than the buffer
- size given to gzbuffer(). The caller should assure that this limit is not
- exceeded. If it is exceeded, then gzprintf() will return an error (0) with
- nothing written. In this case, there may also be a buffer overflow with
- unpredictable consequences, which is possible only if zlib was compiled with
- the insecure functions sprintf() or vsprintf() because the secure snprintf()
- or vsnprintf() functions were not available. This can be determined using
- zlibCompileFlags().
+ uncompressed bytes actually written, or a negative zlib error code in case
+ of error. The number of uncompressed bytes written is limited to 8191, or
+ one less than the buffer size given to gzbuffer(). The caller should assure
+ that this limit is not exceeded. If it is exceeded, then gzprintf() will
+ return an error (0) with nothing written. In this case, there may also be a
+ buffer overflow with unpredictable consequences, which is possible only if
+ zlib was compiled with the insecure functions sprintf() or vsprintf()
+ because the secure snprintf() or vsnprintf() functions were not available.
+ This can be determined using zlibCompileFlags().
*/
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
@@ -1418,7 +1537,7 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
If the flush parameter is Z_FINISH, the remaining data is written and the
gzip stream is completed in the output. If gzwrite() is called again, a new
gzip stream will be started in the output. gzread() is able to read such
- concatented gzip streams.
+ concatenated gzip streams.
gzflush should be called only when strictly necessary because it will
degrade compression if called too often.
@@ -1572,7 +1691,7 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
return the updated checksum. If buf is Z_NULL, this function returns the
required initial value for the checksum.
- An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
much faster.
Usage example:
@@ -1585,6 +1704,12 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
if (adler != original_adler) error();
*/
+ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf,
+ z_size_t len));
+/*
+ Same as adler32(), but with a size_t length.
+*/
+
/*
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
z_off_t len2));
@@ -1614,6 +1739,12 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
if (crc != original_crc) error();
*/
+ZEXTERN uLong ZEXPORT crc32_z OF((uLong adler, const Bytef *buf,
+ z_size_t len));
+/*
+ Same as crc32(), but with a size_t length.
+*/
+
/*
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
@@ -1644,19 +1775,35 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
unsigned char FAR *window,
const char *version,
int stream_size));
-#define deflateInit(strm, level) \
- deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
-#define inflateInit(strm) \
- inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
-#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
- deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
- (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
-#define inflateInit2(strm, windowBits) \
- inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
- (int)sizeof(z_stream))
-#define inflateBackInit(strm, windowBits, window) \
- inflateBackInit_((strm), (windowBits), (window), \
- ZLIB_VERSION, (int)sizeof(z_stream))
+#ifdef Z_PREFIX_SET
+# define z_deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
+# define z_inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
+# define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
+# define z_inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+ (int)sizeof(z_stream))
+# define z_inflateBackInit(strm, windowBits, window) \
+ inflateBackInit_((strm), (windowBits), (window), \
+ ZLIB_VERSION, (int)sizeof(z_stream))
+#else
+# define deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
+# define inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
+# define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
+# define inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+ (int)sizeof(z_stream))
+# define inflateBackInit(strm, windowBits, window) \
+ inflateBackInit_((strm), (windowBits), (window), \
+ ZLIB_VERSION, (int)sizeof(z_stream))
+#endif
#ifndef Z_SOLO
@@ -1676,10 +1823,10 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
#ifdef Z_PREFIX_SET
# undef z_gzgetc
# define z_gzgetc(g) \
- ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#else
# define gzgetc(g) \
- ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#endif
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
@@ -1737,19 +1884,16 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
#endif /* !Z_SOLO */
-/* hack for buggy compilers */
-#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
- struct internal_state {int dummy;};
-#endif
-
/* undocumented functions */
ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
+ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp));
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
-#if defined(_WIN32) && !defined(Z_SOLO)
+#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO)
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
const char *mode));
#endif
diff --git a/src/zlib/zutil.c b/src/ZLib/zutil.c
similarity index 86%
rename from src/zlib/zutil.c
rename to src/ZLib/zutil.c
index 23d2ebef0..a76c6b0c7 100644
--- a/src/zlib/zutil.c
+++ b/src/ZLib/zutil.c
@@ -1,5 +1,5 @@
/* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
+ * Copyright (C) 1995-2017 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -10,21 +10,18 @@
# include "gzguts.h"
#endif
-#ifndef NO_DUMMY_DECL
-struct internal_state {int dummy;}; /* for buggy compilers */
-#endif
-
z_const char * const z_errmsg[10] = {
-"need dictionary", /* Z_NEED_DICT 2 */
-"stream end", /* Z_STREAM_END 1 */
-"", /* Z_OK 0 */
-"file error", /* Z_ERRNO (-1) */
-"stream error", /* Z_STREAM_ERROR (-2) */
-"data error", /* Z_DATA_ERROR (-3) */
-"insufficient memory", /* Z_MEM_ERROR (-4) */
-"buffer error", /* Z_BUF_ERROR (-5) */
-"incompatible version",/* Z_VERSION_ERROR (-6) */
-""};
+ (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
+ (z_const char *)"stream end", /* Z_STREAM_END 1 */
+ (z_const char *)"", /* Z_OK 0 */
+ (z_const char *)"file error", /* Z_ERRNO (-1) */
+ (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
+ (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
+ (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
+ (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
+ (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
+ (z_const char *)""
+};
const char * ZEXPORT zlibVersion()
@@ -61,7 +58,7 @@ uLong ZEXPORT zlibCompileFlags()
case 8: flags += 2 << 6; break;
default: flags += 3 << 6;
}
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
flags += 1 << 8;
#endif
#if defined(ASMV) || defined(ASMINF)
@@ -115,8 +112,8 @@ uLong ZEXPORT zlibCompileFlags()
return flags;
}
-#ifdef DEBUG
-
+#ifdef ZLIB_DEBUG
+#include
# ifndef verbose
# define verbose 0
# endif
@@ -219,9 +216,11 @@ local ptr_table table[MAX_PTR];
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
{
- voidpf buf = opaque; /* just to make some compilers happy */
+ voidpf buf;
ulg bsize = (ulg)items*size;
+ (void)opaque;
+
/* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized.
*/
@@ -244,6 +243,9 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
{
int n;
+
+ (void)opaque;
+
if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr);
return;
@@ -259,7 +261,6 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
next_ptr--;
return;
}
- ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found");
}
@@ -278,13 +279,13 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
{
- if (opaque) opaque = 0; /* to make compiler happy */
+ (void)opaque;
return _halloc((long)items, size);
}
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
{
- if (opaque) opaque = 0; /* to make compiler happy */
+ (void)opaque;
_hfree(ptr);
}
@@ -306,7 +307,7 @@ voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
unsigned items;
unsigned size;
{
- if (opaque) items += size - size; /* make compiler happy */
+ (void)opaque;
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size);
}
@@ -315,8 +316,8 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
voidpf opaque;
voidpf ptr;
{
+ (void)opaque;
free(ptr);
- if (opaque) return; /* make compiler happy */
}
#endif /* MY_ZCALLOC */
diff --git a/src/zlib/zutil.h b/src/ZLib/zutil.h
similarity index 88%
rename from src/zlib/zutil.h
rename to src/ZLib/zutil.h
index 24ab06b1c..b079ea6a8 100644
--- a/src/zlib/zutil.h
+++ b/src/ZLib/zutil.h
@@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -36,7 +36,9 @@
#ifndef local
# define local static
#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
+/* since "static" is used to mean two completely different things in C, we
+ define "local" for the non-static meaning of "static", for readability
+ (compile with -Dlocal if your debugger can't find static symbols) */
typedef unsigned char uch;
typedef uch FAR uchf;
@@ -98,28 +100,38 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif
#ifdef AMIGA
-# define OS_CODE 0x01
+# define OS_CODE 1
#endif
#if defined(VAXC) || defined(VMS)
-# define OS_CODE 0x02
+# define OS_CODE 2
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
+#ifdef __370__
+# if __TARGET_LIB__ < 0x20000000
+# define OS_CODE 4
+# elif __TARGET_LIB__ < 0x40000000
+# define OS_CODE 11
+# else
+# define OS_CODE 8
+# endif
+#endif
+
#if defined(ATARI) || defined(atarist)
-# define OS_CODE 0x05
+# define OS_CODE 5
#endif
#ifdef OS2
-# define OS_CODE 0x06
+# define OS_CODE 6
# if defined(M_I86) && !defined(Z_SOLO)
# include
# endif
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
-# define OS_CODE 0x07
+# define OS_CODE 7
# ifndef Z_SOLO
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include /* for fdopen */
@@ -131,18 +143,24 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
#endif
-#ifdef TOPS20
-# define OS_CODE 0x0a
+#ifdef __acorn
+# define OS_CODE 13
#endif
-#ifdef WIN32
-# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
-# define OS_CODE 0x0b
-# endif
+#if defined(WIN32) && !defined(__CYGWIN__)
+# define OS_CODE 10
+#endif
+
+#ifdef _BEOS_
+# define OS_CODE 16
+#endif
+
+#ifdef __TOS_OS400__
+# define OS_CODE 18
#endif
-#ifdef __50SERIES /* Prime/PRIMOS */
-# define OS_CODE 0x0f
+#ifdef __APPLE__
+# define OS_CODE 19
#endif
#if defined(_BEOS_) || defined(RISCOS)
@@ -177,7 +195,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* common defaults */
#ifndef OS_CODE
-# define OS_CODE 0x03 /* assume Unix */
+# define OS_CODE 3 /* assume Unix */
#endif
#ifndef F_OPEN
@@ -216,7 +234,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif
/* Diagnostic functions */
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
# include
extern int ZLIB_INTERNAL z_verbose;
extern void ZLIB_INTERNAL z_error OF((char *m));
diff --git a/src/boost/SConscript b/src/boost/SConscript
index 71c9481b1..e3b2f9fea 100644
--- a/src/boost/SConscript
+++ b/src/boost/SConscript
@@ -8,13 +8,13 @@ env = env.Clone()
# Remove warnings
import re
-flags = env.subst('${CCFLAGS}')
-flags = re.sub(r'-W((all)|(error))(=[^\s$]+)?(\s|$)', '', flags)
-env.Replace(CCFLAGS = flags)
+pat = r'-W((all)|(error)|(suggest-override))(=[^\s$]+)?(\s|$)'
+env.Replace(CCFLAGS = re.sub(pat, '', env.subst('${CCFLAGS}')))
+env.Replace(CXXFLAGS = re.sub(pat, '', env.subst('${CXXFLAGS}')))
# Build boost lib
src = []
-for lib in ['iostreams', 'filesystem', 'system', 'regex']:
+for lib in ['iostreams', 'filesystem', 'system']:
src += Glob('libs/%s/src/*.cpp' % lib)
lib = env.Library('#/lib/cbang-boost', src)
diff --git a/src/boost/boost/algorithm/string/compare.hpp b/src/boost/boost/algorithm/string/compare.hpp
index f610b3643..a2673c8f3 100644
--- a/src/boost/boost/algorithm/string/compare.hpp
+++ b/src/boost/boost/algorithm/string/compare.hpp
@@ -65,7 +65,7 @@ namespace boost {
template< typename T1, typename T2 >
bool operator()( const T1& Arg1, const T2& Arg2 ) const
{
- #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
+ #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
return std::toupper(Arg1)==std::toupper(Arg2);
#else
return std::toupper(Arg1,m_Loc)==std::toupper(Arg2,m_Loc);
@@ -118,7 +118,7 @@ namespace boost {
template< typename T1, typename T2 >
bool operator()( const T1& Arg1, const T2& Arg2 ) const
{
- #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
+ #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
return std::toupper(Arg1)(Arg1,m_Loc)(Arg2,m_Loc);
@@ -171,7 +171,7 @@ namespace boost {
template< typename T1, typename T2 >
bool operator()( const T1& Arg1, const T2& Arg2 ) const
{
- #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
+ #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
return std::toupper(Arg1)<=std::toupper(Arg2);
#else
return std::toupper(Arg1,m_Loc)<=std::toupper(Arg2,m_Loc);
diff --git a/src/boost/boost/algorithm/string/detail/case_conv.hpp b/src/boost/boost/algorithm/string/detail/case_conv.hpp
index bd45c04cc..220b858ad 100644
--- a/src/boost/boost/algorithm/string/detail/case_conv.hpp
+++ b/src/boost/boost/algorithm/string/detail/case_conv.hpp
@@ -15,6 +15,9 @@
#include
#include
+#include
+#include
+#include
#include
namespace boost {
@@ -40,7 +43,7 @@ namespace boost {
// Operation
CharT operator ()( CharT Ch ) const
{
- #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
+ #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
return std::tolower( static_cast::type> ( Ch ));
#else
return std::tolower( Ch, *m_Loc );
@@ -62,7 +65,7 @@ namespace boost {
// Operation
CharT operator ()( CharT Ch ) const
{
- #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
+ #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
return std::toupper( static_cast::type> ( Ch ));
#else
return std::toupper( Ch, *m_Loc );
diff --git a/src/boost/boost/algorithm/string/detail/find_format_all.hpp b/src/boost/boost/algorithm/string/detail/find_format_all.hpp
index ae1e5da6c..535583712 100644
--- a/src/boost/boost/algorithm/string/detail/find_format_all.hpp
+++ b/src/boost/boost/algorithm/string/detail/find_format_all.hpp
@@ -18,6 +18,8 @@
#include
#include
+#include
+
namespace boost {
namespace algorithm {
namespace detail {
diff --git a/src/boost/boost/algorithm/string/detail/finder.hpp b/src/boost/boost/algorithm/string/detail/finder.hpp
index 5bf36a940..c9bc32d86 100644
--- a/src/boost/boost/algorithm/string/detail/finder.hpp
+++ b/src/boost/boost/algorithm/string/detail/finder.hpp
@@ -13,7 +13,7 @@
#include
#include
-#include
+#include
#include
#include
@@ -127,8 +127,8 @@ namespace boost {
if( boost::empty(m_Search) )
return result_type( End, End );
- typedef BOOST_STRING_TYPENAME boost::detail::
- iterator_traits::iterator_category category;
+ typedef BOOST_STRING_TYPENAME
+ std::iterator_traits::iterator_category category;
return findit( Begin, End, category() );
}
@@ -344,9 +344,8 @@ namespace boost {
typedef iterator_range result_type;
input_iterator_type It=Begin;
- for(
- unsigned int Index=0;
- Index::iterator_category category;
+ typedef BOOST_STRING_TYPENAME
+ std::iterator_traits::iterator_category category;
return ::boost::algorithm::detail::find_head_impl( Begin, End, N, category() );
}
@@ -397,10 +396,12 @@ namespace boost {
input_iterator_type It2=Begin;
// Advance It2 by N increments
- for( Index=0; Index result_type;
input_iterator_type It=End;
- for(
- unsigned int Index=0;
- Index::iterator_category category;
+ typedef BOOST_STRING_TYPENAME
+ std::iterator_traits::iterator_category category;
return ::boost::algorithm::detail::find_tail_impl( Begin, End, N, category() );
}
diff --git a/src/boost/boost/algorithm/string/detail/formatter.hpp b/src/boost/boost/algorithm/string/detail/formatter.hpp
index 9fd16e2f3..98c051b39 100644
--- a/src/boost/boost/algorithm/string/detail/formatter.hpp
+++ b/src/boost/boost/algorithm/string/detail/formatter.hpp
@@ -42,7 +42,7 @@ namespace boost {
m_Format(::boost::begin(Format), ::boost::end(Format)) {}
// Operation
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
+#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
template
result_type& operator()(const Range2T&)
{
diff --git a/src/boost/boost/algorithm/string/find_format.hpp b/src/boost/boost/algorithm/string/find_format.hpp
index deb4bd9b4..97549edba 100644
--- a/src/boost/boost/algorithm/string/find_format.hpp
+++ b/src/boost/boost/algorithm/string/find_format.hpp
@@ -12,7 +12,6 @@
#define BOOST_STRING_FIND_FORMAT_HPP
#include
-#include
#include
#include
#include
@@ -40,7 +39,7 @@ namespace boost {
this substring and replace it in the input.
The result is a modified copy of the input. It is returned as a sequence
or copied to the output iterator.
-
+
\param Output An output iterator to which the result will be copied
\param Input An input sequence
\param Finder A Finder object used to search for a match to be replaced
diff --git a/src/boost/boost/algorithm/string/formatter.hpp b/src/boost/boost/algorithm/string/formatter.hpp
index 1295d6721..c05495092 100644
--- a/src/boost/boost/algorithm/string/formatter.hpp
+++ b/src/boost/boost/algorithm/string/formatter.hpp
@@ -11,7 +11,6 @@
#ifndef BOOST_STRING_FORMATTER_HPP
#define BOOST_STRING_FORMATTER_HPP
-#include
#include
#include
#include
diff --git a/src/boost/boost/align/align.hpp b/src/boost/boost/align/align.hpp
new file mode 100644
index 000000000..17d91537d
--- /dev/null
+++ b/src/boost/boost/align/align.hpp
@@ -0,0 +1,19 @@
+/*
+Copyright 2014-2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_ALIGN_HPP
+#define BOOST_ALIGN_ALIGN_HPP
+
+#include
+
+#if !defined(BOOST_NO_CXX11_STD_ALIGN) && !defined(BOOST_LIBSTDCXX_VERSION)
+#include
+#else
+#include
+#endif
+
+#endif
diff --git a/src/boost/boost/align/aligned_alloc.hpp b/src/boost/boost/align/aligned_alloc.hpp
new file mode 100644
index 000000000..bad433064
--- /dev/null
+++ b/src/boost/boost/align/aligned_alloc.hpp
@@ -0,0 +1,47 @@
+/*
+Copyright 2014-2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_ALIGNED_ALLOC_HPP
+#define BOOST_ALIGN_ALIGNED_ALLOC_HPP
+
+#include
+
+#if defined(BOOST_HAS_UNISTD_H)
+#include
+#endif
+
+#if defined(__APPLE__) || defined(__APPLE_CC__) || defined(macintosh)
+#include
+#endif
+
+#if defined(BOOST_ALIGN_USE_ALIGN)
+#include
+#elif defined(BOOST_ALIGN_USE_NEW)
+#include
+#elif defined(_MSC_VER) && !defined(UNDER_CE)
+#include
+#elif defined(__MINGW32__) && (__MSVCRT_VERSION__ >= 0x0700)
+#include
+#elif defined(__MINGW32__)
+#include
+#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+#include
+#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+#include
+#elif defined(__ANDROID__)
+#include
+#elif defined(__SunOS_5_11) || defined(__SunOS_5_12)
+#include
+#elif defined(sun) || defined(__sun)
+#include
+#elif defined(_POSIX_VERSION)
+#include
+#else
+#include
+#endif
+
+#endif
diff --git a/src/boost/boost/align/alignment_of.hpp b/src/boost/boost/align/alignment_of.hpp
new file mode 100644
index 000000000..5483cf373
--- /dev/null
+++ b/src/boost/boost/align/alignment_of.hpp
@@ -0,0 +1,54 @@
+/*
+Copyright 2014-2016 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_ALIGNMENT_OF_HPP
+#define BOOST_ALIGN_ALIGNMENT_OF_HPP
+
+#include
+#include
+
+#if defined(_MSC_VER) && defined(__clang__)
+#include
+#elif defined(BOOST_MSVC)
+#include
+#elif defined(__GNUC__) && defined(__unix__) && !defined(__LP64__)
+#include
+#elif defined(BOOST_CLANG) && !defined(__x86_64__)
+#include
+#elif !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
+#include
+#elif defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600)
+#include
+#elif defined(BOOST_CODEGEARC)
+#include
+#elif defined(BOOST_CLANG)
+#include
+#elif __GNUC__ > 4
+#include
+#elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)
+#include
+#else
+#include
+#endif
+
+namespace boost {
+namespace alignment {
+
+template
+struct alignment_of
+ : detail::alignment_of::type>::type { };
+
+#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
+template
+constexpr std::size_t alignment_of_v = alignment_of::value;
+#endif
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/alignment_of_forward.hpp b/src/boost/boost/align/alignment_of_forward.hpp
new file mode 100644
index 000000000..87d2c29da
--- /dev/null
+++ b/src/boost/boost/align/alignment_of_forward.hpp
@@ -0,0 +1,20 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP
+#define BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP
+
+namespace boost {
+namespace alignment {
+
+template
+struct alignment_of;
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/align.hpp b/src/boost/boost/align/detail/align.hpp
new file mode 100644
index 000000000..42b29fbeb
--- /dev/null
+++ b/src/boost/boost/align/detail/align.hpp
@@ -0,0 +1,38 @@
+/*
+Copyright 2014-2020 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGN_HPP
+#define BOOST_ALIGN_DETAIL_ALIGN_HPP
+
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+align(std::size_t alignment, std::size_t size, void*& ptr,
+ std::size_t& space)
+{
+ BOOST_ASSERT(boost::alignment::detail::is_alignment(alignment));
+ if (size <= space) {
+ char* p = reinterpret_cast(~(alignment - 1) &
+ (reinterpret_cast(ptr) + alignment - 1));
+ std::size_t n = p - static_cast(ptr);
+ if (n <= space - size) {
+ ptr = p;
+ space -= n;
+ return p;
+ }
+ }
+ return 0;
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/align_cxx11.hpp b/src/boost/boost/align/detail/align_cxx11.hpp
new file mode 100644
index 000000000..59ae267f3
--- /dev/null
+++ b/src/boost/boost/align/detail/align_cxx11.hpp
@@ -0,0 +1,21 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP
+#define BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP
+
+#include
+
+namespace boost {
+namespace alignment {
+
+using std::align;
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc.hpp b/src/boost/boost/align/detail/aligned_alloc.hpp
new file mode 100644
index 000000000..e940ef970
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc.hpp
@@ -0,0 +1,52 @@
+/*
+Copyright 2014-2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
+
+#include
+#include
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ enum {
+ N = alignment_of::value
+ };
+ if (alignment < N) {
+ alignment = N;
+ }
+ std::size_t n = size + alignment - N;
+ void* p = std::malloc(sizeof(void*) + n);
+ if (p) {
+ void* r = static_cast(p) + sizeof(void*);
+ (void)boost::alignment::align(alignment, size, r, n);
+ *(static_cast(r) - 1) = p;
+ p = r;
+ }
+ return p;
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ if (ptr) {
+ std::free(*(static_cast(ptr) - 1));
+ }
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_android.hpp b/src/boost/boost/align/detail/aligned_alloc_android.hpp
new file mode 100644
index 000000000..1fd1ff5e7
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_android.hpp
@@ -0,0 +1,34 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
+
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return ::memalign(alignment, size);
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ ::free(ptr);
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_macos.hpp b/src/boost/boost/align/detail/aligned_alloc_macos.hpp
new file mode 100644
index 000000000..25a51cf04
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_macos.hpp
@@ -0,0 +1,44 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
+
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ if (size == 0) {
+ return 0;
+ }
+ if (alignment < sizeof(void*)) {
+ alignment = sizeof(void*);
+ }
+ void* p;
+ if (::posix_memalign(&p, alignment, size) != 0) {
+ p = 0;
+ }
+ return p;
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ ::free(ptr);
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_mingw.hpp b/src/boost/boost/align/detail/aligned_alloc_mingw.hpp
new file mode 100644
index 000000000..75814eac9
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_mingw.hpp
@@ -0,0 +1,34 @@
+/*
+Copyright 2020 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MINGW_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MINGW_HPP
+
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return ::__mingw_aligned_malloc(size, alignment);
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ ::__mingw_aligned_free(ptr);
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_msvc.hpp b/src/boost/boost/align/detail/aligned_alloc_msvc.hpp
new file mode 100644
index 000000000..99e898f39
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_msvc.hpp
@@ -0,0 +1,34 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
+
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return ::_aligned_malloc(size, alignment);
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ ::_aligned_free(ptr);
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_new.hpp b/src/boost/boost/align/detail/aligned_alloc_new.hpp
new file mode 100644
index 000000000..ca330b032
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_new.hpp
@@ -0,0 +1,52 @@
+/*
+Copyright 2014-2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP
+
+#include
+#include
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ enum {
+ N = alignment_of::value
+ };
+ if (alignment < N) {
+ alignment = N;
+ }
+ std::size_t n = size + alignment - N;
+ void* p = ::operator new(sizeof(void*) + n, std::nothrow);
+ if (p) {
+ void* r = static_cast(p) + sizeof(void*);
+ (void)boost::alignment::align(alignment, size, r, n);
+ *(static_cast(r) - 1) = p;
+ p = r;
+ }
+ return p;
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ if (ptr) {
+ ::operator delete(*(static_cast(ptr) - 1));
+ }
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_posix.hpp b/src/boost/boost/align/detail/aligned_alloc_posix.hpp
new file mode 100644
index 000000000..30b7e9179
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_posix.hpp
@@ -0,0 +1,41 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
+
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ if (alignment < sizeof(void*)) {
+ alignment = sizeof(void*);
+ }
+ void* p;
+ if (::posix_memalign(&p, alignment, size) != 0) {
+ p = 0;
+ }
+ return p;
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ ::free(ptr);
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/aligned_alloc_sunos.hpp b/src/boost/boost/align/detail/aligned_alloc_sunos.hpp
new file mode 100644
index 000000000..186c68784
--- /dev/null
+++ b/src/boost/boost/align/detail/aligned_alloc_sunos.hpp
@@ -0,0 +1,34 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
+
+#include
+#include
+#include
+
+namespace boost {
+namespace alignment {
+
+inline void*
+aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return ::memalign(alignment, size);
+}
+
+inline void
+aligned_free(void* ptr) BOOST_NOEXCEPT
+{
+ ::free(ptr);
+}
+
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/alignment_of.hpp b/src/boost/boost/align/detail/alignment_of.hpp
new file mode 100644
index 000000000..147410b29
--- /dev/null
+++ b/src/boost/boost/align/detail/alignment_of.hpp
@@ -0,0 +1,31 @@
+/*
+Copyright 2014-2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP
+
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+template
+struct offset_value {
+ char value;
+ T object;
+};
+
+template
+struct alignment_of
+ : min_size) - sizeof(T)> { };
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/alignment_of_clang.hpp b/src/boost/boost/align/detail/alignment_of_clang.hpp
new file mode 100644
index 000000000..7bda00299
--- /dev/null
+++ b/src/boost/boost/align/detail/alignment_of_clang.hpp
@@ -0,0 +1,26 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP
+
+#include
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+template
+struct alignment_of
+ : integral_constant { };
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/alignment_of_codegear.hpp b/src/boost/boost/align/detail/alignment_of_codegear.hpp
new file mode 100644
index 000000000..6cac7b822
--- /dev/null
+++ b/src/boost/boost/align/detail/alignment_of_codegear.hpp
@@ -0,0 +1,26 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP
+
+#include
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+template
+struct alignment_of
+ : integral_constant { };
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/alignment_of_cxx11.hpp b/src/boost/boost/align/detail/alignment_of_cxx11.hpp
new file mode 100644
index 000000000..93dad019c
--- /dev/null
+++ b/src/boost/boost/align/detail/alignment_of_cxx11.hpp
@@ -0,0 +1,23 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP
+
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+using std::alignment_of;
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/alignment_of_gcc.hpp b/src/boost/boost/align/detail/alignment_of_gcc.hpp
new file mode 100644
index 000000000..2b716c076
--- /dev/null
+++ b/src/boost/boost/align/detail/alignment_of_gcc.hpp
@@ -0,0 +1,26 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP
+
+#include
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+template
+struct alignment_of
+ : integral_constant { };
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/alignment_of_msvc.hpp b/src/boost/boost/align/detail/alignment_of_msvc.hpp
new file mode 100644
index 000000000..0a6e7ecff
--- /dev/null
+++ b/src/boost/boost/align/detail/alignment_of_msvc.hpp
@@ -0,0 +1,32 @@
+/*
+Copyright 2014-2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP
+#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP
+
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+template
+struct offset_value {
+ T first;
+ char value;
+ T second;
+};
+
+template
+struct alignment_of
+ : min_size) - (sizeof(T) << 1)> { };
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/element_type.hpp b/src/boost/boost/align/detail/element_type.hpp
new file mode 100644
index 000000000..bd0a70411
--- /dev/null
+++ b/src/boost/boost/align/detail/element_type.hpp
@@ -0,0 +1,91 @@
+/*
+Copyright 2015 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
+#define BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
+
+#include
+
+#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
+#include
+#else
+#include
+#endif
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
+using std::remove_reference;
+using std::remove_all_extents;
+using std::remove_cv;
+#else
+template
+struct remove_reference {
+ typedef T type;
+};
+
+template
+struct remove_reference {
+ typedef T type;
+};
+
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
+template
+struct remove_reference {
+ typedef T type;
+};
+#endif
+
+template
+struct remove_all_extents {
+ typedef T type;
+};
+
+template
+struct remove_all_extents {
+ typedef typename remove_all_extents::type type;
+};
+
+template
+struct remove_all_extents {
+ typedef typename remove_all_extents::type type;
+};
+
+template
+struct remove_cv {
+ typedef T type;
+};
+
+template
+struct remove_cv {
+ typedef T type;
+};
+
+template
+struct remove_cv {
+ typedef T type;
+};
+
+template
+struct remove_cv {
+ typedef T type;
+};
+#endif
+
+template
+struct element_type {
+ typedef typename remove_cv::type>::type>::type type;
+};
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/integral_constant.hpp b/src/boost/boost/align/detail/integral_constant.hpp
new file mode 100644
index 000000000..e467e3485
--- /dev/null
+++ b/src/boost/boost/align/detail/integral_constant.hpp
@@ -0,0 +1,53 @@
+/*
+Copyright 2014-2016 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP
+#define BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP
+
+#include
+
+#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
+#include
+#endif
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
+using std::integral_constant;
+using std::true_type;
+using std::false_type;
+#else
+template
+struct integral_constant {
+ typedef T value_type;
+ typedef integral_constant type;
+
+ BOOST_CONSTEXPR operator value_type() const BOOST_NOEXCEPT {
+ return Value;
+ }
+
+ BOOST_CONSTEXPR value_type operator()() const BOOST_NOEXCEPT {
+ return Value;
+ }
+
+ BOOST_STATIC_CONSTEXPR T value = Value;
+};
+
+template
+BOOST_CONSTEXPR_OR_CONST T integral_constant::value;
+
+typedef integral_constant true_type;
+typedef integral_constant false_type;
+#endif
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/is_alignment.hpp b/src/boost/boost/align/detail/is_alignment.hpp
new file mode 100644
index 000000000..0ec57c16f
--- /dev/null
+++ b/src/boost/boost/align/detail/is_alignment.hpp
@@ -0,0 +1,28 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP
+#define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP
+
+#include
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+BOOST_CONSTEXPR inline bool
+is_alignment(std::size_t value) BOOST_NOEXCEPT
+{
+ return (value > 0) && ((value & (value - 1)) == 0);
+}
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/align/detail/min_size.hpp b/src/boost/boost/align/detail/min_size.hpp
new file mode 100644
index 000000000..688d6cf00
--- /dev/null
+++ b/src/boost/boost/align/detail/min_size.hpp
@@ -0,0 +1,26 @@
+/*
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
+
+Distributed under the Boost Software License, Version 1.0.
+(http://www.boost.org/LICENSE_1_0.txt)
+*/
+#ifndef BOOST_ALIGN_DETAIL_MIN_SIZE_HPP
+#define BOOST_ALIGN_DETAIL_MIN_SIZE_HPP
+
+#include
+#include
+
+namespace boost {
+namespace alignment {
+namespace detail {
+
+template
+struct min_size
+ : integral_constant { };
+
+} /* detail */
+} /* alignment */
+} /* boost */
+
+#endif
diff --git a/src/boost/boost/array.hpp b/src/boost/boost/array.hpp
index fdbe00d8a..dbbb5a2c2 100644
--- a/src/boost/boost/array.hpp
+++ b/src/boost/boost/array.hpp
@@ -41,13 +41,12 @@
#endif
#include
+#include
#include
#include
+#include
#include
-#include
-// Handles broken standard libraries better than
-#include
#include
#include
@@ -183,7 +182,7 @@ namespace boost {
// check range (may be private because it is static)
static BOOST_CONSTEXPR bool rangecheck (size_type i) {
- return i > size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
+ return i >= size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
}
};
diff --git a/src/boost/boost/assert/source_location.hpp b/src/boost/boost/assert/source_location.hpp
new file mode 100644
index 000000000..632055bc1
--- /dev/null
+++ b/src/boost/boost/assert/source_location.hpp
@@ -0,0 +1,192 @@
+#ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
+#define BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
+
+// http://www.boost.org/libs/assert
+//
+// Copyright 2019, 2021 Peter Dimov
+// Distributed under the Boost Software License, Version 1.0.
+// http://www.boost.org/LICENSE_1_0.txt
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
+# include
+#endif
+
+namespace boost
+{
+
+struct source_location
+{
+private:
+
+ char const * file_;
+ char const * function_;
+ boost::uint_least32_t line_;
+ boost::uint_least32_t column_;
+
+public:
+
+ BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "" ), function_( "" ), line_( 0 ), column_( 0 )
+ {
+ }
+
+ BOOST_CONSTEXPR source_location( char const * file, boost::uint_least32_t ln, char const * function, boost::uint_least32_t col = 0 ) BOOST_NOEXCEPT: file_( file ), function_( function ), line_( ln ), column_( col )
+ {
+ }
+
+#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
+
+ BOOST_CONSTEXPR source_location( std::source_location const& loc ) BOOST_NOEXCEPT: file_( loc.file_name() ), function_( loc.function_name() ), line_( loc.line() ), column_( loc.column() )
+ {
+ }
+
+#endif
+
+ BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT
+ {
+ return file_;
+ }
+
+ BOOST_CONSTEXPR char const * function_name() const BOOST_NOEXCEPT
+ {
+ return function_;
+ }
+
+ BOOST_CONSTEXPR boost::uint_least32_t line() const BOOST_NOEXCEPT
+ {
+ return line_;
+ }
+
+ BOOST_CONSTEXPR boost::uint_least32_t column() const BOOST_NOEXCEPT
+ {
+ return column_;
+ }
+
+#if defined(BOOST_MSVC)
+# pragma warning( push )
+# pragma warning( disable: 4996 )
+#endif
+
+#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
+# define BOOST_ASSERT_SNPRINTF(buffer, format, arg) std::sprintf(buffer, format, arg)
+#else
+# define BOOST_ASSERT_SNPRINTF(buffer, format, arg) std::snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), format, arg)
+#endif
+
+ std::string to_string() const
+ {
+ unsigned long ln = line();
+
+ if( ln == 0 )
+ {
+ return "(unknown source location)";
+ }
+
+ std::string r = file_name();
+
+ char buffer[ 16 ];
+
+ BOOST_ASSERT_SNPRINTF( buffer, ":%lu", ln );
+ r += buffer;
+
+ unsigned long co = column();
+
+ if( co )
+ {
+ BOOST_ASSERT_SNPRINTF( buffer, ":%lu", co );
+ r += buffer;
+ }
+
+ char const* fn = function_name();
+
+ if( *fn != 0 )
+ {
+ r += " in function '";
+ r += fn;
+ r += '\'';
+ }
+
+ return r;
+ }
+
+#undef BOOST_ASSERT_SNPRINTF
+
+#if defined(BOOST_MSVC)
+# pragma warning( pop )
+#endif
+
+ inline friend bool operator==( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT
+ {
+ return std::strcmp( s1.file_, s2.file_ ) == 0 && std::strcmp( s1.function_, s2.function_ ) == 0 && s1.line_ == s2.line_ && s1.column_ == s2.column_;
+ }
+
+ inline friend bool operator!=( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT
+ {
+ return !( s1 == s2 );
+ }
+};
+
+template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc )
+{
+ os << loc.to_string();
+ return os;
+}
+
+} // namespace boost
+
+#if defined(BOOST_DISABLE_CURRENT_LOCATION)
+
+# define BOOST_CURRENT_LOCATION ::boost::source_location()
+
+#elif defined(BOOST_MSVC) && BOOST_MSVC >= 1926
+
+// std::source_location::current() is available in -std:c++20, but fails with consteval errors before 19.31, and doesn't produce
+// the correct result under 19.31, so prefer the built-ins
+# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN())
+
+#elif defined(BOOST_MSVC)
+
+// __LINE__ is not a constant expression under /ZI (edit and continue) for 1925 and before
+
+# define BOOST_CURRENT_LOCATION_IMPL_1(x) BOOST_CURRENT_LOCATION_IMPL_2(x)
+# define BOOST_CURRENT_LOCATION_IMPL_2(x) (x##0 / 10)
+
+# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, BOOST_CURRENT_LOCATION_IMPL_1(__LINE__), "")
+
+#elif defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && !defined(__NVCC__)
+
+// Under nvcc, __builtin_source_location is not constexpr
+// https://github.com/boostorg/assert/issues/32
+
+# define BOOST_CURRENT_LOCATION ::boost::source_location(::std::source_location::current())
+
+#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION >= 90000
+
+# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN())
+
+#elif defined(BOOST_GCC) && BOOST_GCC >= 70000
+
+// The built-ins are available in 4.8+, but are not constant expressions until 7
+# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION())
+
+#elif defined(BOOST_GCC) && BOOST_GCC >= 50000
+
+// __PRETTY_FUNCTION__ is allowed outside functions under GCC, but 4.x suffers from codegen bugs
+# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#else
+
+// __func__ macros aren't allowed outside functions, but BOOST_CURRENT_LOCATION is
+# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, "")
+
+#endif
+
+#endif // #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
diff --git a/src/boost/boost/atomic/atomic_ref.hpp b/src/boost/boost/atomic/atomic_ref.hpp
new file mode 100644
index 000000000..a28d0d7dc
--- /dev/null
+++ b/src/boost/boost/atomic/atomic_ref.hpp
@@ -0,0 +1,98 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * Copyright (c) 2020-2021 Andrey Semashev
+ */
+/*!
+ * \file atomic/atomic_ref.hpp
+ *
+ * This header contains definition of \c atomic_ref template.
+ */
+
+#ifndef BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
+#define BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+namespace atomics {
+
+//! Atomic reference to external object
+template< typename T >
+class atomic_ref :
+ public atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, false >
+{
+private:
+ typedef atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, false > base_type;
+ typedef typename base_type::value_arg_type value_arg_type;
+
+public:
+ typedef typename base_type::value_type value_type;
+
+ BOOST_STATIC_ASSERT_MSG(sizeof(value_type) > 0u, "boost::atomic_ref requires T to be a complete type");
+#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_IS_TRIVIALLY_COPYABLE)
+ BOOST_STATIC_ASSERT_MSG(atomics::detail::is_trivially_copyable< value_type >::value, "boost::atomic_ref requires T to be a trivially copyable type");
+#endif
+
+private:
+ typedef typename base_type::storage_type storage_type;
+
+public:
+ BOOST_DEFAULTED_FUNCTION(atomic_ref(atomic_ref const& that) BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL, BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL : base_type(static_cast< base_type const& >(that)) {})
+ BOOST_FORCEINLINE explicit atomic_ref(value_type& v) BOOST_NOEXCEPT : base_type(v)
+ {
+ // Check that referenced object alignment satisfies required alignment
+ BOOST_ASSERT((((atomics::detail::uintptr_t)this->m_value) & (base_type::required_alignment - 1u)) == 0u);
+ }
+
+ BOOST_FORCEINLINE value_type operator= (value_arg_type v) const BOOST_NOEXCEPT
+ {
+ this->store(v);
+ return v;
+ }
+
+ BOOST_FORCEINLINE operator value_type() const BOOST_NOEXCEPT
+ {
+ return this->load();
+ }
+
+ BOOST_DELETED_FUNCTION(atomic_ref& operator= (atomic_ref const&))
+};
+
+#if !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
+template< typename T >
+atomic_ref(T&) -> atomic_ref< T >;
+#endif // !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
+
+//! Atomic reference factory function
+template< typename T >
+BOOST_FORCEINLINE atomic_ref< T > make_atomic_ref(T& value) BOOST_NOEXCEPT
+{
+ return atomic_ref< T >(value);
+}
+
+} // namespace atomics
+
+using atomics::atomic_ref;
+using atomics::make_atomic_ref;
+
+} // namespace boost
+
+#include
+
+#endif // BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
diff --git a/src/boost/boost/atomic/capabilities.hpp b/src/boost/boost/atomic/capabilities.hpp
new file mode 100644
index 000000000..690225702
--- /dev/null
+++ b/src/boost/boost/atomic/capabilities.hpp
@@ -0,0 +1,21 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * Copyright (c) 2014 Andrey Semashev
+ */
+/*!
+ * \file atomic/capabilities.hpp
+ *
+ * This header defines feature capabilities macros.
+ */
+
+#ifndef BOOST_ATOMIC_CAPABILITIES_HPP_INCLUDED_
+#define BOOST_ATOMIC_CAPABILITIES_HPP_INCLUDED_
+
+#include
+#include
+#include