aboutsummaryrefslogtreecommitdiff
path: root/bindings/python/clang/cindex.py
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-24 21:19:57 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-24 21:19:57 +0000
commita33dca490ad55c6f4bfc38a911f41a66f508a482 (patch)
treeb1d98010989e71180486b2f4c3c6e49f31382355 /bindings/python/clang/cindex.py
parentbe0b555b8088e5dd5d193560a3f29fe383810b4c (diff)
cindex/Python: Convert CXString objects to regular Python strings below API.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94384 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/clang/cindex.py')
-rw-r--r--bindings/python/clang/cindex.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 0377a298ae..115ea9fbfd 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -61,24 +61,19 @@ CursorKind = c_int
### Structures and Utility Classes ###
-class String(Structure):
- """
- The String class is a simple wrapper around constant string data returned
- from functions in the CIndex library.
+class _CXString(Structure):
+ """Helper for transforming CXString results."""
- String objects do not provide any of the operations that Python strings
- support. However, these objects can be explicitly cast using the str()
- function.
- """
_fields_ = [("spelling", c_char_p), ("free", c_int)]
def __del__(self):
- if self.free:
- String_dispose(self)
-
- def __str__(self):
- return self.spelling
+ _CXString_dispose(self)
+ @staticmethod
+ def from_result(res, fn, args):
+ assert isinstance(res, _CXString)
+ return _CXString_getCString(res)
+
class SourceLocation(Structure):
"""
A SourceLocation represents a particular location within a source file.
@@ -328,8 +323,12 @@ class File(ClangObject):
Callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
# String Functions
-String_dispose = lib.clang_disposeString
-String_dispose.argtypes = [String]
+_CXString_dispose = lib.clang_disposeString
+_CXString_dispose.argtypes = [_CXString]
+
+_CXString_getCString = lib.clang_getCString
+_CXString_getCString.argtypes = [_CXString]
+_CXString_getCString.restype = c_char_p
# Source Location Functions
SourceLocation_loc = lib.clang_getInstantiationLocation
@@ -399,7 +398,8 @@ Cursor_eq.restype = c_uint
Cursor_spelling = lib.clang_getCursorSpelling
Cursor_spelling.argtypes = [Cursor]
-Cursor_spelling.restype = String
+Cursor_spelling.restype = _CXString
+Cursor_spelling.errcheck = _CXString.from_result
Cursor_loc = lib.clang_getCursorLocation
Cursor_loc.argtypes = [Cursor]
@@ -441,7 +441,8 @@ TranslationUnit_cursor.restype = Cursor
TranslationUnit_spelling = lib.clang_getTranslationUnitSpelling
TranslationUnit_spelling.argtypes = [TranslationUnit]
-TranslationUnit_spelling.restype = String
+TranslationUnit_spelling.restype = _CXString
+TranslationUnit_spelling.errcheck = _CXString.from_result
TranslationUnit_dispose = lib.clang_disposeTranslationUnit
TranslationUnit_dispose.argtypes = [TranslationUnit]