[gobject-introspection/wip/dieterv/drive-by-review: 6/13] canner: clarify LibtoolImporter's load_module method
- From: Dieter Verfaillie <dieterv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/dieterv/drive-by-review: 6/13] canner: clarify LibtoolImporter's load_module method
- Date: Thu, 25 Jun 2015 20:25:20 +0000 (UTC)
commit d7031e67e4c69314ec6109b1a9194400d7bb6994
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date: Thu Jun 25 17:12:10 2015 +0200
canner: clarify LibtoolImporter's load_module method
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
Python 3.4.3 : https://hg.python.org/cpython/file/b4cbecbc0781/Lib/imp.py#l220
giscanner/libtoolimporter.py | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)
---
diff --git a/giscanner/libtoolimporter.py b/giscanner/libtoolimporter.py
index 0d26b0c..c850103 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]