* directory cannot be accessed, return SRD_ERR_DECODERS_DIR.
* If not enough memory could be allocated, return SRD_ERR_MALLOC.
*/
-SRD_API int srd_init(char *path)
+SRD_API int srd_init(const char *path)
{
int ret;
char *env_path;
}
/* Helper GComparefunc for g_slist_find_custom() in srd_inst_probes_set() */
-static gint compare_probe_id(struct srd_probe *a, char *probe_id)
+static gint compare_probe_id(const struct srd_probe *a, const char *probe_id)
{
return strcmp(a->id, probe_id);
}
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
SRD_API int srd_inst_stack(struct srd_decoder_inst *di_from,
- struct srd_decoder_inst *di_to)
+ struct srd_decoder_inst *di_to)
{
if (!di_from || !di_to) {
srd_err("Invalid from/to instance pair.");
*
* @return Pointer to struct srd_decoder_inst, or NULL if not found.
*/
-SRD_API struct srd_decoder_inst *srd_inst_find_by_id(char *inst_id)
+SRD_API struct srd_decoder_inst *srd_inst_find_by_id(const char *inst_id)
{
GSList *l;
struct srd_decoder_inst *tmp, *di;
*
* @return Pointer to struct srd_decoder_inst, or NULL if not found.
*/
-SRD_PRIV struct srd_decoder_inst *srd_inst_find_by_obj(GSList *stack,
- PyObject *obj)
+SRD_PRIV struct srd_decoder_inst *srd_inst_find_by_obj(const GSList *stack,
+ const PyObject *obj)
{
- GSList *l;
+// TODO?
+ const GSList *l;
struct srd_decoder_inst *tmp, *di;
di = NULL;
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
SRD_PRIV int srd_inst_decode(uint64_t start_samplenum,
- struct srd_decoder_inst *di,
- uint8_t *inbuf, uint64_t inbuflen)
+ const struct srd_decoder_inst *di,
+ const uint8_t *inbuf, uint64_t inbuflen)
{
PyObject *py_res;
srd_logic *logic;
*/
logic = PyObject_New(srd_logic, &srd_logic_type);
Py_INCREF(logic);
- logic->di = di;
+ logic->di = (struct srd_decoder_inst *)di;
logic->start_samplenum = start_samplenum;
logic->itercnt = 0;
- logic->inbuf = inbuf;
+ logic->inbuf = (uint8_t *)inbuf;
logic->inbuflen = inbuflen;
logic->sample = PyList_New(2);
Py_INCREF(logic->sample);
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-SRD_API int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf,
+SRD_API int srd_session_feed(uint64_t start_samplenum, const uint8_t *inbuf,
uint64_t inbuflen)
{
GSList *d;
/* This is the backend function to Python sigrokdecode.add() call. */
SRD_PRIV int pd_add(struct srd_decoder_inst *di, int output_type,
- char *proto_id)
+ const char *proto_id)
{
struct srd_pd_output *pdo;
* @param dec The loaded protocol decoder.
*
* @return A newly allocated buffer containing the protocol decoder's
- * documentation. The caller is responsible for free'ing this after use.
+ * documentation. The caller is responsible for free'ing the buffer.
*/
-SRD_API char *srd_decoder_doc(struct srd_decoder *dec)
+SRD_API char *srd_decoder_doc(const struct srd_decoder *dec)
{
PyObject *py_str;
char *doc;
SRD_PRIV int add_modulepath(const char *path);
SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di, PyObject *args);
SRD_PRIV int srd_inst_decode(uint64_t start_samplenum,
- struct srd_decoder_inst *dec,
- uint8_t *inbuf, uint64_t inbuflen);
+ const struct srd_decoder_inst *dec,
+ const uint8_t *inbuf, uint64_t inbuflen);
SRD_PRIV void srd_inst_free(struct srd_decoder_inst *di);
SRD_PRIV void srd_inst_free_all(GSList *stack);
SRD_PRIV int pd_add(struct srd_decoder_inst *di, int output_type,
- char *output_id);
+ const char *output_id);
/*--- decoder.c -------------------------------------------------------------*/
/*--- util.c ----------------------------------------------------------------*/
-SRD_PRIV int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr);
-SRD_PRIV int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr);
-SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr);
-SRD_PRIV int py_strlist_to_char(PyObject *py_strlist, char ***outstr);
-SRD_PRIV struct srd_decoder_inst *srd_inst_find_by_obj(GSList *stack,
- PyObject *obj);
+SRD_PRIV int py_attr_as_str(const PyObject *py_obj, const char *attr,
+ char **outstr);
+SRD_PRIV int py_dictitem_as_str(const PyObject *py_obj, const char *key,
+ char **outstr);
+SRD_PRIV int py_str_as_str(const PyObject *py_str, char **outstr);
+SRD_PRIV int py_strlist_to_char(const PyObject *py_strlist, char ***outstr);
+SRD_PRIV struct srd_decoder_inst *srd_inst_find_by_obj(const GSList *stack,
+ const PyObject *obj);
#endif
/*--- controller.c ----------------------------------------------------------*/
-SRD_API int srd_init(char *path);
+SRD_API int srd_init(const char *path);
SRD_API int srd_exit(void);
SRD_API int srd_inst_options_set(struct srd_decoder_inst *di,
GHashTable *options);
GHashTable *options);
SRD_API int srd_inst_stack(struct srd_decoder_inst *di_from,
struct srd_decoder_inst *di_to);
-SRD_API struct srd_decoder_inst *srd_inst_find_by_id(char *inst_id);
+SRD_API struct srd_decoder_inst *srd_inst_find_by_id(const char *inst_id);
SRD_API int srd_session_start(int num_probes, int unitsize,
uint64_t samplerate);
-SRD_API int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf,
+SRD_API int srd_session_feed(uint64_t start_samplenum, const uint8_t *inbuf,
uint64_t inbuflen);
SRD_API int srd_register_callback(int output_type,
srd_pd_output_callback_t cb, void *cb_data);
SRD_API int srd_decoder_unload(struct srd_decoder *dec);
SRD_API int srd_decoders_load_all(void);
SRD_API int srd_decoders_unload_all(void);
-SRD_API char *srd_decoder_doc(struct srd_decoder *dec);
+SRD_API char *srd_decoder_doc(const struct srd_decoder *dec);
/*--- log.c -----------------------------------------------------------------*/
#include <inttypes.h>
/* This is only used for nicer srd_dbg() output. */
-char *OUTPUT_TYPES[] = {
+static const char *OUTPUT_TYPES[] = {
"OUTPUT_ANN",
"OUTPUT_PROTO",
"OUTPUT_BINARY",
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed string upon success.
*/
-SRD_PRIV int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr)
+SRD_PRIV int py_attr_as_str(const PyObject *py_obj, const char *attr,
+ char **outstr)
{
PyObject *py_str;
int ret;
- if (!PyObject_HasAttrString(py_obj, attr)) {
+ if (!PyObject_HasAttrString((PyObject *)py_obj, attr)) {
srd_dbg("%s object has no attribute '%s'.",
Py_TYPE(py_obj)->tp_name, attr);
return SRD_ERR_PYTHON;
}
- if (!(py_str = PyObject_GetAttrString(py_obj, attr))) {
+ if (!(py_str = PyObject_GetAttrString((PyObject *)py_obj, attr))) {
catch_exception("");
return SRD_ERR_PYTHON;
}
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed string upon success.
*/
-SRD_PRIV int py_dictitem_as_str(PyObject *py_obj, const char *key,
+SRD_PRIV int py_dictitem_as_str(const PyObject *py_obj, const char *key,
char **outstr)
{
PyObject *py_value;
int ret;
- if (!PyDict_Check(py_obj)) {
+ if (!PyDict_Check((PyObject *)py_obj)) {
srd_dbg("Object is a %s, not a dictionary.",
- Py_TYPE(py_obj)->tp_name);
+ Py_TYPE((PyObject *)py_obj)->tp_name);
return SRD_ERR_PYTHON;
}
- if (!(py_value = PyDict_GetItemString(py_obj, key))) {
+ if (!(py_value = PyDict_GetItemString((PyObject *)py_obj, key))) {
srd_dbg("Dictionary has no attribute '%s'.", key);
return SRD_ERR_PYTHON;
}
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed string upon success.
*/
-SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr)
+SRD_PRIV int py_str_as_str(const PyObject *py_str, char **outstr)
{
PyObject *py_encstr;
int ret;
str = NULL;
ret = SRD_OK;
- if (!PyUnicode_Check(py_str)) {
+ if (!PyUnicode_Check((PyObject *)py_str)) {
srd_dbg("Object is a %s, not a string object.",
- Py_TYPE(py_str)->tp_name);
+ Py_TYPE((PyObject *)py_str)->tp_name);
ret = SRD_ERR_PYTHON;
goto err_out;
}
- if (!(py_encstr = PyUnicode_AsEncodedString(py_str, "utf-8", NULL))) {
+ if (!(py_encstr = PyUnicode_AsEncodedString((PyObject *)py_str,
+ "utf-8", NULL))) {
ret = SRD_ERR_PYTHON;
goto err_out;
}
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a g_malloc()ed char** upon success.
*/
-SRD_PRIV int py_strlist_to_char(PyObject *py_strlist, char ***outstr)
+SRD_PRIV int py_strlist_to_char(const PyObject *py_strlist, char ***outstr)
{
PyObject *py_str;
int list_len, i;
char **out, *str;
- list_len = PyList_Size(py_strlist);
+ list_len = PyList_Size((PyObject *)py_strlist);
if (!(out = g_try_malloc(sizeof(char *) * (list_len + 1)))) {
srd_err("Failed to g_malloc() 'out'.");
return SRD_ERR_MALLOC;
}
for (i = 0; i < list_len; i++) {
if (!(py_str = PyUnicode_AsEncodedString(
- PyList_GetItem(py_strlist, i), "utf-8", NULL)))
+ PyList_GetItem((PyObject *)py_strlist, i), "utf-8", NULL)))
return SRD_ERR_PYTHON;
if (!(str = PyBytes_AS_STRING(py_str)))
return SRD_ERR_PYTHON;