[Libreoffice-commits] core.git: cppu/qa include/cppu include/rtl include/sal
Stephan Bergmann
sbergman at redhat.com
Wed Nov 18 07:21:10 PST 2015
cppu/qa/test_unotype.cxx | 53 +++++++++++++++++++++++++++++++++++++++++++++++
include/cppu/unotype.hxx | 16 ++++++++++++++
include/rtl/ustrbuf.hxx | 5 ++++
include/sal/types.h | 4 +++
4 files changed, 78 insertions(+)
New commits:
commit 0b07406f7147b9abbb2095d9e038b13293cb8b10
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Nov 18 13:40:34 2015 +0100
Use C++11 char16_t for sal_Unicode
...in LIBO_INTERNAL_ONLY, __cplusplus, non-MSVC case.
It turns out that sal_Unicode happens to not be mangled into any symbols that
make up the stable URE interface, so (for LIBO_INTERNAL_ONLY, at least) we are
free to replace the typedef to sal_uInt16 with a typedef to any integral type
layout-compatible with that. (sal_Unicode does appear in some symbols in sal's
PRIVATE_textenc.1 section, but that is private between the sal and sal_textenc
libraries, so changing those symbols does not require a change of SONAME.)
C++11 chart16_t is the obvious choice (and will ultimately allow using u"..."
to write literals of type array-of-sal_Unicode). Reportedly, char16_t is
supported since GCC 4.4 and Clang 2.9 but will only be available in MSVC 2015.
For plain C, we continue to use sal_uInt16. We could theoretically use C11
char16_t from <uchar.h>, but at least the Mac OS X 10.11 SDK still does not
offer that C11 header.
For MSVC, we continue to use wchar_t (which is actually unsigned short, due to
/Zc:wchar_t-) for now. Potential options there include dropping /Zc:wchar_t-
and using true wchar_t, or using C++11 char16_t once support for MSVC 2013 is
dropped.
Some code needed to be adapted that was written in a way assuming that
sal_Unicode is unsigned short (which indicates that changing sal_Unicode for
non-LIBO_INTERNAL_ONLY would be an ABI change). OUStringBuffer::append can now
differentiate between being called with sal_Unicode (to append a single
character) and erroneously being called with sal_uInt16 (intending to append a
number's textual representation, for which the sal_Int32 overload must be used
instead). Bugs found are 379fe0409e7973b36210cffa3dd1dfd4032f0ecc "Assume that
this code wants to append a number, not a character" and
dc148335a6a438848325f24c49198fba81043279 "Assume this wants to append the
numerical representation."
The GDB support for pretty-printing of sal_Unicode-related data in
solenv/gdb/libreoffice/sal.py can presumably be simplified now.
Change-Id: I445b3a80e65b7cb004d9e08b38bdc9ee93bc9401
Reviewed-on: https://gerrit.libreoffice.org/20036
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
Tested-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/cppu/qa/test_unotype.cxx b/cppu/qa/test_unotype.cxx
index 2732337..338c6f7 100644
--- a/cppu/qa/test_unotype.cxx
+++ b/cppu/qa/test_unotype.cxx
@@ -233,7 +233,11 @@ void Test::testUnoType() {
}
void Test::testGetTypeFavourUnsigned() {
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT(typeid(sal_Unicode) == typeid(sal_uInt16));
+#else
+ CPPUNIT_ASSERT(typeid(sal_Unicode) != typeid(sal_uInt16));
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourUnsigned(static_cast<cppu::UnoVoidType *>(nullptr)),
cppu::UnoType<cppu::UnoVoidType>::get());
@@ -277,9 +281,15 @@ void Test::testGetTypeFavourUnsigned() {
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourUnsigned(static_cast<cppu::UnoCharType *>(nullptr)),
cppu::UnoType<cppu::UnoCharType>::get());
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourUnsigned(static_cast<sal_Unicode *>(nullptr)),
cppu::UnoType<cppu::UnoUnsignedShortType>::get());
+#else
+ CPPUNIT_ASSERT_EQUAL(
+ cppu::getTypeFavourUnsigned(static_cast<sal_Unicode *>(nullptr)),
+ cppu::UnoType<cppu::UnoCharType>::get());
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourUnsigned(static_cast<OUString *>(nullptr)),
cppu::UnoType<OUString>::get());
@@ -316,6 +326,7 @@ void Test::testGetTypeFavourUnsigned() {
cppu::UnoType<
cppu::UnoSequenceType<
cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>>::get());
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourUnsigned(
static_cast<css::uno::Sequence<sal_Unicode> *>(nullptr)),
@@ -329,6 +340,20 @@ void Test::testGetTypeFavourUnsigned() {
cppu::UnoType<
cppu::UnoSequenceType<
cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>>::get());
+#else
+ CPPUNIT_ASSERT_EQUAL(
+ cppu::getTypeFavourUnsigned(
+ static_cast<css::uno::Sequence<sal_Unicode> *>(nullptr)),
+ cppu::UnoType<cppu::UnoSequenceType<cppu::UnoCharType>>::get());
+ CPPUNIT_ASSERT_EQUAL(
+ cppu::getTypeFavourUnsigned(
+ static_cast<
+ css::uno::Sequence<
+ css::uno::Sequence<sal_Unicode>> *>(nullptr)),
+ cppu::UnoType<
+ cppu::UnoSequenceType<
+ cppu::UnoSequenceType<cppu::UnoCharType>>>::get());
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourUnsigned(
static_cast<css::uno::TypeClass *>(nullptr)),
@@ -399,7 +424,11 @@ void Test::testGetTypeFavourUnsigned() {
}
void Test::testGetTypeFavourChar() {
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT(typeid(sal_Unicode) == typeid(sal_uInt16));
+#else
+ CPPUNIT_ASSERT(typeid(sal_Unicode) != typeid(sal_uInt16));
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(static_cast<cppu::UnoVoidType *>(nullptr)),
cppu::UnoType<cppu::UnoVoidType>::get());
@@ -419,9 +448,15 @@ void Test::testGetTypeFavourChar() {
cppu::getTypeFavourChar(
static_cast<cppu::UnoUnsignedShortType *>(nullptr)),
cppu::UnoType<cppu::UnoUnsignedShortType>::get());
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(static_cast<sal_uInt16 *>(nullptr)),
cppu::UnoType<cppu::UnoCharType>::get());
+#else
+ CPPUNIT_ASSERT_EQUAL(
+ cppu::getTypeFavourChar(static_cast<sal_uInt16 *>(nullptr)),
+ cppu::UnoType<cppu::UnoUnsignedShortType>::get());
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(static_cast<sal_Int32 *>(nullptr)),
cppu::UnoType<sal_Int32>::get());
@@ -461,10 +496,18 @@ void Test::testGetTypeFavourChar() {
cppu::UnoSequenceType<cppu::UnoUnsignedShortType> *>(nullptr)),
cppu::UnoType<
cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>::get());
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(
static_cast<css::uno::Sequence<sal_uInt16> *>(nullptr)),
cppu::UnoType<cppu::UnoSequenceType<cppu::UnoCharType>>::get());
+#else
+ CPPUNIT_ASSERT_EQUAL(
+ cppu::getTypeFavourChar(
+ static_cast<css::uno::Sequence<sal_uInt16> *>(nullptr)),
+ cppu::UnoType<
+ cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>::get());
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(
static_cast<
@@ -474,6 +517,7 @@ void Test::testGetTypeFavourChar() {
cppu::UnoType<
cppu::UnoSequenceType<
cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>>::get());
+#if defined SAL_W32 && !defined __MINGW32__ // cf. sal/types.h sal_Unicode
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(
static_cast<
@@ -481,6 +525,15 @@ void Test::testGetTypeFavourChar() {
cppu::UnoType<
cppu::UnoSequenceType<
cppu::UnoSequenceType<cppu::UnoCharType>>>::get());
+#else
+ CPPUNIT_ASSERT_EQUAL(
+ cppu::getTypeFavourChar(
+ static_cast<
+ css::uno::Sequence<css::uno::Sequence<sal_uInt16>> *>(nullptr)),
+ cppu::UnoType<
+ cppu::UnoSequenceType<
+ cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>>::get());
+#endif
CPPUNIT_ASSERT_EQUAL(
cppu::getTypeFavourChar(
static_cast<css::uno::Sequence<sal_Unicode> *>(nullptr)),
diff --git a/include/cppu/unotype.hxx b/include/cppu/unotype.hxx
index 2ab7681..a594450 100644
--- a/include/cppu/unotype.hxx
+++ b/include/cppu/unotype.hxx
@@ -149,6 +149,14 @@ cppu_detail_getUnoType(
::typelib_TypeClass_UNSIGNED_SHORT);
}
+#if LIBO_INTERNAL_ONLY && (!defined SAL_W32 || defined __MINGW32__)
+ // cf. sal/types.h sal_Unicode
+inline css::uno::Type const &
+cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_uInt16 const *) {
+ return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_UNSIGNED_SHORT);
+}
+#endif
+
inline css::uno::Type const &
cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) {
return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG);
@@ -186,6 +194,14 @@ cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) {
return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR);
}
+#if LIBO_INTERNAL_ONLY && (!defined SAL_W32 || defined __MINGW32__)
+ // cf. sal/types.h sal_Unicode
+inline css::uno::Type const &
+cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Unicode const *) {
+ return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_CHAR);
+}
+#endif
+
inline css::uno::Type const &
cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) {
return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING);
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index ef2564d..f8dda00 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -638,6 +638,11 @@ public:
return append( &c, 1 );
}
+#if LIBO_INTERNAL_ONLY && (!defined SAL_W32 || defined __MINGW32__)
+ // cf. sal/types.h sal_Unicode
+ void append(sal_uInt16) = delete;
+#endif
+
/**
Appends the string representation of the <code>sal_Int32</code>
argument to this string buffer.
diff --git a/include/sal/types.h b/include/sal/types.h
index 3f999fc..9cd77f8 100644
--- a/include/sal/types.h
+++ b/include/sal/types.h
@@ -149,8 +149,12 @@ typedef unsigned char sal_uChar;
typedef wchar_t sal_Unicode;
#else
#define SAL_UNICODE_NOTEQUAL_WCHAR_T
+#if LIBO_INTERNAL_ONLY && defined __cplusplus
+ typedef char16_t sal_Unicode;
+#else
typedef sal_uInt16 sal_Unicode;
#endif
+#endif
typedef void * sal_Handle;
More information about the Libreoffice-commits
mailing list