1 Description: Fix Python 3.10 (PEP-620) incompatibility
2 Origin: upstream, https://github.com/boostorg/python/commit/500194edb7833d0627ce7a2595fec49d0aae2484
3 Author: Stefan Seefeld <stefan@seefeld.name>
4 Last-Update: 2020-11-13
6 --- a/src/boost/boost/python/detail/wrap_python.hpp
7 +++ b/src/boost/boost/python/detail/wrap_python.hpp
10 # define PyVarObject_HEAD_INIT(type, size) \
11 PyObject_HEAD_INIT(type) size,
14 +#if PY_VERSION_HEX < 0x030900A4
15 +# define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
16 +# define Py_SET_SIZE(obj, size) ((Py_SIZE(obj) = (size)), (void)0)
20 --- a/src/boost/boost/python/object/make_instance.hpp
21 +++ b/src/boost/boost/python/object/make_instance.hpp
24 // Note the position of the internally-stored Holder,
25 // for the sake of destruction
26 - Py_SIZE(instance) = offsetof(instance_t, storage);
27 + Py_SET_SIZE(instance, offsetof(instance_t, storage));
29 // Release ownership of the python object
31 --- a/src/boost/libs/python/src/object/class.cpp
32 +++ b/src/boost/libs/python/src/object/class.cpp
35 if (static_data_object.tp_dict == 0)
37 - Py_TYPE(&static_data_object) = &PyType_Type;
38 + Py_SET_TYPE(&static_data_object, &PyType_Type);
39 static_data_object.tp_base = &PyProperty_Type;
40 if (PyType_Ready(&static_data_object))
44 if (class_metatype_object.tp_dict == 0)
46 - Py_TYPE(&class_metatype_object) = &PyType_Type;
47 + Py_SET_TYPE(&class_metatype_object, &PyType_Type);
48 class_metatype_object.tp_base = &PyType_Type;
49 if (PyType_Ready(&class_metatype_object))
52 // like, so we'll store the total size of the object
53 // there. A negative number indicates that the extra
54 // instance memory is not yet allocated to any holders.
55 -#if PY_VERSION_HEX >= 0x02060000
60 - -(static_cast<int>(offsetof(instance<>,storage) + instance_size));
61 + Py_SET_SIZE(result,-static_cast<int>(offsetof(instance<>,storage) + instance_size));
63 return (PyObject*)result;
67 if (class_type_object.tp_dict == 0)
69 - Py_TYPE(&class_type_object) = incref(class_metatype().get());
70 + Py_SET_TYPE(&class_type_object, incref(class_metatype().get()));
71 class_type_object.tp_base = &PyBaseObject_Type;
72 if (PyType_Ready(&class_type_object))
75 assert(holder_offset >= offsetof(objects::instance<>,storage));
77 // Record the fact that the storage is occupied, noting where it starts
78 - Py_SIZE(self) = holder_offset;
79 + Py_SET_SIZE(self, holder_offset);
80 return (char*)self + holder_offset;
83 --- a/src/boost/libs/python/src/object/enum.cpp
84 +++ b/src/boost/libs/python/src/object/enum.cpp
87 if (enum_type_object.tp_dict == 0)
89 - Py_TYPE(&enum_type_object) = incref(&PyType_Type);
90 + Py_SET_TYPE(&enum_type_object, incref(&PyType_Type));
91 #if PY_VERSION_HEX >= 0x03000000
92 enum_type_object.tp_base = &PyLong_Type;
94 --- a/src/boost/libs/python/src/object/function.cpp
95 +++ b/src/boost/libs/python/src/object/function.cpp
98 if (Py_TYPE(&function_type) == 0)
100 - Py_TYPE(&function_type) = &PyType_Type;
101 + Py_SET_TYPE(&function_type, &PyType_Type);
102 ::PyType_Ready(&function_type);
105 --- a/src/boost/libs/python/src/object/life_support.cpp
106 +++ b/src/boost/libs/python/src/object/life_support.cpp
109 if (Py_TYPE(&life_support_type) == 0)
111 - Py_TYPE(&life_support_type) = &PyType_Type;
112 + Py_SET_TYPE(&life_support_type, &PyType_Type);
113 PyType_Ready(&life_support_type);