libselinux: support new python3 functions

python3 does not have PyString_FromString use PyBytes_FromString
instead. The same for PyString_Check->PyBytes_Check and for
PyString_AsString->PyBytes_AsString

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Eric Paris 2011-06-28 22:39:40 -04:00
parent 4f621a1686
commit 63df0f7ef1

View File

@ -45,7 +45,7 @@ def install(src, dest):
PyObject* list = PyList_New(*$2);
int i;
for (i = 0; i < *$2; i++) {
PyList_SetItem(list, i, PyString_FromString((*$1)[i]));
PyList_SetItem(list, i, PyBytes_FromString((*$1)[i]));
}
$result = SWIG_Python_AppendOutput($result, list);
}
@ -74,7 +74,9 @@ def install(src, dest):
len++;
plist = PyList_New(len);
for (i = 0; i < len; i++) {
PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
PyList_SetItem(plist, i,
PyBytes_FromString((*$1)[i])
);
}
} else {
plist = PyList_New(0);
@ -91,7 +93,9 @@ def install(src, dest):
if (*$1) {
plist = PyList_New(result);
for (i = 0; i < result; i++) {
PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
PyList_SetItem(plist, i,
PyBytes_FromString((*$1)[i])
);
}
} else {
plist = PyList_New(0);
@ -144,16 +148,20 @@ def install(src, dest):
$1 = (char**) malloc(size + 1);
for(i = 0; i < size; i++) {
if (!PyString_Check(PySequence_GetItem($input, i))) {
PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings");
if (!PyBytes_Check(PySequence_GetItem($input, i))) {
PyErr_SetString(PyExc_ValueError, "Sequence must contain only bytes");
return NULL;
}
}
for(i = 0; i < size; i++) {
s = PySequence_GetItem($input, i);
$1[i] = (char*) malloc(PyString_Size(s) + 1);
strcpy($1[i], PyString_AsString(s));
$1[i] = (char*) malloc(PyBytes_Size(s) + 1);
strcpy($1[i], PyBytes_AsString(s));
}
$1[size] = NULL;
}