diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2015-06-25 17:12:10 +0200 |
---|---|---|
committer | Dieter Verfaillie <dieterv@optionexplicit.be> | 2015-06-29 16:56:18 +0200 |
commit | bb891d97810239fc596ab70503a77a918e5658f5 (patch) | |
tree | c8666cd52652380d9cfb7e562104c33dd3d4fadc /giscanner | |
parent | 87b047cabacfadc3fa04b541ab6d57ff50dbcba8 (diff) | |
download | gobject-introspection-bb891d97810239fc596ab70503a77a918e5658f5.tar.gz |
scanner: document LibtoolImporter.load_module()
It was reported by HeBD on #introspection that Python modules
use the .pyd extension on windows, not .dll.
The simple fix would have been to just rename to .pyd, but we
started investigating the possibility of acquiring the suffix tuple(s)
via imp.get_suffixes() instead. Which led to the discovery that
imp.load_module() simply ignores the first item of said tuple.
Thus, there is no use in pretending it to be of any importance
in this case so we set it to an empty string.
imp_load_module() source for:
Python 2.6.9 : https://hg.python.org/cpython/file/fcb3ec2842f9/Python/import.c#l3021
Python 2.7.10: https://hg.python.org/cpython/file/15c95b7d81dc/Python/import.c#l3148
and just to be future-proof:
Python 3.4.3 : https://hg.python.org/cpython/file/b4cbecbc0781/Lib/imp.py#l220
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/libtoolimporter.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/giscanner/libtoolimporter.py b/giscanner/libtoolimporter.py index 0d26b0c5..c8501035 100644 --- a/giscanner/libtoolimporter.py +++ b/giscanner/libtoolimporter.py @@ -20,7 +20,6 @@ import imp import os -import platform import sys from .utils import extract_libtool @@ -54,16 +53,14 @@ class LibtoolImporter(object): def load_module(self, name): realpath = extract_libtool(self.path) - platform_system = platform.system() - if platform_system == 'Darwin': - extension = '.dylib' - elif platform_system == 'Windows': - extension = '.dll' - else: - extension = '.so' + # The first item of the suffix tuple (which can be, depending on platform, + # one or more valid filename extensions used to name c extension modules) + # is ignored by imp.load_module(). Thus, there is no use in pretending it + # is important and we set it to an empty string. + suffix = ('', 'rb', imp.C_EXTENSION) - mod = imp.load_module(name, open(realpath), realpath, (extension, 'rb', 3)) + mod = imp.load_module(name, open(realpath), realpath, suffix) mod.__loader__ = self return mod |