coding standards and order of include files

This is a discussion on coding standards and order of include files within the mysql forums in Other Databases category; While working on the mutex contention stats patch for MySQL 5.1.26 (http://code.google.com/p/google-mysq...ontentionStats), I had a few compiler errors because a couple of files include system header files from /usr/include before my_global.h. This means that all of the magic done by my_global to make things somewhat portable are undone for those files because the special-case #define values are not set. In my case, this made it difficult to get __USE_UNIX98 set so that pthread_rwlock_t would be declared. Is there an expectation that my_global.h is included before any system ...

Go Back   Database Forum > Other Databases > mysql

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-28-2008, 02:13 AM
Default coding standards and order of include files

While working on the mutex contention stats patch for MySQL 5.1.26
(http://code.google.com/p/google-mysq...ontentionStats),
I had a few compiler errors because a couple of files include system
header files from /usr/include before my_global.h. This means that all
of the magic done by my_global to make things somewhat portable are
undone for those files because the special-case #define values are not
set. In my case, this made it difficult to get __USE_UNIX98 set so
that pthread_rwlock_t would be declared.

Is there an expectation that my_global.h is included before any system
header file?


--
Mark Callaghan
mdcallag-at-gmail.com

--
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe: http://lists.mysql.com/internals?uns...ie.nctu.edu.tw

Reply With Quote
  #2  
Old 08-28-2008, 06:22 AM
Default Re: coding standards and order of include files

Hi!

On Aug 27, MARK CALLAGHAN wrote:
> While working on the mutex contention stats patch for MySQL 5.1.26
> (http://code.google.com/p/google-mysq...ontentionStats),
> I had a few compiler errors because a couple of files include system
> header files from /usr/include before my_global.h. This means that all
> of the magic done by my_global to make things somewhat portable are
> undone for those files because the special-case #define values are not
> set. In my case, this made it difficult to get __USE_UNIX98 set so
> that pthread_rwlock_t would be declared.


Could you elaborate on this, please ?
What file was included before my_global.h, and where ?
What magic was undone, how, why ?
I couldn't quite understand the problem, sorry

Regards / Mit vielen Grüßen,
Sergei

--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Sergei Golubchik
/ /|_/ / // /\ \/ /_/ / /__ Principal Software Engineer/Server Architect
/_/ /_/\_, /___/\___\_\___/ Sun Microsystems GmbH, HRB München 161028
<___/ Sonnenallee 1, 85551 Kirchheim-Heimstetten
Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Häring

--
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe: http://lists.mysql.com/internals?uns...ie.nctu.edu.tw

Reply With Quote
  #3  
Old 08-28-2008, 08:01 AM
Default Re: coding standards and order of include files


Hi!

>>>>> "Sergei" == Sergei Golubchik writes:


Sergei> Hi!
Sergei> On Aug 27, MARK CALLAGHAN wrote:
>> While working on the mutex contention stats patch for MySQL 5.1.26
>> (http://code.google.com/p/google-mysq...ontentionStats),
>> I had a few compiler errors because a couple of files include system
>> header files from /usr/include before my_global.h. This means that all
>> of the magic done by my_global to make things somewhat portable are
>> undone for those files because the special-case #define values are not
>> set. In my case, this made it difficult to get __USE_UNIX98 set so
>> that pthread_rwlock_t would be declared.


Sergei> Could you elaborate on this, please ?
Sergei> What file was included before my_global.h, and where ?
Sergei> What magic was undone, how, why ?
Sergei> I couldn't quite understand the problem, sorry

And to answer your question; For MySQL server code, my_global.h
should be included first.

Regards,
Monty

--
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe: http://lists.mysql.com/internals?uns...ie.nctu.edu.tw

Reply With Quote
  #4  
Old 08-28-2008, 10:17 AM
Default Re: coding standards and order of include files

On Thu, Aug 28, 2008 at 2:22 AM, Sergei Golubchik wrote:
> Hi!
>
> On Aug 27, MARK CALLAGHAN wrote:
>> While working on the mutex contention stats patch for MySQL 5.1.26
>> (http://code.google.com/p/google-mysq...ontentionStats),
>> I had a few compiler errors because a couple of files include system
>> header files from /usr/include before my_global.h. This means that all
>> of the magic done by my_global to make things somewhat portable are
>> undone for those files because the special-case #define values are not
>> set. In my case, this made it difficult to get __USE_UNIX98 set so
>> that pthread_rwlock_t would be declared.

>
> Could you elaborate on this, please ?


In my case, I want to get the declaration of pthread_rwlock_t, so
__USE_UNIX98 must be declared before is included. For
the code that includes a system header file before including
my_global.h, was indirectly includes by the system
header file and __USE_UNIX98 was not set (because my_global.h had yet
to be read). For good reason, I can't force to be reread
as it #defines a value to prevent that.

> What file was included before my_global.h, and where ?


This includes before "my_global.h"
storage/archive/azlib.h

These include before "my_global.h"
unittest/examples/core-t.c
unittest/examples/no_plan-t.c
unittest/examples/skip_all-t.c
unittest/examples/todo-t.c
unittest/mytap/t/basic-t.c

> What magic was undone, how, why ?


In my case, I need __USE_UNIX98 to be #defined before system header
files are read. But my_global.h is full of fixes for platform-specific
problems some of which are related to system header files. Whether or
not my problem occurs, other problems will occur if code continues to
include system header files first.

> I couldn't quite understand the problem, sorry
>
> Regards / Mit vielen Grüßen,
> Sergei
>
> --
> __ ___ ___ ____ __
> / |/ /_ __/ __/ __ \/ / Sergei Golubchik
> / /|_/ / // /\ \/ /_/ / /__ Principal Software Engineer/Server Architect
> /_/ /_/\_, /___/\___\_\___/ Sun Microsystems GmbH, HRB München 161028
> <___/ Sonnenallee 1, 85551 Kirchheim-Heimstetten
> Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
> Vorsitzender des Aufsichtsrates: Martin Häring
>




--
Mark Callaghan
mdcallag-at-gmail.com

--
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe: http://lists.mysql.com/internals?uns...ie.nctu.edu.tw

Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 02:11 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.