Skip to content

Commit becda00

Browse files
committed
Merge branch 'hotfix/v1.8.1'
2 parents b75c151 + 350cf09 commit becda00

File tree

15 files changed

+133
-28
lines changed

15 files changed

+133
-28
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
docs/_build
55
unittests/temp
66
unittests/data/pygccxml.cache
7+
unittests/data/directory_cache_test
78
.idea
89
dist
910
build
@@ -12,3 +13,4 @@ pygccxml.egg-info
1213
.coverage*
1314
docs/examples/caching/example.hpp.xml
1415
test_cost.log
16+
docs/apidocs

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ matrix:
9090
# gcc 5.3.0
9191
- g++-5
9292
- os: osx
93-
osx_image: xcode7.2
93+
osx_image: xcode7.3
9494
language: generic
9595
env:
9696
- XML_GENERATOR="castxml"
9797
- TRAVIS_PYTHON_VERSION="2"
9898
- os: osx
99-
osx_image: xcode7.2
99+
osx_image: xcode7.3
100100
language: generic
101101
env:
102102
- XML_GENERATOR="castxml"
@@ -106,7 +106,6 @@ matrix:
106106
before_install:
107107
# OS X
108108
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then travis_retry brew update; fi
109-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ $TRAVIS_PYTHON_VERSION == 2 ]]; then brew install python; fi
110109
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ $TRAVIS_PYTHON_VERSION == 3 ]]; then brew install python3; fi
111110
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ $TRAVIS_PYTHON_VERSION == 3 ]]; then sudo ln -sf /usr/local/bin/pip3 /usr/local/bin/pip; fi
112111
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ $TRAVIS_PYTHON_VERSION == 3 ]]; then sudo ln -sf /usr/local/bin/python3 /usr/local/bin/python; fi

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Changes
22
=======
33

4+
Version 1.8.1
5+
-------------
6+
7+
1. Added ```is_struct``` function to declarations package. It returns true if
8+
a declaration is a struct.
9+
10+
2. Removed * from decl_string when type is a function pointer (#61)
11+
12+
3. Update travis.yml for newer OS X images. Update CastXML binaries for Travis.
13+
14+
4. Fix regression in directory_cache, which was crashing due an unset variable.
15+
Add support for python3 in directory_cache.
16+
417
Version 1.8.0
518
-------------
619

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
# built documents.
5656
#
5757
# The short X.Y version.
58-
version = '1.8.0'
58+
version = '1.8.1'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '1.8.0'
60+
release = '1.8.1'
6161

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

docs/examples/function-pointer/example.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@
2929
decls = parser.parse([filename], xml_generator_config)
3030
global_namespace = declarations.get_global_namespace(decls)
3131

32-
function = global_namespace.variables()[0]
32+
function_ptr = global_namespace.variables()[0]
3333

3434
# Print the name of the function pointer
35-
print(function.name)
35+
print(function_ptr.name)
3636
# > myFuncPointer
3737

38-
# Print the type of the declaration (it's just a pointer)
39-
print(type(function.decl_type))
38+
# Print the type of the declaration
39+
print(function_ptr.decl_type)
40+
# > void (*)( int,double )
41+
42+
# Print the real type of the declaration (it's just a pointer)
43+
print(type(function_ptr.decl_type))
4044
# > <class 'pygccxml.declarations.cpptypes.pointer_t'>
4145

4246
# Check if this is a function pointer
43-
print(declarations.is_calldef_pointer(function.decl_type))
47+
print(declarations.is_calldef_pointer(function_ptr.decl_type))
4448
# > True
4549

4650
# Remove the pointer part, to access the function's type
47-
f_type = declarations.remove_pointer(function.decl_type)
51+
f_type = declarations.remove_pointer(function_ptr.decl_type)
4852

4953
# Print the type
5054
print(type(f_type))

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__ = '1.8.0'
43+
__version__ = '1.8.1'

pygccxml/declarations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
from .type_traits_classes import is_noncopyable
168168
from .type_traits_classes import is_copy_constructor
169169
from .type_traits_classes import is_trivial_constructor
170+
from .type_traits_classes import is_struct
170171
from .type_traits_classes import is_union
171172

172173
from .type_traits_classes import is_unary_operator

pygccxml/declarations/cpptypes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,12 @@ def __init__(self, base):
574574
compound_t.__init__(self, base)
575575

576576
def build_decl_string(self, with_defaults=True):
577-
return self.base.build_decl_string(with_defaults) + ' *'
577+
decl_string = self.base.build_decl_string(with_defaults)
578+
if isinstance(self.base, calldef_type_t):
579+
# This is a function pointer. Do not add supplementary *
580+
return decl_string
581+
else:
582+
return decl_string + " *"
578583

579584
def _clone_impl(self):
580585
return pointer_t(self.base.clone())

pygccxml/declarations/type_traits_classes.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,38 @@
1515
from .. import utils
1616

1717

18-
def is_union(type_):
19-
"""returns True if type represents a C++ union"""
20-
if not is_class(type_):
18+
def is_union(declaration):
19+
"""
20+
Returns True if declaration represents a C++ union
21+
22+
Args:
23+
declaration (declaration_t): the declaration to be checked.
24+
25+
Returns:
26+
bool: True if declaration represents a C++ union
27+
"""
28+
if not is_class(declaration):
2129
return False
22-
decl = class_traits.get_declaration(type_)
30+
decl = class_traits.get_declaration(declaration)
2331
return decl.class_type == class_declaration.CLASS_TYPES.UNION
2432

2533

34+
def is_struct(declaration):
35+
"""
36+
Returns True if declaration represents a C++ struct
37+
38+
Args:
39+
declaration (declaration_t): the declaration to be checked.
40+
41+
Returns:
42+
bool: True if declaration represents a C++ struct
43+
"""
44+
if not is_class(declaration):
45+
return False
46+
decl = class_traits.get_declaration(declaration)
47+
return decl.class_type == class_declaration.CLASS_TYPES.STRUCT
48+
49+
2650
class declaration_xxx_traits(object):
2751
"""this class implements the functionality needed for convenient work with
2852
declaration classes

pygccxml/parser/directory_cache.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import cPickle as pickle
2525
except ImportError:
2626
import pickle
27+
2728
from . import declarations_cache
29+
from .. import utils
2830

2931

3032
class index_entry_t(object):
@@ -238,6 +240,10 @@ def _load(self):
238240
self.__index = {}
239241
self.__filename_rep = filename_repository_t(self.__sha1_sigs)
240242

243+
# Read the xml generator from the cache and set it
244+
with open(os.path.join(self.__dir, "gen.dat"), "r") as gen_file:
245+
utils.xml_generator = gen_file.read()
246+
241247
self.__modified_flag = False
242248

243249
def _save(self):
@@ -255,6 +261,11 @@ def _save(self):
255261
indexfilename,
256262
(self.__index,
257263
self.__filename_rep))
264+
265+
# Read the xml generator from the cache and set it
266+
with open(os.path.join(self.__dir, "gen.dat"), "w") as gen_file:
267+
gen_file.write(utils.xml_generator)
268+
258269
self.__modified_flag = False
259270

260271
def _read_file(self, filename):
@@ -366,15 +377,15 @@ def _create_config_signature(config):
366377
:rtype: str
367378
"""
368379
m = hashlib.sha1()
369-
m.update(config.working_directory)
380+
m.update(config.working_directory.encode("utf-8"))
370381
for p in config.include_paths:
371-
m.update(p)
382+
m.update(p.encode("utf-8"))
372383
for p in config.define_symbols:
373-
m.update(p)
384+
m.update(p.encode("utf-8"))
374385
for p in config.undefine_symbols:
375-
m.update(p)
386+
m.update(p.encode("utf-8"))
376387
for p in config.cflags:
377-
m.update(p)
388+
m.update(p.encode("utf-8"))
378389
return m.digest()
379390

380391

@@ -531,13 +542,13 @@ def _get_signature(self, entry):
531542
if not os.path.exists(entry.filename):
532543
return None
533544
try:
534-
f = open(entry.filename)
545+
f = open(entry.filename, "r")
535546
except IOError as e:
536547
print("Cannot determine sha1 digest:", e)
537548
return None
538549
data = f.read()
539550
f.close()
540-
return hashlib.sha1(data).digest()
551+
return hashlib.sha1(data.encode("utf-8")).digest()
541552
else:
542553
# return file modification date...
543554
try:

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from setuptools import setup
88

99
setup(name="pygccxml",
10-
version="1.8.0",
10+
version="1.8.1",
1111
author="Roman Yakovenko",
1212
author_email="roman yakovenko at gmail com",
1313
maintainer="Michka Popoff and the Insight Software Consortium",
1414
maintainer_email="castxml@public.kitware.com",
1515
description="Python package for easy C++ declarations navigation.",
1616
url="https://github.com/gccxml/pygccxml",
17-
download_url="https://github.com/gccxml/pygccxml/archive/v1.8.0.tar.gz",
17+
download_url="https://github.com/gccxml/pygccxml/archive/v1.8.1.tar.gz",
1818
license="Boost",
1919
keywords="C++, declaration parser, CastXML, gccxml",
2020
packages=["pygccxml",

unittests/test_all.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import test_smart_pointer
7575
import test_pattern_parser
7676
import test_function_pointer
77+
import test_directory_cache
7778

7879
testers = [
7980
# , demangled_tester # failing right now
@@ -140,7 +141,8 @@
140141
test_argument_without_name,
141142
test_smart_pointer,
142143
test_pattern_parser,
143-
test_function_pointer
144+
test_function_pointer,
145+
test_directory_cache
144146
]
145147

146148
if 'posix' in os.name:

unittests/test_directory_cache.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2014-2016 Insight Software Consortium.
2+
# Copyright 2004-2009 Roman Yakovenko.
3+
# Distributed under the Boost Software License, Version 1.0.
4+
# See http://www.boost.org/LICENSE_1_0.txt
5+
6+
import unittest
7+
import parser_test_case
8+
9+
from pygccxml import parser
10+
11+
12+
class Test(parser_test_case.parser_test_case_t):
13+
14+
def __init__(self, *args):
15+
parser_test_case.parser_test_case_t.__init__(self, *args)
16+
self.header = "core_cache.hpp"
17+
18+
def test_directory_cache(self):
19+
"""
20+
Test the directory cache
21+
22+
"""
23+
24+
cache = parser.directory_cache_t(
25+
dir="unittests/data/directory_cache_test")
26+
# Generate a cache on first read
27+
parser.parse([self.header], self.config, cache=cache)
28+
# Read from the cache the second time
29+
parser.parse([self.header], self.config, cache=cache)
30+
31+
32+
def create_suite():
33+
suite = unittest.TestSuite()
34+
suite.addTest(unittest.makeSuite(Test))
35+
return suite
36+
37+
38+
def run_suite():
39+
unittest.TextTestRunner(verbosity=2).run(create_suite())
40+
41+
if __name__ == "__main__":
42+
run_suite()

unittests/test_function_pointer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_function_pointer(self):
3333
self.assertTrue(
3434
isinstance(variables[0].decl_type, declarations.pointer_t))
3535
self.assertTrue(
36-
str(variables[0].decl_type) == "void (*)( int,double ) *")
36+
str(variables[0].decl_type) == "void (*)( int,double )")
3737
self.assertTrue(
3838
declarations.is_calldef_pointer(variables[0].decl_type))
3939
self.assertTrue(

unittests/unnamed_classes_tester.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ def validate_bitfields(self, parent, bitfields):
3232
def do_union_test(self, union_name, bitfields):
3333
s2 = self.global_ns.class_('S2')
3434
self.assertFalse(declarations.is_union(s2))
35+
self.assertTrue(declarations.is_struct(s2))
3536
self.assertEqual(s2.parent.name, 'S1')
3637
self.assertFalse(declarations.is_union(s2.parent))
3738

3839
union = s2.variable(union_name)
3940
self.assertTrue(declarations.is_union(union.decl_type))
41+
self.assertFalse(declarations.is_struct(union.decl_type))
4042

4143
union_type = type_traits.remove_declarated(union.decl_type)
4244
self.validate_bitfields(union_type, bitfields)

0 commit comments

Comments
 (0)