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

Possible Nonetype comparison in calldef.py #106

Closed adeepkit01 closed 4 years ago

adeepkit01 commented 5 years ago

I have been working on shifting the ns-3 project completely to python 3 which uses this project to generate python bindings.

We have been failing in operation due to an exception here:

    def __lt__(self, other):
        if not isinstance(other, self.__class__):
            return self.__class__.__name__ < other.__class__.__name__
        return self.name < other.name \
            and self.default_value < other.default_value \
            and self.decl_type < other.decl_type

Since None is a supported value for default_value but python 3 does not support None comparison, an exception is thrown in the above line.

I have been able to successfully workaround the issue with the following patch

diff --git a/pygccxml/declarations/calldef.py b/pygccxml/declarations/calldef.py
index fd1fe17..7ed66bd 100644
--- a/pygccxml/declarations/calldef.py
+++ b/pygccxml/declarations/calldef.py
@@ -90,6 +90,11 @@ class argument_t(object):
     def __lt__(self, other):
         if not isinstance(other, self.__class__):
             return self.__class__.__name__ < other.__class__.__name__
+        if other.default_value == None:
+            return False
+        if self.default_value == None:
+            return self.name < other.name \
+                and self.decl_type < other.decl_type
         return self.name < other.name \
             and self.default_value < other.default_value \
             and self.decl_type < other.decl_type

This gives me the same behaviour as python 2.

Please suggest how this can be fixed in the mainline repo.

iMichka commented 4 years ago

This was fixed by #107 on the develop branch and will be added to the 2.0 release.