Skip to content
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

make file var shape_ const since it is only read #2413

Merged
merged 1 commit into from
Feb 13, 2014
Merged

make file var shape_ const since it is only read #2413

merged 1 commit into from
Feb 13, 2014

Conversation

gartung
Copy link
Member

@gartung gartung commented Feb 11, 2014

File vars need to be const qualified when possible for thread safety. Once instantiated this never gets modified in production.

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @gartung (Patrick Gartung) for CMSSW_7_1_X.

make file var shape_ const since it is only read

It involves the following packages:

CondFormats/CastorObjects

@apfeiffer1, @diguida, @cmsbuild, @nclopezo, @rcastello, @ggovi, @Degano can you please review it and eventually sign? Thanks.
You can sign-off by replying to this message having '+1' in the first line of your reply.
You can reject by replying to this message having '-1' in the first line of your reply.
@nclopezo, @ktf you are the release manager for this.
You can merge this pull request by typing 'merge' in the first line of your comment.

@cmsbuild
Copy link
Contributor

@apfeiffer1
Copy link
Contributor

+1

@ktf
Copy link
Contributor

ktf commented Feb 13, 2014

Bypassing AlCa signature. Complain if not ok. The day we will allow constexpr constructors in our data formats is always too far away.

ktf added a commit that referenced this pull request Feb 13, 2014
…s-work

Misc fixes -- Make file var shape_ const since it is only read
@ktf ktf merged commit ad7ff97 into cms-sw:CMSSW_7_1_X Feb 13, 2014
@gartung gartung deleted the CondFormats-CastorObject-statics-work branch February 13, 2014 22:00
@diguida
Copy link
Contributor

diguida commented Feb 14, 2014

+1
Ok for us, no complains at all when thread safety is involved!

@VinInn
Copy link
Contributor

VinInn commented Feb 14, 2014

ahhhgggg
this is anonymous namespace in a header file!!!!
is the same as C static (is our so smart static analyzer not able to catch anonymous namespace in header files?)
it will be local and hidden in each file where the header is included....
Please either move in the compilation unit were is used or make it class static if needed in more than one compilation unit!

@gartung
Copy link
Member Author

gartung commented Feb 14, 2014

@VinInn
Copy link
Contributor

VinInn commented Feb 14, 2014

I am not aging about thread safety,
I am arguing about the fact that it will not work as intended if accessed from multiple compilation units even in the same library. It's a bug
nm -C $CMSSW_RELEASE_BASE/lib/slc6_amd64_gcc481/libCondFormatsCastorObjects.so | grep shape_
000000000007a040 b (anonymous namespace)::shape_
000000000007a280 b (anonymous namespace)::shape_
000000000007a4e0 b (anonymous namespace)::shape_

@diguida
Copy link
Contributor

diguida commented Feb 14, 2014

Hi!
This could easily be a static const in the class definition: it is only accessed by

const CastorQIEShape& getShape () const

and the class interface does not modify it.
@VinInn am I right?

@VinInn
Copy link
Contributor

VinInn commented Feb 14, 2014

yes, I think you are right.

@gartung
Copy link
Member Author

gartung commented Feb 14, 2014

Making shape_ static const class member gives compilation errors.
Making shape_ a function static const var works:

const CastorQIEShape& getShape () const { return shape_;}
const CastorQIEShape& getShape () const { static const CastorQIEShape shape_;return shape_;}

nm -C ~/CMSSW_7_1_0_pre2/lib/slc5_amd64_gcc481/libCondFormatsCastorObjects.so | grep shape_
0000000000079f40 V guard variable for CastorQIEData::getShape() const::shape_
0000000000079d30 V CastorQIEData::getShape() const::shape_

@gartung
Copy link
Member Author

gartung commented Feb 14, 2014

OK, Chris showed me how to initialize a static const member correctly in the .cc file and nm shows only one symbol:

nm -C ~/CMSSW_7_1_0_pre2/lib/slc5_amd64_gcc481/libCondFormatsCastorObjects.so | grep shape_
0000000000079d60 B CastorQIEData::shape_

I will submit a pull request for this change.

@VinInn
Copy link
Contributor

VinInn commented Feb 14, 2014

and no "guard variable" (used to make the function static construction thread safe)
excellent!

@gartung
Copy link
Member Author

gartung commented Feb 14, 2014

#2473

@diguida
Copy link
Contributor

diguida commented Feb 14, 2014

Thanks!

@nclopezo nclopezo modified the milestones: CMSSW_7_1_0_pre4, CMSSW_7_1_0_pre3 Feb 24, 2014
@nclopezo nclopezo modified the milestones: CMSSW_7_1_0_pre5, CMSSW_7_1_0_pre4 Mar 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants