Archived issue #0027478
Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
Description
Xlib.h is a terrible include file. It defines keywords like None, Unsorted, Status, Bool and so on (see InterfaceGraphic.hxx below the line starting with "// workaround name conflicts").
If a header file includes Xlib.h, including that header file becomes dangerous, since whenever keywords like the ones named above are used, the compiler will report errors. Sometimes this is necessary (for example if an element defined in Xlib.h is a member field of a class), but it should be done as rarely as possible.
This compile problem happens here. One of my header files must include Graphic3d_GraphicDriver.hxx, which includes Aspect_DisplayConnection.hxx, which includes InterfaceGraphic.hxx, which includes Xlib.h. And this polluted chain makes g++ refuse compiling my project (this has not been the case with OCCT 6.8.0). :-(
One possibility to solve that would be to stop Graphic3d_GraphicDriver.hxx from including Aspect_DisplayConnection.hxx. Since Graphic3d_GraphicDriver has a member field of type Handle(Aspect_DisplayConnection), it needs to know that handle.
I will create a proposal commit by removing the include and adding the handle definition to Graphic3d_GraphicDriver.hxx.
Caution: This actually means duplication of the handle definition code. This in turn could be prevented by creating a file Aspect_DisplayConnection_Handle.hxx which could contain the handle definition and had to be included by everyone interested in that handle. Do you prefer that? Or do you have another standard way to deal with such cases?
Thank you!
If a header file includes Xlib.h, including that header file becomes dangerous, since whenever keywords like the ones named above are used, the compiler will report errors. Sometimes this is necessary (for example if an element defined in Xlib.h is a member field of a class), but it should be done as rarely as possible.
This compile problem happens here. One of my header files must include Graphic3d_GraphicDriver.hxx, which includes Aspect_DisplayConnection.hxx, which includes InterfaceGraphic.hxx, which includes Xlib.h. And this polluted chain makes g++ refuse compiling my project (this has not been the case with OCCT 6.8.0). :-(
One possibility to solve that would be to stop Graphic3d_GraphicDriver.hxx from including Aspect_DisplayConnection.hxx. Since Graphic3d_GraphicDriver has a member field of type Handle(Aspect_DisplayConnection), it needs to know that handle.
I will create a proposal commit by removing the include and adding the handle definition to Graphic3d_GraphicDriver.hxx.
Caution: This actually means duplication of the handle definition code. This in turn could be prevented by creating a file Aspect_DisplayConnection_Handle.hxx which could contain the handle definition and had to be included by everyone interested in that handle. Do you prefer that? Or do you have another standard way to deal with such cases?
Thank you!
Steps to reproduce
Not required
Public activity
8 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Mon May 9 16:31:38 2016 +0200
0027478: The Include Chain is Polluted with Xlib.h
Removed inclusion of Aspect_DisplayConnection.hxx fromGraphic3d_GraphicDriver.hxx
and added handle definition.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Mon May 9 16:31:38 2016 +0200
0027478: The Include Chain is Polluted with Xlib.h
Removed inclusion of Aspect_DisplayConnection.hxx fromGraphic3d_GraphicDriver.hxx
and added handle definition.
> Caution: This actually means duplication of the handle definition code.
> This in turn could be prevented by creating a file Aspect_DisplayConnection_Handle.hxx which could contain the handle definition and had to be included by everyone interested in that handle.
Since OCCT 7.0.0 handle is a template class - so there would not be a duplicate class definition (typedef to the same type is perfectly fine). Technically forward-declared Aspect_DisplayConnection should be sufficient in this context - no need to use DEFINE_STANDARD_HANDLE macros.
However, in particular cases compiler may complain about missing class definition when instantiating destructor of handle template - which can be solved by adding empty exported destructor ~Graphic3d_GraphicDriver() (otherwise implicit default destructor might be instantiated at application code causing this error).
> This in turn could be prevented by creating a file Aspect_DisplayConnection_Handle.hxx which could contain the handle definition and had to be included by everyone interested in that handle.
Since OCCT 7.0.0 handle is a template class - so there would not be a duplicate class definition (typedef to the same type is perfectly fine). Technically forward-declared Aspect_DisplayConnection should be sufficient in this context - no need to use DEFINE_STANDARD_HANDLE macros.
However, in particular cases compiler may complain about missing class definition when instantiating destructor of handle template - which can be solved by adding empty exported destructor ~Graphic3d_GraphicDriver() (otherwise implicit default destructor might be instantiated at application code causing this error).
Branch [archived branch] has been updated by Author.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Tue May 10 11:50:36 2016 +0200
0027478: Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
Replaced handle definition by forward declaration.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Tue May 10 11:50:36 2016 +0200
0027478: Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
Replaced handle definition by forward declaration.
You are right (I still have to get used to the new handle). I have removed the DEFINE_STANDARD_HANDLE macro and added the forward declaration. It works here on Windows 64 and on Linux. The empty exported destructor I have not added, since it has not been necessary here.
Branch [archived branch] has been created by Commenter 1.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Tue May 10 20:59:55 2016 +0300
0027478: Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
Replace Aspect_DisplayConnection.hxx inclusion by forward declaration.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Tue May 10 20:59:55 2016 +0300
0027478: Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
Replace Aspect_DisplayConnection.hxx inclusion by forward declaration.
Please check compilation of the patch in branch CR27478_1.
Regression testing is not needed.
Regression testing is not needed.
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]