.. _changelog: Changelog ######### Starting with version 1.8.0, pybind11 releases use a `semantic versioning `_ policy. v2.5.0 (Mar 31, 2020) ----------------------------------------------------- * Use C++17 fold expressions in type casters, if available. This can improve performance during overload resolution when functions have multiple arguments. `#2043 `_. * Changed include directory resolution in ``pybind11/__init__.py`` and installation in ``setup.py``. This fixes a number of open issues where pybind11 headers could not be found in certain environments. `#1995 `_. * C++20 ``char8_t`` and ``u8string`` support. `#2026 `_. * CMake: search for Python 3.9. `bb9c91 `_. * Fixes for MSYS-based build environments. `#2087 `_, `#2053 `_. * STL bindings for ``std::vector<...>::clear``. `#2074 `_. * Read-only flag for ``py::buffer``. `#1466 `_. * Exception handling during module initialization. `bf2b031 `_. * Support linking against a CPython debug build. `#2025 `_. * Fixed issues involving the availability and use of aligned ``new`` and ``delete``. `#1988 `_, `759221 `_. * Fixed a resource leak upon interpreter shutdown. `#2020 `_. * Fixed error handling in the boolean caster. `#1976 `_. v2.4.3 (Oct 15, 2019) ----------------------------------------------------- * Adapt pybind11 to a C API convention change in Python 3.8. `#1950 `_. v2.4.2 (Sep 21, 2019) ----------------------------------------------------- * Replaced usage of a C++14 only construct. `#1929 `_. * Made an ifdef future-proof for Python >= 4. `f3109d `_. v2.4.1 (Sep 20, 2019) ----------------------------------------------------- * Fixed a problem involving implicit conversion from enumerations to integers on Python 3.8. `#1780 `_. v2.4.0 (Sep 19, 2019) ----------------------------------------------------- * Try harder to keep pybind11-internal data structures separate when there are potential ABI incompatibilities. Fixes crashes that occurred when loading multiple pybind11 extensions that were e.g. compiled by GCC (libstdc++) and Clang (libc++). `#1588 `_ and `c9f5a `_. * Added support for ``__await__``, ``__aiter__``, and ``__anext__`` protocols. `#1842 `_. * ``pybind11_add_module()``: don't strip symbols when compiling in ``RelWithDebInfo`` mode. `#1980 `_. * ``enum_``: Reproduce Python behavior when comparing against invalid values (e.g. ``None``, strings, etc.). Add back support for ``__invert__()``. `#1912 `_, `#1907 `_. * List insertion operation for ``py::list``. Added ``.empty()`` to all collection types. Added ``py::set::contains()`` and ``py::dict::contains()``. `#1887 `_, `#1884 `_, `#1888 `_. * ``py::details::overload_cast_impl`` is available in C++11 mode, can be used like ``overload_cast`` with an additional set of parantheses. `#1581 `_. * Fixed ``get_include()`` on Conda. `#1877 `_. * ``stl_bind.h``: negative indexing support. `#1882 `_. * Minor CMake fix to add MinGW compatibility. `#1851 `_. * GIL-related fixes. `#1836 `_, `8b90b `_. * Other very minor/subtle fixes and improvements. `#1329 `_, `#1910 `_, `#1863 `_, `#1847 `_, `#1890 `_, `#1860 `_, `#1848 `_, `#1821 `_, `#1837 `_, `#1833 `_, `#1748 `_, `#1852 `_. v2.3.0 (June 11, 2019) ----------------------------------------------------- * Significantly reduced module binary size (10-20%) when compiled in C++11 mode with GCC/Clang, or in any mode with MSVC. Function signatures are now always precomputed at compile time (this was previously only available in C++14 mode for non-MSVC compilers). `#934 `_. * Add basic support for tag-based static polymorphism, where classes provide a method to returns the desired type of an instance. `#1326 `_. * Python type wrappers (``py::handle``, ``py::object``, etc.) now support map Python's number protocol onto C++ arithmetic operators such as ``operator+``, ``operator/=``, etc. `#1511 `_. * A number of improvements related to enumerations: 1. The ``enum_`` implementation was rewritten from scratch to reduce code bloat. Rather than instantiating a full implementation for each enumeration, most code is now contained in a generic base class. `#1511 `_. 2. The ``value()`` method of ``py::enum_`` now accepts an optional docstring that will be shown in the documentation of the associated enumeration. `#1160 `_. 3. check for already existing enum value and throw an error if present. `#1453 `_. * Support for over-aligned type allocation via C++17's aligned ``new`` statement. `#1582 `_. * Added ``py::ellipsis()`` method for slicing of multidimensional NumPy arrays `#1502 `_. * Numerous Improvements to the ``mkdoc.py`` script for extracting documentation from C++ header files. `#1788 `_. * ``pybind11_add_module()``: allow including Python as a ``SYSTEM`` include path. `#1416 `_. * ``pybind11/stl.h`` does not convert strings to ``vector`` anymore. `#1258 `_. * Mark static methods as such to fix auto-generated Sphinx documentation. `#1732 `_. * Re-throw forced unwind exceptions (e.g. during pthread termination). `#1208 `_. * Added ``__contains__`` method to the bindings of maps (``std::map``, ``std::unordered_map``). `#1767 `_. * Improvements to ``gil_scoped_acquire``. `#1211 `_. * Type caster support for ``std::deque``. `#1609 `_. * Support for ``std::unique_ptr`` holders, whose deleters differ between a base and derived class. `#1353 `_. * Construction of STL array/vector-like data structures from iterators. Added an ``extend()`` operation. `#1709 `_, * CMake build system improvements for projects that include non-C++ files (e.g. plain C, CUDA) in ``pybind11_add_module`` et al. `#1678 `_. * Fixed asynchronous invocation and deallocation of Python functions wrapped in ``std::function``. `#1595 `_. * Fixes regarding return value policy propagation in STL type casters. `#1603 `_. * Fixed scoped enum comparisons. `#1571 `_. * Fixed iostream redirection for code that releases the GIL. `#1368 `_, * A number of CI-related fixes. `#1757 `_, `#1744 `_, `#1670 `_. v2.2.4 (September 11, 2018) ----------------------------------------------------- * Use new Python 3.7 Thread Specific Storage (TSS) implementation if available. `#1454 `_, `#1517 `_. * Fixes for newer MSVC versions and C++17 mode. `#1347 `_, `#1462 `_. * Propagate return value policies to type-specific casters when casting STL containers. `#1455 `_. * Allow ostream-redirection of more than 1024 characters. `#1479 `_. * Set ``Py_DEBUG`` define when compiling against a debug Python build. `#1438 `_. * Untangle integer logic in number type caster to work for custom types that may only be castable to a restricted set of builtin types. `#1442 `_. * CMake build system: Remember Python version in cache file. `#1434 `_. * Fix for custom smart pointers: use ``std::addressof`` to obtain holder address instead of ``operator&``. `#1435 `_. * Properly report exceptions thrown during module initialization. `#1362 `_. * Fixed a segmentation fault when creating empty-shaped NumPy array. `#1371 `_. * The version of Intel C++ compiler must be >= 2017, and this is now checked by the header files. `#1363 `_. * A few minor typo fixes and improvements to the test suite, and patches that silence compiler warnings. * Vectors now support construction from generators, as well as ``extend()`` from a list or generator. `#1496 `_. v2.2.3 (April 29, 2018) ----------------------------------------------------- * The pybind11 header location detection was replaced by a new implementation that no longer depends on ``pip`` internals (the recently released ``pip`` 10 has restricted access to this API). `#1190 `_. * Small adjustment to an implementation detail to work around a compiler segmentation fault in Clang 3.3/3.4. `#1350 `_. * The minimal supported version of the Intel compiler was >= 17.0 since pybind11 v2.1. This check is now explicit, and a compile-time error is raised if the compiler meet the requirement. `#1363 `_. * Fixed an endianness-related fault in the test suite. `#1287 `_. v2.2.2 (February 7, 2018) ----------------------------------------------------- * Fixed a segfault when combining embedded interpreter shutdown/reinitialization with external loaded pybind11 modules. `#1092 `_. * Eigen support: fixed a bug where Nx1/1xN numpy inputs couldn't be passed as arguments to Eigen vectors (which for Eigen are simply compile-time fixed Nx1/1xN matrices). `#1106 `_. * Clarified to license by moving the licensing of contributions from ``LICENSE`` into ``CONTRIBUTING.md``: the licensing of contributions is not actually part of the software license as distributed. This isn't meant to be a substantial change in the licensing of the project, but addresses concerns that the clause made the license non-standard. `#1109 `_. * Fixed a regression introduced in 2.1 that broke binding functions with lvalue character literal arguments. `#1128 `_. * MSVC: fix for compilation failures under /permissive-, and added the flag to the appveyor test suite. `#1155 `_. * Fixed ``__qualname__`` generation, and in turn, fixes how class names (especially nested class names) are shown in generated docstrings. `#1171 `_. * Updated the FAQ with a suggested project citation reference. `#1189 `_. * Added fixes for deprecation warnings when compiled under C++17 with ``-Wdeprecated`` turned on, and add ``-Wdeprecated`` to the test suite compilation flags. `#1191 `_. * Fixed outdated PyPI URLs in ``setup.py``. `#1213 `_. * Fixed a refcount leak for arguments that end up in a ``py::args`` argument for functions with both fixed positional and ``py::args`` arguments. `#1216 `_. * Fixed a potential segfault resulting from possible premature destruction of ``py::args``/``py::kwargs`` arguments with overloaded functions. `#1223 `_. * Fixed ``del map[item]`` for a ``stl_bind.h`` bound stl map. `#1229 `_. * Fixed a regression from v2.1.x where the aggregate initialization could unintentionally end up at a constructor taking a templated ``std::initializer_list`` argument. `#1249 `_
/* inffast.c -- fast decoding
 * Copyright (C) 1995-2008, 2010 Mark Adler
 * For conditions of distribution and use, see copyright notice in zlib.h
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc/util/abc_global.h"

#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"

ABC_NAMESPACE_IMPL_START

#ifndef ASMINF

/* Allow machine dependent optimization for post-increment or pre-increment.
   Based on testing to date,
   Pre-increment preferred for:
   - PowerPC G3 (Adler)
   - MIPS R5000 (Randers-Pehrson)
   Post-increment preferred for:
   - none
   No measurable difference:
   - Pentium III (Anderson)
   - M68060 (Nikl)
 */
#ifdef POSTINC
#  define OFF 0
#  define PUP(a) *(a)++
#else
#  define OFF 1
#  define PUP(a) *++(a)
#endif

/*
   Decode literal, length, and distance codes and write out the resulting
   literal and match bytes until either not enough input or output is
   available, an end-of-block is encountered, or a data error is encountered.
   When large enough input and output buffers are supplied to inflate(), for
   example, a 16K input buffer and a 64K output buffer, more than 95% of the
   inflate execution time is spent in this routine.

   Entry assumptions:

        state->mode == LEN
        strm->avail_in >= 6
        strm->avail_out >= 258
        start >= strm->avail_out
        state->bits < 8

   On return, state->mode is one of:

        LEN -- ran out of enough output space or enough available input
        TYPE -- reached end of block code, inflate() to interpret next block
        BAD -- error in block data

   Notes:

    - The maximum input bits used by a length/distance pair is 15 bits for the
      length code, 5 bits for the length extra, 15 bits for the distance code,
      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
      Therefore if strm->avail_in >= 6, then there is enough input to avoid
      checking for available input while decoding.

    - The maximum bytes that a single length/distance pair can output is 258
      bytes, which is the maximum length that can be coded.  inflate_fast()
      requires strm->avail_out >= 258 for each loop to avoid checking for
      output space.
 */
void ZLIB_INTERNAL inflate_fast(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 */
    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 */
#ifdef INFLATE_STRICT
    unsigned dmax;              /* maximum distance from zlib header */
#endif
    unsigned wsize;             /* window size or zero if not using window */
    unsigned whave;             /* valid bytes in the window */
    unsigned wnext;             /* window write index */
    unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
    unsigned long hold;         /* local strm->hold */
    unsigned bits;              /* local strm->bits */
    code const FAR *lcode;      /* local strm->lencode */
    code const FAR *dcode;      /* local strm->distcode */
    unsigned lmask;             /* mask for first level of length codes */
    unsigned dmask;             /* mask for first level of distance codes */
    code here;                  /* retrieved table entry */
    unsigned op;                /* code bits, operation, extra bits, or */
                                /*  window position, window bytes to copy */
    unsigned len;               /* match length, unused bytes */
    unsigned dist;              /* match distance */
    unsigned char FAR *from;    /* where to copy match from */

    /* copy state to local variables */
    state = (struct inflate_state FAR *)strm->state;
    in = strm->next_in - OFF;
    last = in + (strm->avail_in - 5);
    out = strm->next_out - OFF;
    beg = out - (start - strm->avail_out);
    end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT
    dmax = state->dmax;
#endif
    wsize = state->wsize;
    whave = state->whave;
    wnext = state->wnext;
    window = state->window;
    hold = state->hold;
    bits = state->bits;
    lcode = state->lencode;
    dcode = state->distcode;
    lmask = (1U << state->lenbits) - 1;
    dmask = (1U << state->distbits) - 1;

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

    /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
    len = bits >> 3;
    in -= len;
    bits -= len << 3;
    hold &= (1U << bits) - 1;

    /* update state and return */
    strm->next_in = in + OFF;
    strm->next_out = out + OFF;
    strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
    strm->avail_out = (unsigned)(out < end ?
                                 257 + (end - out) : 257 - (out - end));
    state->hold = hold;
    state->bits = bits;
    return;
}

/*
   inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
   - Using bit fields for code structure
   - Different op definition to avoid & for extra bits (do & for table bits)
   - Three separate decoding do-loops for direct, window, and wnext == 0
   - Special case for distance > 1 copies to do overlapped load and store copy
   - Explicit branch predictions (based on measured branch probabilities)
   - Deferring match copy and interspersed it with decoding subsequent codes
   - Swapping literal/length else
   - Swapping window/direct else
   - Larger unrolled copy loops (three is about right)
   - Moving len -= 3 statement into middle of loop
 */

#endif /* !ASMINF */

 

ABC_NAMESPACE_IMPL_END