Skip to content

Commit a7d0a2a

Browse files
committed
Merge branch 'hotfix/v1.7.2'
2 parents 43b798d + 91cd40b commit a7d0a2a

15 files changed

+253
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.pyc
2+
*.pyo
23
*~
34
docs/_build
45
unittests/temp

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
# built documents.
5454
#
5555
# The short X.Y version.
56-
version = 'v1.7.1'
56+
version = 'v1.7.2'
5757
# The full version, including alpha/beta/rc tags.
58-
release = 'v1.7.1'
58+
release = 'v1.7.2'
5959

6060
# The language for content autogenerated by Sphinx. Refer to documentation
6161
# for a list of supported languages.

docs/history.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ to python 3 (keeping it compatible with python 2).
1111
In Mai 2014, Michka Popoff and the Insight Software Consortium revived pygccxml
1212
by setting up a git repositery on github, hosted along with gccxml.
1313

14+
Version 1.7.2
15+
-------------
16+
17+
1. Fix exception in is_copy_constructor when the constructor's argument was
18+
a typedef. is_copy_constructor will now return False instead of failing.
19+
See issue #27.
20+
21+
2. Fix bug with utils.xml_generator being unset when reading cached file.
22+
This could for example happen when reading a cached file from a second
23+
python interpreter (e.g. in a subprocess or by calling pygccxml
24+
multiple times from a script). See issue #27.
25+
26+
3. SafeConfigParser is throwing a deprecation warning in python 3.2 and newer.
27+
Use ConfigParser instead. Thanks to Mark Moll for the patch.
28+
29+
4. Add support for cflags property in config files.
30+
Thanks to Mark Moll for the patch.
31+
1432
Version 1.7.1
1533
-------------
1634

pygccxml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
# TODO:
4141
# 1. Add "explicit" property for constructors
4242

43-
__version__ = 'v1.7.1'
43+
__version__ = 'v1.7.2'

pygccxml/declarations/calldef.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,22 +736,54 @@ def __str__(self):
736736

737737
@property
738738
def is_copy_constructor(self):
739-
"""returns True if described declaration is copy constructor,
740-
otherwise False"""
739+
"""
740+
Returns True if described declaration is copy constructor,
741+
otherwise False.
742+
743+
"""
744+
741745
from . import type_traits
746+
742747
args = self.arguments
743-
if 1 != len(args):
748+
749+
# A copy constructor has only one argument
750+
if len(args) != 1:
744751
return False
752+
753+
# We have only one argument, get it
745754
arg = args[0]
755+
756+
if not isinstance(arg.type, cpptypes.compound_t):
757+
# An argument of type declarated_t (a typedef) could be passed to
758+
# the constructor; and it could be a reference.
759+
# But in c++ you can NOT write :
760+
# "typedef class MyClass { MyClass(const MyClass & arg) {} }"
761+
# If the argument is a typedef, this is not a copy constructor.
762+
# See the hierarchy of declarated_t and coumpound_t. They both
763+
# inherit from type_t but are not related so we can discriminate
764+
# between them.
765+
return False
766+
767+
# The argument needs to be passed by reference in a copy constructor
746768
if not type_traits.is_reference(arg.type):
747769
return False
770+
771+
# The argument needs to be const for a copy constructor
748772
if not type_traits.is_const(arg.type.base):
749773
return False
750-
unaliased = type_traits.remove_alias(arg.type.base)
751-
# unaliased now refers to const_t instance
752-
if not isinstance(unaliased.base, cpptypes.declarated_t):
774+
775+
un_aliased = type_traits.remove_alias(arg.type.base)
776+
# un_aliased now refers to const_t instance
777+
if not isinstance(un_aliased.base, cpptypes.declarated_t):
778+
# We are looking for a declaration
779+
# If "class MyClass { MyClass(const int & arg) {} }" is used,
780+
# this is not copy constructor, so we return False here.
781+
# -> un_aliased.base == cpptypes.int_t (!= cpptypes.declarated_t)
753782
return False
754-
return id(unaliased.base.declaration) == id(self.parent)
783+
784+
# Final check: compare the parent (the class declaration for example)
785+
# with the declaration of the type passed as argument.
786+
return id(un_aliased.base.declaration) == id(self.parent)
755787

756788
@property
757789
def is_trivial_constructor(self):

pygccxml/parser/config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ def load_xml_generator_configuration(configuration, **defaults):
343343
"""
344344
loads CastXML or GCC-XML configuration from an `.ini` file or any other
345345
file class
346-
:class:`ConfigParser.SafeConfigParser` is able to parse.
346+
:class:`configparser.ConfigParser` is able to parse.
347347
348348
:param configuration: configuration could be
349349
string(configuration file path) or instance
350-
of :class:`ConfigParser.SafeConfigParser` class
350+
of :class:`configparser.ConfigParser` class
351351
352352
:rtype: :class:`.xml_generator_configuration_t`
353353
@@ -381,10 +381,10 @@ def load_xml_generator_configuration(configuration, **defaults):
381381
parser = configuration
382382
if utils.is_str(configuration):
383383
try:
384-
from configparser import SafeConfigParser
384+
from configparser import ConfigParser
385385
except ImportError:
386-
from ConfigParser import SafeConfigParser
387-
parser = SafeConfigParser()
386+
from ConfigParser import SafeConfigParser as ConfigParser
387+
parser = ConfigParser()
388388
parser.read(configuration)
389389

390390
# Create a new empty configuration
@@ -419,6 +419,8 @@ def load_xml_generator_configuration(configuration, **defaults):
419419
cfg.xml_generator = value
420420
elif name == 'keep_xml':
421421
cfg.keep_xml = value
422+
elif name == 'cflags':
423+
cfg.cflags = value
422424
elif name == 'flags':
423425
cfg.flags = value
424426
elif name == 'compiler_path':

pygccxml/parser/declarations_cache.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ class record_t(object):
102102

103103
def __init__(
104104
self,
105+
xml_generator,
105106
source_signature,
106107
config_signature,
107108
included_files,
108109
included_files_signature,
109110
declarations):
111+
self.__xml_generator = xml_generator
110112
self.__source_signature = source_signature
111113
self.__config_signature = config_signature
112114
self.__included_files = included_files
@@ -151,6 +153,10 @@ def included_files_signature(self):
151153
def declarations(self):
152154
return self.__declarations
153155

156+
@property
157+
def xml_generator(self):
158+
return self.__xml_generator
159+
154160

155161
class file_cache_t(cache_base_t):
156162

@@ -174,6 +180,23 @@ def __init__(self, name):
174180
self.__cache) # If empty then we need to flush
175181
for entry in self.__cache.values(): # Clear hit flags
176182
entry.was_hit = False
183+
try:
184+
# Make sure the xml_generator variable is defined, else it
185+
# will stay None.
186+
xml_generator = entry.xml_generator
187+
except AttributeError:
188+
msg = (
189+
"The %s cache file is not compatible with this version " +
190+
"of pygccxml. Please regenerate it.") % name
191+
raise RuntimeError(msg)
192+
if utils.xml_generator is None:
193+
# Set the xml_generator to the one read in the cache file
194+
utils.xml_generator = xml_generator
195+
elif utils.xml_generator != xml_generator:
196+
msg = (
197+
"The %s cache file was generated with a different xml " +
198+
"generator. Please regenerate it.") % name
199+
raise RuntimeError(msg)
177200

178201
@staticmethod
179202
def __load(file_name):
@@ -231,6 +254,7 @@ def update(self, source_file, configuration, declarations, included_files):
231254
""" Update a cached record with the current key and value contents. """
232255

233256
record = record_t(
257+
xml_generator=utils.xml_generator,
234258
source_signature=file_signature(source_file),
235259
config_signature=configuration_signature(configuration),
236260
included_files=included_files,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from setuptools import setup
88

99
setup(name="pygccxml",
10-
version="v1.7.1",
10+
version="v1.7.2",
1111
author="Roman Yakovenko",
1212
author_email="roman yakovenko at gmail com",
1313
maintainer="Michka Popoff and the Insight Software Consortium",

unittests/data/new_cache.cache

2.32 KB
Binary file not shown.

unittests/data/old_cache.cache

2.29 KB
Binary file not shown.

0 commit comments

Comments
 (0)