qpyopengl_qlist.sip 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // This is the SIP interface definition for the QList based mapped types
  2. // specific to the QtOpenGL module.
  3. //
  4. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  5. //
  6. // This file is part of PyQt6.
  7. //
  8. // This file may be used under the terms of the GNU General Public License
  9. // version 3.0 as published by the Free Software Foundation and appearing in
  10. // the file LICENSE included in the packaging of this file. Please review the
  11. // following information to ensure the GNU General Public License version 3.0
  12. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  13. //
  14. // If you do not wish to use this file under the terms of the GPL version 3.0
  15. // then you may purchase a commercial license. For more information contact
  16. // info@riverbankcomputing.com.
  17. //
  18. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  19. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. %If (!PyQt_OpenGL_ES2)
  21. %MappedType QList<GLuint64>
  22. /TypeHintIn="Iterable[int]", TypeHintOut="List[int]",
  23. TypeHintValue="[]"/
  24. {
  25. %TypeHeaderCode
  26. #include <qlist.h>
  27. #include <qopengl.h>
  28. %End
  29. %ConvertFromTypeCode
  30. PyObject *l = PyList_New(sipCpp->size());
  31. if (!l)
  32. return 0;
  33. for (int i = 0; i < sipCpp->size(); ++i)
  34. {
  35. // Convert to a Python long to make sure it doesn't get interpreted as
  36. // a signed value.
  37. PyObject *pobj = PyLong_FromUnsignedLongLong(sipCpp->value(i));
  38. if (!pobj)
  39. {
  40. Py_DECREF(l);
  41. return 0;
  42. }
  43. PyList_SetItem(l, i, pobj);
  44. }
  45. return l;
  46. %End
  47. %ConvertToTypeCode
  48. PyObject *iter = PyObject_GetIter(sipPy);
  49. if (!sipIsErr)
  50. {
  51. PyErr_Clear();
  52. Py_XDECREF(iter);
  53. return (iter && !PyBytes_Check(sipPy) && !PyUnicode_Check(sipPy));
  54. }
  55. if (!iter)
  56. {
  57. *sipIsErr = 1;
  58. return 0;
  59. }
  60. QList<GLuint64> *qv = new QList<GLuint64>;
  61. for (Py_ssize_t i = 0; ; ++i)
  62. {
  63. PyErr_Clear();
  64. PyObject *itm = PyIter_Next(iter);
  65. if (!itm)
  66. {
  67. if (PyErr_Occurred())
  68. {
  69. delete qv;
  70. Py_DECREF(iter);
  71. *sipIsErr = 1;
  72. return 0;
  73. }
  74. break;
  75. }
  76. PyErr_Clear();
  77. unsigned long long val = PyLong_AsUnsignedLongLongMask(itm);
  78. if (PyErr_Occurred())
  79. {
  80. PyErr_Format(PyExc_TypeError,
  81. "index %zd has type '%s' but 'int' is expected", i,
  82. sipPyTypeName(Py_TYPE(itm)));
  83. Py_DECREF(itm);
  84. delete qv;
  85. Py_DECREF(iter);
  86. *sipIsErr = 1;
  87. return 0;
  88. }
  89. qv->append(val);
  90. Py_DECREF(itm);
  91. }
  92. Py_DECREF(iter);
  93. *sipCppPtr = qv;
  94. return sipGetState(sipTransferObj);
  95. %End
  96. };
  97. %End