Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

windows: Use windows API calls instead of libtool. #1490

Closed
wants to merge 3 commits into from

2 participants

@avlee

No description provided.

@avlee avlee closed this
@avlee avlee reopened this
@springmeyer
Owner

Thanks for the pull. The number of #ifdefs is significant, so I do not plan to apply this as is. It will need to be refactored so that there are only a few #ifdefs used. I will put this on my list to take a look at. In the meantime I'm fine with just keeping this pull open here.

@springmeyer
Owner

refactoring done in 9aa92a5, closing.

@springmeyer springmeyer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 include/mapnik/plugin.hpp
@@ -29,8 +29,13 @@
// stl
#include <string>
+#if defined(_WINDOWS)
+# include <windows.h>
+# define lt_dlhandle HMODULE
+#else
// ltdl
#include <ltdl.h>
+#endif
namespace mapnik
{
View
28 src/datasource_cache.cpp
@@ -31,7 +31,9 @@
#include <boost/algorithm/string.hpp>
// ltdl
+#if !defined(_WINDOWS)
#include <ltdl.h>
+#endif
// stl
#include <algorithm>
@@ -48,12 +50,16 @@ bool is_input_plugin (std::string const& filename)
datasource_cache::datasource_cache()
{
+#if !defined(_WINDOWS)
if (lt_dlinit()) throw std::runtime_error("lt_dlinit() failed");
+#endif
}
datasource_cache::~datasource_cache()
{
+#if !defined(_WINDOWS)
lt_dlexit();
+#endif
}
datasource_ptr datasource_cache::create(const parameters& params, bool bind)
@@ -80,20 +86,33 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind)
if ( ! itr->second->handle())
{
throw std::runtime_error(std::string("Cannot load library: ") +
+#ifdef _WINDOWS
+ itr->second->name());
+#else
lt_dlerror());
+#endif // _WINDOWS
}
+#ifdef _WINDOWS
+ create_ds* create_datasource =
+ reinterpret_cast<create_ds*>(GetProcAddress(itr->second->handle(), "create"));
+#else
// http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
#ifdef __GNUC__
__extension__
#endif
create_ds* create_datasource =
reinterpret_cast<create_ds*>(lt_dlsym(itr->second->handle(), "create"));
+#endif // _WINDOWS
if (! create_datasource)
{
throw std::runtime_error(std::string("Cannot load symbols: ") +
+#ifdef _WINDOWS
+ "plugin is lacking compatible interface");
+#else
lt_dlerror());
+#endif // _WINDOWS
}
#ifdef MAPNIK_LOG
@@ -174,15 +193,24 @@ bool datasource_cache::register_datasource(std::string const& str)
bool success = false;
try
{
+#ifdef _WINDOWS
+ lt_dlhandle module = LoadLibraryA(str.c_str());
+#else
lt_dlhandle module = lt_dlopen(str.c_str());
+#endif // _WINDOWS
if (module)
{
+#ifdef _WINDOWS
+ datasource_name* ds_name =
+ reinterpret_cast<datasource_name*>(GetProcAddress(module, "datasource_name"));
+#else
// http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
#ifdef __GNUC__
__extension__
#endif
datasource_name* ds_name =
reinterpret_cast<datasource_name*>(lt_dlsym(module, "datasource_name"));
+#endif // _WINDOWS
if (ds_name && insert(ds_name(),module))
{
MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Registered=" << ds_name();
View
36 src/load_map.cpp
@@ -67,6 +67,10 @@
#include <iostream>
#include <sstream>
+#ifdef _WINDOWS
+#include <Windows.h>
+#endif
+
using boost::tokenizer;
using std::endl;
@@ -130,6 +134,27 @@ class map_parser : boost::noncopyable {
std::map<std::string,font_set> fontsets_;
};
+#ifdef _WINDOWS
+std::string wstring2string(const std::wstring& s)
+{
+ int slength = (int)s.length() + 1;
+ int len = ::WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
+ boost::scoped_array<char> buf_ptr(new char [len+1]);
+ ::WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, buf_ptr.get(), len, 0, 0);
+ std::string r(buf_ptr.get());
+ return r;
+}
+
+std::wstring utf8ToWide( const std::string& str )
+{
+ int len = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
+ boost::scoped_array<wchar_t> buf_ptr(new wchar_t [len+1]);
+ ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, buf_ptr.get(), len);
+ std::wstring rt(buf_ptr.get());
+ return rt;
+}
+#endif
+
//#include <mapnik/internal/dump_xml.hpp>
void load_map(Map & map, std::string const& filename, bool strict)
{
@@ -680,7 +705,18 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
{
std::string name = paramIter->get_attr<std::string>("name");
std::string value = paramIter->get_text();
+#ifdef _WINDOWS
+ if (name == "file")
+ {
+ params[name] = wstring2string(utf8ToWide(value));
+ }
+ else
+ {
+ params[name] = value;
+ }
+#else
params[name] = value;
+#endif
}
}
View
7 src/plugin.cpp
@@ -21,7 +21,6 @@
*****************************************************************************/
#include <mapnik/plugin.hpp>
-#include <ltdl.h>
namespace mapnik
{
@@ -33,7 +32,11 @@ PluginInfo::~PluginInfo()
{
if (module_)
{
- lt_dlclose(module_),module_=0;
+#if defined(_WINDOWS)
+ FreeLibrary(module_);
+#else
+ lt_dlclose(module_);
+#endif
}
}
Something went wrong with that request. Please try again.