ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit 7a758649323857b21b58b7eda7aaee0830fd5769
parent 734884fb792c965b409d43580f38bfde5798ea5c
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 14 Jul 2021 17:33:50 -0700

Implement bug reporting function and helper macros

Diffstat:
Maps/aps.c | 3+--
Aaps/bug.c | 27+++++++++++++++++++++++++++
Aaps/bug.h | 1+
Maps/item.c | 4++--
Maps/mkfile | 2+-
Maps/util.h | 4++++
6 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/aps/aps.c b/aps/aps.c @@ -18,7 +18,6 @@ #include <sys/socket.h> -#include <assert.h> #include <errno.h> #include <limits.h> #include <poll.h> @@ -115,7 +114,7 @@ aps_handle(struct aps *aps, int fd) if (aps->clients[fd].resp->lock && respond(aps, fd)) return 1; } else { - assert(!"unhandled poll event"); + BUG("impossible poll event"); } return 0; diff --git a/aps/bug.c b/aps/bug.c @@ -0,0 +1,27 @@ +/* Copyright 2021 Jacob R. Edwards + * + * ap -- audio player + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <stdlib.h> + +void +bug(char *file, long line, char *bug) +{ + fprintf(stderr, "%s:%ld: %s.\n", file, line, bug); + abort(); +} diff --git a/aps/bug.h b/aps/bug.h @@ -0,0 +1 @@ +void bug(char *, long, char *); diff --git a/aps/item.c b/aps/item.c @@ -16,12 +16,12 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <assert.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include "item.h" +#include "util.h" struct item * item_new(char *path) @@ -59,7 +59,7 @@ item_insert(struct item *list, struct item *item) } if (list->prev == NULL) { - assert(list->next == NULL); + ASSERT(list->next == NULL); list->next = list->prev = item; item->next = item->prev = list; } else { diff --git a/aps/mkfile b/aps/mkfile @@ -1,7 +1,7 @@ # Copyright 2021 Jacob R. Edwards name = aps -src = aps.c buf.c command.c find.c item.c log.c main.c match.c player.c queue.c response.c split.c +src = aps.c buf.c bug.c command.c find.c item.c log.c main.c match.c player.c queue.c response.c split.c obj = ${src:%.c=%.o} lib = ap mk = ../mk diff --git a/aps/util.h b/aps/util.h @@ -1,2 +1,6 @@ +#include "bug.h" + #define LEN(X) (sizeof(X) / sizeof(*X)) #define MAX(A,B) (A > B ? A : B) +#define ASSERT(EXP) ((EXP) ? 0 : BUG(#EXP)) +#define BUG(WHY) (bug(__FILE__, __LINE__, WHY))