view runtime/doc/usr_toc.txt @ 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 f8116058ca76
children 4635e43f2c6f
line wrap: on
line source

*usr_toc.txt*	For Vim version 9.0.  Last change: 2022 Jun 20

		     VIM USER MANUAL - by Bram Moolenaar

			      Table Of Contents			*user-manual*

==============================================================================
Overview ~

Getting Started ~
|usr_01.txt|  About the manuals
|usr_02.txt|  The first steps in Vim
|usr_03.txt|  Moving around
|usr_04.txt|  Making small changes
|usr_05.txt|  Set your settings
|usr_06.txt|  Using syntax highlighting
|usr_07.txt|  Editing more than one file
|usr_08.txt|  Splitting windows
|usr_09.txt|  Using the GUI
|usr_10.txt|  Making big changes
|usr_11.txt|  Recovering from a crash
|usr_12.txt|  Clever tricks

Editing Effectively ~
|usr_20.txt|  Typing command-line commands quickly
|usr_21.txt|  Go away and come back
|usr_22.txt|  Finding the file to edit
|usr_23.txt|  Editing other files
|usr_24.txt|  Inserting quickly
|usr_25.txt|  Editing formatted text
|usr_26.txt|  Repeating
|usr_27.txt|  Search commands and patterns
|usr_28.txt|  Folding
|usr_29.txt|  Moving through programs
|usr_30.txt|  Editing programs
|usr_31.txt|  Exploiting the GUI
|usr_32.txt|  The undo tree

Tuning Vim ~
|usr_40.txt|  Make new commands
|usr_41.txt|  Write a Vim script
|usr_42.txt|  Add new menus
|usr_43.txt|  Using filetypes
|usr_44.txt|  Your own syntax highlighted
|usr_45.txt|  Select your language (locale)

Writing Vim script ~
|usr_50.txt|  Advanced Vim script writing
|usr_51.txt|  Write plugins
|usr_52.txt|  Write larger plugins

Making Vim Run ~
|usr_90.txt|  Installing Vim


Reference manual ~
|reference_toc|     More detailed information for all commands

The user manual (an older version) is available as a single, ready to print
HTML and PDF file here:
	http://vimdoc.sf.net

==============================================================================
Getting Started ~

Read this from start to end to learn the essential commands.

|usr_01.txt|  About the manuals
		|01.1|	Two manuals
		|01.2|	Vim installed
		|01.3|	Using the Vim tutor
		|01.4|	Copyright

|usr_02.txt|  The first steps in Vim
		|02.1|	Running Vim for the First Time
		|02.2|	Inserting text
		|02.3|	Moving around
		|02.4|	Deleting characters
		|02.5|	Undo and Redo
		|02.6|	Other editing commands
		|02.7|	Getting out
		|02.8|	Finding help

|usr_03.txt|  Moving around
		|03.1|	Word movement
		|03.2|	Moving to the start or end of a line
		|03.3|	Moving to a character
		|03.4|	Matching a paren
		|03.5|	Moving to a specific line
		|03.6|	Telling where you are
		|03.7|	Scrolling around
		|03.8|	Simple searches
		|03.9|	Simple search patterns
		|03.10|	Using marks

|usr_04.txt|  Making small changes
		|04.1|	Operators and motions
		|04.2|	Changing text
		|04.3|	Repeating a change
		|04.4|	Visual mode
		|04.5|	Moving text
		|04.6|	Copying text
		|04.7|	Using the clipboard
		|04.8|	Text objects
		|04.9|	Replace mode
		|04.10|	Conclusion

|usr_05.txt|  Set your settings
		|05.1|	The vimrc file
		|05.2|	The example vimrc file explained
		|05.3|	The defaults.vim file explained
		|05.4|	Simple mappings
		|05.5|	Adding a package
		|05.6|	Adding a plugin
		|05.7|	Adding a help file
		|05.8|	The option window
		|05.9|	Often used options

|usr_06.txt|  Using syntax highlighting
		|06.1|	Switching it on
		|06.2|	No or wrong colors?
		|06.3|	Different colors
		|06.4|	With colors or without colors
		|06.5|	Printing with colors
		|06.6|	Further reading

|usr_07.txt|  Editing more than one file
		|07.1|	Edit another file
		|07.2|	A list of files
		|07.3|	Jumping from file to file
		|07.4|	Backup files
		|07.5|	Copy text between files
		|07.6|	Viewing a file
		|07.7|	Changing the file name

|usr_08.txt|  Splitting windows
		|08.1|	Split a window
		|08.2|	Split a window on another file
		|08.3|	Window size
		|08.4|	Vertical splits
		|08.5|	Moving windows
		|08.6|	Commands for all windows
		|08.7|	Viewing differences with vimdiff
		|08.8|	Various

|usr_09.txt|  Using the GUI
		|09.1|	Parts of the GUI
		|09.2|	Using the mouse
		|09.3|	The clipboard
		|09.4|	Select mode

|usr_10.txt|  Making big changes
		|10.1|	Record and playback commands
		|10.2|	Substitution
		|10.3|	Command ranges
		|10.4|	The global command
		|10.5|	Visual block mode
		|10.6|	Reading and writing part of a file
		|10.7|	Formatting text
		|10.8|	Changing case
		|10.9|	Using an external program

|usr_11.txt|  Recovering from a crash
		|11.1|	Basic recovery
		|11.2|	Where is the swap file?
		|11.3|	Crashed or not?
		|11.4|	Further reading

|usr_12.txt|  Clever tricks
		|12.1|	Replace a word
		|12.2|	Change "Last, First" to "First Last"
		|12.3|	Sort a list
		|12.4|	Reverse line order
		|12.5|	Count words
		|12.6|	Find a man page
		|12.7|	Trim blanks
		|12.8|	Find where a word is used

==============================================================================
Editing Effectively ~

Subjects that can be read independently.

|usr_20.txt|  Typing command-line commands quickly
		|20.1|	Command line editing
		|20.2|	Command line abbreviations
		|20.3|	Command line completion
		|20.4|	Command line history
		|20.5|	Command line window

|usr_21.txt|  Go away and come back
		|21.1|	Suspend and resume
		|21.2|	Executing shell commands
		|21.3|	Remembering information; viminfo
		|21.4|	Sessions
		|21.5|	Views
		|21.6|	Modelines

|usr_22.txt|  Finding the file to edit
		|22.1|	The file explorer
		|22.2|	The current directory
		|22.3|	Finding a file
		|22.4|	The buffer list

|usr_23.txt|  Editing other files
		|23.1|	DOS, Mac and Unix files
		|23.2|	Files on the internet
		|23.3|	Encryption
		|23.4|	Binary files
		|23.5|	Compressed files

|usr_24.txt|  Inserting quickly
		|24.1|	Making corrections
		|24.2|	Showing matches
		|24.3|	Completion
		|24.4|	Repeating an insert
		|24.5|	Copying from another line
		|24.6|	Inserting a register
		|24.7|	Abbreviations
		|24.8|	Entering special characters
		|24.9|	Digraphs
		|24.10|	Normal mode commands

|usr_25.txt|  Editing formatted text
		|25.1|	Breaking lines
		|25.2|	Aligning text
		|25.3|	Indents and tabs
		|25.4|	Dealing with long lines
		|25.5|	Editing tables

|usr_26.txt|  Repeating
		|26.1|	Repeating with Visual mode
		|26.2|	Add and subtract
		|26.3|	Making a change in many files
		|26.4|	Using Vim from a shell script

|usr_27.txt|  Search commands and patterns
		|27.1|	Ignoring case
		|27.2|	Wrapping around the file end
		|27.3|	Offsets
		|27.4|	Matching multiple times
		|27.5|	Alternatives
		|27.6|	Character ranges
		|27.7|	Character classes
		|27.8|	Matching a line break
		|27.9|	Examples

|usr_28.txt|  Folding
		|28.1|	What is folding?
		|28.2|	Manual folding
		|28.3|	Working with folds
		|28.4|	Saving and restoring folds
		|28.5|	Folding by indent
		|28.6|	Folding with markers
		|28.7|	Folding by syntax
		|28.8|	Folding by expression
		|28.9|	Folding unchanged lines
		|28.10|	Which fold method to use?

|usr_29.txt|  Moving through programs
		|29.1|	Using tags
		|29.2|	The preview window
		|29.3|	Moving through a program
		|29.4|	Finding global identifiers
		|29.5|	Finding local identifiers

|usr_30.txt|  Editing programs
		|30.1|	Compiling
		|30.2|	Indenting C files
		|30.3|	Automatic indenting
		|30.4|	Other indenting
		|30.5|	Tabs and spaces
		|30.6|	Formatting comments

|usr_31.txt|  Exploiting the GUI
		|31.1|	The file browser
		|31.2|	Confirmation
		|31.3|	Menu shortcuts
		|31.4|	Vim window position and size
		|31.5|	Various

|usr_32.txt|  The undo tree
		|32.1|	Undo up to a file write
		|32.2|	Numbering changes
		|32.3|	Jumping around the tree
		|32.4|	Time travelling

==============================================================================
Tuning Vim ~

Make Vim work as you like it.

|usr_40.txt|  Make new commands
		|40.1|	Key mapping
		|40.2|	Defining command-line commands
		|40.3|	Autocommands

|usr_41.txt|  Write a Vim script
		|41.1|	Introduction
		|41.2|	Variables
		|41.3|	Expressions
		|41.4|	Conditionals
		|41.5|	Executing an expression
		|41.6|	Using functions
		|41.7|	Defining a function
		|41.8|	Lists and Dictionaries
		|41.9|	White space
		|41.10|	Line continuation
		|41.11|	Comments
		|41.12|	Fileformat

|usr_42.txt|  Add new menus
		|42.1|	Introduction
		|42.2|	Menu commands
		|42.3|	Various
		|42.4|	Toolbar and popup menus

|usr_43.txt|  Using filetypes
		|43.1|	Plugins for a filetype
		|43.2|	Adding a filetype

|usr_44.txt|  Your own syntax highlighted
		|44.1|	Basic syntax commands
		|44.2|	Keywords
		|44.3|	Matches
		|44.4|	Regions
		|44.5|	Nested items
		|44.6|	Following groups
		|44.7|	Other arguments
		|44.8|	Clusters
		|44.9|	Including another syntax file
		|44.10|	Synchronizing
		|44.11|	Installing a syntax file
		|44.12|	Portable syntax file layout

|usr_45.txt|  Select your language (locale)
		|45.1|	Language for Messages
		|45.2|	Language for Menus
		|45.3|	Using another encoding
		|45.4|	Editing files with a different encoding
		|45.5|	Entering language text

==============================================================================
Writing Vim script ~

|usr_50.txt|  Advanced Vim script writing
		|50.1|	Exceptions
		|50.2|	Function with variable number of arguments
		|50.3|	Restoring the view

|usr_51.txt|  Write plugins
		|51.1|	Writing a generic plugin
		|51.2|	Writing a filetype plugin
		|51.3|	Writing a compiler plugin
		|51.4|	Distributing Vim scripts

|usr_52.txt|  Write larger plugins
		|52.1|	Export and import
		|52.2|	Autoloading
		|52.3|	Autoloading without import/export
		|52.4|	Other mechanisms to use
		|52.5|	Using a Vim9 script from legacy script

==============================================================================
Making Vim Run ~

Before you can use Vim.

|usr_90.txt|  Installing Vim
		|90.1|	Unix
		|90.2|	MS-Windows
		|90.3|	Upgrading
		|90.4|	Common installation issues
		|90.5|	Uninstalling Vim

==============================================================================

Copyright: see |manual-copyright|  vim:tw=78:ts=8:noet:ft=help:norl: