From 280a176f599484b3acf75f070e3f25b756786cc2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 31 Jan 2012 15:10:13 +0000 Subject: [PATCH] Cleanup unicode support. --- specs/dxgi.py | 4 ++-- specs/stdapi.py | 11 ++++++----- trace.py | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/specs/dxgi.py b/specs/dxgi.py index 50327eb..8fef9bd 100644 --- a/specs/dxgi.py +++ b/specs/dxgi.py @@ -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"), diff --git a/specs/stdapi.py b/specs/stdapi.py index 61e2b21..5ba621f 100644 --- a/specs/stdapi.py +++ b/specs/stdapi.py @@ -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") diff --git a/trace.py b/trace.py index c759607..a939533 100644 --- 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) -- 2.43.0