0011_python3_12.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. commit 92d569e51aeb3b5f32b03768f423136a0642d445
  2. Author: CYBERDEV <cyberdevil-no-reply@notabug.org>
  3. Date: Thu Jun 6 00:03:30 2024 +0200
  4. python3.12: "Fix building FreeStyle with Python 3.12"
  5. Fully applied Blender upstream ref
  6. 252ae7029db3bc61a2740bb2cabeda8328b70f30
  7. 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
  8. index 4e1a0a1..fa47dec 100644
  9. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.cpp
  10. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.cpp
  11. @@ -76,6 +76,32 @@ PyObject *PyBool_from_bool(bool b)
  12. return PyBool_FromLong(b ? 1 : 0);
  13. }
  14. +PyObject *PyLong_subtype_new(PyTypeObject *ty, long value)
  15. +{
  16. + BLI_assert(ty->tp_basicsize == sizeof(PyLongObject));
  17. + PyLongObject *result = PyObject_NewVar(PyLongObject, ty, 1);
  18. +#if PY_VERSION_HEX >= 0x030c0000
  19. + {
  20. + /* Account for change in `PyLongObject` in Python 3.12+.
  21. + * The values of longs are no longer accessible via public API's, copy the value instead. */
  22. + PyLongObject *value_py = (PyLongObject *)PyLong_FromLong(value);
  23. + memcpy(&result->long_value, &value_py->long_value, sizeof(result->long_value));
  24. + Py_DECREF(value_py);
  25. + }
  26. +#else
  27. + result->ob_digit[0] = value;
  28. +#endif
  29. + return (PyObject *)result;
  30. +}
  31. +
  32. +void PyLong_subtype_add_to_dict(PyObject *dict, PyTypeObject *ty, const char *attr, long value)
  33. +{
  34. + PyObject *result = PyLong_subtype_new(ty, value);
  35. + PyDict_SetItemString(dict, attr, result);
  36. + /* Owned by the dictionary. */
  37. + Py_DECREF(result);
  38. +}
  39. +
  40. PyObject *Vector_from_Vec2f(Vec2f& vec)
  41. {
  42. float vec_data[2]; // because vec->_coord is protected
  43. 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
  44. index 35c1e58..c71990d 100644
  45. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.h
  46. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Convert.h
  47. @@ -98,6 +98,9 @@ extern "C" {
  48. // C++ => Python
  49. //==============================
  50. +PyObject *PyLong_subtype_new(PyTypeObject *ty, long value);
  51. +void PyLong_subtype_add_to_dict(PyObject *dict, PyTypeObject *ty, const char *attr, long value);
  52. +
  53. PyObject * PyBool_from_bool(bool b);
  54. PyObject * Vector_from_Vec2f(Vec2f& v);
  55. PyObject * Vector_from_Vec3f(Vec3f& v);
  56. 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
  57. index 0db2575..df7eb1e 100644
  58. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
  59. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
  60. @@ -185,33 +185,6 @@ PyTypeObject IntegrationType_Type = {
  61. /*-----------------------BPy_IntegrationType instance definitions -------------------------*/
  62. -static PyLongObject _IntegrationType_MEAN = {
  63. - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
  64. - { MEAN }
  65. -};
  66. -static PyLongObject _IntegrationType_MIN = {
  67. - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
  68. - { MIN }
  69. -};
  70. -static PyLongObject _IntegrationType_MAX = {
  71. - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
  72. - { MAX }
  73. -};
  74. -static PyLongObject _IntegrationType_FIRST = {
  75. - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
  76. - { FIRST }
  77. -};
  78. -static PyLongObject _IntegrationType_LAST = {
  79. - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1)
  80. - { LAST }
  81. -};
  82. -
  83. -#define BPy_IntegrationType_MEAN ((PyObject *)&_IntegrationType_MEAN)
  84. -#define BPy_IntegrationType_MIN ((PyObject *)&_IntegrationType_MIN)
  85. -#define BPy_IntegrationType_MAX ((PyObject *)&_IntegrationType_MAX)
  86. -#define BPy_IntegrationType_FIRST ((PyObject *)&_IntegrationType_FIRST)
  87. -#define BPy_IntegrationType_LAST ((PyObject *)&_IntegrationType_LAST)
  88. -
  89. //-------------------MODULE INITIALIZATION--------------------------------
  90. int IntegrationType_Init(PyObject *module)
  91. {
  92. @@ -225,12 +198,18 @@ int IntegrationType_Init(PyObject *module)
  93. Py_INCREF(&IntegrationType_Type);
  94. PyModule_AddObject(module, "IntegrationType", (PyObject *)&IntegrationType_Type);
  95. - PyDict_SetItemString(IntegrationType_Type.tp_dict, "MEAN", BPy_IntegrationType_MEAN);
  96. - PyDict_SetItemString(IntegrationType_Type.tp_dict, "MIN", BPy_IntegrationType_MIN);
  97. - PyDict_SetItemString(IntegrationType_Type.tp_dict, "MAX", BPy_IntegrationType_MAX);
  98. - PyDict_SetItemString(IntegrationType_Type.tp_dict, "FIRST", BPy_IntegrationType_FIRST);
  99. - PyDict_SetItemString(IntegrationType_Type.tp_dict, "LAST", BPy_IntegrationType_LAST);
  100. -
  101. +#define ADD_TYPE_CONST(id) \
  102. + PyLong_subtype_add_to_dict( \
  103. + IntegrationType_Type.tp_dict, &IntegrationType_Type, STRINGIFY(id), id)
  104. +
  105. + ADD_TYPE_CONST(MEAN);
  106. + ADD_TYPE_CONST(MIN);
  107. + ADD_TYPE_CONST(MAX);
  108. + ADD_TYPE_CONST(FIRST);
  109. + ADD_TYPE_CONST(LAST);
  110. +
  111. +#undef ADD_TYPE_CONST
  112. +
  113. m = PyModule_Create(&module_definition);
  114. if (m == NULL)
  115. return -1;
  116. 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
  117. index 0fc3ec4..418e42e 100644
  118. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
  119. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
  120. @@ -82,9 +82,12 @@ int Interface1D_Init(PyObject *module)
  121. Py_INCREF(&Stroke_Type);
  122. PyModule_AddObject(module, "Stroke", (PyObject *)&Stroke_Type);
  123. - PyDict_SetItemString(Stroke_Type.tp_dict, "DRY_MEDIUM", BPy_MediumType_DRY_MEDIUM);
  124. - PyDict_SetItemString(Stroke_Type.tp_dict, "HUMID_MEDIUM", BPy_MediumType_HUMID_MEDIUM);
  125. - PyDict_SetItemString(Stroke_Type.tp_dict, "OPAQUE_MEDIUM", BPy_MediumType_OPAQUE_MEDIUM);
  126. +#define ADD_TYPE_CONST(id) \
  127. + PyLong_subtype_add_to_dict(Stroke_Type.tp_dict, &MediumType_Type, STRINGIFY(id), Stroke::id)
  128. + ADD_TYPE_CONST(DRY_MEDIUM);
  129. + ADD_TYPE_CONST(HUMID_MEDIUM);
  130. + ADD_TYPE_CONST(OPAQUE_MEDIUM);
  131. +#undef ADD_TYPE_CONST
  132. if (PyType_Ready(&ViewEdge_Type) < 0)
  133. return -1;
  134. 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
  135. index 240f3f2..19ccd0a 100644
  136. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.cpp
  137. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.cpp
  138. @@ -87,19 +87,6 @@ PyTypeObject MediumType_Type = {
  139. /*-----------------------BPy_IntegrationType instance definitions -------------------------*/
  140. -PyLongObject _BPy_MediumType_DRY_MEDIUM = {
  141. - PyVarObject_HEAD_INIT(&MediumType_Type, 1)
  142. - { Stroke::DRY_MEDIUM }
  143. -};
  144. -PyLongObject _BPy_MediumType_HUMID_MEDIUM = {
  145. - PyVarObject_HEAD_INIT(&MediumType_Type, 1)
  146. - { Stroke::HUMID_MEDIUM }
  147. -};
  148. -PyLongObject _BPy_MediumType_OPAQUE_MEDIUM = {
  149. - PyVarObject_HEAD_INIT(&MediumType_Type, 1)
  150. - { Stroke::OPAQUE_MEDIUM }
  151. -};
  152. -
  153. //-------------------MODULE INITIALIZATION--------------------------------
  154. int MediumType_Init(PyObject *module)
  155. 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
  156. index d99fb53..d527606 100644
  157. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.h
  158. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_MediumType.h
  159. @@ -52,15 +52,6 @@ typedef struct {
  160. int MediumType_Init(PyObject *module);
  161. -// internal constants
  162. -extern PyLongObject _BPy_MediumType_DRY_MEDIUM;
  163. -extern PyLongObject _BPy_MediumType_HUMID_MEDIUM;
  164. -extern PyLongObject _BPy_MediumType_OPAQUE_MEDIUM;
  165. -// public constants
  166. -#define BPy_MediumType_DRY_MEDIUM ((PyObject *)&_BPy_MediumType_DRY_MEDIUM)
  167. -#define BPy_MediumType_HUMID_MEDIUM ((PyObject *)&_BPy_MediumType_HUMID_MEDIUM)
  168. -#define BPy_MediumType_OPAQUE_MEDIUM ((PyObject *)&_BPy_MediumType_OPAQUE_MEDIUM)
  169. -
  170. ///////////////////////////////////////////////////////////////////////////////////////////
  171. #ifdef __cplusplus
  172. 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
  173. index deedbb9..fb23587 100644
  174. --- a/blender-2.79b/source/blender/freestyle/intern/python/BPy_Nature.cpp
  175. +++ b/blender-2.79b/source/blender/freestyle/intern/python/BPy_Nature.cpp
  176. @@ -149,83 +149,6 @@ PyTypeObject Nature_Type = {
  177. /*-----------------------BPy_Nature instance definitions ----------------------------------*/
  178. -static PyLongObject _Nature_POINT = {
  179. - PyVarObject_HEAD_INIT(&Nature_Type, 0)
  180. - { Nature::POINT }
  181. -};
  182. -static PyLongObject _Nature_S_VERTEX = {
  183. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  184. - { Nature::S_VERTEX }
  185. -};
  186. -static PyLongObject _Nature_VIEW_VERTEX = {
  187. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  188. - { Nature::VIEW_VERTEX }
  189. -};
  190. -static PyLongObject _Nature_NON_T_VERTEX = {
  191. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  192. - { Nature::NON_T_VERTEX }
  193. -};
  194. -static PyLongObject _Nature_T_VERTEX = {
  195. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  196. - { Nature::T_VERTEX }
  197. -};
  198. -static PyLongObject _Nature_CUSP = {
  199. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  200. - { Nature::CUSP }
  201. -};
  202. -static PyLongObject _Nature_NO_FEATURE = {
  203. - PyVarObject_HEAD_INIT(&Nature_Type, 0)
  204. - { Nature::NO_FEATURE }
  205. -};
  206. -static PyLongObject _Nature_SILHOUETTE = {
  207. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  208. - { Nature::SILHOUETTE }
  209. -};
  210. -static PyLongObject _Nature_BORDER = {
  211. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  212. - { Nature::BORDER }
  213. -};
  214. -static PyLongObject _Nature_CREASE = {
  215. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  216. - { Nature::CREASE }
  217. -};
  218. -static PyLongObject _Nature_RIDGE = {
  219. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  220. - { Nature::RIDGE }
  221. -};
  222. -static PyLongObject _Nature_VALLEY = {
  223. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  224. - { Nature::VALLEY }
  225. -};
  226. -static PyLongObject _Nature_SUGGESTIVE_CONTOUR = {
  227. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  228. - { Nature::SUGGESTIVE_CONTOUR }
  229. -};
  230. -static PyLongObject _Nature_MATERIAL_BOUNDARY = {
  231. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  232. - { Nature::MATERIAL_BOUNDARY }
  233. -};
  234. -static PyLongObject _Nature_EDGE_MARK = {
  235. - PyVarObject_HEAD_INIT(&Nature_Type, 1)
  236. - { Nature::EDGE_MARK }
  237. -};
  238. -
  239. -#define BPy_Nature_POINT ((PyObject *)&_Nature_POINT)
  240. -#define BPy_Nature_S_VERTEX ((PyObject *)&_Nature_S_VERTEX)
  241. -#define BPy_Nature_VIEW_VERTEX ((PyObject *)&_Nature_VIEW_VERTEX)
  242. -#define BPy_Nature_NON_T_VERTEX ((PyObject *)&_Nature_NON_T_VERTEX)
  243. -#define BPy_Nature_T_VERTEX ((PyObject *)&_Nature_T_VERTEX)
  244. -#define BPy_Nature_CUSP ((PyObject *)&_Nature_CUSP)
  245. -#define BPy_Nature_NO_FEATURE ((PyObject *)&_Nature_NO_FEATURE)
  246. -#define BPy_Nature_SILHOUETTE ((PyObject *)&_Nature_SILHOUETTE)
  247. -#define BPy_Nature_BORDER ((PyObject *)&_Nature_BORDER)
  248. -#define BPy_Nature_CREASE ((PyObject *)&_Nature_CREASE)
  249. -#define BPy_Nature_RIDGE ((PyObject *)&_Nature_RIDGE)
  250. -#define BPy_Nature_VALLEY ((PyObject *)&_Nature_VALLEY)
  251. -#define BPy_Nature_SUGGESTIVE_CONTOUR ((PyObject *)&_Nature_SUGGESTIVE_CONTOUR)
  252. -#define BPy_Nature_MATERIAL_BOUNDARY ((PyObject *)&_Nature_MATERIAL_BOUNDARY)
  253. -#define BPy_Nature_EDGE_MARK ((PyObject *)&_Nature_EDGE_MARK)
  254. -
  255. //-------------------MODULE INITIALIZATION--------------------------------
  256. int Nature_Init(PyObject *module)
  257. {
  258. @@ -237,24 +160,29 @@ int Nature_Init(PyObject *module)
  259. Py_INCREF(&Nature_Type);
  260. PyModule_AddObject(module, "Nature", (PyObject *)&Nature_Type);
  261. +#define ADD_TYPE_CONST(id) \
  262. + PyLong_subtype_add_to_dict(Nature_Type.tp_dict, &Nature_Type, STRINGIFY(id), Nature::id)
  263. +
  264. // VertexNature
  265. - PyDict_SetItemString(Nature_Type.tp_dict, "POINT", BPy_Nature_POINT);
  266. - PyDict_SetItemString(Nature_Type.tp_dict, "S_VERTEX", BPy_Nature_S_VERTEX);
  267. - PyDict_SetItemString(Nature_Type.tp_dict, "VIEW_VERTEX", BPy_Nature_VIEW_VERTEX);
  268. - PyDict_SetItemString(Nature_Type.tp_dict, "NON_T_VERTEX", BPy_Nature_NON_T_VERTEX);
  269. - PyDict_SetItemString(Nature_Type.tp_dict, "T_VERTEX", BPy_Nature_T_VERTEX);
  270. - PyDict_SetItemString(Nature_Type.tp_dict, "CUSP", BPy_Nature_CUSP);
  271. + ADD_TYPE_CONST(POINT);
  272. + ADD_TYPE_CONST(S_VERTEX);
  273. + ADD_TYPE_CONST(VIEW_VERTEX);
  274. + ADD_TYPE_CONST(NON_T_VERTEX);
  275. + ADD_TYPE_CONST(T_VERTEX);
  276. + ADD_TYPE_CONST(CUSP);
  277. // EdgeNature
  278. - PyDict_SetItemString(Nature_Type.tp_dict, "NO_FEATURE", BPy_Nature_NO_FEATURE);
  279. - PyDict_SetItemString(Nature_Type.tp_dict, "SILHOUETTE", BPy_Nature_SILHOUETTE);
  280. - PyDict_SetItemString(Nature_Type.tp_dict, "BORDER", BPy_Nature_BORDER);
  281. - PyDict_SetItemString(Nature_Type.tp_dict, "CREASE", BPy_Nature_CREASE);
  282. - PyDict_SetItemString(Nature_Type.tp_dict, "RIDGE", BPy_Nature_RIDGE);
  283. - PyDict_SetItemString(Nature_Type.tp_dict, "VALLEY", BPy_Nature_VALLEY);
  284. - PyDict_SetItemString(Nature_Type.tp_dict, "SUGGESTIVE_CONTOUR", BPy_Nature_SUGGESTIVE_CONTOUR);
  285. - PyDict_SetItemString(Nature_Type.tp_dict, "MATERIAL_BOUNDARY", BPy_Nature_MATERIAL_BOUNDARY);
  286. - PyDict_SetItemString(Nature_Type.tp_dict, "EDGE_MARK", BPy_Nature_EDGE_MARK);
  287. + ADD_TYPE_CONST(NO_FEATURE);
  288. + ADD_TYPE_CONST(SILHOUETTE);
  289. + ADD_TYPE_CONST(BORDER);
  290. + ADD_TYPE_CONST(CREASE);
  291. + ADD_TYPE_CONST(RIDGE);
  292. + ADD_TYPE_CONST(VALLEY);
  293. + ADD_TYPE_CONST(SUGGESTIVE_CONTOUR);
  294. + ADD_TYPE_CONST(MATERIAL_BOUNDARY);
  295. + ADD_TYPE_CONST(EDGE_MARK);
  296. +
  297. +#undef ADD_TYPE_CONST
  298. return 0;
  299. }
  300. @@ -294,9 +222,7 @@ static PyObject *BPy_Nature_bitwise(PyObject *a, int op, PyObject *b)
  301. if (v == 0)
  302. result = PyObject_NewVar(BPy_Nature, &Nature_Type, 0);
  303. else {
  304. - result = PyObject_NewVar(BPy_Nature, &Nature_Type, 1);
  305. - if (result)
  306. - result->i.ob_digit[0] = v;
  307. + result = (BPy_Nature *)PyLong_subtype_new(&Nature_Type, v);
  308. }
  309. return (PyObject *)result;
  310. }