0001-python-enum-fix-build-for-Python-3.11.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From fbaec4b4e6fe735efe6916fe5b92805a0d96bf8a Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
  3. <congdanhqx@gmail.com>
  4. Date: Wed, 21 Sep 2022 10:32:11 +0700
  5. Subject: [PATCH] python: enum: fix build for Python 3.11
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Python 3.9 introduced Py_SET_SIZE function to set size instead of
  10. relying on Py_SIZE() as a macro [3.9].
  11. Python 3.10 started to encourage to use Py_SET_SIZE instead of
  12. assigning into return value of Py_SIZE [3.10].
  13. Python 3.11 flips the switch, turn Py_SIZE into a function [3.11],
  14. thus Py_SIZE(obj) will be a rvalue. We need to use Py_SET_SIZE
  15. to set size now.
  16. [3.9]: https://docs.python.org/3.9/c-api/structures.html#c.Py_SET_SIZE
  17. [3.10]: https://docs.python.org/3.10/c-api/structures.html#c.Py_SIZE
  18. [3.11]: https://docs.python.org/3.11/c-api/structures.html#c.Py_SIZE
  19. Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
  20. Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
  21. [Upstream status:
  22. https://github.com/mchehab/zbar/pull/231]
  23. ---
  24. python/enum.c | 8 ++++++++
  25. 1 file changed, 8 insertions(+)
  26. diff --git a/python/enum.c b/python/enum.c
  27. index dfe1b1e..946344f 100644
  28. --- a/python/enum.c
  29. +++ b/python/enum.c
  30. @@ -52,7 +52,11 @@ enumitem_new (PyTypeObject *type,
  31. /* we assume the "fast path" for a single-digit ints (see longobject.c) */
  32. /* this also holds if we get a small_int preallocated long */
  33. +#if PY_VERSION_HEX >= 0x03090000
  34. + Py_SET_SIZE(&self->val, Py_SIZE(longval));
  35. +#else
  36. Py_SIZE(&self->val) = Py_SIZE(longval);
  37. +#endif
  38. self->val.ob_digit[0] = longval->ob_digit[0];
  39. Py_DECREF(longval);
  40. #else
  41. @@ -143,7 +147,11 @@ zbarEnumItem_New (PyObject *byname,
  42. /* we assume the "fast path" for a single-digit ints (see longobject.c) */
  43. /* this also holds if we get a small_int preallocated long */
  44. +#if PY_VERSION_HEX >= 0x03090000
  45. + Py_SET_SIZE(&self->val, Py_SIZE(longval));
  46. +#else
  47. Py_SIZE(&self->val) = Py_SIZE(longval);
  48. +#endif
  49. self->val.ob_digit[0] = longval->ob_digit[0];
  50. Py_DECREF(longval);
  51. --
  52. 2.34.1