diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-02-10 00:06:58 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-02-10 09:30:41 +0100 |
commit | a61ece2022f9e765d65dcd0ed22dba7e71e138a2 (patch) | |
tree | d8804a8808ca70bd23149e5de4329272608e95d7 | |
parent | a33a0e3bd59214cc4ddb021389f5c2ad91134587 (diff) | |
download | libsigrokdecode-a61ece2022f9e765d65dcd0ed22dba7e71e138a2.tar.gz libsigrokdecode-a61ece2022f9e765d65dcd0ed22dba7e71e138a2.zip |
srd: Add/improve g_malloc() error messages.
-rw-r--r-- | controller.c | 16 | ||||
-rw-r--r-- | decoder.c | 3 | ||||
-rw-r--r-- | sigrokdecode.h | 2 | ||||
-rw-r--r-- | type_decoder.c | 4 | ||||
-rw-r--r-- | util.c | 8 |
5 files changed, 21 insertions, 12 deletions
diff --git a/controller.c b/controller.c index 476f4f3..68ff9f7 100644 --- a/controller.c +++ b/controller.c @@ -317,7 +317,7 @@ SRD_API int srd_instance_set_probes(struct srd_decoder_instance *di, new_probemap = NULL; if (!(new_probemap = g_try_malloc(sizeof(int) * di->dec_num_probes))) { - srd_err("Failed to malloc new probe map."); + srd_err("Failed to g_malloc() new probe map."); return SRD_ERR_MALLOC; } @@ -378,8 +378,8 @@ SRD_API struct srd_decoder_instance *srd_instance_new(const char *decoder_id, return NULL; } - if (!(di = g_try_malloc0(sizeof(*di)))) { - srd_err("Failed to malloc instance."); + if (!(di = g_try_malloc0(sizeof(struct srd_decoder_instance)))) { + srd_err("Failed to g_malloc() instance."); return NULL; } @@ -396,7 +396,7 @@ SRD_API struct srd_decoder_instance *srd_instance_new(const char *decoder_id, if (di->dec_num_probes) { if (!(di->dec_probemap = g_try_malloc(sizeof(int) * di->dec_num_probes))) { - srd_err("Failed to malloc probe map."); + srd_err("Failed to g_malloc() probe map."); g_free(di); return NULL; } @@ -698,8 +698,10 @@ SRD_API int srd_register_callback(int output_type, srd_pd_output_callback_t cb) srd_dbg("Registering new callback for output type %d.", output_type); - if (!(pd_cb = g_try_malloc(sizeof(struct srd_pd_callback)))) + if (!(pd_cb = g_try_malloc(sizeof(struct srd_pd_callback)))) { + srd_err("Failed to g_malloc() struct srd_pd_callback."); return SRD_ERR_MALLOC; + } pd_cb->output_type = output_type; pd_cb->callback = cb; @@ -735,8 +737,10 @@ SRD_PRIV int pd_add(struct srd_decoder_instance *di, int output_type, srd_dbg("Instance %s creating new output type %d for %s.", di->instance_id, output_type, proto_id); - if (!(pdo = g_try_malloc(sizeof(struct srd_pd_output)))) + if (!(pdo = g_try_malloc(sizeof(struct srd_pd_output)))) { + srd_err("Failed to g_malloc() struct srd_pd_output."); return -1; + } /* pdo_id is just a simple index, nothing is deleted from this list anyway. */ pdo->pdo_id = g_slist_length(di->pd_output); @@ -95,6 +95,7 @@ static int get_probes(struct srd_decoder *d, char *attr, GSList **pl) } if (!(p = g_try_malloc(sizeof(struct srd_probe)))) { + srd_err("Failed to g_malloc() struct srd_probe."); ret = SRD_ERR_MALLOC; goto err_out; } @@ -138,7 +139,7 @@ SRD_API int srd_load_decoder(const char *name, struct srd_decoder **dec) py_basedec = py_method = py_attr = NULL; if (!(d = g_try_malloc0(sizeof(struct srd_decoder)))) { - srd_dbg("Failed to malloc struct srd_decoder."); + srd_dbg("Failed to g_malloc() struct srd_decoder."); ret = SRD_ERR_MALLOC; goto err_out; } diff --git a/sigrokdecode.h b/sigrokdecode.h index de08ff6..2ad739b 100644 --- a/sigrokdecode.h +++ b/sigrokdecode.h @@ -94,7 +94,7 @@ enum { SRD_OUTPUT_BINARY, }; -#define SRD_MAX_NUM_PROBES 64 +#define SRD_MAX_NUM_PROBES 64 /* TODO: Documentation. */ struct srd_decoder { diff --git a/type_decoder.c b/type_decoder.c index 9c2cfd6..028865b 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -124,8 +124,10 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) di->instance_id, start_sample, end_sample, OUTPUT_TYPES[pdo->output_type], output_id); - if (!(pdata = g_try_malloc0(sizeof(struct srd_proto_data)))) + if (!(pdata = g_try_malloc0(sizeof(struct srd_proto_data)))) { + srd_err("Failed to g_malloc() struct srd_proto_data."); return NULL; + } pdata->start_sample = start_sample; pdata->end_sample = end_sample; pdata->pdo = pdo; @@ -138,7 +138,7 @@ SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr) } if (!(*outstr = g_strdup(str))) { - srd_dbg("outstr malloc failed"); + srd_dbg("Failed to g_malloc() outstr."); ret = SRD_ERR_MALLOC; goto err_out; } @@ -162,7 +162,7 @@ err_out: * @param outstr ptr to char ** storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. - * The 'outstr' argument points to a malloc()ed char ** upon success. + * The 'outstr' argument points to a g_malloc()ed char** upon success. */ SRD_PRIV int py_strlist_to_char(PyObject *py_strlist, char ***outstr) { @@ -171,8 +171,10 @@ SRD_PRIV int py_strlist_to_char(PyObject *py_strlist, char ***outstr) char **out, *str; list_len = PyList_Size(py_strlist); - if (!(out = g_try_malloc(sizeof(char *) * (list_len + 1)))) + 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))) |