Skip to content

Commit

Permalink
Fix Python 3.10 (PEP-620) incompatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseefeld committed Jan 4, 2021
1 parent cd953cf commit 500194e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
4 changes: 4 additions & 0 deletions include/boost/python/detail/wrap_python.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ typedef int pid_t;

# define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#endif

#if PY_VERSION_HEX < 0x030900A4
# define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
# define Py_SET_SIZE(obj, size) ((Py_SIZE(obj) = (size)), (void)0)
#endif


Expand Down
2 changes: 1 addition & 1 deletion include/boost/python/object/make_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct make_instance_impl

// Note the position of the internally-stored Holder,
// for the sake of destruction
Py_SIZE(instance) = offsetof(instance_t, storage);
Py_SET_SIZE(instance, offsetof(instance_t, storage));

// Release ownership of the python object
protect.cancel();
Expand Down
15 changes: 5 additions & 10 deletions src/object/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace objects
{
if (static_data_object.tp_dict == 0)
{
Py_TYPE(&static_data_object) = &PyType_Type;
Py_SET_TYPE(&static_data_object, &PyType_Type);
static_data_object.tp_base = &PyProperty_Type;
if (PyType_Ready(&static_data_object))
return 0;
Expand Down Expand Up @@ -316,7 +316,7 @@ namespace objects
{
if (class_metatype_object.tp_dict == 0)
{
Py_TYPE(&class_metatype_object) = &PyType_Type;
Py_SET_TYPE(&class_metatype_object, &PyType_Type);
class_metatype_object.tp_base = &PyType_Type;
if (PyType_Ready(&class_metatype_object))
return type_handle();
Expand Down Expand Up @@ -374,12 +374,7 @@ namespace objects
// like, so we'll store the total size of the object
// there. A negative number indicates that the extra
// instance memory is not yet allocated to any holders.
#if PY_VERSION_HEX >= 0x02060000
Py_SIZE(result) =
#else
result->ob_size =
#endif
-(static_cast<int>(offsetof(instance<>,storage) + instance_size));
Py_SET_SIZE(result,-static_cast<int>(offsetof(instance<>,storage) + instance_size));
}
return (PyObject*)result;
}
Expand Down Expand Up @@ -470,7 +465,7 @@ namespace objects
{
if (class_type_object.tp_dict == 0)
{
Py_TYPE(&class_type_object) = incref(class_metatype().get());
Py_SET_TYPE(&class_type_object, incref(class_metatype().get()));
class_type_object.tp_base = &PyBaseObject_Type;
if (PyType_Ready(&class_type_object))
return type_handle();
Expand Down Expand Up @@ -739,7 +734,7 @@ void* instance_holder::allocate(PyObject* self_, std::size_t holder_offset, std:
assert(holder_offset >= offsetof(objects::instance<>,storage));

// Record the fact that the storage is occupied, noting where it starts
Py_SIZE(self) = holder_offset;
Py_SET_SIZE(self, holder_offset);
return (char*)self + holder_offset;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/object/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace
{
if (enum_type_object.tp_dict == 0)
{
Py_TYPE(&enum_type_object) = incref(&PyType_Type);
Py_SET_TYPE(&enum_type_object, incref(&PyType_Type));
#if PY_VERSION_HEX >= 0x03000000
enum_type_object.tp_base = &PyLong_Type;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/object/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function::function(
PyObject* p = this;
if (Py_TYPE(&function_type) == 0)
{
Py_TYPE(&function_type) = &PyType_Type;
Py_SET_TYPE(&function_type, &PyType_Type);
::PyType_Ready(&function_type);
}

Expand Down
2 changes: 1 addition & 1 deletion src/object/life_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ PyObject* make_nurse_and_patient(PyObject* nurse, PyObject* patient)

if (Py_TYPE(&life_support_type) == 0)
{
Py_TYPE(&life_support_type) = &PyType_Type;
Py_SET_TYPE(&life_support_type, &PyType_Type);
PyType_Ready(&life_support_type);
}

Expand Down

0 comments on commit 500194e

Please sign in to comment.