...
 
Commits (2)
......@@ -4,15 +4,7 @@ stages:
- test
- pages
python2:
stage: test
before_script:
- pip install .
- export LD_LIBRARY_PATH=/usr/local/lib
script:
- python -m pytest tests
python3:
unittests:
stage: test
before_script:
- pip3 install .
......@@ -34,3 +26,5 @@ pages:
when: on_success
paths:
- public
only:
- master
#include "pyhelper.h"
bool is_pystring(PyObject *pystr) {
#if PY_MAJOR_VERSION >= 3
return PyUnicode_Check(pystr);
#else
return PyString_Check(pystr);
#endif
}
const char *pystring(PyObject *pystr) {
#if PY_MAJOR_VERSION >= 3
return PyUnicode_AsUTF8(pystr);
#else
return PyString_AsString(pystr);
#endif
}
bool is_pytable(PyObject *pyobj) {
return PyList_Check(pyobj) || PyTuple_Check(pyobj);
}
......@@ -40,5 +24,5 @@ const char *pytable_string(PyObject *pyobj, int index) {
if (!str)
return NULL;
return pystring(str);
return PyUnicode_AsUTF8(str);
}
......@@ -22,10 +22,6 @@
#include <Python.h>
#include <stdbool.h>
// Stupid helper functions for getting string from python str object
bool is_pystring(PyObject *pystr);
const char *pystring(PyObject *pystr);
// Functions for accessing both Lists and Tuples.
bool is_pytable(PyObject *pyobj);
Py_ssize_t pytable_size(PyObject *pyobj);
......
......@@ -242,8 +242,8 @@ static PyObject *pyuci_set(uci_object *self, PyObject *args) {
if (uci_add_list(self->ctx, &ptr))
return pyuci_error(self, UciException);
}
} else if (is_pystring(data)) {
ptr.value = pystring(data);
} else if (PyUnicode_Check(data)) {
ptr.value = PyUnicode_AsUTF8(data);
if (!ptr.value)
return NULL;
if (uci_set(self->ctx, &ptr))
......
......@@ -25,9 +25,6 @@ static PyMethodDef module_methods[] = {
{NULL, NULL, 0, NULL}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"uci",
......@@ -37,34 +34,17 @@ static struct PyModuleDef moduledef = {
NULL, NULL, NULL, NULL
};
#define RETURN_ERROR return NULL
#else
#define RETURN_ERROR return
#endif
#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit_uci(void) {
#else
PyMODINIT_FUNC inituci(void) {
#endif
PyObject *m;
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule("uci", module_methods);
#endif
if (m == NULL)
RETURN_ERROR;
return NULL;
// Add Uci type to module
if (!pyuci_object_init(m))
RETURN_ERROR;
return NULL;
#if PY_MAJOR_VERSION >= 3
return m;
#endif
}