From 6d409d27ca945389d34a43fdde70f548faeb36da Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 2 Nov 2016 09:54:13 +0100 Subject: [PATCH] lib/icu: migrate from class Error to C++ exceptions --- Makefile.am | 3 +-- src/Main.cxx | 5 +---- src/lib/icu/Collate.cxx | 18 ++++++------------ src/lib/icu/Collate.hxx | 7 +++++-- src/lib/icu/Error.cxx | 24 ------------------------ src/lib/icu/Error.hxx | 29 ----------------------------- src/lib/icu/Init.cxx | 17 +++++++---------- src/lib/icu/Init.hxx | 8 +++----- 8 files changed, 23 insertions(+), 88 deletions(-) delete mode 100644 src/lib/icu/Error.cxx delete mode 100644 src/lib/icu/Error.hxx diff --git a/Makefile.am b/Makefile.am index 8411ea6f9..1b5acd9ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -508,8 +508,7 @@ libevent_a_SOURCES = \ libicu_a_SOURCES = \ src/lib/icu/Collate.cxx src/lib/icu/Collate.hxx \ - src/lib/icu/Converter.cxx src/lib/icu/Converter.hxx \ - src/lib/icu/Error.cxx src/lib/icu/Error.hxx + src/lib/icu/Converter.cxx src/lib/icu/Converter.hxx if HAVE_ICU libicu_a_SOURCES += \ diff --git a/src/Main.cxx b/src/Main.cxx index 9a095b1c7..243a7f275 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -400,10 +400,7 @@ try { #endif #endif - if (!IcuInit(error)) { - LogError(error); - return EXIT_FAILURE; - } + IcuInit(); winsock_init(); io_thread_init(); diff --git a/src/lib/icu/Collate.cxx b/src/lib/icu/Collate.cxx index b6fc9e136..3da0175bd 100644 --- a/src/lib/icu/Collate.cxx +++ b/src/lib/icu/Collate.cxx @@ -23,10 +23,9 @@ #ifdef HAVE_ICU #include "Util.hxx" -#include "Error.hxx" #include "util/AllocatedArray.hxx" #include "util/ConstBuffer.hxx" -#include "util/Error.hxx" +#include "util/RuntimeError.hxx" #include #include @@ -53,21 +52,16 @@ static UCollator *collator; #ifdef HAVE_ICU -bool -IcuCollateInit(Error &error) +void +IcuCollateInit() { assert(collator == nullptr); - assert(!error.IsDefined()); UErrorCode code = U_ZERO_ERROR; collator = ucol_open("", &code); - if (collator == nullptr) { - error.Format(icu_domain, int(code), - "ucol_open() failed: %s", u_errorName(code)); - return false; - } - - return true; + if (collator == nullptr) + throw FormatRuntimeError("ucol_open() failed: %s", + u_errorName(code)); } void diff --git a/src/lib/icu/Collate.hxx b/src/lib/icu/Collate.hxx index 37bc3f33c..5bfe5ab05 100644 --- a/src/lib/icu/Collate.hxx +++ b/src/lib/icu/Collate.hxx @@ -26,8 +26,11 @@ class Error; template class AllocatedString; -bool -IcuCollateInit(Error &error); +/** + * Throws #std::runtime_error on error. + */ +void +IcuCollateInit(); void IcuCollateFinish(); diff --git a/src/lib/icu/Error.cxx b/src/lib/icu/Error.cxx deleted file mode 100644 index ad9301c4d..000000000 --- a/src/lib/icu/Error.cxx +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2003-2016 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 "Error.hxx" -#include "util/Domain.hxx" - -const Domain icu_domain("icu"); diff --git a/src/lib/icu/Error.hxx b/src/lib/icu/Error.hxx deleted file mode 100644 index 3d16ce54d..000000000 --- a/src/lib/icu/Error.hxx +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2003-2016 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_ICU_ERROR_HXX -#define MPD_ICU_ERROR_HXX - -#include "check.h" - -class Domain; - -extern const Domain icu_domain; - -#endif diff --git a/src/lib/icu/Init.cxx b/src/lib/icu/Init.cxx index aa6c42383..3eb6060f5 100644 --- a/src/lib/icu/Init.cxx +++ b/src/lib/icu/Init.cxx @@ -19,24 +19,21 @@ #include "config.h" #include "Init.hxx" -#include "Error.hxx" #include "Collate.hxx" -#include "util/Error.hxx" +#include "util/RuntimeError.hxx" #include -bool -IcuInit(Error &error) +void +IcuInit() { UErrorCode code = U_ZERO_ERROR; u_init(&code); - if (U_FAILURE(code)) { - error.Format(icu_domain, int(code), - "u_init() failed: %s", u_errorName(code)); - return false; - } + if (U_FAILURE(code)) + throw FormatRuntimeError("u_init() failed: %s", + u_errorName(code)); - return IcuCollateInit(error); + IcuCollateInit(); } void diff --git a/src/lib/icu/Init.hxx b/src/lib/icu/Init.hxx index 2c39792c3..932eca31a 100644 --- a/src/lib/icu/Init.hxx +++ b/src/lib/icu/Init.hxx @@ -22,19 +22,17 @@ #include "check.h" -class Error; - #ifdef HAVE_ICU -bool -IcuInit(Error &error); +void +IcuInit(); void IcuFinish(); #else -static inline bool IcuInit(Error &) { return true; } +static inline void IcuInit() {} static inline void IcuFinish() {} #endif