diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-11-13 01:24:40 -0500 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-12-07 11:52:31 +0100 |
commit | ad5fb8798b295e9ad706a3836ffb53a0630f752f (patch) | |
tree | 35cdee5e43071fa1788fb6b60eb25623ed0c0b1b /desktop | |
parent | 2bfc4494727d347d6ae8e0c6a68dee39a2dda040 (diff) |
LOK: Fix API for renderShapeSelection
Unlike C++, C doesn't allow reference-to-pointer types,
and we do have C code that wouldn't compile with ref-to-ptr.
Had to change to ptr-to-ptr, which is the proper way of
having output arrays.
For the same reason, we cannot use new/delete, rather we
must use malloc/free.
Another (lesser) issue was that we used the renderShapeSelection
API to echo back an array we give it as prefix. This made
the API unecessarily complex (in undocumented ways) and
forced the implementation to both worry about user-data
and managing the input memory. This logic is best moved
to the client and the API simply returns the output data.
Speaking of returning data, the API now returns the size
of the array it allocated and wrote to, so the client
can do a simple check on the return value directly.
Change-Id: Ida216c10d5b37efd1e0861e26b72cabb25c568e6
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 1 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 50 |
2 files changed, 32 insertions, 19 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 81a51de8cde9..5bf343b8c825 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2459,6 +2459,7 @@ void DesktopLOKTest::testInsertCertificatePEM() comphelper::LibreOfficeKit::setActive(false); } + namespace { constexpr size_t documentClassOffset(int i) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 72af9accb971..90994a92c257 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -751,7 +751,7 @@ static bool doc_addCertificate(LibreOfficeKitDocument* pThis, static int doc_getSignatureState(LibreOfficeKitDocument* pThis); -static void doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char*& pOutput, size_t& nOutputSize); +static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOutput); LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : mxComponent(xComponent) @@ -2602,35 +2602,47 @@ static void doc_postWindowKeyEvent(LibreOfficeKitDocument* /*pThis*/, unsigned n } } -static void doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char*& pOutput, size_t& nOutputSize) +static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOutput) { SolarMutexGuard aGuard; if (gImpl) gImpl->maLastExceptionMsg.clear(); - LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); - - uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); + try + { + LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); - SvMemoryStream aOutStream; - uno::Reference < io::XOutputStream > xOut = new utl::OOutputStreamWrapper( aOutStream ); + uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= OUString("impress_svg_Export"); - aMediaDescriptor["SelectionOnly"] <<= true; - aMediaDescriptor["OutputStream"] <<= xOut; + SvMemoryStream aOutStream; + uno::Reference<io::XOutputStream> xOut = new utl::OOutputStreamWrapper(aOutStream); - xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList()); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("impress_svg_Export"); + aMediaDescriptor["SelectionOnly"] <<= true; + aMediaDescriptor["OutputStream"] <<= xOut; + xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList()); - size_t nStreamSize = aOutStream.GetEndOfData(); - char* pTmp = pOutput; - pOutput = new char[nOutputSize + nStreamSize]; - std::memcpy(pOutput, pTmp, nOutputSize); - std::memcpy(pOutput+nOutputSize, aOutStream.GetData(), nStreamSize); + if (pOutput) + { + const size_t nOutputSize = aOutStream.GetEndOfData(); + *pOutput = static_cast<char*>(malloc(nOutputSize)); + if (*pOutput) + { + std::memcpy(*pOutput, aOutStream.GetData(), nOutputSize); + return nOutputSize; + } + } + } + catch (const uno::Exception& exception) + { + if (gImpl) + gImpl->maLastExceptionMsg = exception.Message; + SAL_WARN("lok", "Failed to render shape selection: " << exception); + } - nOutputSize += nStreamSize; - delete [] pTmp; + return 0; } /** Class to react on finishing of a dispatched command. |