To: vim_dev@googlegroups.com Subject: Patch 8.2.1834 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1834 Problem: PyEval_InitThreads() is deprecated in Python 3.9. Solution: Do not call PyEval_InitThreads in Python 3.9 and later. (Ken Takata, closes #7113) Avoid warnings for functions. Files: src/if_python3.c, src/if_py_both.h *** ../vim-8.2.1833/src/if_python3.c 2020-10-10 23:26:24.926948004 +0200 --- src/if_python3.c 2020-10-11 15:05:50.935553679 +0200 *************** *** 1002,1012 **** reset_stdin(); Py_Initialize(); ! // Initialise threads, and below save the state using ! // PyEval_SaveThread. Without the call to PyEval_SaveThread, thread ! // specific state (such as the system trace hook), will be lost ! // between invocations of Python code. PyEval_InitThreads(); #ifdef DYNAMIC_PYTHON3 get_py3_exceptions(); #endif --- 1002,1011 ---- reset_stdin(); Py_Initialize(); ! #if PY_VERSION_HEX < 0x03090000 ! // Initialise threads. This is deprecated since Python 3.9. PyEval_InitThreads(); + #endif #ifdef DYNAMIC_PYTHON3 get_py3_exceptions(); #endif *************** *** 1024,1035 **** // sys.path. PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); ! // lock is created and acquired in PyEval_InitThreads() and thread ! // state is created in Py_Initialize() ! // there _PyGILState_NoteThreadState() also sets gilcounter to 1 ! // (python must have threads enabled!) ! // so the following does both: unlock GIL and save thread state in TLS ! // without deleting thread state PyEval_SaveThread(); py3initialised = 1; --- 1023,1036 ---- // sys.path. PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); ! // Without the call to PyEval_SaveThread, thread specific state (such ! // as the system trace hook), will be lost between invocations of ! // Python code. ! // GIL may have been created and acquired in PyEval_InitThreads() and ! // thread state is created in Py_Initialize(); there ! // _PyGILState_NoteThreadState() also sets gilcounter to 1 (python must ! // have threads enabled!), so the following does both: unlock GIL and ! // save thread state in TLS without deleting thread state PyEval_SaveThread(); py3initialised = 1; *** ../vim-8.2.1833/src/if_py_both.h 2020-08-29 12:57:12.587813107 +0200 --- src/if_py_both.h 2020-10-11 18:02:34.844603400 +0200 *************** *** 307,313 **** // Output buffer management // Function to write a line, points to either msg() or emsg(). ! typedef void (*writefn)(char_u *); static PyTypeObject OutputType; --- 307,313 ---- // Output buffer management // Function to write a line, points to either msg() or emsg(). ! typedef int (*writefn)(char *); static PyTypeObject OutputType; *************** *** 359,366 **** { if (old_fn != NULL && io_ga.ga_len > 0) { ! ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL; ! old_fn((char_u *)io_ga.ga_data); } io_ga.ga_len = 0; } --- 359,366 ---- { if (old_fn != NULL && io_ga.ga_len > 0) { ! ((char *)io_ga.ga_data)[io_ga.ga_len] = NUL; ! old_fn((char *)io_ga.ga_data); } io_ga.ga_len = 0; } *************** *** 390,396 **** 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; ! fn((char_u *)io_ga.ga_data); str = ptr + 1; n -= len + 1; io_ga.ga_len = 0; --- 390,396 ---- 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; ! fn((char *)io_ga.ga_data); str = ptr + 1; n -= len + 1; io_ga.ga_len = 0; *** ../vim-8.2.1833/src/version.c 2020-10-11 14:58:42.620838437 +0200 --- src/version.c 2020-10-11 18:04:26.060156155 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1834, /**/ -- hundred-and-one symptoms of being an internet addict: 63. You start using smileys in your snail mail. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///