mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
Merge 3.4.0a4 release head back into trunk.
This commit is contained in:
commit
d0a7e67804
103 changed files with 4796 additions and 3930 deletions
|
@ -30,8 +30,8 @@ sampling rate or frame rate is the number of times per second the sound is
|
|||
sampled. The number of channels indicate if the audio is mono, stereo, or
|
||||
quadro. Each frame consists of one sample per channel. The sample size is the
|
||||
size in bytes of each sample. Thus a frame consists of
|
||||
*nchannels*\*\ *samplesize* bytes, and a second's worth of audio consists of
|
||||
*nchannels*\*\ *samplesize*\*\ *framerate* bytes.
|
||||
``nchannels * samplesize`` bytes, and a second's worth of audio consists of
|
||||
``nchannels * samplesize * framerate`` bytes.
|
||||
|
||||
For example, CD quality audio has a sample size of two bytes (16 bits), uses two
|
||||
channels (stereo) and has a frame rate of 44,100 frames/second. This gives a
|
||||
|
|
|
@ -374,10 +374,6 @@ or subtracting from an empty counter.
|
|||
|
||||
.. seealso::
|
||||
|
||||
* `Counter class <http://code.activestate.com/recipes/576611/>`_
|
||||
adapted for Python 2.5 and an early `Bag recipe
|
||||
<http://code.activestate.com/recipes/259174/>`_ for Python 2.4.
|
||||
|
||||
* `Bag class <http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html>`_
|
||||
in Smalltalk.
|
||||
|
||||
|
@ -920,11 +916,6 @@ and more efficient to use a simple class declaration:
|
|||
>>> class Status:
|
||||
open, pending, closed = range(3)
|
||||
|
||||
.. seealso::
|
||||
|
||||
* `Named tuple recipe <http://code.activestate.com/recipes/500261/>`_
|
||||
adapted for Python 2.4.
|
||||
|
||||
* `Recipe for named tuple abstract base class with a metaclass mix-in
|
||||
<http://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/>`_
|
||||
by Jan Kaliszewski. Besides providing an :term:`abstract base class` for
|
||||
|
@ -987,10 +978,6 @@ The :class:`OrderedDict` constructor and :meth:`update` method both accept
|
|||
keyword arguments, but their order is lost because Python's function call
|
||||
semantics pass-in keyword arguments using a regular unordered dictionary.
|
||||
|
||||
.. seealso::
|
||||
|
||||
`Equivalent OrderedDict recipe <http://code.activestate.com/recipes/576693/>`_
|
||||
that runs on Python 2.4 or later.
|
||||
|
||||
:class:`OrderedDict` Examples and Recipes
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -1909,8 +1909,8 @@ Utility functions
|
|||
|
||||
.. function:: sizeof(obj_or_type)
|
||||
|
||||
Returns the size in bytes of a ctypes type or instance memory buffer. Does the
|
||||
same as the C ``sizeof()`` function.
|
||||
Returns the size in bytes of a ctypes type or instance memory buffer.
|
||||
Does the same as the C ``sizeof`` operator.
|
||||
|
||||
|
||||
.. function:: string_at(address, size=-1)
|
||||
|
|
|
@ -27,6 +27,7 @@ tracebacks:
|
|||
* Only the filename, the function name and the line number are
|
||||
displayed. (no source code)
|
||||
* It is limited to 100 frames and 100 threads.
|
||||
* The order is reversed: the most recent call is shown first.
|
||||
|
||||
By default, the Python traceback is written to :data:`sys.stderr`. To see
|
||||
tracebacks, applications must be run in the terminal. A log file can
|
||||
|
@ -129,7 +130,7 @@ Example of a segmentation fault on Linux: ::
|
|||
>>> ctypes.string_at(0)
|
||||
Fatal Python error: Segmentation fault
|
||||
|
||||
Current thread 0x00007fb899f39700:
|
||||
Current thread 0x00007fb899f39700 (most recent call first):
|
||||
File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at
|
||||
File "<stdin>", line 1 in <module>
|
||||
Segmentation fault
|
||||
|
|
|
@ -158,10 +158,13 @@ write code that handles both IP versions correctly.
|
|||
``True`` if the address is reserved for multicast use. See
|
||||
:RFC:`3171` (for IPv4) or :RFC:`2373` (for IPv6).
|
||||
|
||||
.. attribute:: is_private
|
||||
.. attribute:: is_global
|
||||
|
||||
``True`` if the address is allocated for private networks. See
|
||||
:RFC:`1918` (for IPv4) or :RFC:`4193` (for IPv6).
|
||||
iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry
|
||||
(for IPv6).
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
.. attribute:: is_unspecified
|
||||
|
||||
|
|
|
@ -74,6 +74,27 @@ this module for those platforms.
|
|||
``setrlimit`` may also raise :exc:`error` if the underlying system call
|
||||
fails.
|
||||
|
||||
.. function:: prlimit(pid, resource[, limits])
|
||||
|
||||
Combines :func:`setrlimit` and :func:`getrlimit` in one function and
|
||||
supports to get and set the resources limits of an arbitrary process. If
|
||||
*pid* is 0, then the call applies to the current process. *resource* and
|
||||
*limits* have the same meaning as in :func:`setrlimit`, except that
|
||||
*limits* is optional.
|
||||
|
||||
When *limits* is not given the function returns the *resource* limit of the
|
||||
process *pid*. When *limits* is given the *resource* limit of the process is
|
||||
set and the former resource limit is returned.
|
||||
|
||||
Raises :exc:`ProcessLookupError` when *pid* can't be found and
|
||||
:exc:`PermissionError` when the user doesn't have ``CAP_SYS_RESOURCE`` for
|
||||
the process.
|
||||
|
||||
Availability: Linux (glibc 2.13+)
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
These symbols define resources whose consumption can be controlled using the
|
||||
:func:`setrlimit` and :func:`getrlimit` functions described below. The values of
|
||||
these symbols are exactly the constants used by C programs.
|
||||
|
@ -151,6 +172,52 @@ platform.
|
|||
The maximum area (in bytes) of address space which may be taken by the process.
|
||||
|
||||
|
||||
.. data:: RLIMIT_MSGQUEUE
|
||||
|
||||
The number of bytes that can be allocated for POSIX message queues.
|
||||
|
||||
Availability: Linux 2.6.8 or later.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. data:: RLIMIT_NICE
|
||||
|
||||
The ceiling for the process's nice level (calculated as 20 - rlim_cur).
|
||||
|
||||
Availability: Linux 2.6.12 or later.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. data:: RLIMIT_RTPRIO
|
||||
|
||||
The ceiling of the real-time priority.
|
||||
|
||||
Availability: Linux 2.6.12 or later.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. data:: RLIMIT_RTTIME
|
||||
|
||||
The time limit (in microseconds) on CPU time that a process can spend
|
||||
under real-time scheduling without making a blocking syscall.
|
||||
|
||||
Availability: Linux 2.6.25 or later.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. data:: RLIMIT_SIGPENDING
|
||||
|
||||
The number of signals which the process may queue.
|
||||
|
||||
Availability: Linux 2.6.8 or later.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
Resource Usage
|
||||
--------------
|
||||
|
||||
|
|
|
@ -35,21 +35,34 @@ or sample.
|
|||
:func:`mode` Mode (most common value) of discrete data.
|
||||
======================= =============================================
|
||||
|
||||
:func:`mean`
|
||||
~~~~~~~~~~~~
|
||||
Measures of spread
|
||||
------------------
|
||||
|
||||
The :func:`mean` function calculates the arithmetic mean, commonly known
|
||||
as the average, of its iterable argument:
|
||||
These functions calculate a measure of how much the population or sample
|
||||
tends to deviate from the typical or average values.
|
||||
|
||||
======================= =============================================
|
||||
:func:`pstdev` Population standard deviation of data.
|
||||
:func:`pvariance` Population variance of data.
|
||||
:func:`stdev` Sample standard deviation of data.
|
||||
:func:`variance` Sample variance of data.
|
||||
======================= =============================================
|
||||
|
||||
|
||||
Function details
|
||||
----------------
|
||||
|
||||
.. function:: mean(data)
|
||||
|
||||
Return the sample arithmetic mean of *data*, a sequence or iterator
|
||||
of real-valued numbers.
|
||||
Return the sample arithmetic mean of *data*, a sequence or iterator of
|
||||
real-valued numbers.
|
||||
|
||||
The arithmetic mean is the sum of the data divided by the number of
|
||||
data points. It is commonly called "the average", although it is only
|
||||
one of many different mathematical averages. It is a measure of the
|
||||
central location of the data.
|
||||
The arithmetic mean is the sum of the data divided by the number of data
|
||||
points. It is commonly called "the average", although it is only one of many
|
||||
different mathematical averages. It is a measure of the central location of
|
||||
the data.
|
||||
|
||||
If *data* is empty, :exc:`StatisticsError` will be raised.
|
||||
|
||||
Some examples of use:
|
||||
|
||||
|
@ -70,75 +83,56 @@ as the average, of its iterable argument:
|
|||
|
||||
.. note::
|
||||
|
||||
The mean is strongly effected by outliers and is not a robust
|
||||
estimator for central location: the mean is not necessarily a
|
||||
typical example of the data points. For more robust, although less
|
||||
efficient, measures of central location, see :func:`median` and
|
||||
:func:`mode`. (In this case, "efficient" refers to statistical
|
||||
efficiency rather than computational efficiency.)
|
||||
The mean is strongly affected by outliers and is not a robust estimator
|
||||
for central location: the mean is not necessarily a typical example of the
|
||||
data points. For more robust, although less efficient, measures of
|
||||
central location, see :func:`median` and :func:`mode`. (In this case,
|
||||
"efficient" refers to statistical efficiency rather than computational
|
||||
efficiency.)
|
||||
|
||||
The sample mean gives an unbiased estimate of the true population
|
||||
mean, which means that, taken on average over all the possible
|
||||
samples, ``mean(sample)`` converges on the true mean of the entire
|
||||
population. If *data* represents the entire population rather than
|
||||
a sample, then ``mean(data)`` is equivalent to calculating the true
|
||||
population mean μ.
|
||||
The sample mean gives an unbiased estimate of the true population mean,
|
||||
which means that, taken on average over all the possible samples,
|
||||
``mean(sample)`` converges on the true mean of the entire population. If
|
||||
*data* represents the entire population rather than a sample, then
|
||||
``mean(data)`` is equivalent to calculating the true population mean μ.
|
||||
|
||||
If ``data`` is empty, :exc:`StatisticsError` will be raised.
|
||||
|
||||
:func:`median`
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`median` function calculates the median, or middle, data point,
|
||||
using the common "mean of middle two" method.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:func:`median_low`
|
||||
|
||||
:func:`median_high`
|
||||
|
||||
:func:`median_grouped`
|
||||
|
||||
.. function:: median(data)
|
||||
|
||||
Return the median (middle value) of numeric data.
|
||||
Return the median (middle value) of numeric data, using the common "mean of
|
||||
middle two" method. If *data* is empty, :exc:`StatisticsError` is raised.
|
||||
|
||||
The median is a robust measure of central location, and is less affected
|
||||
by the presence of outliers in your data. When the number of data points
|
||||
is odd, the middle data point is returned:
|
||||
The median is a robust measure of central location, and is less affected by
|
||||
the presence of outliers in your data. When the number of data points is
|
||||
odd, the middle data point is returned:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> median([1, 3, 5])
|
||||
3
|
||||
|
||||
When the number of data points is even, the median is interpolated by
|
||||
taking the average of the two middle values:
|
||||
When the number of data points is even, the median is interpolated by taking
|
||||
the average of the two middle values:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> median([1, 3, 5, 7])
|
||||
4.0
|
||||
|
||||
This is suited for when your data is discrete, and you don't mind that
|
||||
the median may not be an actual data point.
|
||||
This is suited for when your data is discrete, and you don't mind that the
|
||||
median may not be an actual data point.
|
||||
|
||||
If data is empty, :exc:`StatisticsError` is raised.
|
||||
.. seealso:: :func:`median_low`, :func:`median_high`, :func:`median_grouped`
|
||||
|
||||
:func:`median_low`
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`median_low` function calculates the low median without
|
||||
interpolation.
|
||||
|
||||
.. function:: median_low(data)
|
||||
|
||||
Return the low median of numeric data.
|
||||
Return the low median of numeric data. If *data* is empty,
|
||||
:exc:`StatisticsError` is raised.
|
||||
|
||||
The low median is always a member of the data set. When the number
|
||||
of data points is odd, the middle value is returned. When it is
|
||||
even, the smaller of the two middle values is returned.
|
||||
The low median is always a member of the data set. When the number of data
|
||||
points is odd, the middle value is returned. When it is even, the smaller of
|
||||
the two middle values is returned.
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
@ -147,24 +141,18 @@ interpolation.
|
|||
>>> median_low([1, 3, 5, 7])
|
||||
3
|
||||
|
||||
Use the low median when your data are discrete and you prefer the median
|
||||
to be an actual data point rather than interpolated.
|
||||
Use the low median when your data are discrete and you prefer the median to
|
||||
be an actual data point rather than interpolated.
|
||||
|
||||
If data is empty, :exc:`StatisticsError` is raised.
|
||||
|
||||
:func:`median_high`
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`median_high` function calculates the high median without
|
||||
interpolation.
|
||||
|
||||
.. function:: median_high(data)
|
||||
|
||||
Return the high median of data.
|
||||
Return the high median of data. If *data* is empty, :exc:`StatisticsError`
|
||||
is raised.
|
||||
|
||||
The high median is always a member of the data set. When the number of
|
||||
data points is odd, the middle value is returned. When it is even, the
|
||||
larger of the two middle values is returned.
|
||||
The high median is always a member of the data set. When the number of data
|
||||
points is odd, the middle value is returned. When it is even, the larger of
|
||||
the two middle values is returned.
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
@ -173,41 +161,34 @@ interpolation.
|
|||
>>> median_high([1, 3, 5, 7])
|
||||
5
|
||||
|
||||
Use the high median when your data are discrete and you prefer the median
|
||||
to be an actual data point rather than interpolated.
|
||||
Use the high median when your data are discrete and you prefer the median to
|
||||
be an actual data point rather than interpolated.
|
||||
|
||||
If data is empty, :exc:`StatisticsError` is raised.
|
||||
|
||||
:func:`median_grouped`
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
.. function:: median_grouped(data, interval=1)
|
||||
|
||||
The :func:`median_grouped` function calculates the median of grouped data
|
||||
as the 50th percentile, using interpolation.
|
||||
|
||||
.. function:: median_grouped(data [, interval])
|
||||
|
||||
Return the median of grouped continuous data, calculated as the
|
||||
50th percentile.
|
||||
Return the median of grouped continuous data, calculated as the 50th
|
||||
percentile, using interpolation. If *data* is empty, :exc:`StatisticsError`
|
||||
is raised.
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> median_grouped([52, 52, 53, 54])
|
||||
52.5
|
||||
|
||||
In the following example, the data are rounded, so that each value
|
||||
represents the midpoint of data classes, e.g. 1 is the midpoint of the
|
||||
class 0.5-1.5, 2 is the midpoint of 1.5-2.5, 3 is the midpoint of
|
||||
2.5-3.5, etc. With the data given, the middle value falls somewhere in
|
||||
the class 3.5-4.5, and interpolation is used to estimate it:
|
||||
In the following example, the data are rounded, so that each value represents
|
||||
the midpoint of data classes, e.g. 1 is the midpoint of the class 0.5-1.5, 2
|
||||
is the midpoint of 1.5-2.5, 3 is the midpoint of 2.5-3.5, etc. With the data
|
||||
given, the middle value falls somewhere in the class 3.5-4.5, and
|
||||
interpolation is used to estimate it:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> median_grouped([1, 2, 2, 3, 4, 4, 4, 4, 4, 5])
|
||||
3.7
|
||||
|
||||
Optional argument ``interval`` represents the class interval, and
|
||||
defaults to 1. Changing the class interval naturally will change the
|
||||
interpolation:
|
||||
Optional argument *interval* represents the class interval, and defaults
|
||||
to 1. Changing the class interval naturally will change the interpolation:
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
@ -217,36 +198,34 @@ as the 50th percentile, using interpolation.
|
|||
3.5
|
||||
|
||||
This function does not check whether the data points are at least
|
||||
``interval`` apart.
|
||||
*interval* apart.
|
||||
|
||||
.. impl-detail::
|
||||
|
||||
Under some circumstances, :func:`median_grouped` may coerce data
|
||||
points to floats. This behaviour is likely to change in the future.
|
||||
Under some circumstances, :func:`median_grouped` may coerce data points to
|
||||
floats. This behaviour is likely to change in the future.
|
||||
|
||||
.. seealso::
|
||||
|
||||
* "Statistics for the Behavioral Sciences", Frederick J Gravetter
|
||||
and Larry B Wallnau (8th Edition).
|
||||
* "Statistics for the Behavioral Sciences", Frederick J Gravetter and
|
||||
Larry B Wallnau (8th Edition).
|
||||
|
||||
* Calculating the `median <http://www.ualberta.ca/~opscan/median.html>`_.
|
||||
|
||||
* The `SSMEDIAN <https://projects.gnome.org/gnumeric/doc/gnumeric-function-SSMEDIAN.shtml>`_
|
||||
function in the Gnome Gnumeric spreadsheet, including
|
||||
`this discussion <https://mail.gnome.org/archives/gnumeric-list/2011-April/msg00018.html>`_.
|
||||
* The `SSMEDIAN
|
||||
<https://projects.gnome.org/gnumeric/doc/gnumeric-function-SSMEDIAN.shtml>`_
|
||||
function in the Gnome Gnumeric spreadsheet, including `this discussion
|
||||
<https://mail.gnome.org/archives/gnumeric-list/2011-April/msg00018.html>`_.
|
||||
|
||||
If data is empty, :exc:`StatisticsError` is raised.
|
||||
|
||||
:func:`mode`
|
||||
~~~~~~~~~~~~
|
||||
|
||||
The :func:`mode` function calculates the mode, or most common element, of
|
||||
discrete or nominal data. The mode (when it exists) is the most typical
|
||||
value, and is a robust measure of central location.
|
||||
|
||||
.. function:: mode(data)
|
||||
|
||||
Return the most common data point from discrete or nominal data.
|
||||
Return the most common data point from discrete or nominal *data*. The mode
|
||||
(when it exists) is the most typical value, and is a robust measure of
|
||||
central location.
|
||||
|
||||
If *data* is empty, or if there is not exactly one most common value,
|
||||
:exc:`StatisticsError` is raised.
|
||||
|
||||
``mode`` assumes discrete data, and returns a single value. This is the
|
||||
standard treatment of the mode as commonly taught in schools:
|
||||
|
@ -264,60 +243,35 @@ value, and is a robust measure of central location.
|
|||
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
|
||||
'red'
|
||||
|
||||
If data is empty, or if there is not exactly one most common value,
|
||||
:exc:`StatisticsError` is raised.
|
||||
|
||||
Measures of spread
|
||||
------------------
|
||||
.. function:: pstdev(data, mu=None)
|
||||
|
||||
These functions calculate a measure of how much the population or sample
|
||||
tends to deviate from the typical or average values.
|
||||
|
||||
======================= =============================================
|
||||
:func:`pstdev` Population standard deviation of data.
|
||||
:func:`pvariance` Population variance of data.
|
||||
:func:`stdev` Sample standard deviation of data.
|
||||
:func:`variance` Sample variance of data.
|
||||
======================= =============================================
|
||||
|
||||
:func:`pstdev`
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`pstdev` function calculates the standard deviation of a
|
||||
population. The standard deviation is equivalent to the square root of
|
||||
the variance.
|
||||
|
||||
.. function:: pstdev(data [, mu])
|
||||
|
||||
Return the square root of the population variance. See :func:`pvariance`
|
||||
for arguments and other details.
|
||||
Return the population standard deviation (the square root of the population
|
||||
variance). See :func:`pvariance` for arguments and other details.
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])
|
||||
0.986893273527251
|
||||
|
||||
:func:`pvariance`
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`pvariance` function calculates the variance of a population.
|
||||
Variance, or second moment about the mean, is a measure of the variability
|
||||
(spread or dispersion) of data. A large variance indicates that the data is
|
||||
spread out; a small variance indicates it is clustered closely around the
|
||||
mean.
|
||||
.. function:: pvariance(data, mu=None)
|
||||
|
||||
.. function:: pvariance(data [, mu])
|
||||
Return the population variance of *data*, a non-empty iterable of real-valued
|
||||
numbers. Variance, or second moment about the mean, is a measure of the
|
||||
variability (spread or dispersion) of data. A large variance indicates that
|
||||
the data is spread out; a small variance indicates it is clustered closely
|
||||
around the mean.
|
||||
|
||||
Return the population variance of *data*, a non-empty iterable of
|
||||
real-valued numbers.
|
||||
|
||||
If the optional second argument *mu* is given, it should be the mean
|
||||
of *data*. If it is missing or None (the default), the mean is
|
||||
If the optional second argument *mu* is given, it should be the mean of
|
||||
*data*. If it is missing or ``None`` (the default), the mean is
|
||||
automatically calculated.
|
||||
|
||||
Use this function to calculate the variance from the entire population.
|
||||
To estimate the variance from a sample, the :func:`variance` function is
|
||||
usually a better choice.
|
||||
Use this function to calculate the variance from the entire population. To
|
||||
estimate the variance from a sample, the :func:`variance` function is usually
|
||||
a better choice.
|
||||
|
||||
Raises :exc:`StatisticsError` if *data* is empty.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -327,8 +281,8 @@ mean.
|
|||
>>> pvariance(data)
|
||||
1.25
|
||||
|
||||
If you have already calculated the mean of your data, you can pass
|
||||
it as the optional second argument *mu* to avoid recalculation:
|
||||
If you have already calculated the mean of your data, you can pass it as the
|
||||
optional second argument *mu* to avoid recalculation:
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
@ -336,9 +290,9 @@ mean.
|
|||
>>> pvariance(data, mu)
|
||||
1.25
|
||||
|
||||
This function does not attempt to verify that you have passed the actual
|
||||
mean as *mu*. Using arbitrary values for *mu* may lead to invalid or
|
||||
impossible results.
|
||||
This function does not attempt to verify that you have passed the actual mean
|
||||
as *mu*. Using arbitrary values for *mu* may lead to invalid or impossible
|
||||
results.
|
||||
|
||||
Decimals and Fractions are supported:
|
||||
|
||||
|
@ -354,53 +308,44 @@ mean.
|
|||
|
||||
.. note::
|
||||
|
||||
When called with the entire population, this gives the population
|
||||
variance σ². When called on a sample instead, this is the biased
|
||||
sample variance s², also known as variance with N degrees of freedom.
|
||||
When called with the entire population, this gives the population variance
|
||||
σ². When called on a sample instead, this is the biased sample variance
|
||||
s², also known as variance with N degrees of freedom.
|
||||
|
||||
If you somehow know the true population mean μ, you may use this
|
||||
function to calculate the variance of a sample, giving the known
|
||||
population mean as the second argument. Provided the data points are
|
||||
representative (e.g. independent and identically distributed), the
|
||||
result will be an unbiased estimate of the population variance.
|
||||
If you somehow know the true population mean μ, you may use this function
|
||||
to calculate the variance of a sample, giving the known population mean as
|
||||
the second argument. Provided the data points are representative
|
||||
(e.g. independent and identically distributed), the result will be an
|
||||
unbiased estimate of the population variance.
|
||||
|
||||
Raises :exc:`StatisticsError` if *data* is empty.
|
||||
|
||||
:func:`stdev`
|
||||
~~~~~~~~~~~~~~
|
||||
.. function:: stdev(data, xbar=None)
|
||||
|
||||
The :func:`stdev` function calculates the standard deviation of a sample.
|
||||
The standard deviation is equivalent to the square root of the variance.
|
||||
|
||||
.. function:: stdev(data [, xbar])
|
||||
|
||||
Return the square root of the sample variance. See :func:`variance` for
|
||||
arguments and other details.
|
||||
Return the sample standard deviation (the square root of the sample
|
||||
variance). See :func:`variance` for arguments and other details.
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])
|
||||
1.0810874155219827
|
||||
|
||||
:func:`variance`
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`variance` function calculates the variance of a sample. Variance,
|
||||
or second moment about the mean, is a measure of the variability (spread or
|
||||
dispersion) of data. A large variance indicates that the data is spread out;
|
||||
a small variance indicates it is clustered closely around the mean.
|
||||
.. function:: variance(data, xbar=None)
|
||||
|
||||
.. function:: variance(data [, xbar])
|
||||
Return the sample variance of *data*, an iterable of at least two real-valued
|
||||
numbers. Variance, or second moment about the mean, is a measure of the
|
||||
variability (spread or dispersion) of data. A large variance indicates that
|
||||
the data is spread out; a small variance indicates it is clustered closely
|
||||
around the mean.
|
||||
|
||||
Return the sample variance of *data*, an iterable of at least two
|
||||
real-valued numbers.
|
||||
|
||||
If the optional second argument *xbar* is given, it should be the mean
|
||||
of *data*. If it is missing or None (the default), the mean is
|
||||
If the optional second argument *xbar* is given, it should be the mean of
|
||||
*data*. If it is missing or ``None`` (the default), the mean is
|
||||
automatically calculated.
|
||||
|
||||
Use this function when your data is a sample from a population. To
|
||||
calculate the variance from the entire population, see :func:`pvariance`.
|
||||
Use this function when your data is a sample from a population. To calculate
|
||||
the variance from the entire population, see :func:`pvariance`.
|
||||
|
||||
Raises :exc:`StatisticsError` if *data* has fewer than two values.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -410,8 +355,8 @@ a small variance indicates it is clustered closely around the mean.
|
|||
>>> variance(data)
|
||||
1.3720238095238095
|
||||
|
||||
If you have already calculated the mean of your data, you can pass
|
||||
it as the optional second argument *xbar* to avoid recalculation:
|
||||
If you have already calculated the mean of your data, you can pass it as the
|
||||
optional second argument *xbar* to avoid recalculation:
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
@ -419,8 +364,8 @@ a small variance indicates it is clustered closely around the mean.
|
|||
>>> variance(data, m)
|
||||
1.3720238095238095
|
||||
|
||||
This function does not attempt to verify that you have passed the actual
|
||||
mean as *xbar*. Using arbitrary values for *xbar* can lead to invalid or
|
||||
This function does not attempt to verify that you have passed the actual mean
|
||||
as *xbar*. Using arbitrary values for *xbar* can lead to invalid or
|
||||
impossible results.
|
||||
|
||||
Decimal and Fraction values are supported:
|
||||
|
@ -437,26 +382,23 @@ a small variance indicates it is clustered closely around the mean.
|
|||
|
||||
.. note::
|
||||
|
||||
This is the sample variance s² with Bessel's correction, also known
|
||||
as variance with N-1 degrees of freedom. Provided that the data
|
||||
points are representative (e.g. independent and identically
|
||||
distributed), the result should be an unbiased estimate of the true
|
||||
population variance.
|
||||
This is the sample variance s² with Bessel's correction, also known as
|
||||
variance with N-1 degrees of freedom. Provided that the data points are
|
||||
representative (e.g. independent and identically distributed), the result
|
||||
should be an unbiased estimate of the true population variance.
|
||||
|
||||
If you somehow know the actual population mean μ you should pass it
|
||||
to the :func:`pvariance` function as the *mu* parameter to get
|
||||
the variance of a sample.
|
||||
|
||||
Raises :exc:`StatisticsError` if *data* has fewer than two values.
|
||||
If you somehow know the actual population mean μ you should pass it to the
|
||||
:func:`pvariance` function as the *mu* parameter to get the variance of a
|
||||
sample.
|
||||
|
||||
Exceptions
|
||||
----------
|
||||
|
||||
A single exception is defined:
|
||||
|
||||
:exc:`StatisticsError`
|
||||
.. exception:: StatisticsError
|
||||
|
||||
Subclass of :exc:`ValueError` for statistics-related exceptions.
|
||||
Subclass of :exc:`ValueError` for statistics-related exceptions.
|
||||
|
||||
..
|
||||
# This modelines must appear within the last ten lines of the file.
|
||||
|
|
|
@ -293,18 +293,18 @@ The general form of a *standard format specifier* is:
|
|||
|
||||
.. productionlist:: sf
|
||||
format_spec: [[`fill`]`align`][`sign`][#][0][`width`][,][.`precision`][`type`]
|
||||
fill: <a character other than '{' or '}'>
|
||||
fill: <any character>
|
||||
align: "<" | ">" | "=" | "^"
|
||||
sign: "+" | "-" | " "
|
||||
width: `integer`
|
||||
precision: `integer`
|
||||
type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
|
||||
|
||||
The *fill* character can be any character other than '{' or '}'. The presence
|
||||
of a fill character is signaled by the character following it, which must be
|
||||
one of the alignment options. If the second character of *format_spec* is not
|
||||
a valid alignment option, then it is assumed that both the fill character and
|
||||
the alignment option are absent.
|
||||
If a valid *align* value is specified, it can be preceeded by a *fill*
|
||||
character that can be any character and defaults to a space if omitted.
|
||||
Note that it is not possible to use ``{`` and ``}`` as *fill* char while
|
||||
using the :meth:`str.format` method; this limitation however doesn't
|
||||
affect the :func:`format` function.
|
||||
|
||||
The meaning of the various alignment options is as follows:
|
||||
|
||||
|
|
|
@ -382,7 +382,7 @@ The :class:`PyZipFile` constructor takes the same parameters as the
|
|||
|
||||
Instances have one method in addition to those of :class:`ZipFile` objects:
|
||||
|
||||
.. method:: PyZipFile.writepy(pathname, basename='')
|
||||
.. method:: PyZipFile.writepy(pathname, basename='', filterfunc=None)
|
||||
|
||||
Search for files :file:`\*.py` and add the corresponding file to the
|
||||
archive.
|
||||
|
@ -404,7 +404,10 @@ The :class:`PyZipFile` constructor takes the same parameters as the
|
|||
package directory, then all :file:`\*.py[co]` are added under the package
|
||||
name as a file path, and if any subdirectories are package directories,
|
||||
all of these are added recursively. *basename* is intended for internal
|
||||
use only. The :meth:`writepy` method makes archives with file names like
|
||||
use only. When *filterfunc(pathname)* is given, it will be called for every
|
||||
invocation. When it returns a False value, that path and its subpaths will
|
||||
be ignored.
|
||||
The :meth:`writepy` method makes archives with file names like
|
||||
this::
|
||||
|
||||
string.pyc # Top level name
|
||||
|
@ -413,6 +416,9 @@ The :class:`PyZipFile` constructor takes the same parameters as the
|
|||
test/bogus/__init__.pyc # Subpackage directory
|
||||
test/bogus/myfile.pyc # Submodule test.bogus.myfile
|
||||
|
||||
.. versionadded:: 3.4
|
||||
The *filterfunc* parameter.
|
||||
|
||||
|
||||
.. _zipinfo-objects:
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ intent of code that deliberately suppresses exceptions from a single
|
|||
statement. (Contributed by Raymond Hettinger in :issue:`15806` and
|
||||
Zero Piraeus in :issue:`19266`)
|
||||
|
||||
The new :class:`contextlib.redirect_stdio` context manager makes it easier
|
||||
The new :func:`contextlib.redirect_stdout` context manager makes it easier
|
||||
for utility scripts to handle inflexible APIs that don't provide any
|
||||
options to retrieve their output as a string or direct it to somewhere
|
||||
other than :data:`sys.stdout`. In conjunction with :class:`io.StringIO`,
|
||||
|
@ -434,10 +434,16 @@ POP3 server.
|
|||
pprint
|
||||
------
|
||||
|
||||
The :mod::`pprint` module now supports *compact* mode for formatting long
|
||||
The :mod:`pprint` module now supports *compact* mode for formatting long
|
||||
sequences (:issue:`19132`).
|
||||
|
||||
|
||||
resource
|
||||
--------
|
||||
|
||||
New :func:`resource.prlimit` function and Linux specific constants.
|
||||
(Contributed by Christian Heimes in :issue:`16595` and :issue:`19324`.)
|
||||
|
||||
smtplib
|
||||
-------
|
||||
|
||||
|
@ -564,6 +570,16 @@ Add an event-driven parser for non-blocking applications,
|
|||
|
||||
(Contributed by Antoine Pitrou in :issue:`17741`.)
|
||||
|
||||
|
||||
zipfile.PyZipfile
|
||||
-----------------
|
||||
|
||||
Add a filter function to ignore some packages (tests for instance),
|
||||
:meth:`~zipfile.PyZipFile.writepy`.
|
||||
|
||||
(Contributed by Christian Tismer in :issue:`19274`.)
|
||||
|
||||
|
||||
Other improvements
|
||||
==================
|
||||
|
||||
|
@ -597,7 +613,7 @@ Major performance enhancements have been added:
|
|||
LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
|
||||
linear probing entirely.
|
||||
|
||||
(Contributed by Raymond Hettinger in :issue"`18771`.)
|
||||
(Contributed by Raymond Hettinger in :issue:`18771`.)
|
||||
|
||||
* The interpreter starts about 30% faster. A couple of measures lead to the
|
||||
speedup. The interpreter loads fewer modules on startup, e.g. the :mod:`re`,
|
||||
|
|
|
@ -126,6 +126,7 @@ def run_test_server(*, host='127.0.0.1', port=0, use_ssl=False):
|
|||
yield httpd
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
server_thread.join()
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import collections
|
||||
import errno
|
||||
import fcntl
|
||||
import functools
|
||||
import os
|
||||
import signal
|
||||
import socket
|
||||
|
@ -167,20 +166,26 @@ class SelectorEventLoop(selector_events.BaseSelectorEventLoop):
|
|||
|
||||
def _sig_chld(self):
|
||||
try:
|
||||
# Because of signal coalescing, we must keep calling waitpid() as
|
||||
# long as we're able to reap a child.
|
||||
while True:
|
||||
try:
|
||||
pid, status = os.waitpid(0, os.WNOHANG)
|
||||
pid, status = os.waitpid(-1, os.WNOHANG)
|
||||
except ChildProcessError:
|
||||
return
|
||||
break # No more child processes exist.
|
||||
if pid == 0:
|
||||
self.call_soon(self._sig_chld)
|
||||
return
|
||||
break # All remaining child processes are still alive.
|
||||
elif os.WIFSIGNALED(status):
|
||||
# A child process died because of a signal.
|
||||
returncode = -os.WTERMSIG(status)
|
||||
elif os.WIFEXITED(status):
|
||||
# A child process exited (e.g. sys.exit()).
|
||||
returncode = os.WEXITSTATUS(status)
|
||||
else:
|
||||
self.call_soon(self._sig_chld)
|
||||
return
|
||||
# A child exited, but we don't understand its status.
|
||||
# This shouldn't happen, but if it does, let's just
|
||||
# return that status; perhaps that helps debug it.
|
||||
returncode = status
|
||||
transp = self._subprocesses.get(pid)
|
||||
if transp is not None:
|
||||
transp._process_exited(returncode)
|
||||
|
@ -208,6 +213,9 @@ class _UnixReadPipeTransport(transports.ReadTransport):
|
|||
self._loop = loop
|
||||
self._pipe = pipe
|
||||
self._fileno = pipe.fileno()
|
||||
mode = os.fstat(self._fileno).st_mode
|
||||
if not (stat.S_ISFIFO(mode) or stat.S_ISSOCK(mode)):
|
||||
raise ValueError("Pipe transport is for pipes/sockets only.")
|
||||
_set_nonblocking(self._fileno)
|
||||
self._protocol = protocol
|
||||
self._closing = False
|
||||
|
@ -270,13 +278,21 @@ class _UnixWritePipeTransport(transports.WriteTransport):
|
|||
self._loop = loop
|
||||
self._pipe = pipe
|
||||
self._fileno = pipe.fileno()
|
||||
if not stat.S_ISFIFO(os.fstat(self._fileno).st_mode):
|
||||
raise ValueError("Pipe transport is for pipes only.")
|
||||
mode = os.fstat(self._fileno).st_mode
|
||||
is_socket = stat.S_ISSOCK(mode)
|
||||
is_pipe = stat.S_ISFIFO(mode)
|
||||
if not (is_socket or is_pipe):
|
||||
raise ValueError("Pipe transport is for pipes/sockets only.")
|
||||
_set_nonblocking(self._fileno)
|
||||
self._protocol = protocol
|
||||
self._buffer = []
|
||||
self._conn_lost = 0
|
||||
self._closing = False # Set when close() or write_eof() called.
|
||||
|
||||
# On AIX, the reader trick only works for sockets.
|
||||
# On other platforms it works for pipes and sockets.
|
||||
# (Exception: OS X 10.4? Issue #19294.)
|
||||
if is_socket or not sys.platform.startswith("aix"):
|
||||
self._loop.add_reader(self._fileno, self._read_ready)
|
||||
|
||||
self._loop.call_soon(self._protocol.connection_made, self)
|
||||
|
@ -284,7 +300,7 @@ class _UnixWritePipeTransport(transports.WriteTransport):
|
|||
self._loop.call_soon(waiter.set_result, None)
|
||||
|
||||
def _read_ready(self):
|
||||
# pipe was closed by peer
|
||||
# Pipe was closed by peer.
|
||||
self._close()
|
||||
|
||||
def write(self, data):
|
||||
|
@ -430,8 +446,15 @@ class _UnixSubprocessTransport(transports.SubprocessTransport):
|
|||
self._loop = loop
|
||||
|
||||
self._pipes = {}
|
||||
stdin_w = None
|
||||
if stdin == subprocess.PIPE:
|
||||
self._pipes[STDIN] = None
|
||||
# Use a socket pair for stdin, since not all platforms
|
||||
# support selecting read events on the write end of a
|
||||
# socket (which we use in order to detect closing of the
|
||||
# other end). Notably this is needed on AIX, and works
|
||||
# just fine on other platforms.
|
||||
stdin, stdin_w = self._loop._socketpair()
|
||||
if stdout == subprocess.PIPE:
|
||||
self._pipes[STDOUT] = None
|
||||
if stderr == subprocess.PIPE:
|
||||
|
@ -443,6 +466,9 @@ class _UnixSubprocessTransport(transports.SubprocessTransport):
|
|||
self._proc = subprocess.Popen(
|
||||
args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr,
|
||||
universal_newlines=False, bufsize=bufsize, **kwargs)
|
||||
if stdin_w is not None:
|
||||
stdin.close()
|
||||
self._proc.stdin = open(stdin_w.detach(), 'rb', buffering=bufsize)
|
||||
self._extra['subprocess'] = self._proc
|
||||
|
||||
def close(self):
|
||||
|
@ -478,18 +504,15 @@ class _UnixSubprocessTransport(transports.SubprocessTransport):
|
|||
loop = self._loop
|
||||
if proc.stdin is not None:
|
||||
transp, proto = yield from loop.connect_write_pipe(
|
||||
functools.partial(
|
||||
_UnixWriteSubprocessPipeProto, self, STDIN),
|
||||
lambda: _UnixWriteSubprocessPipeProto(self, STDIN),
|
||||
proc.stdin)
|
||||
if proc.stdout is not None:
|
||||
transp, proto = yield from loop.connect_read_pipe(
|
||||
functools.partial(
|
||||
_UnixReadSubprocessPipeProto, self, STDOUT),
|
||||
lambda: _UnixReadSubprocessPipeProto(self, STDOUT),
|
||||
proc.stdout)
|
||||
if proc.stderr is not None:
|
||||
transp, proto = yield from loop.connect_read_pipe(
|
||||
functools.partial(
|
||||
_UnixReadSubprocessPipeProto, self, STDERR),
|
||||
lambda: _UnixReadSubprocessPipeProto(self, STDERR),
|
||||
proc.stderr)
|
||||
if not self._pipes:
|
||||
self._try_connected()
|
||||
|
|
|
@ -50,6 +50,8 @@ MSG_OOB = 0x1 # Process data out of band
|
|||
|
||||
# The standard FTP server control port
|
||||
FTP_PORT = 21
|
||||
# The sizehint parameter passed to readline() calls
|
||||
MAXLINE = 8192
|
||||
|
||||
|
||||
# Exception raised when an error or invalid response is received
|
||||
|
@ -97,6 +99,7 @@ class FTP:
|
|||
debugging = 0
|
||||
host = ''
|
||||
port = FTP_PORT
|
||||
maxline = MAXLINE
|
||||
sock = None
|
||||
file = None
|
||||
welcome = None
|
||||
|
@ -197,7 +200,9 @@ class FTP:
|
|||
# Internal: return one line from the server, stripping CRLF.
|
||||
# Raise EOFError if the connection is closed
|
||||
def getline(self):
|
||||
line = self.file.readline()
|
||||
line = self.file.readline(self.maxline + 1)
|
||||
if len(line) > self.maxline:
|
||||
raise Error("got more than %d bytes" % self.maxline)
|
||||
if self.debugging > 1:
|
||||
print('*get*', self.sanitize(line))
|
||||
if not line:
|
||||
|
@ -463,7 +468,9 @@ class FTP:
|
|||
with self.transfercmd(cmd) as conn, \
|
||||
conn.makefile('r', encoding=self.encoding) as fp:
|
||||
while 1:
|
||||
line = fp.readline()
|
||||
line = fp.readline(self.maxline + 1)
|
||||
if len(line) > self.maxline:
|
||||
raise Error("got more than %d bytes" % self.maxline)
|
||||
if self.debugging > 2:
|
||||
print('*retr*', repr(line))
|
||||
if not line:
|
||||
|
@ -522,7 +529,9 @@ class FTP:
|
|||
self.voidcmd('TYPE A')
|
||||
with self.transfercmd(cmd) as conn:
|
||||
while 1:
|
||||
buf = fp.readline()
|
||||
buf = fp.readline(self.maxline + 1)
|
||||
if len(buf) > self.maxline:
|
||||
raise Error("got more than %d bytes" % self.maxline)
|
||||
if not buf:
|
||||
break
|
||||
if buf[-2:] != B_CRLF:
|
||||
|
|
|
@ -64,43 +64,42 @@ __all__ = __always_supported + ('new', 'algorithms_guaranteed',
|
|||
'algorithms_available', 'pbkdf2_hmac')
|
||||
|
||||
|
||||
__builtin_constructor_cache = {}
|
||||
|
||||
def __get_builtin_constructor(name):
|
||||
cache = __builtin_constructor_cache
|
||||
constructor = cache.get(name)
|
||||
if constructor is not None:
|
||||
return constructor
|
||||
try:
|
||||
if name in ('SHA1', 'sha1'):
|
||||
import _sha1
|
||||
return _sha1.sha1
|
||||
cache['SHA1'] = cache['sha1'] = _sha1.sha1
|
||||
elif name in ('MD5', 'md5'):
|
||||
import _md5
|
||||
return _md5.md5
|
||||
cache['MD5'] = cache['md5'] = _md5.md5
|
||||
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
|
||||
import _sha256
|
||||
bs = name[3:]
|
||||
if bs == '256':
|
||||
return _sha256.sha256
|
||||
elif bs == '224':
|
||||
return _sha256.sha224
|
||||
cache['SHA224'] = cache['sha224'] = _sha256.sha224
|
||||
cache['SHA256'] = cache['sha256'] = _sha256.sha256
|
||||
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
|
||||
import _sha512
|
||||
bs = name[3:]
|
||||
if bs == '512':
|
||||
return _sha512.sha512
|
||||
elif bs == '384':
|
||||
return _sha512.sha384
|
||||
cache['SHA384'] = cache['sha384'] = _sha512.sha384
|
||||
cache['SHA512'] = cache['sha512'] = _sha512.sha512
|
||||
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
|
||||
'SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512'}:
|
||||
import _sha3
|
||||
bs = name[5:]
|
||||
if bs == '224':
|
||||
return _sha3.sha3_224
|
||||
elif bs == '256':
|
||||
return _sha3.sha3_256
|
||||
elif bs == '384':
|
||||
return _sha3.sha3_384
|
||||
elif bs == '512':
|
||||
return _sha3.sha3_512
|
||||
cache['SHA3_224'] = cache['sha3_224'] = _sha3.sha3_224
|
||||
cache['SHA3_256'] = cache['sha3_256'] = _sha3.sha3_256
|
||||
cache['SHA3_384'] = cache['sha3_384'] = _sha3.sha3_384
|
||||
cache['SHA3_512'] = cache['sha3_512'] = _sha3.sha3_512
|
||||
except ImportError:
|
||||
pass # no extension module, this hash is unsupported.
|
||||
|
||||
constructor = cache.get(name)
|
||||
if constructor is not None:
|
||||
return constructor
|
||||
|
||||
raise ValueError('unsupported hash type ' + name)
|
||||
|
||||
|
||||
|
|
|
@ -370,12 +370,13 @@ def _call_with_frames_removed(f, *args, **kwds):
|
|||
# Python 3.4a1 3270 (various tweaks to the __class__ closure)
|
||||
# Python 3.4a1 3280 (remove implicit class argument)
|
||||
# Python 3.4a4 3290 (changes to __qualname__ computation)
|
||||
# Python 3.4a4 3300 (more changes to __qualname__ computation)
|
||||
#
|
||||
# MAGIC must change whenever the bytecode emitted by the compiler may no
|
||||
# longer be understood by older implementations of the eval loop (usually
|
||||
# due to the addition of new opcodes).
|
||||
|
||||
MAGIC_NUMBER = (3290).to_bytes(2, 'little') + b'\r\n'
|
||||
MAGIC_NUMBER = (3300).to_bytes(2, 'little') + b'\r\n'
|
||||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
|
||||
|
||||
_PYCACHE = '__pycache__'
|
||||
|
|
|
@ -269,9 +269,9 @@ def getmembers(object, predicate=None):
|
|||
results = []
|
||||
processed = set()
|
||||
names = dir(object)
|
||||
# add any virtual attributes to the list of names if object is a class
|
||||
# :dd any DynamicClassAttributes to the list of names if object is a class;
|
||||
# this may result in duplicate entries if, for example, a virtual
|
||||
# attribute with the same name as a member property exists
|
||||
# attribute with the same name as a DynamicClassAttribute exists
|
||||
try:
|
||||
for base in object.__bases__:
|
||||
for k, v in base.__dict__.items():
|
||||
|
@ -329,79 +329,88 @@ def classify_class_attrs(cls):
|
|||
|
||||
If one of the items in dir(cls) is stored in the metaclass it will now
|
||||
be discovered and not have None be listed as the class in which it was
|
||||
defined.
|
||||
defined. Any items whose home class cannot be discovered are skipped.
|
||||
"""
|
||||
|
||||
mro = getmro(cls)
|
||||
metamro = getmro(type(cls)) # for attributes stored in the metaclass
|
||||
metamro = tuple([cls for cls in metamro if cls not in (type, object)])
|
||||
possible_bases = (cls,) + mro + metamro
|
||||
class_bases = (cls,) + mro
|
||||
all_bases = class_bases + metamro
|
||||
names = dir(cls)
|
||||
# add any virtual attributes to the list of names
|
||||
# :dd any DynamicClassAttributes to the list of names;
|
||||
# this may result in duplicate entries if, for example, a virtual
|
||||
# attribute with the same name as a member property exists
|
||||
# attribute with the same name as a DynamicClassAttribute exists.
|
||||
for base in mro:
|
||||
for k, v in base.__dict__.items():
|
||||
if isinstance(v, types.DynamicClassAttribute):
|
||||
names.append(k)
|
||||
result = []
|
||||
processed = set()
|
||||
sentinel = object()
|
||||
|
||||
for name in names:
|
||||
# Get the object associated with the name, and where it was defined.
|
||||
# Normal objects will be looked up with both getattr and directly in
|
||||
# its class' dict (in case getattr fails [bug #1785], and also to look
|
||||
# for a docstring).
|
||||
# For VirtualAttributes on the second pass we only look in the
|
||||
# For DynamicClassAttributes on the second pass we only look in the
|
||||
# class's dict.
|
||||
#
|
||||
# Getting an obj from the __dict__ sometimes reveals more than
|
||||
# using getattr. Static and class methods are dramatic examples.
|
||||
homecls = None
|
||||
get_obj = sentinel
|
||||
dict_obj = sentinel
|
||||
get_obj = None
|
||||
dict_obj = None
|
||||
if name not in processed:
|
||||
try:
|
||||
if name == '__dict__':
|
||||
raise Exception("__dict__ is special, we don't want the proxy")
|
||||
raise Exception("__dict__ is special, don't want the proxy")
|
||||
get_obj = getattr(cls, name)
|
||||
except Exception as exc:
|
||||
pass
|
||||
else:
|
||||
homecls = getattr(get_obj, "__objclass__", homecls)
|
||||
if homecls not in possible_bases:
|
||||
if homecls not in class_bases:
|
||||
# if the resulting object does not live somewhere in the
|
||||
# mro, drop it and search the mro manually
|
||||
homecls = None
|
||||
last_cls = None
|
||||
last_obj = None
|
||||
for srch_cls in ((cls,) + mro):
|
||||
# first look in the classes
|
||||
for srch_cls in class_bases:
|
||||
srch_obj = getattr(srch_cls, name, None)
|
||||
if srch_obj is get_obj:
|
||||
if srch_obj == get_obj:
|
||||
last_cls = srch_cls
|
||||
# then check the metaclasses
|
||||
for srch_cls in metamro:
|
||||
try:
|
||||
srch_obj = srch_cls.__getattr__(cls, name)
|
||||
except AttributeError:
|
||||
continue
|
||||
if srch_obj == get_obj:
|
||||
last_cls = srch_cls
|
||||
last_obj = srch_obj
|
||||
if last_cls is not None:
|
||||
homecls = last_cls
|
||||
for base in possible_bases:
|
||||
for base in all_bases:
|
||||
if name in base.__dict__:
|
||||
dict_obj = base.__dict__[name]
|
||||
homecls = homecls or base
|
||||
if homecls not in metamro:
|
||||
homecls = base
|
||||
break
|
||||
if homecls is None:
|
||||
# unable to locate the attribute anywhere, most likely due to
|
||||
# buggy custom __dir__; discard and move on
|
||||
continue
|
||||
obj = get_obj or dict_obj
|
||||
# Classify the object or its descriptor.
|
||||
if get_obj is not sentinel:
|
||||
obj = get_obj
|
||||
else:
|
||||
obj = dict_obj
|
||||
if isinstance(dict_obj, staticmethod):
|
||||
kind = "static method"
|
||||
obj = dict_obj
|
||||
elif isinstance(dict_obj, classmethod):
|
||||
kind = "class method"
|
||||
elif isinstance(obj, property):
|
||||
obj = dict_obj
|
||||
elif isinstance(dict_obj, property):
|
||||
kind = "property"
|
||||
obj = dict_obj
|
||||
elif isfunction(obj) or ismethoddescriptor(obj):
|
||||
kind = "method"
|
||||
else:
|
||||
|
|
|
@ -975,12 +975,24 @@ class _BaseNetwork(_IPAddressBase):
|
|||
"""Test if this address is allocated for private networks.
|
||||
|
||||
Returns:
|
||||
A boolean, True if the address is reserved per RFC 4193.
|
||||
A boolean, True if the address is reserved per
|
||||
iana-ipv4-special-registry or iana-ipv6-special-registry.
|
||||
|
||||
"""
|
||||
return (self.network_address.is_private and
|
||||
self.broadcast_address.is_private)
|
||||
|
||||
@property
|
||||
def is_global(self):
|
||||
"""Test if this address is allocated for private networks.
|
||||
|
||||
Returns:
|
||||
A boolean, True if the address is not reserved per
|
||||
iana-ipv4-special-registry or iana-ipv6-special-registry.
|
||||
|
||||
"""
|
||||
return not self.is_private
|
||||
|
||||
@property
|
||||
def is_unspecified(self):
|
||||
"""Test if the address is unspecified.
|
||||
|
@ -1225,15 +1237,37 @@ class IPv4Address(_BaseV4, _BaseAddress):
|
|||
"""Test if this address is allocated for private networks.
|
||||
|
||||
Returns:
|
||||
A boolean, True if the address is reserved per RFC 1918.
|
||||
A boolean, True if the address is reserved per
|
||||
iana-ipv4-special-registry.
|
||||
|
||||
"""
|
||||
private_10 = IPv4Network('10.0.0.0/8')
|
||||
private_172 = IPv4Network('172.16.0.0/12')
|
||||
private_192 = IPv4Network('192.168.0.0/16')
|
||||
return (self in private_10 or
|
||||
self in private_172 or
|
||||
self in private_192)
|
||||
return (self in IPv4Network('0.0.0.0/8') or
|
||||
self in IPv4Network('10.0.0.0/8') or
|
||||
self in IPv4Network('100.64.0.0/10') or
|
||||
self in IPv4Network('127.0.0.0/8') or
|
||||
self in IPv4Network('169.254.0.0/16') or
|
||||
self in IPv4Network('172.16.0.0/12') or
|
||||
self in IPv4Network('192.0.0.0/29') or
|
||||
self in IPv4Network('192.0.0.170/31') or
|
||||
self in IPv4Network('192.0.2.0/24') or
|
||||
self in IPv4Network('192.168.0.0/16') or
|
||||
self in IPv4Network('198.18.0.0/15') or
|
||||
self in IPv4Network('198.51.100.0/24') or
|
||||
self in IPv4Network('203.0.113.0/24') or
|
||||
self in IPv4Network('240.0.0.0/4') or
|
||||
self in IPv4Network('255.255.255.255/32'))
|
||||
|
||||
@property
|
||||
def is_global(self):
|
||||
"""Test if this address is allocated for private networks.
|
||||
|
||||
Returns:
|
||||
A boolean, True if the address is not reserved per
|
||||
iana-ipv4-special-registry.
|
||||
|
||||
"""
|
||||
return not self.is_private
|
||||
|
||||
|
||||
@property
|
||||
def is_multicast(self):
|
||||
|
@ -1826,11 +1860,31 @@ class IPv6Address(_BaseV6, _BaseAddress):
|
|||
"""Test if this address is allocated for private networks.
|
||||
|
||||
Returns:
|
||||
A boolean, True if the address is reserved per RFC 4193.
|
||||
A boolean, True if the address is reserved per
|
||||
iana-ipv6-special-registry.
|
||||
|
||||
"""
|
||||
private_network = IPv6Network('fc00::/7')
|
||||
return self in private_network
|
||||
return (self in IPv6Network('::1/128') or
|
||||
self in IPv6Network('::/128') or
|
||||
self in IPv6Network('::ffff:0:0/96') or
|
||||
self in IPv6Network('100::/64') or
|
||||
self in IPv6Network('2001::/23') or
|
||||
self in IPv6Network('2001:2::/48') or
|
||||
self in IPv6Network('2001:db8::/32') or
|
||||
self in IPv6Network('2001:10::/28') or
|
||||
self in IPv6Network('fc00::/7') or
|
||||
self in IPv6Network('fe80::/10'))
|
||||
|
||||
@property
|
||||
def is_global(self):
|
||||
"""Test if this address is allocated for public networks.
|
||||
|
||||
Returns:
|
||||
A boolean, true if the address is not reserved per
|
||||
iana-ipv6-special-registry.
|
||||
|
||||
"""
|
||||
return not self.is_private
|
||||
|
||||
@property
|
||||
def is_unspecified(self):
|
||||
|
|
|
@ -310,6 +310,11 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
|
|||
The ``encoding`` argument is ignored and deprecated.
|
||||
|
||||
"""
|
||||
if not isinstance(s, str):
|
||||
raise TypeError('the JSON object must be str, not {!r}'.format(
|
||||
s.__class__.__name__))
|
||||
if s.startswith(u'\ufeff'):
|
||||
raise ValueError("Unexpected UTF-8 BOM (decode using utf-8-sig)")
|
||||
if (cls is None and object_hook is None and
|
||||
parse_int is None and parse_float is None and
|
||||
parse_constant is None and object_pairs_hook is None and not kw):
|
||||
|
|
|
@ -1183,6 +1183,14 @@ _ironpython_sys_version_parser = re.compile(
|
|||
'(?: \(([\d\.]+)\))?'
|
||||
' on (.NET [\d\.]+)', re.ASCII)
|
||||
|
||||
# IronPython covering 2.6 and 2.7
|
||||
_ironpython26_sys_version_parser = re.compile(
|
||||
r'([\d.]+)\s*'
|
||||
'\(IronPython\s*'
|
||||
'[\d.]+\s*'
|
||||
'\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
|
||||
)
|
||||
|
||||
_pypy_sys_version_parser = re.compile(
|
||||
r'([\w.+]+)\s*'
|
||||
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
|
||||
|
@ -1220,19 +1228,24 @@ def _sys_version(sys_version=None):
|
|||
return result
|
||||
|
||||
# Parse it
|
||||
if sys_version[:10] == 'IronPython':
|
||||
if 'IronPython' in sys_version:
|
||||
# IronPython
|
||||
name = 'IronPython'
|
||||
if sys_version.startswith('IronPython'):
|
||||
match = _ironpython_sys_version_parser.match(sys_version)
|
||||
else:
|
||||
match = _ironpython26_sys_version_parser.match(sys_version)
|
||||
|
||||
if match is None:
|
||||
raise ValueError(
|
||||
'failed to parse IronPython sys.version: %s' %
|
||||
repr(sys_version))
|
||||
|
||||
version, alt_version, compiler = match.groups()
|
||||
buildno = ''
|
||||
builddate = ''
|
||||
|
||||
elif sys.platform[:4] == 'java':
|
||||
elif sys.platform.startswith('java'):
|
||||
# Jython
|
||||
name = 'Jython'
|
||||
match = _sys_version_parser.match(sys_version)
|
||||
|
|
|
@ -1235,7 +1235,8 @@ location listed above.
|
|||
doc = getdoc(value)
|
||||
else:
|
||||
doc = None
|
||||
push(self.docother(getattr(object, name),
|
||||
push(self.docother(
|
||||
getattr(object, name, None) or homecls.__dict__[name],
|
||||
name, mod, maxlen=70, doc=doc) + '\n')
|
||||
return attrs
|
||||
|
||||
|
@ -1258,7 +1259,6 @@ location listed above.
|
|||
else:
|
||||
tag = "inherited from %s" % classname(thisclass,
|
||||
object.__module__)
|
||||
|
||||
# Sort attrs by name.
|
||||
attrs.sort()
|
||||
|
||||
|
@ -1273,6 +1273,7 @@ location listed above.
|
|||
lambda t: t[1] == 'data descriptor')
|
||||
attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
|
||||
lambda t: t[1] == 'data')
|
||||
|
||||
assert attrs == []
|
||||
attrs = inherited
|
||||
|
||||
|
|
209
Lib/telnetlib.py
209
Lib/telnetlib.py
|
@ -17,13 +17,12 @@ guido Guido van Rossum pts/2 <Dec 2 11:10> snag.cnri.reston..
|
|||
Note that read_all() won't read until eof -- it just reads some data
|
||||
-- but it guarantees to read at least one byte unless EOF is hit.
|
||||
|
||||
It is possible to pass a Telnet object to select.select() in order to
|
||||
wait until more data is available. Note that in this case,
|
||||
read_eager() may return b'' even if there was data on the socket,
|
||||
because the protocol negotiation may have eaten the data. This is why
|
||||
EOFError is needed in some cases to distinguish between "no data" and
|
||||
"connection closed" (since the socket also appears ready for reading
|
||||
when it is closed).
|
||||
It is possible to pass a Telnet object to a selector in order to wait until
|
||||
more data is available. Note that in this case, read_eager() may return b''
|
||||
even if there was data on the socket, because the protocol negotiation may have
|
||||
eaten the data. This is why EOFError is needed in some cases to distinguish
|
||||
between "no data" and "connection closed" (since the socket also appears ready
|
||||
for reading when it is closed).
|
||||
|
||||
To do:
|
||||
- option negotiation
|
||||
|
@ -34,10 +33,9 @@ To do:
|
|||
|
||||
|
||||
# Imported modules
|
||||
import errno
|
||||
import sys
|
||||
import socket
|
||||
import select
|
||||
import selectors
|
||||
|
||||
__all__ = ["Telnet"]
|
||||
|
||||
|
@ -130,6 +128,15 @@ PRAGMA_HEARTBEAT = bytes([140]) # TELOPT PRAGMA HEARTBEAT
|
|||
EXOPL = bytes([255]) # Extended-Options-List
|
||||
NOOPT = bytes([0])
|
||||
|
||||
|
||||
# poll/select have the advantage of not requiring any extra file descriptor,
|
||||
# contrarily to epoll/kqueue (also, they require a single syscall).
|
||||
if hasattr(selectors, 'PollSelector'):
|
||||
_TelnetSelector = selectors.PollSelector
|
||||
else:
|
||||
_TelnetSelector = selectors.SelectSelector
|
||||
|
||||
|
||||
class Telnet:
|
||||
|
||||
"""Telnet interface class.
|
||||
|
@ -206,7 +213,6 @@ class Telnet:
|
|||
self.sb = 0 # flag for SB and SE sequence.
|
||||
self.sbdataq = b''
|
||||
self.option_callback = None
|
||||
self._has_poll = hasattr(select, 'poll')
|
||||
if host is not None:
|
||||
self.open(host, port, timeout)
|
||||
|
||||
|
@ -288,61 +294,6 @@ class Telnet:
|
|||
possibly the empty string. Raise EOFError if the connection
|
||||
is closed and no cooked data is available.
|
||||
|
||||
"""
|
||||
if self._has_poll:
|
||||
return self._read_until_with_poll(match, timeout)
|
||||
else:
|
||||
return self._read_until_with_select(match, timeout)
|
||||
|
||||
def _read_until_with_poll(self, match, timeout):
|
||||
"""Read until a given string is encountered or until timeout.
|
||||
|
||||
This method uses select.poll() to implement the timeout.
|
||||
"""
|
||||
n = len(match)
|
||||
call_timeout = timeout
|
||||
if timeout is not None:
|
||||
from time import time
|
||||
time_start = time()
|
||||
self.process_rawq()
|
||||
i = self.cookedq.find(match)
|
||||
if i < 0:
|
||||
poller = select.poll()
|
||||
poll_in_or_priority_flags = select.POLLIN | select.POLLPRI
|
||||
poller.register(self, poll_in_or_priority_flags)
|
||||
while i < 0 and not self.eof:
|
||||
try:
|
||||
ready = poller.poll(call_timeout)
|
||||
except OSError as e:
|
||||
if e.errno == errno.EINTR:
|
||||
if timeout is not None:
|
||||
elapsed = time() - time_start
|
||||
call_timeout = timeout-elapsed
|
||||
continue
|
||||
raise
|
||||
for fd, mode in ready:
|
||||
if mode & poll_in_or_priority_flags:
|
||||
i = max(0, len(self.cookedq)-n)
|
||||
self.fill_rawq()
|
||||
self.process_rawq()
|
||||
i = self.cookedq.find(match, i)
|
||||
if timeout is not None:
|
||||
elapsed = time() - time_start
|
||||
if elapsed >= timeout:
|
||||
break
|
||||
call_timeout = timeout-elapsed
|
||||
poller.unregister(self)
|
||||
if i >= 0:
|
||||
i = i + n
|
||||
buf = self.cookedq[:i]
|
||||
self.cookedq = self.cookedq[i:]
|
||||
return buf
|
||||
return self.read_very_lazy()
|
||||
|
||||
def _read_until_with_select(self, match, timeout=None):
|
||||
"""Read until a given string is encountered or until timeout.
|
||||
|
||||
The timeout is implemented using select.select().
|
||||
"""
|
||||
n = len(match)
|
||||
self.process_rawq()
|
||||
|
@ -352,13 +303,13 @@ class Telnet:
|
|||
buf = self.cookedq[:i]
|
||||
self.cookedq = self.cookedq[i:]
|
||||
return buf
|
||||
s_reply = ([self], [], [])
|
||||
s_args = s_reply
|
||||
if timeout is not None:
|
||||
s_args = s_args + (timeout,)
|
||||
from time import time
|
||||
time_start = time()
|
||||
while not self.eof and select.select(*s_args) == s_reply:
|
||||
deadline = time() + timeout
|
||||
with _TelnetSelector() as selector:
|
||||
selector.register(self, selectors.EVENT_READ)
|
||||
while not self.eof:
|
||||
if selector.select(timeout):
|
||||
i = max(0, len(self.cookedq)-n)
|
||||
self.fill_rawq()
|
||||
self.process_rawq()
|
||||
|
@ -369,10 +320,9 @@ class Telnet:
|
|||
self.cookedq = self.cookedq[i:]
|
||||
return buf
|
||||
if timeout is not None:
|
||||
elapsed = time() - time_start
|
||||
if elapsed >= timeout:
|
||||
timeout = deadline - time()
|
||||
if timeout < 0:
|
||||
break
|
||||
s_args = s_reply + (timeout-elapsed,)
|
||||
return self.read_very_lazy()
|
||||
|
||||
def read_all(self):
|
||||
|
@ -577,28 +527,34 @@ class Telnet:
|
|||
|
||||
def sock_avail(self):
|
||||
"""Test whether data is available on the socket."""
|
||||
return select.select([self], [], [], 0) == ([self], [], [])
|
||||
with _TelnetSelector() as selector:
|
||||
selector.register(self, selectors.EVENT_READ)
|
||||
return bool(selector.select(0))
|
||||
|
||||
def interact(self):
|
||||
"""Interaction function, emulates a very dumb telnet client."""
|
||||
if sys.platform == "win32":
|
||||
self.mt_interact()
|
||||
return
|
||||
while 1:
|
||||
rfd, wfd, xfd = select.select([self, sys.stdin], [], [])
|
||||
if self in rfd:
|
||||
with _TelnetSelector() as selector:
|
||||
selector.register(self, selectors.EVENT_READ)
|
||||
selector.register(sys.stdin, selectors.EVENT_READ)
|
||||
|
||||
while True:
|
||||
for key, events in selector.select():
|
||||
if key.fileobj is self:
|
||||
try:
|
||||
text = self.read_eager()
|
||||
except EOFError:
|
||||
print('*** Connection closed by remote host ***')
|
||||
break
|
||||
return
|
||||
if text:
|
||||
sys.stdout.write(text.decode('ascii'))
|
||||
sys.stdout.flush()
|
||||
if sys.stdin in rfd:
|
||||
elif key.fileobj is sys.stdin:
|
||||
line = sys.stdin.readline().encode('ascii')
|
||||
if not line:
|
||||
break
|
||||
return
|
||||
self.write(line)
|
||||
|
||||
def mt_interact(self):
|
||||
|
@ -645,79 +601,6 @@ class Telnet:
|
|||
or if more than one expression can match the same input, the
|
||||
results are undeterministic, and may depend on the I/O timing.
|
||||
|
||||
"""
|
||||
if self._has_poll:
|
||||
return self._expect_with_poll(list, timeout)
|
||||
else:
|
||||
return self._expect_with_select(list, timeout)
|
||||
|
||||
def _expect_with_poll(self, expect_list, timeout=None):
|
||||
"""Read until one from a list of a regular expressions matches.
|
||||
|
||||
This method uses select.poll() to implement the timeout.
|
||||
"""
|
||||
re = None
|
||||
expect_list = expect_list[:]
|
||||
indices = range(len(expect_list))
|
||||
for i in indices:
|
||||
if not hasattr(expect_list[i], "search"):
|
||||
if not re: import re
|
||||
expect_list[i] = re.compile(expect_list[i])
|
||||
call_timeout = timeout
|
||||
if timeout is not None:
|
||||
from time import time
|
||||
time_start = time()
|
||||
self.process_rawq()
|
||||
m = None
|
||||
for i in indices:
|
||||
m = expect_list[i].search(self.cookedq)
|
||||
if m:
|
||||
e = m.end()
|
||||
text = self.cookedq[:e]
|
||||
self.cookedq = self.cookedq[e:]
|
||||
break
|
||||
if not m:
|
||||
poller = select.poll()
|
||||
poll_in_or_priority_flags = select.POLLIN | select.POLLPRI
|
||||
poller.register(self, poll_in_or_priority_flags)
|
||||
while not m and not self.eof:
|
||||
try:
|
||||
ready = poller.poll(call_timeout)
|
||||
except OSError as e:
|
||||
if e.errno == errno.EINTR:
|
||||
if timeout is not None:
|
||||
elapsed = time() - time_start
|
||||
call_timeout = timeout-elapsed
|
||||
continue
|
||||
raise
|
||||
for fd, mode in ready:
|
||||
if mode & poll_in_or_priority_flags:
|
||||
self.fill_rawq()
|
||||
self.process_rawq()
|
||||
for i in indices:
|
||||
m = expect_list[i].search(self.cookedq)
|
||||
if m:
|
||||
e = m.end()
|
||||
text = self.cookedq[:e]
|
||||
self.cookedq = self.cookedq[e:]
|
||||
break
|
||||
if timeout is not None:
|
||||
elapsed = time() - time_start
|
||||
if elapsed >= timeout:
|
||||
break
|
||||
call_timeout = timeout-elapsed
|
||||
poller.unregister(self)
|
||||
if m:
|
||||
return (i, m, text)
|
||||
text = self.read_very_lazy()
|
||||
if not text and self.eof:
|
||||
raise EOFError
|
||||
return (-1, None, text)
|
||||
|
||||
def _expect_with_select(self, list, timeout=None):
|
||||
"""Read until one from a list of a regular expressions matches.
|
||||
|
||||
The timeout is implemented using select.select().
|
||||
"""
|
||||
re = None
|
||||
list = list[:]
|
||||
|
@ -728,8 +611,10 @@ class Telnet:
|
|||
list[i] = re.compile(list[i])
|
||||
if timeout is not None:
|
||||
from time import time
|
||||
time_start = time()
|
||||
while 1:
|
||||
deadline = time() + timeout
|
||||
with _TelnetSelector() as selector:
|
||||
selector.register(self, selectors.EVENT_READ)
|
||||
while not self.eof:
|
||||
self.process_rawq()
|
||||
for i in indices:
|
||||
m = list[i].search(self.cookedq)
|
||||
|
@ -738,16 +623,14 @@ class Telnet:
|
|||
text = self.cookedq[:e]
|
||||
self.cookedq = self.cookedq[e:]
|
||||
return (i, m, text)
|
||||
if self.eof:
|
||||
break
|
||||
if timeout is not None:
|
||||
elapsed = time() - time_start
|
||||
if elapsed >= timeout:
|
||||
break
|
||||
s_args = ([self.fileno()], [], [], timeout-elapsed)
|
||||
r, w, x = select.select(*s_args)
|
||||
if not r:
|
||||
ready = selector.select(timeout)
|
||||
timeout = deadline - time()
|
||||
if not ready:
|
||||
if timeout < 0:
|
||||
break
|
||||
else:
|
||||
continue
|
||||
self.fill_rawq()
|
||||
text = self.read_very_lazy()
|
||||
if not text and self.eof:
|
||||
|
|
|
@ -5,6 +5,7 @@ import socket
|
|||
import time
|
||||
import unittest
|
||||
import unittest.mock
|
||||
from test.support import find_unused_port, IPV6_ENABLED
|
||||
|
||||
from asyncio import base_events
|
||||
from asyncio import events
|
||||
|
@ -533,6 +534,7 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
|
|||
self.assertRaises(
|
||||
OSError, self.loop.run_until_complete, coro)
|
||||
|
||||
@unittest.skipUnless(IPV6_ENABLED, 'IPv6 not supported or enabled')
|
||||
def test_create_datagram_endpoint_no_matching_family(self):
|
||||
coro = self.loop.create_datagram_endpoint(
|
||||
protocols.DatagramProtocol,
|
||||
|
@ -588,3 +590,7 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
|
|||
self.loop._accept_connection(MyProto, sock)
|
||||
self.assertTrue(sock.close.called)
|
||||
self.assertTrue(m_log.exception.called)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -896,8 +896,8 @@ class EventLoopTestsMixin:
|
|||
proto = MyWritePipeProto(loop=self.loop)
|
||||
return proto
|
||||
|
||||
rpipe, wpipe = os.pipe()
|
||||
pipeobj = io.open(wpipe, 'wb', 1024)
|
||||
rsock, wsock = self.loop._socketpair()
|
||||
pipeobj = io.open(wsock.detach(), 'wb', 1024)
|
||||
|
||||
@tasks.coroutine
|
||||
def connect():
|
||||
|
@ -913,11 +913,10 @@ class EventLoopTestsMixin:
|
|||
self.assertEqual('CONNECTED', proto.state)
|
||||
|
||||
transport.write(b'1')
|
||||
test_utils.run_briefly(self.loop)
|
||||
data = os.read(rpipe, 1024)
|
||||
data = self.loop.run_until_complete(self.loop.sock_recv(rsock, 1024))
|
||||
self.assertEqual(b'1', data)
|
||||
|
||||
os.close(rpipe)
|
||||
rsock.close()
|
||||
|
||||
self.loop.run_until_complete(proto.done)
|
||||
self.assertEqual('CLOSED', proto.state)
|
||||
|
@ -986,9 +985,6 @@ class EventLoopTestsMixin:
|
|||
|
||||
@unittest.skipIf(sys.platform == 'win32',
|
||||
"Don't support subprocess for Windows yet")
|
||||
# Issue #19293
|
||||
@unittest.skipIf(sys.platform.startswith("aix"),
|
||||
'cannot be interrupted with signal on AIX')
|
||||
def test_subprocess_interactive(self):
|
||||
proto = None
|
||||
transp = None
|
||||
|
@ -1087,9 +1083,6 @@ class EventLoopTestsMixin:
|
|||
|
||||
@unittest.skipIf(sys.platform == 'win32',
|
||||
"Don't support subprocess for Windows yet")
|
||||
# Issue #19293
|
||||
@unittest.skipIf(sys.platform.startswith("aix"),
|
||||
'cannot be interrupted with signal on AIX')
|
||||
def test_subprocess_kill(self):
|
||||
proto = None
|
||||
transp = None
|
||||
|
@ -1113,9 +1106,6 @@ class EventLoopTestsMixin:
|
|||
|
||||
@unittest.skipIf(sys.platform == 'win32',
|
||||
"Don't support subprocess for Windows yet")
|
||||
# Issue #19293
|
||||
@unittest.skipIf(sys.platform.startswith("aix"),
|
||||
'cannot be interrupted with signal on AIX')
|
||||
def test_subprocess_send_signal(self):
|
||||
proto = None
|
||||
transp = None
|
||||
|
@ -1233,6 +1223,26 @@ class EventLoopTestsMixin:
|
|||
self.loop.run_until_complete(proto.completed)
|
||||
self.assertEqual(-signal.SIGTERM, proto.returncode)
|
||||
|
||||
@unittest.skipIf(sys.platform == 'win32',
|
||||
"Don't support subprocess for Windows yet")
|
||||
def test_subprocess_wait_no_same_group(self):
|
||||
proto = None
|
||||
transp = None
|
||||
|
||||
@tasks.coroutine
|
||||
def connect():
|
||||
nonlocal proto
|
||||
# start the new process in a new session
|
||||
transp, proto = yield from self.loop.subprocess_shell(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
'exit 7', stdin=None, stdout=None, stderr=None,
|
||||
start_new_session=True)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
|
||||
self.loop.run_until_complete(connect())
|
||||
self.loop.run_until_complete(proto.completed)
|
||||
self.assertEqual(7, proto.returncode)
|
||||
|
||||
|
||||
if sys.platform == 'win32':
|
||||
from asyncio import windows_events
|
||||
|
|
|
@ -478,3 +478,7 @@ class BaseProactorEventLoopTests(unittest.TestCase):
|
|||
self.loop._stop_serving(sock)
|
||||
self.assertTrue(sock.close.called)
|
||||
self.proactor._stop_serving.assert_called_with(sock)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1483,3 +1483,7 @@ class SelectorDatagramTransportTests(unittest.TestCase):
|
|||
transport._fatal_error(err)
|
||||
self.protocol.connection_refused.assert_called_with(err)
|
||||
m_exc.assert_called_with('Fatal error for %s', transport)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -143,3 +143,7 @@ class BaseSelectorTests(unittest.TestCase):
|
|||
if hasattr(selectors.DefaultSelector, 'fileno'):
|
||||
def test_fileno(self):
|
||||
self.assertIsInstance(selectors.DefaultSelector().fileno(), int)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -53,3 +53,7 @@ class TransportTests(unittest.TestCase):
|
|||
self.assertRaises(NotImplementedError, transport.send_signal, 1)
|
||||
self.assertRaises(NotImplementedError, transport.terminate)
|
||||
self.assertRaises(NotImplementedError, transport.kill)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -266,7 +266,7 @@ class SelectorEventLoopTests(unittest.TestCase):
|
|||
self.loop._subprocesses[7] = transp
|
||||
|
||||
self.loop._sig_chld()
|
||||
self.assertFalse(transp._process_exited.called)
|
||||
self.assertTrue(transp._process_exited.called)
|
||||
self.assertFalse(m_WEXITSTATUS.called)
|
||||
self.assertFalse(m_WTERMSIG.called)
|
||||
|
||||
|
@ -312,6 +312,13 @@ class UnixReadPipeTransportTests(unittest.TestCase):
|
|||
fcntl_patcher.start()
|
||||
self.addCleanup(fcntl_patcher.stop)
|
||||
|
||||
fstat_patcher = unittest.mock.patch('os.fstat')
|
||||
m_fstat = fstat_patcher.start()
|
||||
st = unittest.mock.Mock()
|
||||
st.st_mode = stat.S_IFIFO
|
||||
m_fstat.return_value = st
|
||||
self.addCleanup(fstat_patcher.stop)
|
||||
|
||||
def test_ctor(self):
|
||||
tr = unix_events._UnixReadPipeTransport(
|
||||
self.loop, self.pipe, self.protocol)
|
||||
|
@ -768,3 +775,7 @@ class UnixWritePipeTransportTests(unittest.TestCase):
|
|||
tr.write_eof()
|
||||
self.assertTrue(tr._closing)
|
||||
self.assertFalse(self.protocol.connection_lost.called)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -93,3 +93,7 @@ class ProactorTests(unittest.TestCase):
|
|||
protocols.Protocol, ADDRESS)
|
||||
|
||||
return 'done'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -138,3 +138,7 @@ class PopenTests(unittest.TestCase):
|
|||
# allow for partial reads...
|
||||
self.assertTrue(msg.upper().rstrip().startswith(out))
|
||||
self.assertTrue(b"stderr".startswith(err))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import audioop
|
||||
import sys
|
||||
import unittest
|
||||
from test.support import run_unittest
|
||||
|
||||
def pack(width, data):
|
||||
return b''.join(v.to_bytes(width, sys.byteorder, signed=True) for v in data)
|
||||
|
@ -87,6 +86,7 @@ class TestAudioop(unittest.TestCase):
|
|||
self.assertEqual(audioop.avgpp(packs[w](9, 10, 5, 5, 0, 1), w), 10)
|
||||
self.assertEqual(audioop.avgpp(datas[1], 1), 196)
|
||||
self.assertEqual(audioop.avgpp(datas[2], 2), 50534)
|
||||
self.assertEqual(audioop.avgpp(datas[3], 3), 12937096)
|
||||
self.assertEqual(audioop.avgpp(datas[4], 4), 3311897002)
|
||||
|
||||
def test_rms(self):
|
||||
|
@ -100,6 +100,7 @@ class TestAudioop(unittest.TestCase):
|
|||
-minvalues[w], delta=1)
|
||||
self.assertEqual(audioop.rms(datas[1], 1), 77)
|
||||
self.assertEqual(audioop.rms(datas[2], 2), 20001)
|
||||
self.assertEqual(audioop.rms(datas[3], 3), 5120523)
|
||||
self.assertEqual(audioop.rms(datas[4], 4), 1310854152)
|
||||
|
||||
def test_cross(self):
|
||||
|
@ -227,9 +228,8 @@ class TestAudioop(unittest.TestCase):
|
|||
def test_lin2adpcm(self):
|
||||
self.assertEqual(audioop.lin2adpcm(datas[1], 1, None),
|
||||
(b'\x07\x7f\x7f', (-221, 39)))
|
||||
self.assertEqual(audioop.lin2adpcm(datas[2], 2, None),
|
||||
(b'\x07\x7f\x7f', (31, 39)))
|
||||
self.assertEqual(audioop.lin2adpcm(datas[4], 4, None),
|
||||
for w in 2, 3, 4:
|
||||
self.assertEqual(audioop.lin2adpcm(datas[w], w, None),
|
||||
(b'\x07\x7f\x7f', (31, 39)))
|
||||
|
||||
# Very cursory test
|
||||
|
@ -240,9 +240,8 @@ class TestAudioop(unittest.TestCase):
|
|||
def test_lin2alaw(self):
|
||||
self.assertEqual(audioop.lin2alaw(datas[1], 1),
|
||||
b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
|
||||
self.assertEqual(audioop.lin2alaw(datas[2], 2),
|
||||
b'\xd5\x87\xa4\x24\xaa\x2a\x55')
|
||||
self.assertEqual(audioop.lin2alaw(datas[4], 4),
|
||||
for w in 2, 3, 4:
|
||||
self.assertEqual(audioop.lin2alaw(datas[w], w),
|
||||
b'\xd5\x87\xa4\x24\xaa\x2a\x55')
|
||||
|
||||
def test_alaw2lin(self):
|
||||
|
@ -262,9 +261,8 @@ class TestAudioop(unittest.TestCase):
|
|||
def test_lin2ulaw(self):
|
||||
self.assertEqual(audioop.lin2ulaw(datas[1], 1),
|
||||
b'\xff\xad\x8e\x0e\x80\x00\x67')
|
||||
self.assertEqual(audioop.lin2ulaw(datas[2], 2),
|
||||
b'\xff\xad\x8e\x0e\x80\x00\x7e')
|
||||
self.assertEqual(audioop.lin2ulaw(datas[4], 4),
|
||||
for w in 2, 3, 4:
|
||||
self.assertEqual(audioop.lin2ulaw(datas[w], w),
|
||||
b'\xff\xad\x8e\x0e\x80\x00\x7e')
|
||||
|
||||
def test_ulaw2lin(self):
|
||||
|
@ -416,8 +414,5 @@ class TestAudioop(unittest.TestCase):
|
|||
self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
|
||||
self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
|
||||
|
||||
def test_main():
|
||||
run_unittest(TestAudioop)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
unittest.main()
|
||||
|
|
|
@ -4519,8 +4519,10 @@ order (MRO) for bases """
|
|||
|
||||
global Y
|
||||
class Y:
|
||||
class Inside:
|
||||
pass
|
||||
self.assertEqual(Y.__qualname__, 'Y')
|
||||
self.assertEqual(Y.Inside.__qualname__, 'Y.Inside')
|
||||
|
||||
def test_qualname_dict(self):
|
||||
ns = {'__qualname__': 'some.name'}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import enum
|
||||
import inspect
|
||||
import pydoc
|
||||
import unittest
|
||||
from collections import OrderedDict
|
||||
from enum import Enum, IntEnum, EnumMeta, unique
|
||||
from io import StringIO
|
||||
from pickle import dumps, loads, PicklingError
|
||||
from enum import Enum, IntEnum, unique
|
||||
|
||||
# for pickle tests
|
||||
try:
|
||||
|
@ -1195,5 +1198,117 @@ class TestUnique(unittest.TestCase):
|
|||
turkey = 3
|
||||
|
||||
|
||||
expected_help_output = """
|
||||
Help on class Color in module %s:
|
||||
|
||||
class Color(enum.Enum)
|
||||
| Method resolution order:
|
||||
| Color
|
||||
| enum.Enum
|
||||
| builtins.object
|
||||
|\x20\x20
|
||||
| Data and other attributes defined here:
|
||||
|\x20\x20
|
||||
| blue = <Color.blue: 3>
|
||||
|\x20\x20
|
||||
| green = <Color.green: 2>
|
||||
|\x20\x20
|
||||
| red = <Color.red: 1>
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Data descriptors inherited from enum.Enum:
|
||||
|\x20\x20
|
||||
| name
|
||||
| The name of the Enum member.
|
||||
|\x20\x20
|
||||
| value
|
||||
| The value of the Enum member.
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Data descriptors inherited from enum.EnumMeta:
|
||||
|\x20\x20
|
||||
| __members__
|
||||
| Returns a mapping of member name->value.
|
||||
|\x20\x20\x20\x20\x20\x20
|
||||
| This mapping lists all enum members, including aliases. Note that this
|
||||
| is a read-only view of the internal mapping.
|
||||
""".strip()
|
||||
|
||||
class TestStdLib(unittest.TestCase):
|
||||
|
||||
class Color(Enum):
|
||||
red = 1
|
||||
green = 2
|
||||
blue = 3
|
||||
|
||||
def test_pydoc(self):
|
||||
# indirectly test __objclass__
|
||||
expected_text = expected_help_output % __name__
|
||||
output = StringIO()
|
||||
helper = pydoc.Helper(output=output)
|
||||
helper(self.Color)
|
||||
result = output.getvalue().strip()
|
||||
if result != expected_text:
|
||||
print_diffs(expected_text, result)
|
||||
self.fail("outputs are not equal, see diff above")
|
||||
|
||||
def test_inspect_getmembers(self):
|
||||
values = dict((
|
||||
('__class__', EnumMeta),
|
||||
('__doc__', None),
|
||||
('__members__', self.Color.__members__),
|
||||
('__module__', __name__),
|
||||
('blue', self.Color.blue),
|
||||
('green', self.Color.green),
|
||||
('name', Enum.__dict__['name']),
|
||||
('red', self.Color.red),
|
||||
('value', Enum.__dict__['value']),
|
||||
))
|
||||
result = dict(inspect.getmembers(self.Color))
|
||||
self.assertEqual(values.keys(), result.keys())
|
||||
failed = False
|
||||
for k in values.keys():
|
||||
if result[k] != values[k]:
|
||||
print()
|
||||
print('\n%s\n key: %s\n result: %s\nexpected: %s\n%s\n' %
|
||||
('=' * 75, k, result[k], values[k], '=' * 75), sep='')
|
||||
failed = True
|
||||
if failed:
|
||||
self.fail("result does not equal expected, see print above")
|
||||
|
||||
def test_inspect_classify_class_attrs(self):
|
||||
# indirectly test __objclass__
|
||||
from inspect import Attribute
|
||||
values = [
|
||||
Attribute(name='__class__', kind='data',
|
||||
defining_class=object, object=EnumMeta),
|
||||
Attribute(name='__doc__', kind='data',
|
||||
defining_class=self.Color, object=None),
|
||||
Attribute(name='__members__', kind='property',
|
||||
defining_class=EnumMeta, object=EnumMeta.__members__),
|
||||
Attribute(name='__module__', kind='data',
|
||||
defining_class=self.Color, object=__name__),
|
||||
Attribute(name='blue', kind='data',
|
||||
defining_class=self.Color, object=self.Color.blue),
|
||||
Attribute(name='green', kind='data',
|
||||
defining_class=self.Color, object=self.Color.green),
|
||||
Attribute(name='red', kind='data',
|
||||
defining_class=self.Color, object=self.Color.red),
|
||||
Attribute(name='name', kind='data',
|
||||
defining_class=Enum, object=Enum.__dict__['name']),
|
||||
Attribute(name='value', kind='data',
|
||||
defining_class=Enum, object=Enum.__dict__['value']),
|
||||
]
|
||||
values.sort(key=lambda item: item.name)
|
||||
result = list(inspect.classify_class_attrs(self.Color))
|
||||
result.sort(key=lambda item: item.name)
|
||||
failed = False
|
||||
for v, r in zip(values, result):
|
||||
if r != v:
|
||||
print('\n%s\n%s\n%s\n%s\n' % ('=' * 75, r, v, '=' * 75), sep='')
|
||||
failed = True
|
||||
if failed:
|
||||
self.fail("result does not equal expected, see print above")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -72,9 +72,9 @@ class FaultHandlerTests(unittest.TestCase):
|
|||
Raise an error if the output doesn't match the expected format.
|
||||
"""
|
||||
if all_threads:
|
||||
header = 'Current thread XXX'
|
||||
header = 'Current thread XXX (most recent call first)'
|
||||
else:
|
||||
header = 'Traceback (most recent call first)'
|
||||
header = 'Stack (most recent call first)'
|
||||
regex = """
|
||||
^Fatal Python error: {name}
|
||||
|
||||
|
@ -306,7 +306,7 @@ funcA()
|
|||
else:
|
||||
lineno = 8
|
||||
expected = [
|
||||
'Traceback (most recent call first):',
|
||||
'Stack (most recent call first):',
|
||||
' File "<string>", line %s in funcB' % lineno,
|
||||
' File "<string>", line 11 in funcA',
|
||||
' File "<string>", line 13 in <module>'
|
||||
|
@ -338,7 +338,7 @@ def {func_name}():
|
|||
func_name=func_name,
|
||||
)
|
||||
expected = [
|
||||
'Traceback (most recent call first):',
|
||||
'Stack (most recent call first):',
|
||||
' File "<string>", line 4 in %s' % truncated,
|
||||
' File "<string>", line 6 in <module>'
|
||||
]
|
||||
|
@ -392,13 +392,13 @@ waiter.join()
|
|||
else:
|
||||
lineno = 10
|
||||
regex = """
|
||||
^Thread 0x[0-9a-f]+:
|
||||
^Thread 0x[0-9a-f]+ \(most recent call first\):
|
||||
(?: File ".*threading.py", line [0-9]+ in [_a-z]+
|
||||
){{1,3}} File "<string>", line 23 in run
|
||||
File ".*threading.py", line [0-9]+ in _bootstrap_inner
|
||||
File ".*threading.py", line [0-9]+ in _bootstrap
|
||||
|
||||
Current thread XXX:
|
||||
Current thread XXX \(most recent call first\):
|
||||
File "<string>", line {lineno} in dump
|
||||
File "<string>", line 28 in <module>$
|
||||
""".strip()
|
||||
|
@ -461,7 +461,7 @@ if file is not None:
|
|||
count = loops
|
||||
if repeat:
|
||||
count *= 2
|
||||
header = r'Timeout \(%s\)!\nThread 0x[0-9a-f]+:\n' % timeout_str
|
||||
header = r'Timeout \(%s\)!\nThread 0x[0-9a-f]+ \(most recent call first\):\n' % timeout_str
|
||||
regex = expected_traceback(9, 20, header, min_count=count)
|
||||
self.assertRegex(trace, regex)
|
||||
else:
|
||||
|
@ -563,9 +563,9 @@ sys.exit(exitcode)
|
|||
trace = '\n'.join(trace)
|
||||
if not unregister:
|
||||
if all_threads:
|
||||
regex = 'Current thread XXX:\n'
|
||||
regex = 'Current thread XXX \(most recent call first\):\n'
|
||||
else:
|
||||
regex = 'Traceback \(most recent call first\):\n'
|
||||
regex = 'Stack \(most recent call first\):\n'
|
||||
regex = expected_traceback(7, 28, regex)
|
||||
self.assertRegex(trace, regex)
|
||||
else:
|
||||
|
|
|
@ -92,6 +92,7 @@ class DummyFTPHandler(asynchat.async_chat):
|
|||
self.next_response = ''
|
||||
self.next_data = None
|
||||
self.rest = None
|
||||
self.next_retr_data = RETR_DATA
|
||||
self.push('220 welcome')
|
||||
|
||||
def collect_incoming_data(self, data):
|
||||
|
@ -221,7 +222,7 @@ class DummyFTPHandler(asynchat.async_chat):
|
|||
offset = int(self.rest)
|
||||
else:
|
||||
offset = 0
|
||||
self.dtp.push(RETR_DATA[offset:])
|
||||
self.dtp.push(self.next_retr_data[offset:])
|
||||
self.dtp.close_when_done()
|
||||
self.rest = None
|
||||
|
||||
|
@ -243,6 +244,11 @@ class DummyFTPHandler(asynchat.async_chat):
|
|||
self.dtp.push(MLSD_DATA)
|
||||
self.dtp.close_when_done()
|
||||
|
||||
def cmd_setlongretr(self, arg):
|
||||
# For testing. Next RETR will return long line.
|
||||
self.next_retr_data = 'x' * int(arg)
|
||||
self.push('125 setlongretr ok')
|
||||
|
||||
|
||||
class DummyFTPServer(asyncore.dispatcher, threading.Thread):
|
||||
|
||||
|
@ -759,6 +765,20 @@ class TestFTPClass(TestCase):
|
|||
self.assertEqual(ftplib.parse257('257 "/foo/b""ar"'), '/foo/b"ar')
|
||||
self.assertEqual(ftplib.parse257('257 "/foo/b""ar" created'), '/foo/b"ar')
|
||||
|
||||
def test_line_too_long(self):
|
||||
self.assertRaises(ftplib.Error, self.client.sendcmd,
|
||||
'x' * self.client.maxline * 2)
|
||||
|
||||
def test_retrlines_too_long(self):
|
||||
self.client.sendcmd('SETLONGRETR %d' % (self.client.maxline * 2))
|
||||
received = []
|
||||
self.assertRaises(ftplib.Error,
|
||||
self.client.retrlines, 'retr', received.append)
|
||||
|
||||
def test_storlines_too_long(self):
|
||||
f = io.BytesIO(b'x' * self.client.maxline * 2)
|
||||
self.assertRaises(ftplib.Error, self.client.storlines, 'stor', f)
|
||||
|
||||
|
||||
class TestIPv6Environment(TestCase):
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@ def global_function():
|
|||
pass
|
||||
global inner_global_function
|
||||
def inner_global_function():
|
||||
def inner_function2():
|
||||
pass
|
||||
return inner_function2
|
||||
return LocalClass
|
||||
return lambda: inner_function
|
||||
|
||||
|
@ -120,6 +122,7 @@ class FunctionPropertiesTest(FuncAttrsTest):
|
|||
self.assertEqual(global_function()()().__qualname__,
|
||||
'global_function.<locals>.inner_function.<locals>.LocalClass')
|
||||
self.assertEqual(inner_global_function.__qualname__, 'inner_global_function')
|
||||
self.assertEqual(inner_global_function().__qualname__, 'inner_global_function.<locals>.inner_function2')
|
||||
self.b.__qualname__ = 'c'
|
||||
self.assertEqual(self.b.__qualname__, 'c')
|
||||
self.b.__qualname__ = 'd'
|
||||
|
|
|
@ -84,26 +84,30 @@ class HashLibTestCase(unittest.TestCase):
|
|||
if constructor:
|
||||
constructors.add(constructor)
|
||||
|
||||
def add_builtin_constructor(name):
|
||||
constructor = getattr(hashlib, "__get_builtin_constructor")(name)
|
||||
self.constructors_to_test[name].add(constructor)
|
||||
|
||||
_md5 = self._conditional_import_module('_md5')
|
||||
if _md5:
|
||||
self.constructors_to_test['md5'].add(_md5.md5)
|
||||
add_builtin_constructor('md5')
|
||||
_sha1 = self._conditional_import_module('_sha1')
|
||||
if _sha1:
|
||||
self.constructors_to_test['sha1'].add(_sha1.sha1)
|
||||
add_builtin_constructor('sha1')
|
||||
_sha256 = self._conditional_import_module('_sha256')
|
||||
if _sha256:
|
||||
self.constructors_to_test['sha224'].add(_sha256.sha224)
|
||||
self.constructors_to_test['sha256'].add(_sha256.sha256)
|
||||
add_builtin_constructor('sha224')
|
||||
add_builtin_constructor('sha256')
|
||||
_sha512 = self._conditional_import_module('_sha512')
|
||||
if _sha512:
|
||||
self.constructors_to_test['sha384'].add(_sha512.sha384)
|
||||
self.constructors_to_test['sha512'].add(_sha512.sha512)
|
||||
add_builtin_constructor('sha384')
|
||||
add_builtin_constructor('sha512')
|
||||
_sha3 = self._conditional_import_module('_sha3')
|
||||
if _sha3:
|
||||
self.constructors_to_test['sha3_224'].add(_sha3.sha3_224)
|
||||
self.constructors_to_test['sha3_256'].add(_sha3.sha3_256)
|
||||
self.constructors_to_test['sha3_384'].add(_sha3.sha3_384)
|
||||
self.constructors_to_test['sha3_512'].add(_sha3.sha3_512)
|
||||
add_builtin_constructor('sha3_224')
|
||||
add_builtin_constructor('sha3_256')
|
||||
add_builtin_constructor('sha3_384')
|
||||
add_builtin_constructor('sha3_512')
|
||||
|
||||
super(HashLibTestCase, self).__init__(*args, **kwargs)
|
||||
|
||||
|
@ -132,8 +136,10 @@ class HashLibTestCase(unittest.TestCase):
|
|||
self.assertRaises(TypeError, hashlib.new, 1)
|
||||
|
||||
def test_get_builtin_constructor(self):
|
||||
get_builtin_constructor = hashlib.__dict__[
|
||||
'__get_builtin_constructor']
|
||||
get_builtin_constructor = getattr(hashlib,
|
||||
'__get_builtin_constructor')
|
||||
builtin_constructor_cache = getattr(hashlib,
|
||||
'__builtin_constructor_cache')
|
||||
self.assertRaises(ValueError, get_builtin_constructor, 'test')
|
||||
try:
|
||||
import _md5
|
||||
|
@ -141,6 +147,8 @@ class HashLibTestCase(unittest.TestCase):
|
|||
pass
|
||||
# This forces an ImportError for "import _md5" statements
|
||||
sys.modules['_md5'] = None
|
||||
# clear the cache
|
||||
builtin_constructor_cache.clear()
|
||||
try:
|
||||
self.assertRaises(ValueError, get_builtin_constructor, 'md5')
|
||||
finally:
|
||||
|
@ -149,6 +157,9 @@ class HashLibTestCase(unittest.TestCase):
|
|||
else:
|
||||
del sys.modules['_md5']
|
||||
self.assertRaises(TypeError, get_builtin_constructor, 3)
|
||||
constructor = get_builtin_constructor('md5')
|
||||
self.assertIs(constructor, _md5.md5)
|
||||
self.assertEqual(sorted(builtin_constructor_cache), ['MD5', 'md5'])
|
||||
|
||||
def test_hexdigest(self):
|
||||
for cons in self.hash_constructors:
|
||||
|
|
|
@ -667,9 +667,19 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
return 'eggs'
|
||||
should_find_dca = inspect.Attribute('ham', 'data', VA, VA.__dict__['ham'])
|
||||
self.assertIn(should_find_dca, inspect.classify_class_attrs(VA))
|
||||
should_find_ga = inspect.Attribute('ham', 'data', VA, 'spam')
|
||||
should_find_ga = inspect.Attribute('ham', 'data', Meta, 'spam')
|
||||
self.assertIn(should_find_ga, inspect.classify_class_attrs(VA))
|
||||
|
||||
def test_classify_metaclass_class_attribute(self):
|
||||
class Meta(type):
|
||||
fish = 'slap'
|
||||
def __dir__(self):
|
||||
return ['__class__', '__modules__', '__name__', 'fish']
|
||||
class Class(metaclass=Meta):
|
||||
pass
|
||||
should_find = inspect.Attribute('fish', 'data', Meta, 'slap')
|
||||
self.assertIn(should_find, inspect.classify_class_attrs(Class))
|
||||
|
||||
def test_classify_VirtualAttribute(self):
|
||||
class Meta(type):
|
||||
def __dir__(cls):
|
||||
|
@ -680,7 +690,7 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
return super().__getattr(name)
|
||||
class Class(metaclass=Meta):
|
||||
pass
|
||||
should_find = inspect.Attribute('BOOM', 'data', Class, 42)
|
||||
should_find = inspect.Attribute('BOOM', 'data', Meta, 42)
|
||||
self.assertIn(should_find, inspect.classify_class_attrs(Class))
|
||||
|
||||
def test_classify_VirtualAttribute_multi_classes(self):
|
||||
|
@ -711,9 +721,9 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
class Class2(Class1, metaclass=Meta3):
|
||||
pass
|
||||
|
||||
should_find1 = inspect.Attribute('one', 'data', Class1, 1)
|
||||
should_find2 = inspect.Attribute('two', 'data', Class2, 2)
|
||||
should_find3 = inspect.Attribute('three', 'data', Class2, 3)
|
||||
should_find1 = inspect.Attribute('one', 'data', Meta1, 1)
|
||||
should_find2 = inspect.Attribute('two', 'data', Meta2, 2)
|
||||
should_find3 = inspect.Attribute('three', 'data', Meta3, 3)
|
||||
cca = inspect.classify_class_attrs(Class2)
|
||||
for sf in (should_find1, should_find2, should_find3):
|
||||
self.assertIn(sf, cca)
|
||||
|
|
|
@ -1319,6 +1319,11 @@ class IpaddrUnitTest(unittest.TestCase):
|
|||
self.assertEqual(True, ipaddress.ip_network(
|
||||
'127.42.0.0/16').is_loopback)
|
||||
self.assertEqual(False, ipaddress.ip_network('128.0.0.0').is_loopback)
|
||||
self.assertEqual(True, ipaddress.ip_network('100.64.0.0/10').is_private)
|
||||
self.assertEqual(True,
|
||||
ipaddress.ip_network('192.0.2.128/25').is_private)
|
||||
self.assertEqual(True,
|
||||
ipaddress.ip_network('192.0.3.0/24').is_global)
|
||||
|
||||
# test addresses
|
||||
self.assertEqual(True, ipaddress.ip_address('0.0.0.0').is_unspecified)
|
||||
|
@ -1384,6 +1389,10 @@ class IpaddrUnitTest(unittest.TestCase):
|
|||
self.assertEqual(False, ipaddress.ip_network('::1').is_unspecified)
|
||||
self.assertEqual(False, ipaddress.ip_network('::/127').is_unspecified)
|
||||
|
||||
self.assertEqual(True,
|
||||
ipaddress.ip_network('2001::1/128').is_private)
|
||||
self.assertEqual(True,
|
||||
ipaddress.ip_network('200::1/128').is_global)
|
||||
# test addresses
|
||||
self.assertEqual(True, ipaddress.ip_address('ffff::').is_multicast)
|
||||
self.assertEqual(True, ipaddress.ip_address(2**128 - 1).is_multicast)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import decimal
|
||||
from io import StringIO
|
||||
from io import StringIO, BytesIO
|
||||
from collections import OrderedDict
|
||||
from test.test_json import PyTest, CTest
|
||||
|
||||
|
@ -70,5 +70,26 @@ class TestDecode:
|
|||
msg = 'escape'
|
||||
self.assertRaisesRegex(ValueError, msg, self.loads, s)
|
||||
|
||||
def test_invalid_input_type(self):
|
||||
msg = 'the JSON object must be str'
|
||||
for value in [1, 3.14, b'bytes', b'\xff\x00', [], {}, None]:
|
||||
self.assertRaisesRegex(TypeError, msg, self.loads, value)
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
self.json.load(BytesIO(b'[1,2,3]'))
|
||||
|
||||
def test_string_with_utf8_bom(self):
|
||||
# see #18958
|
||||
bom_json = "[1,2,3]".encode('utf-8-sig').decode('utf-8')
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
self.loads(bom_json)
|
||||
self.assertIn('BOM', str(cm.exception))
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
self.json.load(StringIO(bom_json))
|
||||
self.assertIn('BOM', str(cm.exception))
|
||||
# make sure that the BOM is not detected in the middle of a string
|
||||
bom_in_str = '"{}"'.format(''.encode('utf-8-sig').decode('utf-8'))
|
||||
self.assertEqual(self.loads(bom_in_str), '\ufeff')
|
||||
self.assertEqual(self.json.load(StringIO(bom_in_str)), '\ufeff')
|
||||
|
||||
class TestPyDecode(TestDecode, PyTest): pass
|
||||
class TestCDecode(TestDecode, CTest): pass
|
||||
|
|
|
@ -91,15 +91,28 @@ class PlatformTest(unittest.TestCase):
|
|||
("CPython", "2.6.1", "tags/r261", "67515",
|
||||
('r261:67515', 'Dec 6 2008 15:26:00'),
|
||||
'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),
|
||||
|
||||
("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
|
||||
:
|
||||
("IronPython", "2.0.0", "", "", ("", ""),
|
||||
".NET 2.0.50727.3053"),
|
||||
|
||||
("2.6.1 (IronPython 2.6.1 (2.6.10920.0) on .NET 2.0.50727.1433)", None, "cli")
|
||||
:
|
||||
("IronPython", "2.6.1", "", "", ("", ""),
|
||||
".NET 2.0.50727.1433"),
|
||||
|
||||
("2.7.4 (IronPython 2.7.4 (2.7.0.40) on Mono 4.0.30319.1 (32-bit))", None, "cli")
|
||||
:
|
||||
("IronPython", "2.7.4", "", "", ("", ""),
|
||||
"Mono 4.0.30319.1 (32-bit)"),
|
||||
|
||||
("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
|
||||
('Jython', 'trunk', '6107'), "java1.5.0_16")
|
||||
:
|
||||
("Jython", "2.5.0", "trunk", "6107",
|
||||
('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"),
|
||||
|
||||
("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]",
|
||||
('PyPy', 'trunk', '63378'), self.save_platform)
|
||||
:
|
||||
|
|
|
@ -11,6 +11,7 @@ import re
|
|||
import string
|
||||
import test.support
|
||||
import time
|
||||
import types
|
||||
import unittest
|
||||
import xml.etree
|
||||
import textwrap
|
||||
|
@ -208,6 +209,75 @@ missing_pattern = "no Python documentation found for '%s'"
|
|||
# output pattern for module with bad imports
|
||||
badimport_pattern = "problem in %s - ImportError: No module named %r"
|
||||
|
||||
expected_dynamicattribute_pattern = """
|
||||
Help on class DA in module %s:
|
||||
|
||||
class DA(builtins.object)
|
||||
| Data descriptors defined here:
|
||||
|\x20\x20
|
||||
| __dict__%s
|
||||
|\x20\x20
|
||||
| __weakref__%s
|
||||
|\x20\x20
|
||||
| ham
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Data and other attributes inherited from Meta:
|
||||
|\x20\x20
|
||||
| ham = 'spam'
|
||||
""".strip()
|
||||
|
||||
expected_virtualattribute_pattern1 = """
|
||||
Help on class Class in module %s:
|
||||
|
||||
class Class(builtins.object)
|
||||
| Data and other attributes inherited from Meta:
|
||||
|\x20\x20
|
||||
| LIFE = 42
|
||||
""".strip()
|
||||
|
||||
expected_virtualattribute_pattern2 = """
|
||||
Help on class Class1 in module %s:
|
||||
|
||||
class Class1(builtins.object)
|
||||
| Data and other attributes inherited from Meta1:
|
||||
|\x20\x20
|
||||
| one = 1
|
||||
""".strip()
|
||||
|
||||
expected_virtualattribute_pattern3 = """
|
||||
Help on class Class2 in module %s:
|
||||
|
||||
class Class2(Class1)
|
||||
| Method resolution order:
|
||||
| Class2
|
||||
| Class1
|
||||
| builtins.object
|
||||
|\x20\x20
|
||||
| Data and other attributes inherited from Meta1:
|
||||
|\x20\x20
|
||||
| one = 1
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Data and other attributes inherited from Meta3:
|
||||
|\x20\x20
|
||||
| three = 3
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Data and other attributes inherited from Meta2:
|
||||
|\x20\x20
|
||||
| two = 2
|
||||
""".strip()
|
||||
|
||||
expected_missingattribute_pattern = """
|
||||
Help on class C in module %s:
|
||||
|
||||
class C(builtins.object)
|
||||
| Data and other attributes defined here:
|
||||
|\x20\x20
|
||||
| here = 'present!'
|
||||
""".strip()
|
||||
|
||||
def run_pydoc(module_name, *args, **env):
|
||||
"""
|
||||
Runs pydoc on the specified module. Returns the stripped
|
||||
|
@ -636,6 +706,127 @@ class TestHelper(unittest.TestCase):
|
|||
self.assertEqual(sorted(pydoc.Helper.keywords),
|
||||
sorted(keyword.kwlist))
|
||||
|
||||
class PydocWithMetaClasses(unittest.TestCase):
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __locals__ unexpectedly')
|
||||
def test_DynamicClassAttribute(self):
|
||||
class Meta(type):
|
||||
def __getattr__(self, name):
|
||||
if name == 'ham':
|
||||
return 'spam'
|
||||
return super().__getattr__(name)
|
||||
class DA(metaclass=Meta):
|
||||
@types.DynamicClassAttribute
|
||||
def ham(self):
|
||||
return 'eggs'
|
||||
expected_text_data_docstrings = tuple('\n | ' + s if s else ''
|
||||
for s in expected_data_docstrings)
|
||||
output = StringIO()
|
||||
helper = pydoc.Helper(output=output)
|
||||
helper(DA)
|
||||
expected_text = expected_dynamicattribute_pattern % (
|
||||
(__name__,) + expected_text_data_docstrings[:2])
|
||||
result = output.getvalue().strip()
|
||||
if result != expected_text:
|
||||
print_diffs(expected_text, result)
|
||||
self.fail("outputs are not equal, see diff above")
|
||||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __locals__ unexpectedly')
|
||||
def test_virtualClassAttributeWithOneMeta(self):
|
||||
class Meta(type):
|
||||
def __dir__(cls):
|
||||
return ['__class__', '__module__', '__name__', 'LIFE']
|
||||
def __getattr__(self, name):
|
||||
if name =='LIFE':
|
||||
return 42
|
||||
return super().__getattr(name)
|
||||
class Class(metaclass=Meta):
|
||||
pass
|
||||
output = StringIO()
|
||||
helper = pydoc.Helper(output=output)
|
||||
helper(Class)
|
||||
expected_text = expected_virtualattribute_pattern1 % __name__
|
||||
result = output.getvalue().strip()
|
||||
if result != expected_text:
|
||||
print_diffs(expected_text, result)
|
||||
self.fail("outputs are not equal, see diff above")
|
||||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __locals__ unexpectedly')
|
||||
def test_virtualClassAttributeWithTwoMeta(self):
|
||||
class Meta1(type):
|
||||
def __dir__(cls):
|
||||
return ['__class__', '__module__', '__name__', 'one']
|
||||
def __getattr__(self, name):
|
||||
if name =='one':
|
||||
return 1
|
||||
return super().__getattr__(name)
|
||||
class Meta2(type):
|
||||
def __dir__(cls):
|
||||
return ['__class__', '__module__', '__name__', 'two']
|
||||
def __getattr__(self, name):
|
||||
if name =='two':
|
||||
return 2
|
||||
return super().__getattr__(name)
|
||||
class Meta3(Meta1, Meta2):
|
||||
def __dir__(cls):
|
||||
return list(sorted(set(
|
||||
['__class__', '__module__', '__name__', 'three'] +
|
||||
Meta1.__dir__(cls) + Meta2.__dir__(cls))))
|
||||
def __getattr__(self, name):
|
||||
if name =='three':
|
||||
return 3
|
||||
return super().__getattr__(name)
|
||||
class Class1(metaclass=Meta1):
|
||||
pass
|
||||
class Class2(Class1, metaclass=Meta3):
|
||||
pass
|
||||
fail1 = fail2 = False
|
||||
output = StringIO()
|
||||
helper = pydoc.Helper(output=output)
|
||||
helper(Class1)
|
||||
expected_text1 = expected_virtualattribute_pattern2 % __name__
|
||||
result1 = output.getvalue().strip()
|
||||
if result1 != expected_text1:
|
||||
print_diffs(expected_text1, result1)
|
||||
fail1 = True
|
||||
output = StringIO()
|
||||
helper = pydoc.Helper(output=output)
|
||||
helper(Class2)
|
||||
expected_text2 = expected_virtualattribute_pattern3 % __name__
|
||||
result2 = output.getvalue().strip()
|
||||
if result2 != expected_text2:
|
||||
print_diffs(expected_text2, result2)
|
||||
fail2 = True
|
||||
if fail1 or fail2:
|
||||
self.fail("outputs are not equal, see diff above")
|
||||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __locals__ unexpectedly')
|
||||
def test_buggy_dir(self):
|
||||
class M(type):
|
||||
def __dir__(cls):
|
||||
return ['__class__', '__name__', 'missing', 'here']
|
||||
class C(metaclass=M):
|
||||
here = 'present!'
|
||||
output = StringIO()
|
||||
helper = pydoc.Helper(output=output)
|
||||
helper(C)
|
||||
expected_text = expected_missingattribute_pattern % __name__
|
||||
result = output.getvalue().strip()
|
||||
if result != expected_text:
|
||||
print_diffs(expected_text, result)
|
||||
self.fail("outputs are not equal, see diff above")
|
||||
|
||||
@reap_threads
|
||||
def test_main():
|
||||
try:
|
||||
|
@ -645,6 +836,7 @@ def test_main():
|
|||
PydocServerTest,
|
||||
PydocUrlHandlerTest,
|
||||
TestHelper,
|
||||
PydocWithMetaClasses,
|
||||
)
|
||||
finally:
|
||||
reap_children()
|
||||
|
|
|
@ -1104,6 +1104,28 @@ class ReTests(unittest.TestCase):
|
|||
self.assertEqual(re.compile(pattern, re.S).findall(b'xyz'),
|
||||
[b'xyz'], msg=pattern)
|
||||
|
||||
def test_match_repr(self):
|
||||
for string in '[abracadabra]', S('[abracadabra]'):
|
||||
m = re.search(r'(.+)(.*?)\1', string)
|
||||
self.assertEqual(repr(m), "<%s.%s object; "
|
||||
"span=(1, 12), match='abracadabra'>" %
|
||||
(type(m).__module__, type(m).__qualname__))
|
||||
for string in (b'[abracadabra]', B(b'[abracadabra]'),
|
||||
bytearray(b'[abracadabra]'),
|
||||
memoryview(b'[abracadabra]')):
|
||||
m = re.search(rb'(.+)(.*?)\1', string)
|
||||
self.assertEqual(repr(m), "<%s.%s object; "
|
||||
"span=(1, 12), match=b'abracadabra'>" %
|
||||
(type(m).__module__, type(m).__qualname__))
|
||||
|
||||
first, second = list(re.finditer("(aa)|(bb)", "aa bb"))
|
||||
self.assertEqual(repr(first), "<%s.%s object; "
|
||||
"span=(0, 2), match='aa'>" %
|
||||
(type(second).__module__, type(first).__qualname__))
|
||||
self.assertEqual(repr(second), "<%s.%s object; "
|
||||
"span=(3, 5), match='bb'>" %
|
||||
(type(second).__module__, type(second).__qualname__))
|
||||
|
||||
|
||||
def test_bug_2537(self):
|
||||
# issue 2537: empty submatches
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from test import support
|
||||
import time
|
||||
|
@ -129,6 +131,29 @@ class ResourceTest(unittest.TestCase):
|
|||
self.assertIsInstance(pagesize, int)
|
||||
self.assertGreaterEqual(pagesize, 0)
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'linux', 'test requires Linux')
|
||||
def test_linux_constants(self):
|
||||
self.assertIsInstance(resource.RLIMIT_MSGQUEUE, int)
|
||||
self.assertIsInstance(resource.RLIMIT_NICE, int)
|
||||
self.assertIsInstance(resource.RLIMIT_RTPRIO, int)
|
||||
self.assertIsInstance(resource.RLIMIT_RTTIME, int)
|
||||
self.assertIsInstance(resource.RLIMIT_SIGPENDING, int)
|
||||
|
||||
|
||||
@unittest.skipUnless(hasattr(resource, 'prlimit'), 'no prlimit')
|
||||
def test_prlimit(self):
|
||||
self.assertRaises(TypeError, resource.prlimit)
|
||||
if os.geteuid() != 0:
|
||||
self.assertRaises(PermissionError, resource.prlimit,
|
||||
1, resource.RLIMIT_AS)
|
||||
self.assertRaises(ProcessLookupError, resource.prlimit,
|
||||
-1, resource.RLIMIT_AS)
|
||||
limit = resource.getrlimit(resource.RLIMIT_AS)
|
||||
self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS), limit)
|
||||
self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS, limit),
|
||||
limit)
|
||||
|
||||
|
||||
def test_main(verbose=None):
|
||||
support.run_unittest(ResourceTest)
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import socket
|
||||
import select
|
||||
import selectors
|
||||
import telnetlib
|
||||
import time
|
||||
import contextlib
|
||||
|
||||
import unittest
|
||||
from unittest import TestCase
|
||||
from test import support
|
||||
threading = support.import_module('threading')
|
||||
|
@ -112,40 +111,32 @@ class TelnetAlike(telnetlib.Telnet):
|
|||
self._messages += out.getvalue()
|
||||
return
|
||||
|
||||
def mock_select(*s_args):
|
||||
block = False
|
||||
for l in s_args:
|
||||
for fob in l:
|
||||
if isinstance(fob, TelnetAlike):
|
||||
block = fob.sock.block
|
||||
if block:
|
||||
return [[], [], []]
|
||||
else:
|
||||
return s_args
|
||||
|
||||
class MockPoller(object):
|
||||
test_case = None # Set during TestCase setUp.
|
||||
class MockSelector(selectors.BaseSelector):
|
||||
|
||||
def __init__(self):
|
||||
self._file_objs = []
|
||||
super().__init__()
|
||||
self.keys = {}
|
||||
|
||||
def register(self, fd, eventmask):
|
||||
self.test_case.assertTrue(hasattr(fd, 'fileno'), fd)
|
||||
self.test_case.assertEqual(eventmask, select.POLLIN|select.POLLPRI)
|
||||
self._file_objs.append(fd)
|
||||
def register(self, fileobj, events, data=None):
|
||||
key = selectors.SelectorKey(fileobj, 0, events, data)
|
||||
self.keys[fileobj] = key
|
||||
return key
|
||||
|
||||
def poll(self, timeout=None):
|
||||
def unregister(self, fileobj):
|
||||
key = self.keys.pop(fileobj)
|
||||
return key
|
||||
|
||||
def select(self, timeout=None):
|
||||
block = False
|
||||
for fob in self._file_objs:
|
||||
if isinstance(fob, TelnetAlike):
|
||||
block = fob.sock.block
|
||||
for fileobj in self.keys:
|
||||
if isinstance(fileobj, TelnetAlike):
|
||||
block = fileobj.sock.block
|
||||
break
|
||||
if block:
|
||||
return []
|
||||
else:
|
||||
return zip(self._file_objs, [select.POLLIN]*len(self._file_objs))
|
||||
return [(key, key.events) for key in self.keys.values()]
|
||||
|
||||
def unregister(self, fd):
|
||||
self._file_objs.remove(fd)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def test_socket(reads):
|
||||
|
@ -159,7 +150,7 @@ def test_socket(reads):
|
|||
socket.create_connection = old_conn
|
||||
return
|
||||
|
||||
def test_telnet(reads=(), cls=TelnetAlike, use_poll=None):
|
||||
def test_telnet(reads=(), cls=TelnetAlike):
|
||||
''' return a telnetlib.Telnet object that uses a SocketStub with
|
||||
reads queued up to be read '''
|
||||
for x in reads:
|
||||
|
@ -167,29 +158,14 @@ def test_telnet(reads=(), cls=TelnetAlike, use_poll=None):
|
|||
with test_socket(reads):
|
||||
telnet = cls('dummy', 0)
|
||||
telnet._messages = '' # debuglevel output
|
||||
if use_poll is not None:
|
||||
if use_poll and not telnet._has_poll:
|
||||
raise unittest.SkipTest('select.poll() required.')
|
||||
telnet._has_poll = use_poll
|
||||
return telnet
|
||||
|
||||
|
||||
class ExpectAndReadTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.old_select = select.select
|
||||
select.select = mock_select
|
||||
self.old_poll = False
|
||||
if hasattr(select, 'poll'):
|
||||
self.old_poll = select.poll
|
||||
select.poll = MockPoller
|
||||
MockPoller.test_case = self
|
||||
|
||||
self.old_selector = telnetlib._TelnetSelector
|
||||
telnetlib._TelnetSelector = MockSelector
|
||||
def tearDown(self):
|
||||
if self.old_poll:
|
||||
MockPoller.test_case = None
|
||||
select.poll = self.old_poll
|
||||
select.select = self.old_select
|
||||
|
||||
telnetlib._TelnetSelector = self.old_selector
|
||||
|
||||
class ReadTests(ExpectAndReadTestCase):
|
||||
def test_read_until(self):
|
||||
|
@ -208,22 +184,6 @@ class ReadTests(ExpectAndReadTestCase):
|
|||
data = telnet.read_until(b'match')
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
def test_read_until_with_poll(self):
|
||||
"""Use select.poll() to implement telnet.read_until()."""
|
||||
want = [b'x' * 10, b'match', b'y' * 10]
|
||||
telnet = test_telnet(want, use_poll=True)
|
||||
select.select = lambda *_: self.fail('unexpected select() call.')
|
||||
data = telnet.read_until(b'match')
|
||||
self.assertEqual(data, b''.join(want[:-1]))
|
||||
|
||||
def test_read_until_with_select(self):
|
||||
"""Use select.select() to implement telnet.read_until()."""
|
||||
want = [b'x' * 10, b'match', b'y' * 10]
|
||||
telnet = test_telnet(want, use_poll=False)
|
||||
if self.old_poll:
|
||||
select.poll = lambda *_: self.fail('unexpected poll() call.')
|
||||
data = telnet.read_until(b'match')
|
||||
self.assertEqual(data, b''.join(want[:-1]))
|
||||
|
||||
def test_read_all(self):
|
||||
"""
|
||||
|
@ -427,23 +387,6 @@ class ExpectTests(ExpectAndReadTestCase):
|
|||
(_,_,data) = telnet.expect([b'match'])
|
||||
self.assertEqual(data, b''.join(want[:-1]))
|
||||
|
||||
def test_expect_with_poll(self):
|
||||
"""Use select.poll() to implement telnet.expect()."""
|
||||
want = [b'x' * 10, b'match', b'y' * 10]
|
||||
telnet = test_telnet(want, use_poll=True)
|
||||
select.select = lambda *_: self.fail('unexpected select() call.')
|
||||
(_,_,data) = telnet.expect([b'match'])
|
||||
self.assertEqual(data, b''.join(want[:-1]))
|
||||
|
||||
def test_expect_with_select(self):
|
||||
"""Use select.select() to implement telnet.expect()."""
|
||||
want = [b'x' * 10, b'match', b'y' * 10]
|
||||
telnet = test_telnet(want, use_poll=False)
|
||||
if self.old_poll:
|
||||
select.poll = lambda *_: self.fail('unexpected poll() call.')
|
||||
(_,_,data) = telnet.expect([b'match'])
|
||||
self.assertEqual(data, b''.join(want[:-1]))
|
||||
|
||||
|
||||
def test_main(verbose=None):
|
||||
support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests,
|
||||
|
|
|
@ -591,6 +591,34 @@ class PyZipFileTests(unittest.TestCase):
|
|||
self.assertCompiledIn('email/__init__.py', names)
|
||||
self.assertCompiledIn('email/mime/text.py', names)
|
||||
|
||||
def test_write_filtered_python_package(self):
|
||||
import test
|
||||
packagedir = os.path.dirname(test.__file__)
|
||||
|
||||
with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
|
||||
|
||||
# first make sure that the test folder gives error messages
|
||||
# (on the badsyntax_... files)
|
||||
with captured_stdout() as reportSIO:
|
||||
zipfp.writepy(packagedir)
|
||||
reportStr = reportSIO.getvalue()
|
||||
self.assertTrue('SyntaxError' in reportStr)
|
||||
|
||||
# then check that the filter works on the whole package
|
||||
with captured_stdout() as reportSIO:
|
||||
zipfp.writepy(packagedir, filterfunc=lambda whatever: False)
|
||||
reportStr = reportSIO.getvalue()
|
||||
self.assertTrue('SyntaxError' not in reportStr)
|
||||
|
||||
# then check that the filter works on individual files
|
||||
with captured_stdout() as reportSIO:
|
||||
zipfp.writepy(packagedir, filterfunc=lambda fn:
|
||||
'bad' not in fn)
|
||||
reportStr = reportSIO.getvalue()
|
||||
if reportStr:
|
||||
print(reportStr)
|
||||
self.assertTrue('SyntaxError' not in reportStr)
|
||||
|
||||
def test_write_with_optimization(self):
|
||||
import email
|
||||
packagedir = os.path.dirname(email.__file__)
|
||||
|
@ -630,6 +658,26 @@ class PyZipFileTests(unittest.TestCase):
|
|||
finally:
|
||||
shutil.rmtree(TESTFN2)
|
||||
|
||||
def test_write_python_directory_filtered(self):
|
||||
os.mkdir(TESTFN2)
|
||||
try:
|
||||
with open(os.path.join(TESTFN2, "mod1.py"), "w") as fp:
|
||||
fp.write("print(42)\n")
|
||||
|
||||
with open(os.path.join(TESTFN2, "mod2.py"), "w") as fp:
|
||||
fp.write("print(42 * 42)\n")
|
||||
|
||||
with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
|
||||
zipfp.writepy(TESTFN2, filterfunc=lambda fn:
|
||||
not fn.endswith('mod2.py'))
|
||||
|
||||
names = zipfp.namelist()
|
||||
self.assertCompiledIn('mod1.py', names)
|
||||
self.assertNotIn('mod2.py', names)
|
||||
|
||||
finally:
|
||||
shutil.rmtree(TESTFN2)
|
||||
|
||||
def test_write_non_pyfile(self):
|
||||
with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
|
||||
with open(TESTFN, 'w') as f:
|
||||
|
|
|
@ -1566,7 +1566,7 @@ class PyZipFile(ZipFile):
|
|||
allowZip64=allowZip64)
|
||||
self._optimize = optimize
|
||||
|
||||
def writepy(self, pathname, basename=""):
|
||||
def writepy(self, pathname, basename="", filterfunc=None):
|
||||
"""Add all files from "pathname" to the ZIP archive.
|
||||
|
||||
If pathname is a package directory, search the directory and
|
||||
|
@ -1577,7 +1577,14 @@ class PyZipFile(ZipFile):
|
|||
archive. Added modules are always module.pyo or module.pyc.
|
||||
This method will compile the module.py into module.pyc if
|
||||
necessary.
|
||||
If filterfunc(pathname) is given, it is called with every argument.
|
||||
When it is False, the file or directory is skipped.
|
||||
"""
|
||||
if filterfunc and not filterfunc(pathname):
|
||||
if self.debug:
|
||||
label = 'path' if os.path.isdir(pathname) else 'file'
|
||||
print('%s "%s" skipped by filterfunc' % (label, pathname))
|
||||
return
|
||||
dir, name = os.path.split(pathname)
|
||||
if os.path.isdir(pathname):
|
||||
initname = os.path.join(pathname, "__init__.py")
|
||||
|
@ -1602,8 +1609,13 @@ class PyZipFile(ZipFile):
|
|||
if os.path.isdir(path):
|
||||
if os.path.isfile(os.path.join(path, "__init__.py")):
|
||||
# This is a package directory, add it
|
||||
self.writepy(path, basename) # Recursive call
|
||||
self.writepy(path, basename,
|
||||
filterfunc=filterfunc) # Recursive call
|
||||
elif ext == ".py":
|
||||
if filterfunc and not filterfunc(path):
|
||||
if self.debug:
|
||||
print('file "%s" skipped by filterfunc' % path)
|
||||
continue
|
||||
fname, arcname = self._get_codename(path[0:-3],
|
||||
basename)
|
||||
if self.debug:
|
||||
|
@ -1617,6 +1629,10 @@ class PyZipFile(ZipFile):
|
|||
path = os.path.join(pathname, filename)
|
||||
root, ext = os.path.splitext(filename)
|
||||
if ext == ".py":
|
||||
if filterfunc and not filterfunc(path):
|
||||
if self.debug:
|
||||
print('file "%s" skipped by filterfunc' % path)
|
||||
continue
|
||||
fname, arcname = self._get_codename(path[0:-3],
|
||||
basename)
|
||||
if self.debug:
|
||||
|
|
|
@ -818,6 +818,7 @@ Nick Mathewson
|
|||
Simon Mathieu
|
||||
Laura Matson
|
||||
Graham Matthews
|
||||
Martin Matusiak
|
||||
Dieter Maurer
|
||||
Daniel May
|
||||
Madison May
|
||||
|
|
39
Misc/NEWS
39
Misc/NEWS
|
@ -3,19 +3,52 @@ Python News
|
|||
+++++++++++
|
||||
|
||||
What's New in Python 3.4.0 Beta 1?
|
||||
================================
|
||||
==================================
|
||||
|
||||
Projected release date: 2013-11-24
|
||||
|
||||
Core and Builtins
|
||||
-----------------
|
||||
|
||||
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
|
||||
Python executable and not removed by the linker's optimizer.
|
||||
|
||||
- Issue #19306: Add extra hints to the faulthandler module's stack
|
||||
dumps that these are "upside down".
|
||||
|
||||
Library
|
||||
-------
|
||||
|
||||
- Issue #16595: Add prlimit() to resource module.
|
||||
|
||||
- Issue #19324: Expose Linux-specific constants in resource module.
|
||||
|
||||
- Issue #17400: ipaddress should make it easy to identify rfc6598 addresses.
|
||||
|
||||
- Load SSL's error strings in hashlib.
|
||||
|
||||
- Issue #18527: Upgrade internal copy of zlib to 1.2.8.
|
||||
|
||||
- Issue #19274: Add a filterfunc parameter to PyZipFile.writepy.
|
||||
|
||||
- Issue #8964: fix platform._sys_version to handle IronPython 2.6+.
|
||||
Patch by Martin Matusiak.
|
||||
|
||||
- Issue #18958: Improve error message for json.load(s) while passing a string
|
||||
that starts with a UTF-8 BOM.
|
||||
|
||||
- Issue #19307: Improve error message for json.load(s) while passing objects
|
||||
of the wrong type.
|
||||
|
||||
- Issue #16038: CVE-2013-1752: ftplib: Limit amount of data read by
|
||||
limiting the call to readline(). Original patch by Michał
|
||||
Jastrzębski and Giampaolo Rodola.
|
||||
|
||||
- Issue #17087: Improved the repr for regular expression match objects.
|
||||
|
||||
|
||||
What's New in Python 3.4.0 Alpha 4?
|
||||
================================
|
||||
===================================
|
||||
|
||||
Release date: 2013-10-20
|
||||
|
||||
|
@ -25,7 +58,7 @@ Core and Builtins
|
|||
- Issue #19301: Give classes and functions that are explicitly marked global a
|
||||
global qualname.
|
||||
|
||||
- Issue #19279: UTF-7 decoder no more produces illegal strings.
|
||||
- Issue #19279: UTF-7 decoder no longer produces illegal strings.
|
||||
|
||||
- Issue #16612: Add "Argument Clinic", a compile-time preprocessor for
|
||||
C files to generate argument parsing code. (See PEP 436.)
|
||||
|
|
|
@ -513,7 +513,8 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
|
|||
* Also OpenSSL < 1.0 don't provide PKCS5_PBKDF2_HMAC(), only
|
||||
* PKCS5_PBKDF2_SHA1.
|
||||
*/
|
||||
int PKCS5_PBKDF2_HMAC_fast(const char *pass, int passlen,
|
||||
static int
|
||||
PKCS5_PBKDF2_HMAC_fast(const char *pass, int passlen,
|
||||
const unsigned char *salt, int saltlen,
|
||||
int iter, const EVP_MD *digest,
|
||||
int keylen, unsigned char *out)
|
||||
|
@ -846,6 +847,7 @@ PyInit__hashlib(void)
|
|||
PyObject *m, *openssl_md_meth_names;
|
||||
|
||||
OpenSSL_add_all_digests();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
/* TODO build EVP_functions openssl_* entries dynamically based
|
||||
* on what hashes are supported rather than listing many
|
||||
|
@ -870,10 +872,8 @@ PyInit__hashlib(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if HASH_OBJ_CONSTRUCTOR
|
||||
Py_INCREF(&EVPtype);
|
||||
Py_INCREF((PyObject *)&EVPtype);
|
||||
PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype);
|
||||
#endif
|
||||
|
||||
/* these constants are used by the convenience constructors */
|
||||
INIT_CONSTRUCTOR_CONSTANTS(md5);
|
||||
|
|
|
@ -576,10 +576,18 @@ static struct PyModuleDef _SHA3module = {
|
|||
PyMODINIT_FUNC
|
||||
PyInit__sha3(void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
Py_TYPE(&SHA3type) = &PyType_Type;
|
||||
if (PyType_Ready(&SHA3type) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyModule_Create(&_SHA3module);
|
||||
m = PyModule_Create(&_SHA3module);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF((PyObject *)&SHA3type);
|
||||
PyModule_AddObject(m, "SHA3Type", (PyObject *)&SHA3type);
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -3637,6 +3637,22 @@ match_regs_get(MatchObject *self)
|
|||
return match_regs(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
match_repr(MatchObject *self)
|
||||
{
|
||||
PyObject *result;
|
||||
PyObject *group0 = match_getslice_by_index(self, 0, Py_None);
|
||||
if (group0 == NULL)
|
||||
return NULL;
|
||||
result = PyUnicode_FromFormat(
|
||||
"<%s object; span=(%d, %d), match=%.50R>",
|
||||
Py_TYPE(self)->tp_name,
|
||||
self->mark[0], self->mark[1], group0);
|
||||
Py_DECREF(group0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static PyGetSetDef match_getset[] = {
|
||||
{"lastindex", (getter)match_lastindex_get, (setter)NULL},
|
||||
{"lastgroup", (getter)match_lastgroup_get, (setter)NULL},
|
||||
|
@ -3665,7 +3681,7 @@ static PyTypeObject Match_Type = {
|
|||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_reserved */
|
||||
0, /* tp_repr */
|
||||
(reprfunc)match_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
|
|
|
@ -572,8 +572,17 @@ static struct PyModuleDef _md5module = {
|
|||
PyMODINIT_FUNC
|
||||
PyInit__md5(void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
Py_TYPE(&MD5type) = &PyType_Type;
|
||||
if (PyType_Ready(&MD5type) < 0)
|
||||
return NULL;
|
||||
return PyModule_Create(&_md5module);
|
||||
|
||||
m = PyModule_Create(&_md5module);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF((PyObject *)&MD5type);
|
||||
PyModule_AddObject(m, "MD5Type", (PyObject *)&MD5type);
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -106,6 +106,44 @@ resource_getrusage(PyObject *self, PyObject *args)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
py2rlimit(PyObject *curobj, PyObject *maxobj, struct rlimit *rl_out)
|
||||
{
|
||||
#if !defined(HAVE_LARGEFILE_SUPPORT)
|
||||
rl_out->rlim_cur = PyLong_AsLong(curobj);
|
||||
if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred())
|
||||
return -1;
|
||||
rl_out->rlim_max = PyLong_AsLong(maxobj);
|
||||
if (rl_out->rlim_max == (rlim_t)-1 && PyErr_Occurred())
|
||||
return -1;
|
||||
#else
|
||||
/* The limits are probably bigger than a long */
|
||||
rl_out->rlim_cur = PyLong_AsLongLong(curobj);
|
||||
if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred())
|
||||
return -1;
|
||||
rl_out->rlim_max = PyLong_AsLongLong(maxobj);
|
||||
if (rl_out->rlim_max == (rlim_t)-1 && PyErr_Occurred())
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
rl_out->rlim_cur = rl_out->rlim_cur & RLIM_INFINITY;
|
||||
rl_out->rlim_max = rl_out->rlim_max & RLIM_INFINITY;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
rlimit2py(struct rlimit rl)
|
||||
{
|
||||
#if defined(HAVE_LONG_LONG)
|
||||
if (sizeof(rl.rlim_cur) > sizeof(long)) {
|
||||
return Py_BuildValue("LL",
|
||||
(PY_LONG_LONG) rl.rlim_cur,
|
||||
(PY_LONG_LONG) rl.rlim_max);
|
||||
}
|
||||
#endif
|
||||
return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
resource_getrlimit(PyObject *self, PyObject *args)
|
||||
|
@ -126,15 +164,7 @@ resource_getrlimit(PyObject *self, PyObject *args)
|
|||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(HAVE_LONG_LONG)
|
||||
if (sizeof(rl.rlim_cur) > sizeof(long)) {
|
||||
return Py_BuildValue("LL",
|
||||
(PY_LONG_LONG) rl.rlim_cur,
|
||||
(PY_LONG_LONG) rl.rlim_max);
|
||||
}
|
||||
#endif
|
||||
return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max);
|
||||
return rlimit2py(rl);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -166,25 +196,10 @@ resource_setrlimit(PyObject *self, PyObject *args)
|
|||
curobj = PyTuple_GET_ITEM(limits, 0);
|
||||
maxobj = PyTuple_GET_ITEM(limits, 1);
|
||||
|
||||
#if !defined(HAVE_LARGEFILE_SUPPORT)
|
||||
rl.rlim_cur = PyLong_AsLong(curobj);
|
||||
if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred())
|
||||
if (py2rlimit(curobj, maxobj, &rl) < 0) {
|
||||
goto error;
|
||||
rl.rlim_max = PyLong_AsLong(maxobj);
|
||||
if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred())
|
||||
goto error;
|
||||
#else
|
||||
/* The limits are probably bigger than a long */
|
||||
rl.rlim_cur = PyLong_AsLongLong(curobj);
|
||||
if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred())
|
||||
goto error;
|
||||
rl.rlim_max = PyLong_AsLongLong(maxobj);
|
||||
if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred())
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
|
||||
rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY;
|
||||
rl.rlim_max = rl.rlim_max & RLIM_INFINITY;
|
||||
if (setrlimit(resource, &rl) == -1) {
|
||||
if (errno == EINVAL)
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
@ -205,6 +220,48 @@ resource_setrlimit(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PRLIMIT
|
||||
static PyObject *
|
||||
resource_prlimit(PyObject *self, PyObject *args)
|
||||
{
|
||||
struct rlimit old_limit, new_limit;
|
||||
int resource, retval;
|
||||
pid_t pid;
|
||||
PyObject *curobj=NULL, *maxobj=NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i|(OO):prlimit",
|
||||
&pid, &resource, &curobj, &maxobj))
|
||||
return NULL;
|
||||
|
||||
if (resource < 0 || resource >= RLIM_NLIMITS) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"invalid resource specified");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (curobj != NULL) {
|
||||
if (py2rlimit(curobj, maxobj, &new_limit) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
retval = prlimit(pid, resource, &new_limit, &old_limit);
|
||||
}
|
||||
else {
|
||||
retval = prlimit(pid, resource, NULL, &old_limit);
|
||||
}
|
||||
|
||||
if (retval == -1) {
|
||||
if (errno == EINVAL) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"current limit exceeds maximum limit");
|
||||
} else {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return rlimit2py(old_limit);
|
||||
}
|
||||
#endif /* HAVE_PRLIMIT */
|
||||
|
||||
static PyObject *
|
||||
resource_getpagesize(PyObject *self, PyObject *unused)
|
||||
{
|
||||
|
@ -229,6 +286,9 @@ static struct PyMethodDef
|
|||
resource_methods[] = {
|
||||
{"getrusage", resource_getrusage, METH_VARARGS},
|
||||
{"getrlimit", resource_getrlimit, METH_VARARGS},
|
||||
#ifdef HAVE_PRLIMIT
|
||||
{"prlimit", resource_prlimit, METH_VARARGS},
|
||||
#endif
|
||||
{"setrlimit", resource_setrlimit, METH_VARARGS},
|
||||
{"getpagesize", resource_getpagesize, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
|
@ -326,6 +386,28 @@ PyInit_resource(void)
|
|||
PyModule_AddIntMacro(m, RLIMIT_SBSIZE);
|
||||
#endif
|
||||
|
||||
/* Linux specific */
|
||||
#ifdef RLIMIT_MSGQUEUE
|
||||
PyModule_AddIntMacro(m, RLIMIT_MSGQUEUE);
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_NICE
|
||||
PyModule_AddIntMacro(m, RLIMIT_NICE);
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_RTPRIO
|
||||
PyModule_AddIntMacro(m, RLIMIT_RTPRIO);
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_RTTIME
|
||||
PyModule_AddIntMacro(m, RLIMIT_RTTIME);
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_SIGPENDING
|
||||
PyModule_AddIntMacro(m, RLIMIT_SIGPENDING);
|
||||
#endif
|
||||
|
||||
/* target */
|
||||
#ifdef RUSAGE_SELF
|
||||
PyModule_AddIntMacro(m, RUSAGE_SELF);
|
||||
#endif
|
||||
|
|
|
@ -544,8 +544,17 @@ static struct PyModuleDef _sha1module = {
|
|||
PyMODINIT_FUNC
|
||||
PyInit__sha1(void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
Py_TYPE(&SHA1type) = &PyType_Type;
|
||||
if (PyType_Ready(&SHA1type) < 0)
|
||||
return NULL;
|
||||
return PyModule_Create(&_sha1module);
|
||||
|
||||
m = PyModule_Create(&_sha1module);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF((PyObject *)&SHA1type);
|
||||
PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type);
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -706,11 +706,23 @@ static struct PyModuleDef _sha256module = {
|
|||
PyMODINIT_FUNC
|
||||
PyInit__sha256(void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
Py_TYPE(&SHA224type) = &PyType_Type;
|
||||
if (PyType_Ready(&SHA224type) < 0)
|
||||
return NULL;
|
||||
Py_TYPE(&SHA256type) = &PyType_Type;
|
||||
if (PyType_Ready(&SHA256type) < 0)
|
||||
return NULL;
|
||||
return PyModule_Create(&_sha256module);
|
||||
|
||||
m = PyModule_Create(&_sha256module);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF((PyObject *)&SHA224type);
|
||||
PyModule_AddObject(m, "SHA224Type", (PyObject *)&SHA224type);
|
||||
Py_INCREF((PyObject *)&SHA256type);
|
||||
PyModule_AddObject(m, "SHA256Type", (PyObject *)&SHA256type);
|
||||
return m;
|
||||
|
||||
}
|
||||
|
|
|
@ -772,13 +772,24 @@ static struct PyModuleDef _sha512module = {
|
|||
PyMODINIT_FUNC
|
||||
PyInit__sha512(void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
Py_TYPE(&SHA384type) = &PyType_Type;
|
||||
if (PyType_Ready(&SHA384type) < 0)
|
||||
return NULL;
|
||||
Py_TYPE(&SHA512type) = &PyType_Type;
|
||||
if (PyType_Ready(&SHA512type) < 0)
|
||||
return NULL;
|
||||
return PyModule_Create(&_sha512module);
|
||||
|
||||
m = PyModule_Create(&_sha512module);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF((PyObject *)&SHA384type);
|
||||
PyModule_AddObject(m, "SHA384Type", (PyObject *)&SHA384type);
|
||||
Py_INCREF((PyObject *)&SHA512type);
|
||||
PyModule_AddObject(m, "SHA512Type", (PyObject *)&SHA512type);
|
||||
return m;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,276 @@
|
|||
|
||||
ChangeLog file for zlib
|
||||
|
||||
Changes in 1.2.8 (28 Apr 2013)
|
||||
- Update contrib/minizip/iowin32.c for Windows RT [Vollant]
|
||||
- Do not force Z_CONST for C++
|
||||
- Clean up contrib/vstudio [Ro§]
|
||||
- Correct spelling error in zlib.h
|
||||
- Fix mixed line endings in contrib/vstudio
|
||||
|
||||
Changes in 1.2.7.3 (13 Apr 2013)
|
||||
- Fix version numbers and DLL names in contrib/vstudio/*/zlib.rc
|
||||
|
||||
Changes in 1.2.7.2 (13 Apr 2013)
|
||||
- Change check for a four-byte type back to hexadecimal
|
||||
- Fix typo in win32/Makefile.msc
|
||||
- Add casts in gzwrite.c for pointer differences
|
||||
|
||||
Changes in 1.2.7.1 (24 Mar 2013)
|
||||
- Replace use of unsafe string functions with snprintf if available
|
||||
- Avoid including stddef.h on Windows for Z_SOLO compile [Niessink]
|
||||
- Fix gzgetc undefine when Z_PREFIX set [Turk]
|
||||
- Eliminate use of mktemp in Makefile (not always available)
|
||||
- Fix bug in 'F' mode for gzopen()
|
||||
- Add inflateGetDictionary() function
|
||||
- Correct comment in deflate.h
|
||||
- Use _snprintf for snprintf in Microsoft C
|
||||
- On Darwin, only use /usr/bin/libtool if libtool is not Apple
|
||||
- Delete "--version" file if created by "ar --version" [Richard G.]
|
||||
- Fix configure check for veracity of compiler error return codes
|
||||
- Fix CMake compilation of static lib for MSVC2010 x64
|
||||
- Remove unused variable in infback9.c
|
||||
- Fix argument checks in gzlog_compress() and gzlog_write()
|
||||
- Clean up the usage of z_const and respect const usage within zlib
|
||||
- Clean up examples/gzlog.[ch] comparisons of different types
|
||||
- Avoid shift equal to bits in type (caused endless loop)
|
||||
- Fix unintialized value bug in gzputc() introduced by const patches
|
||||
- Fix memory allocation error in examples/zran.c [Nor]
|
||||
- Fix bug where gzopen(), gzclose() would write an empty file
|
||||
- Fix bug in gzclose() when gzwrite() runs out of memory
|
||||
- Check for input buffer malloc failure in examples/gzappend.c
|
||||
- Add note to contrib/blast to use binary mode in stdio
|
||||
- Fix comparisons of differently signed integers in contrib/blast
|
||||
- Check for invalid code length codes in contrib/puff
|
||||
- Fix serious but very rare decompression bug in inftrees.c
|
||||
- Update inflateBack() comments, since inflate() can be faster
|
||||
- Use underscored I/O function names for WINAPI_FAMILY
|
||||
- Add _tr_flush_bits to the external symbols prefixed by --zprefix
|
||||
- Add contrib/vstudio/vc10 pre-build step for static only
|
||||
- Quote --version-script argument in CMakeLists.txt
|
||||
- Don't specify --version-script on Apple platforms in CMakeLists.txt
|
||||
- Fix casting error in contrib/testzlib/testzlib.c
|
||||
- Fix types in contrib/minizip to match result of get_crc_table()
|
||||
- Simplify contrib/vstudio/vc10 with 'd' suffix
|
||||
- Add TOP support to win32/Makefile.msc
|
||||
- Suport i686 and amd64 assembler builds in CMakeLists.txt
|
||||
- Fix typos in the use of _LARGEFILE64_SOURCE in zconf.h
|
||||
- Add vc11 and vc12 build files to contrib/vstudio
|
||||
- Add gzvprintf() as an undocumented function in zlib
|
||||
- Fix configure for Sun shell
|
||||
- Remove runtime check in configure for four-byte integer type
|
||||
- Add casts and consts to ease user conversion to C++
|
||||
- Add man pages for minizip and miniunzip
|
||||
- In Makefile uninstall, don't rm if preceding cd fails
|
||||
- Do not return Z_BUF_ERROR if deflateParam() has nothing to write
|
||||
|
||||
Changes in 1.2.7 (2 May 2012)
|
||||
- Replace use of memmove() with a simple copy for portability
|
||||
- Test for existence of strerror
|
||||
- Restore gzgetc_ for backward compatibility with 1.2.6
|
||||
- Fix build with non-GNU make on Solaris
|
||||
- Require gcc 4.0 or later on Mac OS X to use the hidden attribute
|
||||
- Include unistd.h for Watcom C
|
||||
- Use __WATCOMC__ instead of __WATCOM__
|
||||
- Do not use the visibility attribute if NO_VIZ defined
|
||||
- Improve the detection of no hidden visibility attribute
|
||||
- Avoid using __int64 for gcc or solo compilation
|
||||
- Cast to char * in gzprintf to avoid warnings [Zinser]
|
||||
- Fix make_vms.com for VAX [Zinser]
|
||||
- Don't use library or built-in byte swaps
|
||||
- Simplify test and use of gcc hidden attribute
|
||||
- Fix bug in gzclose_w() when gzwrite() fails to allocate memory
|
||||
- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen()
|
||||
- Fix bug in test/minigzip.c for configure --solo
|
||||
- Fix contrib/vstudio project link errors [Mohanathas]
|
||||
- Add ability to choose the builder in make_vms.com [Schweda]
|
||||
- Add DESTDIR support to mingw32 win32/Makefile.gcc
|
||||
- Fix comments in win32/Makefile.gcc for proper usage
|
||||
- Allow overriding the default install locations for cmake
|
||||
- Generate and install the pkg-config file with cmake
|
||||
- Build both a static and a shared version of zlib with cmake
|
||||
- Include version symbols for cmake builds
|
||||
- If using cmake with MSVC, add the source directory to the includes
|
||||
- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta]
|
||||
- Move obsolete emx makefile to old [Truta]
|
||||
- Allow the use of -Wundef when compiling or using zlib
|
||||
- Avoid the use of the -u option with mktemp
|
||||
- Improve inflate() documentation on the use of Z_FINISH
|
||||
- Recognize clang as gcc
|
||||
- Add gzopen_w() in Windows for wide character path names
|
||||
- Rename zconf.h in CMakeLists.txt to move it out of the way
|
||||
- Add source directory in CMakeLists.txt for building examples
|
||||
- Look in build directory for zlib.pc in CMakeLists.txt
|
||||
- Remove gzflags from zlibvc.def in vc9 and vc10
|
||||
- Fix contrib/minizip compilation in the MinGW environment
|
||||
- Update ./configure for Solaris, support --64 [Mooney]
|
||||
- Remove -R. from Solaris shared build (possible security issue)
|
||||
- Avoid race condition for parallel make (-j) running example
|
||||
- Fix type mismatch between get_crc_table() and crc_table
|
||||
- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler]
|
||||
- Fix the path to zlib.map in CMakeLists.txt
|
||||
- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe]
|
||||
- Add instructions to win32/Makefile.gcc for shared install [Torri]
|
||||
|
||||
Changes in 1.2.6.1 (12 Feb 2012)
|
||||
- Avoid the use of the Objective-C reserved name "id"
|
||||
- Include io.h in gzguts.h for Microsoft compilers
|
||||
- Fix problem with ./configure --prefix and gzgetc macro
|
||||
- Include gz_header definition when compiling zlib solo
|
||||
- Put gzflags() functionality back in zutil.c
|
||||
- Avoid library header include in crc32.c for Z_SOLO
|
||||
- Use name in GCC_CLASSIC as C compiler for coverage testing, if set
|
||||
- Minor cleanup in contrib/minizip/zip.c [Vollant]
|
||||
- Update make_vms.com [Zinser]
|
||||
- Remove unnecessary gzgetc_ function
|
||||
- Use optimized byte swap operations for Microsoft and GNU [Snyder]
|
||||
- Fix minor typo in zlib.h comments [Rzesniowiecki]
|
||||
|
||||
Changes in 1.2.6 (29 Jan 2012)
|
||||
- Update the Pascal interface in contrib/pascal
|
||||
- Fix function numbers for gzgetc_ in zlibvc.def files
|
||||
- Fix configure.ac for contrib/minizip [Schiffer]
|
||||
- Fix large-entry detection in minizip on 64-bit systems [Schiffer]
|
||||
- Have ./configure use the compiler return code for error indication
|
||||
- Fix CMakeLists.txt for cross compilation [McClure]
|
||||
- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes]
|
||||
- Fix compilation of contrib/minizip on FreeBSD [Marquez]
|
||||
- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath]
|
||||
- Include io.h for Turbo C / Borland C on all platforms [Truta]
|
||||
- Make version explicit in contrib/minizip/configure.ac [Bosmans]
|
||||
- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant]
|
||||
- Minor cleanup up contrib/minizip/unzip.c [Vollant]
|
||||
- Fix bug when compiling minizip with C++ [Vollant]
|
||||
- Protect for long name and extra fields in contrib/minizip [Vollant]
|
||||
- Avoid some warnings in contrib/minizip [Vollant]
|
||||
- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip
|
||||
- Add missing libs to minizip linker command
|
||||
- Add support for VPATH builds in contrib/minizip
|
||||
- Add an --enable-demos option to contrib/minizip/configure
|
||||
- Add the generation of configure.log by ./configure
|
||||
- Exit when required parameters not provided to win32/Makefile.gcc
|
||||
- Have gzputc return the character written instead of the argument
|
||||
- Use the -m option on ldconfig for BSD systems [Tobias]
|
||||
- Correct in zlib.map when deflateResetKeep was added
|
||||
|
||||
Changes in 1.2.5.3 (15 Jan 2012)
|
||||
- Restore gzgetc function for binary compatibility
|
||||
- Do not use _lseeki64 under Borland C++ [Truta]
|
||||
- Update win32/Makefile.msc to build test/*.c [Truta]
|
||||
- Remove old/visualc6 given CMakefile and other alternatives
|
||||
- Update AS400 build files and documentation [Monnerat]
|
||||
- Update win32/Makefile.gcc to build test/*.c [Truta]
|
||||
- Permit stronger flushes after Z_BLOCK flushes
|
||||
- Avoid extraneous empty blocks when doing empty flushes
|
||||
- Permit Z_NULL arguments to deflatePending
|
||||
- Allow deflatePrime() to insert bits in the middle of a stream
|
||||
- Remove second empty static block for Z_PARTIAL_FLUSH
|
||||
- Write out all of the available bits when using Z_BLOCK
|
||||
- Insert the first two strings in the hash table after a flush
|
||||
|
||||
Changes in 1.2.5.2 (17 Dec 2011)
|
||||
- fix ld error: unable to find version dependency 'ZLIB_1.2.5'
|
||||
- use relative symlinks for shared libs
|
||||
- Avoid searching past window for Z_RLE strategy
|
||||
- Assure that high-water mark initialization is always applied in deflate
|
||||
- Add assertions to fill_window() in deflate.c to match comments
|
||||
- Update python link in README
|
||||
- Correct spelling error in gzread.c
|
||||
- Fix bug in gzgets() for a concatenated empty gzip stream
|
||||
- Correct error in comment for gz_make()
|
||||
- Change gzread() and related to ignore junk after gzip streams
|
||||
- Allow gzread() and related to continue after gzclearerr()
|
||||
- Allow gzrewind() and gzseek() after a premature end-of-file
|
||||
- Simplify gzseek() now that raw after gzip is ignored
|
||||
- Change gzgetc() to a macro for speed (~40% speedup in testing)
|
||||
- Fix gzclose() to return the actual error last encountered
|
||||
- Always add large file support for windows
|
||||
- Include zconf.h for windows large file support
|
||||
- Include zconf.h.cmakein for windows large file support
|
||||
- Update zconf.h.cmakein on make distclean
|
||||
- Merge vestigial vsnprintf determination from zutil.h to gzguts.h
|
||||
- Clarify how gzopen() appends in zlib.h comments
|
||||
- Correct documentation of gzdirect() since junk at end now ignored
|
||||
- Add a transparent write mode to gzopen() when 'T' is in the mode
|
||||
- Update python link in zlib man page
|
||||
- Get inffixed.h and MAKEFIXED result to match
|
||||
- Add a ./config --solo option to make zlib subset with no libary use
|
||||
- Add undocumented inflateResetKeep() function for CAB file decoding
|
||||
- Add --cover option to ./configure for gcc coverage testing
|
||||
- Add #define ZLIB_CONST option to use const in the z_stream interface
|
||||
- Add comment to gzdopen() in zlib.h to use dup() when using fileno()
|
||||
- Note behavior of uncompress() to provide as much data as it can
|
||||
- Add files in contrib/minizip to aid in building libminizip
|
||||
- Split off AR options in Makefile.in and configure
|
||||
- Change ON macro to Z_ARG to avoid application conflicts
|
||||
- Facilitate compilation with Borland C++ for pragmas and vsnprintf
|
||||
- Include io.h for Turbo C / Borland C++
|
||||
- Move example.c and minigzip.c to test/
|
||||
- Simplify incomplete code table filling in inflate_table()
|
||||
- Remove code from inflate.c and infback.c that is impossible to execute
|
||||
- Test the inflate code with full coverage
|
||||
- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw)
|
||||
- Add deflateResetKeep and fix inflateResetKeep to retain dictionary
|
||||
- Fix gzwrite.c to accommodate reduced memory zlib compilation
|
||||
- Have inflate() with Z_FINISH avoid the allocation of a window
|
||||
- Do not set strm->adler when doing raw inflate
|
||||
- Fix gzeof() to behave just like feof() when read is not past end of file
|
||||
- Fix bug in gzread.c when end-of-file is reached
|
||||
- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF
|
||||
- Document gzread() capability to read concurrently written files
|
||||
- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo]
|
||||
|
||||
Changes in 1.2.5.1 (10 Sep 2011)
|
||||
- Update FAQ entry on shared builds (#13)
|
||||
- Avoid symbolic argument to chmod in Makefile.in
|
||||
- Fix bug and add consts in contrib/puff [Oberhumer]
|
||||
- Update contrib/puff/zeros.raw test file to have all block types
|
||||
- Add full coverage test for puff in contrib/puff/Makefile
|
||||
- Fix static-only-build install in Makefile.in
|
||||
- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno]
|
||||
- Add libz.a dependency to shared in Makefile.in for parallel builds
|
||||
- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out
|
||||
- Replace $(...) with `...` in configure for non-bash sh [Bowler]
|
||||
- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen]
|
||||
- Add solaris* to Linux* in configure to allow gcc use [Groffen]
|
||||
- Add *bsd* to Linux* case in configure [Bar-Lev]
|
||||
- Add inffast.obj to dependencies in win32/Makefile.msc
|
||||
- Correct spelling error in deflate.h [Kohler]
|
||||
- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc
|
||||
- Add test to configure for GNU C looking for gcc in output of $cc -v
|
||||
- Add zlib.pc generation to win32/Makefile.gcc [Weigelt]
|
||||
- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not
|
||||
- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense
|
||||
- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser)
|
||||
- Make stronger test in zconf.h to include unistd.h for LFS
|
||||
- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack]
|
||||
- Fix zlib.h LFS support when Z_PREFIX used
|
||||
- Add updated as400 support (removed from old) [Monnerat]
|
||||
- Avoid deflate sensitivity to volatile input data
|
||||
- Avoid division in adler32_combine for NO_DIVIDE
|
||||
- Clarify the use of Z_FINISH with deflateBound() amount of space
|
||||
- Set binary for output file in puff.c
|
||||
- Use u4 type for crc_table to avoid conversion warnings
|
||||
- Apply casts in zlib.h to avoid conversion warnings
|
||||
- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller]
|
||||
- Improve inflateSync() documentation to note indeterminancy
|
||||
- Add deflatePending() function to return the amount of pending output
|
||||
- Correct the spelling of "specification" in FAQ [Randers-Pehrson]
|
||||
- Add a check in configure for stdarg.h, use for gzprintf()
|
||||
- Check that pointers fit in ints when gzprint() compiled old style
|
||||
- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler]
|
||||
- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt]
|
||||
- Add debug records in assmebler code [Londer]
|
||||
- Update RFC references to use http://tools.ietf.org/html/... [Li]
|
||||
- Add --archs option, use of libtool to configure for Mac OS X [Borstel]
|
||||
|
||||
Changes in 1.2.5 (19 Apr 2010)
|
||||
- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev]
|
||||
- Default to libdir as sharedlibdir in configure [Nieder]
|
||||
- Update copyright dates on modified source files
|
||||
- Update trees.c to be able to generate modified trees.h
|
||||
- Exit configure for MinGW, suggesting win32/Makefile.gcc
|
||||
- Check for NULL path in gz_open [Homurlu]
|
||||
|
||||
Changes in 1.2.4.5 (18 Apr 2010)
|
||||
- Set sharedlibdir in configure [Torok]
|
||||
|
@ -261,7 +525,7 @@ Changes in 1.2.3.4 (21 Dec 2009)
|
|||
- Clear bytes after deflate lookahead to avoid use of uninitialized data
|
||||
- Change a limit in inftrees.c to be more transparent to Coverity Prevent
|
||||
- Update win32/zlib.def with exported symbols from zlib.h
|
||||
- Correct spelling error in zlib.h [Willem]
|
||||
- Correct spelling errors in zlib.h [Willem, Sobrado]
|
||||
- Allow Z_BLOCK for deflate() to force a new block
|
||||
- Allow negative bits in inflatePrime() to delete existing bit buffer
|
||||
- Add Z_TREES flush option to inflate() to return at end of trees
|
||||
|
|
|
@ -44,8 +44,8 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
|
|||
|
||||
6. Where's the zlib documentation (man pages, etc.)?
|
||||
|
||||
It's in zlib.h . Examples of zlib usage are in the files example.c and
|
||||
minigzip.c, with more in examples/ .
|
||||
It's in zlib.h . Examples of zlib usage are in the files test/example.c
|
||||
and test/minigzip.c, with more in examples/ .
|
||||
|
||||
7. Why don't you use GNU autoconf or libtool or ...?
|
||||
|
||||
|
@ -84,8 +84,10 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
|
|||
|
||||
13. How can I make a Unix shared library?
|
||||
|
||||
make clean
|
||||
./configure -s
|
||||
By default a shared (and a static) library is built for Unix. So:
|
||||
|
||||
make distclean
|
||||
./configure
|
||||
make
|
||||
|
||||
14. How do I install a shared zlib library on Unix?
|
||||
|
@ -325,7 +327,7 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
|
|||
correctly points to the zlib specification in RFC 1950 for the "deflate"
|
||||
transfer encoding, there have been reports of servers and browsers that
|
||||
incorrectly produce or expect raw deflate data per the deflate
|
||||
specficiation in RFC 1951, most notably Microsoft. So even though the
|
||||
specification in RFC 1951, most notably Microsoft. So even though the
|
||||
"deflate" transfer encoding using the zlib format would be the more
|
||||
efficient approach (and in fact exactly what the zlib format was designed
|
||||
for), using the "gzip" transfer encoding is probably more reliable due to
|
||||
|
|
|
@ -7,6 +7,9 @@ Makefile.in template for Unix Makefile
|
|||
README guess what
|
||||
configure configure script for Unix
|
||||
make_vms.com makefile for VMS
|
||||
test/example.c zlib usages examples for build testing
|
||||
test/minigzip.c minimal gzip-like functionality for build testing
|
||||
test/infcover.c inf*.c code coverage for build coverage testing
|
||||
treebuild.xml XML description of source file dependencies
|
||||
zconf.h.cmakein zconf.h template for cmake
|
||||
zconf.h.in zconf.h template for configure
|
||||
|
@ -14,9 +17,11 @@ zlib.3 Man page for zlib
|
|||
zlib.3.pdf Man page in PDF format
|
||||
zlib.map Linux symbol information
|
||||
zlib.pc.in Template for pkg-config descriptor
|
||||
zlib.pc.cmakein zlib.pc template for cmake
|
||||
zlib2ansi perl script to convert source files for C++ compilation
|
||||
|
||||
amiga/ makefiles for Amiga SAS C
|
||||
as400/ makefiles for AS/400
|
||||
doc/ documentation for formats and algorithms
|
||||
msdos/ makefiles for MSDOS
|
||||
nintendods/ makefile for Nintendo DS
|
||||
|
@ -56,10 +61,8 @@ uncompr.c
|
|||
zutil.c
|
||||
zutil.h
|
||||
|
||||
source files for sample programs:
|
||||
example.c
|
||||
minigzip.c
|
||||
See examples/README.examples for more
|
||||
source files for sample programs
|
||||
See examples/README.examples
|
||||
|
||||
unsupported contribution by third parties
|
||||
unsupported contributions by third parties
|
||||
See contrib/README.contrib
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Makefile for zlib
|
||||
# Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler
|
||||
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
||||
# To compile and test, type:
|
||||
|
@ -32,11 +32,12 @@ CPP=$(CC) -E
|
|||
|
||||
STATICLIB=libz.a
|
||||
SHAREDLIB=libz.so
|
||||
SHAREDLIBV=libz.so.1.2.5
|
||||
SHAREDLIBV=libz.so.1.2.8
|
||||
SHAREDLIBM=libz.so.1
|
||||
LIBS=$(STATICLIB) $(SHAREDLIBV)
|
||||
|
||||
AR=ar rc
|
||||
AR=ar
|
||||
ARFLAGS=rc
|
||||
RANLIB=ranlib
|
||||
LDCONFIG=ldconfig
|
||||
LDSHAREDLIBC=-lc
|
||||
|
@ -53,11 +54,13 @@ mandir = ${prefix}/share/man
|
|||
man3dir = ${mandir}/man3
|
||||
pkgconfigdir = ${libdir}/pkgconfig
|
||||
|
||||
OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
|
||||
gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
|
||||
OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
|
||||
OBJC = $(OBJZ) $(OBJG)
|
||||
|
||||
PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo \
|
||||
gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo
|
||||
PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
|
||||
PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
|
||||
PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
|
||||
|
||||
# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
|
||||
OBJA =
|
||||
|
@ -80,35 +83,49 @@ check: test
|
|||
test: all teststatic testshared
|
||||
|
||||
teststatic: static
|
||||
@if echo hello world | ./minigzip | ./minigzip -d && ./example; then \
|
||||
@TMPST=tmpst_$$; \
|
||||
if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
|
||||
echo ' *** zlib test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib test FAILED ***'; false; \
|
||||
fi
|
||||
-@rm -f foo.gz
|
||||
fi; \
|
||||
rm -f $$TMPST
|
||||
|
||||
testshared: shared
|
||||
@LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
|
||||
DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
|
||||
SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
|
||||
if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh; then \
|
||||
TMPSH=tmpsh_$$; \
|
||||
if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
|
||||
echo ' *** zlib shared test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib shared test FAILED ***'; false; \
|
||||
fi
|
||||
-@rm -f foo.gz
|
||||
fi; \
|
||||
rm -f $$TMPSH
|
||||
|
||||
test64: all64
|
||||
@if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64; then \
|
||||
@TMP64=tmp64_$$; \
|
||||
if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
|
||||
echo ' *** zlib 64-bit test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib 64-bit test FAILED ***'; false; \
|
||||
fi
|
||||
-@rm -f foo.gz
|
||||
fi; \
|
||||
rm -f $$TMP64
|
||||
|
||||
infcover.o: test/infcover.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c
|
||||
|
||||
infcover: infcover.o libz.a
|
||||
$(CC) $(CFLAGS) -o $@ infcover.o libz.a
|
||||
|
||||
cover: infcover
|
||||
rm -f *.gcda
|
||||
./infcover
|
||||
gcov inf*.c
|
||||
|
||||
libz.a: $(OBJS)
|
||||
$(AR) $@ $(OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJS)
|
||||
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
|
||||
|
||||
match.o: match.S
|
||||
|
@ -123,11 +140,17 @@ match.lo: match.S
|
|||
mv _match.o match.lo
|
||||
rm -f _match.s
|
||||
|
||||
example64.o: example.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
|
||||
example.o: test/example.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -c -o $@ test/example.c
|
||||
|
||||
minigzip64.o: minigzip.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
|
||||
minigzip.o: test/minigzip.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c
|
||||
|
||||
example64.o: test/example.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c
|
||||
|
||||
minigzip64.o: test/minigzip.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c
|
||||
|
||||
.SUFFIXES: .lo
|
||||
|
||||
|
@ -136,7 +159,7 @@ minigzip64.o: minigzip.c zlib.h zconf.h
|
|||
$(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
|
||||
-@mv objs/$*.o $@
|
||||
|
||||
$(SHAREDLIBV): $(PIC_OBJS)
|
||||
placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
|
||||
$(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM)
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
|
@ -168,14 +191,16 @@ install-libs: $(LIBS)
|
|||
-@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
|
||||
cp $(STATICLIB) $(DESTDIR)$(libdir)
|
||||
cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)
|
||||
cd $(DESTDIR)$(libdir); chmod u=rw,go=r $(STATICLIB)
|
||||
-@(cd $(DESTDIR)$(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
|
||||
-@cd $(DESTDIR)$(sharedlibdir); if test "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
|
||||
chmod 755 $(SHAREDLIBV); \
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
ln -s $(SHAREDLIBV) $(SHAREDLIB); \
|
||||
ln -s $(SHAREDLIBV) $(SHAREDLIBM); \
|
||||
chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
|
||||
-@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
|
||||
-@if test -n "$(SHAREDLIBV)"; then \
|
||||
cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
|
||||
echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
|
||||
chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
|
||||
echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
|
||||
rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
|
||||
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
|
||||
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
|
||||
($(LDCONFIG) || true) >/dev/null 2>&1; \
|
||||
fi
|
||||
cp zlib.3 $(DESTDIR)$(man3dir)
|
||||
|
@ -191,22 +216,25 @@ install: install-libs
|
|||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
|
||||
|
||||
uninstall:
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
|
||||
cd $(DESTDIR)$(libdir); rm -f libz.a; \
|
||||
if test "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
|
||||
cd $(DESTDIR)$(includedir) && rm -f zlib.h zconf.h
|
||||
cd $(DESTDIR)$(libdir) && rm -f libz.a; \
|
||||
if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
|
||||
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
fi
|
||||
cd $(DESTDIR)$(man3dir); rm -f zlib.3
|
||||
cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc
|
||||
cd $(DESTDIR)$(man3dir) && rm -f zlib.3
|
||||
cd $(DESTDIR)$(pkgconfigdir) && rm -f zlib.pc
|
||||
|
||||
docs: zlib.3.pdf
|
||||
|
||||
zlib.3.pdf: zlib.3
|
||||
groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
|
||||
|
||||
zconf.h.in: zconf.h.cmakein
|
||||
sed "/^#cmakedefine/D" < zconf.h.cmakein > zconf.h.in
|
||||
touch -r zconf.h.cmakein zconf.h.in
|
||||
zconf.h.cmakein: zconf.h.in
|
||||
-@ TEMPFILE=zconfh_$$; \
|
||||
echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
|
||||
sed -f $$TEMPFILE zconf.h.in > zconf.h.cmakein &&\
|
||||
touch -r zconf.h.in zconf.h.cmakein &&\
|
||||
rm $$TEMPFILE
|
||||
|
||||
zconf: zconf.h.in
|
||||
cp -p zconf.h.in zconf.h
|
||||
|
@ -216,13 +244,16 @@ clean:
|
|||
rm -f *.o *.lo *~ \
|
||||
example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
|
||||
example64$(EXE) minigzip64$(EXE) \
|
||||
infcover \
|
||||
libz.* foo.gz so_locations \
|
||||
_match.s maketree contrib/infback9/*.o
|
||||
rm -rf objs
|
||||
rm -f *.gcda *.gcno *.gcov
|
||||
rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
|
||||
|
||||
maintainer-clean: distclean
|
||||
distclean: clean zconf docs
|
||||
rm -f Makefile zlib.pc
|
||||
distclean: clean zconf zconf.h.cmakein docs
|
||||
rm -f Makefile zlib.pc configure.log
|
||||
-@rm -f .DS_Store
|
||||
-@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile
|
||||
-@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
ZLIB DATA COMPRESSION LIBRARY
|
||||
|
||||
zlib 1.2.5 is a general purpose data compression library. All the code is
|
||||
zlib 1.2.8 is a general purpose data compression library. All the code is
|
||||
thread safe. The data format used by the zlib library is described by RFCs
|
||||
(Request for Comments) 1950 to 1952 in the files
|
||||
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
|
||||
and rfc1952.txt (gzip format).
|
||||
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
|
||||
rfc1952 (gzip format).
|
||||
|
||||
All functions of the compression library are documented in the file zlib.h
|
||||
(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
|
||||
of the library is given in the file example.c which also tests that the library
|
||||
is working correctly. Another example is given in the file minigzip.c. The
|
||||
compression library itself is composed of all source files except example.c and
|
||||
minigzip.c.
|
||||
of the library is given in the file test/example.c which also tests that
|
||||
the library is working correctly. Another example is given in the file
|
||||
test/minigzip.c. The compression library itself is composed of all source
|
||||
files in the root directory.
|
||||
|
||||
To compile all files and run the test program, follow the instructions given at
|
||||
the top of Makefile.in. In short "./configure; make test", and if that goes
|
||||
well, "make install" should work for most flavors of Unix. For Windows, use one
|
||||
of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
|
||||
well, "make install" should work for most flavors of Unix. For Windows, use
|
||||
one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
|
||||
make_vms.com.
|
||||
|
||||
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
|
||||
|
@ -31,7 +31,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
|
|||
issue of Dr. Dobb's Journal; a copy of the article is available at
|
||||
http://marknelson.us/1997/01/01/zlib-engine/ .
|
||||
|
||||
The changes made in version 1.2.5 are documented in the file ChangeLog.
|
||||
The changes made in version 1.2.8 are documented in the file ChangeLog.
|
||||
|
||||
Unsupported third party contributions are provided in directory contrib/ .
|
||||
|
||||
|
@ -44,7 +44,7 @@ http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
|
|||
|
||||
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
|
||||
available in Python 1.5 and later versions, see
|
||||
http://www.python.org/doc/lib/module-zlib.html .
|
||||
http://docs.python.org/library/zlib.html .
|
||||
|
||||
zlib is built into tcl: http://wiki.tcl.tk/4610 .
|
||||
|
||||
|
@ -84,7 +84,7 @@ Acknowledgments:
|
|||
|
||||
Copyright notice:
|
||||
|
||||
(C) 1995-2010 Jean-loup Gailly and Mark Adler
|
||||
(C) 1995-2013 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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2007 Mark Adler
|
||||
* Copyright (C) 1995-2011 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
|||
|
||||
#define local static
|
||||
|
||||
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
||||
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
||||
|
||||
#define BASE 65521UL /* largest prime smaller than 65536 */
|
||||
#define BASE 65521 /* 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 */
|
||||
|
||||
|
@ -21,39 +21,44 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
|||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
/* use NO_DIVIDE if your processor does not do division in hardware */
|
||||
/* use NO_DIVIDE if your processor does not do division in hardware --
|
||||
try it both ways to see which is faster */
|
||||
#ifdef NO_DIVIDE
|
||||
# define MOD(a) \
|
||||
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
|
||||
(thank you to John Reiser for pointing this out) */
|
||||
# define CHOP(a) \
|
||||
do { \
|
||||
if (a >= (BASE << 16)) a -= (BASE << 16); \
|
||||
if (a >= (BASE << 15)) a -= (BASE << 15); \
|
||||
if (a >= (BASE << 14)) a -= (BASE << 14); \
|
||||
if (a >= (BASE << 13)) a -= (BASE << 13); \
|
||||
if (a >= (BASE << 12)) a -= (BASE << 12); \
|
||||
if (a >= (BASE << 11)) a -= (BASE << 11); \
|
||||
if (a >= (BASE << 10)) a -= (BASE << 10); \
|
||||
if (a >= (BASE << 9)) a -= (BASE << 9); \
|
||||
if (a >= (BASE << 8)) a -= (BASE << 8); \
|
||||
if (a >= (BASE << 7)) a -= (BASE << 7); \
|
||||
if (a >= (BASE << 6)) a -= (BASE << 6); \
|
||||
if (a >= (BASE << 5)) a -= (BASE << 5); \
|
||||
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
||||
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
||||
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
||||
unsigned long tmp = a >> 16; \
|
||||
a &= 0xffffUL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
} while (0)
|
||||
# define MOD28(a) \
|
||||
do { \
|
||||
CHOP(a); \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
# define MOD4(a) \
|
||||
# define MOD(a) \
|
||||
do { \
|
||||
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
||||
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
||||
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
||||
CHOP(a); \
|
||||
MOD28(a); \
|
||||
} while (0)
|
||||
# define MOD63(a) \
|
||||
do { /* this assumes a is not negative */ \
|
||||
z_off64_t tmp = a >> 32; \
|
||||
a &= 0xffffffffL; \
|
||||
a += (tmp << 8) - (tmp << 5) + tmp; \
|
||||
tmp = a >> 16; \
|
||||
a &= 0xffffL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
tmp = a >> 16; \
|
||||
a &= 0xffffL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
#else
|
||||
# define MOD(a) a %= BASE
|
||||
# define MOD4(a) a %= BASE
|
||||
# define MOD28(a) a %= BASE
|
||||
# define MOD63(a) a %= BASE
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
|
@ -92,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
|
|||
}
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
MOD4(sum2); /* only added so many BASE's */
|
||||
MOD28(sum2); /* only added so many BASE's */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
|
@ -137,8 +142,13 @@ local uLong adler32_combine_(adler1, adler2, len2)
|
|||
unsigned long sum2;
|
||||
unsigned rem;
|
||||
|
||||
/* for negative len, return invalid adler32 as a clue for debugging */
|
||||
if (len2 < 0)
|
||||
return 0xffffffffUL;
|
||||
|
||||
/* the derivation of this formula is left as an exercise for the reader */
|
||||
rem = (unsigned)(len2 % BASE);
|
||||
MOD63(len2); /* assumes len2 >= 0 */
|
||||
rem = (unsigned)len2;
|
||||
sum1 = adler1 & 0xffff;
|
||||
sum2 = rem * sum1;
|
||||
MOD(sum2);
|
||||
|
|
|
@ -121,7 +121,7 @@ At least for deflate's output that generates new trees every several 10's of
|
|||
kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
|
||||
would take too long if you're only decoding several thousand symbols. At the
|
||||
other extreme, you could make a new table for every bit in the code. In fact,
|
||||
that's essentially a Huffman tree. But then you spend two much time
|
||||
that's essentially a Huffman tree. But then you spend too much time
|
||||
traversing the tree while decoding, even for short symbols.
|
||||
|
||||
So the number of bits for the first lookup table is a trade of the time to
|
||||
|
@ -206,4 +206,4 @@ Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
|
|||
pp. 337-343.
|
||||
|
||||
``DEFLATE Compressed Data Format Specification'' available in
|
||||
http://www.ietf.org/rfc/rfc1951.txt
|
||||
http://tools.ietf.org/html/rfc1951
|
||||
|
|
|
@ -29,7 +29,7 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
|||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.next_in = (z_const Bytef *)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
#ifdef MAXSEG_64K
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
|
|
511
Modules/zlib/configure
vendored
511
Modules/zlib/configure
vendored
|
@ -13,39 +13,52 @@
|
|||
# If you have problems, try without defining CC and CFLAGS before reporting
|
||||
# an error.
|
||||
|
||||
# start off configure.log
|
||||
echo -------------------- >> configure.log
|
||||
echo $0 $* >> configure.log
|
||||
date >> configure.log
|
||||
|
||||
# set command prefix for cross-compilation
|
||||
if [ -n "${CHOST}" ]; then
|
||||
uname="$(echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/')"
|
||||
uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
|
||||
CROSS_PREFIX="${CHOST}-"
|
||||
fi
|
||||
|
||||
# destination name for static library
|
||||
STATICLIB=libz.a
|
||||
LDFLAGS="${LDFLAGS} -L. ${STATICLIB}"
|
||||
|
||||
# extract zlib version numbers from zlib.h
|
||||
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
|
||||
VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
|
||||
VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
|
||||
VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
|
||||
|
||||
# establish commands for library building
|
||||
if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
|
||||
AR=${AR-"${CROSS_PREFIX}ar"}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${AR}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
|
||||
else
|
||||
AR=${AR-"ar"}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${AR}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
|
||||
fi
|
||||
AR_RC="${AR} rc"
|
||||
ARFLAGS=${ARFLAGS-"rc"}
|
||||
if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
|
||||
RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${RANLIB}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
|
||||
else
|
||||
RANLIB=${RANLIB-"ranlib"}
|
||||
fi
|
||||
if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
|
||||
NM=${NM-"${CROSS_PREFIX}nm"}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${NM}
|
||||
test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
|
||||
else
|
||||
NM=${NM-"nm"}
|
||||
fi
|
||||
|
||||
# set defaults before processing command line options
|
||||
LDCONFIG=${LDCONFIG-"ldconfig"}
|
||||
LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
|
||||
ARCHS=
|
||||
prefix=${prefix-/usr/local}
|
||||
exec_prefix=${exec_prefix-'${prefix}'}
|
||||
libdir=${libdir-'${exec_prefix}/lib'}
|
||||
|
@ -54,20 +67,39 @@ includedir=${includedir-'${prefix}/include'}
|
|||
mandir=${mandir-'${prefix}/share/man'}
|
||||
shared_ext='.so'
|
||||
shared=1
|
||||
solo=0
|
||||
cover=0
|
||||
zprefix=0
|
||||
zconst=0
|
||||
build64=0
|
||||
gcc=0
|
||||
old_cc="$CC"
|
||||
old_cflags="$CFLAGS"
|
||||
OBJC='$(OBJZ) $(OBJG)'
|
||||
PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
|
||||
|
||||
# leave this script, optionally in a bad way
|
||||
leave()
|
||||
{
|
||||
if test "$*" != "0"; then
|
||||
echo "** $0 aborting." | tee -a configure.log
|
||||
fi
|
||||
rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version
|
||||
echo -------------------- >> configure.log
|
||||
echo >> configure.log
|
||||
echo >> configure.log
|
||||
exit $1
|
||||
}
|
||||
|
||||
# process command line options
|
||||
while test $# -ge 1
|
||||
do
|
||||
case "$1" in
|
||||
-h* | --help)
|
||||
echo 'usage:'
|
||||
echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]'
|
||||
echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]'
|
||||
echo ' [--includedir=INCLUDEDIR]'
|
||||
echo 'usage:' | tee -a configure.log
|
||||
echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log
|
||||
echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
|
||||
echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
|
||||
exit 0 ;;
|
||||
-p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
|
||||
-e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
|
||||
|
@ -81,51 +113,88 @@ case "$1" in
|
|||
-i* | --includedir) includedir="$2"; shift; shift ;;
|
||||
-s* | --shared | --enable-shared) shared=1; shift ;;
|
||||
-t | --static) shared=0; shift ;;
|
||||
--solo) solo=1; shift ;;
|
||||
--cover) cover=1; shift ;;
|
||||
-z* | --zprefix) zprefix=1; shift ;;
|
||||
-6* | --64) build64=1; shift ;;
|
||||
--sysconfdir=*) echo "ignored option: --sysconfdir"; shift ;;
|
||||
--localstatedir=*) echo "ignored option: --localstatedir"; shift ;;
|
||||
*) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
|
||||
-a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
|
||||
--sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
|
||||
--localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
|
||||
-c* | --const) zconst=1; shift ;;
|
||||
*)
|
||||
echo "unknown option: $1" | tee -a configure.log
|
||||
echo "$0 --help for help" | tee -a configure.log
|
||||
leave 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
# temporary file name
|
||||
test=ztest$$
|
||||
|
||||
# put arguments in log, also put test file in log if used in arguments
|
||||
show()
|
||||
{
|
||||
case "$*" in
|
||||
*$test.c*)
|
||||
echo === $test.c === >> configure.log
|
||||
cat $test.c >> configure.log
|
||||
echo === >> configure.log;;
|
||||
esac
|
||||
echo $* >> configure.log
|
||||
}
|
||||
|
||||
# check for gcc vs. cc and set compile and link flags based on the system identified by uname
|
||||
cat > $test.c <<EOF
|
||||
extern int getchar();
|
||||
int hello() {return getchar();}
|
||||
EOF
|
||||
|
||||
test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc...
|
||||
test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
|
||||
cc=${CC-${CROSS_PREFIX}gcc}
|
||||
cflags=${CFLAGS-"-O3"}
|
||||
# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
|
||||
case "$cc" in
|
||||
*gcc*) gcc=1 ;;
|
||||
*clang*) gcc=1 ;;
|
||||
esac
|
||||
case `$cc -v 2>&1` in
|
||||
*gcc*) gcc=1 ;;
|
||||
esac
|
||||
|
||||
if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
|
||||
show $cc -c $test.c
|
||||
if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
|
||||
echo ... using gcc >> configure.log
|
||||
CC="$cc"
|
||||
CFLAGS="${CFLAGS--O3} ${ARCHS}"
|
||||
SFLAGS="${CFLAGS--O3} -fPIC"
|
||||
CFLAGS="${CFLAGS--O3}"
|
||||
LDFLAGS="${LDFLAGS} ${ARCHS}"
|
||||
if test $build64 -eq 1; then
|
||||
CFLAGS="${CFLAGS} -m64"
|
||||
SFLAGS="${SFLAGS} -m64"
|
||||
fi
|
||||
if test "${ZLIBGCCWARN}" = "YES"; then
|
||||
if test "$zconst" -eq 1; then
|
||||
CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
|
||||
else
|
||||
CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
|
||||
fi
|
||||
fi
|
||||
if test -z "$uname"; then
|
||||
uname=`(uname -s || echo unknown) 2>/dev/null`
|
||||
fi
|
||||
case "$uname" in
|
||||
Linux* | linux* | GNU | GNU/* | *BSD | DragonFly) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
|
||||
Linux* | linux* | GNU | GNU/* | solaris*)
|
||||
LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
|
||||
*BSD | *bsd* | DragonFly)
|
||||
LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"}
|
||||
LDCONFIG="ldconfig -m" ;;
|
||||
CYGWIN* | Cygwin* | cygwin* | OS/2*)
|
||||
EXE='.exe' ;;
|
||||
MINGW*|mingw*)
|
||||
MINGW* | mingw*)
|
||||
# temporary bypass
|
||||
rm -f $test.[co] $test $test$shared_ext
|
||||
echo "Please use win32/Makefile.gcc instead."
|
||||
exit 1
|
||||
echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
|
||||
leave 1
|
||||
LDSHARED=${LDSHARED-"$cc -shared"}
|
||||
LDSHAREDLIBC=""
|
||||
EXE='.exe' ;;
|
||||
|
@ -142,17 +211,25 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
|
|||
shared_ext='.sl'
|
||||
SHAREDLIB='libz.sl' ;;
|
||||
esac ;;
|
||||
Darwin*) shared_ext='.dylib'
|
||||
Darwin* | darwin*)
|
||||
shared_ext='.dylib'
|
||||
SHAREDLIB=libz$shared_ext
|
||||
SHAREDLIBV=libz.$VER$shared_ext
|
||||
SHAREDLIBM=libz.$VER1$shared_ext
|
||||
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} ;;
|
||||
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
|
||||
if libtool -V 2>&1 | grep Apple > /dev/null; then
|
||||
AR="libtool"
|
||||
else
|
||||
AR="/usr/bin/libtool"
|
||||
fi
|
||||
ARFLAGS="-o" ;;
|
||||
*) LDSHARED=${LDSHARED-"$cc -shared"} ;;
|
||||
esac
|
||||
else
|
||||
# find system name and corresponding cc options
|
||||
CC=${CC-cc}
|
||||
gcc=0
|
||||
echo ... using $CC >> configure.log
|
||||
if test -z "$uname"; then
|
||||
uname=`(uname -sr || echo unknown) 2>/dev/null`
|
||||
fi
|
||||
|
@ -183,19 +260,34 @@ else
|
|||
CFLAGS=${CFLAGS-"-4 -O"}
|
||||
LDSHARED=${LDSHARED-"cc"}
|
||||
RANLIB=${RANLIB-"true"}
|
||||
AR_RC="cc -A" ;;
|
||||
AR="cc"
|
||||
ARFLAGS="-A" ;;
|
||||
SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
|
||||
CFLAGS=${CFLAGS-"-O3"}
|
||||
LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
|
||||
SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
|
||||
SunOS\ 5* | solaris*)
|
||||
LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
|
||||
SFLAGS=${CFLAGS-"-fast -KPIC"}
|
||||
CFLAGS=${CFLAGS-"-fast"}
|
||||
if test $build64 -eq 1; then
|
||||
# old versions of SunPRO/Workshop/Studio don't support -m64,
|
||||
# but newer ones do. Check for it.
|
||||
flag64=`$CC -flags | egrep -- '^-m64'`
|
||||
if test x"$flag64" != x"" ; then
|
||||
CFLAGS="${CFLAGS} -m64"
|
||||
SFLAGS="${SFLAGS} -m64"
|
||||
else
|
||||
case `(uname -m || echo unknown) 2>/dev/null` in
|
||||
i86*)
|
||||
SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
|
||||
CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
|
||||
SFLAGS="$SFLAGS -xarch=amd64"
|
||||
CFLAGS="$CFLAGS -xarch=amd64" ;;
|
||||
*)
|
||||
SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
|
||||
CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
|
||||
esac ;;
|
||||
SFLAGS="$SFLAGS -xarch=v9"
|
||||
CFLAGS="$CFLAGS -xarch=v9" ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
|
||||
CFLAGS=${CFLAGS-"-O2"}
|
||||
LDSHARED=${LDSHARED-"ld"} ;;
|
||||
|
@ -225,25 +317,79 @@ else
|
|||
esac
|
||||
fi
|
||||
|
||||
# destination names for shared library if not defined above
|
||||
SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
|
||||
SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
|
||||
SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# define functions for testing compiler and library characteristics and logging the results
|
||||
|
||||
cat > $test.c <<EOF
|
||||
#error error
|
||||
EOF
|
||||
if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
|
||||
try()
|
||||
{
|
||||
show $*
|
||||
test "`( $* ) 2>&1 | tee -a configure.log`" = ""
|
||||
}
|
||||
echo - using any output from compiler to indicate an error >> configure.log
|
||||
else
|
||||
try()
|
||||
{
|
||||
show $*
|
||||
( $* ) >> configure.log 2>&1
|
||||
ret=$?
|
||||
if test $ret -ne 0; then
|
||||
echo "(exit code "$ret")" >> configure.log
|
||||
fi
|
||||
return $ret
|
||||
}
|
||||
fi
|
||||
|
||||
tryboth()
|
||||
{
|
||||
show $*
|
||||
got=`( $* ) 2>&1`
|
||||
ret=$?
|
||||
printf %s "$got" >> configure.log
|
||||
if test $ret -ne 0; then
|
||||
return $ret
|
||||
fi
|
||||
test "$got" = ""
|
||||
}
|
||||
|
||||
cat > $test.c << EOF
|
||||
int foo() { return 0; }
|
||||
EOF
|
||||
echo "Checking for obsessive-compulsive compiler options..." >> configure.log
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
:
|
||||
else
|
||||
echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
|
||||
leave 1
|
||||
fi
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# see if shared library build supported
|
||||
cat > $test.c <<EOF
|
||||
extern int getchar();
|
||||
int hello() {return getchar();}
|
||||
EOF
|
||||
if test $shared -eq 1; then
|
||||
echo Checking for shared library support...
|
||||
echo Checking for shared library support... | tee -a configure.log
|
||||
# we must test in two steps (cc then ld), required at least on SunOS 4.x
|
||||
if test "`($CC -w -c $SFLAGS $test.c) 2>&1`" = "" &&
|
||||
test "`($LDSHARED $SFLAGS -o $test$shared_ext $test.o) 2>&1`" = ""; then
|
||||
echo Building shared library $SHAREDLIBV with $CC.
|
||||
if try $CC -w -c $SFLAGS $test.c &&
|
||||
try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
|
||||
echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
|
||||
elif test -z "$old_cc" -a -z "$old_cflags"; then
|
||||
echo No shared library support.
|
||||
echo No shared library support. | tee -a configure.log
|
||||
shared=0;
|
||||
else
|
||||
echo Tested $CC -w -c $SFLAGS $test.c
|
||||
$CC -w -c $SFLAGS $test.c
|
||||
echo Tested $LDSHARED $SFLAGS -o $test$shared_ext $test.o
|
||||
$LDSHARED $SFLAGS -o $test$shared_ext $test.o
|
||||
echo 'No shared library support; try without defining CC and CFLAGS'
|
||||
echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
|
||||
shared=0;
|
||||
fi
|
||||
fi
|
||||
|
@ -254,25 +400,43 @@ if test $shared -eq 0; then
|
|||
SHAREDLIB=""
|
||||
SHAREDLIBV=""
|
||||
SHAREDLIBM=""
|
||||
echo Building static library $STATICLIB version $VER with $CC.
|
||||
echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
|
||||
else
|
||||
ALL="static shared"
|
||||
TEST="all teststatic testshared"
|
||||
fi
|
||||
|
||||
# check for underscores in external names for use by assembler code
|
||||
CPP=${CPP-"$CC -E"}
|
||||
case $CFLAGS in
|
||||
*ASMV*)
|
||||
echo >> configure.log
|
||||
show "$NM $test.o | grep _hello"
|
||||
if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
|
||||
CPP="$CPP -DNO_UNDERLINE"
|
||||
echo Checking for underline in external names... No. | tee -a configure.log
|
||||
else
|
||||
echo Checking for underline in external names... Yes. | tee -a configure.log
|
||||
fi ;;
|
||||
esac
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# check for large file support, and if none, check for fseeko()
|
||||
cat > $test.c <<EOF
|
||||
#include <sys/types.h>
|
||||
off64_t dummy = 0;
|
||||
EOF
|
||||
if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c) 2>&1`" = ""; then
|
||||
if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
|
||||
CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
|
||||
SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
|
||||
ALL="${ALL} all64"
|
||||
TEST="${TEST} test64"
|
||||
echo "Checking for off64_t... Yes."
|
||||
echo "Checking for fseeko... Yes."
|
||||
echo "Checking for off64_t... Yes." | tee -a configure.log
|
||||
echo "Checking for fseeko... Yes." | tee -a configure.log
|
||||
else
|
||||
echo "Checking for off64_t... No."
|
||||
echo "Checking for off64_t... No." | tee -a configure.log
|
||||
echo >> configure.log
|
||||
cat > $test.c <<EOF
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
|
@ -280,272 +444,335 @@ int main(void) {
|
|||
return 0;
|
||||
}
|
||||
EOF
|
||||
if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for fseeko... Yes."
|
||||
if try $CC $CFLAGS -o $test $test.c; then
|
||||
echo "Checking for fseeko... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="${CFLAGS} -DNO_FSEEKO"
|
||||
SFLAGS="${SFLAGS} -DNO_FSEEKO"
|
||||
echo "Checking for fseeko... No."
|
||||
echo "Checking for fseeko... No." | tee -a configure.log
|
||||
fi
|
||||
fi
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# check for strerror() for use by gz* functions
|
||||
cat > $test.c <<EOF
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
int main() { return strlen(strerror(errno)); }
|
||||
EOF
|
||||
if try $CC $CFLAGS -o $test $test.c; then
|
||||
echo "Checking for strerror... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="${CFLAGS} -DNO_STRERROR"
|
||||
SFLAGS="${SFLAGS} -DNO_STRERROR"
|
||||
echo "Checking for strerror... No." | tee -a configure.log
|
||||
fi
|
||||
|
||||
# copy clean zconf.h for subsequent edits
|
||||
cp -p zconf.h.in zconf.h
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# check for unistd.h and save result in zconf.h
|
||||
cat > $test.c <<EOF
|
||||
#include <unistd.h>
|
||||
int main() { return 0; }
|
||||
EOF
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
|
||||
mv zconf.temp.h zconf.h
|
||||
echo "Checking for unistd.h... Yes."
|
||||
echo "Checking for unistd.h... Yes." | tee -a configure.log
|
||||
else
|
||||
echo "Checking for unistd.h... No."
|
||||
echo "Checking for unistd.h... No." | tee -a configure.log
|
||||
fi
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# check for stdarg.h and save result in zconf.h
|
||||
cat > $test.c <<EOF
|
||||
#include <stdarg.h>
|
||||
int main() { return 0; }
|
||||
EOF
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
|
||||
mv zconf.temp.h zconf.h
|
||||
echo "Checking for stdarg.h... Yes." | tee -a configure.log
|
||||
else
|
||||
echo "Checking for stdarg.h... No." | tee -a configure.log
|
||||
fi
|
||||
|
||||
# if the z_ prefix was requested, save that in zconf.h
|
||||
if test $zprefix -eq 1; then
|
||||
sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
|
||||
mv zconf.temp.h zconf.h
|
||||
echo "Using z_ prefix on all symbols."
|
||||
echo >> configure.log
|
||||
echo "Using z_ prefix on all symbols." | tee -a configure.log
|
||||
fi
|
||||
|
||||
# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
|
||||
if test $solo -eq 1; then
|
||||
sed '/#define ZCONF_H/a\
|
||||
#define Z_SOLO
|
||||
|
||||
' < zconf.h > zconf.temp.h
|
||||
mv zconf.temp.h zconf.h
|
||||
OBJC='$(OBJZ)'
|
||||
PIC_OBJC='$(PIC_OBJZ)'
|
||||
fi
|
||||
|
||||
# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
|
||||
if test $cover -eq 1; then
|
||||
CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
|
||||
if test -n "$GCC_CLASSIC"; then
|
||||
CC=$GCC_CLASSIC
|
||||
fi
|
||||
fi
|
||||
|
||||
echo >> configure.log
|
||||
|
||||
# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
|
||||
# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
|
||||
# return value. The most secure result is vsnprintf() with a return value. snprintf() with a
|
||||
# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
|
||||
cat > $test.c <<EOF
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "zconf.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef STDC
|
||||
choke me
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
|
||||
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
|
||||
|
||||
echo >> configure.log
|
||||
cat > $test.c <<EOF
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int mytest(const char *fmt, ...)
|
||||
{
|
||||
char buf[20];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return (mytest("Hello%d\n", 1));
|
||||
}
|
||||
EOF
|
||||
if try $CC $CFLAGS -o $test $test.c; then
|
||||
echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
|
||||
|
||||
if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for vsnprintf() in stdio.h... Yes."
|
||||
|
||||
echo >> configure.log
|
||||
cat >$test.c <<EOF
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int mytest(const char *fmt, ...)
|
||||
{
|
||||
int n;
|
||||
char buf[20];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
return n;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return (mytest("Hello%d\n", 1));
|
||||
}
|
||||
EOF
|
||||
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for return value of vsnprintf()... Yes."
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
|
||||
echo "Checking for return value of vsnprintf()... No."
|
||||
echo " WARNING: apparently vsnprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
echo " vulnerabilities."
|
||||
echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
|
||||
echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
|
||||
echo " can build but will be open to possible string-format security" | tee -a configure.log
|
||||
echo " vulnerabilities." | tee -a configure.log
|
||||
fi
|
||||
else
|
||||
CFLAGS="$CFLAGS -DNO_vsnprintf"
|
||||
SFLAGS="$SFLAGS -DNO_vsnprintf"
|
||||
echo "Checking for vsnprintf() in stdio.h... No."
|
||||
echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
|
||||
echo " can build but will be open to possible buffer-overflow security"
|
||||
echo " vulnerabilities."
|
||||
echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
|
||||
echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
|
||||
echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
|
||||
echo " vulnerabilities." | tee -a configure.log
|
||||
|
||||
echo >> configure.log
|
||||
cat >$test.c <<EOF
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int mytest(const char *fmt, ...)
|
||||
{
|
||||
int n;
|
||||
char buf[20];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsprintf(buf, fmt, ap);
|
||||
va_end(ap);
|
||||
return n;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return (mytest("Hello%d\n", 1));
|
||||
}
|
||||
EOF
|
||||
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for return value of vsprintf()... Yes."
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_vsprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_vsprintf_void"
|
||||
echo "Checking for return value of vsprintf()... No."
|
||||
echo " WARNING: apparently vsprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
echo " vulnerabilities."
|
||||
echo "Checking for return value of vsprintf()... No." | tee -a configure.log
|
||||
echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
|
||||
echo " can build but will be open to possible string-format security" | tee -a configure.log
|
||||
echo " vulnerabilities." | tee -a configure.log
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
|
||||
echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
|
||||
|
||||
echo >> configure.log
|
||||
cat >$test.c <<EOF
|
||||
#include <stdio.h>
|
||||
|
||||
int mytest()
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s", "foo");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return (mytest());
|
||||
}
|
||||
EOF
|
||||
|
||||
if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for snprintf() in stdio.h... Yes."
|
||||
if try $CC $CFLAGS -o $test $test.c; then
|
||||
echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
|
||||
|
||||
echo >> configure.log
|
||||
cat >$test.c <<EOF
|
||||
#include <stdio.h>
|
||||
|
||||
int mytest()
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
return snprintf(buf, sizeof(buf), "%s", "foo");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return (mytest());
|
||||
}
|
||||
EOF
|
||||
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for return value of snprintf()... Yes."
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_snprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_snprintf_void"
|
||||
echo "Checking for return value of snprintf()... No."
|
||||
echo " WARNING: apparently snprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
echo " vulnerabilities."
|
||||
echo "Checking for return value of snprintf()... No." | tee -a configure.log
|
||||
echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
|
||||
echo " can build but will be open to possible string-format security" | tee -a configure.log
|
||||
echo " vulnerabilities." | tee -a configure.log
|
||||
fi
|
||||
else
|
||||
CFLAGS="$CFLAGS -DNO_snprintf"
|
||||
SFLAGS="$SFLAGS -DNO_snprintf"
|
||||
echo "Checking for snprintf() in stdio.h... No."
|
||||
echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
|
||||
echo " can build but will be open to possible buffer-overflow security"
|
||||
echo " vulnerabilities."
|
||||
echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
|
||||
echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
|
||||
echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
|
||||
echo " vulnerabilities." | tee -a configure.log
|
||||
|
||||
echo >> configure.log
|
||||
cat >$test.c <<EOF
|
||||
#include <stdio.h>
|
||||
|
||||
int mytest()
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
return sprintf(buf, "%s", "foo");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return (mytest());
|
||||
}
|
||||
EOF
|
||||
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for return value of sprintf()... Yes."
|
||||
if try $CC -c $CFLAGS $test.c; then
|
||||
echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_sprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_sprintf_void"
|
||||
echo "Checking for return value of sprintf()... No."
|
||||
echo " WARNING: apparently sprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
echo " vulnerabilities."
|
||||
echo "Checking for return value of sprintf()... No." | tee -a configure.log
|
||||
echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
|
||||
echo " can build but will be open to possible string-format security" | tee -a configure.log
|
||||
echo " vulnerabilities." | tee -a configure.log
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# see if we can hide zlib internal symbols that are linked between separate source files
|
||||
if test "$gcc" -eq 1; then
|
||||
echo >> configure.log
|
||||
cat > $test.c <<EOF
|
||||
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33)
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
#endif
|
||||
#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
int ZLIB_INTERNAL foo;
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for attribute(visibility) support... Yes."
|
||||
if tryboth $CC -c $CFLAGS $test.c; then
|
||||
CFLAGS="$CFLAGS -DHAVE_HIDDEN"
|
||||
SFLAGS="$SFLAGS -DHAVE_HIDDEN"
|
||||
echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
|
||||
else
|
||||
CFLAGS="$CFLAGS -DNO_VIZ"
|
||||
SFLAGS="$SFLAGS -DNO_VIZ"
|
||||
echo "Checking for attribute(visibility) support... No."
|
||||
echo "Checking for attribute(visibility) support... No." | tee -a configure.log
|
||||
fi
|
||||
fi
|
||||
|
||||
CPP=${CPP-"$CC -E"}
|
||||
case $CFLAGS in
|
||||
*ASMV*)
|
||||
if test "`$NM $test.o | grep _hello`" = ""; then
|
||||
CPP="$CPP -DNO_UNDERLINE"
|
||||
echo Checking for underline in external names... No.
|
||||
else
|
||||
echo Checking for underline in external names... Yes.
|
||||
fi ;;
|
||||
esac
|
||||
# show the results in the log
|
||||
echo >> configure.log
|
||||
echo ALL = $ALL >> configure.log
|
||||
echo AR = $AR >> configure.log
|
||||
echo ARFLAGS = $ARFLAGS >> configure.log
|
||||
echo CC = $CC >> configure.log
|
||||
echo CFLAGS = $CFLAGS >> configure.log
|
||||
echo CPP = $CPP >> configure.log
|
||||
echo EXE = $EXE >> configure.log
|
||||
echo LDCONFIG = $LDCONFIG >> configure.log
|
||||
echo LDFLAGS = $LDFLAGS >> configure.log
|
||||
echo LDSHARED = $LDSHARED >> configure.log
|
||||
echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
|
||||
echo OBJC = $OBJC >> configure.log
|
||||
echo PIC_OBJC = $PIC_OBJC >> configure.log
|
||||
echo RANLIB = $RANLIB >> configure.log
|
||||
echo SFLAGS = $SFLAGS >> configure.log
|
||||
echo SHAREDLIB = $SHAREDLIB >> configure.log
|
||||
echo SHAREDLIBM = $SHAREDLIBM >> configure.log
|
||||
echo SHAREDLIBV = $SHAREDLIBV >> configure.log
|
||||
echo STATICLIB = $STATICLIB >> configure.log
|
||||
echo TEST = $TEST >> configure.log
|
||||
echo VER = $VER >> configure.log
|
||||
echo Z_U4 = $Z_U4 >> configure.log
|
||||
echo exec_prefix = $exec_prefix >> configure.log
|
||||
echo includedir = $includedir >> configure.log
|
||||
echo libdir = $libdir >> configure.log
|
||||
echo mandir = $mandir >> configure.log
|
||||
echo prefix = $prefix >> configure.log
|
||||
echo sharedlibdir = $sharedlibdir >> configure.log
|
||||
echo uname = $uname >> configure.log
|
||||
|
||||
rm -f $test.[co] $test $test$shared_ext
|
||||
|
||||
# udpate Makefile
|
||||
# udpate Makefile with the configure results
|
||||
sed < Makefile.in "
|
||||
/^CC *=/s#=.*#=$CC#
|
||||
/^CFLAGS *=/s#=.*#=$CFLAGS#
|
||||
|
@ -557,7 +784,8 @@ sed < Makefile.in "
|
|||
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
|
||||
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
|
||||
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
|
||||
/^AR *=/s#=.*#=$AR_RC#
|
||||
/^AR *=/s#=.*#=$AR#
|
||||
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
|
||||
/^RANLIB *=/s#=.*#=$RANLIB#
|
||||
/^LDCONFIG *=/s#=.*#=$LDCONFIG#
|
||||
/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
|
||||
|
@ -568,10 +796,13 @@ sed < Makefile.in "
|
|||
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
|
||||
/^includedir *=/s#=.*#=$includedir#
|
||||
/^mandir *=/s#=.*#=$mandir#
|
||||
/^OBJC *=/s#=.*#= $OBJC#
|
||||
/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
|
||||
/^all: */s#:.*#: $ALL#
|
||||
/^test: */s#:.*#: $TEST#
|
||||
" > Makefile
|
||||
|
||||
# create zlib.pc with the configure results
|
||||
sed < zlib.pc.in "
|
||||
/^CC *=/s#=.*#=$CC#
|
||||
/^CFLAGS *=/s#=.*#=$CFLAGS#
|
||||
|
@ -581,7 +812,8 @@ sed < zlib.pc.in "
|
|||
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
|
||||
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
|
||||
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
|
||||
/^AR *=/s#=.*#=$AR_RC#
|
||||
/^AR *=/s#=.*#=$AR#
|
||||
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
|
||||
/^RANLIB *=/s#=.*#=$RANLIB#
|
||||
/^EXE *=/s#=.*#=$EXE#
|
||||
/^prefix *=/s#=.*#=$prefix#
|
||||
|
@ -594,3 +826,6 @@ sed < zlib.pc.in "
|
|||
" | sed -e "
|
||||
s/\@VERSION\@/$VER/g;
|
||||
" > zlib.pc
|
||||
|
||||
# done
|
||||
leave 0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2006, 2010 Mark Adler
|
||||
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||
|
@ -17,6 +17,8 @@
|
|||
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
||||
first call get_crc_table() to initialize the tables before allowing more than
|
||||
one thread to use crc32().
|
||||
|
||||
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
|
||||
*/
|
||||
|
||||
#ifdef MAKECRCH
|
||||
|
@ -30,31 +32,11 @@
|
|||
|
||||
#define local static
|
||||
|
||||
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
||||
#ifndef NOBYFOUR
|
||||
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
||||
# include <limits.h>
|
||||
# define BYFOUR
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
typedef unsigned int u4;
|
||||
# else
|
||||
# if (ULONG_MAX == 0xffffffffUL)
|
||||
typedef unsigned long u4;
|
||||
# else
|
||||
# if (USHRT_MAX == 0xffffffffUL)
|
||||
typedef unsigned short u4;
|
||||
# else
|
||||
# undef BYFOUR /* can't find a four-byte integer type! */
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif /* STDC */
|
||||
#endif /* !NOBYFOUR */
|
||||
|
||||
/* Definitions for doing the crc four data bytes at a time. */
|
||||
#if !defined(NOBYFOUR) && defined(Z_U4)
|
||||
# define BYFOUR
|
||||
#endif
|
||||
#ifdef BYFOUR
|
||||
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
|
||||
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
||||
local unsigned long crc32_little OF((unsigned long,
|
||||
const unsigned char FAR *, unsigned));
|
||||
local unsigned long crc32_big OF((unsigned long,
|
||||
|
@ -68,16 +50,16 @@
|
|||
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||
unsigned long vec));
|
||||
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
|
||||
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
|
||||
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
||||
local volatile int crc_table_empty = 1;
|
||||
local unsigned long FAR crc_table[TBLS][256];
|
||||
local z_crc_t FAR crc_table[TBLS][256];
|
||||
local void make_crc_table OF((void));
|
||||
#ifdef MAKECRCH
|
||||
local void write_table OF((FILE *, const unsigned long FAR *));
|
||||
local void write_table OF((FILE *, const z_crc_t FAR *));
|
||||
#endif /* MAKECRCH */
|
||||
/*
|
||||
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
|
@ -107,9 +89,9 @@ local void make_crc_table OF((void));
|
|||
*/
|
||||
local void make_crc_table()
|
||||
{
|
||||
unsigned long c;
|
||||
z_crc_t c;
|
||||
int n, k;
|
||||
unsigned long poly; /* polynomial exclusive-or pattern */
|
||||
z_crc_t poly; /* polynomial exclusive-or pattern */
|
||||
/* terms of polynomial defining this crc (except x^32): */
|
||||
static volatile int first = 1; /* flag to limit concurrent making */
|
||||
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||
|
@ -121,13 +103,13 @@ local void make_crc_table()
|
|||
first = 0;
|
||||
|
||||
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
||||
poly = 0UL;
|
||||
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
||||
poly |= 1UL << (31 - p[n]);
|
||||
poly = 0;
|
||||
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
|
||||
poly |= (z_crc_t)1 << (31 - p[n]);
|
||||
|
||||
/* generate a crc for every 8-bit value */
|
||||
for (n = 0; n < 256; n++) {
|
||||
c = (unsigned long)n;
|
||||
c = (z_crc_t)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||
crc_table[0][n] = c;
|
||||
|
@ -138,11 +120,11 @@ local void make_crc_table()
|
|||
and then the byte reversal of those as well as the first table */
|
||||
for (n = 0; n < 256; n++) {
|
||||
c = crc_table[0][n];
|
||||
crc_table[4][n] = REV(c);
|
||||
crc_table[4][n] = ZSWAP32(c);
|
||||
for (k = 1; k < 4; k++) {
|
||||
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
||||
crc_table[k][n] = c;
|
||||
crc_table[k + 4][n] = REV(c);
|
||||
crc_table[k + 4][n] = ZSWAP32(c);
|
||||
}
|
||||
}
|
||||
#endif /* BYFOUR */
|
||||
|
@ -164,7 +146,7 @@ local void make_crc_table()
|
|||
if (out == NULL) return;
|
||||
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
||||
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
||||
fprintf(out, "local const unsigned long FAR ");
|
||||
fprintf(out, "local const z_crc_t FAR ");
|
||||
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
||||
write_table(out, crc_table[0]);
|
||||
# ifdef BYFOUR
|
||||
|
@ -184,12 +166,13 @@ local void make_crc_table()
|
|||
#ifdef MAKECRCH
|
||||
local void write_table(out, table)
|
||||
FILE *out;
|
||||
const unsigned long FAR *table;
|
||||
const z_crc_t FAR *table;
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
||||
(unsigned long)(table[n]),
|
||||
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
||||
}
|
||||
#endif /* MAKECRCH */
|
||||
|
@ -204,13 +187,13 @@ local void write_table(out, table)
|
|||
/* =========================================================================
|
||||
* This function can be used by asm versions of crc32()
|
||||
*/
|
||||
const unsigned long FAR * ZEXPORT get_crc_table()
|
||||
const z_crc_t FAR * ZEXPORT get_crc_table()
|
||||
{
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
return (const unsigned long FAR *)crc_table;
|
||||
return (const z_crc_t FAR *)crc_table;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
@ -232,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
|
|||
|
||||
#ifdef BYFOUR
|
||||
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
||||
u4 endian;
|
||||
z_crc_t endian;
|
||||
|
||||
endian = 1;
|
||||
if (*((unsigned char *)(&endian)))
|
||||
|
@ -266,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
|
|||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
register u4 c;
|
||||
register const u4 FAR *buf4;
|
||||
register z_crc_t c;
|
||||
register const z_crc_t FAR *buf4;
|
||||
|
||||
c = (u4)crc;
|
||||
c = (z_crc_t)crc;
|
||||
c = ~c;
|
||||
while (len && ((ptrdiff_t)buf & 3)) {
|
||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||
len--;
|
||||
}
|
||||
|
||||
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
||||
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
||||
while (len >= 32) {
|
||||
DOLIT32;
|
||||
len -= 32;
|
||||
|
@ -306,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
|
|||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
register u4 c;
|
||||
register const u4 FAR *buf4;
|
||||
register z_crc_t c;
|
||||
register const z_crc_t FAR *buf4;
|
||||
|
||||
c = REV((u4)crc);
|
||||
c = ZSWAP32((z_crc_t)crc);
|
||||
c = ~c;
|
||||
while (len && ((ptrdiff_t)buf & 3)) {
|
||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
len--;
|
||||
}
|
||||
|
||||
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
||||
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
||||
buf4--;
|
||||
while (len >= 32) {
|
||||
DOBIG32;
|
||||
|
@ -333,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
|
|||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)(REV(c));
|
||||
return (unsigned long)(ZSWAP32(c));
|
||||
}
|
||||
|
||||
#endif /* BYFOUR */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Generated automatically by crc32.c
|
||||
*/
|
||||
|
||||
local const unsigned long FAR crc_table[TBLS][256] =
|
||||
local const z_crc_t FAR crc_table[TBLS][256] =
|
||||
{
|
||||
{
|
||||
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* deflate.c -- compress data using the deflation algorithm
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
|
||||
* Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
|||
* REFERENCES
|
||||
*
|
||||
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
|
||||
* Available in http://www.ietf.org/rfc/rfc1951.txt
|
||||
* Available in http://tools.ietf.org/html/rfc1951
|
||||
*
|
||||
* A description of the Rabin and Karp algorithm is given in the book
|
||||
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
|
||||
|
@ -52,7 +52,7 @@
|
|||
#include "deflate.h"
|
||||
|
||||
const char deflate_copyright[] =
|
||||
" deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
|
||||
" deflate 1.2.8 Copyright 1995-2013 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
|
||||
|
@ -155,9 +155,12 @@ local const config configuration_table[10] = {
|
|||
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))
|
||||
|
||||
/* ===========================================================================
|
||||
* Update a hash value with the given input byte
|
||||
* IN assertion: all calls to UPDATE_HASH are made with consecutive
|
||||
* 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.
|
||||
*/
|
||||
|
@ -170,7 +173,7 @@ 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 INSERT_STRING are made with consecutive
|
||||
* 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).
|
||||
*/
|
||||
|
@ -235,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
|||
|
||||
strm->msg = Z_NULL;
|
||||
if (strm->zalloc == (alloc_func)0) {
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
#endif
|
||||
}
|
||||
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
|
||||
if (strm->zfree == (free_func)0)
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zfree = zcfree;
|
||||
#endif
|
||||
|
||||
#ifdef FASTEST
|
||||
if (level != 0) level = 1;
|
||||
|
@ -293,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
|||
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
|
||||
s->pending_buf == Z_NULL) {
|
||||
s->status = FINISH_STATE;
|
||||
strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
|
||||
strm->msg = ERR_MSG(Z_MEM_ERROR);
|
||||
deflateEnd (strm);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
|
@ -314,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
|||
uInt dictLength;
|
||||
{
|
||||
deflate_state *s;
|
||||
uInt length = dictLength;
|
||||
uInt n;
|
||||
IPos hash_head = 0;
|
||||
uInt str, n;
|
||||
int wrap;
|
||||
unsigned avail;
|
||||
z_const unsigned char *next;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
|
||||
strm->state->wrap == 2 ||
|
||||
(strm->state->wrap == 1 && strm->state->status != INIT_STATE))
|
||||
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
s = strm->state;
|
||||
wrap = s->wrap;
|
||||
if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
s = strm->state;
|
||||
if (s->wrap)
|
||||
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
|
||||
if (wrap == 1)
|
||||
strm->adler = adler32(strm->adler, dictionary, dictLength);
|
||||
s->wrap = 0; /* avoid computing Adler-32 in read_buf */
|
||||
|
||||
if (length < MIN_MATCH) return Z_OK;
|
||||
if (length > s->w_size) {
|
||||
length = s->w_size;
|
||||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
||||
/* if dictionary would fill window, just replace the history */
|
||||
if (dictLength >= s->w_size) {
|
||||
if (wrap == 0) { /* already empty otherwise */
|
||||
CLEAR_HASH(s);
|
||||
s->strstart = 0;
|
||||
s->block_start = 0L;
|
||||
s->insert = 0;
|
||||
}
|
||||
dictionary += dictLength - s->w_size; /* use the tail */
|
||||
dictLength = s->w_size;
|
||||
}
|
||||
zmemcpy(s->window, dictionary, length);
|
||||
s->strstart = length;
|
||||
s->block_start = (long)length;
|
||||
|
||||
/* Insert all strings in the hash table (except for the last two bytes).
|
||||
* s->lookahead stays null, so s->ins_h will be recomputed at the next
|
||||
* call of fill_window.
|
||||
*/
|
||||
s->ins_h = s->window[0];
|
||||
UPDATE_HASH(s, s->ins_h, s->window[1]);
|
||||
for (n = 0; n <= length - MIN_MATCH; n++) {
|
||||
INSERT_STRING(s, n, hash_head);
|
||||
/* insert dictionary into window and hash */
|
||||
avail = strm->avail_in;
|
||||
next = strm->next_in;
|
||||
strm->avail_in = dictLength;
|
||||
strm->next_in = (z_const Bytef *)dictionary;
|
||||
fill_window(s);
|
||||
while (s->lookahead >= MIN_MATCH) {
|
||||
str = s->strstart;
|
||||
n = s->lookahead - (MIN_MATCH-1);
|
||||
do {
|
||||
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
|
||||
#ifndef FASTEST
|
||||
s->prev[str & s->w_mask] = s->head[s->ins_h];
|
||||
#endif
|
||||
s->head[s->ins_h] = (Pos)str;
|
||||
str++;
|
||||
} while (--n);
|
||||
s->strstart = str;
|
||||
s->lookahead = MIN_MATCH-1;
|
||||
fill_window(s);
|
||||
}
|
||||
if (hash_head) hash_head = 0; /* to make compiler happy */
|
||||
s->strstart += s->lookahead;
|
||||
s->block_start = (long)s->strstart;
|
||||
s->insert = s->lookahead;
|
||||
s->lookahead = 0;
|
||||
s->match_length = s->prev_length = MIN_MATCH-1;
|
||||
s->match_available = 0;
|
||||
strm->next_in = next;
|
||||
strm->avail_in = avail;
|
||||
s->wrap = wrap;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateReset (strm)
|
||||
int ZEXPORT deflateResetKeep (strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
deflate_state *s;
|
||||
|
@ -380,11 +419,22 @@ int ZEXPORT deflateReset (strm)
|
|||
s->last_flush = Z_NO_FLUSH;
|
||||
|
||||
_tr_init(s);
|
||||
lm_init(s);
|
||||
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateReset (strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = deflateResetKeep(strm);
|
||||
if (ret == Z_OK)
|
||||
lm_init(strm->state);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateSetHeader (strm, head)
|
||||
z_streamp strm;
|
||||
|
@ -396,15 +446,43 @@ int ZEXPORT deflateSetHeader (strm, head)
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflatePending (strm, pending, bits)
|
||||
unsigned *pending;
|
||||
int *bits;
|
||||
z_streamp strm;
|
||||
{
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
if (pending != Z_NULL)
|
||||
*pending = strm->state->pending;
|
||||
if (bits != Z_NULL)
|
||||
*bits = strm->state->bi_valid;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflatePrime (strm, bits, value)
|
||||
z_streamp strm;
|
||||
int bits;
|
||||
int value;
|
||||
{
|
||||
deflate_state *s;
|
||||
int put;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
strm->state->bi_valid = bits;
|
||||
strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
|
||||
s = strm->state;
|
||||
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
|
||||
return Z_BUF_ERROR;
|
||||
do {
|
||||
put = Buf_size - s->bi_valid;
|
||||
if (put > bits)
|
||||
put = bits;
|
||||
s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
|
||||
s->bi_valid += put;
|
||||
_tr_flush_bits(s);
|
||||
value >>= put;
|
||||
bits -= put;
|
||||
} while (bits);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
@ -435,6 +513,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
|||
strm->total_in != 0) {
|
||||
/* Flush the last buffer: */
|
||||
err = deflate(strm, Z_BLOCK);
|
||||
if (err == Z_BUF_ERROR && s->pending == 0)
|
||||
err = Z_OK;
|
||||
}
|
||||
if (s->level != level) {
|
||||
s->level = level;
|
||||
|
@ -562,19 +642,22 @@ local void putShortMSB (s, b)
|
|||
local void flush_pending(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
unsigned len = strm->state->pending;
|
||||
unsigned len;
|
||||
deflate_state *s = strm->state;
|
||||
|
||||
_tr_flush_bits(s);
|
||||
len = s->pending;
|
||||
if (len > strm->avail_out) len = strm->avail_out;
|
||||
if (len == 0) return;
|
||||
|
||||
zmemcpy(strm->next_out, strm->state->pending_out, len);
|
||||
zmemcpy(strm->next_out, s->pending_out, len);
|
||||
strm->next_out += len;
|
||||
strm->state->pending_out += len;
|
||||
s->pending_out += len;
|
||||
strm->total_out += len;
|
||||
strm->avail_out -= len;
|
||||
strm->state->pending -= len;
|
||||
if (strm->state->pending == 0) {
|
||||
strm->state->pending_out = strm->state->pending_buf;
|
||||
s->pending -= len;
|
||||
if (s->pending == 0) {
|
||||
s->pending_out = s->pending_buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -801,7 +884,7 @@ int ZEXPORT deflate (strm, flush)
|
|||
* 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 && flush <= old_flush &&
|
||||
} else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
|
||||
flush != Z_FINISH) {
|
||||
ERR_RETURN(strm, Z_BUF_ERROR);
|
||||
}
|
||||
|
@ -850,6 +933,7 @@ int ZEXPORT deflate (strm, flush)
|
|||
if (s->lookahead == 0) {
|
||||
s->strstart = 0;
|
||||
s->block_start = 0L;
|
||||
s->insert = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -945,12 +1029,12 @@ int ZEXPORT deflateCopy (dest, source)
|
|||
|
||||
ss = source->state;
|
||||
|
||||
zmemcpy(dest, source, sizeof(z_stream));
|
||||
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
|
||||
|
||||
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
||||
if (ds == Z_NULL) return Z_MEM_ERROR;
|
||||
dest->state = (struct internal_state FAR *) ds;
|
||||
zmemcpy(ds, ss, sizeof(deflate_state));
|
||||
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
|
||||
ds->strm = dest;
|
||||
|
||||
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
||||
|
@ -966,8 +1050,8 @@ int ZEXPORT deflateCopy (dest, source)
|
|||
}
|
||||
/* following zmemcpy do not work for 16-bit MSDOS */
|
||||
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
|
||||
zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
|
||||
zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
|
||||
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
|
||||
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
|
||||
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
|
||||
|
||||
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
|
||||
|
@ -1001,15 +1085,15 @@ local int read_buf(strm, buf, size)
|
|||
|
||||
strm->avail_in -= len;
|
||||
|
||||
zmemcpy(buf, strm->next_in, len);
|
||||
if (strm->state->wrap == 1) {
|
||||
strm->adler = adler32(strm->adler, strm->next_in, len);
|
||||
strm->adler = adler32(strm->adler, buf, len);
|
||||
}
|
||||
#ifdef GZIP
|
||||
else if (strm->state->wrap == 2) {
|
||||
strm->adler = crc32(strm->adler, strm->next_in, len);
|
||||
strm->adler = crc32(strm->adler, buf, len);
|
||||
}
|
||||
#endif
|
||||
zmemcpy(buf, strm->next_in, len);
|
||||
strm->next_in += len;
|
||||
strm->total_in += len;
|
||||
|
||||
|
@ -1036,6 +1120,7 @@ local void lm_init (s)
|
|||
s->strstart = 0;
|
||||
s->block_start = 0L;
|
||||
s->lookahead = 0;
|
||||
s->insert = 0;
|
||||
s->match_length = s->prev_length = MIN_MATCH-1;
|
||||
s->match_available = 0;
|
||||
s->ins_h = 0;
|
||||
|
@ -1310,6 +1395,8 @@ local void fill_window(s)
|
|||
unsigned more; /* Amount of free space at the end of the window. */
|
||||
uInt wsize = s->w_size;
|
||||
|
||||
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
|
||||
|
||||
do {
|
||||
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
|
||||
|
||||
|
@ -1362,7 +1449,7 @@ local void fill_window(s)
|
|||
#endif
|
||||
more += wsize;
|
||||
}
|
||||
if (s->strm->avail_in == 0) return;
|
||||
if (s->strm->avail_in == 0) break;
|
||||
|
||||
/* If there was no sliding:
|
||||
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
|
||||
|
@ -1381,12 +1468,24 @@ local void fill_window(s)
|
|||
s->lookahead += n;
|
||||
|
||||
/* Initialize the hash value now that we have some input: */
|
||||
if (s->lookahead >= MIN_MATCH) {
|
||||
s->ins_h = s->window[s->strstart];
|
||||
UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
|
||||
if (s->lookahead + s->insert >= MIN_MATCH) {
|
||||
uInt str = s->strstart - s->insert;
|
||||
s->ins_h = s->window[str];
|
||||
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
|
||||
#if MIN_MATCH != 3
|
||||
Call UPDATE_HASH() MIN_MATCH-3 more times
|
||||
#endif
|
||||
while (s->insert) {
|
||||
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
|
||||
#ifndef FASTEST
|
||||
s->prev[str & s->w_mask] = s->head[s->ins_h];
|
||||
#endif
|
||||
s->head[s->ins_h] = (Pos)str;
|
||||
str++;
|
||||
s->insert--;
|
||||
if (s->lookahead + s->insert < MIN_MATCH)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
|
||||
* but this is not important since only literal bytes will be emitted.
|
||||
|
@ -1427,6 +1526,9 @@ local void fill_window(s)
|
|||
s->high_water += init;
|
||||
}
|
||||
}
|
||||
|
||||
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
|
||||
"not enough room for search");
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
|
@ -1506,8 +1608,14 @@ local block_state deflate_stored(s, flush)
|
|||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
s->insert = 0;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if ((long)s->strstart > s->block_start)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
|
@ -1603,8 +1711,14 @@ local block_state deflate_fast(s, flush)
|
|||
}
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (s->last_lit)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
|
||||
#ifndef FASTEST
|
||||
|
@ -1728,8 +1842,14 @@ local block_state deflate_slow(s, flush)
|
|||
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
||||
s->match_available = 0;
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (s->last_lit)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
#endif /* FASTEST */
|
||||
|
||||
|
@ -1749,11 +1869,11 @@ local block_state deflate_rle(s, flush)
|
|||
for (;;) {
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
* at the end of the input file. We need MAX_MATCH bytes
|
||||
* for the longest encodable run.
|
||||
* for the longest run, plus one for the unrolled loop.
|
||||
*/
|
||||
if (s->lookahead < MAX_MATCH) {
|
||||
if (s->lookahead <= MAX_MATCH) {
|
||||
fill_window(s);
|
||||
if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
|
||||
if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
|
||||
return need_more;
|
||||
}
|
||||
if (s->lookahead == 0) break; /* flush the current block */
|
||||
|
@ -1776,6 +1896,7 @@ local block_state deflate_rle(s, flush)
|
|||
if (s->match_length > s->lookahead)
|
||||
s->match_length = s->lookahead;
|
||||
}
|
||||
Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
|
||||
}
|
||||
|
||||
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
|
||||
|
@ -1796,8 +1917,14 @@ local block_state deflate_rle(s, flush)
|
|||
}
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
s->insert = 0;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (s->last_lit)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
|
@ -1829,6 +1956,12 @@ local block_state deflate_huff(s, flush)
|
|||
s->strstart++;
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
s->insert = 0;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (s->last_lit)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly
|
||||
* Copyright (C) 1995-2012 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -48,6 +48,9 @@
|
|||
#define MAX_BITS 15
|
||||
/* All codes must not exceed MAX_BITS bits */
|
||||
|
||||
#define Buf_size 16
|
||||
/* size of bit buffer in bi_buf */
|
||||
|
||||
#define INIT_STATE 42
|
||||
#define EXTRA_STATE 69
|
||||
#define NAME_STATE 73
|
||||
|
@ -101,7 +104,7 @@ typedef struct internal_state {
|
|||
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 */
|
||||
Byte method; /* STORED (for zip only) or DEFLATED */
|
||||
Byte method; /* can only be DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
|
||||
/* used by deflate.c: */
|
||||
|
@ -188,7 +191,7 @@ typedef struct internal_state {
|
|||
int nice_match; /* Stop searching when current match exceeds this */
|
||||
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to supress compiler warning */
|
||||
/* Didn't use ct_data typedef below to suppress compiler warning */
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
||||
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
||||
|
@ -244,7 +247,7 @@ typedef struct internal_state {
|
|||
ulg opt_len; /* bit length of current block with optimal trees */
|
||||
ulg static_len; /* bit length of current block with static trees */
|
||||
uInt matches; /* number of string matches in current block */
|
||||
int last_eob_len; /* bit length of EOB code for last block */
|
||||
uInt insert; /* bytes at end of window left to insert */
|
||||
|
||||
#ifdef DEBUG
|
||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
|
@ -294,6 +297,7 @@ void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
|
|||
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last));
|
||||
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
|
||||
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
|
||||
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* example.c -- usage example of the zlib compression library
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2006, 2011 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
|||
} \
|
||||
}
|
||||
|
||||
const char hello[] = "hello, hello!";
|
||||
z_const char hello[] = "hello, hello!";
|
||||
/* "hello world" would be more standard, but the repeated "hello"
|
||||
* stresses the compression code better, sorry...
|
||||
*/
|
||||
|
@ -34,10 +34,6 @@ const char hello[] = "hello, hello!";
|
|||
const char dictionary[] = "hello";
|
||||
uLong dictId; /* Adler32 value of the dictionary */
|
||||
|
||||
void test_compress OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *fname,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
|
@ -53,6 +49,39 @@ void test_dict_inflate OF((Byte *compr, uLong comprLen,
|
|||
Byte *uncompr, uLong uncomprLen));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
|
||||
#ifdef Z_SOLO
|
||||
|
||||
void *myalloc OF((void *, unsigned, unsigned));
|
||||
void myfree OF((void *, void *));
|
||||
|
||||
void *myalloc(q, n, m)
|
||||
void *q;
|
||||
unsigned n, m;
|
||||
{
|
||||
q = Z_NULL;
|
||||
return calloc(n, m);
|
||||
}
|
||||
|
||||
void myfree(void *q, void *p)
|
||||
{
|
||||
q = Z_NULL;
|
||||
free(p);
|
||||
}
|
||||
|
||||
static alloc_func zalloc = myalloc;
|
||||
static free_func zfree = myfree;
|
||||
|
||||
#else /* !Z_SOLO */
|
||||
|
||||
static alloc_func zalloc = (alloc_func)0;
|
||||
static free_func zfree = (free_func)0;
|
||||
|
||||
void test_compress OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *fname,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
|
||||
/* ===========================================================================
|
||||
* Test compress() and uncompress()
|
||||
*/
|
||||
|
@ -163,6 +192,8 @@ void test_gzio(fname, uncompr, uncomprLen)
|
|||
#endif
|
||||
}
|
||||
|
||||
#endif /* Z_SOLO */
|
||||
|
||||
/* ===========================================================================
|
||||
* Test deflate() with small buffers
|
||||
*/
|
||||
|
@ -174,14 +205,14 @@ void test_deflate(compr, comprLen)
|
|||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_in = (Bytef*)hello;
|
||||
c_stream.next_in = (z_const unsigned char *)hello;
|
||||
c_stream.next_out = compr;
|
||||
|
||||
while (c_stream.total_in != len && c_stream.total_out < comprLen) {
|
||||
|
@ -213,8 +244,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.zalloc = zalloc;
|
||||
d_stream.zfree = zfree;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
|
@ -252,8 +283,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
|||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_BEST_SPEED);
|
||||
|
@ -309,8 +340,8 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.zalloc = zalloc;
|
||||
d_stream.zfree = zfree;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
|
@ -349,14 +380,14 @@ void test_flush(compr, comprLen)
|
|||
int err;
|
||||
uInt len = (uInt)strlen(hello)+1;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_in = (Bytef*)hello;
|
||||
c_stream.next_in = (z_const unsigned char *)hello;
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_in = 3;
|
||||
c_stream.avail_out = (uInt)*comprLen;
|
||||
|
@ -388,8 +419,8 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
|
|||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.zalloc = zalloc;
|
||||
d_stream.zfree = zfree;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
|
@ -430,22 +461,22 @@ void test_dict_deflate(compr, comprLen)
|
|||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
err = deflateSetDictionary(&c_stream,
|
||||
(const Bytef*)dictionary, sizeof(dictionary));
|
||||
(const Bytef*)dictionary, (int)sizeof(dictionary));
|
||||
CHECK_ERR(err, "deflateSetDictionary");
|
||||
|
||||
dictId = c_stream.adler;
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_out = (uInt)comprLen;
|
||||
|
||||
c_stream.next_in = (Bytef*)hello;
|
||||
c_stream.next_in = (z_const unsigned char *)hello;
|
||||
c_stream.avail_in = (uInt)strlen(hello)+1;
|
||||
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
|
@ -469,8 +500,8 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.zalloc = zalloc;
|
||||
d_stream.zfree = zfree;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
|
@ -491,7 +522,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
exit(1);
|
||||
}
|
||||
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
|
||||
sizeof(dictionary));
|
||||
(int)sizeof(dictionary));
|
||||
}
|
||||
CHECK_ERR(err, "inflate with dict");
|
||||
}
|
||||
|
@ -540,10 +571,15 @@ int main(argc, argv)
|
|||
printf("out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef Z_SOLO
|
||||
argc = strlen(argv[0]);
|
||||
#else
|
||||
test_compress(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
test_gzio((argc > 1 ? argv[1] : TESTFILE),
|
||||
uncompr, uncomprLen);
|
||||
#endif
|
||||
|
||||
test_deflate(compr, comprLen);
|
||||
test_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* gzguts.h -- zlib internal header definitions for gz* operations
|
||||
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
|
||||
#ifdef HAVE_HIDDEN
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
|
@ -27,13 +27,80 @@
|
|||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef WINAPI_FAMILY
|
||||
# define open _open
|
||||
# define read _read
|
||||
# define write _write
|
||||
# define close _close
|
||||
#endif
|
||||
|
||||
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
||||
# define NO_GZCOMPRESS
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <io.h>
|
||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
# ifdef MSDOS
|
||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||
but for now we just assume it doesn't. */
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __TURBOC__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef WIN32
|
||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __SASC
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef VMS
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __OS400__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __MVS__
|
||||
# define NO_vsnprintf
|
||||
# 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
|
||||
the result is assured to fit in the space provided */
|
||||
#ifdef _MSC_VER
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
|
@ -52,7 +119,7 @@
|
|||
# include <windows.h>
|
||||
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
||||
#else
|
||||
# ifdef STDC
|
||||
# ifndef NO_STRERROR
|
||||
# include <errno.h>
|
||||
# define zstrerror() strerror(errno)
|
||||
# else
|
||||
|
@ -68,7 +135,15 @@
|
|||
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
|
||||
#endif
|
||||
|
||||
/* default i/o buffer size -- double this for output when reading */
|
||||
/* default memLevel */
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
|
||||
/* default i/o buffer size -- double this for output when reading (this and
|
||||
twice this must be able to fit in an unsigned type) */
|
||||
#define GZBUFSIZE 8192
|
||||
|
||||
/* gzip modes, also provide a little integrity check on the passed structure */
|
||||
|
@ -84,23 +159,25 @@
|
|||
|
||||
/* internal gzip file state data structure */
|
||||
typedef struct {
|
||||
/* exposed contents for gzgetc() macro */
|
||||
struct gzFile_s x; /* "x" for exposed */
|
||||
/* x.have: number of bytes available at x.next */
|
||||
/* x.next: next output data to deliver or write */
|
||||
/* x.pos: current position in uncompressed data */
|
||||
/* used for both reading and writing */
|
||||
int mode; /* see gzip modes above */
|
||||
int fd; /* file descriptor */
|
||||
char *path; /* path or fd for error messages */
|
||||
z_off64_t pos; /* current position in uncompressed data */
|
||||
unsigned size; /* buffer size, zero if not allocated yet */
|
||||
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
||||
unsigned char *in; /* input buffer */
|
||||
unsigned char *out; /* output buffer (double-sized when reading) */
|
||||
unsigned char *next; /* next output data to deliver or write */
|
||||
int direct; /* 0 if processing gzip, 1 if transparent */
|
||||
/* just for reading */
|
||||
unsigned have; /* amount of output data unused at next */
|
||||
int eof; /* true if end of input file reached */
|
||||
z_off64_t start; /* where the gzip data started, for rewinding */
|
||||
z_off64_t raw; /* where the raw data started, for seeking */
|
||||
int how; /* 0: get header, 1: copy, 2: decompress */
|
||||
int direct; /* true if last read direct, false if gzip */
|
||||
z_off64_t start; /* where the gzip data started, for rewinding */
|
||||
int eof; /* true if end of input file reached */
|
||||
int past; /* true if read requested past end */
|
||||
/* just for writing */
|
||||
int level; /* compression level */
|
||||
int strategy; /* compression strategy */
|
||||
|
|
1026
Modules/zlib/gzio.c
1026
Modules/zlib/gzio.c
File diff suppressed because it is too large
Load diff
|
@ -1,19 +1,23 @@
|
|||
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
||||
* Copyright (C) 2004, 2010 Mark Adler
|
||||
* Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "gzguts.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(__BORLANDC__)
|
||||
# define LSEEK _lseeki64
|
||||
#else
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
# define LSEEK lseek64
|
||||
#else
|
||||
# define LSEEK lseek
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Local functions */
|
||||
local void gz_reset OF((gz_statep));
|
||||
local gzFile gz_open OF((const char *, int, const char *));
|
||||
local gzFile gz_open OF((const void *, int, const char *));
|
||||
|
||||
#if defined UNDER_CE
|
||||
|
||||
|
@ -71,28 +75,40 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
|
|||
local void gz_reset(state)
|
||||
gz_statep state;
|
||||
{
|
||||
state->x.have = 0; /* no output data available */
|
||||
if (state->mode == GZ_READ) { /* for reading ... */
|
||||
state->have = 0; /* no output data available */
|
||||
state->eof = 0; /* not at end of file */
|
||||
state->past = 0; /* have not read past end yet */
|
||||
state->how = LOOK; /* look for gzip header */
|
||||
state->direct = 1; /* default for empty file */
|
||||
}
|
||||
state->seek = 0; /* no seek request pending */
|
||||
gz_error(state, Z_OK, NULL); /* clear error */
|
||||
state->pos = 0; /* no uncompressed data yet */
|
||||
state->x.pos = 0; /* no uncompressed data yet */
|
||||
state->strm.avail_in = 0; /* no input data yet */
|
||||
}
|
||||
|
||||
/* Open a gzip file either by name or file descriptor. */
|
||||
local gzFile gz_open(path, fd, mode)
|
||||
const char *path;
|
||||
const void *path;
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
gz_statep state;
|
||||
size_t len;
|
||||
int oflag;
|
||||
#ifdef O_CLOEXEC
|
||||
int cloexec = 0;
|
||||
#endif
|
||||
#ifdef O_EXCL
|
||||
int exclusive = 0;
|
||||
#endif
|
||||
|
||||
/* check input */
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
||||
/* allocate gzFile structure to return */
|
||||
state = malloc(sizeof(gz_state));
|
||||
state = (gz_statep)malloc(sizeof(gz_state));
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
state->size = 0; /* no buffers allocated yet */
|
||||
|
@ -103,6 +119,7 @@ local gzFile gz_open(path, fd, mode)
|
|||
state->mode = GZ_NONE;
|
||||
state->level = Z_DEFAULT_COMPRESSION;
|
||||
state->strategy = Z_DEFAULT_STRATEGY;
|
||||
state->direct = 0;
|
||||
while (*mode) {
|
||||
if (*mode >= '0' && *mode <= '9')
|
||||
state->level = *mode - '0';
|
||||
|
@ -124,6 +141,16 @@ local gzFile gz_open(path, fd, mode)
|
|||
return NULL;
|
||||
case 'b': /* ignore -- will request binary anyway */
|
||||
break;
|
||||
#ifdef O_CLOEXEC
|
||||
case 'e':
|
||||
cloexec = 1;
|
||||
break;
|
||||
#endif
|
||||
#ifdef O_EXCL
|
||||
case 'x':
|
||||
exclusive = 1;
|
||||
break;
|
||||
#endif
|
||||
case 'f':
|
||||
state->strategy = Z_FILTERED;
|
||||
break;
|
||||
|
@ -135,6 +162,10 @@ local gzFile gz_open(path, fd, mode)
|
|||
break;
|
||||
case 'F':
|
||||
state->strategy = Z_FIXED;
|
||||
break;
|
||||
case 'T':
|
||||
state->direct = 1;
|
||||
break;
|
||||
default: /* could consider as an error, but just ignore */
|
||||
;
|
||||
}
|
||||
|
@ -147,30 +178,71 @@ local gzFile gz_open(path, fd, mode)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* can't force transparent read */
|
||||
if (state->mode == GZ_READ) {
|
||||
if (state->direct) {
|
||||
free(state);
|
||||
return NULL;
|
||||
}
|
||||
state->direct = 1; /* for empty file */
|
||||
}
|
||||
|
||||
/* save the path name for error messages */
|
||||
state->path = malloc(strlen(path) + 1);
|
||||
#ifdef _WIN32
|
||||
if (fd == -2) {
|
||||
len = wcstombs(NULL, path, 0);
|
||||
if (len == (size_t)-1)
|
||||
len = 0;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
len = strlen((const char *)path);
|
||||
state->path = (char *)malloc(len + 1);
|
||||
if (state->path == NULL) {
|
||||
free(state);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (fd == -2)
|
||||
if (len)
|
||||
wcstombs(state->path, path, len + 1);
|
||||
else
|
||||
*(state->path) = 0;
|
||||
else
|
||||
#endif
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(state->path, len + 1, "%s", (const char *)path);
|
||||
#else
|
||||
strcpy(state->path, path);
|
||||
#endif
|
||||
|
||||
/* open the file with the appropriate mode (or just use fd) */
|
||||
state->fd = fd != -1 ? fd :
|
||||
open(path,
|
||||
/* compute the flags for open() */
|
||||
oflag =
|
||||
#ifdef O_LARGEFILE
|
||||
O_LARGEFILE |
|
||||
#endif
|
||||
#ifdef O_BINARY
|
||||
O_BINARY |
|
||||
#endif
|
||||
#ifdef O_CLOEXEC
|
||||
(cloexec ? O_CLOEXEC : 0) |
|
||||
#endif
|
||||
(state->mode == GZ_READ ?
|
||||
O_RDONLY :
|
||||
(O_WRONLY | O_CREAT | (
|
||||
state->mode == GZ_WRITE ?
|
||||
(O_WRONLY | O_CREAT |
|
||||
#ifdef O_EXCL
|
||||
(exclusive ? O_EXCL : 0) |
|
||||
#endif
|
||||
(state->mode == GZ_WRITE ?
|
||||
O_TRUNC :
|
||||
O_APPEND))),
|
||||
0666);
|
||||
O_APPEND)));
|
||||
|
||||
/* open the file with the appropriate flags (or just use fd) */
|
||||
state->fd = fd > -1 ? fd : (
|
||||
#ifdef _WIN32
|
||||
fd == -2 ? _wopen(path, oflag, 0666) :
|
||||
#endif
|
||||
open((const char *)path, oflag, 0666));
|
||||
if (state->fd == -1) {
|
||||
free(state->path);
|
||||
free(state);
|
||||
|
@ -216,14 +288,28 @@ gzFile ZEXPORT gzdopen(fd, mode)
|
|||
char *path; /* identifier for error messages */
|
||||
gzFile gz;
|
||||
|
||||
if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL)
|
||||
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
|
||||
return NULL;
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
|
||||
#else
|
||||
sprintf(path, "<fd:%d>", fd); /* for debugging */
|
||||
#endif
|
||||
gz = gz_open(path, fd, mode);
|
||||
free(path);
|
||||
return gz;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
#ifdef _WIN32
|
||||
gzFile ZEXPORT gzopen_w(path, mode)
|
||||
const wchar_t *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -2, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzbuffer(file, size)
|
||||
gzFile file;
|
||||
|
@ -243,8 +329,8 @@ int ZEXPORT gzbuffer(file, size)
|
|||
return -1;
|
||||
|
||||
/* check and set requested size */
|
||||
if (size == 0)
|
||||
return -1;
|
||||
if (size < 2)
|
||||
size = 2; /* need two bytes to check magic header */
|
||||
state->want = size;
|
||||
return 0;
|
||||
}
|
||||
|
@ -261,7 +347,8 @@ int ZEXPORT gzrewind(file)
|
|||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* back up and start over */
|
||||
|
@ -289,7 +376,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||
return -1;
|
||||
|
||||
/* check that there's no error */
|
||||
if (state->err != Z_OK)
|
||||
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
|
||||
return -1;
|
||||
|
||||
/* can only seek from start or relative to current position */
|
||||
|
@ -298,31 +385,32 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||
|
||||
/* normalize offset to a SEEK_CUR specification */
|
||||
if (whence == SEEK_SET)
|
||||
offset -= state->pos;
|
||||
offset -= state->x.pos;
|
||||
else if (state->seek)
|
||||
offset += state->skip;
|
||||
state->seek = 0;
|
||||
|
||||
/* if within raw area while reading, just go there */
|
||||
if (state->mode == GZ_READ && state->how == COPY &&
|
||||
state->pos + offset >= state->raw) {
|
||||
ret = LSEEK(state->fd, offset - state->have, SEEK_CUR);
|
||||
state->x.pos + offset >= 0) {
|
||||
ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
state->have = 0;
|
||||
state->x.have = 0;
|
||||
state->eof = 0;
|
||||
state->past = 0;
|
||||
state->seek = 0;
|
||||
gz_error(state, Z_OK, NULL);
|
||||
state->strm.avail_in = 0;
|
||||
state->pos += offset;
|
||||
return state->pos;
|
||||
state->x.pos += offset;
|
||||
return state->x.pos;
|
||||
}
|
||||
|
||||
/* calculate skip amount, rewinding if needed for back seek when reading */
|
||||
if (offset < 0) {
|
||||
if (state->mode != GZ_READ) /* writing -- can't go backwards */
|
||||
return -1;
|
||||
offset += state->pos;
|
||||
offset += state->x.pos;
|
||||
if (offset < 0) /* before start of file! */
|
||||
return -1;
|
||||
if (gzrewind(file) == -1) /* rewind, then skip to offset */
|
||||
|
@ -331,11 +419,11 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||
|
||||
/* if reading, skip what's in output buffer (one less gzgetc() check) */
|
||||
if (state->mode == GZ_READ) {
|
||||
n = GT_OFF(state->have) || (z_off64_t)state->have > offset ?
|
||||
(unsigned)offset : state->have;
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
|
||||
(unsigned)offset : state->x.have;
|
||||
state->x.have -= n;
|
||||
state->x.next += n;
|
||||
state->x.pos += n;
|
||||
offset -= n;
|
||||
}
|
||||
|
||||
|
@ -344,7 +432,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||
state->seek = 1;
|
||||
state->skip = offset;
|
||||
}
|
||||
return state->pos + offset;
|
||||
return state->x.pos + offset;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
|
@ -373,7 +461,7 @@ z_off64_t ZEXPORT gztell64(file)
|
|||
return -1;
|
||||
|
||||
/* return position */
|
||||
return state->pos + (state->seek ? state->skip : 0);
|
||||
return state->x.pos + (state->seek ? state->skip : 0);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
|
@ -433,8 +521,7 @@ int ZEXPORT gzeof(file)
|
|||
return 0;
|
||||
|
||||
/* return end-of-file state */
|
||||
return state->mode == GZ_READ ?
|
||||
(state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
|
||||
return state->mode == GZ_READ ? state->past : 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
|
@ -454,7 +541,8 @@ const char * ZEXPORT gzerror(file, errnum)
|
|||
/* return error information */
|
||||
if (errnum != NULL)
|
||||
*errnum = state->err;
|
||||
return state->msg == NULL ? "" : state->msg;
|
||||
return state->err == Z_MEM_ERROR ? "out of memory" :
|
||||
(state->msg == NULL ? "" : state->msg);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
|
@ -471,8 +559,10 @@ void ZEXPORT gzclearerr(file)
|
|||
return;
|
||||
|
||||
/* clear error and end-of-file */
|
||||
if (state->mode == GZ_READ)
|
||||
if (state->mode == GZ_READ) {
|
||||
state->eof = 0;
|
||||
state->past = 0;
|
||||
}
|
||||
gz_error(state, Z_OK, NULL);
|
||||
}
|
||||
|
||||
|
@ -494,26 +584,33 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
|
|||
state->msg = NULL;
|
||||
}
|
||||
|
||||
/* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
|
||||
if (err != Z_OK && err != Z_BUF_ERROR)
|
||||
state->x.have = 0;
|
||||
|
||||
/* set error code, and if no message, then done */
|
||||
state->err = err;
|
||||
if (msg == NULL)
|
||||
return;
|
||||
|
||||
/* for an out of memory error, save as static string */
|
||||
if (err == Z_MEM_ERROR) {
|
||||
state->msg = (char *)msg;
|
||||
/* for an out of memory error, return literal string when requested */
|
||||
if (err == Z_MEM_ERROR)
|
||||
return;
|
||||
}
|
||||
|
||||
/* construct error message with path */
|
||||
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
|
||||
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
|
||||
NULL) {
|
||||
state->err = Z_MEM_ERROR;
|
||||
state->msg = (char *)"out of memory";
|
||||
return;
|
||||
}
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
|
||||
"%s%s%s", state->path, ": ", msg);
|
||||
#else
|
||||
strcpy(state->msg, state->path);
|
||||
strcat(state->msg, ": ");
|
||||
strcat(state->msg, msg);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* gzread.c -- zlib functions for reading gzip files
|
||||
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -8,10 +8,9 @@
|
|||
/* Local functions */
|
||||
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
|
||||
local int gz_avail OF((gz_statep));
|
||||
local int gz_next4 OF((gz_statep, unsigned long *));
|
||||
local int gz_head OF((gz_statep));
|
||||
local int gz_look OF((gz_statep));
|
||||
local int gz_decomp OF((gz_statep));
|
||||
local int gz_make OF((gz_statep));
|
||||
local int gz_fetch OF((gz_statep));
|
||||
local int gz_skip OF((gz_statep, z_off64_t));
|
||||
|
||||
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
||||
|
@ -46,73 +45,54 @@ local int gz_load(state, buf, len, have)
|
|||
error, 0 otherwise. Note that the eof flag is set when the end of the input
|
||||
file is reached, even though there may be unused data in the buffer. Once
|
||||
that data has been used, no more attempts will be made to read the file.
|
||||
gz_avail() assumes that strm->avail_in == 0. */
|
||||
If strm->avail_in != 0, then the current data is moved to the beginning of
|
||||
the input buffer, and then the remainder of the buffer is loaded with the
|
||||
available data from the input file. */
|
||||
local int gz_avail(state)
|
||||
gz_statep state;
|
||||
{
|
||||
unsigned got;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
if (state->err != Z_OK)
|
||||
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
|
||||
return -1;
|
||||
if (state->eof == 0) {
|
||||
if (gz_load(state, state->in, state->size,
|
||||
(unsigned *)&(strm->avail_in)) == -1)
|
||||
if (strm->avail_in) { /* copy what's there to the start */
|
||||
unsigned char *p = state->in;
|
||||
unsigned const char *q = strm->next_in;
|
||||
unsigned n = strm->avail_in;
|
||||
do {
|
||||
*p++ = *q++;
|
||||
} while (--n);
|
||||
}
|
||||
if (gz_load(state, state->in + strm->avail_in,
|
||||
state->size - strm->avail_in, &got) == -1)
|
||||
return -1;
|
||||
strm->avail_in += got;
|
||||
strm->next_in = state->in;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get next byte from input, or -1 if end or error. */
|
||||
#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
|
||||
(strm->avail_in == 0 ? -1 : \
|
||||
(strm->avail_in--, *(strm->next_in)++)))
|
||||
|
||||
/* Get a four-byte little-endian integer and return 0 on success and the value
|
||||
in *ret. Otherwise -1 is returned and *ret is not modified. */
|
||||
local int gz_next4(state, ret)
|
||||
gz_statep state;
|
||||
unsigned long *ret;
|
||||
{
|
||||
int ch;
|
||||
unsigned long val;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
val = NEXT();
|
||||
val += (unsigned)NEXT() << 8;
|
||||
val += (unsigned long)NEXT() << 16;
|
||||
ch = NEXT();
|
||||
if (ch == -1)
|
||||
return -1;
|
||||
val += (unsigned long)ch << 24;
|
||||
*ret = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Look for gzip header, set up for inflate or copy. state->have must be zero.
|
||||
/* Look for gzip header, set up for inflate or copy. state->x.have must be 0.
|
||||
If this is the first time in, allocate required memory. state->how will be
|
||||
left unchanged if there is no more input data available, will be set to COPY
|
||||
if there is no gzip header and direct copying will be performed, or it will
|
||||
be set to GZIP for decompression, and the gzip header will be skipped so
|
||||
that the next available input data is the raw deflate stream. If direct
|
||||
copying, then leftover input data from the input buffer will be copied to
|
||||
the output buffer. In that case, all further file reads will be directly to
|
||||
either the output buffer or a user buffer. If decompressing, the inflate
|
||||
state and the check value will be initialized. gz_head() will return 0 on
|
||||
success or -1 on failure. Failures may include read errors or gzip header
|
||||
errors. */
|
||||
local int gz_head(state)
|
||||
be set to GZIP for decompression. If direct copying, then leftover input
|
||||
data from the input buffer will be copied to the output buffer. In that
|
||||
case, all further file reads will be directly to either the output buffer or
|
||||
a user buffer. If decompressing, the inflate state will be initialized.
|
||||
gz_look() will return 0 on success or -1 on failure. */
|
||||
local int gz_look(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
int flags;
|
||||
unsigned len;
|
||||
|
||||
/* allocate read buffers and inflate memory */
|
||||
if (state->size == 0) {
|
||||
/* allocate buffers */
|
||||
state->in = malloc(state->want);
|
||||
state->out = malloc(state->want << 1);
|
||||
state->in = (unsigned char *)malloc(state->want);
|
||||
state->out = (unsigned char *)malloc(state->want << 1);
|
||||
if (state->in == NULL || state->out == NULL) {
|
||||
if (state->out != NULL)
|
||||
free(state->out);
|
||||
|
@ -129,7 +109,7 @@ local int gz_head(state)
|
|||
state->strm.opaque = Z_NULL;
|
||||
state->strm.avail_in = 0;
|
||||
state->strm.next_in = Z_NULL;
|
||||
if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */
|
||||
if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
|
||||
free(state->out);
|
||||
free(state->in);
|
||||
state->size = 0;
|
||||
|
@ -138,83 +118,45 @@ local int gz_head(state)
|
|||
}
|
||||
}
|
||||
|
||||
/* get some data in the input buffer */
|
||||
if (strm->avail_in == 0) {
|
||||
/* get at least the magic bytes in the input buffer */
|
||||
if (strm->avail_in < 2) {
|
||||
if (gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* look for the gzip magic header bytes 31 and 139 */
|
||||
if (strm->next_in[0] == 31) {
|
||||
strm->avail_in--;
|
||||
strm->next_in++;
|
||||
if (strm->avail_in == 0 && gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in && strm->next_in[0] == 139) {
|
||||
/* we have a gzip header, woo hoo! */
|
||||
strm->avail_in--;
|
||||
strm->next_in++;
|
||||
|
||||
/* skip rest of header */
|
||||
if (NEXT() != 8) { /* compression method */
|
||||
gz_error(state, Z_DATA_ERROR, "unknown compression method");
|
||||
return -1;
|
||||
}
|
||||
flags = NEXT();
|
||||
if (flags & 0xe0) { /* reserved flag bits */
|
||||
gz_error(state, Z_DATA_ERROR, "unknown header flags set");
|
||||
return -1;
|
||||
}
|
||||
NEXT(); /* modification time */
|
||||
NEXT();
|
||||
NEXT();
|
||||
NEXT();
|
||||
NEXT(); /* extra flags */
|
||||
NEXT(); /* operating system */
|
||||
if (flags & 4) { /* extra field */
|
||||
len = (unsigned)NEXT();
|
||||
len += (unsigned)NEXT() << 8;
|
||||
while (len--)
|
||||
if (NEXT() < 0)
|
||||
break;
|
||||
}
|
||||
if (flags & 8) /* file name */
|
||||
while (NEXT() > 0)
|
||||
;
|
||||
if (flags & 16) /* comment */
|
||||
while (NEXT() > 0)
|
||||
;
|
||||
if (flags & 2) { /* header crc */
|
||||
NEXT();
|
||||
NEXT();
|
||||
}
|
||||
/* an unexpected end of file is not checked for here -- it will be
|
||||
noticed on the first request for uncompressed data */
|
||||
|
||||
/* set up for decompression */
|
||||
/* look for gzip magic bytes -- if there, do gzip decoding (note: there is
|
||||
a logical dilemma here when considering the case of a partially written
|
||||
gzip file, to wit, if a single 31 byte is written, then we cannot tell
|
||||
whether this is a single-byte file, or just a partially written gzip
|
||||
file -- for here we assume that if a gzip file is being written, then
|
||||
the header will be written in a single operation, so that reading a
|
||||
single byte is sufficient indication that it is not a gzip file) */
|
||||
if (strm->avail_in > 1 &&
|
||||
strm->next_in[0] == 31 && strm->next_in[1] == 139) {
|
||||
inflateReset(strm);
|
||||
strm->adler = crc32(0L, Z_NULL, 0);
|
||||
state->how = GZIP;
|
||||
state->direct = 0;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
/* not a gzip file -- save first byte (31) and fall to raw i/o */
|
||||
state->out[0] = 31;
|
||||
state->have = 1;
|
||||
}
|
||||
|
||||
/* no gzip header -- if we were decoding gzip before, then this is trailing
|
||||
garbage. Ignore the trailing garbage and finish. */
|
||||
if (state->direct == 0) {
|
||||
strm->avail_in = 0;
|
||||
state->eof = 1;
|
||||
state->x.have = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* doing raw i/o, save start of raw data for seeking, copy any leftover
|
||||
input to output -- this assumes that the output buffer is larger than
|
||||
the input buffer, which also assures space for gzungetc() */
|
||||
state->raw = state->pos;
|
||||
state->next = state->out;
|
||||
/* doing raw i/o, copy any leftover input to output -- this assumes that
|
||||
the output buffer is larger than the input buffer, which also assures
|
||||
space for gzungetc() */
|
||||
state->x.next = state->out;
|
||||
if (strm->avail_in) {
|
||||
memcpy(state->next + state->have, strm->next_in, strm->avail_in);
|
||||
state->have += strm->avail_in;
|
||||
memcpy(state->x.next, strm->next_in, strm->avail_in);
|
||||
state->x.have = strm->avail_in;
|
||||
strm->avail_in = 0;
|
||||
}
|
||||
state->how = COPY;
|
||||
|
@ -223,19 +165,15 @@ local int gz_head(state)
|
|||
}
|
||||
|
||||
/* Decompress from input to the provided next_out and avail_out in the state.
|
||||
If the end of the compressed data is reached, then verify the gzip trailer
|
||||
check value and length (modulo 2^32). state->have and state->next are set
|
||||
to point to the just decompressed data, and the crc is updated. If the
|
||||
trailer is verified, state->how is reset to LOOK to look for the next gzip
|
||||
stream or raw data, once state->have is depleted. Returns 0 on success, -1
|
||||
on failure. Failures may include invalid compressed data or a failed gzip
|
||||
trailer verification. */
|
||||
On return, state->x.have and state->x.next point to the just decompressed
|
||||
data. If the gzip stream completes, state->how is reset to LOOK to look for
|
||||
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
|
||||
on success, -1 on failure. */
|
||||
local int gz_decomp(state)
|
||||
gz_statep state;
|
||||
{
|
||||
int ret;
|
||||
int ret = Z_OK;
|
||||
unsigned had;
|
||||
unsigned long crc, len;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* fill output buffer up to end of deflate stream */
|
||||
|
@ -245,8 +183,8 @@ local int gz_decomp(state)
|
|||
if (strm->avail_in == 0 && gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0) {
|
||||
gz_error(state, Z_DATA_ERROR, "unexpected end of file");
|
||||
return -1;
|
||||
gz_error(state, Z_BUF_ERROR, "unexpected end of file");
|
||||
break;
|
||||
}
|
||||
|
||||
/* decompress and handle errors */
|
||||
|
@ -267,62 +205,50 @@ local int gz_decomp(state)
|
|||
}
|
||||
} while (strm->avail_out && ret != Z_STREAM_END);
|
||||
|
||||
/* update available output and crc check value */
|
||||
state->have = had - strm->avail_out;
|
||||
state->next = strm->next_out - state->have;
|
||||
strm->adler = crc32(strm->adler, state->next, state->have);
|
||||
/* update available output */
|
||||
state->x.have = had - strm->avail_out;
|
||||
state->x.next = strm->next_out - state->x.have;
|
||||
|
||||
/* check gzip trailer if at end of deflate stream */
|
||||
if (ret == Z_STREAM_END) {
|
||||
if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
|
||||
gz_error(state, Z_DATA_ERROR, "unexpected end of file");
|
||||
return -1;
|
||||
}
|
||||
if (crc != strm->adler) {
|
||||
gz_error(state, Z_DATA_ERROR, "incorrect data check");
|
||||
return -1;
|
||||
}
|
||||
if (len != (strm->total_out & 0xffffffffL)) {
|
||||
gz_error(state, Z_DATA_ERROR, "incorrect length check");
|
||||
return -1;
|
||||
}
|
||||
state->how = LOOK; /* ready for next stream, once have is 0 (leave
|
||||
state->direct unchanged to remember how) */
|
||||
}
|
||||
/* if the gzip stream completed successfully, look for another */
|
||||
if (ret == Z_STREAM_END)
|
||||
state->how = LOOK;
|
||||
|
||||
/* good decompression */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Make data and put in the output buffer. Assumes that state->have == 0.
|
||||
/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
|
||||
Data is either copied from the input file or decompressed from the input
|
||||
file depending on state->how. If state->how is LOOK, then a gzip header is
|
||||
looked for (and skipped if found) to determine wither to copy or decompress.
|
||||
Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY
|
||||
or GZIP unless the end of the input file has been reached and all data has
|
||||
been processed. */
|
||||
local int gz_make(state)
|
||||
looked for to determine whether to copy or decompress. Returns -1 on error,
|
||||
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
|
||||
end of the input file has been reached and all data has been processed. */
|
||||
local int gz_fetch(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
if (state->how == LOOK) { /* look for gzip header */
|
||||
if (gz_head(state) == -1)
|
||||
do {
|
||||
switch(state->how) {
|
||||
case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
|
||||
if (gz_look(state) == -1)
|
||||
return -1;
|
||||
if (state->have) /* got some data from gz_head() */
|
||||
if (state->how == LOOK)
|
||||
return 0;
|
||||
}
|
||||
if (state->how == COPY) { /* straight copy */
|
||||
if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
|
||||
break;
|
||||
case COPY: /* -> COPY */
|
||||
if (gz_load(state, state->out, state->size << 1, &(state->x.have))
|
||||
== -1)
|
||||
return -1;
|
||||
state->next = state->out;
|
||||
}
|
||||
else if (state->how == GZIP) { /* decompress */
|
||||
state->x.next = state->out;
|
||||
return 0;
|
||||
case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */
|
||||
strm->avail_out = state->size << 1;
|
||||
strm->next_out = state->out;
|
||||
if (gz_decomp(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
} while (state->x.have == 0 && (!state->eof || strm->avail_in));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -336,12 +262,12 @@ local int gz_skip(state, len)
|
|||
/* skip over len bytes or reach end-of-file, whichever comes first */
|
||||
while (len)
|
||||
/* skip over whatever is in output buffer */
|
||||
if (state->have) {
|
||||
n = GT_OFF(state->have) || (z_off64_t)state->have > len ?
|
||||
(unsigned)len : state->have;
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
if (state->x.have) {
|
||||
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
|
||||
(unsigned)len : state->x.have;
|
||||
state->x.have -= n;
|
||||
state->x.next += n;
|
||||
state->x.pos += n;
|
||||
len -= n;
|
||||
}
|
||||
|
||||
|
@ -352,7 +278,7 @@ local int gz_skip(state, len)
|
|||
/* need more data to skip -- load up output buffer */
|
||||
else {
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_make(state) == -1)
|
||||
if (gz_fetch(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -374,14 +300,15 @@ int ZEXPORT gzread(file, buf, len)
|
|||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids the flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
|
||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -400,49 +327,51 @@ int ZEXPORT gzread(file, buf, len)
|
|||
got = 0;
|
||||
do {
|
||||
/* first just try copying data from the output buffer */
|
||||
if (state->have) {
|
||||
n = state->have > len ? len : state->have;
|
||||
memcpy(buf, state->next, n);
|
||||
state->next += n;
|
||||
state->have -= n;
|
||||
if (state->x.have) {
|
||||
n = state->x.have > len ? len : state->x.have;
|
||||
memcpy(buf, state->x.next, n);
|
||||
state->x.next += n;
|
||||
state->x.have -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && strm->avail_in == 0)
|
||||
else if (state->eof && strm->avail_in == 0) {
|
||||
state->past = 1; /* tried to read past end */
|
||||
break;
|
||||
}
|
||||
|
||||
/* need output data -- for small len or new stream load up our output
|
||||
buffer */
|
||||
else if (state->how == LOOK || len < (state->size << 1)) {
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_make(state) == -1)
|
||||
if (gz_fetch(state) == -1)
|
||||
return -1;
|
||||
continue; /* no progress yet -- go back to memcpy() above */
|
||||
continue; /* no progress yet -- go back to copy above */
|
||||
/* the copy above assures that we will leave with space in the
|
||||
output buffer, allowing at least one gzungetc() to succeed */
|
||||
}
|
||||
|
||||
/* large len -- read directly into user buffer */
|
||||
else if (state->how == COPY) { /* read directly */
|
||||
if (gz_load(state, buf, len, &n) == -1)
|
||||
if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* large len -- decompress directly into user buffer */
|
||||
else { /* state->how == GZIP */
|
||||
strm->avail_out = len;
|
||||
strm->next_out = buf;
|
||||
strm->next_out = (unsigned char *)buf;
|
||||
if (gz_decomp(state) == -1)
|
||||
return -1;
|
||||
n = state->have;
|
||||
state->have = 0;
|
||||
n = state->x.have;
|
||||
state->x.have = 0;
|
||||
}
|
||||
|
||||
/* update progress */
|
||||
len -= n;
|
||||
buf = (char *)buf + n;
|
||||
got += n;
|
||||
state->pos += n;
|
||||
state->x.pos += n;
|
||||
} while (len);
|
||||
|
||||
/* return number of bytes read into user buffer (will fit in int) */
|
||||
|
@ -450,6 +379,11 @@ int ZEXPORT gzread(file, buf, len)
|
|||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
#ifdef Z_PREFIX_SET
|
||||
# undef z_gzgetc
|
||||
#else
|
||||
# undef gzgetc
|
||||
#endif
|
||||
int ZEXPORT gzgetc(file)
|
||||
gzFile file;
|
||||
{
|
||||
|
@ -462,15 +396,16 @@ int ZEXPORT gzgetc(file)
|
|||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* try output buffer (no need to check for skip request) */
|
||||
if (state->have) {
|
||||
state->have--;
|
||||
state->pos++;
|
||||
return *(state->next)++;
|
||||
if (state->x.have) {
|
||||
state->x.have--;
|
||||
state->x.pos++;
|
||||
return *(state->x.next)++;
|
||||
}
|
||||
|
||||
/* nothing there -- try gzread() */
|
||||
|
@ -478,6 +413,12 @@ int ZEXPORT gzgetc(file)
|
|||
return ret < 1 ? -1 : buf[0];
|
||||
}
|
||||
|
||||
int ZEXPORT gzgetc_(file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzgetc(file);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzungetc(c, file)
|
||||
int c;
|
||||
|
@ -490,8 +431,9 @@ int ZEXPORT gzungetc(c, file)
|
|||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* process a skip request */
|
||||
|
@ -506,32 +448,34 @@ int ZEXPORT gzungetc(c, file)
|
|||
return -1;
|
||||
|
||||
/* if output buffer empty, put byte at end (allows more pushing) */
|
||||
if (state->have == 0) {
|
||||
state->have = 1;
|
||||
state->next = state->out + (state->size << 1) - 1;
|
||||
state->next[0] = c;
|
||||
state->pos--;
|
||||
if (state->x.have == 0) {
|
||||
state->x.have = 1;
|
||||
state->x.next = state->out + (state->size << 1) - 1;
|
||||
state->x.next[0] = c;
|
||||
state->x.pos--;
|
||||
state->past = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* if no room, give up (must have already done a gzungetc()) */
|
||||
if (state->have == (state->size << 1)) {
|
||||
gz_error(state, Z_BUF_ERROR, "out of room to push characters");
|
||||
if (state->x.have == (state->size << 1)) {
|
||||
gz_error(state, Z_DATA_ERROR, "out of room to push characters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* slide output data if needed and insert byte before existing data */
|
||||
if (state->next == state->out) {
|
||||
unsigned char *src = state->out + state->have;
|
||||
if (state->x.next == state->out) {
|
||||
unsigned char *src = state->out + state->x.have;
|
||||
unsigned char *dest = state->out + (state->size << 1);
|
||||
while (src > state->out)
|
||||
*--dest = *--src;
|
||||
state->next = dest;
|
||||
state->x.next = dest;
|
||||
}
|
||||
state->have++;
|
||||
state->next--;
|
||||
state->next[0] = c;
|
||||
state->pos--;
|
||||
state->x.have++;
|
||||
state->x.next--;
|
||||
state->x.next[0] = c;
|
||||
state->x.pos--;
|
||||
state->past = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -551,8 +495,9 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||
return NULL;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return NULL;
|
||||
|
||||
/* process a skip request */
|
||||
|
@ -569,32 +514,31 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||
left = (unsigned)len - 1;
|
||||
if (left) do {
|
||||
/* assure that something is in the output buffer */
|
||||
if (state->have == 0) {
|
||||
if (gz_make(state) == -1)
|
||||
if (state->x.have == 0 && gz_fetch(state) == -1)
|
||||
return NULL; /* error */
|
||||
if (state->have == 0) { /* end of file */
|
||||
if (buf == str) /* got bupkus */
|
||||
return NULL;
|
||||
break; /* got something -- return it */
|
||||
}
|
||||
if (state->x.have == 0) { /* end of file */
|
||||
state->past = 1; /* read past end */
|
||||
break; /* return what we have */
|
||||
}
|
||||
|
||||
/* look for end-of-line in current output buffer */
|
||||
n = state->have > left ? left : state->have;
|
||||
eol = memchr(state->next, '\n', n);
|
||||
n = state->x.have > left ? left : state->x.have;
|
||||
eol = (unsigned char *)memchr(state->x.next, '\n', n);
|
||||
if (eol != NULL)
|
||||
n = (unsigned)(eol - state->next) + 1;
|
||||
n = (unsigned)(eol - state->x.next) + 1;
|
||||
|
||||
/* copy through end-of-line, or remainder if not found */
|
||||
memcpy(buf, state->next, n);
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
memcpy(buf, state->x.next, n);
|
||||
state->x.have -= n;
|
||||
state->x.next += n;
|
||||
state->x.pos += n;
|
||||
left -= n;
|
||||
buf += n;
|
||||
} while (left && eol == NULL);
|
||||
|
||||
/* found end-of-line or out of space -- terminate string and return it */
|
||||
/* return terminated string, or if nothing, end of file */
|
||||
if (buf == str)
|
||||
return NULL;
|
||||
buf[0] = 0;
|
||||
return str;
|
||||
}
|
||||
|
@ -610,16 +554,12 @@ int ZEXPORT gzdirect(file)
|
|||
return 0;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading */
|
||||
if (state->mode != GZ_READ)
|
||||
return 0;
|
||||
|
||||
/* if the state is not known, but we can find out, then do so (this is
|
||||
mainly for right after a gzopen() or gzdopen()) */
|
||||
if (state->how == LOOK && state->have == 0)
|
||||
(void)gz_head(state);
|
||||
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
|
||||
(void)gz_look(state);
|
||||
|
||||
/* return 1 if reading direct, 0 if decompressing a gzip stream */
|
||||
/* return 1 if transparent, 0 if processing a gzip stream */
|
||||
return state->direct;
|
||||
}
|
||||
|
||||
|
@ -627,7 +567,7 @@ int ZEXPORT gzdirect(file)
|
|||
int ZEXPORT gzclose_r(file)
|
||||
gzFile file;
|
||||
{
|
||||
int ret;
|
||||
int ret, err;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
|
@ -645,9 +585,10 @@ int ZEXPORT gzclose_r(file)
|
|||
free(state->out);
|
||||
free(state->in);
|
||||
}
|
||||
err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
|
||||
gz_error(state, Z_OK, NULL);
|
||||
free(state->path);
|
||||
ret = close(state->fd);
|
||||
free(state);
|
||||
return ret ? Z_ERRNO : Z_OK;
|
||||
return ret ? Z_ERRNO : err;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* gzwrite.c -- zlib functions for writing gzip files
|
||||
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -18,13 +18,18 @@ local int gz_init(state)
|
|||
int ret;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* allocate input and output buffers */
|
||||
state->in = malloc(state->want);
|
||||
state->out = malloc(state->want);
|
||||
if (state->in == NULL || state->out == NULL) {
|
||||
if (state->out != NULL)
|
||||
free(state->out);
|
||||
if (state->in != NULL)
|
||||
/* allocate input buffer */
|
||||
state->in = (unsigned char *)malloc(state->want);
|
||||
if (state->in == NULL) {
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* only need output buffer and deflate state if compressing */
|
||||
if (!state->direct) {
|
||||
/* allocate output buffer */
|
||||
state->out = (unsigned char *)malloc(state->want);
|
||||
if (state->out == NULL) {
|
||||
free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
|
@ -35,27 +40,33 @@ local int gz_init(state)
|
|||
strm->zfree = Z_NULL;
|
||||
strm->opaque = Z_NULL;
|
||||
ret = deflateInit2(strm, state->level, Z_DEFLATED,
|
||||
15 + 16, 8, state->strategy);
|
||||
MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
|
||||
if (ret != Z_OK) {
|
||||
free(state->out);
|
||||
free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* mark state as initialized */
|
||||
state->size = state->want;
|
||||
|
||||
/* initialize write buffer */
|
||||
/* initialize write buffer if compressing */
|
||||
if (!state->direct) {
|
||||
strm->avail_out = state->size;
|
||||
strm->next_out = state->out;
|
||||
state->next = strm->next_out;
|
||||
state->x.next = strm->next_out;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compress whatever is at avail_in and next_in and write to the output file.
|
||||
Return -1 if there is an error writing to the output file, otherwise 0.
|
||||
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
|
||||
then the deflate() state is reset to start a new gzip stream. */
|
||||
then the deflate() state is reset to start a new gzip stream. If gz->direct
|
||||
is true, then simply write to the output file without compressing, and
|
||||
ignore flush. */
|
||||
local int gz_comp(state, flush)
|
||||
gz_statep state;
|
||||
int flush;
|
||||
|
@ -68,6 +79,17 @@ local int gz_comp(state, flush)
|
|||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return -1;
|
||||
|
||||
/* write directly if requested */
|
||||
if (state->direct) {
|
||||
got = write(state->fd, strm->next_in, strm->avail_in);
|
||||
if (got < 0 || (unsigned)got != strm->avail_in) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
strm->avail_in = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* run deflate() on provided input until it produces no more output */
|
||||
ret = Z_OK;
|
||||
do {
|
||||
|
@ -75,8 +97,8 @@ local int gz_comp(state, flush)
|
|||
doing Z_FINISH then don't write until we get to Z_STREAM_END */
|
||||
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
||||
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
||||
have = (unsigned)(strm->next_out - state->next);
|
||||
if (have && ((got = write(state->fd, state->next, have)) < 0 ||
|
||||
have = (unsigned)(strm->next_out - state->x.next);
|
||||
if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
|
||||
(unsigned)got != have)) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
|
@ -85,7 +107,7 @@ local int gz_comp(state, flush)
|
|||
strm->avail_out = state->size;
|
||||
strm->next_out = state->out;
|
||||
}
|
||||
state->next = strm->next_out;
|
||||
state->x.next = strm->next_out;
|
||||
}
|
||||
|
||||
/* compress */
|
||||
|
@ -131,7 +153,7 @@ local int gz_zero(state, len)
|
|||
}
|
||||
strm->avail_in = n;
|
||||
strm->next_in = state->in;
|
||||
state->pos += n;
|
||||
state->x.pos += n;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return -1;
|
||||
len -= n;
|
||||
|
@ -146,7 +168,6 @@ int ZEXPORT gzwrite(file, buf, len)
|
|||
unsigned len;
|
||||
{
|
||||
unsigned put = len;
|
||||
unsigned n;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
|
@ -163,7 +184,7 @@ int ZEXPORT gzwrite(file, buf, len)
|
|||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids the flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
|
||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -186,16 +207,19 @@ int ZEXPORT gzwrite(file, buf, len)
|
|||
if (len < state->size) {
|
||||
/* copy to input buffer, compress when full */
|
||||
do {
|
||||
unsigned have, copy;
|
||||
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
n = state->size - strm->avail_in;
|
||||
if (n > len)
|
||||
n = len;
|
||||
memcpy(strm->next_in + strm->avail_in, buf, n);
|
||||
strm->avail_in += n;
|
||||
state->pos += n;
|
||||
buf = (char *)buf + n;
|
||||
len -= n;
|
||||
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
||||
copy = state->size - have;
|
||||
if (copy > len)
|
||||
copy = len;
|
||||
memcpy(state->in + have, buf, copy);
|
||||
strm->avail_in += copy;
|
||||
state->x.pos += copy;
|
||||
buf = (const char *)buf + copy;
|
||||
len -= copy;
|
||||
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
} while (len);
|
||||
|
@ -207,8 +231,8 @@ int ZEXPORT gzwrite(file, buf, len)
|
|||
|
||||
/* directly compress user buffer to file */
|
||||
strm->avail_in = len;
|
||||
strm->next_in = (voidp)buf;
|
||||
state->pos += len;
|
||||
strm->next_in = (z_const Bytef *)buf;
|
||||
state->x.pos += len;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
}
|
||||
|
@ -222,6 +246,7 @@ int ZEXPORT gzputc(file, c)
|
|||
gzFile file;
|
||||
int c;
|
||||
{
|
||||
unsigned have;
|
||||
unsigned char buf[1];
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
@ -245,19 +270,23 @@ int ZEXPORT gzputc(file, c)
|
|||
|
||||
/* try writing to input buffer for speed (state->size == 0 if buffer not
|
||||
initialized) */
|
||||
if (strm->avail_in < state->size) {
|
||||
if (state->size) {
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
strm->next_in[strm->avail_in++] = c;
|
||||
state->pos++;
|
||||
return c;
|
||||
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
||||
if (have < state->size) {
|
||||
state->in[have] = c;
|
||||
strm->avail_in++;
|
||||
state->x.pos++;
|
||||
return c & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
/* no room in buffer or not initialized, use gz_write() */
|
||||
buf[0] = c;
|
||||
if (gzwrite(file, buf, 1) != 1)
|
||||
return -1;
|
||||
return c;
|
||||
return c & 0xff;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
|
@ -274,16 +303,15 @@ int ZEXPORT gzputs(file, str)
|
|||
return ret == 0 && len != 0 ? -1 : ret;
|
||||
}
|
||||
|
||||
#ifdef STDC
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
#include <stdarg.h>
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
|
||||
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
||||
{
|
||||
int size, len;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
va_list va;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
|
@ -313,25 +341,20 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
|
|||
/* do the printf() into the input buffer, put length in len */
|
||||
size = (int)(state->size);
|
||||
state->in[size - 1] = 0;
|
||||
va_start(va, format);
|
||||
#ifdef NO_vsnprintf
|
||||
# ifdef HAS_vsprintf_void
|
||||
(void)vsprintf(state->in, format, va);
|
||||
va_end(va);
|
||||
(void)vsprintf((char *)(state->in), format, va);
|
||||
for (len = 0; len < size; len++)
|
||||
if (state->in[len] == 0) break;
|
||||
# else
|
||||
len = vsprintf(state->in, format, va);
|
||||
va_end(va);
|
||||
len = vsprintf((char *)(state->in), format, va);
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAS_vsnprintf_void
|
||||
(void)vsnprintf(state->in, size, format, va);
|
||||
va_end(va);
|
||||
len = strlen(state->in);
|
||||
(void)vsnprintf((char *)(state->in), size, format, va);
|
||||
len = strlen((char *)(state->in));
|
||||
# else
|
||||
len = vsnprintf((char *)(state->in), size, format, va);
|
||||
va_end(va);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
@ -342,11 +365,22 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
|
|||
/* update buffer and position, defer compression until needed */
|
||||
strm->avail_in = (unsigned)len;
|
||||
strm->next_in = state->in;
|
||||
state->pos += len;
|
||||
state->x.pos += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
#else /* !STDC */
|
||||
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
int ret;
|
||||
|
||||
va_start(va, format);
|
||||
ret = gzvprintf(file, format, va);
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* !STDC && !Z_HAVE_STDARG_H */
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
|
@ -366,6 +400,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
|||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that can really pass pointer in ints */
|
||||
if (sizeof(int) != sizeof(void *))
|
||||
return 0;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
|
@ -390,22 +428,23 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
|||
state->in[size - 1] = 0;
|
||||
#ifdef NO_snprintf
|
||||
# ifdef HAS_sprintf_void
|
||||
sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
for (len = 0; len < size; len++)
|
||||
if (state->in[len] == 0) break;
|
||||
# else
|
||||
len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAS_snprintf_void
|
||||
snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
len = strlen(state->in);
|
||||
len = strlen((char *)(state->in));
|
||||
# else
|
||||
len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
|
||||
a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
|
||||
a19, a20);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
@ -416,7 +455,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
|||
/* update buffer and position, defer compression until needed */
|
||||
strm->avail_in = (unsigned)len;
|
||||
strm->next_in = state->in;
|
||||
state->pos += len;
|
||||
state->x.pos += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -500,7 +539,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
|
|||
int ZEXPORT gzclose_w(file)
|
||||
gzFile file;
|
||||
{
|
||||
int ret = 0;
|
||||
int ret = Z_OK;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
|
@ -515,17 +554,24 @@ int ZEXPORT gzclose_w(file)
|
|||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
ret += gz_zero(state, state->skip);
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
ret = state->err;
|
||||
}
|
||||
|
||||
/* flush, free memory, and close file */
|
||||
ret += gz_comp(state, Z_FINISH);
|
||||
if (gz_comp(state, Z_FINISH) == -1)
|
||||
ret = state->err;
|
||||
if (state->size) {
|
||||
if (!state->direct) {
|
||||
(void)deflateEnd(&(state->strm));
|
||||
free(state->out);
|
||||
}
|
||||
free(state->in);
|
||||
}
|
||||
gz_error(state, Z_OK, NULL);
|
||||
free(state->path);
|
||||
ret += close(state->fd);
|
||||
if (close(state->fd) == -1)
|
||||
ret = Z_ERRNO;
|
||||
free(state);
|
||||
return ret ? Z_ERRNO : Z_OK;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* infback.c -- inflate using a call-back interface
|
||||
* Copyright (C) 1995-2009 Mark Adler
|
||||
* Copyright (C) 1995-2011 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -42,10 +42,19 @@ int stream_size;
|
|||
return Z_STREAM_ERROR;
|
||||
strm->msg = Z_NULL; /* in case we return an error */
|
||||
if (strm->zalloc == (alloc_func)0) {
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
#endif
|
||||
}
|
||||
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
|
||||
if (strm->zfree == (free_func)0)
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zfree = zcfree;
|
||||
#endif
|
||||
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
|
||||
sizeof(struct inflate_state));
|
||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||
|
@ -246,7 +255,7 @@ out_func out;
|
|||
void FAR *out_desc;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *next; /* next input */
|
||||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
|
@ -394,7 +403,6 @@ void FAR *out_desc;
|
|||
PULLBYTE();
|
||||
}
|
||||
if (here.val < 16) {
|
||||
NEEDBITS(here.bits);
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* inffast.c -- fast decoding
|
||||
* Copyright (C) 1995-2008, 2010 Mark Adler
|
||||
* Copyright (C) 1995-2008, 2010, 2013 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -69,8 +69,8 @@ z_streamp strm;
|
|||
unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *in; /* local strm->next_in */
|
||||
unsigned char FAR *last; /* while in < last, enough input available */
|
||||
z_const unsigned char FAR *in; /* local strm->next_in */
|
||||
z_const unsigned char FAR *last; /* have enough input while in < last */
|
||||
unsigned char FAR *out; /* local strm->next_out */
|
||||
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
||||
unsigned char FAR *end; /* while out < end, enough space available */
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
* Generated automatically by makefixed().
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It
|
||||
is part of the implementation of the compression library and
|
||||
is subject to change. Applications should only use zlib.h.
|
||||
/* WARNING: this file should *not* be used by applications.
|
||||
It is part of the implementation of this library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
static const code lenfix[512] = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* inflate.c -- zlib decompression
|
||||
* Copyright (C) 1995-2010 Mark Adler
|
||||
* Copyright (C) 1995-2012 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -93,14 +93,15 @@
|
|||
|
||||
/* function prototypes */
|
||||
local void fixedtables OF((struct inflate_state FAR *state));
|
||||
local int updatewindow OF((z_streamp strm, unsigned out));
|
||||
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
|
||||
unsigned copy));
|
||||
#ifdef BUILDFIXED
|
||||
void makefixed OF((void));
|
||||
#endif
|
||||
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
|
||||
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
|
||||
unsigned len));
|
||||
|
||||
int ZEXPORT inflateReset(strm)
|
||||
int ZEXPORT inflateResetKeep(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
@ -109,15 +110,13 @@ z_streamp strm;
|
|||
state = (struct inflate_state FAR *)strm->state;
|
||||
strm->total_in = strm->total_out = state->total = 0;
|
||||
strm->msg = Z_NULL;
|
||||
strm->adler = 1; /* to support ill-conceived Java test suite */
|
||||
if (state->wrap) /* to support ill-conceived Java test suite */
|
||||
strm->adler = state->wrap & 1;
|
||||
state->mode = HEAD;
|
||||
state->last = 0;
|
||||
state->havedict = 0;
|
||||
state->dmax = 32768U;
|
||||
state->head = Z_NULL;
|
||||
state->wsize = 0;
|
||||
state->whave = 0;
|
||||
state->wnext = 0;
|
||||
state->hold = 0;
|
||||
state->bits = 0;
|
||||
state->lencode = state->distcode = state->next = state->codes;
|
||||
|
@ -127,6 +126,19 @@ z_streamp strm;
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateReset(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
state->wsize = 0;
|
||||
state->whave = 0;
|
||||
state->wnext = 0;
|
||||
return inflateResetKeep(strm);
|
||||
}
|
||||
|
||||
int ZEXPORT inflateReset2(strm, windowBits)
|
||||
z_streamp strm;
|
||||
int windowBits;
|
||||
|
@ -180,10 +192,19 @@ int stream_size;
|
|||
if (strm == Z_NULL) return Z_STREAM_ERROR;
|
||||
strm->msg = Z_NULL; /* in case we return an error */
|
||||
if (strm->zalloc == (alloc_func)0) {
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
#endif
|
||||
}
|
||||
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
|
||||
if (strm->zfree == (free_func)0)
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zfree = zcfree;
|
||||
#endif
|
||||
state = (struct inflate_state FAR *)
|
||||
ZALLOC(strm, 1, sizeof(struct inflate_state));
|
||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||
|
@ -321,8 +342,8 @@ void makefixed()
|
|||
low = 0;
|
||||
for (;;) {
|
||||
if ((low % 7) == 0) printf("\n ");
|
||||
printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
|
||||
state.lencode[low].val);
|
||||
printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
|
||||
state.lencode[low].bits, state.lencode[low].val);
|
||||
if (++low == size) break;
|
||||
putchar(',');
|
||||
}
|
||||
|
@ -355,12 +376,13 @@ void makefixed()
|
|||
output will fall in the output data, making match copies simpler and faster.
|
||||
The advantage may be dependent on the size of the processor's data caches.
|
||||
*/
|
||||
local int updatewindow(strm, out)
|
||||
local int updatewindow(strm, end, copy)
|
||||
z_streamp strm;
|
||||
unsigned out;
|
||||
const Bytef *end;
|
||||
unsigned copy;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned copy, dist;
|
||||
unsigned dist;
|
||||
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
|
||||
|
@ -380,19 +402,18 @@ unsigned out;
|
|||
}
|
||||
|
||||
/* copy state->wsize or less output bytes into the circular window */
|
||||
copy = out - strm->avail_out;
|
||||
if (copy >= state->wsize) {
|
||||
zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
|
||||
zmemcpy(state->window, end - state->wsize, state->wsize);
|
||||
state->wnext = 0;
|
||||
state->whave = state->wsize;
|
||||
}
|
||||
else {
|
||||
dist = state->wsize - state->wnext;
|
||||
if (dist > copy) dist = copy;
|
||||
zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
|
||||
zmemcpy(state->window + state->wnext, end - copy, dist);
|
||||
copy -= dist;
|
||||
if (copy) {
|
||||
zmemcpy(state->window, strm->next_out - copy, copy);
|
||||
zmemcpy(state->window, end - copy, copy);
|
||||
state->wnext = copy;
|
||||
state->whave = state->wsize;
|
||||
}
|
||||
|
@ -499,11 +520,6 @@ unsigned out;
|
|||
bits -= bits & 7; \
|
||||
} while (0)
|
||||
|
||||
/* Reverse the bytes in a 32-bit value */
|
||||
#define REVERSE(q) \
|
||||
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||
|
||||
/*
|
||||
inflate() uses a state machine to process as much input data and generate as
|
||||
much output data as possible before returning. The state machine is
|
||||
|
@ -591,7 +607,7 @@ z_streamp strm;
|
|||
int flush;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *next; /* next input */
|
||||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
|
@ -797,7 +813,7 @@ int flush;
|
|||
#endif
|
||||
case DICTID:
|
||||
NEEDBITS(32);
|
||||
strm->adler = state->check = REVERSE(hold);
|
||||
strm->adler = state->check = ZSWAP32(hold);
|
||||
INITBITS();
|
||||
state->mode = DICT;
|
||||
case DICT:
|
||||
|
@ -905,7 +921,7 @@ int flush;
|
|||
while (state->have < 19)
|
||||
state->lens[order[state->have++]] = 0;
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lencode = (const code FAR *)(state->next);
|
||||
state->lenbits = 7;
|
||||
ret = inflate_table(CODES, state->lens, 19, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
|
@ -925,7 +941,6 @@ int flush;
|
|||
PULLBYTE();
|
||||
}
|
||||
if (here.val < 16) {
|
||||
NEEDBITS(here.bits);
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
|
@ -980,7 +995,7 @@ int flush;
|
|||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lencode = (const code FAR *)(state->next);
|
||||
state->lenbits = 9;
|
||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
|
@ -989,7 +1004,7 @@ int flush;
|
|||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->distcode = (code const FAR *)(state->next);
|
||||
state->distcode = (const code FAR *)(state->next);
|
||||
state->distbits = 6;
|
||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
|
@ -1170,7 +1185,7 @@ int flush;
|
|||
#ifdef GUNZIP
|
||||
state->flags ? hold :
|
||||
#endif
|
||||
REVERSE(hold)) != state->check) {
|
||||
ZSWAP32(hold)) != state->check) {
|
||||
strm->msg = (char *)"incorrect data check";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
|
@ -1214,8 +1229,9 @@ int flush;
|
|||
*/
|
||||
inf_leave:
|
||||
RESTORE();
|
||||
if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
|
||||
if (updatewindow(strm, out)) {
|
||||
if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
|
||||
(state->mode < CHECK || flush != Z_FINISH)))
|
||||
if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
|
||||
state->mode = MEM;
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
|
@ -1249,13 +1265,37 @@ z_streamp strm;
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
|
||||
z_streamp strm;
|
||||
Bytef *dictionary;
|
||||
uInt *dictLength;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
/* check state */
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
|
||||
/* copy dictionary */
|
||||
if (state->whave && dictionary != Z_NULL) {
|
||||
zmemcpy(dictionary, state->window + state->wnext,
|
||||
state->whave - state->wnext);
|
||||
zmemcpy(dictionary + state->whave - state->wnext,
|
||||
state->window, state->wnext);
|
||||
}
|
||||
if (dictLength != Z_NULL)
|
||||
*dictLength = state->whave;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
|
||||
z_streamp strm;
|
||||
const Bytef *dictionary;
|
||||
uInt dictLength;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned long id;
|
||||
unsigned long dictid;
|
||||
int ret;
|
||||
|
||||
/* check state */
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
|
@ -1263,29 +1303,21 @@ uInt dictLength;
|
|||
if (state->wrap != 0 && state->mode != DICT)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* check for correct dictionary id */
|
||||
/* check for correct dictionary identifier */
|
||||
if (state->mode == DICT) {
|
||||
id = adler32(0L, Z_NULL, 0);
|
||||
id = adler32(id, dictionary, dictLength);
|
||||
if (id != state->check)
|
||||
dictid = adler32(0L, Z_NULL, 0);
|
||||
dictid = adler32(dictid, dictionary, dictLength);
|
||||
if (dictid != state->check)
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
|
||||
/* copy dictionary to window */
|
||||
if (updatewindow(strm, strm->avail_out)) {
|
||||
/* copy dictionary to window using updatewindow(), which will amend the
|
||||
existing dictionary if appropriate */
|
||||
ret = updatewindow(strm, dictionary + dictLength, dictLength);
|
||||
if (ret) {
|
||||
state->mode = MEM;
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
if (dictLength > state->wsize) {
|
||||
zmemcpy(state->window, dictionary + dictLength - state->wsize,
|
||||
state->wsize);
|
||||
state->whave = state->wsize;
|
||||
}
|
||||
else {
|
||||
zmemcpy(state->window + state->wsize - dictLength, dictionary,
|
||||
dictLength);
|
||||
state->whave = dictLength;
|
||||
}
|
||||
state->havedict = 1;
|
||||
Tracev((stderr, "inflate: dictionary set\n"));
|
||||
return Z_OK;
|
||||
|
@ -1321,7 +1353,7 @@ gz_headerp head;
|
|||
*/
|
||||
local unsigned syncsearch(have, buf, len)
|
||||
unsigned FAR *have;
|
||||
unsigned char FAR *buf;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
unsigned got;
|
||||
|
@ -1433,8 +1465,8 @@ z_streamp source;
|
|||
}
|
||||
|
||||
/* copy state */
|
||||
zmemcpy(dest, source, sizeof(z_stream));
|
||||
zmemcpy(copy, state, sizeof(struct inflate_state));
|
||||
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
|
||||
zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
|
||||
if (state->lencode >= state->codes &&
|
||||
state->lencode <= state->codes + ENOUGH - 1) {
|
||||
copy->lencode = copy->codes + (state->lencode - state->codes);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2010 Mark Adler
|
||||
* Copyright (C) 1995-2013 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.5 Copyright 1995-2010 Mark Adler ";
|
||||
" inflate 1.2.8 Copyright 1995-2013 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
|
||||
|
@ -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, 73, 195};
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
|
||||
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,
|
||||
|
@ -208,8 +208,8 @@ unsigned short FAR *work;
|
|||
mask = used - 1; /* mask for comparing low */
|
||||
|
||||
/* check available table space */
|
||||
if ((type == LENS && used >= ENOUGH_LENS) ||
|
||||
(type == DISTS && used >= ENOUGH_DISTS))
|
||||
if ((type == LENS && used > ENOUGH_LENS) ||
|
||||
(type == DISTS && used > ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* process all codes and make table entries */
|
||||
|
@ -277,8 +277,8 @@ unsigned short FAR *work;
|
|||
|
||||
/* check for enough space */
|
||||
used += 1U << curr;
|
||||
if ((type == LENS && used >= ENOUGH_LENS) ||
|
||||
(type == DISTS && used >= ENOUGH_DISTS))
|
||||
if ((type == LENS && used > ENOUGH_LENS) ||
|
||||
(type == DISTS && used > ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* point entry in root table to sub-table */
|
||||
|
@ -289,38 +289,14 @@ unsigned short FAR *work;
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Fill in rest of table for incomplete codes. This loop is similar to the
|
||||
loop above in incrementing huff for table indices. It is assumed that
|
||||
len is equal to curr + drop, so there is no loop needed to increment
|
||||
through high index bits. When the current sub-table is filled, the loop
|
||||
drops back to the root table to fill in any remaining entries there.
|
||||
*/
|
||||
/* fill in remaining table entry if code is incomplete (guaranteed to have
|
||||
at most one remaining entry, since if the code is incomplete, the
|
||||
maximum code length that was allowed to get this far is one bit) */
|
||||
if (huff != 0) {
|
||||
here.op = (unsigned char)64; /* invalid code marker */
|
||||
here.bits = (unsigned char)(len - drop);
|
||||
here.val = (unsigned short)0;
|
||||
while (huff != 0) {
|
||||
/* when done with sub-table, drop back to root table */
|
||||
if (drop != 0 && (huff & mask) != low) {
|
||||
drop = 0;
|
||||
len = root;
|
||||
next = *table;
|
||||
here.bits = (unsigned char)len;
|
||||
}
|
||||
|
||||
/* put invalid code marker in table */
|
||||
next[huff >> drop] = here;
|
||||
|
||||
/* backwards increment the len-bit code huff */
|
||||
incr = 1U << (len - 1);
|
||||
while (huff & incr)
|
||||
incr >>= 1;
|
||||
if (incr != 0) {
|
||||
huff &= incr - 1;
|
||||
huff += incr;
|
||||
}
|
||||
else
|
||||
huff = 0;
|
||||
next[huff] = here;
|
||||
}
|
||||
|
||||
/* set return parameters */
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
examples/enough.c found in the zlib distribtution. The arguments to that
|
||||
program are the number of symbols, the initial root table size, and the
|
||||
maximum bit length of a code. "enough 286 9 15" for literal/length codes
|
||||
returns 852, and "enough 30 6 15" for distance codes returns 592.
|
||||
returns returns 852, and "enough 30 6 15" for distance codes returns 592.
|
||||
The initial root table size (9 or 6) is found in the fifth argument of the
|
||||
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
||||
changed, then these maximum sizes would be need to be recalculated and
|
||||
|
|
|
@ -3,7 +3,7 @@ $! Martin P.J. Zinser
|
|||
$!
|
||||
$! In case of problems with the install you might contact me at
|
||||
$! zinser@zinser.no-ip.info(preferred) or
|
||||
$! zinser@sysdev.deutsche-boerse.com (work)
|
||||
$! martin.zinser@eurexchange.com (work)
|
||||
$!
|
||||
$! Make procedure history for Zlib
|
||||
$!
|
||||
|
@ -14,9 +14,16 @@ $! 0.02 20061008 Adapt to new Makefile.in
|
|||
$! 0.03 20091224 Add support for large file check
|
||||
$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite
|
||||
$! 0.05 20100221 Exchange zlibdefs.h by zconf.h.in
|
||||
$! 0.06 20120111 Fix missing amiss_err, update zconf_h.in, fix new exmples
|
||||
$! subdir path, update module search in makefile.in
|
||||
$! 0.07 20120115 Triggered by work done by Alexey Chupahin completly redesigned
|
||||
$! shared image creation
|
||||
$! 0.08 20120219 Make it work on VAX again, pre-load missing symbols to shared
|
||||
$! image
|
||||
$! 0.09 20120305 SMS. P1 sets builder ("MMK", "MMS", " " (built-in)).
|
||||
$! "" -> automatic, preference: MMK, MMS, built-in.
|
||||
$!
|
||||
$ on error then goto err_exit
|
||||
$ set proc/parse=ext
|
||||
$!
|
||||
$ true = 1
|
||||
$ false = 0
|
||||
|
@ -32,31 +39,43 @@ $ s_case = False
|
|||
$!
|
||||
$! Setup variables holding "config" information
|
||||
$!
|
||||
$ Make = ""
|
||||
$ Make = "''p1'"
|
||||
$ name = "Zlib"
|
||||
$ version = "?.?.?"
|
||||
$ v_string = "ZLIB_VERSION"
|
||||
$ v_file = "zlib.h"
|
||||
$ ccopt = ""
|
||||
$ ccopt = "/include = []"
|
||||
$ lopts = ""
|
||||
$ dnsrl = ""
|
||||
$ aconf_in_file = "zconf.h.in#zconf.h_in"
|
||||
$ aconf_in_file = "zconf.h.in#zconf.h_in#zconf_h.in"
|
||||
$ conf_check_string = ""
|
||||
$ linkonly = false
|
||||
$ optfile = name + ".opt"
|
||||
$ mapfile = name + ".map"
|
||||
$ libdefs = ""
|
||||
$ vax = f$getsyi("HW_MODEL").lt.1024
|
||||
$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096
|
||||
$ ia64 = f$getsyi("HW_MODEL").ge.4096
|
||||
$!
|
||||
$ whoami = f$parse(f$enviornment("Procedure"),,,,"NO_CONCEAL")
|
||||
$! 2012-03-05 SMS.
|
||||
$! Why is this needed? And if it is needed, why not simply ".not. vax"?
|
||||
$!
|
||||
$!!! if axp .or. ia64 then set proc/parse=extended
|
||||
$!
|
||||
$ whoami = f$parse(f$environment("Procedure"),,,,"NO_CONCEAL")
|
||||
$ mydef = F$parse(whoami,,,"DEVICE")
|
||||
$ mydir = f$parse(whoami,,,"DIRECTORY") - "]["
|
||||
$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type")
|
||||
$!
|
||||
$! Check for MMK/MMS
|
||||
$!
|
||||
$ if (Make .eqs. "")
|
||||
$ then
|
||||
$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS"
|
||||
$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK"
|
||||
$!
|
||||
$ else
|
||||
$ Make = f$edit( Make, "trim")
|
||||
$ endif
|
||||
$!
|
||||
$ gosub find_version
|
||||
$!
|
||||
|
@ -69,6 +88,7 @@ $! Look for the compiler used
|
|||
$!
|
||||
$ gosub check_compiler
|
||||
$ close topt
|
||||
$ close optf
|
||||
$!
|
||||
$ if its_decc
|
||||
$ then
|
||||
|
@ -83,6 +103,15 @@ $ ccopt = "/decc" + ccopt
|
|||
$ define sys decc$library_include:
|
||||
$ endif
|
||||
$ endif
|
||||
$!
|
||||
$! 2012-03-05 SMS.
|
||||
$! Why /NAMES = AS_IS? Why not simply ".not. vax"? And why not on VAX?
|
||||
$!
|
||||
$ if axp .or. ia64
|
||||
$ then
|
||||
$ ccopt = ccopt + "/name=as_is/opt=(inline=speed)"
|
||||
$ s_case = true
|
||||
$ endif
|
||||
$ endif
|
||||
$ if its_vaxc .or. its_gnuc
|
||||
$ then
|
||||
|
@ -122,15 +151,20 @@ $ gosub check_config
|
|||
$ endif
|
||||
$ goto aconf_loop
|
||||
$ACONF_EXIT:
|
||||
$ write aconf ""
|
||||
$ write aconf "/* VMS specifics added by make_vms.com: */"
|
||||
$ write aconf "#define VMS 1"
|
||||
$ write aconf "#include <unistd.h>"
|
||||
$ write aconf "#include <unixio.h>"
|
||||
$ write aconf "#ifdef _LARGEFILE"
|
||||
$ write aconf "#define off64_t __off64_t"
|
||||
$ write aconf "#define fopen64 fopen"
|
||||
$ write aconf "#define fseeko64 fseeko"
|
||||
$ write aconf "#define lseek64 lseek"
|
||||
$ write aconf "#define ftello64 ftell"
|
||||
$ write aconf "# define off64_t __off64_t"
|
||||
$ write aconf "# define fopen64 fopen"
|
||||
$ write aconf "# define fseeko64 fseeko"
|
||||
$ write aconf "# define lseek64 lseek"
|
||||
$ write aconf "# define ftello64 ftell"
|
||||
$ write aconf "#endif"
|
||||
$ write aconf "#if !defined( __VAX) && (__CRTL_VER >= 70312000)"
|
||||
$ write aconf "# define HAVE_VSNPRINTF"
|
||||
$ write aconf "#endif"
|
||||
$ close aconf_in
|
||||
$ close aconf
|
||||
|
@ -140,7 +174,8 @@ $!
|
|||
$ write sys$output "Compiling Zlib sources ..."
|
||||
$ if make.eqs.""
|
||||
$ then
|
||||
$ dele example.obj;*,minigzip.obj;*
|
||||
$ if (f$search( "example.obj;*") .nes. "") then delete example.obj;*
|
||||
$ if (f$search( "minigzip.obj;*") .nes. "") then delete minigzip.obj;*
|
||||
$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" -
|
||||
adler32.c zlib.h zconf.h
|
||||
$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" -
|
||||
|
@ -174,41 +209,34 @@ $ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" -
|
|||
$ write sys$output "Building Zlib ..."
|
||||
$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ
|
||||
$ write sys$output "Building example..."
|
||||
$ CALL MAKE example.OBJ "CC ''CCOPT' example" -
|
||||
example.c zlib.h zconf.h
|
||||
$ CALL MAKE example.OBJ "CC ''CCOPT' [.test]example" -
|
||||
[.test]example.c zlib.h zconf.h
|
||||
$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb
|
||||
$ if f$search("x11vms:xvmsutils.olb") .nes. ""
|
||||
$ then
|
||||
$ write sys$output "Building minigzip..."
|
||||
$ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" -
|
||||
minigzip.c zlib.h zconf.h
|
||||
$ CALL MAKE minigzip.OBJ "CC ''CCOPT' [.test]minigzip" -
|
||||
[.test]minigzip.c zlib.h zconf.h
|
||||
$ call make minigzip.exe -
|
||||
"LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" -
|
||||
"LINK minigzip,libz.olb/lib" -
|
||||
minigzip.obj libz.olb
|
||||
$ endif
|
||||
$ else
|
||||
$ gosub crea_mms
|
||||
$ write sys$output "Make ''name' ''version' with ''Make' "
|
||||
$ 'make'
|
||||
$ endif
|
||||
$!
|
||||
$! Alpha gets a shareable image
|
||||
$! Create shareable image
|
||||
$!
|
||||
$ If axp
|
||||
$ Then
|
||||
$ gosub crea_olist
|
||||
$ write sys$output "Creating libzshr.exe"
|
||||
$ call anal_obj_axp modules.opt _link.opt
|
||||
$ if s_case
|
||||
$ then
|
||||
$ open/append optf modules.opt
|
||||
$ write optf "case_sensitive=YES"
|
||||
$ close optf
|
||||
$ endif
|
||||
$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,_link.opt/opt
|
||||
$ endif
|
||||
$ call map_2_shopt 'mapfile' 'optfile'
|
||||
$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,'optfile'/opt
|
||||
$ write sys$output "Zlib build completed"
|
||||
$ delete/nolog tmp.opt;*
|
||||
$ exit
|
||||
$AMISS_ERR:
|
||||
$ write sys$output "No source for config.hin found."
|
||||
$ write sys$output "Tried any of ''aconf_in_file'"
|
||||
$ goto err_exit
|
||||
$CC_ERR:
|
||||
$ write sys$output "C compiler required to build ''name'"
|
||||
$ goto err_exit
|
||||
|
@ -216,7 +244,6 @@ $ERR_EXIT:
|
|||
$ set message/facil/ident/sever/text
|
||||
$ close/nolog optf
|
||||
$ close/nolog topt
|
||||
$ close/nolog conf_hin
|
||||
$ close/nolog aconf_in
|
||||
$ close/nolog aconf
|
||||
$ close/nolog out
|
||||
|
@ -397,7 +424,7 @@ $ copy sys$input: out
|
|||
$ deck
|
||||
# descrip.mms: MMS description file for building zlib on VMS
|
||||
# written by Martin P.J. Zinser
|
||||
# <zinser@zinser.no-ip.info or zinser@sysdev.deutsche-boerse.com>
|
||||
# <zinser@zinser.no-ip.info or martin.zinser@eurexchange.com>
|
||||
|
||||
OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\
|
||||
gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\
|
||||
|
@ -407,10 +434,9 @@ OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\
|
|||
$ eod
|
||||
$ write out "CFLAGS=", ccopt
|
||||
$ write out "LOPTS=", lopts
|
||||
$ write out "all : example.exe minigzip.exe libz.olb"
|
||||
$ copy sys$input: out
|
||||
$ deck
|
||||
|
||||
all : example.exe minigzip.exe libz.olb
|
||||
@ write sys$output " Example applications available"
|
||||
|
||||
libz.olb : libz.olb($(OBJS))
|
||||
|
@ -420,7 +446,7 @@ example.exe : example.obj libz.olb
|
|||
link $(LOPTS) example,libz.olb/lib
|
||||
|
||||
minigzip.exe : minigzip.obj libz.olb
|
||||
link $(LOPTS) minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib
|
||||
link $(LOPTS) minigzip,libz.olb/lib
|
||||
|
||||
clean :
|
||||
delete *.obj;*,libz.olb;*,*.opt;*,*.exe;*
|
||||
|
@ -431,7 +457,7 @@ adler32.obj : adler32.c zutil.h zlib.h zconf.h
|
|||
compress.obj : compress.c zlib.h zconf.h
|
||||
crc32.obj : crc32.c zutil.h zlib.h zconf.h
|
||||
deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
example.obj : example.c zlib.h zconf.h
|
||||
example.obj : [.test]example.c zlib.h zconf.h
|
||||
gzclose.obj : gzclose.c zutil.h zlib.h zconf.h
|
||||
gzlib.obj : gzlib.c zutil.h zlib.h zconf.h
|
||||
gzread.obj : gzread.c zutil.h zlib.h zconf.h
|
||||
|
@ -439,7 +465,7 @@ gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h
|
|||
inffast.obj : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h
|
||||
inflate.obj : inflate.c zutil.h zlib.h zconf.h
|
||||
inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h
|
||||
minigzip.obj : minigzip.c zlib.h zconf.h
|
||||
minigzip.obj : [.test]minigzip.c zlib.h zconf.h
|
||||
trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h
|
||||
uncompr.obj : uncompr.c zlib.h zconf.h
|
||||
zutil.obj : zutil.c zutil.h zlib.h zconf.h
|
||||
|
@ -455,13 +481,18 @@ $!
|
|||
$CREA_OLIST:
|
||||
$ open/read min makefile.in
|
||||
$ open/write mod modules.opt
|
||||
$ src_check = "OBJC ="
|
||||
$ src_check_list = "OBJZ =#OBJG ="
|
||||
$MRLOOP:
|
||||
$ read/end=mrdone min rec
|
||||
$ if (f$extract(0,6,rec) .nes. src_check) then goto mrloop
|
||||
$ i = 0
|
||||
$SRC_CHECK_LOOP:
|
||||
$ src_check = f$element(i, "#", src_check_list)
|
||||
$ i = i+1
|
||||
$ if src_check .eqs. "#" then goto mrloop
|
||||
$ if (f$extract(0,6,rec) .nes. src_check) then goto src_check_loop
|
||||
$ rec = rec - src_check
|
||||
$ gosub extra_filnam
|
||||
$ if (f$element(1,"\",rec) .eqs. "\") then goto mrdone
|
||||
$ if (f$element(1,"\",rec) .eqs. "\") then goto mrloop
|
||||
$MRSLOOP:
|
||||
$ read/end=mrdone min rec
|
||||
$ gosub extra_filnam
|
||||
|
@ -672,124 +703,6 @@ $ endif
|
|||
$ return
|
||||
$!------------------------------------------------------------------------------
|
||||
$!
|
||||
$! Analyze Object files for OpenVMS AXP to extract Procedure and Data
|
||||
$! information to build a symbol vector for a shareable image
|
||||
$! All the "brains" of this logic was suggested by Hartmut Becker
|
||||
$! (Hartmut.Becker@compaq.com). All the bugs were introduced by me
|
||||
$! (zinser@zinser.no-ip.info), so if you do have problem reports please do not
|
||||
$! bother Hartmut/HP, but get in touch with me
|
||||
$!
|
||||
$! Version history
|
||||
$! 0.01 20040406 Skip over shareable images in option file
|
||||
$! 0.02 20041109 Fix option file for shareable images with case_sensitive=YES
|
||||
$! 0.03 20050107 Skip over Identification labels in option file
|
||||
$! 0.04 20060117 Add uppercase alias to code compiled with /name=as_is
|
||||
$!
|
||||
$ ANAL_OBJ_AXP: Subroutine
|
||||
$ V = 'F$Verify(0)
|
||||
$ SAY := "WRITE_ SYS$OUTPUT"
|
||||
$
|
||||
$ IF F$SEARCH("''P1'") .EQS. ""
|
||||
$ THEN
|
||||
$ SAY "ANAL_OBJ_AXP-E-NOSUCHFILE: Error, inputfile ''p1' not available"
|
||||
$ goto exit_aa
|
||||
$ ENDIF
|
||||
$ IF "''P2'" .EQS. ""
|
||||
$ THEN
|
||||
$ SAY "ANAL_OBJ_AXP: Error, no output file provided"
|
||||
$ goto exit_aa
|
||||
$ ENDIF
|
||||
$
|
||||
$ open/read in 'p1
|
||||
$ create a.tmp
|
||||
$ open/append atmp a.tmp
|
||||
$ loop:
|
||||
$ read/end=end_loop in line
|
||||
$ if f$locate("/SHARE",f$edit(line,"upcase")) .lt. f$length(line)
|
||||
$ then
|
||||
$ write sys$output "ANAL_SKP_SHR-i-skipshare, ''line'"
|
||||
$ goto loop
|
||||
$ endif
|
||||
$ if f$locate("IDENTIFICATION=",f$edit(line,"upcase")) .lt. f$length(line)
|
||||
$ then
|
||||
$ write sys$output "ANAL_OBJ_AXP-i-ident: Identification ", -
|
||||
f$element(1,"=",line)
|
||||
$ goto loop
|
||||
$ endif
|
||||
$ f= f$search(line)
|
||||
$ if f .eqs. ""
|
||||
$ then
|
||||
$ write sys$output "ANAL_OBJ_AXP-w-nosuchfile, ''line'"
|
||||
$ goto loop
|
||||
$ endif
|
||||
$ define/user sys$output nl:
|
||||
$ define/user sys$error nl:
|
||||
$ anal/obj/gsd 'f /out=x.tmp
|
||||
$ open/read xtmp x.tmp
|
||||
$ XLOOP:
|
||||
$ read/end=end_xloop xtmp xline
|
||||
$ xline = f$edit(xline,"compress")
|
||||
$ write atmp xline
|
||||
$ goto xloop
|
||||
$ END_XLOOP:
|
||||
$ close xtmp
|
||||
$ goto loop
|
||||
$ end_loop:
|
||||
$ close in
|
||||
$ close atmp
|
||||
$ if f$search("a.tmp") .eqs. "" -
|
||||
then $ exit
|
||||
$ ! all global definitions
|
||||
$ search a.tmp "symbol:","EGSY$V_DEF 1","EGSY$V_NORM 1"/out=b.tmp
|
||||
$ ! all procedures
|
||||
$ search b.tmp "EGSY$V_NORM 1"/wind=(0,1) /out=c.tmp
|
||||
$ search c.tmp "symbol:"/out=d.tmp
|
||||
$ define/user sys$output nl:
|
||||
$ edito/edt/command=sys$input d.tmp
|
||||
sub/symbol: "/symbol_vector=(/whole
|
||||
sub/"/=PROCEDURE)/whole
|
||||
exit
|
||||
$ ! all data
|
||||
$ search b.tmp "EGSY$V_DEF 1"/wind=(0,1) /out=e.tmp
|
||||
$ search e.tmp "symbol:"/out=f.tmp
|
||||
$ define/user sys$output nl:
|
||||
$ edito/edt/command=sys$input f.tmp
|
||||
sub/symbol: "/symbol_vector=(/whole
|
||||
sub/"/=DATA)/whole
|
||||
exit
|
||||
$ sort/nodupl d.tmp,f.tmp g.tmp
|
||||
$ open/read raw_vector g.tmp
|
||||
$ open/write case_vector 'p2'
|
||||
$ RAWLOOP:
|
||||
$ read/end=end_rawloop raw_vector raw_element
|
||||
$ write case_vector raw_element
|
||||
$ if f$locate("=PROCEDURE)",raw_element) .lt. f$length(raw_element)
|
||||
$ then
|
||||
$ name = f$element(1,"=",raw_element) - "("
|
||||
$ if f$edit(name,"UPCASE") .nes. name then -
|
||||
write case_vector f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)", -
|
||||
f$edit(name,"UPCASE"), name)
|
||||
$ endif
|
||||
$ if f$locate("=DATA)",raw_element) .lt. f$length(raw_element)
|
||||
$ then
|
||||
$ name = f$element(1,"=",raw_element) - "("
|
||||
$ if f$edit(name,"UPCASE") .nes. name then -
|
||||
write case_vector f$fao(" symbol_vector=(!AS/!AS=DATA)", -
|
||||
f$edit(name,"UPCASE"), name)
|
||||
$ endif
|
||||
$ goto rawloop
|
||||
$ END_RAWLOOP:
|
||||
$ close raw_vector
|
||||
$ close case_vector
|
||||
$ delete a.tmp;*,b.tmp;*,c.tmp;*,d.tmp;*,e.tmp;*,f.tmp;*,g.tmp;*
|
||||
$ if f$search("x.tmp") .nes. "" -
|
||||
then $ delete x.tmp;*
|
||||
$!
|
||||
$ EXIT_AA:
|
||||
$ if V then set verify
|
||||
$ endsubroutine
|
||||
$!------------------------------------------------------------------------------
|
||||
$!
|
||||
$! Write configuration to both permanent and temporary config file
|
||||
$!
|
||||
$! Version history
|
||||
|
@ -802,3 +715,153 @@ $ write confh 'p1'
|
|||
$ close confh
|
||||
$ENDSUBROUTINE
|
||||
$!------------------------------------------------------------------------------
|
||||
$!
|
||||
$! Analyze the project map file and create the symbol vector for a shareable
|
||||
$! image from it
|
||||
$!
|
||||
$! Version history
|
||||
$! 0.01 20120128 First version
|
||||
$! 0.02 20120226 Add pre-load logic
|
||||
$!
|
||||
$ MAP_2_SHOPT: Subroutine
|
||||
$!
|
||||
$ SAY := "WRITE_ SYS$OUTPUT"
|
||||
$!
|
||||
$ IF F$SEARCH("''P1'") .EQS. ""
|
||||
$ THEN
|
||||
$ SAY "MAP_2_SHOPT-E-NOSUCHFILE: Error, inputfile ''p1' not available"
|
||||
$ goto exit_m2s
|
||||
$ ENDIF
|
||||
$ IF "''P2'" .EQS. ""
|
||||
$ THEN
|
||||
$ SAY "MAP_2_SHOPT: Error, no output file provided"
|
||||
$ goto exit_m2s
|
||||
$ ENDIF
|
||||
$!
|
||||
$ module1 = "deflate#deflateEnd#deflateInit_#deflateParams#deflateSetDictionary"
|
||||
$ module2 = "gzclose#gzerror#gzgetc#gzgets#gzopen#gzprintf#gzputc#gzputs#gzread"
|
||||
$ module3 = "gzseek#gztell#inflate#inflateEnd#inflateInit_#inflateSetDictionary"
|
||||
$ module4 = "inflateSync#uncompress#zlibVersion#compress"
|
||||
$ open/read map 'p1
|
||||
$ if axp .or. ia64
|
||||
$ then
|
||||
$ open/write aopt a.opt
|
||||
$ open/write bopt b.opt
|
||||
$ write aopt " CASE_SENSITIVE=YES"
|
||||
$ write bopt "SYMBOL_VECTOR= (-"
|
||||
$ mod_sym_num = 1
|
||||
$ MOD_SYM_LOOP:
|
||||
$ if f$type(module'mod_sym_num') .nes. ""
|
||||
$ then
|
||||
$ mod_in = 0
|
||||
$ MOD_SYM_IN:
|
||||
$ shared_proc = f$element(mod_in, "#", module'mod_sym_num')
|
||||
$ if shared_proc .nes. "#"
|
||||
$ then
|
||||
$ write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",-
|
||||
f$edit(shared_proc,"upcase"),shared_proc)
|
||||
$ write bopt f$fao("!AS=PROCEDURE,-",shared_proc)
|
||||
$ mod_in = mod_in + 1
|
||||
$ goto mod_sym_in
|
||||
$ endif
|
||||
$ mod_sym_num = mod_sym_num + 1
|
||||
$ goto mod_sym_loop
|
||||
$ endif
|
||||
$MAP_LOOP:
|
||||
$ read/end=map_end map line
|
||||
$ if (f$locate("{",line).lt. f$length(line)) .or. -
|
||||
(f$locate("global:", line) .lt. f$length(line))
|
||||
$ then
|
||||
$ proc = true
|
||||
$ goto map_loop
|
||||
$ endif
|
||||
$ if f$locate("}",line).lt. f$length(line) then proc = false
|
||||
$ if f$locate("local:", line) .lt. f$length(line) then proc = false
|
||||
$ if proc
|
||||
$ then
|
||||
$ shared_proc = f$edit(line,"collapse")
|
||||
$ chop_semi = f$locate(";", shared_proc)
|
||||
$ if chop_semi .lt. f$length(shared_proc) then -
|
||||
shared_proc = f$extract(0, chop_semi, shared_proc)
|
||||
$ write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",-
|
||||
f$edit(shared_proc,"upcase"),shared_proc)
|
||||
$ write bopt f$fao("!AS=PROCEDURE,-",shared_proc)
|
||||
$ endif
|
||||
$ goto map_loop
|
||||
$MAP_END:
|
||||
$ close/nolog aopt
|
||||
$ close/nolog bopt
|
||||
$ open/append libopt 'p2'
|
||||
$ open/read aopt a.opt
|
||||
$ open/read bopt b.opt
|
||||
$ALOOP:
|
||||
$ read/end=aloop_end aopt line
|
||||
$ write libopt line
|
||||
$ goto aloop
|
||||
$ALOOP_END:
|
||||
$ close/nolog aopt
|
||||
$ sv = ""
|
||||
$BLOOP:
|
||||
$ read/end=bloop_end bopt svn
|
||||
$ if (svn.nes."")
|
||||
$ then
|
||||
$ if (sv.nes."") then write libopt sv
|
||||
$ sv = svn
|
||||
$ endif
|
||||
$ goto bloop
|
||||
$BLOOP_END:
|
||||
$ write libopt f$extract(0,f$length(sv)-2,sv), "-"
|
||||
$ write libopt ")"
|
||||
$ close/nolog bopt
|
||||
$ delete/nolog/noconf a.opt;*,b.opt;*
|
||||
$ else
|
||||
$ if vax
|
||||
$ then
|
||||
$ open/append libopt 'p2'
|
||||
$ mod_sym_num = 1
|
||||
$ VMOD_SYM_LOOP:
|
||||
$ if f$type(module'mod_sym_num') .nes. ""
|
||||
$ then
|
||||
$ mod_in = 0
|
||||
$ VMOD_SYM_IN:
|
||||
$ shared_proc = f$element(mod_in, "#", module'mod_sym_num')
|
||||
$ if shared_proc .nes. "#"
|
||||
$ then
|
||||
$ write libopt f$fao("UNIVERSAL=!AS",-
|
||||
f$edit(shared_proc,"upcase"))
|
||||
$ mod_in = mod_in + 1
|
||||
$ goto vmod_sym_in
|
||||
$ endif
|
||||
$ mod_sym_num = mod_sym_num + 1
|
||||
$ goto vmod_sym_loop
|
||||
$ endif
|
||||
$VMAP_LOOP:
|
||||
$ read/end=vmap_end map line
|
||||
$ if (f$locate("{",line).lt. f$length(line)) .or. -
|
||||
(f$locate("global:", line) .lt. f$length(line))
|
||||
$ then
|
||||
$ proc = true
|
||||
$ goto vmap_loop
|
||||
$ endif
|
||||
$ if f$locate("}",line).lt. f$length(line) then proc = false
|
||||
$ if f$locate("local:", line) .lt. f$length(line) then proc = false
|
||||
$ if proc
|
||||
$ then
|
||||
$ shared_proc = f$edit(line,"collapse")
|
||||
$ chop_semi = f$locate(";", shared_proc)
|
||||
$ if chop_semi .lt. f$length(shared_proc) then -
|
||||
shared_proc = f$extract(0, chop_semi, shared_proc)
|
||||
$ write libopt f$fao("UNIVERSAL=!AS",-
|
||||
f$edit(shared_proc,"upcase"))
|
||||
$ endif
|
||||
$ goto vmap_loop
|
||||
$VMAP_END:
|
||||
$ else
|
||||
$ write sys$output "Unknown Architecture (Not VAX, AXP, or IA64)"
|
||||
$ write sys$output "No options file created"
|
||||
$ endif
|
||||
$ endif
|
||||
$ EXIT_M2S:
|
||||
$ close/nolog map
|
||||
$ close/nolog libopt
|
||||
$ endsubroutine
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* minigzip.c -- simulate gzip using the zlib compression library
|
||||
* Copyright (C) 1995-2006, 2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -40,6 +40,10 @@
|
|||
# define SET_BINARY_MODE(file)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifdef VMS
|
||||
# define unlink delete
|
||||
# define GZ_SUFFIX "-gz"
|
||||
|
@ -138,6 +142,197 @@ static void pwinerror (s)
|
|||
# define local
|
||||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
/* for Z_SOLO, create simplified gz* functions using deflate and inflate */
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
|
||||
# include <unistd.h> /* for unlink() */
|
||||
#endif
|
||||
|
||||
void *myalloc OF((void *, unsigned, unsigned));
|
||||
void myfree OF((void *, void *));
|
||||
|
||||
void *myalloc(q, n, m)
|
||||
void *q;
|
||||
unsigned n, m;
|
||||
{
|
||||
q = Z_NULL;
|
||||
return calloc(n, m);
|
||||
}
|
||||
|
||||
void myfree(q, p)
|
||||
void *q, *p;
|
||||
{
|
||||
q = Z_NULL;
|
||||
free(p);
|
||||
}
|
||||
|
||||
typedef struct gzFile_s {
|
||||
FILE *file;
|
||||
int write;
|
||||
int err;
|
||||
char *msg;
|
||||
z_stream strm;
|
||||
} *gzFile;
|
||||
|
||||
gzFile gzopen OF((const char *, const char *));
|
||||
gzFile gzdopen OF((int, const char *));
|
||||
gzFile gz_open OF((const char *, int, const char *));
|
||||
|
||||
gzFile gzopen(path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
gzFile gzdopen(fd, mode)
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(NULL, fd, mode);
|
||||
}
|
||||
|
||||
gzFile gz_open(path, fd, mode)
|
||||
const char *path;
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
gzFile gz;
|
||||
int ret;
|
||||
|
||||
gz = malloc(sizeof(struct gzFile_s));
|
||||
if (gz == NULL)
|
||||
return NULL;
|
||||
gz->write = strchr(mode, 'w') != NULL;
|
||||
gz->strm.zalloc = myalloc;
|
||||
gz->strm.zfree = myfree;
|
||||
gz->strm.opaque = Z_NULL;
|
||||
if (gz->write)
|
||||
ret = deflateInit2(&(gz->strm), -1, 8, 15 + 16, 8, 0);
|
||||
else {
|
||||
gz->strm.next_in = 0;
|
||||
gz->strm.avail_in = Z_NULL;
|
||||
ret = inflateInit2(&(gz->strm), 15 + 16);
|
||||
}
|
||||
if (ret != Z_OK) {
|
||||
free(gz);
|
||||
return NULL;
|
||||
}
|
||||
gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") :
|
||||
fopen(path, gz->write ? "wb" : "rb");
|
||||
if (gz->file == NULL) {
|
||||
gz->write ? deflateEnd(&(gz->strm)) : inflateEnd(&(gz->strm));
|
||||
free(gz);
|
||||
return NULL;
|
||||
}
|
||||
gz->err = 0;
|
||||
gz->msg = "";
|
||||
return gz;
|
||||
}
|
||||
|
||||
int gzwrite OF((gzFile, const void *, unsigned));
|
||||
|
||||
int gzwrite(gz, buf, len)
|
||||
gzFile gz;
|
||||
const void *buf;
|
||||
unsigned len;
|
||||
{
|
||||
z_stream *strm;
|
||||
unsigned char out[BUFLEN];
|
||||
|
||||
if (gz == NULL || !gz->write)
|
||||
return 0;
|
||||
strm = &(gz->strm);
|
||||
strm->next_in = (void *)buf;
|
||||
strm->avail_in = len;
|
||||
do {
|
||||
strm->next_out = out;
|
||||
strm->avail_out = BUFLEN;
|
||||
(void)deflate(strm, Z_NO_FLUSH);
|
||||
fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
|
||||
} while (strm->avail_out == 0);
|
||||
return len;
|
||||
}
|
||||
|
||||
int gzread OF((gzFile, void *, unsigned));
|
||||
|
||||
int gzread(gz, buf, len)
|
||||
gzFile gz;
|
||||
void *buf;
|
||||
unsigned len;
|
||||
{
|
||||
int ret;
|
||||
unsigned got;
|
||||
unsigned char in[1];
|
||||
z_stream *strm;
|
||||
|
||||
if (gz == NULL || gz->write)
|
||||
return 0;
|
||||
if (gz->err)
|
||||
return 0;
|
||||
strm = &(gz->strm);
|
||||
strm->next_out = (void *)buf;
|
||||
strm->avail_out = len;
|
||||
do {
|
||||
got = fread(in, 1, 1, gz->file);
|
||||
if (got == 0)
|
||||
break;
|
||||
strm->next_in = in;
|
||||
strm->avail_in = 1;
|
||||
ret = inflate(strm, Z_NO_FLUSH);
|
||||
if (ret == Z_DATA_ERROR) {
|
||||
gz->err = Z_DATA_ERROR;
|
||||
gz->msg = strm->msg;
|
||||
return 0;
|
||||
}
|
||||
if (ret == Z_STREAM_END)
|
||||
inflateReset(strm);
|
||||
} while (strm->avail_out);
|
||||
return len - strm->avail_out;
|
||||
}
|
||||
|
||||
int gzclose OF((gzFile));
|
||||
|
||||
int gzclose(gz)
|
||||
gzFile gz;
|
||||
{
|
||||
z_stream *strm;
|
||||
unsigned char out[BUFLEN];
|
||||
|
||||
if (gz == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
strm = &(gz->strm);
|
||||
if (gz->write) {
|
||||
strm->next_in = Z_NULL;
|
||||
strm->avail_in = 0;
|
||||
do {
|
||||
strm->next_out = out;
|
||||
strm->avail_out = BUFLEN;
|
||||
(void)deflate(strm, Z_FINISH);
|
||||
fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
|
||||
} while (strm->avail_out == 0);
|
||||
deflateEnd(strm);
|
||||
}
|
||||
else
|
||||
inflateEnd(strm);
|
||||
fclose(gz->file);
|
||||
free(gz);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
const char *gzerror OF((gzFile, int *));
|
||||
|
||||
const char *gzerror(gz, err)
|
||||
gzFile gz;
|
||||
int *err;
|
||||
{
|
||||
*err = gz->err;
|
||||
return gz->msg;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char *prog;
|
||||
|
||||
void error OF((const char *msg));
|
||||
|
@ -272,8 +467,12 @@ void file_compress(file, mode)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX);
|
||||
#else
|
||||
strcpy(outfile, file);
|
||||
strcat(outfile, GZ_SUFFIX);
|
||||
#endif
|
||||
|
||||
in = fopen(file, "rb");
|
||||
if (in == NULL) {
|
||||
|
@ -308,7 +507,11 @@ void file_uncompress(file)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(buf, sizeof(buf), "%s", file);
|
||||
#else
|
||||
strcpy(buf, file);
|
||||
#endif
|
||||
|
||||
if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
|
||||
infile = file;
|
||||
|
@ -317,7 +520,11 @@ void file_uncompress(file)
|
|||
} else {
|
||||
outfile = file;
|
||||
infile = buf;
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(buf + len, sizeof(buf) - len, "%s", GZ_SUFFIX);
|
||||
#else
|
||||
strcat(infile, GZ_SUFFIX);
|
||||
#endif
|
||||
}
|
||||
in = gzopen(infile, "rb");
|
||||
if (in == NULL) {
|
||||
|
@ -355,7 +562,11 @@ int main(argc, argv)
|
|||
gzFile file;
|
||||
char *bname, outmode[20];
|
||||
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
snprintf(outmode, sizeof(outmode), "%s", "wb6 ");
|
||||
#else
|
||||
strcpy(outmode, "wb6 ");
|
||||
#endif
|
||||
|
||||
prog = argv[0];
|
||||
bname = strrchr(argv[0], '/');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* trees.c -- output deflated data using Huffman coding
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly
|
||||
* Copyright (C) 1995-2012 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
|
||||
*/
|
||||
|
@ -74,11 +74,6 @@ local const uch bl_order[BL_CODES]
|
|||
* probability, to avoid transmitting the lengths for unused bit length codes.
|
||||
*/
|
||||
|
||||
#define Buf_size (8 * 2*sizeof(char))
|
||||
/* Number of bits used within bi_buf. (bi_buf might be implemented on
|
||||
* more than 16 bits on some systems.)
|
||||
*/
|
||||
|
||||
/* ===========================================================================
|
||||
* Local data. These are initialized only once.
|
||||
*/
|
||||
|
@ -151,8 +146,8 @@ local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
|
|||
local int build_bl_tree OF((deflate_state *s));
|
||||
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
|
||||
int blcodes));
|
||||
local void compress_block OF((deflate_state *s, ct_data *ltree,
|
||||
ct_data *dtree));
|
||||
local void compress_block OF((deflate_state *s, const ct_data *ltree,
|
||||
const ct_data *dtree));
|
||||
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));
|
||||
|
@ -399,7 +394,6 @@ void ZLIB_INTERNAL _tr_init(s)
|
|||
|
||||
s->bi_buf = 0;
|
||||
s->bi_valid = 0;
|
||||
s->last_eob_len = 8; /* enough lookahead for inflate */
|
||||
#ifdef DEBUG
|
||||
s->compressed_len = 0L;
|
||||
s->bits_sent = 0L;
|
||||
|
@ -882,16 +876,18 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
|
|||
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_flush_bits(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
bi_flush(s);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Send one empty static block to give enough lookahead for inflate.
|
||||
* This takes 10 bits, of which 7 may remain in the bit buffer.
|
||||
* The current inflate code requires 9 bits of lookahead. If the
|
||||
* last two codes for the previous block (real code plus EOB) were coded
|
||||
* on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
|
||||
* the last real code. In this case we send two empty static blocks instead
|
||||
* of one. (There are no problems if the previous block is stored or fixed.)
|
||||
* To simplify the code, we assume the worst case of last real code encoded
|
||||
* on one bit only.
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_align(s)
|
||||
deflate_state *s;
|
||||
|
@ -902,20 +898,6 @@ void ZLIB_INTERNAL _tr_align(s)
|
|||
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
|
||||
#endif
|
||||
bi_flush(s);
|
||||
/* Of the 10 bits for the empty block, we have already sent
|
||||
* (10 - bi_valid) bits. The lookahead for the last real code (before
|
||||
* the EOB of the previous block) was thus at least one plus the length
|
||||
* of the EOB plus what we have just sent of the empty static block.
|
||||
*/
|
||||
if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
|
||||
send_bits(s, STATIC_TREES<<1, 3);
|
||||
send_code(s, END_BLOCK, static_ltree);
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 10L;
|
||||
#endif
|
||||
bi_flush(s);
|
||||
}
|
||||
s->last_eob_len = 7;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
|
@ -990,7 +972,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
|||
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
|
||||
#endif
|
||||
send_bits(s, (STATIC_TREES<<1)+last, 3);
|
||||
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
|
||||
compress_block(s, (const ct_data *)static_ltree,
|
||||
(const ct_data *)static_dtree);
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 3 + s->static_len;
|
||||
#endif
|
||||
|
@ -998,7 +981,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
|||
send_bits(s, (DYN_TREES<<1)+last, 3);
|
||||
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
|
||||
max_blindex+1);
|
||||
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
|
||||
compress_block(s, (const ct_data *)s->dyn_ltree,
|
||||
(const ct_data *)s->dyn_dtree);
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 3 + s->opt_len;
|
||||
#endif
|
||||
|
@ -1075,8 +1059,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
|
|||
*/
|
||||
local void compress_block(s, ltree, dtree)
|
||||
deflate_state *s;
|
||||
ct_data *ltree; /* literal tree */
|
||||
ct_data *dtree; /* distance tree */
|
||||
const ct_data *ltree; /* literal tree */
|
||||
const ct_data *dtree; /* distance tree */
|
||||
{
|
||||
unsigned dist; /* distance of matched string */
|
||||
int lc; /* match length or unmatched char (if dist == 0) */
|
||||
|
@ -1118,7 +1102,6 @@ local void compress_block(s, ltree, dtree)
|
|||
} while (lx < s->last_lit);
|
||||
|
||||
send_code(s, END_BLOCK, ltree);
|
||||
s->last_eob_len = ltree[END_BLOCK].Len;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
|
@ -1226,7 +1209,6 @@ local void copy_block(s, buf, len, header)
|
|||
int header; /* true if block header must be written */
|
||||
{
|
||||
bi_windup(s); /* align on byte boundary */
|
||||
s->last_eob_len = 8; /* enough lookahead for inflate */
|
||||
|
||||
if (header) {
|
||||
put_short(s, (ush)len);
|
||||
|
|
|
@ -30,7 +30,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
|
|||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.next_in = (z_const Bytef *)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -15,11 +15,13 @@
|
|||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
# define Z_PREFIX_SET
|
||||
|
||||
/* all linked symbols */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_bits z__tr_flush_bits
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
|
@ -27,9 +29,11 @@
|
|||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# endif
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
|
@ -40,13 +44,16 @@
|
|||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePending z_deflatePending
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateResetKeep z_deflateResetKeep
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# ifndef Z_SOLO
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
|
@ -61,12 +68,17 @@
|
|||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# ifdef _WIN32
|
||||
# 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
|
||||
|
@ -78,6 +90,7 @@
|
|||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
|
@ -92,16 +105,22 @@
|
|||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# 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 inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# ifndef Z_SOLO
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# endif
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
|
@ -111,7 +130,9 @@
|
|||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# ifndef Z_SOLO
|
||||
# define gzFile z_gzFile
|
||||
# endif
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
|
@ -197,6 +218,12 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
# define z_const const
|
||||
#else
|
||||
# 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
|
||||
|
@ -243,6 +270,14 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_ARG /* function prototypes for stdarg */
|
||||
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# define Z_ARG(args) args
|
||||
# else
|
||||
# define Z_ARG(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
|
@ -356,12 +391,47 @@ typedef uLong FAR uLongf;
|
|||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_STDARG_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef Z_SOLO
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
# include <stdarg.h> /* for va_list */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef Z_SOLO
|
||||
# include <stddef.h> /* for wchar_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
|
@ -370,21 +440,38 @@ typedef uLong FAR uLongf;
|
|||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
|
@ -394,18 +481,14 @@ typedef uLong FAR uLongf;
|
|||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -17,11 +17,13 @@
|
|||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
# define Z_PREFIX_SET
|
||||
|
||||
/* all linked symbols */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_bits z__tr_flush_bits
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
|
@ -29,9 +31,11 @@
|
|||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# endif
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
|
@ -42,13 +46,16 @@
|
|||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePending z_deflatePending
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateResetKeep z_deflateResetKeep
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# ifndef Z_SOLO
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
|
@ -63,12 +70,17 @@
|
|||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# ifdef _WIN32
|
||||
# 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
|
||||
|
@ -80,6 +92,7 @@
|
|||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
|
@ -94,16 +107,22 @@
|
|||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# 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 inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# ifndef Z_SOLO
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# endif
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
|
@ -113,7 +132,9 @@
|
|||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# ifndef Z_SOLO
|
||||
# define gzFile z_gzFile
|
||||
# endif
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
|
@ -199,6 +220,12 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
# define z_const const
|
||||
#else
|
||||
# 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
|
||||
|
@ -245,6 +272,14 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_ARG /* function prototypes for stdarg */
|
||||
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# define Z_ARG(args) args
|
||||
# else
|
||||
# define Z_ARG(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
|
@ -358,12 +393,47 @@ typedef uLong FAR uLongf;
|
|||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_STDARG_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef Z_SOLO
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
# include <stdarg.h> /* for va_list */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef Z_SOLO
|
||||
# include <stddef.h> /* for wchar_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
|
@ -372,21 +442,38 @@ typedef uLong FAR uLongf;
|
|||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
|
@ -396,18 +483,14 @@ typedef uLong FAR uLongf;
|
|||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -15,11 +15,13 @@
|
|||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
# define Z_PREFIX_SET
|
||||
|
||||
/* all linked symbols */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_bits z__tr_flush_bits
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
|
@ -27,9 +29,11 @@
|
|||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# endif
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
|
@ -40,13 +44,16 @@
|
|||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePending z_deflatePending
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateResetKeep z_deflateResetKeep
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# ifndef Z_SOLO
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
|
@ -61,12 +68,17 @@
|
|||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# ifdef _WIN32
|
||||
# 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
|
||||
|
@ -78,6 +90,7 @@
|
|||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
|
@ -92,16 +105,22 @@
|
|||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# 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 inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# ifndef Z_SOLO
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# endif
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
|
@ -111,7 +130,9 @@
|
|||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# ifndef Z_SOLO
|
||||
# define gzFile z_gzFile
|
||||
# endif
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
|
@ -197,6 +218,12 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
# define z_const const
|
||||
#else
|
||||
# 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
|
||||
|
@ -243,6 +270,14 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_ARG /* function prototypes for stdarg */
|
||||
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# define Z_ARG(args) args
|
||||
# else
|
||||
# define Z_ARG(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
|
@ -356,12 +391,47 @@ typedef uLong FAR uLongf;
|
|||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_STDARG_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef Z_SOLO
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
# include <stdarg.h> /* for va_list */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef Z_SOLO
|
||||
# include <stddef.h> /* for wchar_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
|
@ -370,21 +440,38 @@ typedef uLong FAR uLongf;
|
|||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
|
@ -394,18 +481,14 @@ typedef uLong FAR uLongf;
|
|||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
|
|
|
@ -1,332 +0,0 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define zError z_zError
|
||||
|
||||
# define alloc_func z_alloc_func
|
||||
# define free_func z_free_func
|
||||
# define in_func z_in_func
|
||||
# define out_func z_out_func
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||
# define OS2
|
||||
#endif
|
||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
#endif
|
||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||
# ifndef SYS16BIT
|
||||
# define SYS16BIT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#ifdef __STDC_VERSION__
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const /* note: need a more gentle solution here */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=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
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# if defined(M_I86SM) || defined(M_I86MM)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
/* Turbo C small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef __BORLANDC__
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS) || defined(WIN32)
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
# ifdef ZLIB_DLL
|
||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
# endif /* ZLIB_DLL */
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
# ifdef ZLIB_WINAPI
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR CDECL
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# ifdef ZLIB_DLL
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXPORT __declspec(dllexport)
|
||||
# define ZEXPORTVA __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXPORT __declspec(dllimport)
|
||||
# define ZEXPORTVA __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void const *voidpc;
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte const *voidpc;
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(deflateBound,"DEBND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(compressBound,"CMBND")
|
||||
# pragma map(inflate_table,"INTABL")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
|
||||
#endif /* ZCONF_H */
|
|
@ -1,4 +1,4 @@
|
|||
.TH ZLIB 3 "19 Apr 2010"
|
||||
.TH ZLIB 3 "28 Apr 2013"
|
||||
.SH NAME
|
||||
zlib \- compression/decompression library
|
||||
.SH SYNOPSIS
|
||||
|
@ -36,9 +36,9 @@ All functions of the compression library are documented in the file
|
|||
.IR zlib.h .
|
||||
The distribution source includes examples of use of the library
|
||||
in the files
|
||||
.I example.c
|
||||
.I test/example.c
|
||||
and
|
||||
.IR minigzip.c,
|
||||
.IR test/minigzip.c,
|
||||
as well as other examples in the
|
||||
.IR examples/
|
||||
directory.
|
||||
|
@ -65,7 +65,7 @@ A Python interface to
|
|||
written by A.M. Kuchling (amk@magnet.com),
|
||||
is available in Python 1.5 and later versions:
|
||||
.IP
|
||||
http://www.python.org/doc/lib/module-zlib.html
|
||||
http://docs.python.org/library/zlib.html
|
||||
.LP
|
||||
.I zlib
|
||||
is built into
|
||||
|
@ -95,11 +95,11 @@ http://zlib.net/
|
|||
The data format used by the zlib library is described by RFC
|
||||
(Request for Comments) 1950 to 1952 in the files:
|
||||
.IP
|
||||
http://www.ietf.org/rfc/rfc1950.txt (for the zlib header and trailer format)
|
||||
http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format)
|
||||
.br
|
||||
http://www.ietf.org/rfc/rfc1951.txt (for the deflate compressed data format)
|
||||
http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format)
|
||||
.br
|
||||
http://www.ietf.org/rfc/rfc1952.txt (for the gzip header and trailer format)
|
||||
http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format)
|
||||
.LP
|
||||
Mark Nelson wrote an article about
|
||||
.I zlib
|
||||
|
@ -125,8 +125,8 @@ before asking for help.
|
|||
Send questions and/or comments to zlib@gzip.org,
|
||||
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
|
||||
.SH AUTHORS
|
||||
Version 1.2.5
|
||||
Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org)
|
||||
Version 1.2.8
|
||||
Copyright (C) 1995-2013 Jean-loup Gailly (jloup@gzip.org)
|
||||
and Mark Adler (madler@alumni.caltech.edu).
|
||||
.LP
|
||||
This software is provided "as-is,"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.2.5, April 19th, 2010
|
||||
version 1.2.8, April 28th, 2013
|
||||
|
||||
Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
|
||||
Copyright (C) 1995-2013 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
|
||||
|
@ -24,8 +24,8 @@
|
|||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
|
||||
(zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_H
|
||||
|
@ -37,11 +37,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.2.5"
|
||||
#define ZLIB_VERNUM 0x1250
|
||||
#define ZLIB_VERSION "1.2.8"
|
||||
#define ZLIB_VERNUM 0x1280
|
||||
#define ZLIB_VER_MAJOR 1
|
||||
#define ZLIB_VER_MINOR 2
|
||||
#define ZLIB_VER_REVISION 5
|
||||
#define ZLIB_VER_REVISION 8
|
||||
#define ZLIB_VER_SUBREVISION 0
|
||||
|
||||
/*
|
||||
|
@ -83,15 +83,15 @@ typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
|||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
z_const Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
uLong total_in; /* total number of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
uLong total_out; /* total number of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
z_const char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
|
@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
|||
|
||||
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). If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
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).
|
||||
|
@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
|||
error. However if all decompression is to be performed in a single step (a
|
||||
single call of inflate), the parameter flush should be set to Z_FINISH. In
|
||||
this case all pending input is processed and all pending output is flushed;
|
||||
avail_out must be large enough to hold all the uncompressed data. (The size
|
||||
of the uncompressed data may have been saved by the compressor for this
|
||||
purpose.) The next operation on this stream must be inflateEnd to deallocate
|
||||
the decompression state. The use of Z_FINISH is never required, but can be
|
||||
used to inform inflate that a faster approach may be used for the single
|
||||
inflate() call.
|
||||
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
|
||||
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
|
||||
stream completes, which reduces inflate's memory footprint. If the stream
|
||||
does not complete, either because not all of the stream is provided or not
|
||||
enough output space is provided, then a sliding window will be allocated and
|
||||
inflate() can be called again to continue the operation as if Z_NO_FLUSH had
|
||||
been used.
|
||||
|
||||
In this implementation, inflate() always flushes as much output as
|
||||
possible to the output buffer, and always uses the faster approach on the
|
||||
first call. So the only effect of the flush parameter in this implementation
|
||||
is on the return value of inflate(), as noted below, or when it returns early
|
||||
because Z_BLOCK or Z_TREES is used.
|
||||
first call. So the effects of the flush parameter in this implementation are
|
||||
on the return value of inflate() as noted below, when inflate() returns early
|
||||
when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
|
||||
memory for a sliding window when Z_FINISH is used.
|
||||
|
||||
If a preset dictionary is needed after this call (see inflateSetDictionary
|
||||
below), inflate sets strm->adler to the adler32 checksum of the dictionary
|
||||
below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
|
||||
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
||||
strm->adler to the adler32 checksum of all output produced so far (that is,
|
||||
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
|
||||
checksum is equal to that saved by the compressor and returns Z_STREAM_END
|
||||
|
@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
|||
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.
|
||||
perform their own processing of the gzip header and trailer. 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.
|
||||
|
||||
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
|
||||
|
@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
|||
uInt dictLength));
|
||||
/*
|
||||
Initializes the compression dictionary from the given byte sequence
|
||||
without producing any compressed output. This function must be called
|
||||
immediately after deflateInit, deflateInit2 or deflateReset, before any call
|
||||
of deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
without producing any compressed output. When using the zlib format, this
|
||||
function must be called immediately after deflateInit, deflateInit2 or
|
||||
deflateReset, and before any call of deflate. When doing raw deflate, this
|
||||
function must be called either before any call of deflate, or immediately
|
||||
after the completion of a deflate block, i.e. after all input has been
|
||||
consumed and all output has been delivered when using any of the flush
|
||||
options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
|
||||
compressor and decompressor must use exactly the same dictionary (see
|
||||
inflateSetDictionary).
|
||||
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
|
@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
|||
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
|
||||
inconsistent (for example if deflate has already been called for this stream
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
or if not at a block boundary for raw deflate). deflateSetDictionary does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||
|
@ -688,9 +702,29 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
|
|||
deflation of sourceLen bytes. It must be called after deflateInit() or
|
||||
deflateInit2(), and after deflateSetHeader(), if used. This would be used
|
||||
to allocate an output buffer for deflation in a single pass, and so would be
|
||||
called before deflate().
|
||||
called before deflate(). If that first deflate() call is provided the
|
||||
sourceLen input bytes, an output buffer allocated to the size returned by
|
||||
deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
|
||||
to return Z_STREAM_END. Note that it is possible for the compressed size to
|
||||
be larger than the value returned by deflateBound() if flush options other
|
||||
than Z_FINISH or Z_NO_FLUSH are used.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
|
||||
unsigned *pending,
|
||||
int *bits));
|
||||
/*
|
||||
deflatePending() returns the number of bytes and bits of output that have
|
||||
been generated, but not yet provided in the available output. The bytes not
|
||||
provided would be due to the available output space having being consumed.
|
||||
The number of bits of output not provided are between 0 and 7, where they
|
||||
await more bits to join them in order to fill out a full byte. If pending
|
||||
or bits are Z_NULL, then those values are not set.
|
||||
|
||||
deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
|
||||
int bits,
|
||||
int value));
|
||||
|
@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
|
|||
than or equal to 16, and that many of the least significant bits of value
|
||||
will be inserted in the output.
|
||||
|
||||
deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
|
||||
room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
|
||||
source stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
|
||||
|
@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
|||
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.
|
||||
The compressor and decompressor must use exactly the same dictionary (see
|
||||
deflateSetDictionary). For raw inflate, this function can be called
|
||||
immediately after inflateInit2() or inflateReset() and before any call of
|
||||
inflate() to set the dictionary. The application must insure that the
|
||||
dictionary that was used for compression is provided.
|
||||
deflateSetDictionary). For raw inflate, this function can be called at any
|
||||
time to set the dictionary. If the provided dictionary is smaller than the
|
||||
window and there is already data in the window, then the provided dictionary
|
||||
will amend what's there. The application must insure that the dictionary
|
||||
that was used for compression is provided.
|
||||
|
||||
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
|
||||
|
@ -803,19 +839,38 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
|||
inflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
|
||||
Bytef *dictionary,
|
||||
uInt *dictLength));
|
||||
/*
|
||||
Returns the sliding dictionary being maintained by inflate. 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 inflateGetDictionary() 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.
|
||||
|
||||
inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
|
||||
stream state is inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
Skips invalid compressed data until a possible full flush point (see above
|
||||
for the description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been
|
||||
found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
|
||||
success case, the application may save the current value of total_in
|
||||
which indicates where valid compressed data was found. In the error case,
|
||||
the application may repeatedly call inflateSync, providing more input each
|
||||
time, until success or end of the input data.
|
||||
inflateSync searches for a 00 00 FF FF pattern in the compressed data.
|
||||
All full flush points have this pattern, but not all occurrences of this
|
||||
pattern are full flush points.
|
||||
|
||||
inflateSync returns Z_OK if a possible full flush point has been found,
|
||||
Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
|
||||
has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
|
||||
In the success case, the application may save the current current value of
|
||||
total_in which indicates where valid compressed data was found. In the
|
||||
error case, the application may repeatedly call inflateSync, providing more
|
||||
input each time, until success or end of the input data.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
|
||||
|
@ -962,12 +1017,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
|
|||
See inflateBack() for the usage of these routines.
|
||||
|
||||
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
|
||||
the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
|
||||
the parameters are invalid, Z_MEM_ERROR if the internal state could not be
|
||||
allocated, or Z_VERSION_ERROR if the version of the library does not match
|
||||
the version of the header file.
|
||||
*/
|
||||
|
||||
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
|
||||
typedef unsigned (*in_func) OF((void FAR *,
|
||||
z_const unsigned char FAR * FAR *));
|
||||
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
|
||||
|
||||
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
||||
|
@ -975,11 +1031,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
|||
out_func out, void FAR *out_desc));
|
||||
/*
|
||||
inflateBack() does a raw inflate with a single call using a call-back
|
||||
interface for input and output. This is more efficient than inflate() for
|
||||
file i/o applications in that it avoids copying between the output and the
|
||||
sliding window by simply making the window itself the output buffer. This
|
||||
function trusts the application to not change the output buffer passed by
|
||||
the output function, at least until inflateBack() returns.
|
||||
interface for input and output. This is potentially more efficient than
|
||||
inflate() for file i/o applications, in that it avoids copying between the
|
||||
output and the sliding window by simply making the window itself the output
|
||||
buffer. inflate() can be faster on modern CPUs when used with large
|
||||
buffers. inflateBack() trusts the application to not change the output
|
||||
buffer passed by the output function, at least until inflateBack() returns.
|
||||
|
||||
inflateBackInit() must be called first to allocate the internal state
|
||||
and to initialize the state with the user-provided window buffer.
|
||||
|
@ -1088,6 +1145,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
|
|||
27-31: 0 (reserved)
|
||||
*/
|
||||
|
||||
#ifndef Z_SOLO
|
||||
|
||||
/* utility functions */
|
||||
|
||||
|
@ -1149,10 +1207,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
|||
|
||||
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 or incomplete.
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
|
||||
the case where there is not enough room, uncompress() will fill the output
|
||||
buffer with the uncompressed data up to that point.
|
||||
*/
|
||||
|
||||
|
||||
/* gzip file access functions */
|
||||
|
||||
/*
|
||||
|
@ -1162,7 +1221,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
|||
wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
||||
*/
|
||||
|
||||
typedef voidp gzFile; /* opaque gzip file descriptor */
|
||||
typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
|
||||
|
||||
/*
|
||||
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||
|
@ -1172,13 +1231,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
|||
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
|
||||
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
|
||||
for fixed code compression as in "wb9F". (See the description of
|
||||
deflateInit2 for more information about the strategy parameter.) Also "a"
|
||||
can be used instead of "w" to request that the gzip stream that will be
|
||||
written be appended to the file. "+" will result in an error, since reading
|
||||
and writing to the same gzip file is not supported.
|
||||
deflateInit2 for more information about the strategy parameter.) 'T' will
|
||||
request transparent writing or appending with no compression and not using
|
||||
the gzip format.
|
||||
|
||||
"a" can be used instead of "w" to request that the gzip stream that will
|
||||
be written be appended to the file. "+" will result in an error, since
|
||||
reading and writing to the same gzip file is not supported. The addition of
|
||||
"x" when writing will create the file exclusively, which fails if the file
|
||||
already exists. On systems that support it, the addition of "e" when
|
||||
reading or writing will set the flag to close the file on an execve() call.
|
||||
|
||||
These functions, as well as gzip, will read and decode a sequence of gzip
|
||||
streams in a file. The append function of gzopen() can be used to create
|
||||
such a file. (Also see gzflush() for another way to do this.) When
|
||||
appending, gzopen does not test whether the file begins with a gzip stream,
|
||||
nor does it look for the end of the gzip streams to begin appending. gzopen
|
||||
will simply append a gzip stream to the existing file.
|
||||
|
||||
gzopen can be used to read a file which is not in gzip format; in this
|
||||
case gzread will directly read from the file without decompression.
|
||||
case gzread will directly read from the file without decompression. When
|
||||
reading, this will be detected automatically by looking for the magic two-
|
||||
byte gzip header.
|
||||
|
||||
gzopen returns NULL if the file could not be opened, if there was
|
||||
insufficient memory to allocate the gzFile state, or if an invalid mode was
|
||||
|
@ -1197,7 +1271,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
|||
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
|
||||
fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
|
||||
mode);. The duplicated descriptor should be saved to avoid a leak, since
|
||||
gzdopen does not close fd if it fails.
|
||||
gzdopen does not close fd if it fails. If you are using fileno() to get the
|
||||
file descriptor from a FILE *, then you will have to use dup() to avoid
|
||||
double-close()ing the file descriptor. Both gzclose() and fclose() will
|
||||
close the associated file descriptor, so they need to have different file
|
||||
descriptors.
|
||||
|
||||
gzdopen returns NULL if there was insufficient memory to allocate the
|
||||
gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
|
||||
|
@ -1235,14 +1313,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
|||
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file. If
|
||||
the input file was not in gzip format, gzread copies the given number of
|
||||
bytes into the buffer.
|
||||
the input file is not in gzip format, gzread copies the given number of
|
||||
bytes into the buffer directly from the file.
|
||||
|
||||
After reaching the end of a gzip stream in the input, gzread will continue
|
||||
to read, looking for another gzip stream, or failing that, reading the rest
|
||||
of the input file directly without decompression. The entire input file
|
||||
will be read if gzread is called until it returns less than the requested
|
||||
len.
|
||||
to read, looking for another gzip stream. Any number of gzip streams may be
|
||||
concatenated in the input file, and will all be decompressed by gzread().
|
||||
If something other than a gzip stream is encountered after a gzip stream,
|
||||
that remaining trailing garbage is ignored (and no error is returned).
|
||||
|
||||
gzread can be used to read a gzip file that is being concurrently written.
|
||||
Upon reaching the end of the input, gzread will return with the available
|
||||
data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
|
||||
gzclearerr can be used to clear the end of file indicator in order to permit
|
||||
gzread to be tried again. Z_OK indicates that a gzip stream was completed
|
||||
on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
|
||||
middle of a gzip stream. Note that gzread does not return -1 in the event
|
||||
of an incomplete gzip stream. This error is deferred until gzclose(), which
|
||||
will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
|
||||
stream. Alternatively, gzerror can be used before gzclose to detect this
|
||||
case.
|
||||
|
||||
gzread returns the number of uncompressed bytes actually read, less than
|
||||
len for end of file, or -1 for error.
|
||||
|
@ -1256,7 +1346,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
|||
error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
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
|
||||
|
@ -1301,7 +1391,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
|
|||
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
|
||||
/*
|
||||
Reads one byte from the compressed file. gzgetc returns this byte or -1
|
||||
in case of end of file or error.
|
||||
in case of end of file or error. This is implemented as a macro for speed.
|
||||
As such, it does not do all of the checking the other functions do. I.e.
|
||||
it does not check to see if file is NULL, nor whether the structure file
|
||||
points to has been clobbered or not.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
|
||||
|
@ -1397,9 +1490,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
|||
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
|
||||
/*
|
||||
Returns true (1) if file is being copied directly while reading, or false
|
||||
(0) if file is a gzip stream being decompressed. This state can change from
|
||||
false to true while reading the input file if the end of a gzip stream is
|
||||
reached, but is followed by data that is not another gzip stream.
|
||||
(0) if file is a gzip stream being decompressed.
|
||||
|
||||
If the input file is empty, gzdirect() will return true, since the input
|
||||
does not contain a gzip stream.
|
||||
|
@ -1408,6 +1499,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
|
|||
cause buffers to be allocated to allow reading the file to determine if it
|
||||
is a gzip file. Therefore if gzbuffer() is used, it should be called before
|
||||
gzdirect().
|
||||
|
||||
When writing, gzdirect() returns true (1) if transparent writing was
|
||||
requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
|
||||
gzdirect() is not needed when writing. Transparent writing must be
|
||||
explicitly requested, so the application already knows the answer. When
|
||||
linking statically, using gzdirect() will include all of the zlib code for
|
||||
gzip file reading and decompression, which may not be desired.)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||
|
@ -1419,7 +1517,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
|||
must not be called more than once on the same allocation.
|
||||
|
||||
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
|
||||
file operation error, or Z_OK on success.
|
||||
file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
|
||||
last read ended in the middle of a gzip stream, or Z_OK on success.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
|
||||
|
@ -1457,6 +1556,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
|
|||
file that is being written concurrently.
|
||||
*/
|
||||
|
||||
#endif /* !Z_SOLO */
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
|
@ -1492,16 +1592,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
|
|||
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
|
||||
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
|
||||
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
|
||||
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
|
||||
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
|
||||
that the z_off_t type (like off_t) is a signed integer. If len2 is
|
||||
negative, the result has no meaning or utility.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running CRC-32 with the bytes buf[0..len-1] and return the
|
||||
updated CRC-32. If buf is Z_NULL, this function returns the required
|
||||
initial value for the for the crc. Pre- and post-conditioning (one's
|
||||
complement) is performed within this function so it shouldn't be done by the
|
||||
application.
|
||||
initial value for the crc. Pre- and post-conditioning (one's complement) is
|
||||
performed within this function so it shouldn't be done by the application.
|
||||
|
||||
Usage example:
|
||||
|
||||
|
@ -1544,17 +1645,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
const char *version,
|
||||
int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
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, sizeof(z_stream))
|
||||
(strategy), ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
|
||||
(int)sizeof(z_stream))
|
||||
#define inflateBackInit(strm, windowBits, window) \
|
||||
inflateBackInit_((strm), (windowBits), (window), \
|
||||
ZLIB_VERSION, sizeof(z_stream))
|
||||
ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
|
||||
#ifndef Z_SOLO
|
||||
|
||||
/* gzgetc() macro and its supporting function and exposed data structure. Note
|
||||
* that the real internal state is much larger than the exposed structure.
|
||||
* This abbreviated structure exposes just enough for the gzgetc() macro. The
|
||||
* user should not mess with these exposed elements, since their names or
|
||||
* behavior could change in the future, perhaps even capriciously. They can
|
||||
* only be used by the gzgetc() macro. You have been warned.
|
||||
*/
|
||||
struct gzFile_s {
|
||||
unsigned have;
|
||||
unsigned char *next;
|
||||
z_off64_t pos;
|
||||
};
|
||||
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))
|
||||
#else
|
||||
# define gzgetc(g) \
|
||||
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
|
||||
#endif
|
||||
|
||||
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
|
||||
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
|
||||
|
@ -1562,7 +1688,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
* functions are changed to 64 bits) -- in case these are set on systems
|
||||
* without large file support, _LFS64_LARGEFILE must also be true
|
||||
*/
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
#ifdef Z_LARGE64
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
||||
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
||||
|
@ -1571,14 +1697,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
|
||||
#endif
|
||||
|
||||
#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
|
||||
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
|
||||
# ifdef Z_PREFIX_SET
|
||||
# define z_gzopen z_gzopen64
|
||||
# define z_gzseek z_gzseek64
|
||||
# define z_gztell z_gztell64
|
||||
# define z_gzoffset z_gzoffset64
|
||||
# define z_adler32_combine z_adler32_combine64
|
||||
# define z_crc32_combine z_crc32_combine64
|
||||
# else
|
||||
# define gzopen gzopen64
|
||||
# define gzseek gzseek64
|
||||
# define gztell gztell64
|
||||
# define gzoffset gzoffset64
|
||||
# define adler32_combine adler32_combine64
|
||||
# define crc32_combine crc32_combine64
|
||||
# ifdef _LARGEFILE64_SOURCE
|
||||
# endif
|
||||
# ifndef Z_LARGE64
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
|
||||
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
|
||||
|
@ -1595,6 +1730,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
|
||||
#endif
|
||||
|
||||
#else /* Z_SOLO */
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
|
||||
|
||||
#endif /* !Z_SOLO */
|
||||
|
||||
/* hack for buggy compilers */
|
||||
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;};
|
||||
|
@ -1603,8 +1745,21 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
/* undocumented functions */
|
||||
ZEXTERN const char * ZEXPORT zError OF((int));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
|
||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
|
||||
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
|
||||
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
|
||||
#if defined(_WIN32) && !defined(Z_SOLO)
|
||||
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
|
||||
const char *mode));
|
||||
#endif
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
|
||||
const char *format,
|
||||
va_list va));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -66,3 +66,18 @@ ZLIB_1.2.3.5 {
|
|||
gzclose_r;
|
||||
gzclose_w;
|
||||
} ZLIB_1.2.3.4;
|
||||
|
||||
ZLIB_1.2.5.1 {
|
||||
deflatePending;
|
||||
} ZLIB_1.2.3.5;
|
||||
|
||||
ZLIB_1.2.5.2 {
|
||||
deflateResetKeep;
|
||||
gzgetc_;
|
||||
inflateResetKeep;
|
||||
} ZLIB_1.2.5.1;
|
||||
|
||||
ZLIB_1.2.7.1 {
|
||||
inflateGetDictionary;
|
||||
gzvprintf;
|
||||
} ZLIB_1.2.5.2;
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
/* zutil.c -- target dependent utility functions for the compression library
|
||||
* Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include "zutil.h"
|
||||
#ifndef Z_SOLO
|
||||
# include "gzguts.h"
|
||||
#endif
|
||||
|
||||
#ifndef NO_DUMMY_DECL
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
#endif
|
||||
|
||||
const char * const z_errmsg[10] = {
|
||||
z_const char * const z_errmsg[10] = {
|
||||
"need dictionary", /* Z_NEED_DICT 2 */
|
||||
"stream end", /* Z_STREAM_END 1 */
|
||||
"", /* Z_OK 0 */
|
||||
|
@ -85,7 +88,7 @@ uLong ZEXPORT zlibCompileFlags()
|
|||
#ifdef FASTEST
|
||||
flags += 1L << 21;
|
||||
#endif
|
||||
#ifdef STDC
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifdef NO_vsnprintf
|
||||
flags += 1L << 25;
|
||||
# ifdef HAS_vsprintf_void
|
||||
|
@ -181,6 +184,7 @@ void ZLIB_INTERNAL zmemzero(dest, len)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef Z_SOLO
|
||||
|
||||
#ifdef SYS16BIT
|
||||
|
||||
|
@ -316,3 +320,5 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
|
|||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
||||
|
||||
#endif /* !Z_SOLO */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
|||
#ifndef ZUTIL_H
|
||||
#define ZUTIL_H
|
||||
|
||||
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
|
||||
#ifdef HAVE_HIDDEN
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
#if defined(STDC) && !defined(Z_SOLO)
|
||||
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
|
@ -29,6 +29,10 @@
|
|||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
|
@ -40,13 +44,13 @@ typedef unsigned short ush;
|
|||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
||||
|
||||
#define ERR_RETURN(strm,err) \
|
||||
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||
return (strm->msg = ERR_MSG(err), (err))
|
||||
/* To be used only when the state is known to be valid */
|
||||
|
||||
/* common constants */
|
||||
|
@ -78,6 +82,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
|
||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||
# define OS_CODE 0x00
|
||||
# ifndef Z_SOLO
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
|
@ -89,6 +94,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
# else /* MSC or DJGPP */
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
|
@ -107,13 +113,14 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
|
||||
#ifdef OS2
|
||||
# define OS_CODE 0x06
|
||||
# ifdef M_I86
|
||||
# if defined(M_I86) && !defined(Z_SOLO)
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||
# define OS_CODE 0x07
|
||||
# ifndef Z_SOLO
|
||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||
# include <unix.h> /* for fdopen */
|
||||
# else
|
||||
|
@ -121,6 +128,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef TOPS20
|
||||
|
@ -153,14 +161,15 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#if defined(__BORLANDC__) && !defined(MSDOS)
|
||||
#pragma warn -8004
|
||||
#pragma warn -8008
|
||||
#pragma warn -8066
|
||||
#endif
|
||||
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
||||
#if !defined(_WIN32) && \
|
||||
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
|
||||
#endif
|
||||
|
@ -177,42 +186,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
|
||||
/* functions */
|
||||
|
||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
# ifdef MSDOS
|
||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||
but for now we just assume it doesn't. */
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __TURBOC__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef WIN32
|
||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __SASC
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
#ifdef VMS
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(pyr)
|
||||
#if defined(pyr) || defined(Z_SOLO)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||
|
@ -261,14 +235,19 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
# define Tracecv(c,x)
|
||||
#endif
|
||||
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
|
||||
#ifndef Z_SOLO
|
||||
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
|
||||
unsigned size));
|
||||
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
|
||||
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
|
||||
#endif
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
/* Reverse the bytes in a 32-bit value */
|
||||
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||
|
||||
#endif /* ZUTIL_H */
|
||||
|
|
|
@ -1245,74 +1245,6 @@
|
|||
RelativePath="..\..\Modules\zlib\deflate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Modules\zlib\gzio.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="PGInstrument|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="PGInstrument|Win64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="PGUpdate|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="PGUpdate|Win64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Modules\zlib\infback.c"
|
||||
>
|
||||
|
|
139
Python/compile.c
139
Python/compile.c
|
@ -94,6 +94,7 @@ enum {
|
|||
COMPILER_SCOPE_MODULE,
|
||||
COMPILER_SCOPE_CLASS,
|
||||
COMPILER_SCOPE_FUNCTION,
|
||||
COMPILER_SCOPE_LAMBDA,
|
||||
COMPILER_SCOPE_COMPREHENSION,
|
||||
};
|
||||
|
||||
|
@ -104,6 +105,7 @@ struct compiler_unit {
|
|||
PySTEntryObject *u_ste;
|
||||
|
||||
PyObject *u_name;
|
||||
PyObject *u_qualname; /* dot-separated qualified name (lazy) */
|
||||
int u_scope_type;
|
||||
|
||||
/* The following fields are dicts that map objects to
|
||||
|
@ -199,6 +201,7 @@ static int compiler_call_helper(struct compiler *c, int n,
|
|||
expr_ty starargs,
|
||||
expr_ty kwargs);
|
||||
static int compiler_try_except(struct compiler *, stmt_ty);
|
||||
static int compiler_set_qualname(struct compiler *);
|
||||
|
||||
static PyCodeObject *assemble(struct compiler *, int addNone);
|
||||
static PyObject *__doc__;
|
||||
|
@ -506,6 +509,7 @@ compiler_unit_free(struct compiler_unit *u)
|
|||
}
|
||||
Py_CLEAR(u->u_ste);
|
||||
Py_CLEAR(u->u_name);
|
||||
Py_CLEAR(u->u_qualname);
|
||||
Py_CLEAR(u->u_consts);
|
||||
Py_CLEAR(u->u_names);
|
||||
Py_CLEAR(u->u_varnames);
|
||||
|
@ -620,6 +624,11 @@ compiler_enter_scope(struct compiler *c, identifier name,
|
|||
if (compiler_use_new_block(c) == NULL)
|
||||
return 0;
|
||||
|
||||
if (u->u_scope_type != COMPILER_SCOPE_MODULE) {
|
||||
if (!compiler_set_qualname(c))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -647,72 +656,77 @@ compiler_exit_scope(struct compiler *c)
|
|||
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
compiler_scope_qualname(struct compiler *c, identifier scope_name)
|
||||
static int
|
||||
compiler_set_qualname(struct compiler *c)
|
||||
{
|
||||
Py_ssize_t stack_size;
|
||||
int global_scope;
|
||||
_Py_static_string(dot, ".");
|
||||
_Py_static_string(locals, "<locals>");
|
||||
struct compiler_unit *u;
|
||||
PyObject *capsule, *name, *seq, *dot_str, *locals_str;
|
||||
|
||||
u = c->u;
|
||||
seq = PyList_New(0);
|
||||
if (seq == NULL)
|
||||
return NULL;
|
||||
_Py_static_string(dot_locals, ".<locals>");
|
||||
Py_ssize_t stack_size;
|
||||
struct compiler_unit *u = c->u;
|
||||
PyObject *name, *base, *dot_str, *dot_locals_str;
|
||||
|
||||
base = NULL;
|
||||
stack_size = PyList_GET_SIZE(c->c_stack);
|
||||
assert(stack_size >= 1);
|
||||
global_scope = stack_size == 1;
|
||||
if (scope_name != NULL && !global_scope) {
|
||||
int scope;
|
||||
PyObject *mangled;
|
||||
if (stack_size > 1) {
|
||||
int scope, force_global = 0;
|
||||
struct compiler_unit *parent;
|
||||
PyObject *mangled, *capsule;
|
||||
|
||||
capsule = PyList_GET_ITEM(c->c_stack, stack_size - 1);
|
||||
u = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT);
|
||||
assert(u);
|
||||
mangled = _Py_Mangle(u->u_private, scope_name);
|
||||
parent = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT);
|
||||
assert(parent);
|
||||
|
||||
if (u->u_scope_type == COMPILER_SCOPE_FUNCTION || u->u_scope_type == COMPILER_SCOPE_CLASS) {
|
||||
assert(u->u_name);
|
||||
mangled = _Py_Mangle(parent->u_private, u->u_name);
|
||||
if (!mangled)
|
||||
return NULL;
|
||||
scope = PyST_GetScope(u->u_ste, mangled);
|
||||
return 0;
|
||||
scope = PyST_GetScope(parent->u_ste, mangled);
|
||||
Py_DECREF(mangled);
|
||||
assert(scope != GLOBAL_IMPLICIT);
|
||||
if (scope == GLOBAL_EXPLICIT)
|
||||
global_scope = 1;
|
||||
force_global = 1;
|
||||
}
|
||||
if (!global_scope) {
|
||||
Py_ssize_t i;
|
||||
for (i = 1; i < stack_size; i++) {
|
||||
capsule = PyList_GET_ITEM(c->c_stack, i);
|
||||
u = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT);
|
||||
assert(u);
|
||||
assert(u->u_scope_type != COMPILER_SCOPE_MODULE);
|
||||
if (PyList_Append(seq, u->u_name))
|
||||
goto _error;
|
||||
if (u->u_scope_type == COMPILER_SCOPE_FUNCTION) {
|
||||
locals_str = _PyUnicode_FromId(&locals);
|
||||
if (locals_str == NULL)
|
||||
goto _error;
|
||||
if (PyList_Append(seq, locals_str))
|
||||
goto _error;
|
||||
|
||||
if (!force_global) {
|
||||
if (parent->u_scope_type == COMPILER_SCOPE_FUNCTION
|
||||
|| parent->u_scope_type == COMPILER_SCOPE_LAMBDA) {
|
||||
dot_locals_str = _PyUnicode_FromId(&dot_locals);
|
||||
if (dot_locals_str == NULL)
|
||||
return 0;
|
||||
base = PyUnicode_Concat(parent->u_qualname, dot_locals_str);
|
||||
if (base == NULL)
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
Py_INCREF(parent->u_qualname);
|
||||
base = parent->u_qualname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u = c->u;
|
||||
if (PyList_Append(seq, u->u_name))
|
||||
goto _error;
|
||||
if (base != NULL) {
|
||||
dot_str = _PyUnicode_FromId(&dot);
|
||||
if (dot_str == NULL)
|
||||
goto _error;
|
||||
name = PyUnicode_Join(dot_str, seq);
|
||||
Py_DECREF(seq);
|
||||
Py_XINCREF(name);
|
||||
return name;
|
||||
if (dot_str == NULL) {
|
||||
Py_DECREF(base);
|
||||
return 0;
|
||||
}
|
||||
name = PyUnicode_Concat(base, dot_str);
|
||||
Py_DECREF(base);
|
||||
if (name == NULL)
|
||||
return 0;
|
||||
PyUnicode_Append(&name, u->u_name);
|
||||
if (name == NULL)
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
Py_INCREF(u->u_name);
|
||||
name = u->u_name;
|
||||
}
|
||||
u->u_qualname = name;
|
||||
|
||||
_error:
|
||||
Py_XDECREF(seq);
|
||||
return NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Allocate a new block and return a pointer to it.
|
||||
|
@ -1662,9 +1676,10 @@ compiler_function(struct compiler *c, stmt_ty s)
|
|||
VISIT_IN_SCOPE(c, stmt, st);
|
||||
}
|
||||
co = assemble(c, 1);
|
||||
qualname = compiler_scope_qualname(c, s->v.FunctionDef.name);
|
||||
qualname = c->u->u_qualname;
|
||||
Py_INCREF(qualname);
|
||||
compiler_exit_scope(c);
|
||||
if (qualname == NULL || co == NULL) {
|
||||
if (co == NULL) {
|
||||
Py_XDECREF(qualname);
|
||||
Py_XDECREF(co);
|
||||
return 0;
|
||||
|
@ -1734,14 +1749,8 @@ compiler_class(struct compiler *c, stmt_ty s)
|
|||
return 0;
|
||||
}
|
||||
Py_DECREF(str);
|
||||
/* store the __qualname__ */
|
||||
str = compiler_scope_qualname(c, s->v.ClassDef.name);
|
||||
if (!str) {
|
||||
compiler_exit_scope(c);
|
||||
return 0;
|
||||
}
|
||||
ADDOP_O(c, LOAD_CONST, str, consts);
|
||||
Py_DECREF(str);
|
||||
assert(c->u->u_qualname);
|
||||
ADDOP_O(c, LOAD_CONST, c->u->u_qualname, consts);
|
||||
str = PyUnicode_InternFromString("__qualname__");
|
||||
if (!str || !compiler_nameop(c, str, Store)) {
|
||||
Py_XDECREF(str);
|
||||
|
@ -1856,7 +1865,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
|
|||
if (res < 0) return 0;
|
||||
kw_default_count = res;
|
||||
}
|
||||
if (!compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION,
|
||||
if (!compiler_enter_scope(c, name, COMPILER_SCOPE_LAMBDA,
|
||||
(void *)e, e->lineno))
|
||||
return 0;
|
||||
|
||||
|
@ -1875,9 +1884,10 @@ compiler_lambda(struct compiler *c, expr_ty e)
|
|||
ADDOP_IN_SCOPE(c, RETURN_VALUE);
|
||||
}
|
||||
co = assemble(c, 1);
|
||||
qualname = compiler_scope_qualname(c, NULL);
|
||||
qualname = c->u->u_qualname;
|
||||
Py_INCREF(qualname);
|
||||
compiler_exit_scope(c);
|
||||
if (qualname == NULL || co == NULL)
|
||||
if (co == NULL)
|
||||
return 0;
|
||||
|
||||
arglength = asdl_seq_LEN(args->defaults);
|
||||
|
@ -3152,9 +3162,10 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, identifier name,
|
|||
}
|
||||
|
||||
co = assemble(c, 1);
|
||||
qualname = compiler_scope_qualname(c, NULL);
|
||||
qualname = c->u->u_qualname;
|
||||
Py_INCREF(qualname);
|
||||
compiler_exit_scope(c);
|
||||
if (qualname == NULL || co == NULL)
|
||||
if (co == NULL)
|
||||
goto error;
|
||||
|
||||
if (!compiler_make_closure(c, co, 0, qualname))
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -116,6 +116,10 @@ int Py_IsolatedFlag = 0; /* for -I, isolate from user's env */
|
|||
|
||||
PyThreadState *_Py_Finalizing = NULL;
|
||||
|
||||
/* Hack to force loading of object files */
|
||||
int (*_PyOS_mystrnicmp_hack)(const char *, const char *, Py_ssize_t) = \
|
||||
PyOS_mystrnicmp; /* Python/pystrcmp.o */
|
||||
|
||||
/* PyModule_GetWarningsModule is no longer necessary as of 2.6
|
||||
since _warnings is builtin. This API should not be used. */
|
||||
PyObject *
|
||||
|
|
|
@ -471,13 +471,13 @@ dump_decimal(int fd, int value)
|
|||
write(fd, buffer, len);
|
||||
}
|
||||
|
||||
/* Format an integer in range [0; 0xffffffff] to hexdecimal of 'width' digits,
|
||||
/* Format an integer in range [0; 0xffffffff] to hexadecimal of 'width' digits,
|
||||
and write it into the file fd.
|
||||
|
||||
This function is signal safe. */
|
||||
|
||||
static void
|
||||
dump_hexadecimal(int width, unsigned long value, int fd)
|
||||
dump_hexadecimal(int fd, unsigned long value, int width)
|
||||
{
|
||||
int len;
|
||||
char buffer[sizeof(unsigned long) * 2 + 1];
|
||||
|
@ -544,15 +544,15 @@ dump_ascii(int fd, PyObject *text)
|
|||
}
|
||||
else if (ch < 0xff) {
|
||||
PUTS(fd, "\\x");
|
||||
dump_hexadecimal(2, ch, fd);
|
||||
dump_hexadecimal(fd, ch, 2);
|
||||
}
|
||||
else if (ch < 0xffff) {
|
||||
PUTS(fd, "\\u");
|
||||
dump_hexadecimal(4, ch, fd);
|
||||
dump_hexadecimal(fd, ch, 4);
|
||||
}
|
||||
else {
|
||||
PUTS(fd, "\\U");
|
||||
dump_hexadecimal(8, ch, fd);
|
||||
dump_hexadecimal(fd, ch, 8);
|
||||
}
|
||||
}
|
||||
if (truncated)
|
||||
|
@ -603,7 +603,7 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
|
|||
unsigned int depth;
|
||||
|
||||
if (write_header)
|
||||
PUTS(fd, "Traceback (most recent call first):\n");
|
||||
PUTS(fd, "Stack (most recent call first):\n");
|
||||
|
||||
frame = _PyThreadState_GetFrame(tstate);
|
||||
if (frame == NULL)
|
||||
|
@ -641,8 +641,8 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
|
|||
PUTS(fd, "Current thread 0x");
|
||||
else
|
||||
PUTS(fd, "Thread 0x");
|
||||
dump_hexadecimal(sizeof(long)*2, (unsigned long)tstate->thread_id, fd);
|
||||
PUTS(fd, ":\n");
|
||||
dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(long)*2);
|
||||
PUTS(fd, " (most recent call first):\n");
|
||||
}
|
||||
|
||||
const char*
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue