Skip to content

Commits on Nov 15, 2022

  1. gh-99300: Use Py_NewRef() in Python/Python-ast.c (#99499)

    Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
    Py_XNewRef() in Python/Python-ast.c.
    
    Update Parser/asdl_c.py to regenerate code.
    vstinner committed Nov 15, 2022

Commits on Nov 14, 2022

  1. gh-81057: Move Global Variables Holding Objects to _PyRuntimeState. (g…

    …h-99487)
    
    This moves nearly all remaining object-holding globals in core code (other than static types).
    
    #81057
    ericsnowcurrently committed Nov 14, 2022

Commits on Nov 10, 2022

  1. gh-99300: Use Py_NewRef() in Python/ directory (#99317)

    Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
    Py_XNewRef() in C files of the Python/ directory.
    
    Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
    vstinner committed Nov 10, 2022

Commits on Jul 24, 2022

  1. gh-95185: Check recursion depth in the AST constructor (#95186)

    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    pablogsal and serhiy-storchaka committed Jul 24, 2022

Commits on May 31, 2022

Commits on May 4, 2022

  1. Use static inline function Py_EnterRecursiveCall() (#91988)

    Currently, calling Py_EnterRecursiveCall() and
    Py_LeaveRecursiveCall() may use a function call or a static inline
    function call, depending if the internal pycore_ceval.h header file
    is included or not. Use a different name for the static inline
    function to ensure that the static inline function is always used in
    Python internals for best performance. Similar approach than
    PyThreadState_GET() (function call) and _PyThreadState_GET() (static
    inline function).
    
    * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate()
    * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate()
    * pycore_ceval.h: Rename Py_EnterRecursiveCall() to
      _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and
      _Py_LeaveRecursiveCall()
    vstinner committed May 4, 2022

Commits on Jan 7, 2022

  1. bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH…

    …-30467)
    
    Automerge-Triggered-By: GH:isidentical
    isidentical committed Jan 7, 2022

Commits on Dec 14, 2021

Commits on Jun 3, 2021

  1. bpo-11105: Do not crash when compiling recursive ASTs (GH-20594)

    When compiling an AST object with a direct / indirect reference
    cycles, on the conversion phase because of exceeding amount of
    calls, a segfault was raised. This patch adds recursion guards to
    places for preventing user inputs to not to crash AST but instead
    raise a RecursionError.
    isidentical committed Jun 3, 2021

Commits on Apr 29, 2021

  1. bpo-43892: Make match patterns explicit in the AST (GH-25585)

    Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
    ncoghlan and brandtbucher committed Apr 29, 2021

Commits on Apr 10, 2021

  1. bpo-43798: Add source location attributes to alias (GH-25324)

    * Add source location attributes to alias.
    * Move alias star construction to pegen helper.
    
    Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
    Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
    3 people committed Apr 10, 2021

Commits on Apr 7, 2021

  1. bpo-43244: Rename pycore_ast.h functions to _PyAST_xxx() (GH-25252)

    Rename AST functions of pycore_ast.h to use the "_PyAST_" prefix.
    Remove macros creating aliases without prefix. For example, Module()
    becomes _PyAST_Module(). Update Grammar/python.gram to use
    _PyAST_xxx() functions.
    vstinner committed Apr 7, 2021
  2. bpo-43244: Remove Yield macro from pycore_ast.h (GH-25243)

    * pycore_ast.h no longer defines the Yield macro.
    * Fix a compiler warning on Windows: "warning C4005: 'Yield': macro
      redefinition".
    * Python-ast.c now defines directly functions with their real
      _Py_xxx() name, rather than xxx().
    * Remove "#undef Yield" in C files including pycore_ast.h.
    vstinner committed Apr 7, 2021

Commits on Mar 24, 2021

  1. bpo-43244: Remove the pyarena.h header (GH-25007)

    Remove the pyarena.h header file with functions:
    
    * PyArena_New()
    * PyArena_Free()
    * PyArena_Malloc()
    * PyArena_AddPyObject()
    
    These functions were undocumented, excluded from the limited C API,
    and were only used internally by the compiler.
    
    Add pycore_pyarena.h header. Rename functions:
    
    * PyArena_New() => _PyArena_New()
    * PyArena_Free() => _PyArena_Free()
    * PyArena_Malloc() => _PyArena_Malloc()
    * PyArena_AddPyObject() => _PyArena_AddPyObject()
    vstinner committed Mar 24, 2021

Commits on Mar 23, 2021

  1. bpo-43244: Remove ast.h, asdl.h, Python-ast.h headers (GH-24933)

    These functions were undocumented and excluded from the limited C
    API.
    
    Most names defined by these header files were not prefixed by "Py"
    and so could create names conflicts. For example, Python-ast.h
    defined a "Yield" macro which was conflict with the "Yield" name used
    by the Windows <winbase.h> header.
    
    Use the Python ast module instead.
    
    * Move Include/asdl.h to Include/internal/pycore_asdl.h.
    * Move Include/Python-ast.h to Include/internal/pycore_ast.h.
    * Remove ast.h header file.
    * pycore_symtable.h no longer includes Python-ast.h.
    vstinner committed Mar 23, 2021

Commits on Mar 18, 2021

  1. bpo-43244: Fix test_peg_generator for PyAST_Validate() (GH-24912)

    test_peg_generator now defines _Py_TEST_PEGEN macro when building C
    code to not call PyAST_Validate() in Parser/pegen.c. Moreover, it
    defines Py_BUILD_CORE_MODULE macro to get access to the internal
    C API.
    
    Remove "global_ast_state" from Python-ast.c when it's built by
    test_peg_generator: always get the AST state from the current interpreter.
    vstinner committed Mar 18, 2021

Commits on Feb 26, 2021

  1. bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)

    Co-authored-by: Guido van Rossum <guido@python.org>
    Co-authored-by: Talin <viridia@gmail.com>
    Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
    4 people committed Feb 26, 2021

Commits on Nov 4, 2020

  1. bpo-1635741: _ast uses PyModule_AddObjectRef() (GH-23146)

    Replace PyModule_AddObject() with PyModule_AddObjectRef() in the _ast
    module (Python-ast.c).
    vstinner committed Nov 4, 2020

Commits on Nov 3, 2020

  1. bpo-41796: Call _PyAST_Fini() earlier to fix a leak (GH-23131)

    Call _PyAST_Fini() on all interpreters, not only on the main
    interpreter. Also, call it ealier to fix a reference leak.
    
    Python types contain a reference to themselves in in their
    PyTypeObject.tp_mro member. _PyAST_Fini() must called before the last
    GC collection to destroy AST types.
    
    _PyInterpreterState_Clear() now calls _PyAST_Fini(). It now also
    calls _PyWarnings_Fini() on subinterpeters, not only on the main
    interpreter.
    
    Add an assertion in AST init_types() to ensure that the _ast module
    is no longer used after _PyAST_Fini() has been called.
    vstinner committed Nov 3, 2020

Commits on Nov 2, 2020

  1. bpo-41796: Make _ast module state per interpreter (GH-23024)

    The ast module internal state is now per interpreter.
    
    * Rename "astmodulestate" to "struct ast_state"
    * Add pycore_ast.h internal header: the ast_state structure is now
      declared in pycore_ast.h.
    * Add PyInterpreterState.ast (struct ast_state)
    * Remove get_ast_state()
    * Rename get_global_ast_state() to get_ast_state()
    * PyAST_obj2mod() now handles get_ast_state() failures
    vstinner committed Nov 2, 2020

Commits on Sep 16, 2020

  1. bpo-41746: Add type information to asdl_seq objects (GH-22223)

    * Add new capability to the PEG parser to type variable assignments. For instance:
    ```
           | a[asdl_stmt_seq*]=';'.small_stmt+ [';'] NEWLINE { a }
    ```
    
    * Add new sequence types from the asdl definition (automatically generated)
    * Make `asdl_seq` type a generic aliasing pointer type.
    * Create a new `asdl_generic_seq` for the generic case using `void*`.
    * The old `asdl_seq_GET`/`ast_seq_SET` macros now are typed.
    * New `asdl_seq_GET_UNTYPED`/`ast_seq_SET_UNTYPED` macros for dealing with generic sequences.
    * Changes all possible `asdl_seq` types to use specific versions everywhere.
    pablogsal committed Sep 16, 2020

Commits on Sep 15, 2020

  1. bpo-41631: _ast module uses again a global state (#21961)

    Partially revert commit ac46eb4:
    "bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)".
    
    Using a module state per module instance is causing subtle practical
    problems.
    
    For example, the Mercurial project replaces the __import__() function
    to implement lazy import, whereas Python expected that "import _ast"
    always return a fully initialized _ast module.
    
    Add _PyAST_Fini() to clear the state at exit.
    
    The _ast module has no state (set _astmodule.m_size to 0). Remove
    astmodule_traverse(), astmodule_clear() and astmodule_free()
    functions.
    vstinner committed Sep 15, 2020

Commits on Jul 3, 2020

  1. bpo-41194: Convert _ast extension to PEP 489 (GH-21293)

    Convert the _ast extension module to PEP 489 "Multiphase
    initialization". Replace the global _ast state with a module state.
    vstinner committed Jul 3, 2020
  2. bpo-41194: The _ast module cannot be loaded more than once (GH-21290)

    Fix a crash in the _ast module: it can no longer be loaded more than
    once. It now uses a global state rather than a module state.
    
    * Move _ast module state: use a global state instead.
    * Set _astmodule.m_size to -1, so the extension cannot be loaded more
      than once.
    vstinner committed Jul 3, 2020
  3. bpo-41194: Pass module state in Python-ast.c (GH-21284)

    Rework asdl_c.py to pass the module state to functions in
    Python-ast.c, instead of using astmodulestate_global.
    
    Handle also PyState_AddModule() failure in init_types().
    vstinner committed Jul 3, 2020

Commits on May 27, 2020

  1. bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType…

    …_FromSpec types (reverts GH-19414) (GH-20264)
    
    Heap types now always visit the type in tp_traverse. See added docs for details.
    
    This reverts commit 0169d30.
    
    Automerge-Triggered-By: @encukou
    pablogsal committed May 27, 2020

Commits on May 6, 2020

Commits on Apr 15, 2020

  1. bpo-40268: Remove unused structmember.h includes (GH-19530)

    If only offsetof() is needed: include stddef.h instead.
    
    When structmember.h is used, add a comment explaining that
    PyMemberDef is used.
    vstinner committed Apr 15, 2020

Commits on Mar 22, 2020

  1. bpo-39999: Improve compatibility of the ast module. (GH-19056)

    * Re-add removed classes Suite, slice, Param, AugLoad and AugStore.
    * Add docstrings for dummy classes.
    * Add docstrings for attribute aliases.
    * Set __module__ to "ast" instead of "_ast".
    serhiy-storchaka committed Mar 22, 2020
Older