Bug 82580

Summary: get rid of prewin.h / postwin.h wrapper headers
Product: LibreOffice Reporter: Michael Stahl <mst.fdo>
Component: LibreofficeAssignee: Not Assigned <libreoffice-bugs>
Status: NEW --- QA Contact:
Severity: normal    
Priority: medium CC: libreoffice
Version: Inherited From OOo   
Hardware: Other   
OS: Windows (All)   
Whiteboard: EasyHack DifficultyBeginner SkillCpp TopicCleanup target:4.4.0
i915 platform: i915 features:

Description Michael Stahl 2014-08-13 20:12:30 UTC
includes of Win32 headers in LO are wrapped with
#include <prewin.h>
and
#include <postwin.h>

this is because old LO code, especially in "tools" and "vcl",
defines types that have the same names as Win32 types,
so the headers do a bunch of stupid macro hackery
to rename the Win32 types so they don't collide with LO types.

it would be obviously much simpler if the LO types
simply had names that don't collide with Win32 types.

"git grep" or ctags or opengrok.libreoffice.org
should find the definitions of types in LO that are re-defined
in the wrapper headers.

there are several ways to clean up collisions:

1) if there is no equivalent in LO of the redefined type,
   it can just be removed from the wrapper header

2) in some cases it can be avoided to have the Win32 type
   and the LO type visible in the same LO source file
   by not including both the defining LO and Win32 headers

3) if the Win32 type is not a macro, then putting the LO
   type into a namespace and namespace-qualifying the uses
   should avoid the collisions

4) if the Win32 type is a macro, then adding a namespace-like
   prefix to the LO type is probably required
Comment 1 Tor Lillqvist 2014-08-16 06:39:42 UTC
One note, that I sadly think needs to be spelled out: Please don't attempt to do this unless you actually have Windows, Visual Studio, etc and are able to build LibreOffice on Windows. Don't submit changes without verifying yourself that they don't break the compilation.
Comment 2 Commit Notification 2014-08-16 15:55:26 UTC
Tor Lillqvist committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=a8669b56b194a7cd6da771dfb9904710da24c0b4

fdo#82580: Win32 GetObject() simplification



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 3 Thomas Arnhold 2014-08-16 17:47:24 UTC
(In reply to comment #0)
> 2) in some cases it can be avoided to have the Win32 type
>    and the LO type visible in the same LO source file
>    by not including both the defining LO and Win32 headers

Note, that this could be complicated, because we (mostly) use precompiled headers on Windows, which include nearly all headers needed by a module. See for example oox/inc/pch/precompiled_oox.hxx, which includes all headers from the oox module. And thus avoiding to include one file could be problematic.
Comment 4 Noel Grandin 2014-08-17 08:43:40 UTC
Personally I think we should do what Cygwin have done and create our own copy of the win32 header that only contains the definitions we need, thus minimizing the odds of conflict.
Comment 5 Tor Lillqvist 2014-08-17 09:57:22 UTC
That is madness. We can't cross-compile a complete LibreOffice because the reverse-engineered headers provided by mingw-w64 are incomplete. And those headers have a very long history. So you expect us to be able to create something similar, and in a legally valid clean-room fashion, just like that?

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.