Browse Source

Fix SWIG helper functions

test_fixup
Vadim Lebedev 2 years ago
parent
commit
35a412ac1f
3 changed files with 5 additions and 3 deletions
  1. +1
    -1
      libarchive/Makefile
  2. +2
    -1
      libarchive/_libarchive.i
  3. +2
    -1
      libarchive/_libarchive_wrap.c

+ 1
- 1
libarchive/Makefile View File

@@ -2,7 +2,7 @@ CFLAGS = -g
INCLUDE = -I/usr/include -I.
LIBS = -larchive

DEFINES = -DPyUnicode_AS_STRING=PyUnicode_AS_DATA
#DEFINES = -DPyUnicode_AS_STRING=PyUnicode_AS_DATA
PYVER ?= 3.9

all: __libarchive.so


+ 2
- 1
libarchive/_libarchive.i View File

@@ -521,13 +521,14 @@ extern const char *archive_error_string(struct archive *);


%inline %{

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


+ 2
- 1
libarchive/_libarchive_wrap.c View File

@@ -3193,13 +3193,14 @@ SWIG_AsVal_unsigned_SS_short (PyObject * obj, unsigned short *val)
}



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


Loading…
Cancel
Save