summaryrefslogtreecommitdiffstats
path: root/src/if_py_both.h
AgeCommit message (Collapse)Author
2024-01-29patch 9.1.0062: Internal error when :luado/perldo/pydo etc delete linesv9.1.0062zeertzjq
Problem: Internal error when :luado/perldo/pydo etc delete lines Solution: Test that the line is still valid line number (zeertzjq) closes: #13931 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-01-04patch 9.1.0006: is*() and to*() function may be unsafev9.1.0006Keith Thompson
Problem: is*() and to*() function may be unsafe Solution: Add SAFE_* macros and start using those instead (Keith Thompson) Use SAFE_() macros for is*() and to*() functions The standard is*() and to*() functions declared in <ctype.h> have undefined behavior for negative arguments other than EOF. If plain char is signed, passing an unchecked value from argv for from user input to one of these functions has undefined behavior. Solution: Add SAFE_*() macros that cast the argument to unsigned char. Most implementations behave sanely for negative arguments, and most character values in practice are non-negative, but it's still best to avoid undefined behavior. The change from #13347 has been omitted, as this has already been separately fixed in commit ac709e2fc0db6d31abb7da96f743c40956b60c3a (v9.0.2054) fixes: #13332 closes: #13347 Signed-off-by: Keith Thompson <Keith.S.Thompson@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-10-27patch 9.0.2076: Vim9: No support for type aliasesv9.0.2076Yegappan Lakshmanan
Problem: Vim9: No support for type aliases Solution: Implement :type command A type definition is giving a name to a type specification. This also known type alias. :type ListOfStrings = list<string> The type alias can be used wherever a built-in type can be used. The type alias name must start with an upper case character. closes: #13407 Signed-off-by: Christian Brabandt <cb@256bit.org> Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-30patch 9.0.1960: Make CI checks more strictv9.0.1960Yee Cheng Chin
Problem: Make CI checks more strict Solution: Add -Wstrict-prototypes -Wmissing-prototypes to CI, fix uncovered problems Add -Wstrict-prototypes -Wmissing-prototypes warnings check to CI Add two new warnings to CI, silence some Perl related build-warnings: - `strict-prototypes` helps prevent declaring a function with an empty argument list, e.g. `int func()`. In C++, that's equivalent to `int func(void)`, but in C, that means a function that can take any number of arguments which is rarely what we want. - `missing-prototypes` makes sure we use `static` for file-only internal functions. Non-static functions should have been declared on a prototype file. - Add `no-compound-token-split-by-macro` to the perl cflags, since it throws out a bunch of perl-related warnings that make the CI log unnecessary verbose and hard to read. This seems to happen only with clang 12 and above. When applying those changes, it already uncovered a few warnings, so fix up the code as well (fix prototypes, make the code static, remove shadowed var declaration) GTK header needs to have #pragma warning suppressiong because GTK2 headers will warn on `-Wstrict-prototypes`, and it's included by gui.h and so we can't just turn off the warning in a couple files. closes: #13223 closes: #13226 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2023-09-21patch 9.0.1925: if_python: still undefined behaviour with function pointerv9.0.1925Yee Cheng Chin
Problem: if_python: still undefined behaviour with function pointer Solution: fix remaining problems Fix remaining issues in the if_python code in casting incompatible function pointers leading to Clang 17 giving runtime errors during UBSAN. closes: #13140 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2023-09-20patch 9.0.1917: undefined behaviour with python function pointerv9.0.1917Yee Cheng Chin
Problem: undefined behaviour with python function pointer Solution: correctly cast function pointers from void Fix more undefined behaviors in if_python Fix remaining UBSAN errors from Clang 17 in if_python in casting function pointers. Also fix a mistake where `PyMem_Free()` should be returning void, by the dynamic build is mistakenly casting it as a function that returns an int. closes: #13128 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2023-09-19patch 9.0.1913: if_python: undefined behaviour for function pointersv9.0.1913Yee Cheng Chin
Problem: if_python: undefined behaviour for function pointers Solution: Fix if_python undefined behavior for function pointer casts Identified by clang 17 UBSAN (see #12745). Make sure to cast function pointers with the same signature only. closes: #13122 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2023-08-27patch 9.0.1795: Indentation issuesv9.0.1795Yegappan Lakshmanan
Problem: Indentation issues Solution: Fix code indentation issues. closes: #12906 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-20patch 9.0.1778: if_py_both: code-style issuev9.0.1778Christian Brabandt
Problem: if_py_both: code-style issue Solution: add space Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-08-20patch 9.0.1776: No support for stable Python 3 ABIv9.0.1776Yee Cheng Chin
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>
2022-12-10patch 9.0.1044: setting window height using Python may cause errorsv9.0.1044Bram Moolenaar
Problem: Setting window height using Python may cause errors. Solution: When setting "curwin" also set "curbuf". (closes #11687)
2022-12-08patch 9.0.1031: Vim9 class is not implemented yetv9.0.1031Bram Moolenaar
Problem: Vim9 class is not implemented yet. Solution: Add very basic class support.
2022-11-29patch 9.0.0970: Coverity warns for uninitialized variablev9.0.0970Bram Moolenaar
Problem: Coverity warns for uninitialized variable. Solution: Initialize "ren_ret".
2022-11-28patch 9.0.0965: using one window for executing autocommands is insufficientv9.0.0965Bram Moolenaar
Problem: Using one window for executing autocommands is insufficient. Solution: Use up to five windows for executing autocommands.
2022-11-25patch 9.0.0949: crash when unletting a variable while listing variablesv9.0.0949Bram Moolenaar
Problem: Crash when unletting a variable while listing variables. Solution: Disallow changing a hashtable while going over the entries. (closes #11435)
2022-09-17patch 9.0.0491: no good reason to build without the float featurev9.0.0491Bram Moolenaar
Problem: No good reason to build without the float feature. Solution: Remove configure check for float and "#ifdef FEAT_FLOAT".
2022-08-14patch 9.0.0206: redraw flags are not named specificallyv9.0.0206Bram Moolenaar
Problem: Redraw flags are not named specifically. Solution: Prefix "UPD_" to the flags, for UPDate_screen().
2022-05-22patch 8.2.4997: Python: changing hidden buffer can cause display mess upv8.2.4997Bram Moolenaar
Problem: Python: changing hidden buffer can cause the display to be messed up. Solution: Do not mark changed lines when using another buffer. (Paul Ollis, closes #10437, closes #7972)
2022-05-12patch 8.2.4945: inconsistent use of white spacev8.2.4945Bram Moolenaar
Problem: Inconsistent use of white space. Solution: Use Tabs and Spaces consistently.
2022-03-27patch 8.2.4639: not sufficient parenthesis in preprocessor macroskylo252
Problem: Not sufficient parenthesis in preprocessor macros. Solution: Add more parenthesis. (closes #10031)
2022-01-09patch 8.2.4048: gcc complains about use of "%p" in printfv8.2.4048Dominique Pelle
Problem: gcc complains about use of "%p" in printf. Solution: Add (void *) typecast. (Dominique Pellé, closes #9494)
2022-01-08patch 8.2.4043: using int for second argument of ga_init2()v8.2.4043Bram Moolenaar
Problem: Using int for second argument of ga_init2(). Solution: Remove unnessary type cast (int) when using sizeof().
2022-01-06patch 8.2.4018: ml_get error when win_execute redraws with Visual selectionv8.2.4018Bram Moolenaar
Problem: ml_get error when win_execute redraws with Visual selection. Solution: Disable Visual area temporarily. (closes #9479)
2022-01-05patch 8.2.4012: error messages are spread outv8.2.4012Bram Moolenaar
Problem: Error messages are spread out. Solution: Move the last error messages to errors.h.
2022-01-05patch 8.2.4010: error messages are spread outv8.2.4010Bram Moolenaar
Problem: Error messages are spread out. Solution: Move more error messages to errors.h.
2022-01-01patch 8.2.3977: error messages are spread outv8.2.3977Bram Moolenaar
Problem: Error messages are spread out. Solution: Move more error messages to errors.h.
2021-07-22patch 8.2.3200: Vim9: hard to guess where a type error is givenv8.2.3200Bram Moolenaar
Problem: Vim9: hard to guess where a type error is given. Solution: Add the function name where possible. (closes #8608)
2021-05-07patch 8.2.2842: Vim9: skip argument to searchpair() is not compiledv8.2.2842Bram Moolenaar
Problem: Vim9: skip argument to searchpair() is not compiled. Solution: Add VAR_INSTR.
2021-02-21patch 8.2.2538: crash when using Python list iteratorv8.2.2538Bram Moolenaar
Problem: Crash when using Python list iterator. Solution: Increment the list reference count. (closes #7886)
2020-12-21patch 8.2.2178: Python 3: non-utf8 character cannot be handledv8.2.2178Bram Moolenaar
Problem: Python 3: non-utf8 character cannot be handled. Solution: Change the string decode. (Björn Linse, closes #1053)
2020-10-21patch 8.2.1883: compiler warnings when using Pythonv8.2.1883Bram Moolenaar
Problem: Compiler warnings when using Python. Solution: Adjust PyCFunction to also have the second argument. Use "int" return type for some functions. Insert "(void *)" to get rid of the remaining warnings.
2020-10-11patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9v8.2.1834Bram Moolenaar
Problem: PyEval_InitThreads() is deprecated in Python 3.9. Solution: Do not call PyEval_InitThreads in Python 3.9 and later. (Ken Takata, closes #7113) Avoid warnings for functions.
2020-08-29patch 8.2.1538: Python: iteration over vim objects fails to keep referencev8.2.1538Bram Moolenaar
Problem: Python: iteration over vim objects fails to keep reference. Solution: Keep a reference for the object. (Paul Ollis, closes #6803, closes #6806)
2020-07-14patch 8.2.1210: using ht_used when looping through a hashtab is less reliablev8.2.1210Bram Moolenaar
Problem: Using ht_used when looping through a hashtab is less reliable. Solution: Use ht_changed in a few more places.
2020-07-07patch 8.2.1150: ml_get error when using Pythonv8.2.1150Bram Moolenaar
Problem: ml_get error when using Python. (Yegappan Lakshmanan) Solution: Check the line number is not out of range. Call "Check" with "fromObj" instead of "from".
2020-07-06patch 8.2.1146: not enough testing for Pythonv8.2.1146Bram Moolenaar
Problem: Not enough testing for Python. Solution: Add more tests. Fix uncovered problems. (Yegappan Lakshmanan, closes #6392)
2020-06-29patch 8.2.1093: Python: double free when adding item to dict failsv8.2.1093Bram Moolenaar
Problem: Python: double free when adding item to dict fails. Solution: Remove vim_free() call.
2020-05-30patch 8.2.0853: ml_delete() often called with FALSE argumentv8.2.0853Bram Moolenaar
Problem: ml_delete() often called with FALSE argument. Solution: Use ml_delete_flags(x, ML_DEL_MESSAGE) when argument is TRUE.
2020-05-13patch 8.2.0751: Vim9: performance can be improvedv8.2.0751Bram Moolenaar
Problem: Vim9: performance can be improved. Solution: Don't call break. Inline check for list materialize. Make an inline version of ga_grow().
2020-05-11patch 8.2.0740: minor message mistakesv8.2.0740Bram Moolenaar
Problem: Minor message mistakes. Solution: Change vim to Vim and other fixes.
2020-04-28patch 8.2.0654: building with Python failsv8.2.0654Bram Moolenaar
Problem: Building with Python fails. Solution: Add missing argument.
2020-04-12patch 8.2.0559: clearing a struct is verbosev8.2.0559Bram Moolenaar
Problem: Clearing a struct is verbose. Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER().
2020-04-05patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"v8.2.0517Bram Moolenaar
Problem: Vim9: cannot separate "func" and "func(): void". Solution: Use VAR_ANY for "any" and VAR_UNKNOWN for "no type".
2020-04-02patch 8.2.0500: using the same loop in many placesv8.2.0500Bram Moolenaar
Problem: Using the same loop in many places. Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes #5339)
2020-01-29patch 8.2.0173: build fails with old compilerv8.2.0173Bram Moolenaar
Problem: Build fails with old compiler. Solution: Do not use anonymous unions. (John Marriott)
2020-01-26patch 8.2.0155: warnings from MinGW compiler; tests fail without +floatv8.2.0155Bram Moolenaar
Problem: Warnings from MinGW compiler. (John Marriott) Json test fails when building without +float feature. Solution: Init variables. Fix Json parsing. Skip a few tests that require the +float feature.
2020-01-26patch 8.2.0149: maintaining a Vim9 branch separately is more workv8.2.0149Bram Moolenaar
Problem: Maintaining a Vim9 branch separately is more work. Solution: Merge the Vim9 script changes.
2020-01-11patch 8.2.0111: VAR_SPECIAL is also used for booleansv8.2.0111Bram Moolenaar
Problem: VAR_SPECIAL is also used for booleans. Solution: Add VAR_BOOL for better type checking.
2020-01-01patch 8.2.0070: crash when using Python 3 with "debug" encodingv8.2.0070Bram Moolenaar
Problem: Crash when using Python 3 with "debug" encoding. (Dominique Pelle) Solution: Use "euc-jp" whenever enc_dbcs is set.
2019-12-31patch 8.2.0068: crash when using Python 3 with "utf32" encodingv8.2.0068Bram Moolenaar
Problem: Crash when using Python 3 with "utf32" encoding. (Dominique Pelle) Solution: Use "utf-8" whenever enc_utf8 is set. (closes #5423)