Replace uses of die() with err() + return
This commit is contained in:
parent
0bdfea309a
commit
4a2a9ec685
@ -107,8 +107,10 @@ cpu_init_end(struct cpu *cpu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < CPU_CHAN_MAX; i++) {
|
for (int i = 0; i < CPU_CHAN_MAX; i++) {
|
||||||
if (chan_name[i] == NULL)
|
if (chan_name[i] == NULL) {
|
||||||
die("chan_name is null");
|
err("chan_name is null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
chan_init(&cpu->chan[i], CHAN_SINGLE,
|
chan_init(&cpu->chan[i], CHAN_SINGLE,
|
||||||
chan_fmt, cpu->gindex, chan_name[i]);
|
chan_fmt, cpu->gindex, chan_name[i]);
|
||||||
|
@ -18,8 +18,12 @@ create_values(const struct model_pvt_spec *pvt,
|
|||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (const struct pcf_value_label *p = q; p->label != NULL; p++)
|
for (const struct pcf_value_label *p = q; p->label != NULL; p++) {
|
||||||
pcf_add_value(t, p->value, p->label);
|
if (pcf_add_value(t, p->value, p->label) == NULL) {
|
||||||
|
err("pcf_add_value failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -47,6 +51,10 @@ create_type(const struct model_pvt_spec *pvt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct pcf_type *pcftype = pcf_add_type(pcf, type, label);
|
struct pcf_type *pcftype = pcf_add_type(pcf, type, label);
|
||||||
|
if (pcftype == NULL) {
|
||||||
|
err("pcf_add_type failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (create_values(pvt, pcftype, i) != 0) {
|
if (create_values(pvt, pcftype, i) != 0) {
|
||||||
err("create_values failed");
|
err("create_values failed");
|
||||||
|
@ -28,11 +28,15 @@ main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emu_init(emu, argc, argv) != 0)
|
if (emu_init(emu, argc, argv) != 0) {
|
||||||
die("emu_init failed\n");
|
err("emu_init failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (emu_connect(emu) != 0)
|
if (emu_connect(emu) != 0) {
|
||||||
die("emu_connect failed\n");
|
err("emu_connect failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
signal(SIGINT, stop_emulation);
|
signal(SIGINT, stop_emulation);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ copy_recursive(const char *src, const char *dst)
|
|||||||
|
|
||||||
char *newdst = calloc(1, PATH_MAX);
|
char *newdst = calloc(1, PATH_MAX);
|
||||||
if (newdst == NULL) {
|
if (newdst == NULL) {
|
||||||
die("calloc failed:");
|
err("calloc failed:");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,20 +153,26 @@ pcf_add_type(struct pcf *pcf, int type_id, const char *label)
|
|||||||
{
|
{
|
||||||
struct pcf_type *pcftype = pcf_find_type(pcf, type_id);
|
struct pcf_type *pcftype = pcf_find_type(pcf, type_id);
|
||||||
|
|
||||||
if (pcftype != NULL)
|
if (pcftype != NULL) {
|
||||||
die("PCF type %d already defined\n", type_id);
|
err("PCF type %d already defined", type_id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pcftype = calloc(1, sizeof(struct pcf_type));
|
pcftype = calloc(1, sizeof(struct pcf_type));
|
||||||
if (pcftype == NULL)
|
if (pcftype == NULL) {
|
||||||
die("calloc failed: %s\n", strerror(errno));
|
err("calloc failed:");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pcftype->id = type_id;
|
pcftype->id = type_id;
|
||||||
pcftype->values = NULL;
|
pcftype->values = NULL;
|
||||||
pcftype->nvalues = 0;
|
pcftype->nvalues = 0;
|
||||||
|
|
||||||
int len = snprintf(pcftype->label, MAX_PCF_LABEL, "%s", label);
|
int len = snprintf(pcftype->label, MAX_PCF_LABEL, "%s", label);
|
||||||
if (len >= MAX_PCF_LABEL)
|
if (len >= MAX_PCF_LABEL) {
|
||||||
die("PCF type label too long\n");
|
err("PCF type label too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
HASH_ADD_INT(pcf->types, id, pcftype);
|
HASH_ADD_INT(pcf->types, id, pcftype);
|
||||||
|
|
||||||
@ -193,18 +199,24 @@ pcf_add_value(struct pcf_type *type, int value, const char *label)
|
|||||||
{
|
{
|
||||||
struct pcf_value *pcfvalue = pcf_find_value(type, value);
|
struct pcf_value *pcfvalue = pcf_find_value(type, value);
|
||||||
|
|
||||||
if (pcfvalue != NULL)
|
if (pcfvalue != NULL) {
|
||||||
die("PCF value %d already in type %d\n", value, type->id);
|
err("PCF value %d already in type %d", value, type->id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pcfvalue = calloc(1, sizeof(struct pcf_value));
|
pcfvalue = calloc(1, sizeof(struct pcf_value));
|
||||||
if (pcfvalue == NULL)
|
if (pcfvalue == NULL) {
|
||||||
die("calloc failed: %s\n", strerror(errno));
|
err("calloc failed:");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pcfvalue->value = value;
|
pcfvalue->value = value;
|
||||||
|
|
||||||
int len = snprintf(pcfvalue->label, MAX_PCF_LABEL, "%s", label);
|
int len = snprintf(pcfvalue->label, MAX_PCF_LABEL, "%s", label);
|
||||||
if (len >= MAX_PCF_LABEL)
|
if (len >= MAX_PCF_LABEL) {
|
||||||
die("PCF value label too long\n");
|
err("PCF value label too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
HASH_ADD_INT(type->values, value, pcfvalue);
|
HASH_ADD_INT(type->values, value, pcfvalue);
|
||||||
|
|
||||||
|
@ -34,8 +34,7 @@ prv_open(struct prv *prv, long nrows, const char *path)
|
|||||||
FILE *f = fopen(path, "w");
|
FILE *f = fopen(path, "w");
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
die("cannot open file '%s' for writting: %s\n",
|
err("cannot open file '%s' for writting:", path);
|
||||||
path, strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ int
|
|||||||
stream_clkoff_set(struct stream *stream, int64_t clkoff)
|
stream_clkoff_set(struct stream *stream, int64_t clkoff)
|
||||||
{
|
{
|
||||||
if (stream->cur_ev) {
|
if (stream->cur_ev) {
|
||||||
die("cannot set clokoff in started stream '%s'",
|
err("cannot set clokoff in started stream '%s'",
|
||||||
stream->relpath);
|
stream->relpath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,10 @@ task_create_pcf_types(struct pcf_type *pcftype, struct task_type *types)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pcf_add_value(pcftype, tt->gid, tt->label);
|
if (pcf_add_value(pcftype, tt->gid, tt->label) == NULL) {
|
||||||
|
err("pcf_add_value failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -163,8 +163,12 @@ create_values(struct pcf_type *t, int i)
|
|||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (const struct pcf_value_label *p = *q; p->label != NULL; p++)
|
for (const struct pcf_value_label *p = *q; p->label != NULL; p++) {
|
||||||
pcf_add_value(t, p->value, p->label);
|
if (pcf_add_value(t, p->value, p->label) == NULL) {
|
||||||
|
err("pcf_add_value failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -179,6 +183,10 @@ create_type(struct pcf *pcf, int i)
|
|||||||
|
|
||||||
const char *label = pvt_name[i];
|
const char *label = pvt_name[i];
|
||||||
struct pcf_type *pcftype = pcf_add_type(pcf, type, label);
|
struct pcf_type *pcftype = pcf_add_type(pcf, type, label);
|
||||||
|
if (pcftype == NULL) {
|
||||||
|
err("pcf_add_type failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (create_values(pcftype, i) != 0) {
|
if (create_values(pcftype, i) != 0) {
|
||||||
err("create_values failed");
|
err("create_values failed");
|
||||||
@ -255,7 +263,7 @@ thread_set_state(struct thread *th, enum thread_state state)
|
|||||||
{
|
{
|
||||||
/* The state must be updated when a cpu is set */
|
/* The state must be updated when a cpu is set */
|
||||||
if (th->cpu == NULL) {
|
if (th->cpu == NULL) {
|
||||||
die("thread %d doesn't have a CPU", th->tid);
|
err("thread %d doesn't have a CPU", th->tid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,12 +393,12 @@ int
|
|||||||
thread_set_cpu(struct thread *th, struct cpu *cpu)
|
thread_set_cpu(struct thread *th, struct cpu *cpu)
|
||||||
{
|
{
|
||||||
if (cpu == NULL) {
|
if (cpu == NULL) {
|
||||||
err("thread_set_cpu: CPU is NULL\n");
|
err("CPU is NULL");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (th->cpu != NULL) {
|
if (th->cpu != NULL) {
|
||||||
err("thread_set_cpu: thread %d already has a CPU\n", th->tid);
|
err("thread %d already has a CPU", th->tid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +407,7 @@ thread_set_cpu(struct thread *th, struct cpu *cpu)
|
|||||||
/* Update cpu channel */
|
/* Update cpu channel */
|
||||||
struct chan *c = &th->chan[TH_CHAN_CPU];
|
struct chan *c = &th->chan[TH_CHAN_CPU];
|
||||||
if (chan_set(c, value_int64(cpu->gindex)) != 0) {
|
if (chan_set(c, value_int64(cpu->gindex)) != 0) {
|
||||||
err("thread_set_cpu: chan_set failed\n");
|
err("chan_set failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +418,7 @@ int
|
|||||||
thread_unset_cpu(struct thread *th)
|
thread_unset_cpu(struct thread *th)
|
||||||
{
|
{
|
||||||
if (th->cpu == NULL) {
|
if (th->cpu == NULL) {
|
||||||
err("thread_unset_cpu: thread %d doesn't have a CPU\n", th->tid);
|
err("thread %d doesn't have a CPU", th->tid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +426,7 @@ thread_unset_cpu(struct thread *th)
|
|||||||
|
|
||||||
struct chan *c = &th->chan[TH_CHAN_CPU];
|
struct chan *c = &th->chan[TH_CHAN_CPU];
|
||||||
if (chan_set(c, value_null()) != 0) {
|
if (chan_set(c, value_null()) != 0) {
|
||||||
err("thread_set_cpu: chan_set failed\n");
|
err("chan_set failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +437,7 @@ int
|
|||||||
thread_migrate_cpu(struct thread *th, struct cpu *cpu)
|
thread_migrate_cpu(struct thread *th, struct cpu *cpu)
|
||||||
{
|
{
|
||||||
if (th->cpu == NULL) {
|
if (th->cpu == NULL) {
|
||||||
die("thread_migrate_cpu: thread %d doesn't have a CPU\n", th->tid);
|
err("thread %d doesn't have a CPU", th->tid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +445,7 @@ thread_migrate_cpu(struct thread *th, struct cpu *cpu)
|
|||||||
|
|
||||||
struct chan *c = &th->chan[TH_CHAN_CPU];
|
struct chan *c = &th->chan[TH_CHAN_CPU];
|
||||||
if (chan_set(c, value_int64(cpu->gindex)) != 0) {
|
if (chan_set(c, value_int64(cpu->gindex)) != 0) {
|
||||||
err("thread_set_cpu: chan_set failed\n");
|
err("chan_set failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user