- autoconf-archive (only needed when building from git)
- doxygen (required for building the bindings, not only for C++ API docs!)
- graphviz (optional, only needed for the C++ API docs)
- - Python (2 or 3) executable (development files are not needed)
+ - Python 3 executable (development files are not needed)
- glibmm-2.4 (>= 2.32.0) or glibmm-2.68 (>= 2.68.0)
Requirements for the Python bindings:
- libsigrokcxx >= 0.4.0 (the libsigrok C++ bindings, see above)
- - Python >= 2.7 or Python >= 3 (including development files!)
- - Python setuptools (for Python 2 or 3)
- - pygobject >= 3.0.0 (for Python 2 or 3), a.k.a python-gi
- - numpy (for Python 2 or 3)
- SWIG >= 2.0.0
+ - Python >= 3 (including development files!)
+ - Python setuptools
+ - pygobject >= 3.0.0, a.k.a python-gi
+ - numpy
- doxygen (optional, only needed for the Python API docs)
- graphviz (optional, only needed for the Python API docs)
- doxypy (optional, only needed for the Python API docs)
typedef guint pyg_flags_type;
#endif
-#if PY_VERSION_HEX >= 0x03000000
-#define string_check PyUnicode_Check
-#define string_from_python PyUnicode_AsUTF8
-#define string_to_python PyUnicode_FromString
-#else
-#define string_check PyString_Check
-#define string_from_python PyString_AsString
-#define string_to_python PyString_FromString
-#endif
-
%}
%init %{
*/
if (!GLib) {
fprintf(stderr, "Import of gi.repository.GLib failed.\n");
-#if PY_VERSION_HEX >= 0x03000000
return nullptr;
-#else
- return;
-#endif
}
import_array();
%}
auto log_obj = SWIG_NewPointerObj(
SWIG_as_voidptr(loglevel), SWIGTYPE_p_sigrok__LogLevel, 0);
- auto string_obj = string_to_python(message.c_str());
+ auto string_obj = PyUnicode_FromString(message.c_str());
auto arglist = Py_BuildValue("(OO)", log_obj, string_obj);
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &py_key, &py_value)) {
- if (!string_check(py_key))
+ if (!PyUnicode_Check(py_key))
throw sigrok::Error(SR_ERR_ARG);
- if (!string_check(py_value))
+ if (!PyUnicode_Check(py_value))
throw sigrok::Error(SR_ERR_ARG);
- auto key = string_from_python(py_key);
- auto value = string_from_python(py_value);
+ auto key = PyUnicode_AsUTF8(py_key);
+ auto value = PyUnicode_AsUTF8(py_value);
output[key] = value;
}
return Glib::Variant<guint64>::create(PyInt_AsLong(input));
if (type == SR_T_UINT64 && PyLong_Check(input))
return Glib::Variant<guint64>::create(PyLong_AsLong(input));
- else if (type == SR_T_STRING && string_check(input))
- return Glib::Variant<Glib::ustring>::create(string_from_python(input));
+ else if (type == SR_T_STRING && PyUnicode_Check(input))
+ return Glib::Variant<Glib::ustring>::create(PyUnicode_AsUTF8(input));
else if (type == SR_T_BOOL && PyBool_Check(input))
return Glib::Variant<bool>::create(input == Py_True);
else if (type == SR_T_FLOAT && PyFloat_Check(input))
return Glib::Variant<guint64>::create(PyInt_AsLong(input));
if (type == G_VARIANT_TYPE_UINT64 && PyLong_Check(input))
return Glib::Variant<guint64>::create(PyLong_AsLong(input));
- else if (type == G_VARIANT_TYPE_STRING && string_check(input))
- return Glib::Variant<Glib::ustring>::create(string_from_python(input));
+ else if (type == G_VARIANT_TYPE_STRING && PyUnicode_Check(input))
+ return Glib::Variant<Glib::ustring>::create(PyUnicode_AsUTF8(input));
else if (type == G_VARIANT_TYPE_BOOLEAN && PyBool_Check(input))
return Glib::Variant<bool>::create(input == Py_True);
else if (type == G_VARIANT_TYPE_DOUBLE && PyFloat_Check(input))
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &py_key, &py_value)) {
- if (!string_check(py_key))
+ if (!PyUnicode_Check(py_key))
throw sigrok::Error(SR_ERR_ARG);
- auto key = string_from_python(py_key);
+ auto key = PyUnicode_AsUTF8(py_key);
auto value = python_to_variant_by_option(py_value, options[key]);
output[key] = value;
}
while (PyDict_Next(dict, &pos, &py_key, &py_value))
{
- if (!string_check(py_key))
+ if (!PyUnicode_Check(py_key))
throw sigrok::Error(SR_ERR_ARG);
- auto key = sigrok::ConfigKey::get_by_identifier(string_from_python(py_key));
+ auto key = sigrok::ConfigKey::get_by_identifier(PyUnicode_AsUTF8(py_key));
auto value = python_to_variant_by_key(py_value, key);
options[key] = value;
}
SR_SEARCH_LIBS([SR_EXTRA_CXX_LIBS], [__cxa_throw], [gnustl_shared])
# Python is needed for the C++ bindings.
-AM_PATH_PYTHON([2.7],
+AM_PATH_PYTHON([3.8],
[HAVE_PYTHON=yes],
[HAVE_PYTHON=no
SR_APPEND([sr_cxx_missing], [', '], [Python])])
sr_pyminor=${PYTHON_VERSION#*.}
# The Python bindings need Python development files. Check for either
-# Python 3 or Python 2 headers depending on the interpreter version.
+# Python 3 headers depending on the interpreter version.
SR_PKG_CHECK([python_dev], [SR_PKGLIBS_PYTHON],
[python = $PYTHON_VERSION],
[python$sr_pymajor = $PYTHON_VERSION],