# HG changeset patch # User Christian Brabandt # Date 1692559804 -7200 # Node ID c517845bd10e7e5f69b2c3b2c9889235ec52c938 # Parent e437712960317ae6d1cc7a6509b5785f206720ad patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin 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 Co-authored-by: Yee Cheng Chin diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml --- 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 diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt --- 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. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- 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 diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt --- 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. diff --git a/runtime/doc/tags b/runtime/doc/tags --- 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* diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt --- 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 diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak --- 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 diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak --- 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" diff --git a/src/auto/configure b/src/auto/configure --- 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 \".\"" "$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}\\\"" diff --git a/src/config.h.in b/src/config.h.in --- 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 diff --git a/src/configure.ac b/src/configure.ac --- 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 "."]) + 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}\\\"" diff --git a/src/evalfunc.c b/src/evalfunc.c --- 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 diff --git a/src/evalvars.c b/src/evalvars.c --- 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); diff --git a/src/if_py_both.h b/src/if_py_both.h --- 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) diff --git a/src/if_python3.c b/src/if_python3.c index e4d4a90ed0ee29f79bceb8d581f9174f6596c316..9d44b7a196fb57ab65afc931a6bc5e53ed0f8370 GIT binary patch literal 65228 zc%1Ehe|H-&FLcT*B~ z*5CcA3cu0lCS@nHbMG#1MwZZ3g+ifFRR9XW(>->Zye#69mBs7tSph%4W5pf(NVB+n zxy$z8f9%8Xgzd8r2^*d)^XxXBGWhRm&EDqGf}Ld9JWiu17r=)ZYrVXQ=S#M_j?!t= zVk}7kdBMtz<#9A+lWe(8(rX4^*{X=HV<<_dNttA6(X~lT@)$l8ErUc6$1Gy=q$pW7 zW6L;O&SQ3WlOd5ZPp(#FJS8e)06ZV`4o?Q%^1fuVEQcByu%F*1@f{+UH!)EyvQ<7o zE~YVJKHYsvEje44H(AQ!`!Y@oWDeVW7Om#k=A1xT|0YVWmNE)G@E2wN$ zE>|V=7>IQ7lHKJ=32cbc+azMY#J??y>!3|+zUZ>y0tB^)(=tLqo6TQj(-p`No4|=9 z#&=zIStj$OT(j9Kolxfx2sC&)$L>RP;&m2*@UG(WE{=IGVaIYxT%1Cl=h>XTtbm6E z8u$F*;IB`Mcv(Ju_7{>tZyGH*dj<9MYPrnvl3iux4O= zVDo@4kaRKw)dEGmO8^%+oyJ$IYX+TPh}Lrwi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