changeset 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents e43771296031
children e47005b6a69f
files .github/workflows/ci.yml runtime/doc/builtin.txt runtime/doc/eval.txt runtime/doc/if_pyth.txt runtime/doc/tags runtime/doc/various.txt src/Make_cyg_ming.mak src/Make_mvc.mak src/auto/configure src/config.h.in src/configure.ac src/evalfunc.c src/evalvars.c src/if_py_both.h src/if_python3.c src/proto/if_python3.pro src/version.c src/vim.h
diffstat 18 files changed, 625 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -51,8 +51,14 @@ jobs:
           - features: huge
             coverage: true
           - features: huge
+            compiler: clang
+            extra: none
+            interface: dynamic
+            python3: stable-abi
+          - features: huge
             compiler: gcc
             coverage: true
+            interface: dynamic
             extra: testgui
             uchar: true
             luaver: lua5.4
@@ -141,7 +147,16 @@ jobs:
             ;;
           huge)
             echo "TEST=scripttests test_libvterm"
-            echo "CONFOPT=--enable-perlinterp --enable-pythoninterp --enable-python3interp --enable-rubyinterp --enable-luainterp --enable-tclinterp"
+            if ${{ matrix.interface == 'dynamic' }}; then
+              if ${{ matrix.python3 == 'stable-abi' }}; then
+                PYTHON3_FLAGS="--with-python3-stable-abi=3.8"
+              else
+                PYTHON3_FLAGS=""
+              fi
+              echo "CONFOPT=--enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic --enable-luainterp=dynamic --enable-tclinterp=dynamic ${PYTHON3_FLAGS}"
+            else
+              echo "CONFOPT=--enable-perlinterp --enable-pythoninterp --enable-python3interp --enable-rubyinterp --enable-luainterp --enable-tclinterp"
+            fi
             ;;
           esac
 
@@ -369,8 +384,8 @@ jobs:
       fail-fast: false
       matrix:
         include:
-          - { features: HUGE,   toolchain: msvc,  VIMDLL: no,  GUI: no,  arch: x64 }
-          - { features: HUGE,   toolchain: mingw, VIMDLL: yes, GUI: yes, arch: x86, coverage: yes }
+          - { features: HUGE,   toolchain: msvc,  VIMDLL: no,  GUI: no,  arch: x64, python3: stable }
+          - { features: HUGE,   toolchain: mingw, VIMDLL: yes, GUI: yes, arch: x86, python3: stable, coverage: yes }
           - { features: HUGE,   toolchain: msvc,  VIMDLL: no,  GUI: yes, arch: x86 }
           - { features: HUGE,   toolchain: mingw, VIMDLL: yes, GUI: no,  arch: x64, coverage: yes }
           - { features: NORMAL, toolchain: msvc,  VIMDLL: yes, GUI: no,  arch: x86 }
@@ -501,6 +516,11 @@ jobs:
           ) else (
             set GUI=${{ matrix.GUI }}
           )
+          if "${{ matrix.python3 }}"=="stable" (
+            set PYTHON3_STABLE=yes
+          ) else (
+            set PYTHON3_STABLE=no
+          )
           if "${{ matrix.features }}"=="HUGE" (
             nmake -nologo -f Make_mvc.mak ^
               FEATURES=${{ matrix.features }} ^
@@ -508,6 +528,7 @@ jobs:
               DYNAMIC_LUA=yes LUA=%LUA_DIR% ^
               DYNAMIC_PYTHON=yes PYTHON=%PYTHON_DIR% ^
               DYNAMIC_PYTHON3=yes PYTHON3=%PYTHON3_DIR% ^
+              DYNAMIC_PYTHON3_STABLE_ABI=%PYTHON3_STABLE% ^
               DYNAMIC_SODIUM=yes SODIUM=%SODIUM_DIR%
           ) else (
             nmake -nologo -f Make_mvc.mak ^
@@ -525,6 +546,11 @@ jobs:
           else
             GUI=${{ matrix.GUI }}
           fi
+          if [ "${{ matrix.python3 }}" = "stable" ]; then
+            PYTHON3_STABLE=yes
+          else
+            PYTHON3_STABLE=no
+          fi
           if [ "${{ matrix.features }}" = "HUGE" ]; then
             mingw32-make -f Make_ming.mak -j2 \
               FEATURES=${{ matrix.features }} \
@@ -532,6 +558,7 @@ jobs:
               DYNAMIC_LUA=yes LUA=${LUA_DIR_SLASH} \
               DYNAMIC_PYTHON=yes PYTHON=${PYTHON_DIR} \
               DYNAMIC_PYTHON3=yes PYTHON3=${PYTHON3_DIR} \
+              DYNAMIC_PYTHON3_STABLE_ABI=${PYTHON3_STABLE} \
               DYNAMIC_SODIUM=yes SODIUM=${SODIUM_DIR} \
               STATIC_STDCPLUS=yes COVERAGE=${{ matrix.coverage }}
           else
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -10984,6 +10984,7 @@ python_dynamic		Python 2.x interface is 
 python3			Python 3.x interface available. |has-python|
 python3_compiled	Compiled with Python 3.x interface. |has-python|
 python3_dynamic		Python 3.x interface is dynamically loaded. |has-python|
+python3_stable		Python 3.x interface is using Python Stable ABI. |has-python|
 pythonx			Python 2.x and/or 3.x interface available. |python_x|
 qnx			QNX version of Vim.
 quickfix		Compiled with |quickfix| support.
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2424,6 +2424,25 @@ v:progpath	Contains the command with whi
 		".exe" is not added to v:progpath.
 		Read-only.
 
+				    *v:python3_version* *python3-version-variable*
+v:python3_version
+		Version of Python 3 that Vim was built against.  When
+		Python is loaded dynamically (|python-dynamic|), this version
+		should exactly match the Python library up to the minor
+		version (e.g.  3.10.2 and 3.10.3 are compatible as the minor
+		version is "10", whereas 3.9.4 and 3.10.3 are not compatible).
+		When |python-stable-abi| is used, this will be the minimum Python
+		version that you can use instead. (e.g. if v:python3_version
+		indicates 3.9, you can use 3.9, 3.10, or anything above).
+
+		This number is encoded as a hex number following Python ABI
+		versioning conventions.  Do the following to have a
+		human-readable full version in hex: >
+			echo printf("%08X", v:python3_version)
+<		You can obtain only the minor version by doing: >
+			echo and(v:python3_version>>16,0xff)
+<		Read-only.
+
 					*v:register* *register-variable*
 v:register	The name of the register in effect for the current normal mode
 		command (regardless of whether that command actually used a
--- a/runtime/doc/if_pyth.txt
+++ b/runtime/doc/if_pyth.txt
@@ -769,7 +769,19 @@ Unix ~
 The 'pythondll' or 'pythonthreedll' option can be used to specify the Python
 shared library file instead of DYNAMIC_PYTHON_DLL or DYNAMIC_PYTHON3_DLL file
 what were specified at compile time.  The version of the shared library must
-match the Python 2.x or Python 3 version Vim was compiled with.
+match the Python 2.x or Python 3 version (|v:python3_version|) Vim was
+compiled with unless using |python3-stable-abi|.
+
+
+Stable ABI and mixing Python versions ~
+			*python-stable* *python-stable-abi* *python3-stable-abi*
+If Vim was not compiled with Stable ABI (only available for Python 3), the
+version of the Python shared library must match the version that Vim was
+compiled with.  Otherwise, mixing versions could result in unexpected crashes
+and failures.  With Stable ABI, this restriction is relaxed, and any Python 3
+library with version of at least |v:python3_version| will work.  See
+|has-python| for how to check if Stable ABI is supported, or see if version
+output includes |+python3/dyn-stable|.
 
 ==============================================================================
 10. Python 3						*python3*
@@ -881,6 +893,18 @@ python support: >
 	  endif
 	endif
 
+When loading the library dynamically, Vim can be compiled to support Python 3
+Stable ABI (|python3-stable-abi|) which allows you to load a different version
+of Python 3 library than the one Vim was compiled with.  To check it: >
+	if has('python3_dynamic')
+	  if has('python3_stable')
+	    echo 'support Python 3 Stable ABI.'
+	  else
+	    echo 'does not support Python 3 Stable ABI.'
+	    echo 'only use Python 3 version ' .. v:python3_version
+	  endif
+	endif
+
 This also tells you whether Python is dynamically loaded, which will fail if
 the runtime library cannot be found.
 
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -1434,6 +1434,7 @@
 +python/dyn	various.txt	/*+python\/dyn*
 +python3	various.txt	/*+python3*
 +python3/dyn	various.txt	/*+python3\/dyn*
++python3/dyn-stable	various.txt	/*+python3\/dyn-stable*
 +quickfix	various.txt	/*+quickfix*
 +reltime	various.txt	/*+reltime*
 +rightleft	various.txt	/*+rightleft*
@@ -9294,6 +9295,8 @@ python-path_hook	if_pyth.txt	/*python-pa
 python-pyeval	if_pyth.txt	/*python-pyeval*
 python-range	if_pyth.txt	/*python-range*
 python-special-path	if_pyth.txt	/*python-special-path*
+python-stable	if_pyth.txt	/*python-stable*
+python-stable-abi	if_pyth.txt	/*python-stable-abi*
 python-strwidth	if_pyth.txt	/*python-strwidth*
 python-tabpage	if_pyth.txt	/*python-tabpage*
 python-tabpages	if_pyth.txt	/*python-tabpages*
@@ -9306,6 +9309,8 @@ python.vim	syntax.txt	/*python.vim*
 python2-directory	if_pyth.txt	/*python2-directory*
 python3	if_pyth.txt	/*python3*
 python3-directory	if_pyth.txt	/*python3-directory*
+python3-stable-abi	if_pyth.txt	/*python3-stable-abi*
+python3-version-variable	eval.txt	/*python3-version-variable*
 python_x	if_pyth.txt	/*python_x*
 python_x-special-comments	if_pyth.txt	/*python_x-special-comments*
 pythonx	if_pyth.txt	/*pythonx*
@@ -10632,6 +10637,7 @@ v:prevcount	eval.txt	/*v:prevcount*
 v:profiling	eval.txt	/*v:profiling*
 v:progname	eval.txt	/*v:progname*
 v:progpath	eval.txt	/*v:progpath*
+v:python3_version	eval.txt	/*v:python3_version*
 v:register	eval.txt	/*v:register*
 v:scrollstart	eval.txt	/*v:scrollstart*
 v:searchforward	eval.txt	/*v:searchforward*
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -450,6 +450,8 @@ m  *+python*		Python 2 interface |python
 m  *+python/dyn*	Python 2 interface |python-dynamic| |/dyn|
 m  *+python3*		Python 3 interface |python|
 m  *+python3/dyn*	Python 3 interface |python-dynamic| |/dyn|
+m  *+python3/dyn-stable*
+			Python 3 interface |python-dynamic| |python-stable| |/dyn|
 N  *+quickfix*		|:make| and |quickfix| commands
 N  *+reltime*		|reltime()| function, 'hlsearch'/'incsearch' timeout,
 			'redrawtime' option
--- a/src/Make_cyg_ming.mak
+++ b/src/Make_cyg_ming.mak
@@ -412,6 +412,9 @@ PYTHON3INC=-I $(PYTHON3)/include
   else
 PYTHON3INC=-I $(PYTHON3)/win32inc
   endif
+  ifeq ($(DYNAMIC_PYTHON3_STABLE_ABI),yes)
+PYTHON3INC += -DPy_LIMITED_API=0x3080000
+  endif
  endif
 endif
 
@@ -594,6 +597,9 @@ ifdef PYTHON3
 CFLAGS += -DFEAT_PYTHON3
  ifeq (yes, $(DYNAMIC_PYTHON3))
 CFLAGS += -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"$(DYNAMIC_PYTHON3_DLL)\"
+  ifeq (yes, $(DYNAMIC_PYTHON3_STABLE_ABI))
+CFLAGS += -DDYNAMIC_PYTHON3_STABLE_ABI
+  endif
  else
 CFLAGS += -DPYTHON3_DLL=\"$(DYNAMIC_PYTHON3_DLL)\"
  endif
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -950,7 +950,13 @@ PYTHON3_INC = /I "$(PYTHON3)\Include" /I
 ! if "$(DYNAMIC_PYTHON3)" == "yes"
 CFLAGS = $(CFLAGS) -DDYNAMIC_PYTHON3 \
 		-DDYNAMIC_PYTHON3_DLL=\"$(DYNAMIC_PYTHON3_DLL)\"
+!  if "$(DYNAMIC_PYTHON3_STABLE_ABI)" == "yes"
+CFLAGS = $(CFLAGS) -DDYNAMIC_PYTHON3_STABLE_ABI
+PYTHON3_INC = $(PYTHON3_INC) -DPy_LIMITED_API=0x3080000
+PYTHON3_LIB = /nodefaultlib:python3.lib
+!  else
 PYTHON3_LIB = /nodefaultlib:python$(PYTHON3_VER).lib
+!  endif
 ! else
 CFLAGS = $(CFLAGS) -DPYTHON3_DLL=\"$(DYNAMIC_PYTHON3_DLL)\"
 PYTHON3_LIB = "$(PYTHON3)\libs\python$(PYTHON3_VER).lib"
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -680,6 +680,7 @@ PYTHON3_SRC
 PYTHON3_CFLAGS_EXTRA
 PYTHON3_CFLAGS
 PYTHON3_LIBS
+vi_cv_var_python3_stable_abi
 vi_cv_path_python3
 PYTHON_OBJ
 PYTHON_SRC
@@ -811,6 +812,7 @@ with_python_command
 with_python_config_dir
 enable_python3interp
 with_python3_command
+with_python3_stable_abi
 with_python3_config_dir
 enable_tclinterp
 with_tclsh
@@ -1531,6 +1533,7 @@ Optional Packages:
   --with-python-command=NAME  name of the Python 2 command (default: python2 or python)
   --with-python-config-dir=PATH  Python's config directory (deprecated)
   --with-python3-command=NAME  name of the Python 3 command (default: python3 or python)
+  --with-python3-stable-abi=VERSION  stable ABI version to target (e.g. 3.8)
   --with-python3-config-dir=PATH  Python's config directory (deprecated)
   --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)
   --with-ruby-command=RUBY  name of the Ruby command (default: ruby)
@@ -6753,6 +6756,34 @@ fi
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: yep" >&5
 $as_echo "yep" >&6; }
 
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking --with-python3-stable-abi argument" >&5
+$as_echo_n "checking --with-python3-stable-abi argument... " >&6; }
+
+
+# Check whether --with-python3-stable-abi was given.
+if test "${with_python3_stable_abi+set}" = set; then :
+  withval=$with_python3_stable_abi; vi_cv_var_python3_stable_abi="$withval"; { $as_echo "$as_me:${as_lineno-$LINENO}: result: $vi_cv_var_python3_stable_abi" >&5
+$as_echo "$vi_cv_var_python3_stable_abi" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+      if test "X$vi_cv_var_python3_stable_abi" != "X"; then
+        if ${vi_cv_var_python3_stable_abi_hex+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+         vi_cv_var_python3_stable_abi_hex=`
+         ${vi_cv_path_python3} -c \
+         "major_minor='${vi_cv_var_python3_stable_abi}'.split('.'); print('0x{0:X}'.format( (int(major_minor.__getitem__(0))<<24) + (int(major_minor.__getitem__(1))<<16) ))"`
+fi
+
+        if test "X$vi_cv_var_python3_stable_abi_hex" == "X"; then
+          as_fn_error $? "can't parse Python 3 stable ABI version. It should be \"<major>.<minor>\"" "$LINENO" 5
+        fi
+      fi
+
             { $as_echo "$as_me:${as_lineno-$LINENO}: checking Python's abiflags" >&5
 $as_echo_n "checking Python's abiflags... " >&6; }
 if ${vi_cv_var_python3_abiflags+:} false; then :
@@ -6897,9 +6928,12 @@ fi
         else
           PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags}"
         fi
-	if test "X$have_python3_config_dir" = "X1" -a "$enable_python3interp" = "dynamic"; then
-	  	  PYTHON3_CFLAGS="${PYTHON3_CFLAGS}  -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'"
-	fi
+        if test "X$have_python3_config_dir" = "X1" -a "$enable_python3interp" = "dynamic"; then
+                    PYTHON3_CFLAGS="${PYTHON3_CFLAGS}  -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'"
+        fi
+        if test "X$vi_cv_var_python3_stable_abi_hex" != "X"; then
+          PYTHON3_CFLAGS="${PYTHON3_CFLAGS} -DPy_LIMITED_API=${vi_cv_var_python3_stable_abi_hex}"
+        fi
         PYTHON3_SRC="if_python3.c"
         PYTHON3_OBJ="objects/if_python3.o"
 
@@ -7009,6 +7043,10 @@ if test "$python_ok" = yes && test "$pyt
 
   $as_echo "#define DYNAMIC_PYTHON3 1" >>confdefs.h
 
+  if test "X$vi_cv_var_python3_stable_abi_hex" != "X"; then
+    $as_echo "#define DYNAMIC_PYTHON3_STABLE_ABI 1" >>confdefs.h
+
+  fi
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can do without RTLD_GLOBAL for Python" >&5
 $as_echo_n "checking whether we can do without RTLD_GLOBAL for Python... " >&6; }
   cflags_save=$CFLAGS
@@ -7190,6 +7228,10 @@ rm -f core conftest.err conftest.$ac_obj
 elif test "$python3_ok" = yes && test "$enable_python3interp" = "dynamic"; then
   $as_echo "#define DYNAMIC_PYTHON3 1" >>confdefs.h
 
+  if test "X$vi_cv_var_python3_stable_abi_hex" != "X"; then
+    $as_echo "#define DYNAMIC_PYTHON3_STABLE_ABI 1" >>confdefs.h
+
+  fi
   PYTHON3_SRC="if_python3.c"
   PYTHON3_OBJ="objects/if_python3.o"
   PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${vi_cv_dll_name_python3}\\\""
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -354,6 +354,9 @@
 /* Define for linking via dlopen() or LoadLibrary() */
 #undef DYNAMIC_PYTHON3
 
+/* Define if compiled against Python 3 stable ABI / limited API */
+#undef DYNAMIC_PYTHON3_STABLE_ABI
+
 /* Define if dynamic python does not require RTLD_GLOBAL */
 #undef PY_NO_RTLD_GLOBAL
 
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -1503,6 +1503,23 @@ if test "$enable_python3interp" = "yes" 
     then
       AC_MSG_RESULT(yep)
 
+      dnl -- get the stable ABI version if passed in
+      AC_MSG_CHECKING(--with-python3-stable-abi argument)
+      AC_SUBST(vi_cv_var_python3_stable_abi)
+      AC_ARG_WITH(python3-stable-abi, [  --with-python3-stable-abi=VERSION  stable ABI version to target (e.g. 3.8)],
+        vi_cv_var_python3_stable_abi="$withval"; AC_MSG_RESULT($vi_cv_var_python3_stable_abi),
+        AC_MSG_RESULT(no))
+      if test "X$vi_cv_var_python3_stable_abi" != "X"; then
+        AC_CACHE_VAL(vi_cv_var_python3_stable_abi_hex,
+        [
+         vi_cv_var_python3_stable_abi_hex=`
+         ${vi_cv_path_python3} -c \
+         "major_minor='${vi_cv_var_python3_stable_abi}'.split('.'); print('0x{0:X}'.format( (int(major_minor.__getitem__(0))<<24) + (int(major_minor.__getitem__(1))<<16) ))"` ])
+        if test "X$vi_cv_var_python3_stable_abi_hex" == "X"; then
+          AC_MSG_ERROR([can't parse Python 3 stable ABI version. It should be "<major>.<minor>"])
+        fi
+      fi
+
       dnl -- get abiflags for python 3.2 or higher (PEP 3149)
       AC_CACHE_CHECK(Python's abiflags,vi_cv_var_python3_abiflags,
       [
@@ -1609,10 +1626,13 @@ eof
         else
           PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags}"
         fi
-	if test "X$have_python3_config_dir" = "X1" -a "$enable_python3interp" = "dynamic"; then
-	  dnl Define PYTHON3_HOME if --with-python-config-dir was used
-	  PYTHON3_CFLAGS="${PYTHON3_CFLAGS}  -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'"
-	fi
+        if test "X$have_python3_config_dir" = "X1" -a "$enable_python3interp" = "dynamic"; then
+          dnl Define PYTHON3_HOME if --with-python-config-dir was used
+          PYTHON3_CFLAGS="${PYTHON3_CFLAGS}  -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'"
+        fi
+        if test "X$vi_cv_var_python3_stable_abi_hex" != "X"; then
+          PYTHON3_CFLAGS="${PYTHON3_CFLAGS} -DPy_LIMITED_API=${vi_cv_var_python3_stable_abi_hex}"
+        fi
         PYTHON3_SRC="if_python3.c"
         PYTHON3_OBJ="objects/if_python3.o"
 
@@ -1693,6 +1713,9 @@ dnl with dlopen(), dlsym(), dlclose()
 if test "$python_ok" = yes && test "$python3_ok" = yes; then
   AC_DEFINE(DYNAMIC_PYTHON)
   AC_DEFINE(DYNAMIC_PYTHON3)
+  if test "X$vi_cv_var_python3_stable_abi_hex" != "X"; then
+    AC_DEFINE(DYNAMIC_PYTHON3_STABLE_ABI)
+  fi
   AC_MSG_CHECKING(whether we can do without RTLD_GLOBAL for Python)
   cflags_save=$CFLAGS
   CFLAGS="$CFLAGS $PYTHON_CFLAGS"
@@ -1816,6 +1839,9 @@ elif test "$python_ok" = yes; then
   fi
 elif test "$python3_ok" = yes && test "$enable_python3interp" = "dynamic"; then
   AC_DEFINE(DYNAMIC_PYTHON3)
+  if test "X$vi_cv_var_python3_stable_abi_hex" != "X"; then
+    AC_DEFINE(DYNAMIC_PYTHON3_STABLE_ABI)
+  fi
   PYTHON3_SRC="if_python3.c"
   PYTHON3_OBJ="objects/if_python3.o"
   PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${vi_cv_dll_name_python3}\\\""
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -6167,6 +6167,13 @@ f_has(typval_T *argvars, typval_T *rettv
 		0
 #endif
 		},
+	{"python3_stable",
+#if defined(FEAT_PYTHON3) && defined(DYNAMIC_PYTHON3_STABLE_ABI)
+		1
+#else
+		0
+#endif
+		},
 	{"python3",
 #if defined(FEAT_PYTHON3) && !defined(DYNAMIC_PYTHON3)
 		1
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -157,6 +157,7 @@ static struct vimvar
     {VV_NAME("sizeoflong",	 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("sizeofpointer",	 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("maxcol",		 VAR_NUMBER), NULL, VV_RO},
+    {VV_NAME("python3_version",	 VAR_NUMBER), NULL, VV_RO},
 };
 
 // shorthand
@@ -264,6 +265,10 @@ evalvars_init(void)
 
     set_vim_var_dict(VV_COLORNAMES, dict_alloc());
 
+#ifdef FEAT_PYTHON3
+    set_vim_var_nr(VV_PYTHON3_VERSION, python3_version());
+#endif
+
     // Default for v:register is not 0 but '"'.  This is adjusted once the
     // clipboard has been setup by calling reset_reg_var().
     set_reg_var(0);
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -30,9 +30,285 @@ static const char *vim_special_path = "_
 #define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2)
 #define PyErr_VIM_FORMAT(str, arg) PyErr_FORMAT(VimError, str, arg)
 
-#define Py_TYPE_NAME(obj) ((obj)->ob_type->tp_name == NULL \
+#ifdef USE_LIMITED_API
+// Limited Python API. Need to call only exposed functions and remap macros.
+// PyTypeObject is an opaque struct.
+
+typedef struct {
+    lenfunc sq_length;
+    binaryfunc sq_concat;
+    ssizeargfunc sq_repeat;
+    ssizeargfunc sq_item;
+    void *was_sq_slice;
+    ssizeobjargproc sq_ass_item;
+    void *was_sq_ass_slice;
+    objobjproc sq_contains;
+
+    binaryfunc sq_inplace_concat;
+    ssizeargfunc sq_inplace_repeat;
+} PySequenceMethods;
+
+typedef struct {
+    lenfunc mp_length;
+    binaryfunc mp_subscript;
+    objobjargproc mp_ass_subscript;
+} PyMappingMethods;
+
+// This struct emulates the concrete _typeobject struct to allow the code to
+// work the same way in both limited and full Python APIs.
+struct typeobject_wrapper {
+    const char *tp_name;
+    Py_ssize_t tp_basicsize;
+    unsigned long tp_flags;
+
+    // When adding new slots below, also need to make sure we add ADD_TP_SLOT
+    // call in AddHeapType for it.
+
+    destructor tp_dealloc;
+    reprfunc tp_repr;
+
+    PySequenceMethods *tp_as_sequence;
+    PyMappingMethods *tp_as_mapping;
+
+    ternaryfunc tp_call;
+    getattrofunc tp_getattro;
+    setattrofunc tp_setattro;
+
+    const char *tp_doc;
+
+    traverseproc tp_traverse;
+
+    inquiry tp_clear;
+
+    getiterfunc tp_iter;
+    iternextfunc tp_iternext;
+
+    struct PyMethodDef *tp_methods;
+    struct _typeobject *tp_base;
+    allocfunc tp_alloc;
+    newfunc tp_new;
+    freefunc tp_free;
+};
+
+# define DEFINE_PY_TYPE_OBJECT(type) \
+    static struct typeobject_wrapper type; \
+    static PyTypeObject* type##Ptr = NULL
+
+// PyObject_HEAD_INIT_TYPE and PyObject_FINISH_INIT_TYPE need to come in pairs
+// We first initialize with NULL because the type is not allocated until
+// init_types() is called later. It's in FINISH_INIT_TYPE where we fill the
+// type in with the newly allocated type.
+# define PyObject_HEAD_INIT_TYPE(type) PyObject_HEAD_INIT(NULL)
+# define PyObject_FINISH_INIT_TYPE(obj, type) obj.ob_base.ob_type = type##Ptr
+
+# define Py_TYPE_GET_TP_ALLOC(type) ((allocfunc)PyType_GetSlot(type, Py_tp_alloc))
+# define Py_TYPE_GET_TP_METHODS(type) ((PyMethodDef *)PyType_GetSlot(type, Py_tp_methods))
+
+// PyObject_NEW is not part of stable ABI, but PyObject_Malloc/Init are.
+PyObject* Vim_PyObject_New(PyTypeObject *type, size_t objsize)
+{
+    PyObject *obj = (PyObject *)PyObject_Malloc(objsize);
+    if (obj == NULL)
+        return PyErr_NoMemory();
+    return PyObject_Init(obj, type);
+}
+# undef PyObject_NEW
+# define PyObject_NEW(type, typeobj) ((type *)Vim_PyObject_New(typeobj, sizeof(type)))
+
+// This is a somewhat convoluted because limited API doesn't expose an easy way
+// to get the tp_name field, and so we have to manually reconstruct it as
+// "__module__.__name__" (with __module__ omitted for builtins to emulate
+// Python behavior). Also, some of the more convenient functions like
+// PyUnicode_AsUTF8AndSize and PyType_GetQualName() are not available until
+// late Python 3 versions, and won't be available if you set Py_LIMITED_API too
+// low.
+# define PyErr_FORMAT_TYPE(msg, obj) \
+    do { \
+	PyObject* qualname = PyObject_GetAttrString((PyObject*)(obj)->ob_type, "__qualname__"); \
+	if (qualname == NULL) \
+	{ \
+	    PyErr_FORMAT(PyExc_TypeError, msg, "(NULL)"); \
+	    break; \
+	} \
+	PyObject* module = PyObject_GetAttrString((PyObject*)(obj)->ob_type, "__module__"); \
+	PyObject* full; \
+	if (module == NULL || PyUnicode_CompareWithASCIIString(module, "builtins") == 0 \
+		|| PyUnicode_CompareWithASCIIString(module, "__main__") == 0) \
+	{ \
+	    full = qualname; \
+	    Py_INCREF(full); \
+	} \
+	else \
+	    full = PyUnicode_FromFormat("%U.%U", module, qualname); \
+	PyObject* full_bytes = PyUnicode_AsUTF8String(full); \
+	const char* full_str = PyBytes_AsString(full_bytes); \
+	full_str = full_str == NULL ? "(NULL)" : full_str; \
+	PyErr_FORMAT(PyExc_TypeError, msg, full_str); \
+	Py_DECREF(qualname); \
+	Py_XDECREF(module); \
+	Py_XDECREF(full); \
+	Py_XDECREF(full_bytes); \
+    } while(0)
+
+# define PyList_GET_ITEM(list, i) PyList_GetItem(list, i)
+# define PyList_GET_SIZE(o) PyList_Size(o)
+# define PyTuple_GET_ITEM(o, pos) PyTuple_GetItem(o, pos)
+# define PyTuple_GET_SIZE(o) PyTuple_Size(o)
+
+// PyList_SET_ITEM and PyList_SetItem have slightly different behaviors. The
+// former will leave the old item dangling, and the latter will decref on it.
+// Since we only use this on new lists, this difference doesn't matter.
+# define PyList_SET_ITEM(list, i, item) PyList_SetItem(list, i, item)
+
+# if Py_LIMITED_API < 0x03080000
+// PyIter_check only became part of stable ABI in 3.8, and there is no easy way
+// to check for it in the API. We simply return false as a compromise. This
+// does mean we should avoid compiling with stable ABI < 3.8.
+#  undef PyIter_Check
+#  define PyIter_Check(obj) (FALSE)
+# endif
+
+PyTypeObject* AddHeapType(struct typeobject_wrapper* type_object)
+{
+    PyType_Spec type_spec;
+    type_spec.name = type_object->tp_name;
+    type_spec.basicsize = type_object->tp_basicsize;
+    type_spec.itemsize = 0;
+    type_spec.flags = type_object->tp_flags;
+
+    // We just need to statically allocate a large enough buffer that can hold
+    // all slots. We need to leave a null-terminated slot at the end.
+    PyType_Slot slots[40] = { {0, NULL} };
+    size_t slot_i = 0;
+
+# define ADD_TP_SLOT(slot_name) \
+    if (slot_i >= 40) return NULL; /* this should never happen */ \
+    if (type_object->slot_name != NULL) \
+    { \
+	slots[slot_i].slot = Py_##slot_name; \
+	slots[slot_i].pfunc = (void*)type_object->slot_name; \
+	++slot_i; \
+    }
+# define ADD_TP_SUB_SLOT(sub_slot, slot_name) \
+    if (slot_i >= 40) return NULL; /* this should never happen */ \
+    if (type_object->sub_slot != NULL && type_object->sub_slot->slot_name != NULL) \
+    { \
+	slots[slot_i].slot = Py_##slot_name; \
+	slots[slot_i].pfunc = (void*)type_object->sub_slot->slot_name; \
+	++slot_i; \
+    }
+
+    ADD_TP_SLOT(tp_dealloc)
+    ADD_TP_SLOT(tp_repr)
+    ADD_TP_SLOT(tp_call)
+    ADD_TP_SLOT(tp_getattro)
+    ADD_TP_SLOT(tp_setattro)
+    ADD_TP_SLOT(tp_doc)
+    ADD_TP_SLOT(tp_traverse)
+    ADD_TP_SLOT(tp_clear)
+    ADD_TP_SLOT(tp_iter)
+    ADD_TP_SLOT(tp_iternext)
+    ADD_TP_SLOT(tp_methods)
+    ADD_TP_SLOT(tp_base)
+    ADD_TP_SLOT(tp_alloc)
+    ADD_TP_SLOT(tp_new)
+    ADD_TP_SLOT(tp_free)
+
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_length)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_concat)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_repeat)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_item)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_ass_item)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_contains)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_inplace_concat)
+    ADD_TP_SUB_SLOT(tp_as_sequence, sq_inplace_repeat)
+
+    ADD_TP_SUB_SLOT(tp_as_mapping, mp_length)
+    ADD_TP_SUB_SLOT(tp_as_mapping, mp_subscript)
+    ADD_TP_SUB_SLOT(tp_as_mapping, mp_ass_subscript)
+# undef ADD_TP_SLOT
+# undef ADD_TP_SUB_SLOT
+
+    type_spec.slots = slots;
+
+    PyObject* newtype = PyType_FromSpec(&type_spec);
+    return (PyTypeObject*)newtype;
+}
+
+// Add a heap type, since static types do not work in limited API
+// Each PYTYPE_READY is paired with PYTYPE_CLEANUP.
+//
+// Note that we don't call Py_DECREF(type##Ptr) in clean up. The reason for
+// that in 3.7, it's possible to de-allocate a heap type before all instances
+// are cleared, leading to a crash, whereas in 3.8 the semantics were changed
+// and instances hold strong references to types. Since these types are
+// designed to be static, just keep them around to avoid having to write
+// version-specific handling. Vim does not re-start the Python runtime so there
+// will be no long-term leak.
+# define PYTYPE_READY(type) \
+    type##Ptr = AddHeapType(&(type)); \
+    if (type##Ptr == NULL) \
+	return -1;
+# define PYTYPE_CLEANUP(type) \
+    type##Ptr = NULL;
+
+// Limited API does not provide PyRun_* functions. Need to implement manually
+// using PyCompile and PyEval.
+PyObject* Vim_PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals)
+{
+    // Just pass "" for filename for now.
+    PyObject* compiled = Py_CompileString(str, "", start);
+    if (compiled == NULL)
+	return NULL;
+
+    PyObject* eval_result = PyEval_EvalCode(compiled, globals, locals);
+    Py_DECREF(compiled);
+    return eval_result;
+}
+int Vim_PyRun_SimpleString(const char *str)
+{
+    // This function emulates CPython's implementation.
+    PyObject* m = PyImport_AddModule("__main__");
+    if (m == NULL)
+        return -1;
+    PyObject* d = PyModule_GetDict(m);
+    PyObject* output = Vim_PyRun_String(str, Py_file_input, d, d);
+    if (output == NULL)
+    {
+	PyErr_PrintEx(TRUE);
+	return -1;
+    }
+    Py_DECREF(output);
+    return 0;
+}
+#define PyRun_String Vim_PyRun_String
+#define PyRun_SimpleString Vim_PyRun_SimpleString
+
+#else // !defined(USE_LIMITED_API)
+
+// Full Python API. Can make use of structs and macros directly.
+# define DEFINE_PY_TYPE_OBJECT(type) \
+    static PyTypeObject type; \
+    static PyTypeObject* type##Ptr = &type
+# define PyObject_HEAD_INIT_TYPE(type) PyObject_HEAD_INIT(&type)
+
+# define Py_TYPE_GET_TP_ALLOC(type) type->tp_alloc
+# define Py_TYPE_GET_TP_METHODS(type) type->tp_methods
+
+# define Py_TYPE_NAME(obj) ((obj)->ob_type->tp_name == NULL \
 	? "(NULL)" \
 	: (obj)->ob_type->tp_name)
+# define PyErr_FORMAT_TYPE(msg, obj) \
+    PyErr_FORMAT(PyExc_TypeError, msg, \
+	    Py_TYPE_NAME(obj))
+
+// Add a static type
+# define PYTYPE_READY(type) \
+    if (PyType_Ready(type##Ptr)) \
+	return -1;
+
+#endif
+
 
 #define RAISE_NO_EMPTY_KEYS PyErr_SET_STRING(PyExc_ValueError, \
 					    N_("empty keys are not allowed"))
@@ -45,8 +321,7 @@ static const char *vim_special_path = "_
 #define RAISE_KEY_ADD_FAIL(key) \
     PyErr_VIM_FORMAT(N_("failed to add key '%s' to dictionary"), key)
 #define RAISE_INVALID_INDEX_TYPE(idx) \
-    PyErr_FORMAT(PyExc_TypeError, N_("index must be int or slice, not %s"), \
-	    Py_TYPE_NAME(idx));
+    PyErr_FORMAT_TYPE(N_("index must be int or slice, not %s"), idx);
 
 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
@@ -144,13 +419,11 @@ StringToChars(PyObject *obj, PyObject **
     else
     {
 #if PY_MAJOR_VERSION < 3
-	PyErr_FORMAT(PyExc_TypeError,
-		N_("expected str() or unicode() instance, but got %s"),
-		Py_TYPE_NAME(obj));
+	PyErr_FORMAT_TYPE(N_("expected str() or unicode() instance, but got %s"),
+		obj);
 #else
-	PyErr_FORMAT(PyExc_TypeError,
-		N_("expected bytes() or str() instance, but got %s"),
-		Py_TYPE_NAME(obj));
+	PyErr_FORMAT_TYPE(N_("expected bytes() or str() instance, but got %s"),
+		obj);
 #endif
 	return NULL;
     }
@@ -198,15 +471,15 @@ NumberToLong(PyObject *obj, long *result
     else
     {
 #if PY_MAJOR_VERSION < 3
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("expected int(), long() or something supporting "
 		   "coercing to long(), but got %s"),
-		Py_TYPE_NAME(obj));
+		obj);
 #else
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("expected int() or something supporting coercing to int(), "
 		   "but got %s"),
-		Py_TYPE_NAME(obj));
+		obj);
 #endif
 	return -1;
     }
@@ -278,7 +551,7 @@ ObjectDir(PyObject *self, char **attribu
 	return NULL;
 
     if (self)
-	for (method = self->ob_type->tp_methods ; method->ml_name != NULL ; ++method)
+	for (method = Py_TYPE_GET_TP_METHODS(self->ob_type) ; method->ml_name != NULL ; ++method)
 	    if (add_string(ret, (char *)method->ml_name))
 	    {
 		Py_DECREF(ret);
@@ -308,7 +581,7 @@ ObjectDir(PyObject *self, char **attribu
 // Function to write a line, points to either msg() or emsg().
 typedef int (*writefn)(char *);
 
-static PyTypeObject OutputType;
+DEFINE_PY_TYPE_OBJECT(OutputType);
 
 typedef struct
 {
@@ -514,14 +787,14 @@ static struct PyMethodDef OutputMethods[
 
 static OutputObject Output =
 {
-    PyObject_HEAD_INIT(&OutputType)
+    PyObject_HEAD_INIT_TYPE(OutputType)
     0,
     0
 };
 
 static OutputObject Error =
 {
-    PyObject_HEAD_INIT(&OutputType)
+    PyObject_HEAD_INIT_TYPE(OutputType)
     0,
     1
 };
@@ -552,7 +825,7 @@ typedef struct
     char	*fullname;
     PyObject	*result;
 } LoaderObject;
-static PyTypeObject LoaderType;
+DEFINE_PY_TYPE_OBJECT(LoaderType);
 
     static void
 LoaderDestructor(LoaderObject *self)
@@ -1243,9 +1516,9 @@ call_load_module(char *name, int len, Py
 
     if (!PyTuple_Check(find_module_result))
     {
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("expected 3-tuple as imp.find_module() result, but got %s"),
-		Py_TYPE_NAME(find_module_result));
+		find_module_result);
 	return NULL;
     }
     if (PyTuple_GET_SIZE(find_module_result) != 3)
@@ -1367,7 +1640,7 @@ FinderFindModule(PyObject *self, PyObjec
 	return NULL;
     }
 
-    if (!(loader = PyObject_NEW(LoaderObject, &LoaderType)))
+    if (!(loader = PyObject_NEW(LoaderObject, LoaderTypePtr)))
     {
 	vim_free(fullname);
 	Py_DECREF(result);
@@ -1424,7 +1697,7 @@ static struct PyMethodDef VimMethods[] =
  * Generic iterator object
  */
 
-static PyTypeObject IterType;
+DEFINE_PY_TYPE_OBJECT(IterType);
 
 typedef PyObject *(*nextfun)(void **);
 typedef void (*destructorfun)(void *);
@@ -1451,7 +1724,7 @@ IterNew(void *start, destructorfun destr
 {
     IterObject *self;
 
-    self = PyObject_GC_New(IterObject, &IterType);
+    self = PyObject_GC_New(IterObject, IterTypePtr);
     self->cur = start;
     self->next = next;
     self->destruct = destruct;
@@ -1556,7 +1829,7 @@ pyll_add(PyObject *self, pylinkedlist_T 
     *last = ref;
 }
 
-static PyTypeObject DictionaryType;
+DEFINE_PY_TYPE_OBJECT(DictionaryType);
 
 typedef struct
 {
@@ -1567,14 +1840,14 @@ typedef struct
 
 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *);
 
-#define NEW_DICTIONARY(dict) DictionaryNew(&DictionaryType, dict)
+#define NEW_DICTIONARY(dict) DictionaryNew(DictionaryTypePtr, dict)
 
     static PyObject *
 DictionaryNew(PyTypeObject *subtype, dict_T *dict)
 {
     DictionaryObject	*self;
 
-    self = (DictionaryObject *) subtype->tp_alloc(subtype, 0);
+    self = (DictionaryObject *) Py_TYPE_GET_TP_ALLOC(subtype)(subtype, 0);
     if (self == NULL)
 	return NULL;
     self->dict = dict;
@@ -2238,7 +2511,7 @@ static struct PyMethodDef DictionaryMeth
     { NULL,	NULL,					0,		NULL}
 };
 
-static PyTypeObject ListType;
+DEFINE_PY_TYPE_OBJECT(ListType);
 
 typedef struct
 {
@@ -2247,7 +2520,7 @@ typedef struct
     pylinkedlist_T	ref;
 } ListObject;
 
-#define NEW_LIST(list) ListNew(&ListType, list)
+#define NEW_LIST(list) ListNew(ListTypePtr, list)
 
     static PyObject *
 ListNew(PyTypeObject *subtype, list_T *list)
@@ -2257,7 +2530,7 @@ ListNew(PyTypeObject *subtype, list_T *l
     if (list == NULL)
 	return NULL;
 
-    self = (ListObject *) subtype->tp_alloc(subtype, 0);
+    self = (ListObject *) Py_TYPE_GET_TP_ALLOC(subtype)(subtype, 0);
     if (self == NULL)
 	return NULL;
     self->list = list;
@@ -2937,10 +3210,10 @@ typedef struct
     int		auto_rebind;
 } FunctionObject;
 
-static PyTypeObject FunctionType;
+DEFINE_PY_TYPE_OBJECT(FunctionType);
 
 #define NEW_FUNCTION(name, argc, argv, self, pt_auto) \
-    FunctionNew(&FunctionType, (name), (argc), (argv), (self), (pt_auto))
+    FunctionNew(FunctionTypePtr, (name), (argc), (argv), (self), (pt_auto))
 
     static PyObject *
 FunctionNew(PyTypeObject *subtype, char_u *name, int argc, typval_T *argv,
@@ -2948,7 +3221,7 @@ FunctionNew(PyTypeObject *subtype, char_
 {
     FunctionObject	*self;
 
-    self = (FunctionObject *)subtype->tp_alloc(subtype, 0);
+    self = (FunctionObject *) Py_TYPE_GET_TP_ALLOC(subtype)(subtype, 0);
     if (self == NULL)
 	return NULL;
 
@@ -3311,7 +3584,7 @@ static struct PyMethodDef FunctionMethod
  * Options object
  */
 
-static PyTypeObject OptionsType;
+DEFINE_PY_TYPE_OBJECT(OptionsType);
 
 typedef int (*checkfun)(void *);
 
@@ -3335,7 +3608,7 @@ OptionsNew(int opt_type, void *from, che
 {
     OptionsObject	*self;
 
-    self = PyObject_GC_New(OptionsObject, &OptionsType);
+    self = PyObject_GC_New(OptionsObject, OptionsTypePtr);
     if (self == NULL)
 	return NULL;
 
@@ -3692,7 +3965,7 @@ typedef struct
 
 static PyObject *WinListNew(TabPageObject *tabObject);
 
-static PyTypeObject TabPageType;
+DEFINE_PY_TYPE_OBJECT(TabPageType);
 
     static int
 CheckTabPage(TabPageObject *self)
@@ -3718,7 +3991,7 @@ TabPageNew(tabpage_T *tab)
     }
     else
     {
-	self = PyObject_NEW(TabPageObject, &TabPageType);
+	self = PyObject_NEW(TabPageObject, TabPageTypePtr);
 	if (self == NULL)
 	    return NULL;
 	self->tab = tab;
@@ -3810,7 +4083,7 @@ static struct PyMethodDef TabPageMethods
  * Window list object
  */
 
-static PyTypeObject TabListType;
+DEFINE_PY_TYPE_OBJECT(TabListType);
 static PySequenceMethods TabListAsSeq;
 
 typedef struct
@@ -3818,6 +4091,11 @@ typedef struct
     PyObject_HEAD
 } TabListObject;
 
+static TabListObject TheTabPageList =
+{
+    PyObject_HEAD_INIT_TYPE(TabListType)
+};
+
     static PyInt
 TabListLength(PyObject *self UNUSED)
 {
@@ -3857,7 +4135,7 @@ typedef struct
     TabPageObject	*tabObject;
 } WindowObject;
 
-static PyTypeObject WindowType;
+DEFINE_PY_TYPE_OBJECT(WindowType);
 
     static int
 CheckWindow(WindowObject *self)
@@ -3899,7 +4177,7 @@ WindowNew(win_T *win, tabpage_T *tab)
     }
     else
     {
-	self = PyObject_GC_New(WindowObject, &WindowType);
+	self = PyObject_GC_New(WindowObject, WindowTypePtr);
 	if (self == NULL)
 	    return NULL;
 	self->win = win;
@@ -4150,7 +4428,7 @@ static struct PyMethodDef WindowMethods[
  * Window list object
  */
 
-static PyTypeObject WinListType;
+DEFINE_PY_TYPE_OBJECT(WinListType);
 static PySequenceMethods WinListAsSeq;
 
 typedef struct
@@ -4159,12 +4437,18 @@ typedef struct
     TabPageObject	*tabObject;
 } WinListObject;
 
+static WinListObject TheWindowList =
+{
+    PyObject_HEAD_INIT_TYPE(WinListType)
+    NULL
+};
+
     static PyObject *
 WinListNew(TabPageObject *tabObject)
 {
     WinListObject	*self;
 
-    self = PyObject_NEW(WinListObject, &WinListType);
+    self = PyObject_NEW(WinListObject, WinListTypePtr);
     self->tabObject = tabObject;
     Py_INCREF(tabObject);
 
@@ -4259,13 +4543,13 @@ StringToLine(PyObject *obj)
     else
     {
 #if PY_MAJOR_VERSION < 3
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("expected str() or unicode() instance, but got %s"),
-		Py_TYPE_NAME(obj));
+		obj);
 #else
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("expected bytes() or str() instance, but got %s"),
-		Py_TYPE_NAME(obj));
+		obj);
 #endif
 	return NULL;
     }
@@ -5028,7 +5312,7 @@ RBAppend(
 
 // Range object
 
-static PyTypeObject RangeType;
+DEFINE_PY_TYPE_OBJECT(RangeType);
 static PySequenceMethods RangeAsSeq;
 static PyMappingMethods RangeAsMapping;
 
@@ -5045,7 +5329,7 @@ RangeNew(buf_T *buf, PyInt start, PyInt 
 {
     BufferObject *bufr;
     RangeObject *self;
-    self = PyObject_GC_New(RangeObject, &RangeType);
+    self = PyObject_GC_New(RangeObject, RangeTypePtr);
     if (self == NULL)
 	return NULL;
 
@@ -5150,7 +5434,7 @@ static struct PyMethodDef RangeMethods[]
     { NULL,	NULL,				0,		NULL}
 };
 
-static PyTypeObject BufferType;
+DEFINE_PY_TYPE_OBJECT(BufferType);
 static PySequenceMethods BufferAsSeq;
 static PyMappingMethods BufferAsMapping;
 
@@ -5184,7 +5468,7 @@ BufferNew(buf_T *buf)
     }
     else
     {
-	self = PyObject_NEW(BufferObject, &BufferType);
+	self = PyObject_NEW(BufferObject, BufferTypePtr);
 	if (self == NULL)
 	    return NULL;
 	self->buf = buf;
@@ -5410,13 +5694,18 @@ static struct PyMethodDef BufferMethods[
  * Buffer list object - Implementation
  */
 
-static PyTypeObject BufMapType;
+DEFINE_PY_TYPE_OBJECT(BufMapType);
 
 typedef struct
 {
     PyObject_HEAD
 } BufMapObject;
 
+static BufMapObject TheBufferMap =
+{
+    PyObject_HEAD_INIT_TYPE(BufMapType)
+};
+
     static PyInt
 BufMapLength(PyObject *self UNUSED)
 {
@@ -5574,11 +5863,11 @@ CurrentSetattr(PyObject *self UNUSED, ch
     {
 	int count;
 
-	if (valObject->ob_type != &BufferType)
+	if (valObject->ob_type != BufferTypePtr)
 	{
-	    PyErr_FORMAT(PyExc_TypeError,
+	    PyErr_FORMAT_TYPE(
 		    N_("expected vim.Buffer object, but got %s"),
-		    Py_TYPE_NAME(valObject));
+		    valObject);
 	    return -1;
 	}
 
@@ -5601,11 +5890,11 @@ CurrentSetattr(PyObject *self UNUSED, ch
     {
 	int count;
 
-	if (valObject->ob_type != &WindowType)
+	if (valObject->ob_type != WindowTypePtr)
 	{
-	    PyErr_FORMAT(PyExc_TypeError,
+	    PyErr_FORMAT_TYPE(
 		    N_("expected vim.Window object, but got %s"),
-		    Py_TYPE_NAME(valObject));
+		    valObject);
 	    return -1;
 	}
 
@@ -5635,11 +5924,11 @@ CurrentSetattr(PyObject *self UNUSED, ch
     }
     else if (strcmp(name, "tabpage") == 0)
     {
-	if (valObject->ob_type != &TabPageType)
+	if (valObject->ob_type != TabPageTypePtr)
 	{
-	    PyErr_FORMAT(PyExc_TypeError,
+	    PyErr_FORMAT_TYPE(
 		    N_("expected vim.TabPage object, but got %s"),
-		    Py_TYPE_NAME(valObject));
+		    valObject);
 	    return -1;
 	}
 
@@ -6180,7 +6469,7 @@ ConvertFromPyMapping(PyObject *obj, typv
     if (!(lookup_dict = PyDict_New()))
 	return -1;
 
-    if (PyType_IsSubtype(obj->ob_type, &DictionaryType))
+    if (PyType_IsSubtype(obj->ob_type, DictionaryTypePtr))
     {
 	tv->v_type = VAR_DICT;
 	tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
@@ -6193,9 +6482,9 @@ ConvertFromPyMapping(PyObject *obj, typv
 	ret = convert_dl(obj, tv, pymap_to_tv, lookup_dict);
     else
     {
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("unable to convert %s to a Vim dictionary"),
-		Py_TYPE_NAME(obj));
+		obj);
 	ret = -1;
     }
     Py_DECREF(lookup_dict);
@@ -6211,7 +6500,7 @@ ConvertFromPySequence(PyObject *obj, typ
     if (!(lookup_dict = PyDict_New()))
 	return -1;
 
-    if (PyType_IsSubtype(obj->ob_type, &ListType))
+    if (PyType_IsSubtype(obj->ob_type, ListTypePtr))
     {
 	tv->v_type = VAR_LIST;
 	tv->vval.v_list = (((ListObject *)(obj))->list);
@@ -6222,9 +6511,9 @@ ConvertFromPySequence(PyObject *obj, typ
 	ret = convert_dl(obj, tv, pyseq_to_tv, lookup_dict);
     else
     {
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("unable to convert %s to a Vim list"),
-		Py_TYPE_NAME(obj));
+		obj);
 	ret = -1;
     }
     Py_DECREF(lookup_dict);
@@ -6247,19 +6536,19 @@ ConvertFromPyObject(PyObject *obj, typva
     static int
 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
 {
-    if (PyType_IsSubtype(obj->ob_type, &DictionaryType))
+    if (PyType_IsSubtype(obj->ob_type, DictionaryTypePtr))
     {
 	tv->v_type = VAR_DICT;
 	tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
 	++tv->vval.v_dict->dv_refcount;
     }
-    else if (PyType_IsSubtype(obj->ob_type, &ListType))
+    else if (PyType_IsSubtype(obj->ob_type, ListTypePtr))
     {
 	tv->v_type = VAR_LIST;
 	tv->vval.v_list = (((ListObject *)(obj))->list);
 	++tv->vval.v_list->lv_refcount;
     }
-    else if (PyType_IsSubtype(obj->ob_type, &FunctionType))
+    else if (PyType_IsSubtype(obj->ob_type, FunctionTypePtr))
     {
 	FunctionObject *func = (FunctionObject *) obj;
 	if (func->self != NULL || func->argv != NULL)
@@ -6365,9 +6654,9 @@ ConvertFromPyObject(PyObject *obj, typva
     }
     else
     {
-	PyErr_FORMAT(PyExc_TypeError,
+	PyErr_FORMAT_TYPE(
 		N_("unable to convert %s to a Vim structure"),
-		Py_TYPE_NAME(obj));
+		obj);
 	return -1;
     }
     return 0;
@@ -6445,11 +6734,17 @@ ConvertToPyObject(typval_T *tv)
     return NULL;
 }
 
+DEFINE_PY_TYPE_OBJECT(CurrentType);
+
 typedef struct
 {
     PyObject_HEAD
 } CurrentObject;
-static PyTypeObject CurrentType;
+
+static CurrentObject TheCurrent =
+{
+    PyObject_HEAD_INIT_TYPE(CurrentType)
+};
 
     static void
 init_structs(void)
@@ -6466,7 +6761,11 @@ init_structs(void)
     OutputType.tp_alloc = call_PyType_GenericAlloc;
     OutputType.tp_new = call_PyType_GenericNew;
     OutputType.tp_free = call_PyObject_Free;
+# ifndef USE_LIMITED_API
+    // The std printer type is only exposed in full API. It is not essential
+    // anyway and so in limited API we don't set it.
     OutputType.tp_base = &PyStdPrinter_Type;
+# endif
 #else
     OutputType.tp_getattr = (getattrfunc)OutputGetattr;
     OutputType.tp_setattr = (setattrfunc)OutputSetattr;
@@ -6487,7 +6786,7 @@ init_structs(void)
 
     CLEAR_FIELD(BufferType);
     BufferType.tp_name = "vim.buffer";
-    BufferType.tp_basicsize = sizeof(BufferType);
+    BufferType.tp_basicsize = sizeof(BufferObject);
     BufferType.tp_dealloc = (destructor)BufferDestructor;
     BufferType.tp_repr = (reprfunc)BufferRepr;
     BufferType.tp_as_sequence = &BufferAsSeq;
@@ -6550,11 +6849,11 @@ init_structs(void)
     BufMapType.tp_as_mapping = &BufMapAsMapping;
     BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
     BufMapType.tp_iter = BufMapIter;
-    BufferType.tp_doc = "vim buffer list";
+    BufMapType.tp_doc = "vim buffer list";
 
     CLEAR_FIELD(WinListType);
     WinListType.tp_name = "vim.windowlist";
-    WinListType.tp_basicsize = sizeof(WinListType);
+    WinListType.tp_basicsize = sizeof(WinListObject);
     WinListType.tp_as_sequence = &WinListAsSeq;
     WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
     WinListType.tp_doc = "vim window list";
@@ -6562,7 +6861,7 @@ init_structs(void)
 
     CLEAR_FIELD(TabListType);
     TabListType.tp_name = "vim.tabpagelist";
-    TabListType.tp_basicsize = sizeof(TabListType);
+    TabListType.tp_basicsize = sizeof(TabListObject);
     TabListType.tp_as_sequence = &TabListAsSeq;
     TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
     TabListType.tp_doc = "vim tab page list";
@@ -6690,10 +6989,6 @@ init_structs(void)
 #endif
 }
 
-#define PYTYPE_READY(type) \
-    if (PyType_Ready(&(type))) \
-	return -1;
-
     static int
 init_types(void)
 {
@@ -6714,9 +7009,46 @@ init_types(void)
 #if PY_VERSION_HEX < 0x030700f0
     PYTYPE_READY(LoaderType);
 #endif
+
+#ifdef USE_LIMITED_API
+    // We need to finish initializing all the static objects because the types
+    // are only just allocated on the heap now.
+    // Each PyObject_HEAD_INIT_TYPE should correspond to a
+    // PyObject_FINISH_INIT_TYPE below.
+    PyObject_FINISH_INIT_TYPE(Output, OutputType);
+    PyObject_FINISH_INIT_TYPE(Error, OutputType);
+    PyObject_FINISH_INIT_TYPE(TheBufferMap, BufMapType);
+    PyObject_FINISH_INIT_TYPE(TheWindowList, WinListType);
+    PyObject_FINISH_INIT_TYPE(TheCurrent, CurrentType);
+    PyObject_FINISH_INIT_TYPE(TheTabPageList, TabListType);
+#endif
     return 0;
 }
 
+#ifdef USE_LIMITED_API
+    static void
+shutdown_types(void)
+{
+    PYTYPE_CLEANUP(IterType);
+    PYTYPE_CLEANUP(BufferType);
+    PYTYPE_CLEANUP(RangeType);
+    PYTYPE_CLEANUP(WindowType);
+    PYTYPE_CLEANUP(TabPageType);
+    PYTYPE_CLEANUP(BufMapType);
+    PYTYPE_CLEANUP(WinListType);
+    PYTYPE_CLEANUP(TabListType);
+    PYTYPE_CLEANUP(CurrentType);
+    PYTYPE_CLEANUP(DictionaryType);
+    PYTYPE_CLEANUP(ListType);
+    PYTYPE_CLEANUP(FunctionType);
+    PYTYPE_CLEANUP(OptionsType);
+    PYTYPE_CLEANUP(OutputType);
+# if PY_VERSION_HEX < 0x030700f0
+    PYTYPE_CLEANUP(LoaderType);
+# endif
+}
+#endif
+
     static int
 init_sys_path(void)
 {
@@ -6789,27 +7121,6 @@ init_sys_path(void)
     return 0;
 }
 
-static BufMapObject TheBufferMap =
-{
-    PyObject_HEAD_INIT(&BufMapType)
-};
-
-static WinListObject TheWindowList =
-{
-    PyObject_HEAD_INIT(&WinListType)
-    NULL
-};
-
-static CurrentObject TheCurrent =
-{
-    PyObject_HEAD_INIT(&CurrentType)
-};
-
-static TabListObject TheTabPageList =
-{
-    PyObject_HEAD_INIT(&TabListType)
-};
-
 static struct numeric_constant {
     char	*name;
     int		val;
@@ -6820,26 +7131,9 @@ static struct numeric_constant {
     {"VAR_DEF_SCOPE",	VAR_DEF_SCOPE},
 };
 
-static struct object_constant {
+struct object_constant {
     char	*name;
     PyObject	*valObject;
-} object_constants[] = {
-    {"buffers",  (PyObject *)(void *)&TheBufferMap},
-    {"windows",  (PyObject *)(void *)&TheWindowList},
-    {"tabpages", (PyObject *)(void *)&TheTabPageList},
-    {"current",  (PyObject *)(void *)&TheCurrent},
-
-    {"Buffer",     (PyObject *)&BufferType},
-    {"Range",      (PyObject *)&RangeType},
-    {"Window",     (PyObject *)&WindowType},
-    {"TabPage",    (PyObject *)&TabPageType},
-    {"Dictionary", (PyObject *)&DictionaryType},
-    {"List",       (PyObject *)&ListType},
-    {"Function",   (PyObject *)&FunctionType},
-    {"Options",    (PyObject *)&OptionsType},
-#if PY_VERSION_HEX < 0x030700f0
-    {"_Loader",    (PyObject *)&LoaderType},
-#endif
 };
 
 #define ADD_OBJECT(m, name, obj) \
@@ -6872,6 +7166,25 @@ populate_module(PyObject *m)
 	ADD_CHECKED_OBJECT(m, numeric_constants[i].name,
 		PyInt_FromLong(numeric_constants[i].val));
 
+    struct object_constant object_constants[] = {
+	{"buffers",  (PyObject *)(void *)&TheBufferMap},
+	{"windows",  (PyObject *)(void *)&TheWindowList},
+	{"tabpages", (PyObject *)(void *)&TheTabPageList},
+	{"current",  (PyObject *)(void *)&TheCurrent},
+
+	{"Buffer",     (PyObject *)BufferTypePtr},
+	{"Range",      (PyObject *)RangeTypePtr},
+	{"Window",     (PyObject *)WindowTypePtr},
+	{"TabPage",    (PyObject *)TabPageTypePtr},
+	{"Dictionary", (PyObject *)DictionaryTypePtr},
+	{"List",       (PyObject *)ListTypePtr},
+	{"Function",   (PyObject *)FunctionTypePtr},
+	{"Options",    (PyObject *)OptionsTypePtr},
+#if PY_VERSION_HEX < 0x030700f0
+	{"_Loader",    (PyObject *)LoaderTypePtr},
+#endif
+    };
+
     for (i = 0; i < (int)(sizeof(object_constants)
 					    / sizeof(struct object_constant));
 	    ++i)
index e4d4a90ed0ee29f79bceb8d581f9174f6596c316..9d44b7a196fb57ab65afc931a6bc5e53ed0f8370
GIT binary patch
literal 65228
zc%1Ehe|H-<lHmO-eF}uRwVN_U%XW5N#*V#@rYM^miPDOaootfVuSGVcj>&FLcT*B~
z*5CcA3cu0lCS@nHbMG#1MwZZ3g+ifFRR9XW(>->Zye#69mBs7tSph%4W5pf(NVB+n
zxy$z8f9%8Xgzd8r2^*d)^XxXBGWhRm&EDqGf}Ld9JWiu17r=)ZYrVXQ=S#M_j?!t=
zV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0x-`VTNetd>ox<rqT=~)$k*SGTTku#6`szrti@08em2ZC9T*VToO)LZ@O)`ZS3Goy
z{%>?KHXR<27s3L6cTt`O>TLRWUEqy2J%A6M(do=vYxM&U!HE=U<4TV{U3?HcQuokX
zk4IKHqZ1U_a)lQS333Kye`{2ep*<lAx2DyiM3eiPbn%)D^6$FrvP|Ylxi(&w#FTNm
z3Y4Emi?wZ12hQa2H?9+1HHVOQjuQZ;1RyT-l{}jvjuRtnZ!U};TE8^DLufkcChu~i
z`@!f<Zhc2OVj}XXyfvX?p1@O=yzuAG5_}}H<d?(KnM=}c6ly%J+%#rICuw|<$rHZD
z*+k<Wa%15wE>`nW9ri7(>#W4FW_`~%CsZz$9Xi^`$Nplep2gPpZ{rs%hp)!PkCnIm
zxN{n1Cv=-tP_re$jifmLMa>ZCbe@V1X5(?HR34|=TQYvU>XkeXrAqhc#)I9RCr^Mc
z_^B>H;A`OqrqE&(kMG<!34z}A-s-3~H_-CvDj+-4HPH>GC7)(^_$da{rcT(?A#kuY
zc;Uwdc3xTDs=18kv=jE=R)@4=zFElujZ<1?xjd%DYc-+_{Coe+t;(qX&^r$=M?a2E
zKaNySIY0z6x;%M1IDe%-LS^0CFr^!F`Q_QXXFkh&A<A96FDs8{#;s6v+aca-Fg$cN
pY%SP8fV?uPNoOgZnhwOJ8@?;84Z8O86y~!=62Q7f%6Qx8{{W`x(?|dS
--- a/src/proto/if_python3.pro
+++ b/src/proto/if_python3.pro
@@ -10,4 +10,5 @@ void python3_window_free(win_T *win);
 void python3_tabpage_free(tabpage_T *tab);
 void do_py3eval(char_u *str, typval_T *rettv);
 int set_ref_in_python3(int copyID);
+int python3_version();
 /* vim: set ft=c : */
--- a/src/version.c
+++ b/src/version.c
@@ -474,7 +474,11 @@ static char *(features[]) =
 #endif
 #ifdef FEAT_PYTHON3
 # ifdef DYNAMIC_PYTHON3
+#  ifdef DYNAMIC_PYTHON3_STABLE_ABI
+	"+python3/dyn-stable",
+#  else
 	"+python3/dyn",
+#  endif
 # else
 	"+python3",
 # endif
@@ -696,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1776,
+/**/
     1775,
 /**/
     1772,
--- a/src/vim.h
+++ b/src/vim.h
@@ -2130,7 +2130,8 @@ typedef int sock_T;
 #define VV_SIZEOFLONG	103
 #define VV_SIZEOFPOINTER 104
 #define VV_MAXCOL	105
-#define VV_LEN		106	// number of v: vars
+#define VV_PYTHON3_VERSION 106
+#define VV_LEN		107	// number of v: vars
 
 // used for v_number in VAR_BOOL and VAR_SPECIAL
 #define VVAL_FALSE	0L	// VAR_BOOL