0.21 (2014-09-10)

Features added

  • C (cdef) functions allow inner Python functions.
  • Enums can now be declared as cpdef to export their values tothe module’s Python namespace. Cpdef enums in pxd files exporttheir values to their own module, iff it exists.
  • Allow @staticmethod decorator to declare static cdef methods.This is especially useful for declaring “constructors” forcdef classes that can take non-Python arguments.
  • Taking a char* from a temporary Python string object is saferin more cases and can be done inside of non-trivial expressions,including arguments of a function call. A compile time erroris raised only when such a pointer is assigned to a variable andwould thus exceed the lifetime of the string itself.
  • Generators have new properties name and qualnamethat provide the plain/qualified name of the generator function(following CPython 3.5). See https://bugs.python.org/issue21205
  • The inline function modifier is available as a decorator@cython.inline in pure mode.
  • When cygdb is run in a virtualenv, it enables the same virtualenvinside of the debugger. Patch by Marc Abramowitz.
  • PEP 465: dedicated infix operator for matrix multiplication (A @ B).
  • HTML output of annotated code uses Pygments for code highlightingand generally received a major overhaul by Matthias Bussonier.
  • IPython magic support is now available directly from Cython withthe command “%load_ext cython”. Cython code can directly beexecuted in a cell when marked with “%%cython”. Code analysisis available with “%%cython -a”. Patch by Martín Gaitán.
  • Simple support for declaring Python object types in Python signatureannotations. Currently requires setting the compiler directiveannotation_typing=True.
  • New directive use_switch (defaults to True) to optionally disablethe optimization of chained if statement to C switch statements.
  • Defines dynamic_cast et al. in libcpp.cast and C++ heap datastructure operations in libcpp.algorithm.
  • Shipped header declarations in posix.* were extended to covermore of the POSIX API. Patches by Lars Buitinck and Mark Peek.

Optimizations

  • Simple calls to C implemented Python functions/methods are faster.This also speeds up many operations on builtins that Cython cannototherwise optimise.
  • The “and”/”or” operators try to avoid unnecessary coercions of theirarguments. They now evaluate the truth value of each argumentindependently and only coerce the final result of the whole expressionto the target type (e.g. the type on the left side of an assignment).This also avoids reference counting overhead for Python values duringevaluation and generally improves the code flow in the generated C code.
  • The Python expression “2 ** N” is optimised into bit shifting.See https://bugs.python.org/issue21420
  • Cascaded assignments (a = b = …) try to minimise the number oftype coercions.
  • Calls to slice() are translated to a straight C-API call.

Bugs fixed

  • Crash when assigning memory views from ternary conditional expressions.
  • Nested C++ templates could lead to unseparated “>>” characters beinggenerated into the C++ declarations, which older C++ compilers couldnot parse.
  • Sending SIGINT (Ctrl-C) during parallel cythonize() builds couldhang the child processes.
  • No longer ignore local setup.cfg files for distutils in pyximport.Patch by Martin Teichmann.
  • Taking a char* from an indexed Python string generated unsafereference counting code.
  • Set literals now create all of their items before trying to add themto the set, following the behaviour in CPython. This makes adifference in the rare case that the item creation has side effectsand some items are not hashable (or if hashing them has side effects,too).
  • Cython no longer generates the cross product of C functions for codethat uses memory views of fused types in function signatures (e.g.cdef func(floating[:] a, floating[:] b)). This is considered theexpected behaviour by most users and was previously inconsistent withother structured types like C arrays. Code that really wants all typecombinations can create the same fused memoryview type under differentnames and use those in the signature to make it clear which types areindependent.
  • Names that were unknown at compile time were looked up as builtins atruntime but not as global module names. Trying both lookups helps withglobals() manipulation.
  • Fixed stl container conversion for typedef element types.
  • obj.pop(x) truncated large C integer values of x to Py_ssize_t.
  • init.pyc is recognised as marking a package directory(in addition to .py, .pyx and .pxd).
  • Syntax highlighting in cython-mode.el for Emacs no longerincorrectly highlights keywords found as part of longer names.
  • Correctly handle from cython.submodule cimport name.
  • Fix infinite recursion when using super with cpdef methods.
  • No-args dir() was not guaranteed to return a sorted list.

Other changes

  • The header line in the generated C files no longer contains thetimestamp but only the Cython version that wrote it. This waschanged to make builds more reproducible.
  • Removed support for CPython 2.4, 2.5 and 3.1.
  • The licensing implications on the generated code were clarifiedto avoid legal constraints for users.