patch 9.1.0784: there are several problems with python 3.13

Commit: 
https://github.com/vim/vim/commit/83a06705dcfb10e13a75eace6319cb77b6af4d29
Author: Boris Staletic <boris.stale...@protonmail.com>
Date:   Mon Oct 14 20:28:39 2024 +0200

    patch 9.1.0784: there are several problems with python 3.13
    
    Problem:  there are several problems with python 3.13
    Solution: fix the problems in the python3 interface (Boris Staletic)
    
    This commit does the following things:
    1) Since python 3.13.0b1, all statically defined objects are "immortal".
       Besides never getting garbage collected, this also affects reference
       counting:
    
       - Immportal objects have a reference count of 2^32-1.
       - Reference counting is a no-op.
    
       All this is considered implementation details by cpython, so
       documentation is next to non-existent.
    
       Relevant CPython source code:
       https://github.com/python/cpython/blob/v3.13.0/Include/object.h#L62-L107
       https://github.com/python/cpython/blob/v3.13.0/Include/object.h#L389-L391
    
    2) Opt-out of ANSI-painted python stack traces
    
    3) Make python error message severity more consistent
    
    fixes: #15838
    closes: #15842
    
    Signed-off-by: Boris Staletic <boris.stale...@protonmail.com>
    Signed-off-by: puremourning <puremourn...@users.noreply.github.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/if_py_both.h b/src/if_py_both.h
index 3643f8be2..5ba443b49 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -635,13 +635,14 @@ PythonIO_Flush(void)
     if (old_fn != NULL && io_ga.ga_len > 0)
     {
        ((char *)io_ga.ga_data)[io_ga.ga_len] = NUL;
+       // We don't know what emsg_severe should be here, so ... hope?
        old_fn((char *)io_ga.ga_data);
     }
     io_ga.ga_len = 0;
 }
 
     static void
-writer(writefn fn, char_u *str, PyInt n)
+writer(writefn fn, char_u *str, PyInt n, int severe)
 {
     char_u *ptr;
 
@@ -665,6 +666,7 @@ writer(writefn fn, char_u *str, PyInt n)
 
        mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
        ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
+       emsg_severe = severe;
        fn((char *)io_ga.ga_data);
        str = ptr + 1;
        n -= len + 1;
@@ -692,9 +694,7 @@ write_output(OutputObject *self, PyObject *string)
 
     Py_BEGIN_ALLOW_THREADS
     Python_Lock_Vim();
-    if (error)
-       emsg_severe = TRUE;
-    writer((writefn)(error ? emsg : msg), (char_u *)str, len);
+    writer((writefn)(error ? emsg : msg), (char_u *)str, len, error);
     Python_Release_Vim();
     Py_END_ALLOW_THREADS
     PyMem_Free(str);
diff --git a/src/if_python3.c b/src/if_python3.c
index 139ec54df..5d45ba15f 100644
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -1338,6 +1338,11 @@ Python3_Init(void)
            goto fail;
        }
 #endif
+       // Python 3.13 introduced a really useful feature: colorized exceptions.
+       // This is great if you're reading them from the terminal, but useless
+       // and broken everywhere else (such as in log files, or text editors).
+       // Opt out, forcefully.
+       vim_setenv((char_u*)"PYTHON_COLORS", (char_u*)"0");
 
        init_structs();
 
diff --git a/src/testdir/test_python3.vim b/src/testdir/test_python3.vim
index 7f04f11ab..3178cffd6 100644
--- a/src/testdir/test_python3.vim
+++ b/src/testdir/test_python3.vim
@@ -4029,30 +4029,34 @@ func Test_python3_iter_ref()
       v = create_list()
       base_ref_count = sys.getrefcount(v)
       for el in v:
-          vim.vars['list_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
+        vim.vars['list_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
 
       create_dict = vim.Function('Create_vim_dict')
       v = create_dict()
       base_ref_count = sys.getrefcount(v)
       for el in v:
-          vim.vars['dict_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
+        vim.vars['dict_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
 
       v = vim.buffers
       base_ref_count = sys.getrefcount(v)
       for el in v:
-          vim.vars['bufmap_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
+        vim.vars['bufmap_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
 
       v = vim.options
       base_ref_count = sys.getrefcount(v)
       for el in v:
-          vim.vars['options_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
+        vim.vars['options_iter_ref_count_increase'] = sys.getrefcount(v) - 
base_ref_count
 
     test_python3_iter_ref()
   EOF
 
   call assert_equal(1, g:list_iter_ref_count_increase)
   call assert_equal(1, g:dict_iter_ref_count_increase)
-  call assert_equal(1, g:bufmap_iter_ref_count_increase)
+  if py3eval('sys.version_info[:2] < (3, 13)')
+    call assert_equal(1, g:bufmap_iter_ref_count_increase)
+  else
+    call assert_equal(0, g:bufmap_iter_ref_count_increase)
+  endif
   call assert_equal(1, g:options_iter_ref_count_increase)
 endfunc
 
diff --git a/src/version.c b/src/version.c
index 204356328..ec23e70cd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    784,
 /**/
     783,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1t0Q3z-00Gyij-5M%40256bit.org.

Raspunde prin e-mail lui