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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
commit 92d569e51aeb3b5f32b03768f423136a0642d445
Author: CYBERDEV <cyberdevil-no-reply@notabug.org>
Date: Thu Jun 6 00:03:30 2024 +0200
python3.12: "Fix building FreeStyle with Python 3.12"
Fully applied Blender upstream ref
252ae7029db3bc61a2740bb2cabeda8328b70f30
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.cpp b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index 4e1a0a1..fa47dec 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.cpp
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.cpp
@@ -76,6 +76,32 @@ PyObject *PyBool_from_bool(bool b)
return PyBool_FromLong(b ? 1 : 0);
}
+PyObject *PyLong_subtype_new(PyTypeObject *ty, long value)
+{
+ BLI_assert(ty->tp_basicsize == sizeof(PyLongObject));
+ PyLongObject *result = PyObject_NewVar(PyLongObject, ty, 1);
+#if PY_VERSION_HEX >= 0x030c0000
+ {
+ /* Account for change in `PyLongObject` in Python 3.12+.
+ * The values of longs are no longer accessible via public API's, copy the value instead. */
+ PyLongObject *value_py = (PyLongObject *)PyLong_FromLong(value);
+ memcpy(&result->long_value, &value_py->long_value, sizeof(result->long_value));
+ Py_DECREF(value_py);
+ }
+#else
+ result->ob_digit[0] = value;
+#endif
+ return (PyObject *)result;
+}
+
+void PyLong_subtype_add_to_dict(PyObject *dict, PyTypeObject *ty, const char *attr, long value)
+{
+ PyObject *result = PyLong_subtype_new(ty, value);
+ PyDict_SetItemString(dict, attr, result);
+ /* Owned by the dictionary. */
+ Py_DECREF(result);
+}
+
PyObject *Vector_from_Vec2f(Vec2f& vec)
{
float vec_data[2]; // because vec->_coord is protected
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.h b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.h
index 35c1e58..c71990d 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.h
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.h
@@ -98,6 +98,9 @@ extern "C" {
// C++ => Python
//==============================
+PyObject *PyLong_subtype_new(PyTypeObject *ty, long value);
+void PyLong_subtype_add_to_dict(PyObject *dict, PyTypeObject *ty, const char *attr, long value);
+
PyObject * PyBool_from_bool(bool b);
PyObject * Vector_from_Vec2f(Vec2f& v);
PyObject * Vector_from_Vec3f(Vec3f& v);
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp b/blender-2.79b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
index 0db2575..df7eb1e 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
@@ -185,33 +185,6 @@ PyTypeObject IntegrationType_Type = {
/*-----------------------BPy_IntegrationType instance definitions -------------------------*/
-static PyLongObject _IntegrationType_MEAN = {
- PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
- { MEAN }
-};
-static PyLongObject _IntegrationType_MIN = {
- PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
- { MIN }
-};
-static PyLongObject _IntegrationType_MAX = {
- PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
- { MAX }
-};
-static PyLongObject _IntegrationType_FIRST = {
- PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
- { FIRST }
-};
-static PyLongObject _IntegrationType_LAST = {
- PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
- { LAST }
-};
-
-#define BPy_IntegrationType_MEAN ((PyObject *)&_IntegrationType_MEAN)
-#define BPy_IntegrationType_MIN ((PyObject *)&_IntegrationType_MIN)
-#define BPy_IntegrationType_MAX ((PyObject *)&_IntegrationType_MAX)
-#define BPy_IntegrationType_FIRST ((PyObject *)&_IntegrationType_FIRST)
-#define BPy_IntegrationType_LAST ((PyObject *)&_IntegrationType_LAST)
-
//-------------------MODULE INITIALIZATION--------------------------------
int IntegrationType_Init(PyObject *module)
{
@@ -225,12 +198,18 @@ int IntegrationType_Init(PyObject *module)
Py_INCREF(&IntegrationType_Type);
PyModule_AddObject(module, "IntegrationType", (PyObject *)&IntegrationType_Type);
- PyDict_SetItemString(IntegrationType_Type.tp_dict, "MEAN", BPy_IntegrationType_MEAN);
- PyDict_SetItemString(IntegrationType_Type.tp_dict, "MIN", BPy_IntegrationType_MIN);
- PyDict_SetItemString(IntegrationType_Type.tp_dict, "MAX", BPy_IntegrationType_MAX);
- PyDict_SetItemString(IntegrationType_Type.tp_dict, "FIRST", BPy_IntegrationType_FIRST);
- PyDict_SetItemString(IntegrationType_Type.tp_dict, "LAST", BPy_IntegrationType_LAST);
-
+#define ADD_TYPE_CONST(id) \
+ PyLong_subtype_add_to_dict( \
+ IntegrationType_Type.tp_dict, &IntegrationType_Type, STRINGIFY(id), id)
+
+ ADD_TYPE_CONST(MEAN);
+ ADD_TYPE_CONST(MIN);
+ ADD_TYPE_CONST(MAX);
+ ADD_TYPE_CONST(FIRST);
+ ADD_TYPE_CONST(LAST);
+
+#undef ADD_TYPE_CONST
+
m = PyModule_Create(&module_definition);
if (m == NULL)
return -1;
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
index 0fc3ec4..418e42e 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
@@ -82,9 +82,12 @@ int Interface1D_Init(PyObject *module)
Py_INCREF(&Stroke_Type);
PyModule_AddObject(module, "Stroke", (PyObject *)&Stroke_Type);
- PyDict_SetItemString(Stroke_Type.tp_dict, "DRY_MEDIUM", BPy_MediumType_DRY_MEDIUM);
- PyDict_SetItemString(Stroke_Type.tp_dict, "HUMID_MEDIUM", BPy_MediumType_HUMID_MEDIUM);
- PyDict_SetItemString(Stroke_Type.tp_dict, "OPAQUE_MEDIUM", BPy_MediumType_OPAQUE_MEDIUM);
+#define ADD_TYPE_CONST(id) \
+ PyLong_subtype_add_to_dict(Stroke_Type.tp_dict, &MediumType_Type, STRINGIFY(id), Stroke::id)
+ ADD_TYPE_CONST(DRY_MEDIUM);
+ ADD_TYPE_CONST(HUMID_MEDIUM);
+ ADD_TYPE_CONST(OPAQUE_MEDIUM);
+#undef ADD_TYPE_CONST
if (PyType_Ready(&ViewEdge_Type) < 0)
return -1;
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.cpp b/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.cpp
index 240f3f2..19ccd0a 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.cpp
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.cpp
@@ -87,19 +87,6 @@ PyTypeObject MediumType_Type = {
/*-----------------------BPy_IntegrationType instance definitions -------------------------*/
-PyLongObject _BPy_MediumType_DRY_MEDIUM = {
- PyVarObject_HEAD_INIT(&MediumType_Type, 1)
- { Stroke::DRY_MEDIUM }
-};
-PyLongObject _BPy_MediumType_HUMID_MEDIUM = {
- PyVarObject_HEAD_INIT(&MediumType_Type, 1)
- { Stroke::HUMID_MEDIUM }
-};
-PyLongObject _BPy_MediumType_OPAQUE_MEDIUM = {
- PyVarObject_HEAD_INIT(&MediumType_Type, 1)
- { Stroke::OPAQUE_MEDIUM }
-};
-
//-------------------MODULE INITIALIZATION--------------------------------
int MediumType_Init(PyObject *module)
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.h b/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.h
index d99fb53..d527606 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.h
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.h
@@ -52,15 +52,6 @@ typedef struct {
int MediumType_Init(PyObject *module);
-// internal constants
-extern PyLongObject _BPy_MediumType_DRY_MEDIUM;
-extern PyLongObject _BPy_MediumType_HUMID_MEDIUM;
-extern PyLongObject _BPy_MediumType_OPAQUE_MEDIUM;
-// public constants
-#define BPy_MediumType_DRY_MEDIUM ((PyObject *)&_BPy_MediumType_DRY_MEDIUM)
-#define BPy_MediumType_HUMID_MEDIUM ((PyObject *)&_BPy_MediumType_HUMID_MEDIUM)
-#define BPy_MediumType_OPAQUE_MEDIUM ((PyObject *)&_BPy_MediumType_OPAQUE_MEDIUM)
-
///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
diff --git a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Nature.cpp b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Nature.cpp
index deedbb9..fb23587 100644
--- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Nature.cpp
+++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Nature.cpp
@@ -149,83 +149,6 @@ PyTypeObject Nature_Type = {
/*-----------------------BPy_Nature instance definitions ----------------------------------*/
-static PyLongObject _Nature_POINT = {
- PyVarObject_HEAD_INIT(&Nature_Type, 0)
- { Nature::POINT }
-};
-static PyLongObject _Nature_S_VERTEX = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::S_VERTEX }
-};
-static PyLongObject _Nature_VIEW_VERTEX = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::VIEW_VERTEX }
-};
-static PyLongObject _Nature_NON_T_VERTEX = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::NON_T_VERTEX }
-};
-static PyLongObject _Nature_T_VERTEX = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::T_VERTEX }
-};
-static PyLongObject _Nature_CUSP = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::CUSP }
-};
-static PyLongObject _Nature_NO_FEATURE = {
- PyVarObject_HEAD_INIT(&Nature_Type, 0)
- { Nature::NO_FEATURE }
-};
-static PyLongObject _Nature_SILHOUETTE = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::SILHOUETTE }
-};
-static PyLongObject _Nature_BORDER = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::BORDER }
-};
-static PyLongObject _Nature_CREASE = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::CREASE }
-};
-static PyLongObject _Nature_RIDGE = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::RIDGE }
-};
-static PyLongObject _Nature_VALLEY = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::VALLEY }
-};
-static PyLongObject _Nature_SUGGESTIVE_CONTOUR = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::SUGGESTIVE_CONTOUR }
-};
-static PyLongObject _Nature_MATERIAL_BOUNDARY = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::MATERIAL_BOUNDARY }
-};
-static PyLongObject _Nature_EDGE_MARK = {
- PyVarObject_HEAD_INIT(&Nature_Type, 1)
- { Nature::EDGE_MARK }
-};
-
-#define BPy_Nature_POINT ((PyObject *)&_Nature_POINT)
-#define BPy_Nature_S_VERTEX ((PyObject *)&_Nature_S_VERTEX)
-#define BPy_Nature_VIEW_VERTEX ((PyObject *)&_Nature_VIEW_VERTEX)
-#define BPy_Nature_NON_T_VERTEX ((PyObject *)&_Nature_NON_T_VERTEX)
-#define BPy_Nature_T_VERTEX ((PyObject *)&_Nature_T_VERTEX)
-#define BPy_Nature_CUSP ((PyObject *)&_Nature_CUSP)
-#define BPy_Nature_NO_FEATURE ((PyObject *)&_Nature_NO_FEATURE)
-#define BPy_Nature_SILHOUETTE ((PyObject *)&_Nature_SILHOUETTE)
-#define BPy_Nature_BORDER ((PyObject *)&_Nature_BORDER)
-#define BPy_Nature_CREASE ((PyObject *)&_Nature_CREASE)
-#define BPy_Nature_RIDGE ((PyObject *)&_Nature_RIDGE)
-#define BPy_Nature_VALLEY ((PyObject *)&_Nature_VALLEY)
-#define BPy_Nature_SUGGESTIVE_CONTOUR ((PyObject *)&_Nature_SUGGESTIVE_CONTOUR)
-#define BPy_Nature_MATERIAL_BOUNDARY ((PyObject *)&_Nature_MATERIAL_BOUNDARY)
-#define BPy_Nature_EDGE_MARK ((PyObject *)&_Nature_EDGE_MARK)
-
//-------------------MODULE INITIALIZATION--------------------------------
int Nature_Init(PyObject *module)
{
@@ -237,24 +160,29 @@ int Nature_Init(PyObject *module)
Py_INCREF(&Nature_Type);
PyModule_AddObject(module, "Nature", (PyObject *)&Nature_Type);
+#define ADD_TYPE_CONST(id) \
+ PyLong_subtype_add_to_dict(Nature_Type.tp_dict, &Nature_Type, STRINGIFY(id), Nature::id)
+
// VertexNature
- PyDict_SetItemString(Nature_Type.tp_dict, "POINT", BPy_Nature_POINT);
- PyDict_SetItemString(Nature_Type.tp_dict, "S_VERTEX", BPy_Nature_S_VERTEX);
- PyDict_SetItemString(Nature_Type.tp_dict, "VIEW_VERTEX", BPy_Nature_VIEW_VERTEX);
- PyDict_SetItemString(Nature_Type.tp_dict, "NON_T_VERTEX", BPy_Nature_NON_T_VERTEX);
- PyDict_SetItemString(Nature_Type.tp_dict, "T_VERTEX", BPy_Nature_T_VERTEX);
- PyDict_SetItemString(Nature_Type.tp_dict, "CUSP", BPy_Nature_CUSP);
+ ADD_TYPE_CONST(POINT);
+ ADD_TYPE_CONST(S_VERTEX);
+ ADD_TYPE_CONST(VIEW_VERTEX);
+ ADD_TYPE_CONST(NON_T_VERTEX);
+ ADD_TYPE_CONST(T_VERTEX);
+ ADD_TYPE_CONST(CUSP);
// EdgeNature
- PyDict_SetItemString(Nature_Type.tp_dict, "NO_FEATURE", BPy_Nature_NO_FEATURE);
- PyDict_SetItemString(Nature_Type.tp_dict, "SILHOUETTE", BPy_Nature_SILHOUETTE);
- PyDict_SetItemString(Nature_Type.tp_dict, "BORDER", BPy_Nature_BORDER);
- PyDict_SetItemString(Nature_Type.tp_dict, "CREASE", BPy_Nature_CREASE);
- PyDict_SetItemString(Nature_Type.tp_dict, "RIDGE", BPy_Nature_RIDGE);
- PyDict_SetItemString(Nature_Type.tp_dict, "VALLEY", BPy_Nature_VALLEY);
- PyDict_SetItemString(Nature_Type.tp_dict, "SUGGESTIVE_CONTOUR", BPy_Nature_SUGGESTIVE_CONTOUR);
- PyDict_SetItemString(Nature_Type.tp_dict, "MATERIAL_BOUNDARY", BPy_Nature_MATERIAL_BOUNDARY);
- PyDict_SetItemString(Nature_Type.tp_dict, "EDGE_MARK", BPy_Nature_EDGE_MARK);
+ ADD_TYPE_CONST(NO_FEATURE);
+ ADD_TYPE_CONST(SILHOUETTE);
+ ADD_TYPE_CONST(BORDER);
+ ADD_TYPE_CONST(CREASE);
+ ADD_TYPE_CONST(RIDGE);
+ ADD_TYPE_CONST(VALLEY);
+ ADD_TYPE_CONST(SUGGESTIVE_CONTOUR);
+ ADD_TYPE_CONST(MATERIAL_BOUNDARY);
+ ADD_TYPE_CONST(EDGE_MARK);
+
+#undef ADD_TYPE_CONST
return 0;
}
@@ -294,9 +222,7 @@ static PyObject *BPy_Nature_bitwise(PyObject *a, int op, PyObject *b)
if (v == 0)
result = PyObject_NewVar(BPy_Nature, &Nature_Type, 0);
else {
- result = PyObject_NewVar(BPy_Nature, &Nature_Type, 1);
- if (result)
- result->i.ob_digit[0] = v;
+ result = (BPy_Nature *)PyLong_subtype_new(&Nature_Type, v);
}
return (PyObject *)result;
}
|