<div>+    @property</div><div>+    def translation_unit(self):</div><div>+        """Returns the TranslationUnit to which this Cursor belongs."""</div><div>+        return getattr(self, '_tu', None)</div>
<div><br></div><div>What's the reason for the default value? Do we expect that people create cursers via the lowlevel calls? Why would just return tu_ not work?</div><div><br></div><div><div>+        # Store a reference to the TU in the Python object so it won't get GC'd</div>
<div>+        # before the Cursor.</div><div>+        tu = None</div><div>+        for arg in args:</div><div>+            if isinstance(arg, TranslationUnit):</div><div>+                tu = arg</div><div>+                break</div>
<div>+</div><div>+            if hasattr(arg, 'translation_unit'):</div><div>+                tu = arg.translation_unit</div><div>+                break</div><div>+</div><div>+        assert tu is not None</div><div>
+</div><div>+        res._tu = tu</div></div><div><br></div><div>That seems - odd. I can't find docs what from_result is supposed to do, or what "args" are provided. But having to search through them for a TU seems wrong - shouldn't they all have a TU?</div>
<div><br></div><div>Also, regarding the test - would it be possible to create a test that drops the reference, triggers the gc and then makes sure the cursor is still valid (as that is what we really care about)?</div><div>
<br></div><div>Cheers,</div><div>/Manuel</div><br><div class="gmail_quote">On Sun, May 13, 2012 at 7:20 AM, Gregory Szorc <span dir="ltr"><<a href="mailto:gregory.szorc@gmail.com" target="_blank">gregory.szorc@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch stores a reference to the underlying TranslationUnit in<br>
Cursor and Type instances. We want to keep this reference so garbage<br>
collection doesn't collect the TranslationUnit instance, which would<br>
free the backing memory and possibly cause a segfault if the Cursor or<br>
Type instance makes a C API call against a dead TU.<br>
<br>
Other types in the module (like File) also need this treatment. Those<br>
will be addressed in a later patch.<br>
<br>
---<br>
 bindings/python/clang/cindex.py             |   46 ++++++++++++++++++++++++++-<br>
 bindings/python/tests/cindex/test_cursor.py |    3 ++<br>
 bindings/python/tests/cindex/test_type.py   |    1 +<br>
 3 files changed, 49 insertions(+), 1 deletion(-)<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br>