Merge pull request #3395 from mapnik/register-gdal-once

register gdal once at plugin load
This commit is contained in:
Dane Springmeyer 2016-04-05 20:53:25 -04:00
commit 585de5956b
4 changed files with 25 additions and 9 deletions

View file

@ -39,6 +39,7 @@ class PluginInfo : util::noncopyable
{
public:
using callable_returning_string = const char* (*) ();
using callable_returning_void = void (*) ();
PluginInfo (std::string const& filename,
std::string const& library_name);
~PluginInfo();

View file

@ -44,11 +44,14 @@ using mapnik::featureset_ptr;
using mapnik::layer_descriptor;
using mapnik::datasource_exception;
static std::once_flag once_flag;
static bool GDALAllRegister_once_()
extern "C" MAPNIK_EXP void on_plugin_load()
{
static bool const quiet_unused = (GDALAllRegister(), true);
return quiet_unused;
// initialize gdal formats
std::call_once(once_flag,[](){
GDALAllRegister();
});
}
gdal_datasource::gdal_datasource(parameters const& params)
@ -60,8 +63,6 @@ gdal_datasource::gdal_datasource(parameters const& params)
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Initializing...";
GDALAllRegister_once_();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::init");
#endif

View file

@ -59,6 +59,16 @@ using mapnik::datasource_exception;
using mapnik::filter_in_box;
using mapnik::filter_at_point;
static std::once_flag once_flag;
extern "C" MAPNIK_EXP void on_plugin_load()
{
// initialize ogr formats
// NOTE: in GDAL >= 2.0 this is the same as GDALAllRegister()
std::call_once(once_flag,[](){
OGRRegisterAll();
});
}
ogr_datasource::ogr_datasource(parameters const& params)
: datasource(params),
@ -87,10 +97,6 @@ void ogr_datasource::init(mapnik::parameters const& params)
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::init");
#endif
// initialize ogr formats
// NOTE: in GDAL >= 2.0 this is the same as GDALAllRegister()
OGRRegisterAll();
boost::optional<std::string> file = params.get<std::string>("file");
boost::optional<std::string> string = params.get<std::string>("string");
if (!string) string = params.get<std::string>("inline");

View file

@ -60,6 +60,10 @@ PluginInfo::PluginInfo(std::string const& filename,
{
callable_returning_string name = reinterpret_cast<callable_returning_string>(dlsym(module_->dl, library_name.c_str()));
if (name) name_ = name();
callable_returning_void init_once = reinterpret_cast<callable_returning_void>(dlsym(module_->dl, "on_plugin_load"));;
if (init_once) {
init_once();
}
}
#else
#ifdef MAPNIK_HAS_DLCFN
@ -68,6 +72,10 @@ PluginInfo::PluginInfo(std::string const& filename,
{
callable_returning_string name = reinterpret_cast<callable_returning_string>(dlsym(module_->dl, library_name.c_str()));
if (name) name_ = name();
callable_returning_void init_once = reinterpret_cast<callable_returning_void>(dlsym(module_->dl, "on_plugin_load"));;
if (init_once) {
init_once();
}
}
#else
throw std::runtime_error("no support for loading dynamic objects (Mapnik not compiled with -DMAPNIK_HAS_DLCFN)");