0008_python3_9.patch 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. commit cef9646dbecd745b70f10501477fd7497e874f19
  2. Author: CYBERDEViL <cyberdevil@notabug.org>
  3. Date: Sun Dec 17 01:22:11 2023 +0100
  4. python3.9: "Fix crash starting Blender with Python 3.9"
  5. Fully applied Blender upstream ref: 0133bcaf38f6ecb5d6937c9b762026cc452720de
  6. commit 500ea8f791406747ec430e654cabe8a5a90f5dad
  7. Author: CYBERDEViL <cyberdevil@notabug.org>
  8. Date: Sun Dec 17 01:07:33 2023 +0100
  9. python3.9: "Fix T81688: BPY_thread_save crashes with Python 3.9"
  10. Fully applied Blender upstream ref: 5edba9b42f684bf8b99894bb6988e7f46180e12c
  11. commit 1a02a89e57a5fcd61da7cf7c2949250ccc88c6bf
  12. Author: CYBERDEViL <cyberdevil@notabug.org>
  13. Date: Sat Dec 16 02:10:10 2023 +0100
  14. python3.9: "Python: support building again version 3.9 (unreleased)"
  15. Fully applied Blender upstream ref: 56d0df51a36fdce7ec2d1fbb7b47b1d95b591b5f
  16. diff --git a/blender-2.79b/source/blender/python/generic/bpy_threads.c b/blender-2.79b/source/blender/python/generic/bpy_threads.c
  17. index fbc1456..628e28f 100644
  18. --- a/blender-2.79b/source/blender/python/generic/bpy_threads.c
  19. +++ b/blender-2.79b/source/blender/python/generic/bpy_threads.c
  20. @@ -35,14 +35,11 @@
  21. /* analogue of PyEval_SaveThread() */
  22. BPy_ThreadStatePtr BPY_thread_save(void)
  23. {
  24. - PyThreadState *tstate = PyThreadState_Swap(NULL);
  25. - /* note: tstate can be NULL when quitting Blender */
  26. -
  27. - if (tstate && PyEval_ThreadsInitialized()) {
  28. - PyEval_ReleaseLock();
  29. + /* The thread-state can be NULL when quitting Blender. */
  30. + if (_PyThreadState_UncheckedGet()) {
  31. + return (BPy_ThreadStatePtr)PyEval_SaveThread();
  32. }
  33. -
  34. - return (BPy_ThreadStatePtr)tstate;
  35. + return NULL;
  36. }
  37. /* analogue of PyEval_RestoreThread() */
  38. diff --git a/blender-2.79b/source/blender/python/intern/bpy_rna.c b/blender-2.79b/source/blender/python/intern/bpy_rna.c
  39. index b473398..26a4351 100644
  40. --- a/blender-2.79b/source/blender/python/intern/bpy_rna.c
  41. +++ b/blender-2.79b/source/blender/python/intern/bpy_rna.c
  42. @@ -7321,13 +7321,15 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
  43. PyErr_Clear();
  44. }
  45. else {
  46. - Py_DECREF(item); /* no need to keep a ref, the class owns it (technically we should keep a ref but...) */
  47. + /* Store original so we can decrement it's reference before returning. */
  48. + PyObject *item_orig = item;
  49. if (is_staticmethod) {
  50. if (PyMethod_Check(item) == 0) {
  51. PyErr_Format(PyExc_TypeError,
  52. "expected %.200s, %.200s class \"%.200s\" "
  53. "attribute to be a static/class method, not a %.200s",
  54. class_type, py_class_name, RNA_function_identifier(func), Py_TYPE(item)->tp_name);
  55. + Py_DECREF(item_orig);
  56. return -1;
  57. }
  58. item = ((PyMethodObject *)item)->im_func;
  59. @@ -7338,6 +7340,7 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
  60. "expected %.200s, %.200s class \"%.200s\" "
  61. "attribute to be a function, not a %.200s",
  62. class_type, py_class_name, RNA_function_identifier(func), Py_TYPE(item)->tp_name);
  63. + Py_DECREF(item_orig);
  64. return -1;
  65. }
  66. }
  67. @@ -7369,9 +7372,11 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
  68. class_type, py_class_name, RNA_function_identifier(func),
  69. func_arg_count, arg_count);
  70. }
  71. + Py_DECREF(item_orig);
  72. return -1;
  73. }
  74. }
  75. + Py_DECREF(item_orig);
  76. }
  77. }
  78. diff --git a/blender-2.79b/source/blender/python/mathutils/mathutils_Matrix.c b/blender-2.79b/source/blender/python/mathutils/mathutils_Matrix.c
  79. index 1b05aae..0805ab1 100644
  80. --- a/blender-2.79b/source/blender/python/mathutils/mathutils_Matrix.c
  81. +++ b/blender-2.79b/source/blender/python/mathutils/mathutils_Matrix.c
  82. @@ -48,7 +48,8 @@ static PyObject *Matrix_copy_notest(MatrixObject *self, const float *matrix);
  83. static PyObject *Matrix_copy(MatrixObject *self);
  84. static PyObject *Matrix_deepcopy(MatrixObject *self, PyObject *args);
  85. static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value);
  86. -static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self);
  87. +static PyObject *matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *),
  88. + MatrixObject *self);
  89. static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type);
  90. static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row)
  91. @@ -385,14 +386,15 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  92. return NULL;
  93. }
  94. -static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self)
  95. +static PyObject *matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *),
  96. + MatrixObject *self)
  97. {
  98. PyObject *ret = Matrix_copy(self);
  99. if (ret) {
  100. - PyObject *ret_dummy = matrix_func(ret);
  101. + PyObject *ret_dummy = matrix_func((MatrixObject *)ret);
  102. if (ret_dummy) {
  103. Py_DECREF(ret_dummy);
  104. - return (PyObject *)ret;
  105. + return ret;
  106. }
  107. else { /* error */
  108. Py_DECREF(ret);
  109. @@ -1598,7 +1600,7 @@ PyDoc_STRVAR(Matrix_adjugated_doc,
  110. );
  111. static PyObject *Matrix_adjugated(MatrixObject *self)
  112. {
  113. - return matrix__apply_to_copy((PyNoArgsFunction)Matrix_adjugate, self);
  114. + return matrix__apply_to_copy(Matrix_adjugate, self);
  115. }
  116. PyDoc_STRVAR(Matrix_rotate_doc,
  117. @@ -1795,7 +1797,7 @@ PyDoc_STRVAR(Matrix_transposed_doc,
  118. );
  119. static PyObject *Matrix_transposed(MatrixObject *self)
  120. {
  121. - return matrix__apply_to_copy((PyNoArgsFunction)Matrix_transpose, self);
  122. + return matrix__apply_to_copy(Matrix_transpose, self);
  123. }
  124. /*---------------------------matrix.normalize() ------------------*/
  125. @@ -1842,7 +1844,7 @@ PyDoc_STRVAR(Matrix_normalized_doc,
  126. );
  127. static PyObject *Matrix_normalized(MatrixObject *self)
  128. {
  129. - return matrix__apply_to_copy((PyNoArgsFunction)Matrix_normalize, self);
  130. + return matrix__apply_to_copy(Matrix_normalize, self);
  131. }
  132. /*---------------------------matrix.zero() -----------------------*/
  133. diff --git a/blender-2.79b/source/blender/python/mathutils/mathutils_Quaternion.c b/blender-2.79b/source/blender/python/mathutils/mathutils_Quaternion.c
  134. index 02aabd0..c8eeaa2 100644
  135. --- a/blender-2.79b/source/blender/python/mathutils/mathutils_Quaternion.c
  136. +++ b/blender-2.79b/source/blender/python/mathutils/mathutils_Quaternion.c
  137. @@ -40,7 +40,8 @@
  138. #define QUAT_SIZE 4
  139. -static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self);
  140. +static PyObject *quat__apply_to_copy(PyObject *(*quat_func)(QuaternionObject *),
  141. + QuaternionObject *self);
  142. static void quat__axis_angle_sanitize(float axis[3], float *angle);
  143. static PyObject *Quaternion_copy(QuaternionObject *self);
  144. static PyObject *Quaternion_deepcopy(QuaternionObject *self, PyObject *args);
  145. @@ -381,7 +382,7 @@ PyDoc_STRVAR(Quaternion_normalized_doc,
  146. );
  147. static PyObject *Quaternion_normalized(QuaternionObject *self)
  148. {
  149. - return quat__apply_to_copy((PyNoArgsFunction)Quaternion_normalize, self);
  150. + return quat__apply_to_copy(Quaternion_normalize, self);
  151. }
  152. PyDoc_STRVAR(Quaternion_invert_doc,
  153. @@ -409,7 +410,7 @@ PyDoc_STRVAR(Quaternion_inverted_doc,
  154. );
  155. static PyObject *Quaternion_inverted(QuaternionObject *self)
  156. {
  157. - return quat__apply_to_copy((PyNoArgsFunction)Quaternion_invert, self);
  158. + return quat__apply_to_copy(Quaternion_invert, self);
  159. }
  160. PyDoc_STRVAR(Quaternion_identity_doc,
  161. @@ -473,7 +474,7 @@ PyDoc_STRVAR(Quaternion_conjugated_doc,
  162. );
  163. static PyObject *Quaternion_conjugated(QuaternionObject *self)
  164. {
  165. - return quat__apply_to_copy((PyNoArgsFunction)Quaternion_conjugate, self);
  166. + return quat__apply_to_copy(Quaternion_conjugate, self);
  167. }
  168. PyDoc_STRVAR(Quaternion_copy_doc,
  169. @@ -1146,10 +1147,11 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
  170. return Quaternion_CreatePyObject(quat, type);
  171. }
  172. -static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self)
  173. +static PyObject *quat__apply_to_copy(PyObject *(*quat_func)(QuaternionObject *),
  174. + QuaternionObject *self)
  175. {
  176. PyObject *ret = Quaternion_copy(self);
  177. - PyObject *ret_dummy = quat_func(ret);
  178. + PyObject *ret_dummy = quat_func((QuaternionObject *)ret);
  179. if (ret_dummy) {
  180. Py_DECREF(ret_dummy);
  181. return ret;
  182. diff --git a/blender-2.79b/source/blender/python/mathutils/mathutils_Vector.c b/blender-2.79b/source/blender/python/mathutils/mathutils_Vector.c
  183. index af73aa2..18ecf2f 100644
  184. --- a/blender-2.79b/source/blender/python/mathutils/mathutils_Vector.c
  185. +++ b/blender-2.79b/source/blender/python/mathutils/mathutils_Vector.c
  186. @@ -92,10 +92,10 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  187. return Vector_CreatePyObject_alloc(vec, size, type);
  188. }
  189. -static PyObject *vec__apply_to_copy(PyNoArgsFunction vec_func, VectorObject *self)
  190. +static PyObject *vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), VectorObject *self)
  191. {
  192. PyObject *ret = Vector_copy(self);
  193. - PyObject *ret_dummy = vec_func(ret);
  194. + PyObject *ret_dummy = vec_func((VectorObject *)ret);
  195. if (ret_dummy) {
  196. Py_DECREF(ret_dummy);
  197. return (PyObject *)ret;
  198. @@ -378,7 +378,7 @@ PyDoc_STRVAR(Vector_normalized_doc,
  199. );
  200. static PyObject *Vector_normalized(VectorObject *self)
  201. {
  202. - return vec__apply_to_copy((PyNoArgsFunction)Vector_normalize, self);
  203. + return vec__apply_to_copy(Vector_normalize, self);
  204. }
  205. PyDoc_STRVAR(Vector_resize_doc,