Opened 9 months ago

Closed 9 months ago

#21551 closed enhancement (fixed)

cython-3.1.0 (Python module)

Reported by: Bruce Dubbs Owned by: Bruce Dubbs
Priority: normal Milestone: 12.4
Component: BOOK Version: git
Severity: normal Keywords:
Cc:

Description

New minor version.

Change History (3)

comment:1 by Bruce Dubbs, 9 months ago

Owner: changed from blfs-book to Bruce Dubbs
Status: newassigned

comment:2 by Bruce Dubbs, 9 months ago

3.1.0 (2025-05-08)

Other changes

  • No functional changes since 3.1.0 rc 2.

3.1.0 rc 2 (2025-05-07)

Features added

  • Declarations for C++ std::stop_token were added as libcpp.stop_token to provide additional low-level synchronisation primitives also in the light of free-threading Python.
  • The generation of the shared module now happens automatically from cythonize() in a setuptools build if a corresponding Extension has been configured. This avoids an additional step outside of the setup.py or pip wheel run.

Bugs fixed

  • Variables typed as builtin Python exception types now accept subtypes instead of rejecting them. This specifically impacted types like BaseException, Exception or OSError, which almost always intend to reference subtypes.
  • Functions with more than 10 constant default argument values could generate invalid C code.
  • The call_once() function argument in libc.threads (new in 3.1) was changed to require a nogil declaration, as semantically implied. Code that used it with a callback function expecting to hold the GIL must change the callback code to use with gil.
  • Calling cimported C functions with their fully qualified package name could crash Cython.

  • Naming a variable after its inferred type (e.g. str += "") could trigger an infinite loop in Cython.

  • Cython is more relaxed about the exact C++ constructor name when it calls new() on ctypedefs.
  • Using cpp_locals in nogil sections could crash.
  • const struct declarations could lead to invalid assignments to const temp variables.
  • A refcounting error was fixed in the method class cell support code.

3.1.0 rc 1 (2025-05-01)

Features added

  • cython.pymutex provides a fast mutex by wrapping the new PyMutex feature of recent CPython versions (including free-threading) and falls back to PyThread locks in older Pythons.

  • A new directive subinterpreters_compatible=shared_gil/own_gil was added to allow modules to declare support for subinterpreters.
  • divmod() is also optimised for C floating point types and can be called on C number types without holding the GIL.
  • New C++ declarations were added.
  • embedsignature now works for special methods (if they have a docstring).

Bugs fixed

  • Iterating over literal sequences in generator expressions could generate invalid C code.
  • Tracing could generate invalid C code.
  • Non-ASCII function argument names could generate invalid C code.
  • Optimised divmod() calls could produce incorrect results in beta-1 due to incorrect C type usage.
  • Raising UnboundLocalError could fail for non-ascii variable names.
  • The signature of PyByteArray_Resize() in cpython.bytearray failed to propagate exceptions.
  • Some more issues with the Limited C-API and free-threading Python were resolved.
  • The signature of cythonize_one() accidentally changed in 3.1.0b1.

Other changes

  • Named cpdef enums no longer copy their item names into the global module namespace. This was considered unhelpful for named enums which already live in their own class namespace. In cases where the old behaviour was desired, users can add the following backwards compatible command after their enum class definition: globals().update(TheUserEnumClass.members). Anonymous enums still produce global item names, as before.

3.1.0 beta 1 (2025-04-03)

Features added

  • Global cdef const … variables are supported.
  • A new context manager / function decorator cython.critical_section was added wrapping Python's critical section C-API feature.
  • Some common Cython-internal code (currently only memoryview related) can now be extracted into a shared extension module to reduce the installed overall size of a package with many Cython compiled modules.
  • The type of prange loop targets is now inferred.
  • Extracting keyword arguments is faster in some cases.
  • Calling divmod()on any C integer types is efficient.
  • Some async/coroutine/vectorcall code has improved fast-paths.
  • Calls to Python builtins and extension types use the vectorcall protocol.
  • Method calls use PyObject_VectorcallMethod() where possible.
  • Some C-API shortcuts were (re-)added.
  • Cython can avoid normalising exceptions in an except clause if it knows that they are unused.
  • The cython command has a new option --cache to cache generated files.
  • The cythonize command has a new option --timeit to benchmark Cython code snippets.
  • The argument parsing cygdb command was improved based on argparse.
  • The PyWeakref_GetRef declaration was added to cpython.weakref and backported.
  • std::span declarations were added to libcpp.
  • std::string_view declarations were added to libcpp.
  • Mutex declarations for libc and libcpp were added.
  • Several C++ declarations were improved and extended.
  • Bazel build rules were updated for better interoperability.
  • The Demos/benchmarks/ directory include a new benchmark runner that can run selected benchmarks against different Cython git revisions.

Bugs fixed

  • Many issues with the Limited C-API and free-threading Python were resolved. This includes better thread-safety of Cython-internal types like functions and generators.
  • for-in loops could generate invalid code for C++ containers.
  • PyDict_GetItemRef() and PyList_GetItemRef() were not always used correctly.
  • Inlined calls to local functions could crash with binding=False.
  • Calling sorted() could crash in 3.1.0a1.
  • Calling 0-arg methods was unnecessarily slow in 3.1.0a1.
  • A crash when reading the interpreter ID was fixed.
  • Crashes while tracing C function returns were resolved.
  • A compiler crash on complex/complex was resolved.
  • A compiler crash when using the cpp_locals directive was resolved.
  • Name mangling did not work correctly for attributes of extension types that have reserved C names.
  • Declaring a @staticmethod in a pxd file and overriding it in a subclass could trigger incorrect "declared but not defined" errors.
  • Cython's fake code objects are now compatible with GraalPython.
  • Stepping through foreign code with cygdb could fail with an IndexError.
  • Some PyPy incompatibilities were resolved.
  • Interoperability with recent Pythran releases was fixed.
  • The gdb compatibility of cygdb was improved.
  • Some redundant exception normalisation work was removed in Python 3.12+.
  • A compiler hang introduced in 3.1a1 when overriding methods was resolved.
  • A compiler crash was resolved when trying to issue a warning.
  • Some incomplete import time "safety checks" from 3.1.0a1 were removed again.
  • Using the common_utility_include_dir option in parallel builds on Windows could fail.
  • Some "unused" warnings from the C compiler were resolved.

Other changes

  • All Cython-internal types (functions, coroutines, …) are now heap types and use type specs.
  • Tracing/monitoring is now disabled in parallel/prange sections.
  • The numpy.math cimport module has been deprecated. Usages should be replaced by libc.math.

3.1.0 alpha 1 (2024-11-08)

Features added

  • Support for freethreading builds of CPython 3.13 was added. It comes with a new directive freethreading_compatible=True to mark modules as free-threading compatible (Py_mod_gil).
  • Support for monitoring Cython modules via sys.monitoring in CPython 3.13+ was added. For coverage reporting, this needs to be disabled with -DCYTHON_USE_SYS_MONITORING=0 as long as coverage.py does not support sys.monitoring for coverage plugins.
  • Many issues with the Limited C-API were resolved. It is now sufficient to define the macro Py_LIMITED_API to activate the support.
  • Support for GraalPython was improved (but is still incomplete).
  • Several issues with the gdb support were resolved.
  • typing.Union[SomeType, None] and SomeType | None are now understood and mean the same as typing.Optional[SomeType], allowing None in type checks.
  • cython.const[] and cython.volatile[] are now available as type modifiers in Python code.
  • cython.pointer[SomeCType] can now be used to define pointer types in Python type annotations.
  • Several improvements were made to reduce the size of the resulting extension modules.
  • Function calls now use the PEP-590 Vectorcall protocol, even when passing keyword arguments.
  • Coroutines now use the am_send slot function instead of going through a Python .send() call.
  • set_name is called when assigning to class attributes.
  • Most builtin methods now provide their return type for type inference.
  • Method calls on builtin literal values are evaluated at compile time, if applicable.
  • The Python int type now maps directly to PyLong and is inferred accordingly.
  • Integer operations on known int types are faster.
  • f-strings are faster in some cases.
  • divmod() is faster on C int.
  • dict.pop() is faster in some cases.
  • .isprintable() is optimised for Unicode characters.
  • x in () and similar tests against empty constant sequences (e.g. in generated code) are now discarded if they have no side-effects.
  • Constant (non-GC) Python objects are no longer traversed with Py_VISIT() during GC runs.
  • C++ classes implemented in Cython can now use method overloading.
  • Assigning a Python container to a C++ vector now makes use of length_hint to avoid reallocations.
  • The C++11 emplace* methods were added to libcpp.deque.
  • cpython.time was updated and extended for Python 3.13.
  • Dataclasses support the match_args option.
  • Threading in parallel sections can now be disabled with a new use_threads_if condition.
  • New options warn.deprecated.DEF and warn.deprecated.IF can silence the deprecation warnings.
  • cygdb shows more helpful output for some objects.
  • Bazel build support for improved.
  • The parser was updated for Unicode 15.1 (as provided by CPython 3.13b4).

Bugs fixed

  • C functions used different start lines and columns for error reporting and tracing than Python functions. They now use the line and column of their first decorator or (if none) their definition line, as in Python.
  • Dataclasses did not handle default fields without init value correctly.
  • Implementing a special method based on another could lead to infinite recursion.
  • The class cell variable in methods was not always working as in Python.
  • Lambda functions had no code objects. Their signature can now be introspected.
  • Subtyping complex as extension type could fail.
  • hasattr() now propagates exceptions that occur during lookup.
  • The base type of extension heap types is now traversed during GC runs in Py3.9+.
  • The Python & operator could touch invalid memory with certain 0 values in Python <= 3.10.
  • Exception values were not always recognised as equal at compile time.
  • Running Cython in different Python versions could generate slightly different C code due to differences in the builtins.
  • The common_include_dir feature used different file paths in the C code on Windows and Posix. It now uses forward slashes as directory separator consistently.
  • File paths in the C code are now relative to the build directory.
  • depfiles now use relative paths whenever possible.
  • The -a option in the IPython magic no longer copies the complete HTML document into the notebook but only a more reasonable content snippet.
  • Uselessly referring to C enums (not enum values) as Python objects is now rejected.
  • Cython no longer acquires the GIL during in-place assignments to C attributes in nogil sections.
  • Several C++ warnings about char* casts were resolved.
  • C++ undefined behaviour was fixed in an error handling case.
  • Dict assignments to struct members with reserved C/C++ names could generate invalid C code.
  • The PEP-479 implementation could raise a visible RuntimeError without a trace of the original StopIteration.
  • A crash was fixed when assigning a zero-length slice to a memoryview.
  • Conditionally assigning to variables with the walrus operator could crash.
  • Unterminated string literals could lock up the build in an infinite loop.
  • Exporting C functions uses better platform compatible code.
  • The shebang in libpython.py was incorrect.
  • Cython now uses SHA-256 instead of SHA-1 for caching etc. as the latter may not be available on all Python installations.

Other changes

  • Support for Python 2.7 - 3.7 was removed, along with large chunks of legacy code.
  • The pxd files cpython.int, cpython.cobject, cpython.oldbuffer and cpython.string were removed as they refer to C-API declarations that are only in Python 2.x.
  • The generated C code now requires a C99 compatible C compiler.
  • language_level=3 is now the default. language_level=3str has become a legacy alias.
  • The Py2 types unicode and basestring are now deprecated and have become aliases of the str type.
  • Docstrings now strip their leading whitespace according to PEP-257.
  • Type checkers should have it easier to find and validate Cython types in .py files.
  • The previously shipped NumPy C-API declarations (cimport numpy) were removed. NumPy has been providing version specific declarations for several versions now.
  • Usages of the outdated WITH_THREAD macro guard were removed.
  • The options for showing the C code line in Python exception stack traces were cleaned up. Previously, disabling the option with the CYTHON_CLINE_IN_TRACEBACK macro did not reduce the code overhead of the feature, and the c_line_in_traceback compile option was partly redundant with the C macro switches and lead to warnings about unused code. Since this is considered mostly a debug feature, the new default is that it is _disabled_ to avoid code and runtime overhead. It can be enabled by setting the C macro to 1, and a new macro CYTHON_CLINE_IN_TRACEBACK_RUNTIME was added that controls the runtime configurable setting if the feature is enabled, which was previously only available through the compile option. The compile option is now deprecated (but still available), and users should migrate to using the two C macros only.

comment:3 by Bruce Dubbs, 9 months ago

Resolution: fixed
Status: assignedclosed

Fixed at commits

cd6aaac888 Update to nss-3.111.
63ab222e83 Update to SDL2-2.32.6.
8c86698398 Update to cython-3.1.0 (Python module).
Note: See TracTickets for help on using tickets.