Browse Source

fixes archive_read_data_into_str to return python byte array

test_fixup
Vadim Lebedev 2 years ago
parent
commit
9c0f6391e0
2 changed files with 4 additions and 4 deletions
  1. +2
    -2
      libarchive/_libarchive.i
  2. +2
    -2
      libarchive/_libarchive_wrap.c

+ 2
- 2
libarchive/_libarchive.i View File

@@ -524,11 +524,11 @@ extern const char *archive_error_string(struct archive *);


PyObject *archive_read_data_into_str(struct archive *archive, int len) { PyObject *archive_read_data_into_str(struct archive *archive, int len) {
PyObject *str = NULL; PyObject *str = NULL;
if (!(str = PyUnicode_FromStringAndSize(NULL, len))) {
if (!(str = PyBytes_FromStringAndSize(NULL, len))) {
PyErr_SetString(PyExc_MemoryError, "could not allocate string."); PyErr_SetString(PyExc_MemoryError, "could not allocate string.");
return NULL; return NULL;
} }
if (len != archive_read_data(archive, PyUnicode_AS_DATA(str), len)) {
if (len != archive_read_data(archive, PyBytes_AS_STRING(str), len)) {
PyErr_SetString(PyExc_RuntimeError, "could not read requested data."); PyErr_SetString(PyExc_RuntimeError, "could not read requested data.");
return NULL; return NULL;
} }


+ 2
- 2
libarchive/_libarchive_wrap.c View File

@@ -3196,11 +3196,11 @@ SWIG_AsVal_unsigned_SS_short (PyObject * obj, unsigned short *val)


PyObject *archive_read_data_into_str(struct archive *archive, int len) { PyObject *archive_read_data_into_str(struct archive *archive, int len) {
PyObject *str = NULL; PyObject *str = NULL;
if (!(str = PyUnicode_FromStringAndSize(NULL, len))) {
if (!(str = PyBytes_FromStringAndSize(NULL, len))) {
PyErr_SetString(PyExc_MemoryError, "could not allocate string."); PyErr_SetString(PyExc_MemoryError, "could not allocate string.");
return NULL; return NULL;
} }
if (len != archive_read_data(archive, PyUnicode_AS_DATA(str), len)) {
if (len != archive_read_data(archive, PyBytes_AS_STRING(str), len)) {
PyErr_SetString(PyExc_RuntimeError, "could not read requested data."); PyErr_SetString(PyExc_RuntimeError, "could not read requested data.");
return NULL; return NULL;
} }


Loading…
Cancel
Save