CastXML / pygccxml

pygccxml is a specialized XML reader that reads the output from CastXML or GCCXML. It provides a simple framework to navigate C++ declarations, using Python classes.
Boost Software License 1.0
131 stars 45 forks source link

smart_pointer_traits.py bug #85

Closed RomanYakovenko closed 7 years ago

RomanYakovenko commented 7 years ago

Hello. Method "get_by_name" contains a small typo, which is very problematic: "class_declaration_traits" are used twice. I believe the first time, there was intention to use "class_traits" patch.txt

Regards, Roman

RomanYakovenko commented 7 years ago

It looks like I fired the issue too early, as the file contains few more. So the summary: 1) It contains the type 2) wrong function call, instead of class_traits.declaration_class it should call class_traits.get_declaration 3) Modern smart pointers refer to the "pointer type" as element_type, instead of "value_type". So I changed it too.

The patch is attached patch.txt

Regards, Roman

iMichka commented 7 years ago

I confirm that there is definitively a typo there. Happened probably during one of the last refactorings.

The bug is in a part of the code that has no code coverage. Funnily all the bigger bugs I introduced during the last years happened in places that were untested. Code coverage is pretty good, around 92%, but would need to be pushed a little bit more. I'll add a test for that function while fixing this, and make a fix for the 1.9.1 release.

RomanYakovenko commented 7 years ago

Sorry, but this bug was not fixed. It looks like you applied my first patch and not the second one. ! Modern smart pointers refer to the "pointer type" as element_type, instead of "value_type". So I changed it too.

Thank you.

iMichka commented 7 years ago

I didn't fix the bug, had no time to write the code for it on the 1.9.1 branch. I hope I can do this in the next days.

iMichka commented 7 years ago

Okay I pushed the changes to the 1.9.1 branch (https://github.com/gccxml/pygccxml/tree/hotfix/v1.9.1). I added also some tests for all the methods.

Interestingly they work locally for me on mac, and on the mac builds. But the Linux and windows builds all failed: https://travis-ci.org/gccxml/pygccxml/builds/264160493

I think this has to do with the value_type / element_type change. I will need to investigate the produced xml files.

======================================================================
ERROR: test_smart_pointer_value_type (unittests.test_smart_pointer.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/gccxml/pygccxml/unittests/test_smart_pointer.py", line 90, in test_smart_pointer_value_type
    vt = declarations.smart_pointer_traits.value_type(decls[0].decl_type)
  File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/smart_pointer_traits.py", line 75, in value_type
    return internal_type_traits.get_by_name(type_, "element_type")
  File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/smart_pointer_traits.py", line 23, in get_by_name
    cls.typedef(name, recursive=False).decl_type)
  File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/scopedef.py", line 1184, in typedef
    recursive=recursive)
  File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/scopedef.py", line 484, in _find_single
    found = matcher.get_single(decl_matcher, decls, False)
  File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/scopedef.py", line 87, in get_single
    raise runtime_errors.declaration_not_found_t(decl_matcher)
pygccxml.declarations.runtime_errors.declaration_not_found_t: Unable to find declaration. Matcher: [(decl type==typedef_t) and (name==element_type)]
RomanYakovenko commented 7 years ago

It may depend on the stl/boost library you are testing again. Modern libraries use "element_type", while the old one "value_type". In my opinion, pygccmxml should look for element_type, if it is not found, then look for "value_type".

Regards, Roman

On Mon, Aug 14, 2017 at 12:26 AM, Michka Popoff notifications@github.com wrote:

Okay I pushed the changes to the 1.9.1 branch (https://github.com/gccxml/ pygccxml/tree/hotfix/v1.9.1). I added also some tests for all the methods.

Interestingly they work locally for me on mac, and on the mac builds. But the Linux and windows builds all failed: https://travis-ci.org/gccxml/pygccxml/builds/264160493

I think this has to do with the value_type / element_type change. I will need to investigate the produced xml files.

====================================================================== ERROR: test_smart_pointer_value_type (unittests.test_smart_pointer.Test)

Traceback (most recent call last): File "/home/travis/build/gccxml/pygccxml/unittests/test_smart_pointer.py", line 90, in test_smart_pointer_value_type vt = declarations.smart_pointer_traits.value_type(decls[0].decl_type) File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/smart_pointer_traits.py", line 75, in value_type return internal_type_traits.get_byname(type, "element_type") File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/smart_pointer_traits.py", line 23, in get_by_name cls.typedef(name, recursive=False).decl_type) File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/scopedef.py", line 1184, in typedef recursive=recursive) File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/scopedef.py", line 484, in _find_single found = matcher.get_single(decl_matcher, decls, False) File "/home/travis/build/gccxml/pygccxml/pygccxml/declarations/scopedef.py", line 87, in get_single raise runtime_errors.declaration_not_found_t(decl_matcher) pygccxml.declarations.runtime_errors.declaration_not_found_t: Unable to find declaration. Matcher: [(decl type==typedef_t) and (name==element_type)]

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gccxml/pygccxml/issues/85#issuecomment-322068559, or mute the thread https://github.com/notifications/unsubscribe-auth/AQH2W5t8MHj619thm0Zxe6gAz8QUBttIks5sX2oJgaJpZM4Ob1CL .

iMichka commented 7 years ago

In fact I had to loop over the base class to find the "element_type" typedef. I made a patch for that: https://github.com/gccxml/pygccxml/commit/76bf57c844bafab22ed011724cb17e19f357bfbf

There is some xml in the commit message which explains why this is like this.

If this is fine for you, I'll make a new release tomorrow with these changes.

RomanYakovenko commented 7 years ago

May I ask you to fix "incomplete declarations tree" bug? It is pretty serious and actually very easy to fix. Without it, I am not able to introduce a new code generator to py++.

Also I was not able to test against hotfix branch; There are too many differences between it and the default one.

Regards, Roman

On Tue, Aug 15, 2017 at 12:41 AM, Michka Popoff notifications@github.com wrote:

In fact I had to loop over the base class to find the "element_type" typedef. I made a patch for that: 76bf57c https://github.com/gccxml/pygccxml/commit/76bf57c844bafab22ed011724cb17e19f357bfbf

There is some xml in the commit message which explains why this is like this.

If this is fine for you, I'll make a new release tomorrow with these changes.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gccxml/pygccxml/issues/85#issuecomment-322317616, or mute the thread https://github.com/notifications/unsubscribe-auth/AQH2W_iXtMEsebaa2qt8-jOBbokM9CsRks5sYL7wgaJpZM4Ob1CL .

iMichka commented 7 years ago

I answered in the other issue for the "incomplete declarations tree" bug.

I just merged the 1.9.1 branch to master. I will push the 1.9.1 tag once the unit tests are done running on Travis. Of course if you want to work with the bleeding edge version, you can use the develop branch, which also contains the fixes.