summarylogtreecommitdiffstats
path: root/python311-compatibility.patch
blob: 9b5474a06633a44185c5c2812c2d5df389357818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
diff --unified --recursive --text boost_1_74_0.orig/boost/python/detail/wrap_python.hpp boost_1_74_0/boost/python/detail/wrap_python.hpp
--- boost_1_74_0.orig/boost/python/detail/wrap_python.hpp	2023-06-14 21:47:07.406473129 +0200
+++ boost_1_74_0/boost/python/detail/wrap_python.hpp	2023-06-14 22:16:24.558611081 +0200
@@ -227,7 +227,11 @@
 
 # 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
 
 
diff --unified --recursive --text boost_1_74_0.orig/boost/python/object/make_instance.hpp boost_1_74_0/boost/python/object/make_instance.hpp
--- boost_1_74_0.orig/boost/python/object/make_instance.hpp	2023-06-14 21:47:07.403139788 +0200
+++ boost_1_74_0/boost/python/object/make_instance.hpp	2023-06-14 22:20:46.242736154 +0200
@@ -47,7 +47,7 @@
               
             // 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();
diff --unified --recursive --text boost_1_74_0.orig/libs/python/src/exec.cpp boost_1_74_0/libs/python/src/exec.cpp
--- boost_1_74_0.orig/libs/python/src/exec.cpp	2023-06-14 21:47:05.089801030 +0200
+++ boost_1_74_0/libs/python/src/exec.cpp	2023-06-14 22:26:14.977048858 +0200
@@ -104,14 +104,22 @@
   if (local.is_none()) local = global;
   // should be 'char const *' but older python versions don't use 'const' yet.
   char *f = const_cast<char *>(filename);
-  // Let python open the file to avoid potential binary incompatibilities.
-#if PY_VERSION_HEX >= 0x03040000
-  FILE *fs = _Py_fopen(f, "r");
+#if PY_VERSION_HEX >= 0x03010000
+  // Let python manage any UTF bits to avoid potential incompatibilities.
+  PyObject *fo = Py_BuildValue("s", f);
+  PyObject *fb = Py_None;
+  PyUnicode_FSConverter(fo, &fb);
+  char *f_as_uft = PyBytes_AsString(fb);
+  FILE *fs = fopen(f_as_uft, "r");
+  Py_DECREF(fo);
+  Py_DECREF(fb);
 #elif PY_VERSION_HEX >= 0x03000000
+  // Let python open the file to avoid potential binary incompatibilities.
   PyObject *fo = Py_BuildValue("s", f);
-  FILE *fs = _Py_fopen(fo, "r");
+  FILE *fs = fopen(fo, "r");
   Py_DECREF(fo);
 #else
+  // Let python open the file to avoid potential binary incompatibilities.
   PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
   if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
   python::handle<> file(pyfile);
@@ -121,6 +129,7 @@
                 f,
                 Py_file_input,
 		global.ptr(), local.ptr());
+  fclose(fs);
   if (!result) throw_error_already_set();
   return object(detail::new_reference(result));
 }
diff --unified --recursive --text boost_1_74_0.orig/libs/python/src/object/class.cpp boost_1_74_0/libs/python/src/object/class.cpp
--- boost_1_74_0.orig/libs/python/src/object/class.cpp	2023-06-14 21:47:05.089801030 +0200
+++ boost_1_74_0/libs/python/src/object/class.cpp	2023-06-14 22:32:08.551496842 +0200
@@ -208,7 +208,7 @@
   {
       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;
@@ -316,7 +316,7 @@
   {
       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();
@@ -374,12 +374,7 @@
               // 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;
       }
@@ -470,7 +465,7 @@
   {
       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();
@@ -739,7 +734,7 @@
         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
diff --unified --recursive --text boost_1_74_0.orig/libs/python/src/object/enum.cpp boost_1_74_0/libs/python/src/object/enum.cpp
--- boost_1_74_0.orig/libs/python/src/object/enum.cpp	2023-06-14 21:47:05.089801030 +0200
+++ boost_1_74_0/libs/python/src/object/enum.cpp	2023-06-14 21:48:07.003280973 +0200
@@ -153,7 +153,7 @@
   {
       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
diff --unified --recursive --text boost_1_74_0.orig/libs/python/src/object/function.cpp boost_1_74_0/libs/python/src/object/function.cpp
--- boost_1_74_0.orig/libs/python/src/object/function.cpp	2023-06-14 21:47:05.089801030 +0200
+++ boost_1_74_0/libs/python/src/object/function.cpp	2023-06-14 21:48:07.006614314 +0200
@@ -107,7 +107,7 @@
     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);
     }
     
diff --unified --recursive --text boost_1_74_0.orig/libs/python/src/object/life_support.cpp boost_1_74_0/libs/python/src/object/life_support.cpp
--- boost_1_74_0.orig/libs/python/src/object/life_support.cpp	2023-06-14 21:47:05.089801030 +0200
+++ boost_1_74_0/libs/python/src/object/life_support.cpp	2023-06-14 21:48:07.006614314 +0200
@@ -93,7 +93,7 @@
     
     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);
     }