Use macro to apply __attribute__((init_priority(val))) where it's supported (gcc+clang) (#3821)

This commit is contained in:
Artem Pavlenko 2018-01-04 14:29:00 +00:00
parent 50169e95b2
commit 92afd0bebf
6 changed files with 47 additions and 7 deletions

View file

@ -0,0 +1,34 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2017 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_INIT_PRIORITY_HPP
#define MAPNIK_INIT_PRIORITY_HPP
// helper macro for dealing with static variables initialising order fiasco (#3821)
#if defined(__GNUC__) || defined(__clang__)
#define MAPNIK_INIT_PRIORITY(priority) __attribute__((init_priority(priority)))
#else
#define MAPNIK_INIT_PRIORITY
// TODO: anything we can do on windows?
#endif
#endif //MAPNIK_INIT_PRIORITY_HPP

View file

@ -26,6 +26,7 @@
#include <boost/fusion/include/std_pair.hpp>
#include <mapnik/json/generic_json_grammar_x3.hpp>
#include <mapnik/json/unicode_string_grammar_x3.hpp>
#include <mapnik/init_priority.hpp>
namespace mapnik { namespace json { namespace grammar {
@ -73,7 +74,7 @@ namespace { auto const& json_string = mapnik::json::unicode_string_grammar(); }
// exported rules
// start
generic_json_grammar_type const value __attribute__((init_priority(102))) ("JSON Value");
generic_json_grammar_type const value MAPNIK_INIT_PRIORITY(102) ("JSON Value");
generic_json_key_value_type const key_value("JSON Object element");
// rules
x3::rule<class json_object_tag, json_object> const object("JSON Object");

View file

@ -23,10 +23,11 @@
#ifndef MAPNIK_JSON_GEOJSON_GRAMMAR_X3_DEF_HPP
#define MAPNIK_JSON_GEOJSON_GRAMMAR_X3_DEF_HPP
#include <mapnik/json/geojson_grammar_x3.hpp>
#include <mapnik/json/unicode_string_grammar_x3.hpp>
#include <mapnik/json/positions_grammar_x3.hpp>
#include <mapnik/init_priority.hpp>
#include <boost/fusion/include/std_pair.hpp>
namespace mapnik { namespace json { namespace grammar {
@ -89,8 +90,8 @@ struct geometry_type_ : x3::symbols<mapnik::geometry::geometry_types>
// exported rules
// start
geojson_grammar_type const value __attribute__((init_priority(106))) ("JSON Value");
key_value_type const key_value __attribute__((init_priority(107))) ("JSON key/value");
geojson_grammar_type const value MAPNIK_INIT_PRIORITY(106) ("JSON Value");
key_value_type const key_value MAPNIK_INIT_PRIORITY(107) ("JSON key/value");
// rules
x3::rule<class json_object_tag, geojson_object> const object("JSON Object");
x3::rule<class json_array_tag, geojson_array> const array("JSON Array");

View file

@ -25,6 +25,7 @@
#include <mapnik/json/positions_grammar_x3.hpp>
#include <mapnik/geometry/fusion_adapted.hpp>
#include <mapnik/init_priority.hpp>
namespace mapnik { namespace json { namespace grammar {
@ -42,7 +43,7 @@ auto assign_helper = [](auto const& ctx)
} // anonymous ns
// start rule
positions_grammar_type const positions __attribute__((init_priority(103))) ("Positions");
positions_grammar_type const positions MAPNIK_INIT_PRIORITY(103) ("Positions");
// rules
x3::rule<class point_class, point> const point("Position");
x3::rule<class ring_class, ring> const ring("Ring");

View file

@ -26,6 +26,8 @@
#include <mapnik/json/unicode_string_grammar_x3.hpp>
#include <mapnik/json/generic_json_grammar_x3.hpp>
#include <mapnik/json/topojson_grammar_x3.hpp>
#include <mapnik/init_priority.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/fusion/adapted/struct.hpp>
@ -304,7 +306,7 @@ struct topojson_geometry_type_ : x3::symbols<int>
} topojson_geometry_type;
// start rule
topojson_grammar_type const topology __attribute__((init_priority(104))) ("Topology");
topojson_grammar_type const topology MAPNIK_INIT_PRIORITY(104) ("Topology");
// rules
x3::rule<class transform_tag, mapnik::topojson::transform> const transform = "Transform";
x3::rule<class bbox_tag, mapnik::topojson::bounding_box> const bbox = "Bounding Box";

View file

@ -24,6 +24,7 @@
#define MAPNIK_JSON_UNICODE_STRING_GRAMMAR_X3_DEF_HPP
#include <mapnik/json/unicode_string_grammar_x3.hpp>
#include <mapnik/init_priority.hpp>
// boost
#include <boost/regex/pending/unicode_iterator.hpp>
//
@ -109,7 +110,7 @@ x3::uint_parser<std::uint16_t, 16, 4, 4> const hex4 {};
x3::uint_parser<uchar, 16, 8, 8> const hex8 {};
// start rule
unicode_string_grammar_type const unicode_string __attribute__((init_priority(101))) ("Unicode String");
unicode_string_grammar_type const unicode_string MAPNIK_INIT_PRIORITY(101) ("Unicode String");
// rules
x3::rule<class double_quoted_tag, std::string> const double_quoted("Double-quoted string");
x3::rule<class escaped_tag, std::string> const escaped("Escaped Character");