diff options
-rw-r--r-- | controller.c | 27 | ||||
-rw-r--r-- | decoder.c | 4 | ||||
-rw-r--r-- | sigrokdecode-internal.h | 20 | ||||
-rw-r--r-- | sigrokdecode.h | 8 | ||||
-rw-r--r-- | type_decoder.c | 2 | ||||
-rw-r--r-- | util.c | 30 |
6 files changed, 48 insertions, 43 deletions
diff --git a/controller.c b/controller.c index 5ffe7ae..4db4ee8 100644 --- a/controller.c +++ b/controller.c @@ -65,7 +65,7 @@ extern SRD_PRIV PyTypeObject srd_logic_type; * 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; @@ -316,7 +316,7 @@ err_out: } /* 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); } @@ -477,7 +477,7 @@ SRD_API struct srd_decoder_inst *srd_inst_new(const char *decoder_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."); @@ -505,7 +505,7 @@ SRD_API int srd_inst_stack(struct srd_decoder_inst *di_from, * * @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; @@ -535,10 +535,11 @@ SRD_API struct srd_decoder_inst *srd_inst_find_by_id(char *inst_id) * * @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; @@ -604,8 +605,8 @@ SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di, PyObject *args) * @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; @@ -634,10 +635,10 @@ SRD_PRIV int srd_inst_decode(uint64_t start_samplenum, */ 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); @@ -747,7 +748,7 @@ SRD_API int srd_session_start(int num_probes, int unitsize, uint64_t samplerate) * * @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; @@ -818,7 +819,7 @@ SRD_PRIV void *srd_find_callback(int output_type) /* 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; @@ -290,9 +290,9 @@ err_out: * @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; diff --git a/sigrokdecode-internal.h b/sigrokdecode-internal.h index 23f52b8..5351b13 100644 --- a/sigrokdecode-internal.h +++ b/sigrokdecode-internal.h @@ -29,12 +29,12 @@ 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 -------------------------------------------------------------*/ @@ -55,11 +55,13 @@ SRD_PRIV int srd_err(const char *format, ...); /*--- 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 diff --git a/sigrokdecode.h b/sigrokdecode.h index bebad10..1cc6782 100644 --- a/sigrokdecode.h +++ b/sigrokdecode.h @@ -211,7 +211,7 @@ typedef struct { /*--- 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); @@ -221,10 +221,10 @@ SRD_API struct srd_decoder_inst *srd_inst_new(const char *id, 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); @@ -237,7 +237,7 @@ SRD_API int srd_decoder_load(const char *name); 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 -----------------------------------------------------------------*/ diff --git a/type_decoder.c b/type_decoder.c index be3cb31..e5426c1 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -23,7 +23,7 @@ #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", @@ -33,18 +33,19 @@ * @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; } @@ -73,19 +74,19 @@ SRD_PRIV int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr) * @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; } @@ -111,7 +112,7 @@ SRD_PRIV int py_dictitem_as_str(PyObject *py_obj, const char *key, * @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; @@ -121,14 +122,15 @@ SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr) 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; } @@ -164,20 +166,20 @@ 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; |