From f8cbba18503d7e86f182a62f4fd34fd15d28c811 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 13 Oct 2021 12:51:04 +0200 Subject: [PATCH] util/Alloc: remove unused library --- src/db/update/Walk.cxx | 1 - src/util/Alloc.cxx | 111 -------------------------------------- src/util/Alloc.hxx | 86 ----------------------------- src/util/ConcatString.hxx | 66 ----------------------- src/util/meson.build | 1 - 5 files changed, 265 deletions(-) delete mode 100644 src/util/Alloc.cxx delete mode 100644 src/util/Alloc.hxx delete mode 100644 src/util/ConcatString.hxx diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index 168051d56..b544516b9 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -33,7 +33,6 @@ #include "storage/FileInfo.hxx" #include "input/InputStream.hxx" #include "input/Error.hxx" -#include "util/Alloc.hxx" #include "util/StringCompare.hxx" #include "util/UriExtract.hxx" #include "Log.hxx" diff --git a/src/util/Alloc.cxx b/src/util/Alloc.cxx deleted file mode 100644 index 079e20763..000000000 --- a/src/util/Alloc.cxx +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2003-2021 The Music Player Daemon Project - * http://www.musicpd.org - * - * 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 2 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, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "Alloc.hxx" -#include "ConcatString.hxx" - -#include - -#include - -[[noreturn]] -static void -oom() -{ - (void)write(STDERR_FILENO, "Out of memory\n", 14); - std::_Exit(1); -} - -void * -xalloc(size_t size) -{ - auto p = std::malloc(size); - if (gcc_unlikely(p == nullptr)) - oom(); - - return p; -} - -void * -xmemdup(const void *s, size_t size) -{ - auto p = xalloc(size); - std::memcpy(p, s, size); - return p; -} - -char * -xstrdup(const char *s) -{ - char *p = strdup(s); - if (gcc_unlikely(p == nullptr)) - oom(); - - return p; -} - -char * -xstrndup(const char *s, size_t n) -{ -#ifdef HAVE_STRNDUP - char *p = strndup(s, n); - if (gcc_unlikely(p == nullptr)) - oom(); -#else - auto p = (char *)xalloc(n + 1); - std::memcpy(p, s, n); - p[n] = 0; -#endif - - return p; -} - -template -gcc_malloc gcc_nonnull_all -static inline char * -t_xstrcatdup(Args&&... args) -{ - constexpr size_t n = sizeof...(args); - - size_t lengths[n]; - const size_t total = FillLengths(lengths, args...); - - auto p = (char *)xalloc(total + 1); - *StringCat(p, lengths, args...) = 0; - return p; -} - -char * -xstrcatdup(const char *a, const char *b) -{ - return t_xstrcatdup(a, b); -} - -char * -xstrcatdup(const char *a, const char *b, const char *c) -{ - return t_xstrcatdup(a, b, c); -} - -char * -xstrcatdup(const char *a, const char *b, const char *c, const char *d) -{ - return t_xstrcatdup(a, b, c, d); -} diff --git a/src/util/Alloc.hxx b/src/util/Alloc.hxx deleted file mode 100644 index 7dc8463f9..000000000 --- a/src/util/Alloc.hxx +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2003-2021 The Music Player Daemon Project - * http://www.musicpd.org - * - * 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 2 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, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_ALLOC_HXX -#define MPD_ALLOC_HXX - -#include "Compiler.h" - -#include - -/** - * Allocate memory. Use free() to free it. - * - * This function never fails; in out-of-memory situations, it aborts - * the process. - */ -gcc_malloc gcc_returns_nonnull -void * -xalloc(size_t size); - -/** - * Duplicate memory. Use free() to free it. - * - * This function never fails; in out-of-memory situations, it aborts - * the process. - */ -gcc_malloc gcc_returns_nonnull gcc_nonnull_all -void * -xmemdup(const void *s, size_t size); - -/** - * Duplicate a string. Use free() to free it. - * - * This function never fails; in out-of-memory situations, it aborts - * the process. - */ -gcc_malloc gcc_returns_nonnull gcc_nonnull_all -char * -xstrdup(const char *s); - -/** - * Duplicate a string. Use free() to free it. - * - * This function never fails; in out-of-memory situations, it aborts - * the process. - */ -gcc_malloc gcc_returns_nonnull gcc_nonnull_all -char * -xstrndup(const char *s, size_t n); - -/** - * Concatenate two strings, returning a new allocation. Use free() to - * free it. - * - * This function never fails; in out-of-memory situations, it aborts - * the process. - */ -gcc_malloc gcc_returns_nonnull gcc_nonnull_all -char * -xstrcatdup(const char *a, const char *b); - -gcc_malloc gcc_returns_nonnull gcc_nonnull_all -char * -xstrcatdup(const char *a, const char *b, const char *c); - -gcc_malloc gcc_returns_nonnull gcc_nonnull_all -char * -xstrcatdup(const char *a, const char *b, const char *c, const char *d); - -#endif diff --git a/src/util/ConcatString.hxx b/src/util/ConcatString.hxx deleted file mode 100644 index abc6dd59b..000000000 --- a/src/util/ConcatString.hxx +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2014-2017 Max Kellermann - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CONCAT_STRING_HXX -#define CONCAT_STRING_HXX - -#include - -#include - -template -size_t -FillLengths(size_t *lengths, const char *a, Args&&... args) -{ - return FillLengths(lengths, a) + FillLengths(lengths + 1, args...); -} - -template<> -size_t -FillLengths(size_t *lengths, const char *a) -{ - return *lengths = strlen(a); -} - -template -char * -StringCat(char *p, const size_t *lengths, const char *a, Args&&... args) -{ - return StringCat(StringCat(p, lengths, a), - lengths + 1, args...); -} - -template<> -char * -StringCat(char *p, const size_t *lengths, const char *a) -{ - return std::copy_n(a, *lengths, p); -} - -#endif diff --git a/src/util/meson.build b/src/util/meson.build index 953296e5c..2a13058e7 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -1,7 +1,6 @@ util = static_library( 'util', 'Exception.cxx', - 'Alloc.cxx', 'UTF8.cxx', 'HexFormat.cxx', 'MimeType.cxx',