Mercurial > vim
comparison src/if_python3.c @ 33491:e6c00b4c3ee5 v9.0.1996
patch 9.0.1996: Cannot build with python312
Commit: https://github.com/vim/vim/commit/fa145f200966e47e11c403520374d6d37cfd1de7
Author: Ken Takata <kentkt@csc.jp>
Date: Fri Oct 6 19:27:13 2023 +0200
patch 9.0.1996: Cannot build with python312
Problem: Cannot build with python312
Solution: Define wrapper types and functions for python 3.12
Py_SIZE() uses PyLong_Type and PyBool_Type starting from Python 3.12.
We need to define our own Py_SIZE() to replace Py{Bool,Long}_Type with
py3_Py{Bool,Long}_Type.
We also need to redefine PyTuple_GET_SIZE() and PyList_GET_SIZE(), because
they use Py_SIZE().
closes: #13281
closes: #13290
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ken Takata <kentkt@csc.jp>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 06 Oct 2023 19:45:03 +0200 |
parents | ed8db57d1034 |
children | 1a769647d661 |
comparison
equal
deleted
inserted
replaced
33490:33593174288b | 33491:e6c00b4c3ee5 |
---|---|
66 #ifdef _XOPEN_SOURCE | 66 #ifdef _XOPEN_SOURCE |
67 # undef _XOPEN_SOURCE // pyconfig.h defines it as well. | 67 # undef _XOPEN_SOURCE // pyconfig.h defines it as well. |
68 #endif | 68 #endif |
69 | 69 |
70 #define PY_SSIZE_T_CLEAN | 70 #define PY_SSIZE_T_CLEAN |
71 #define PyLong_Type (*py3_PyLong_Type) | |
72 #define PyBool_Type (*py3_PyBool_Type) | |
73 | 71 |
74 #ifdef Py_LIMITED_API | 72 #ifdef Py_LIMITED_API |
75 # define USE_LIMITED_API // Using Python 3 limited ABI | 73 # define USE_LIMITED_API // Using Python 3 limited ABI |
76 #endif | 74 #endif |
77 | 75 |
295 # endif | 293 # endif |
296 # define PySlice_Type (*py3_PySlice_Type) | 294 # define PySlice_Type (*py3_PySlice_Type) |
297 # define PyFloat_Type (*py3_PyFloat_Type) | 295 # define PyFloat_Type (*py3_PyFloat_Type) |
298 # define PyNumber_Check (*py3_PyNumber_Check) | 296 # define PyNumber_Check (*py3_PyNumber_Check) |
299 # define PyNumber_Long (*py3_PyNumber_Long) | 297 # define PyNumber_Long (*py3_PyNumber_Long) |
298 # define PyBool_Type (*py3_PyBool_Type) | |
299 # if PY_VERSION_HEX >= 0x030c00b0 | |
300 # define PyLong_Type (*py3_PyLong_Type) | |
301 # endif | |
300 # define PyErr_NewException py3_PyErr_NewException | 302 # define PyErr_NewException py3_PyErr_NewException |
301 # ifdef Py_DEBUG | 303 # ifdef Py_DEBUG |
302 # define _Py_NegativeRefcount py3__Py_NegativeRefcount | 304 # define _Py_NegativeRefcount py3__Py_NegativeRefcount |
303 # define _Py_RefTotal (*py3__Py_RefTotal) | 305 # define _Py_RefTotal (*py3__Py_RefTotal) |
304 # define PyModule_Create2TraceRefs py3_PyModule_Create2TraceRefs | 306 # define PyModule_Create2TraceRefs py3_PyModule_Create2TraceRefs |
494 # ifndef USE_LIMITED_API | 496 # ifndef USE_LIMITED_API |
495 static PyTypeObject* py3_PyStdPrinter_Type; | 497 static PyTypeObject* py3_PyStdPrinter_Type; |
496 # endif | 498 # endif |
497 static PyTypeObject* py3_PySlice_Type; | 499 static PyTypeObject* py3_PySlice_Type; |
498 static PyTypeObject* py3_PyFloat_Type; | 500 static PyTypeObject* py3_PyFloat_Type; |
499 PyTypeObject* py3_PyBool_Type; | 501 static PyTypeObject* py3_PyBool_Type; |
500 # if PY_VERSION_HEX >= 0x030c00b0 | 502 # if PY_VERSION_HEX >= 0x030c00b0 |
501 PyTypeObject* py3_PyLong_Type; | 503 static PyTypeObject* py3_PyLong_Type; |
502 # endif | 504 # endif |
503 static int (*py3_PyNumber_Check)(PyObject *); | 505 static int (*py3_PyNumber_Check)(PyObject *); |
504 static PyObject* (*py3_PyNumber_Long)(PyObject *); | 506 static PyObject* (*py3_PyNumber_Long)(PyObject *); |
505 static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict); | 507 static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict); |
506 static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor); | 508 static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor); |
694 # ifndef USE_LIMITED_API | 696 # ifndef USE_LIMITED_API |
695 {"PyStdPrinter_Type", (PYTHON_PROC*)&py3_PyStdPrinter_Type}, | 697 {"PyStdPrinter_Type", (PYTHON_PROC*)&py3_PyStdPrinter_Type}, |
696 # endif | 698 # endif |
697 {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type}, | 699 {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type}, |
698 {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type}, | 700 {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type}, |
699 # if PY_VERSION_HEX < 0x030c00b0 | |
700 {"PyBool_Type", (PYTHON_PROC*)&py3_PyBool_Type}, | 701 {"PyBool_Type", (PYTHON_PROC*)&py3_PyBool_Type}, |
702 # if PY_VERSION_HEX >= 0x030c00b0 | |
703 {"PyLong_Type", (PYTHON_PROC*)&py3_PyLong_Type}, | |
701 # endif | 704 # endif |
702 {"PyNumber_Check", (PYTHON_PROC*)&py3_PyNumber_Check}, | 705 {"PyNumber_Check", (PYTHON_PROC*)&py3_PyNumber_Check}, |
703 {"PyNumber_Long", (PYTHON_PROC*)&py3_PyNumber_Long}, | 706 {"PyNumber_Long", (PYTHON_PROC*)&py3_PyNumber_Long}, |
704 {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException}, | 707 {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException}, |
705 # ifdef Py_DEBUG | 708 # ifdef Py_DEBUG |
785 # undef PyObject_TypeCheck | 788 # undef PyObject_TypeCheck |
786 # define PyObject_TypeCheck(o,t) py3__PyObject_TypeCheck(o,t) | 789 # define PyObject_TypeCheck(o,t) py3__PyObject_TypeCheck(o,t) |
787 # else | 790 # else |
788 # define _PyObject_TypeCheck(o,t) py3__PyObject_TypeCheck(o,t) | 791 # define _PyObject_TypeCheck(o,t) py3__PyObject_TypeCheck(o,t) |
789 # endif | 792 # endif |
793 # endif | |
794 | |
795 # if !defined(USE_LIMITED_API) && PY_VERSION_HEX >= 0x030c00b0 | |
796 // Py_SIZE() uses PyLong_Type and PyBool_Type starting from Python 3.12. | |
797 // We need to define our own Py_SIZE() to replace Py{Bool,Long}_Type with | |
798 // py3_Py{Bool,Long}_Type. | |
799 // We also need to redefine PyTuple_GET_SIZE() and PyList_GET_SIZE(), because | |
800 // they use Py_SIZE(). | |
801 static inline Py_ssize_t | |
802 py3_Py_SIZE(PyObject *ob) | |
803 { | |
804 assert(ob->ob_type != &PyLong_Type); | |
805 assert(ob->ob_type != &PyBool_Type); | |
806 PyVarObject *var_ob = _PyVarObject_CAST(ob); | |
807 return var_ob->ob_size; | |
808 } | |
809 # undef Py_SIZE | |
810 # define Py_SIZE(ob) py3_Py_SIZE(_PyObject_CAST(ob)) | |
811 | |
812 static inline Py_ssize_t | |
813 py3_PyTuple_GET_SIZE(PyObject *op) | |
814 { | |
815 PyTupleObject *tuple = _PyTuple_CAST(op); | |
816 return Py_SIZE(tuple); | |
817 } | |
818 # undef PyTuple_GET_SIZE | |
819 # define PyTuple_GET_SIZE(op) py3_PyTuple_GET_SIZE(_PyObject_CAST(op)) | |
820 | |
821 static inline | |
822 Py_ssize_t py3_PyList_GET_SIZE(PyObject *op) | |
823 { | |
824 PyListObject *list = _PyList_CAST(op); | |
825 return Py_SIZE(list); | |
826 } | |
827 # undef PyList_GET_SIZE | |
828 # define PyList_GET_SIZE(op) py3_PyList_GET_SIZE(_PyObject_CAST(op)) | |
790 # endif | 829 # endif |
791 | 830 |
792 # ifdef MSWIN | 831 # ifdef MSWIN |
793 /* | 832 /* |
794 * Look up the library "libname" using the InstallPath registry key. | 833 * Look up the library "libname" using the InstallPath registry key. |