mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
dtoolutil: writelines() should accept any iterable
This commit is contained in:
parent
84ed141b2a
commit
128000b03a
@ -283,19 +283,18 @@ write(PyObject *b) {
|
|||||||
*/
|
*/
|
||||||
void Extension<ostream>::
|
void Extension<ostream>::
|
||||||
writelines(PyObject *lines) {
|
writelines(PyObject *lines) {
|
||||||
PyObject *seq = PySequence_Fast(lines, "writelines() expects a sequence");
|
PyObject *iter = PyObject_GetIter(lines);
|
||||||
if (seq == nullptr) {
|
if (iter == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject **items = PySequence_Fast_ITEMS(seq);
|
PyObject *next = PyIter_Next(iter);
|
||||||
Py_ssize_t len = PySequence_Fast_GET_SIZE(seq);
|
while (next != nullptr) {
|
||||||
|
write(next);
|
||||||
for (Py_ssize_t i = 0; i < len; ++i) {
|
Py_DECREF(next);
|
||||||
write(items[i]);
|
next = PyIter_Next(iter);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(iter);
|
||||||
Py_DECREF(seq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user