[Python-Dev] #ifdeffery

Michael Hudson mwh at python.net
Fri Aug 13 13:05:20 CEST 2004


"Raymond Hettinger" <python at rcn.com> writes:

> P.S.  Side rant:  Also, in the last few months, the #ifdefs have
> multiplied.  While I understand that some things like time stamping are
> worthwhile, the code is getting harder to read and maintain because of
> all this b.s.  

Is it really getting worse?

I think there are two qualitatively different sorts of #ifdef mess:
feature ones, like the WITH_TSC I've recently been fiddling with
recently and portability ones.

The feature #ifdefs aren't (or shouldn't be) that much of a big deal.
Ideally, they are documented in Misc/SpecialBuilds.txt and depending
on whether they are defined or not, bits and pieces of code are or are
not included.

Platform #ifdefs, on the other hand, are pain in a tin.

> At some point, someone changed a definition and I had to add an #ifdef
> to import addrinfo.h for VC++ 6.0.  I noticed the same had to be done
> for Cygwin and there was a similar GCC entry.  Each checkin was done by
> a separate person fixing a crash in their own part of the universe.  The
> right answer would have likely been to refactor the original change that
> mucked up everyone else's compile.   Instead we ended up with a pile of
> conditionals that will be hard to maintain going forward because the
> surrounding code has become so stiff.

Of course the problem here is that it's takes a lot of courage to make
changes that affect systems you don't have access to.  One of the
goals of Include/pyport.h is that this localizes the mess: think of a
sensibly named preprocessor symbol (PY_WE_NEED_ADDRINFO_H?) and put
all the bullshit needed to work out whether to define it in one place.
But you really want to get things like this right, especially if one
of the affected platforms is something a little obscure.  Break things
on linux/x86 and you'll find out pretty quickly, but break them on
Irix and it may take months and it won't be obvious which change is
at fault.

Still, I want at some point to do test builds on all the test drive
machines at some point before 2.4 final, so any changes will hopefully
get some amount of testing on these systems at least.

Cheers,
mwh

-- 
  (Unfortunately, while you get Tom Baker saying "then we 
   were attacked by monsters", he doesn't flash and make 
  "neeeeooww-sploot" noises.)
      -- Gareth Marlow, ucam.chat, from Owen Dunn's review of the year


More information about the Python-Dev mailing list