From 47f5cb17525143c85822846139922d9e634a4d0a Mon Sep 17 00:00:00 2001
From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl>
Date: Thu, 21 Feb 2013 13:46:59 +0100
Subject: [PATCH] get back to previous dlopen flags after importing libs that
 need the hack; don't trigger the hack on non-linux systems

---
 iobber/chunker.py | 16 +++++++++++-----
 iobber/corpio.py  | 12 ++++++++++--
 setup.py          |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/iobber/chunker.py b/iobber/chunker.py
index 0a2040c..3abe740 100644
--- a/iobber/chunker.py
+++ b/iobber/chunker.py
@@ -17,18 +17,24 @@ __doc__ = """The actual chunker implementation."""
 # SWIG bug workaround: loading multiple SWIG modules brought unwrapped
 # swig::stop_iteration exceptions
 import ctypes, sys
-if 'setdlopenflags' in sys.__dict__:
-	sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
+import platform
+if 'Linux' in platform.system():
+	# this prevents from problems with multiple SWIG wrappers
+	# (probably bug in SWIG) and possible problems with locating Maca plugin
+	dlflags = sys.getdlopenflags()
+	sys.setdlopenflags(dlflags | ctypes.RTLD_GLOBAL)
 
 import corpus2
-# TODO: get back to default dlopen policy?
+import corpio, config, classify
+
+if 'Linux' in platform.system():
+	# get back to default dlopen policy
+	sys.setdlopenflags(dlflags)
 
 import os, codecs
 import ConfigParser
 from operator import itemgetter as ig
 
-import corpio, config, classify
-
 def get_layers(conf):
 	layers = [(k, v.split(',')) for (k, v) in conf.items(config.S_LAYERS)]
 	for layer in layers:
diff --git a/iobber/corpio.py b/iobber/corpio.py
index 5304651..e44f92c 100644
--- a/iobber/corpio.py
+++ b/iobber/corpio.py
@@ -15,12 +15,20 @@
 # SWIG bug workaround: loading multiple SWIG modules brought unwrapped
 # swig::stop_iteration exceptions
 import ctypes, sys
-if 'setdlopenflags' in sys.__dict__:
-	sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
+import platform
+if 'Linux' in platform.system():
+	# this prevents from problems with multiple SWIG wrappers
+	# (probably bug in SWIG) and possible problems with locating Maca plugin
+	dlflags = sys.getdlopenflags()
+	sys.setdlopenflags(dlflags | ctypes.RTLD_GLOBAL)
 
 import corpus2, wccl
 # TODO: get back to default dlopen policy?
 
+if 'Linux' in platform.system():
+	# get back to default dlopen policy
+	sys.setdlopenflags(dlflags)
+
 import config
 import codecs, os
 
diff --git a/setup.py b/setup.py
index 352cb03..4cb9ca6 100755
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@
 from setuptools import setup
 
 setup(name='iobber',
-	version='1.0.0',
+	version='1.0.1',
 	description='Chunker for Slavic languages based on CRF++ and WCCL',
 	author= "Adam Radziszewski",
 	author_email="adam.radziszewski@pwr.wroc.pl",
-- 
GitLab