Skip to content

Commit 83a0670

Browse files
bstaleticchrisbra
authored andcommitted
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.staletic@protonmail.com> Signed-off-by: puremourning <puremourning@users.noreply.github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 322ad0c commit 83a0670

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/if_py_both.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,14 @@ PythonIO_Flush(void)
635635
if (old_fn != NULL && io_ga.ga_len > 0)
636636
{
637637
((char *)io_ga.ga_data)[io_ga.ga_len] = NUL;
638+
// We don't know what emsg_severe should be here, so ... hope?
638639
old_fn((char *)io_ga.ga_data);
639640
}
640641
io_ga.ga_len = 0;
641642
}
642643

643644
static void
644-
writer(writefn fn, char_u *str, PyInt n)
645+
writer(writefn fn, char_u *str, PyInt n, int severe)
645646
{
646647
char_u *ptr;
647648

@@ -665,6 +666,7 @@ writer(writefn fn, char_u *str, PyInt n)
665666

666667
mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
667668
((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
669+
emsg_severe = severe;
668670
fn((char *)io_ga.ga_data);
669671
str = ptr + 1;
670672
n -= len + 1;
@@ -692,9 +694,7 @@ write_output(OutputObject *self, PyObject *string)
692694

693695
Py_BEGIN_ALLOW_THREADS
694696
Python_Lock_Vim();
695-
if (error)
696-
emsg_severe = TRUE;
697-
writer((writefn)(error ? emsg : msg), (char_u *)str, len);
697+
writer((writefn)(error ? emsg : msg), (char_u *)str, len, error);
698698
Python_Release_Vim();
699699
Py_END_ALLOW_THREADS
700700
PyMem_Free(str);

src/if_python3.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,11 @@ Python3_Init(void)
13381338
goto fail;
13391339
}
13401340
#endif
1341+
// Python 3.13 introduced a really useful feature: colorized exceptions.
1342+
// This is great if you're reading them from the terminal, but useless
1343+
// and broken everywhere else (such as in log files, or text editors).
1344+
// Opt out, forcefully.
1345+
vim_setenv((char_u*)"PYTHON_COLORS", (char_u*)"0");
13411346

13421347
init_structs();
13431348

src/testdir/test_python3.vim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,30 +4029,34 @@ func Test_python3_iter_ref()
40294029
v = create_list()
40304030
base_ref_count = sys.getrefcount(v)
40314031
for el in v:
4032-
vim.vars['list_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
4032+
vim.vars['list_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
40334033

40344034
create_dict = vim.Function('Create_vim_dict')
40354035
v = create_dict()
40364036
base_ref_count = sys.getrefcount(v)
40374037
for el in v:
4038-
vim.vars['dict_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
4038+
vim.vars['dict_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
40394039

40404040
v = vim.buffers
40414041
base_ref_count = sys.getrefcount(v)
40424042
for el in v:
4043-
vim.vars['bufmap_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
4043+
vim.vars['bufmap_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
40444044

40454045
v = vim.options
40464046
base_ref_count = sys.getrefcount(v)
40474047
for el in v:
4048-
vim.vars['options_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
4048+
vim.vars['options_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count
40494049

40504050
test_python3_iter_ref()
40514051
EOF
40524052

40534053
call assert_equal(1, g:list_iter_ref_count_increase)
40544054
call assert_equal(1, g:dict_iter_ref_count_increase)
4055-
call assert_equal(1, g:bufmap_iter_ref_count_increase)
4055+
if py3eval('sys.version_info[:2] < (3, 13)')
4056+
call assert_equal(1, g:bufmap_iter_ref_count_increase)
4057+
else
4058+
call assert_equal(0, g:bufmap_iter_ref_count_increase)
4059+
endif
40564060
call assert_equal(1, g:options_iter_ref_count_increase)
40574061
endfunc
40584062

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
784,
707709
/**/
708710
783,
709711
/**/

0 commit comments

Comments
 (0)