-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intrusive 'private' and 'protected' macros (cleanup list) #11520
Intrusive 'private' and 'protected' macros (cleanup list) #11520
Conversation
We cannot redefine 'private' and 'protected' keywords via macros to e.g. 'public'. This is extremely intrusive and breaks encapsulation. This does not work anymore with new libstdc++ libraries, because foward delcaration of struct is implicitly private and then implementation is under explicit private clause. Redefining 'private' only change one of them thus creating compile-time errors in sstream. Details in PR65899 (GCC BZ). It's WONTFIX. Such cleanups are required for GCC 5 and above. The files in this PR used such intrusive macros, but removal of them breaks compilation. Thus additional review and refactoring is required for droping intrusive macros. This PR acts as a cleanup list. Signed-off-by: David Abdurachmanov <[email protected]>
A new Pull Request was created by @davidlt for CMSSW_7_6_X. Intrusive 'private' and 'protected' macros (cleanup list) It involves the following packages: CalibTracker/SiStripDCS @smuzaffar, @civanch, @diguida, @cvuosalo, @mdhildreth, @monttj, @cmsbuild, @alja, @franzoni, @Dr15Jones, @cerminar, @slava77, @ggovi, @vadler, @mmusich can you please review it and eventually sign? Thanks. |
@cmsbuild please test |
@slava77 this PR will not compile. It only includes cleanups which do not compile. These require a review and refactoring to work without redefining 'private' and 'public'. |
The tests are being triggered in jenkins. |
@davidlt |
I suggest to use sed instead of the macro... |
-1 >> Compiling /tmp/cmsbuild/workspace/ib-any-integration/CMSSW_7_6_X_2015-09-27-2300/src/Fireworks/Core/src/FWExpressionEvaluator.cc >> Compiling /tmp/cmsbuild/workspace/ib-any-integration/CMSSW_7_6_X_2015-09-27-2300/src/Fireworks/Core/src/FWExpressionValidator.cc >> Compiling /tmp/cmsbuild/workspace/ib-any-integration/CMSSW_7_6_X_2015-09-27-2300/src/Fireworks/Core/src/FWFileEntry.cc In file included from /tmp/cmsbuild/workspace/ib-any-integration/CMSSW_7_6_X_2015-09-27-2300/src/Fireworks/Core/src/FWEveView.cc:22:0: /afs/cern.ch/cms/sw/ReleaseCandidates/vol0/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke/include/TGLOrthoCamera.h: In member function 'void FWEveView::addToOrthoCamera(TGLOrthoCamera*, FWConfiguration&) const': /afs/cern.ch/cms/sw/ReleaseCandidates/vol0/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke/include/TGLOrthoCamera.h:54:19: error: 'Double_t TGLOrthoCamera::fZoom' is private Double_t fZoom; // current zoom ^ /tmp/cmsbuild/workspace/ib-any-integration/CMSSW_7_6_X_2015-09-27-2300/src/Fireworks/Core/src/FWEveView.cc:418:16: error: within this context s<<(camera->fZoom); ^ you can see the results of the tests here: |
@VinInn I believe, some of the "target" classes are not from CMSSW code. E.g. Fireworks seems to look into ROOT classes internals. There are other techniques (found after some googling): Or even better, design classes in a way that they could be tested. |
Should we disallow people testing/accessing internals of various classes (CMSSW or not) or we should this to some degree? If allowed (e.g. for white-box testing), I could prepare some slides for showing possible alternatives for Personal opinion would be not to allow and classes should be tested by a public contact (API). If there is a need to test a lots of private/protected stuff, most likely such class needs refactoring. Now for non-test code, we should into refactoring it or/and creating such public API that there wouldn't be a need for @davidlange6 your opinion? |
I have two of these in test code, the purpose was obviously to allow N. On 29-Sep-15 15:23, davidlt wrote:
|
@namapane that's one way to go, e.g. such thing is allowed in Google C++ Test Framework [1]. Also the following should work, by having members as protected:
The in test implementation:
You make it visible in public. In once case it cost you to have a test a friend to the class you want to test, in other case you have to convert private to protected and then have a wrapper class in test code which would expose it as public. Or you can make public APIs and just use those for testing :) The last option templates to make things public: http://bloglitb.blogspot.ch/2010/07/access-to-private-members-thats-easy.html [1] https://code.google.com/p/googletest/wiki/AdvancedGuide#Testing_Private_Code |
I am strongly against making them protected. ROOT did that and it was extremely difficult to avoid problems. |
@Dr15Jones good input, but you elaborate on the issues faced on such method (for the record)? Did that gave too much freedom and people started to abusive it, i.e. changing the internal members of some ROOT classes? |
Allowing protected access makes it very easy for inheriting classes to break class invariants. This was happening all the time in ROOT. When looking for threading problems, one didn't just need to look into the one class iself, but into all classes that directly or indirectly inherited from the class. This was extremely hard to maintain. |
I personally would opt for friendship, in fact this specifes clearly My question was if friendship is anything out of fashion nowadays for N. On 29-Sep-15 16:30, Chris Jones wrote:
|
I would simply add const access methods where possible to get necessary information for testing. |
Personally, I would prefer to allow friendship to be declared for these white-box unit tests. I also find these kinds of tests to be very useful in some cases. |
I believe, people can go ahead and start cleaning up the test code by using adding a test class or/and functions as friends to the class to be tested. Fireworks code will be handled separately (half of the stuff is already available via public APIs on ROOT side). I would like to ask to add a reference from cleanup PRs to this one, that we could track the progress. Or this should be converted to an issue with a list of files to be cleaned up and all the references to PRs should go into that issue. |
Here are all the framework ones |
@davidlt - should we close this PR? |
Latest updates are: Thus we slowly moving forward. Some categories have not yet cleaned up their files, I think. |
I think, all or most of the fixes exist. Closing. |
We cannot redefine 'private' and 'protected' keywords via macros to e.g.
'public'. This is extremely intrusive and breaks encapsulation.
This does not work anymore with new libstdc++ libraries, because foward
delcaration of struct is implicitly private and then implementation is
under explicit private clause. Redefining 'private' only change one of
them thus creating compile-time errors in sstream.
Details in PR65899 (GCC BZ). It's WONTFIX.
Such cleanups are required for GCC 5 and above.
The files in this PR used such intrusive macros, but removal of them
breaks compilation. Thus additional review and refactoring is required
for droping intrusive macros. This PR acts as a cleanup list.
Most of such things (about 35 out of 45) are used in tests.
Signed-off-by: David Abdurachmanov [email protected]