int rtn, use_xy = 0, y = 0, x = 0;
unsigned int max_buf_size = 2048;
unsigned int n = max_buf_size - 1;
- PyObject *res;
if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
"_curses.window.instr"))
}
n = Py_MIN(n, max_buf_size - 1);
- res = PyBytes_FromStringAndSize(NULL, n + 1);
- if (res == NULL) {
+ PyBytesWriter *writer = PyBytesWriter_Create(n + 1);
+ if (writer == NULL) {
return NULL;
}
- char *buf = PyBytes_AS_STRING(res);
+ char *buf = PyBytesWriter_GetData(writer);
if (use_xy) {
Py_BEGIN_ALLOW_THREADS
}
if (rtn == ERR) {
- Py_DECREF(res);
+ PyBytesWriter_Discard(writer);
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
}
- _PyBytes_Resize(&res, strlen(buf)); // 'res' is set to NULL on failure
- return res;
+ return PyBytesWriter_FinishWithSize(writer, strlen(buf));
}
/*[clinic input]
int rtn, use_xy = 0, y = 0, x = 0;
unsigned int max_buf_size = 2048;
unsigned int n = max_buf_size - 1;
- PyObject *res;
if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
"_curses.window.instr"))
}
n = Py_MIN(n, max_buf_size - 1);
- res = PyBytes_FromStringAndSize(NULL, n + 1);
- if (res == NULL) {
+ PyBytesWriter *writer = PyBytesWriter_Create(n + 1);
+ if (writer == NULL) {
return NULL;
}
- char *buf = PyBytes_AS_STRING(res);
+ char *buf = PyBytesWriter_GetData(writer);
if (use_xy) {
rtn = mvwinnstr(self->win, y, x, buf, n);
}
if (rtn == ERR) {
- Py_DECREF(res);
+ PyBytesWriter_Discard(writer);
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
}
- _PyBytes_Resize(&res, strlen(buf)); // 'res' is set to NULL on failure
- return res;
+ return PyBytesWriter_FinishWithSize(writer, strlen(buf));
}
/*[clinic input]