Boost.Geometry and macros made by Apple

Boost Geometry (aka Generic Geometry Library, GGL)I have no pleasure continuing my macros are evil tales but the life of C++ programmer eagerly wants to writes add another chapter to the story. Today, it’s time to rant on Apple and its XCode.

One of Boost Geometry (aka GGL) users, Mark, reported that he can not compile his program using the library with GNU C++ compiler from XCode. The compiler throws mysterious complain of a very low-level nature of C++ programming language:

Expected unqualified-id before 'do' in
/usr/local/include/boost_1_42_0/boost/geometry/geometries/concepts/check.hpp

Thanks to follow-up by Stjepan we quickly know who to blame for that. It is XCode header AssertMacros.h. It even might be one of public headers from development package of XNU, the Mac OS X kernel, what’s even more fun.

What actually happens that causes the problem?

Boost Geometry defines function template for concept checking:

template <typename Geometry>
inline void check()
{
    detail::checker<Geometry, boost::is_const<Geometry>::type::value> c;
    boost::ignore_unused_variable_warning(c);
}

Apple XCode defines macro using exactly the same name as the function check. The C++ preprocessor, which operates before compiler, substitutes the name check with content of the macro. For the Boost Geometry function check it means that a pile of garbage is injected in place were the function name is expected:

template <typename Geometry>
inline void do { if ( __builtin_expect(!(), 0) ) { DebugAssert('?*?*',
0, "Third Party Client" ": " "", 0, 0, "/usr/local/include/boost/
geometry/geometries/concepts/check.hpp", 181, (void*)0); } } while ( 0 )
{
     detail::checker::type::value> c;
     boost::ignore_unused_variable_warning(c);
}

Obviously, it makes compiler to give up to instantiate the check function from the template and to compile it properly.

C/C++ macros are evil, however, not by design but by insanity of programmers. Every macro defined in a public C/C++ header, should be defined using as unique as possible, but still usable name. I wish Apple folks designed their C/C++ macros as unique as they make their hardware products, even if made in China eventually. This particular macro that caused the problems discussed here, could be named to APPLE_XNU_CHECK and life would be easier. Or, given the fact that almost 3000 files using these identifiers live in Boost C++ Libraries only, I probably should say: life would be more productive, efficient and cheaper.

By the way, it’s a known problem @ Boost and it looks Boost Folks are trying to figure out best solution. See ticket #2115 – Avoid bad Apple macros.

…to be continued

Kitware Developer blog launched

CMake - cross-platform build systemA few minutes ago, Bill Hoffman from Kitware posted short message to the CMake project mailing list with an interesting announce:

Kitware launched its first developer blog today with contributions from Company technical and business leaders.

The CMake build system is one of the main category of topics on the Kitware blog, so I presume it may be of interest of OSGeo Community as the CMake build system is slowly winning over more and more folks here :-)

First CMake-related post is about Deploying on Windows with DLL Manifest Issue

Another interesting post on the blog is Will Schroeder‘s answer to the question Why Open Source Will Rule Scientific Computing? It’s really worth reading.

Video lecture about CMake

Bill Hoffman from Kitware gives presentation about CMake and a pack of related tools to the happiest easygoing working nation on the Earth:

It’s worth to watch if interested in CMake.

Mac Pro collocation wanted

Don't ask what OSGeo can do for you, ask what you can do for OSGeoToday, I sent a post to OSGeo Discuss mailing list asking for help with finding new home for my Mac Pro workstation. I’m trying to use all possible channels to spread my call, so here we go:

Folks,

I have a pretty powerful workstation that I’d like to connect to OSGeo infrastructure, somehow. It is: Mac Pro:

  • 2 x Intel Xeon 2.66GHz (5150, “Woodcrest”, dual core)
  • 16 GB RAM
  • 1.5 TB HDD

If I’ll manage to find a new home for my machine, I want to extend the RAM to 16 GB and get one or more TB of HDD.

I’m looking for possibility of collocation my machine somewhere in UK (not necessarily in London), so it can be permanently connected to OSGeo infrastructure. Unfortunately, I am not able to connect this machine from home and keep connected 24/7.

I would be delighted to make it available for OSGeo projects and their development purposes like Buildbot, scheduled builds, software testing, etc. The only personal use of this machine I would like to be able to do is…development and software testing of OSGeo software I work with plus I’d like to keep some personal backups there (disks are getting cheap, so it shouldn’t be a problem to extent to tens of TB in near future). OS X Leopard and license for Parallels VM software is included.

I tried to find collocation service in Poland or UK but prices like ~100 GBP/month are too high to pay for the purposes I’d like to dedicate my machine to.

So, if anyone knows a data centre in UK that would be interested in “rescuing” the wasted CPU cycles of my machine resting in the box please let me know. I think providing collocation could be a nice way to sponsor OSGeo by contributing this reasonably good hardware option :-)

Currently, the machine rests in box in my flat in Poland (I live in London, UK). If I find a place for it, I’ll ship it from PL to UK quickly.

A few pictures of the hardware:

Two Towers IMGP2541.JPG Make jobs benchmark building GDAL/OGR Isn't it beautiful? IMGP2533.JPG

Please, contact me if you can help!

Portability poem

Meaning of PortabilityNumber of OSGeo stack software written by C/C++ camp have to run on Microsoft Windows systems. I think I wouldn’t be dead wrong if said that most of hackers from OSGeo Community work on Unix systems (Linux, Mac OS X) but there is large number of users who work on Windows.

Conclusion? Portability. Google is bursting at the seams of the essays about how to write portable code in C or C++ language. I’d add a little poem to the collection.

Principles of Portability

  • Obey the standards, because they are not just dumb rules.
  • Make a list of compilers that must be supported. Learn about their differences.
  • If possible, use GCC 4+ and Visual C++ 7.1+.
  • Using old compilers? If possible, use C89 but avoid C99.
  • Prefer GCC 4.3 and Visual C++ 8.0+, so you get C++0x support. C++0x “brings C++ more in line with the C99″ – Wikipedia, so portability is much easier.
  • Write code in C or in C++, but do not write both at the same time.
  • Avoid (direct) use of C POSIX Library.
  • Never ever disable any warnings compiler throw. Fix them.
  • Be pedantic. Compile in highest strict mode possible.
  • If possible, do not use compiler-specific features.
  • Do not make platform/architecture specific assumptions about memory addressing, memory layout, etc.
  • First understand why, then cast the hack.
  • Personal preferences are evil. Make decisions based on reasoning.
  • (Re)Use good code that already exist. Boost C++ Libraries won’t bite you!
  • KIMS (Keep it modular, stupid) and let modules to loose coupling but keep cohesion in architecture, design as well as in development cycle (releases, inter-modular dependencies).

Quick Look and Spotlight plugins for GIS

I had been thinking about developing something like that since I started to use Mac OS X as my development environment, but I left my Apple boxes at home in PL and now I’ve switched back to Linux (you simply can’t forget your roots :-)) . So, the idea has been swapped in the abyss of my mind until I accidentally came across GISLook five minutes ago:

GISLook and GISMeta are plugins for Mac OS X 10.5 that show GIS data in the Finder.

These cool-looking plugins were created by Bernhard Jenny.

I know many GIS users loving products of the forbidden fruit, so I’m spreading the word about these nice looking and, hopefully, well working tools.