Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
01b68db3
Commit
01b68db3
authored
Apr 12, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Converter: Create() throws exception on error
parent
33fdaa5b
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
45 additions
and
45 deletions
+45
-45
Makefile.am
Makefile.am
+4
-4
Main.cxx
src/Main.cxx
+1
-4
Charset.cxx
src/fs/Charset.cxx
+4
-6
Charset.hxx
src/fs/Charset.hxx
+5
-2
Config.cxx
src/fs/Config.cxx
+4
-6
Config.hxx
src/fs/Config.hxx
+4
-2
Converter.cxx
src/lib/icu/Converter.cxx
+11
-14
Converter.hxx
src/lib/icu/Converter.hxx
+4
-3
TestIcu.cxx
test/TestIcu.cxx
+8
-4
No files found.
Makefile.am
View file @
01b68db3
...
@@ -1657,11 +1657,11 @@ test_DumpDatabase_LDADD = \
...
@@ -1657,11 +1657,11 @@ test_DumpDatabase_LDADD = \
$(DB_LIBS)
\
$(DB_LIBS)
\
$(TAG_LIBS)
\
$(TAG_LIBS)
\
libconf.a
\
libconf.a
\
libutil.a
\
libevent.a
\
libevent.a
\
$(FS_LIBS)
\
$(FS_LIBS)
\
libsystem.a
\
libsystem.a
\
$(ICU_LDADD)
$(ICU_LDADD)
\
libutil.a
test_DumpDatabase_SOURCES
=
test
/DumpDatabase.cxx
\
test_DumpDatabase_SOURCES
=
test
/DumpDatabase.cxx
\
src/protocol/Ack.cxx
\
src/protocol/Ack.cxx
\
src/Log.cxx src/LogBackend.cxx
\
src/Log.cxx src/LogBackend.cxx
\
...
@@ -2002,8 +2002,8 @@ test_run_convert_LDADD = \
...
@@ -2002,8 +2002,8 @@ test_run_convert_LDADD = \
libconf.a
\
libconf.a
\
$(FS_LIBS)
\
$(FS_LIBS)
\
libsystem.a
\
libsystem.a
\
libutil.a
\
$(ICU_LDADD)
\
$(ICU_LDADD)
libutil.a
test_run_output_LDADD
=
$(MPD_LIBS)
\
test_run_output_LDADD
=
$(MPD_LIBS)
\
$(PCM_LIBS)
\
$(PCM_LIBS)
\
...
...
src/Main.cxx
View file @
01b68db3
...
@@ -510,10 +510,7 @@ static int mpd_main_after_fork(struct options options)
...
@@ -510,10 +510,7 @@ static int mpd_main_after_fork(struct options options)
try
{
try
{
Error
error
;
Error
error
;
if
(
!
ConfigureFS
(
error
))
{
ConfigureFS
();
LogError
(
error
);
return
EXIT_FAILURE
;
}
if
(
!
glue_mapper_init
(
error
))
{
if
(
!
glue_mapper_init
(
error
))
{
LogError
(
error
);
LogError
(
error
);
...
...
src/fs/Charset.cxx
View file @
01b68db3
...
@@ -40,19 +40,17 @@ static std::string fs_charset;
...
@@ -40,19 +40,17 @@ static std::string fs_charset;
static
IcuConverter
*
fs_converter
;
static
IcuConverter
*
fs_converter
;
bool
void
SetFSCharset
(
const
char
*
charset
,
Error
&
error
)
SetFSCharset
(
const
char
*
charset
)
{
{
assert
(
charset
!=
nullptr
);
assert
(
charset
!=
nullptr
);
assert
(
fs_converter
==
nullptr
);
assert
(
fs_converter
==
nullptr
);
fs_converter
=
IcuConverter
::
Create
(
charset
,
error
);
fs_converter
=
IcuConverter
::
Create
(
charset
);
if
(
fs_converter
==
nullptr
)
assert
(
fs_converter
!=
nullptr
);
return
false
;
FormatDebug
(
path_domain
,
FormatDebug
(
path_domain
,
"SetFSCharset: fs charset is: %s"
,
fs_charset
.
c_str
());
"SetFSCharset: fs charset is: %s"
,
fs_charset
.
c_str
());
return
true
;
}
}
#endif
#endif
...
...
src/fs/Charset.hxx
View file @
01b68db3
...
@@ -37,8 +37,11 @@ gcc_const
...
@@ -37,8 +37,11 @@ gcc_const
const
char
*
const
char
*
GetFSCharset
();
GetFSCharset
();
bool
/**
SetFSCharset
(
const
char
*
charset
,
Error
&
error
);
* Throws std::runtime_error on error.
*/
void
SetFSCharset
(
const
char
*
charset
);
void
void
DeinitFSCharset
();
DeinitFSCharset
();
...
...
src/fs/Config.cxx
View file @
01b68db3
...
@@ -22,15 +22,13 @@
...
@@ -22,15 +22,13 @@
#include "Charset.hxx"
#include "Charset.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigGlobal.hxx"
bool
void
ConfigureFS
(
Error
&
error
)
ConfigureFS
()
{
{
#ifdef HAVE_FS_CHARSET
#ifdef HAVE_FS_CHARSET
const
char
*
charset
=
config_get_string
(
ConfigOption
::
FS_CHARSET
);
const
char
*
charset
=
config_get_string
(
ConfigOption
::
FS_CHARSET
);
return
charset
==
nullptr
||
SetFSCharset
(
charset
,
error
);
if
(
charset
!=
nullptr
)
#else
SetFSCharset
(
charset
);
(
void
)
error
;
return
true
;
#endif
#endif
}
}
...
...
src/fs/Config.hxx
View file @
01b68db3
...
@@ -26,9 +26,11 @@ class Error;
...
@@ -26,9 +26,11 @@ class Error;
/**
/**
* Performs global one-time initialization of this class.
* Performs global one-time initialization of this class.
*
* Throws std::runtime_error on error.
*/
*/
bool
void
ConfigureFS
(
Error
&
error
);
ConfigureFS
();
void
void
DeinitFS
();
DeinitFS
();
...
...
src/lib/icu/Converter.cxx
View file @
01b68db3
...
@@ -19,12 +19,13 @@
...
@@ -19,12 +19,13 @@
#include "config.h"
#include "config.h"
#include "Converter.hxx"
#include "Converter.hxx"
#include "Error.hxx"
#include "util/Error.hxx"
#include "util/Macros.hxx"
#include "util/Macros.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedArray.hxx"
#include "util/AllocatedArray.hxx"
#include "util/ConstBuffer.hxx"
#include "util/ConstBuffer.hxx"
#include "util/FormatString.hxx"
#include <stdexcept>
#include <string.h>
#include <string.h>
...
@@ -32,8 +33,7 @@
...
@@ -32,8 +33,7 @@
#include "Util.hxx"
#include "Util.hxx"
#include <unicode/ucnv.h>
#include <unicode/ucnv.h>
#elif defined(HAVE_ICONV)
#elif defined(HAVE_ICONV)
#include "util/Domain.hxx"
#include "system/Error.hxx"
static
constexpr
Domain
iconv_domain
(
"iconv"
);
#endif
#endif
#ifdef HAVE_ICU
#ifdef HAVE_ICU
...
@@ -48,30 +48,27 @@ IcuConverter::~IcuConverter()
...
@@ -48,30 +48,27 @@ IcuConverter::~IcuConverter()
#ifdef HAVE_ICU_CONVERTER
#ifdef HAVE_ICU_CONVERTER
IcuConverter
*
IcuConverter
*
IcuConverter
::
Create
(
const
char
*
charset
,
Error
&
error
)
IcuConverter
::
Create
(
const
char
*
charset
)
{
{
#ifdef HAVE_ICU
#ifdef HAVE_ICU
UErrorCode
code
=
U_ZERO_ERROR
;
UErrorCode
code
=
U_ZERO_ERROR
;
UConverter
*
converter
=
ucnv_open
(
charset
,
&
code
);
UConverter
*
converter
=
ucnv_open
(
charset
,
&
code
);
if
(
converter
==
nullptr
)
{
if
(
converter
==
nullptr
)
error
.
Format
(
icu_domain
,
int
(
code
),
throw
std
::
runtime_error
(
FormatString
(
"Failed to initialize charset '%s': %s"
,
"Failed to initialize charset '%s': %s"
,
charset
,
u_errorName
(
code
)).
c_str
());
charset
,
u_errorName
(
code
));
return
nullptr
;
}
return
new
IcuConverter
(
converter
);
return
new
IcuConverter
(
converter
);
#elif defined(HAVE_ICONV)
#elif defined(HAVE_ICONV)
iconv_t
to
=
iconv_open
(
"utf-8"
,
charset
);
iconv_t
to
=
iconv_open
(
"utf-8"
,
charset
);
iconv_t
from
=
iconv_open
(
charset
,
"utf-8"
);
iconv_t
from
=
iconv_open
(
charset
,
"utf-8"
);
if
(
to
==
(
iconv_t
)
-
1
||
from
==
(
iconv_t
)
-
1
)
{
if
(
to
==
(
iconv_t
)
-
1
||
from
==
(
iconv_t
)
-
1
)
{
error
.
FormatErrno
(
"Failed to initialize charset '%s'"
,
int
e
=
errno
;
charset
);
if
(
to
!=
(
iconv_t
)
-
1
)
if
(
to
!=
(
iconv_t
)
-
1
)
iconv_close
(
to
);
iconv_close
(
to
);
if
(
from
!=
(
iconv_t
)
-
1
)
if
(
from
!=
(
iconv_t
)
-
1
)
iconv_close
(
from
);
iconv_close
(
from
);
return
nullptr
;
throw
FormatErrno
(
e
,
"Failed to initialize charset '%s'"
,
charset
);
}
}
return
new
IcuConverter
(
to
,
from
);
return
new
IcuConverter
(
to
,
from
);
...
...
src/lib/icu/Converter.hxx
View file @
01b68db3
...
@@ -33,8 +33,6 @@
...
@@ -33,8 +33,6 @@
#ifdef HAVE_ICU_CONVERTER
#ifdef HAVE_ICU_CONVERTER
class
Error
;
#ifdef HAVE_ICU
#ifdef HAVE_ICU
struct
UConverter
;
struct
UConverter
;
#endif
#endif
...
@@ -73,7 +71,10 @@ public:
...
@@ -73,7 +71,10 @@ public:
}
}
#endif
#endif
static
IcuConverter
*
Create
(
const
char
*
charset
,
Error
&
error
);
/**
* Throws std::runtime_error on error.
*/
static
IcuConverter
*
Create
(
const
char
*
charset
);
/**
/**
* Convert the string to UTF-8.
* Convert the string to UTF-8.
...
...
test/TestIcu.cxx
View file @
01b68db3
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/HelperMacros.h>
#include <stdexcept>
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -39,14 +41,16 @@ class TestIcuConverter : public CppUnit::TestFixture {
...
@@ -39,14 +41,16 @@ class TestIcuConverter : public CppUnit::TestFixture {
public
:
public
:
void
TestInvalidCharset
()
{
void
TestInvalidCharset
()
{
CPPUNIT_ASSERT_EQUAL
((
IcuConverter
*
)
nullptr
,
try
{
IcuConverter
::
Create
(
"doesntexist"
,
IcuConverter
::
Create
(
"doesntexist"
);
IgnoreError
()));
CPPUNIT_FAIL
(
"Exception expected"
);
}
catch
(
const
std
::
runtime_error
&
)
{
}
}
}
void
TestLatin1
()
{
void
TestLatin1
()
{
IcuConverter
*
const
converter
=
IcuConverter
*
const
converter
=
IcuConverter
::
Create
(
"iso-8859-1"
,
IgnoreError
()
);
IcuConverter
::
Create
(
"iso-8859-1"
);
CPPUNIT_ASSERT
(
converter
!=
nullptr
);
CPPUNIT_ASSERT
(
converter
!=
nullptr
);
for
(
const
auto
i
:
invalid_utf8
)
{
for
(
const
auto
i
:
invalid_utf8
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment