]> git.cworth.org Git - apitrace/commitdiff
Cleanup unicode support.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 31 Jan 2012 15:10:13 +0000 (15:10 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 31 Jan 2012 15:10:13 +0000 (15:10 +0000)
specs/dxgi.py
specs/stdapi.py
trace.py

index 50327ebef0802deb855f23bf04e5cff15742cbb7..8fef9bd532f9827ec543935e771ac5146a5f390a 100644 (file)
@@ -56,7 +56,7 @@ DXGI_MAPPED_RECT = Struct("DXGI_MAPPED_RECT", [
 ])
 
 DXGI_OUTPUT_DESC = Struct("DXGI_OUTPUT_DESC", [
-    (Array(WCHAR, 32), "DeviceName"),
+    (WString, "DeviceName"),
     (RECT, "DesktopCoordinates"),
     (BOOL, "AttachedToDesktop"),
     (DXGI_MODE_ROTATION, "Rotation"),
@@ -72,7 +72,7 @@ DXGI_FRAME_STATISTICS = Struct("DXGI_FRAME_STATISTICS", [
 ])
 
 DXGI_ADAPTER_DESC = Struct("DXGI_ADAPTER_DESC", [
-    (Array(WCHAR, 128), "Description"),
+    (WString, "Description"),
     (UINT, "VendorId"),
     (UINT, "DeviceId"),
     (UINT, "SubSysId"),
index 61e2b21b756e2f241f2d8a7b130e07f18fbce58c..5ba621fff35ceb7e26df9d94d0d303240d77e68c 100644 (file)
@@ -361,16 +361,14 @@ class Method(Function):
 
 class String(Type):
 
-    def __init__(self, expr = "char *", length = None):
+    def __init__(self, expr = "char *", length = None, kind = 'String'):
         Type.__init__(self, expr)
         self.length = length
+        self.kind = kind
 
     def visit(self, visitor, *args, **kwargs):
         return visitor.visitString(self, *args, **kwargs)
 
-# C string (i.e., zero terminated)
-CString = String()
-
 
 class Opaque(Type):
     '''Opaque pointer.'''
@@ -708,7 +706,10 @@ ULongLong = Literal("unsigned long long", "UInt")
 Float = Literal("float", "Float")
 Double = Literal("double", "Double")
 SizeT = Literal("size_t", "UInt")
-WString = Literal("wchar_t *", "WString")
+
+# C string (i.e., zero terminated)
+CString = String()
+WString = String("wchar_t *", kind="WString")
 
 Int8 = Literal("int8_t", "SInt")
 UInt8 = Literal("uint8_t", "UInt")
index c759607ebe12678b0e9012c4363d2608d0a5bb81..a9395339c2981b054a612fbbacdcd43c2adcf4ec 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -148,10 +148,20 @@ class ValueSerializer(stdapi.Visitor):
         print '    trace::localWriter.write%s(%s);' % (literal.kind, instance)
 
     def visitString(self, string, instance):
+        if string.kind == 'String':
+            cast = 'const char *'
+        elif string.kind == 'WString':
+            cast = 'const wchar_t *'
+        else:
+            assert False
+        if cast != string.expr:
+            # reinterpret_cast is necessary for GLubyte * <=> char *
+            instance = 'reinterpret_cast<%s>(%s)' % (cast, instance)
         if string.length is not None:
-            print '    trace::localWriter.writeString((const char *)%s, %s);' % (instance, string.length)
+            length = ', %s' % string.length
         else:
-            print '    trace::localWriter.writeString((const char *)%s);' % instance
+            length = ''
+        print '    trace::localWriter.write%s(%s%s);' % (string.kind, instance, length)
 
     def visitConst(self, const, instance):
         self.visit(const.type, instance)