[Libreoffice] Removal of rtl::O[U]String[Buffer]::operator sal_{char|Unicode} const *()
Stephan Bergmann
sbergman at redhat.com
Tue Sep 27 12:00:28 PDT 2011
Hi all,
As has recently been discussed on #libreoffice-dev, its probably a good
idea to remove the rather unhelpful conversion operators
rtl::OString::operator sal_Char const * ()
rtl::OStringBuffer::operator sal_Char const * ()
rtl::OUString::operator sal_Unicode const * ()
rtl::OUStringBuffer::operator sal_Unicode const * ()
(The reason why this came up on IRC this time was that the expression
"aStr = aStr + cSep" with aStr of type rtl::OString and cSep of type
sal_Char had a rather non-intuitive meaning, implicitly converting aStr
into a sal_Char const *, adding the integral value of cSep to that
pointer, and then converting that modified sal_Char const * back into an
rtl::OString via the rtl::OString(sal_Char const *) constructor.)
The change will be source-code incompatible, but that is probably
acceptable:
- The change is ABI compatible (involving only inline C++ functions).
- The ~only legitimate use case for those conversion operators was in
indexing expressions like aStr[n]. To continue those expressions to
work, appropriate operator [](sal_Int) member functions will be added to
the four classes.
- All other uses of the conversion operators should use the getStr()
member functions. (Also note that there might be cases where
translation between, say, rtl::OString and char const * via naive
application of rtl::OString::getStr() is not appropriate as it
potentially looses information, when the given rtl::OString instance
contains NUL characters. Having the calls to getStr explicitly in the
code helps auditing in this case.)
My plan is as follows:
- I just pushed
<http://cgit.freedesktop.org/libreoffice/core/commit/?id=6671fa81db0ecea4ada005bb79f55f08fb440ad4>
"Removed uses of rtl::O[U]String[Buffer]::operator sal_{char|Unicode}
const *()." and
<http://cgit.freedesktop.org/libreoffice/binfilter/commit/?id=34c2ec87db4b6962ded661157056c58163e39821>
"Removed uses of rtl::O[U]String[Buffer]::operator sal_{char|Unicode}
const *()." That clears the current master of all dubious (i.e.,
non-[]) uses of the conversion operators for a Linux x86_64
--enable-binfilter --enable-dbgutil "make check" build.
- A few more builds (e.g., Windows, Mac OS X) should be done with the
below patch to ensure that as many dubious uses in
platform-/configuration-switch-specific code as possible have been
fixed. If someone wants to give me a hand here, that would be great.
- The attached no-string-conversion.patch will remove the conversion
operators and introduce the operator [] replacements. It can be
committed to master once the above step is done, in the 3.5 time frame.
(If anybody has objections to this, esp. as it nominally breaks
backwards compatibility at the source level, raise your hands.)
-Stephan
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: no-string-conversion.patch
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110927/58c2d440/attachment.txt>
More information about the LibreOffice
mailing list