MantisBT - Community
View Issue Details
0027478Community[OCCT] OCCT:Configurationpublic2016-05-09 17:282016-12-09 16:37
BenjaminBihler 
kgv 
normalintegration request 
closedfixed 
LinuxDebian 64 Bit
[OCCT] 7.0.0 
[OCCT] 7.1.0[OCCT] 7.1.0 
0027478: Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
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!
Not required
No tags attached.
Issue History
2016-05-09 17:28BenjaminBihlerNew Issue
2016-05-09 17:28BenjaminBihlerAssigned To => BenjaminBihler
2016-05-09 17:33gitNote Added: 0053920
2016-05-09 17:37BenjaminBihlerAssigned ToBenjaminBihler => kgv
2016-05-09 17:37BenjaminBihlerStatusnew => resolved
2016-05-09 17:37BenjaminBihlerSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=13671#r13671
2016-05-09 17:59kgvSeverityminor => integration request
2016-05-09 17:59kgvCategoryOCCT:Visualization => OCCT:Configuration
2016-05-09 18:07kgvNote Added: 0053921
2016-05-09 18:08kgvSummaryThe Include Chain is Polluted with Xlib.h => Configuration - avoid includsion of Xlib.h within Graphic3d_GraphicDriver.hxx
2016-05-09 18:08kgvSummaryConfiguration - avoid includsion of Xlib.h within Graphic3d_GraphicDriver.hxx => Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
2016-05-10 12:51gitNote Added: 0053944
2016-05-10 12:52BenjaminBihlerNote Added: 0053945
2016-05-10 21:00gitNote Added: 0053973
2016-05-10 21:01kgvNote Added: 0053974
2016-05-10 21:01kgvAssigned Tokgv => bugmaster
2016-05-10 21:01kgvStatusresolved => reviewed
2016-05-13 12:41kgvChangeset attached => occt master 5950d781
2016-05-13 12:41kgvAssigned Tobugmaster => kgv
2016-05-13 12:41kgvStatusreviewed => verified
2016-05-13 12:41kgvResolutionopen => fixed
2016-05-20 12:21gitNote Added: 0054180
2016-05-20 12:21gitNote Added: 0054182
2016-12-09 16:33aivStatusverified => closed
2016-12-09 16:37aivFixed in Version => 7.1.0

Notes
(0053920)
git   
2016-05-09 17:33   
Branch CR27478 has been created by BenjaminBihler.

SHA-1: 27c333c7d64165bed4dc156f271fd1890b0d22e9


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.
(0053921)
kgv   
2016-05-09 18:07   
> 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).
(0053944)
git   
2016-05-10 12:51   
Branch CR27478 has been updated by BenjaminBihler.

SHA-1: 1ce974d32838656fa00f91f18abbe0942beed711


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.

(0053945)
BenjaminBihler   
2016-05-10 12:52   
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.
(0053973)
git   
2016-05-10 21:00   
Branch CR27478_1 has been created by kgv.

SHA-1: 5950d7816e4dd6f51d1deaea767d65f80b607bc3


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.
(0053974)
kgv   
2016-05-10 21:01   
Please check compilation of the patch in branch CR27478_1.
Regression testing is not needed.
(0054180)
git   
2016-05-20 12:21   
Branch CR27478_1 has been deleted by inv.

SHA-1: 5950d7816e4dd6f51d1deaea767d65f80b607bc3
(0054182)
git   
2016-05-20 12:21   
Branch CR27478 has been deleted by inv.

SHA-1: 1ce974d32838656fa00f91f18abbe0942beed711