- );
-
-static PyObject *
-journal_sendv(PyObject *self, PyObject *args) {
- struct iovec *iov = NULL;
- int argc = PyTuple_Size(args);
- int i, r;
- PyObject *ret = NULL;
-
- PyObject **encoded = calloc(argc, sizeof(PyObject*));
- if (!encoded) {
- ret = PyErr_NoMemory();
- goto out1;
- }
-
- // Allocate sufficient iovector space for the arguments.
- iov = malloc(argc * sizeof(struct iovec));
- if (!iov) {
- ret = PyErr_NoMemory();
- goto out;
- }
-
- // Iterate through the Python arguments and fill the iovector.
- for (i = 0; i < argc; ++i) {
- PyObject *item = PyTuple_GetItem(args, i);
- char *stritem;
- Py_ssize_t length;
-
- if (PyUnicode_Check(item)) {
- encoded[i] = PyUnicode_AsEncodedString(item, "utf-8", "strict");
- if (encoded[i] == NULL)
- goto out;
- item = encoded[i];
+);
+
+static PyObject *journal_sendv(PyObject *self, PyObject *args) {
+ struct iovec *iov = NULL;
+ int argc;
+ int i, r;
+ PyObject *ret = NULL;
+ PyObject **encoded;
+
+ /* Allocate an array for the argument strings */
+ argc = PyTuple_Size(args);
+ encoded = alloca(argc * sizeof(PyObject*));
+ memset(encoded, 0, argc * sizeof(PyObject*));
+
+ /* Allocate sufficient iovector space for the arguments. */
+ iov = alloca(argc * sizeof(struct iovec));
+
+ /* Iterate through the Python arguments and fill the iovector. */
+ for (i = 0; i < argc; ++i) {
+ PyObject *item = PyTuple_GetItem(args, i);
+ char *stritem;
+ Py_ssize_t length;
+
+ if (PyUnicode_Check(item)) {
+ encoded[i] = PyUnicode_AsEncodedString(item, "utf-8", "strict");
+ if (encoded[i] == NULL)
+ goto out;
+ item = encoded[i];
+ }
+ if (PyBytes_AsStringAndSize(item, &stritem, &length))
+ goto out;
+
+ iov[i].iov_base = stritem;
+ iov[i].iov_len = length;