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
9 years ago
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 = \
$(DB_LIBS)
\
$(TAG_LIBS)
\
libconf.a
\
libutil.a
\
libevent.a
\
$(FS_LIBS)
\
libsystem.a
\
$(ICU_LDADD)
$(ICU_LDADD)
\
libutil.a
test_DumpDatabase_SOURCES
=
test
/DumpDatabase.cxx
\
src/protocol/Ack.cxx
\
src/Log.cxx src/LogBackend.cxx
\
...
...
@@ -2002,8 +2002,8 @@ test_run_convert_LDADD = \
libconf.a
\
$(FS_LIBS)
\
libsystem.a
\
libutil.a
\
$(ICU_LDADD)
$(ICU_LDADD)
\
libutil.a
test_run_output_LDADD
=
$(MPD_LIBS)
\
$(PCM_LIBS)
\
...
...
This diff is collapsed.
Click to expand it.
src/Main.cxx
View file @
01b68db3
...
...
@@ -510,10 +510,7 @@ static int mpd_main_after_fork(struct options options)
try
{
Error
error
;
if
(
!
ConfigureFS
(
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
}
ConfigureFS
();
if
(
!
glue_mapper_init
(
error
))
{
LogError
(
error
);
...
...
This diff is collapsed.
Click to expand it.
src/fs/Charset.cxx
View file @
01b68db3
...
...
@@ -40,19 +40,17 @@ static std::string fs_charset;
static
IcuConverter
*
fs_converter
;
bool
SetFSCharset
(
const
char
*
charset
,
Error
&
error
)
void
SetFSCharset
(
const
char
*
charset
)
{
assert
(
charset
!=
nullptr
);
assert
(
fs_converter
==
nullptr
);
fs_converter
=
IcuConverter
::
Create
(
charset
,
error
);
if
(
fs_converter
==
nullptr
)
return
false
;
fs_converter
=
IcuConverter
::
Create
(
charset
);
assert
(
fs_converter
!=
nullptr
);
FormatDebug
(
path_domain
,
"SetFSCharset: fs charset is: %s"
,
fs_charset
.
c_str
());
return
true
;
}
#endif
...
...
This diff is collapsed.
Click to expand it.
src/fs/Charset.hxx
View file @
01b68db3
...
...
@@ -37,8 +37,11 @@ gcc_const
const
char
*
GetFSCharset
();
bool
SetFSCharset
(
const
char
*
charset
,
Error
&
error
);
/**
* Throws std::runtime_error on error.
*/
void
SetFSCharset
(
const
char
*
charset
);
void
DeinitFSCharset
();
...
...
This diff is collapsed.
Click to expand it.
src/fs/Config.cxx
View file @
01b68db3
...
...
@@ -22,15 +22,13 @@
#include "Charset.hxx"
#include "config/ConfigGlobal.hxx"
bool
ConfigureFS
(
Error
&
error
)
void
ConfigureFS
()
{
#ifdef HAVE_FS_CHARSET
const
char
*
charset
=
config_get_string
(
ConfigOption
::
FS_CHARSET
);
return
charset
==
nullptr
||
SetFSCharset
(
charset
,
error
);
#else
(
void
)
error
;
return
true
;
if
(
charset
!=
nullptr
)
SetFSCharset
(
charset
);
#endif
}
...
...
This diff is collapsed.
Click to expand it.
src/fs/Config.hxx
View file @
01b68db3
...
...
@@ -26,9 +26,11 @@ class Error;
/**
* Performs global one-time initialization of this class.
*
* Throws std::runtime_error on error.
*/
bool
ConfigureFS
(
Error
&
error
);
void
ConfigureFS
();
void
DeinitFS
();
...
...
This diff is collapsed.
Click to expand it.
src/lib/icu/Converter.cxx
View file @
01b68db3
...
...
@@ -19,12 +19,13 @@
#include "config.h"
#include "Converter.hxx"
#include "Error.hxx"
#include "util/Error.hxx"
#include "util/Macros.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedArray.hxx"
#include "util/ConstBuffer.hxx"
#include "util/FormatString.hxx"
#include <stdexcept>
#include <string.h>
...
...
@@ -32,8 +33,7 @@
#include "Util.hxx"
#include <unicode/ucnv.h>
#elif defined(HAVE_ICONV)
#include "util/Domain.hxx"
static
constexpr
Domain
iconv_domain
(
"iconv"
);
#include "system/Error.hxx"
#endif
#ifdef HAVE_ICU
...
...
@@ -48,30 +48,27 @@ IcuConverter::~IcuConverter()
#ifdef HAVE_ICU_CONVERTER
IcuConverter
*
IcuConverter
::
Create
(
const
char
*
charset
,
Error
&
error
)
IcuConverter
::
Create
(
const
char
*
charset
)
{
#ifdef HAVE_ICU
UErrorCode
code
=
U_ZERO_ERROR
;
UConverter
*
converter
=
ucnv_open
(
charset
,
&
code
);
if
(
converter
==
nullptr
)
{
error
.
Format
(
icu_domain
,
int
(
code
),
"Failed to initialize charset '%s': %s"
,
charset
,
u_errorName
(
code
));
return
nullptr
;
}
if
(
converter
==
nullptr
)
throw
std
::
runtime_error
(
FormatString
(
"Failed to initialize charset '%s': %s"
,
charset
,
u_errorName
(
code
)).
c_str
());
return
new
IcuConverter
(
converter
);
#elif defined(HAVE_ICONV)
iconv_t
to
=
iconv_open
(
"utf-8"
,
charset
);
iconv_t
from
=
iconv_open
(
charset
,
"utf-8"
);
if
(
to
==
(
iconv_t
)
-
1
||
from
==
(
iconv_t
)
-
1
)
{
error
.
FormatErrno
(
"Failed to initialize charset '%s'"
,
charset
);
int
e
=
errno
;
if
(
to
!=
(
iconv_t
)
-
1
)
iconv_close
(
to
);
if
(
from
!=
(
iconv_t
)
-
1
)
iconv_close
(
from
);
return
nullptr
;
throw
FormatErrno
(
e
,
"Failed to initialize charset '%s'"
,
charset
);
}
return
new
IcuConverter
(
to
,
from
);
...
...
This diff is collapsed.
Click to expand it.
src/lib/icu/Converter.hxx
View file @
01b68db3
...
...
@@ -33,8 +33,6 @@
#ifdef HAVE_ICU_CONVERTER
class
Error
;
#ifdef HAVE_ICU
struct
UConverter
;
#endif
...
...
@@ -73,7 +71,10 @@ public:
}
#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.
...
...
This diff is collapsed.
Click to expand it.
test/TestIcu.cxx
View file @
01b68db3
...
...
@@ -13,6 +13,8 @@
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <stdexcept>
#include <string.h>
#include <stdlib.h>
...
...
@@ -39,14 +41,16 @@ class TestIcuConverter : public CppUnit::TestFixture {
public
:
void
TestInvalidCharset
()
{
CPPUNIT_ASSERT_EQUAL
((
IcuConverter
*
)
nullptr
,
IcuConverter
::
Create
(
"doesntexist"
,
IgnoreError
()));
try
{
IcuConverter
::
Create
(
"doesntexist"
);
CPPUNIT_FAIL
(
"Exception expected"
);
}
catch
(
const
std
::
runtime_error
&
)
{
}
}
void
TestLatin1
()
{
IcuConverter
*
const
converter
=
IcuConverter
::
Create
(
"iso-8859-1"
,
IgnoreError
()
);
IcuConverter
::
Create
(
"iso-8859-1"
);
CPPUNIT_ASSERT
(
converter
!=
nullptr
);
for
(
const
auto
i
:
invalid_utf8
)
{
...
...
This diff is collapsed.
Click to expand it.
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