summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--giscanner/cachestore.py24
-rw-r--r--giscanner/ccompiler.py2
-rw-r--r--giscanner/codegen.py4
-rw-r--r--giscanner/docmain.py2
-rw-r--r--giscanner/dumper.py4
-rw-r--r--giscanner/gdumpparser.py2
-rw-r--r--giscanner/giscannermodule.c11
-rw-r--r--giscanner/libtoolimporter.py73
-rw-r--r--giscanner/meson.build1
-rw-r--r--giscanner/scannermain.py16
-rw-r--r--giscanner/sourcescanner.py17
-rw-r--r--giscanner/utils.py20
-rw-r--r--misc/update-gtkdoc-tests.py2
-rw-r--r--misc/update-vulkan-gir.py2
-rw-r--r--tests/scanner/test_maintransformer.py2
-rw-r--r--tests/scanner/test_transformer.py2
-rw-r--r--tests/warn/warningtester.py2
17 files changed, 50 insertions, 136 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py
index baaaf1ed..3512badc 100644
--- a/giscanner/cachestore.py
+++ b/giscanner/cachestore.py
@@ -65,7 +65,7 @@ class CacheStore(object):
current_hash = _get_versionhash()
version = os.path.join(self._directory, _CACHE_VERSION_FILENAME)
try:
- with open(version, 'r') as version_file:
+ with open(version, 'r', encoding='utf-8') as version_file:
cache_hash = version_file.read()
except (IOError, OSError) as e:
# File does not exist
@@ -81,7 +81,7 @@ class CacheStore(object):
tmp_fd, tmp_filename = tempfile.mkstemp(prefix='g-ir-scanner-cache-version-')
try:
- with os.fdopen(tmp_fd, 'w') as tmp_file:
+ with os.fdopen(tmp_fd, 'w', encoding='utf-8') as tmp_file:
tmp_file.write(current_hash)
# On Unix, this would just be os.rename() but Windows
@@ -169,12 +169,14 @@ class CacheStore(object):
return None
else:
raise
- if not self._cache_is_valid(store_filename, filename):
- return None
- try:
- data = pickle.load(fd)
- except Exception:
- # Broken cache entry, remove it
- self._remove_filename(store_filename)
- data = None
- return data
+
+ with fd:
+ if not self._cache_is_valid(store_filename, filename):
+ return None
+ try:
+ data = pickle.load(fd)
+ except Exception:
+ # Broken cache entry, remove it
+ self._remove_filename(store_filename)
+ data = None
+ return data
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index bd1aa78e..cb97e76f 100644
--- a/giscanner/ccompiler.py
+++ b/giscanner/ccompiler.py
@@ -387,7 +387,7 @@ class CCompiler(object):
output_flag = ['-out:' + tmp_filename]
proc = subprocess.call(args + [implib] + output_flag,
stdout=subprocess.PIPE)
- with open(tmp_filename, 'r') as tmp_fileobj:
+ with open(tmp_filename, 'r', encoding='utf-8') as tmp_fileobj:
for line in tmp_fileobj.read().splitlines():
if '__IMPORT_DESCRIPTOR_' in line:
diff --git a/giscanner/codegen.py b/giscanner/codegen.py
index 138acf72..9faf3cab 100644
--- a/giscanner/codegen.py
+++ b/giscanner/codegen.py
@@ -161,8 +161,8 @@ class CCodeGenerator(object):
self._function_bodies[node] = body
def codegen(self):
- self.out_h = open(self.out_h_filename, 'w')
- self.out_c = open(self.out_c_filename, 'w')
+ self.out_h = open(self.out_h_filename, 'w', encoding='utf-8')
+ self.out_c = open(self.out_c_filename, 'w', encoding='utf-8')
self._codegen_start()
diff --git a/giscanner/docmain.py b/giscanner/docmain.py
index 6ef1de4e..dab063ef 100644
--- a/giscanner/docmain.py
+++ b/giscanner/docmain.py
@@ -71,7 +71,7 @@ def doc_main(args):
if args.format == 'sections':
sections_file = generate_sections_file(transformer)
- with open(args.output, 'w') as fp:
+ with open(args.output, 'w', encoding='utf-8') as fp:
write_sections_file(fp, sections_file)
else:
writer = DocWriter(transformer, args.language, args.format)
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index e4b6ea03..f61c46c1 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -111,13 +111,13 @@ class DumpCompiler(object):
'gobject-introspection-1.0', 'gdump.c')
if not os.path.isfile(gdump_path):
raise SystemExit("Couldn't find %r" % (gdump_path, ))
- with open(gdump_path) as gdump_file:
+ with open(gdump_path, encoding='utf-8') as gdump_file:
gdump_contents = gdump_file.read()
tpl_args['gdump_include'] = gdump_contents
tpl_args['init_sections'] = "\n".join(self._options.init_sections)
c_path = self._generate_tempfile(tmpdir, '.c')
- with open(c_path, 'w') as f:
+ with open(c_path, 'w', encoding='utf-8') as f:
f.write(_PROGRAM_TEMPLATE % tpl_args)
# We need to reference our get_type and error_quark functions
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index e7ccf575..3d9720d0 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -144,7 +144,7 @@ class GDumpParser(object):
"""Load the library (or executable), returning an XML
blob containing data gleaned from GObject's primitive introspection."""
in_path = os.path.join(self._binary.tmpdir, 'functions.txt')
- with open(in_path, 'w') as f:
+ with open(in_path, 'w', encoding='utf-8') as f:
for func in self._get_type_functions:
f.write('get-type:')
f.write(func)
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 43f8bdea..2e7e55bc 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -22,15 +22,12 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "sourcescanner.h"
#include <glib-object.h>
-#ifndef Py_TYPE
- #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
-#endif
-
#if PY_MAJOR_VERSION >= 3
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
#define MOD_ERROR_RETURN NULL
@@ -52,8 +49,12 @@ PyTypeObject Py##cname##_Type = { \
0 \
}
+#if PY_VERSION_HEX < 0x030900A4
+# define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
+#endif
+
#define REGISTER_TYPE(d, name, type) \
- Py_TYPE(&type) = &PyType_Type; \
+ Py_SET_TYPE(&type, &PyType_Type); \
type.tp_alloc = PyType_GenericAlloc; \
type.tp_new = PyType_GenericNew; \
type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; \
diff --git a/giscanner/libtoolimporter.py b/giscanner/libtoolimporter.py
deleted file mode 100644
index c8501035..00000000
--- a/giscanner/libtoolimporter.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# -*- Mode: Python -*-
-# GObject-Introspection - a framework for introspecting GObject libraries
-# Copyright (C) 2008 Johan Dahlin
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-#
-
-import imp
-import os
-import sys
-
-from .utils import extract_libtool
-
-
-class LibtoolImporter(object):
-
- def __init__(self, name, path):
- self.name = name
- self.path = path
-
- @classmethod
- def find_module(cls, name, packagepath=None):
- modparts = name.split('.')
- filename = modparts.pop() + '.la'
-
- # Given some.package.module 'path' is where subpackages of some.package
- # should be looked for. See if we can find a ".libs/module.la" relative
- # to those directories and failing that look for file
- # "some/package/.libs/module.la" relative to sys.path
- if len(modparts) > 0:
- modprefix = os.path.join(*modparts)
- modprefix = os.path.join(modprefix, '.libs')
- else:
- modprefix = '.libs'
-
- for path in sys.path:
- full = os.path.join(path, modprefix, filename)
- if os.path.exists(full):
- return cls(name, full)
-
- def load_module(self, name):
- realpath = extract_libtool(self.path)
-
- # 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, suffix)
- mod.__loader__ = self
- return mod
-
- @classmethod
- def __enter__(cls):
- sys.meta_path.append(cls)
-
- @classmethod
- def __exit__(cls, exc_type, exc_val, exc_tb):
- sys.meta_path.remove(cls)
diff --git a/giscanner/meson.build b/giscanner/meson.build
index a3b06f37..098b7b6b 100644
--- a/giscanner/meson.build
+++ b/giscanner/meson.build
@@ -13,7 +13,6 @@ giscanner_files = [
'girparser.py',
'girwriter.py',
'gdumpparser.py',
- 'libtoolimporter.py',
'maintransformer.py',
'mdextensions.py',
'message.py',
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index ca9065b2..957ba0b7 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -334,7 +334,7 @@ def extract_filelist(options):
filenames = []
if not os.path.exists(options.filelist):
_error('%s: no such filelist file' % (options.filelist, ))
- with open(options.filelist, "r") as filelist_file:
+ with open(options.filelist, "r", encoding=None) as filelist_file:
lines = filelist_file.readlines()
for line in lines:
# We don't support real C++ parsing yet, but we should be able
@@ -472,6 +472,10 @@ def write_output(data, options):
"""Write encoded XML 'data' to the filename specified in 'options'."""
if options.output == "-":
output = sys.stdout
+ try:
+ output.write(data)
+ except IOError as e:
+ _error("while writing output: %s" % (e.strerror, ))
elif options.reparse_validate_gir:
main_f, main_f_name = tempfile.mkstemp(suffix='.gir')
@@ -500,14 +504,10 @@ def write_output(data, options):
return 0
else:
try:
- output = open(options.output, 'wb')
+ with open(options.output, 'wb') as output:
+ output.write(data)
except IOError as e:
- _error("opening output for writing: %s" % (e.strerror, ))
-
- try:
- output.write(data)
- except IOError as e:
- _error("while writing output: %s" % (e.strerror, ))
+ _error("opening/writing output: %s" % (e.strerror, ))
def get_source_root_dirs(options, filenames):
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index e50f40aa..09f90441 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -21,19 +21,18 @@
import os
import tempfile
-from .libtoolimporter import LibtoolImporter
from .message import Position
from .ccompiler import CCompiler
from .utils import have_debug_flag, dll_dirs
-with LibtoolImporter(None, None):
- dlldirs = dll_dirs()
- dlldirs.add_dll_dirs(['gio-2.0'])
- if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
- from _giscanner import SourceScanner as CSourceScanner
- else:
- from giscanner._giscanner import SourceScanner as CSourceScanner
- dlldirs.cleanup_dll_dirs()
+
+dlldirs = dll_dirs()
+dlldirs.add_dll_dirs(['gio-2.0'])
+if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
+ from _giscanner import SourceScanner as CSourceScanner
+else:
+ from giscanner._giscanner import SourceScanner as CSourceScanner
+dlldirs.cleanup_dll_dirs()
HEADER_EXTS = ['.h', '.hpp', '.hxx']
SOURCE_EXTS = ['.c', '.cpp', '.cc', '.cxx']
diff --git a/giscanner/utils.py b/giscanner/utils.py
index 9007db13..45807f17 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -84,7 +84,7 @@ _libtool_pat = re.compile("dlname='([A-z0-9\\.\\-\\+]+)'\n")
def _extract_dlname_field(la_file):
- with open(la_file) as f:
+ with open(la_file, encoding='utf-8') as f:
data = f.read()
m = _libtool_pat.search(data)
if m:
@@ -97,7 +97,7 @@ _libtool_libdir_pat = re.compile("libdir='([^']+)'")
def _extract_libdir_field(la_file):
- with open(la_file) as f:
+ with open(la_file, encoding='utf-8') as f:
data = f.read()
m = _libtool_libdir_pat.search(data)
if m:
@@ -121,24 +121,10 @@ def extract_libtool_shlib(la_file):
if libdir is None:
return dlbasename
return libdir + '/' + dlbasename
- # From the comments in extract_libtool(), older libtools had
- # a path rather than the raw dlname
+ # Older libtools had a path rather than the raw dlname
return os.path.basename(dlname)
-def extract_libtool(la_file):
- dlname = _extract_dlname_field(la_file)
- if dlname is None:
- raise ValueError("%s has no dlname. Not a shared library?" % la_file)
- libname = os.path.join(os.path.dirname(la_file),
- '.libs', dlname)
- # FIXME: This hackish, but I'm not sure how to do this
- # in a way which is compatible with both libtool 2.2
- # and pre-2.2. Johan 2008-10-21
- libname = libname.replace('.libs/.libs', '.libs').replace('.libs\\.libs', '.libs')
- return libname
-
-
# Returns arguments for invoking libtool, if applicable, otherwise None
def get_libtool_command(options):
libtool_infection = not options.nolibtool
diff --git a/misc/update-gtkdoc-tests.py b/misc/update-gtkdoc-tests.py
index c182fc11..6f45e348 100644
--- a/misc/update-gtkdoc-tests.py
+++ b/misc/update-gtkdoc-tests.py
@@ -191,7 +191,7 @@ if __name__ == '__main__':
writer = GtkDocCommentBlockWriter(indent=True)
logger.enable_warnings(True)
- with io.open(path, 'r') as f:
+ with io.open(path, 'r', encoding='utf-8') as f:
lines = f.readlines()
chunks = []
diff --git a/misc/update-vulkan-gir.py b/misc/update-vulkan-gir.py
index 89792c12..4154702a 100644
--- a/misc/update-vulkan-gir.py
+++ b/misc/update-vulkan-gir.py
@@ -24,7 +24,7 @@ def show_func_defs(filename, output, extra_cpp_args=None):
ast = parse_file(filename, use_cpp=True,
cpp_args=extra_cpp_args)
- with open(output, 'w') as f:
+ with open(output, 'w', encoding='utf-8') as f:
f.write("""<?xml version="1.0"?>
<repository version="1.2"
xmlns="http://www.gtk.org/introspection/core/1.0"
diff --git a/tests/scanner/test_maintransformer.py b/tests/scanner/test_maintransformer.py
index abf3ee73..f0e2d629 100644
--- a/tests/scanner/test_maintransformer.py
+++ b/tests/scanner/test_maintransformer.py
@@ -16,7 +16,7 @@ def create_scanner_from_source_string(source):
tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True)
try:
- with os.fdopen(tmp_fd, 'wt') as file:
+ with os.fdopen(tmp_fd, 'w', encoding='utf-8') as file:
file.write(source)
ss.parse_files([tmp_name])
finally:
diff --git a/tests/scanner/test_transformer.py b/tests/scanner/test_transformer.py
index c6fbf4e7..3feed441 100644
--- a/tests/scanner/test_transformer.py
+++ b/tests/scanner/test_transformer.py
@@ -18,7 +18,7 @@ def create_scanner_from_source_string(source):
tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True)
try:
- with os.fdopen(tmp_fd, 'wt') as file:
+ with os.fdopen(tmp_fd, 'w', encoding='utf-8') as file:
file.write(source)
ss.parse_files([tmp_name])
finally:
diff --git a/tests/warn/warningtester.py b/tests/warn/warningtester.py
index fedd3a59..3bb9e4b2 100644
--- a/tests/warn/warningtester.py
+++ b/tests/warn/warningtester.py
@@ -78,7 +78,7 @@ def _diff(a, b):
def _extract_expected(filename):
- fd = open(filename, 'r')
+ fd = open(filename, 'r', encoding='utf-8')
data = fd.read()
fd.close()