qpybluetooth_quint128.sip 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // This is the SIP interface definition for the quint128 mapped type.
  2. //
  3. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of PyQt6.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. %If (Qt_6_2_0 -)
  20. %MappedType quint128 /TypeHint="Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int]"/
  21. {
  22. %TypeHeaderCode
  23. #include <qbluetoothuuid.h>
  24. %End
  25. %ConvertFromTypeCode
  26. PyObject *t = PyTuple_New(16);
  27. if (!t)
  28. return 0;
  29. #if defined(QT_SUPPORTS_INT128)
  30. // This was added in Qt v6.6.0.
  31. quint128 value = *sipCpp;
  32. #endif
  33. for (Py_ssize_t i = 0; i < 16; ++i)
  34. {
  35. // Convert to a Python long to make sure it doesn't get interpreted as
  36. // a signed value.
  37. #if defined(QT_SUPPORTS_INT128)
  38. PyObject *pobj = PyLong_FromUnsignedLong(value & 255);
  39. value >>= 8;
  40. #else
  41. PyObject *pobj = PyLong_FromUnsignedLong(sipCpp->data[i]);
  42. #endif
  43. if (!pobj)
  44. {
  45. Py_DECREF(t);
  46. return 0;
  47. }
  48. PyTuple_SetItem(t, i, pobj);
  49. }
  50. return t;
  51. %End
  52. %ConvertToTypeCode
  53. if (!sipIsErr)
  54. return (PySequence_Check(sipPy) && !PyUnicode_Check(sipPy));
  55. Py_ssize_t len = PySequence_Size(sipPy);
  56. if (len != 16)
  57. {
  58. // A negative length should only be an internal error so let the
  59. // original exception stand.
  60. if (len >= 0)
  61. PyErr_Format(PyExc_TypeError,
  62. "sequence has %zd elements but 16 elements are expected",
  63. len);
  64. *sipIsErr = 1;
  65. return 0;
  66. }
  67. quint128 *qv = new quint128;
  68. for (Py_ssize_t i = 15; i >= 0; --i)
  69. {
  70. PyObject *itm = PySequence_GetItem(sipPy, i);
  71. if (!itm)
  72. {
  73. delete qv;
  74. *sipIsErr = 1;
  75. return 0;
  76. }
  77. PyErr_Clear();
  78. unsigned long val = PyLong_AsUnsignedLongMask(itm);
  79. if (PyErr_Occurred())
  80. {
  81. PyErr_Format(PyExc_TypeError,
  82. "element %zd has type '%s' but 'int' is expected", i,
  83. sipPyTypeName(Py_TYPE(itm)));
  84. Py_DECREF(itm);
  85. delete qv;
  86. *sipIsErr = 1;
  87. return 0;
  88. }
  89. #if defined(QT_SUPPORTS_INT128)
  90. // This was added in Qt v6.6.0.
  91. (*qv) <<= 8;
  92. (*qv) |= (val & 255);
  93. #else
  94. qv->data[i] = val;
  95. #endif
  96. Py_DECREF(itm);
  97. }
  98. *sipCppPtr = qv;
  99. return sipGetState(sipTransferObj);
  100. %End
  101. };
  102. %End