From 7ebb9e259c7b94bb3aef3a0308a27eb01e0f2ec3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 6 May 2011 09:58:45 +0100 Subject: [PATCH] Handle pointer casts better. --- glretrace.py | 4 ++-- glretrace_glx.cpp | 4 ++-- glretrace_wgl.cpp | 20 ++++++++++---------- retrace.py | 6 +++--- trace_model.cpp | 33 +++++++++++++++++---------------- trace_model.hpp | 15 ++++++++++----- 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/glretrace.py b/glretrace.py index 7eab126..91176e1 100644 --- a/glretrace.py +++ b/glretrace.py @@ -160,11 +160,11 @@ class GlRetracer(Retracer): def extract_arg(self, function, arg, arg_type, lvalue, rvalue): if function.name in self.array_pointer_function_names and arg.name == 'pointer': - print ' %s = static_cast<%s>(%s.blob());' % (lvalue, arg_type, rvalue) + print ' %s = static_cast<%s>(%s.toPointer());' % (lvalue, arg_type, rvalue) return if function.name in self.draw_elements_function_names and arg.name == 'indices': - print ' %s = %s.blob();' % (lvalue, rvalue) + print ' %s = %s.toPointer();' % (lvalue, rvalue) return if function.name.startswith('glUniform') and function.args[0].name == arg.name == 'location': diff --git a/glretrace_glx.cpp b/glretrace_glx.cpp index 5f2645d..682995e 100644 --- a/glretrace_glx.cpp +++ b/glretrace_glx.cpp @@ -57,7 +57,7 @@ static void retrace_glXChooseVisual(Trace::Call &call) { } static void retrace_glXCreateContext(Trace::Call &call) { - void * orig_context = call.ret->blob(); + void * orig_context = call.ret->toPointer(); glws::Context *context = ws->createContext(glretrace::visual); context_map[orig_context] = context; } @@ -74,7 +74,7 @@ static void retrace_glXMakeCurrent(Trace::Call &call) { } glws::Drawable *new_drawable = getDrawable(static_cast(call.arg(1))); - glws::Context *new_context = context_map[call.arg(2).blob()]; + glws::Context *new_context = context_map[call.arg(2).toPointer()]; bool result = ws->makeCurrent(new_drawable, new_context); diff --git a/glretrace_wgl.cpp b/glretrace_wgl.cpp index fd76dbb..308017e 100644 --- a/glretrace_wgl.cpp +++ b/glretrace_wgl.cpp @@ -32,16 +32,16 @@ using namespace glretrace; -typedef std::map DrawableMap; -typedef std::map ContextMap; +typedef std::map DrawableMap; +typedef std::map ContextMap; static DrawableMap drawable_map; static DrawableMap pbuffer_map; static ContextMap context_map; static glws::Drawable * -getDrawable(void * hdc) { - if (hdc == NULL) { +getDrawable(unsigned long long hdc) { + if (hdc == 0) { return NULL; } @@ -55,7 +55,7 @@ getDrawable(void * hdc) { } static void retrace_wglCreateContext(Trace::Call &call) { - void * orig_context = call.ret->blob(); + unsigned long long orig_context = call.ret->toUIntPtr(); glws::Context *context = ws->createContext(glretrace::visual); context_map[orig_context] = context; } @@ -71,8 +71,8 @@ static void retrace_wglMakeCurrent(Trace::Call &call) { } } - glws::Drawable *new_drawable = getDrawable(call.arg(0).blob()); - glws::Context *new_context = context_map[call.arg(1).blob()]; + glws::Drawable *new_drawable = getDrawable(call.arg(0).toUIntPtr()); + glws::Context *new_context = context_map[call.arg(1).toUIntPtr()]; bool result = ws->makeCurrent(new_drawable, new_context); @@ -161,7 +161,7 @@ static void retrace_wglCreatePbufferARB(Trace::Call &call) { unsigned iWidth = call.arg(2); unsigned iHeight = call.arg(3); - void * orig_pbuffer = call.ret->blob(); + unsigned long long orig_pbuffer = call.ret->toUIntPtr(); glws::Drawable *drawable = ws->createDrawable(glretrace::visual); drawable->resize(iWidth, iHeight); @@ -170,9 +170,9 @@ static void retrace_wglCreatePbufferARB(Trace::Call &call) { } static void retrace_wglGetPbufferDCARB(Trace::Call &call) { - glws::Drawable *pbuffer = pbuffer_map[call.arg(0).blob()]; + glws::Drawable *pbuffer = pbuffer_map[call.arg(0).toUIntPtr()]; - void * orig_hdc = call.ret->blob(); + unsigned long long orig_hdc = call.ret->toUIntPtr(); drawable_map[orig_hdc] = pbuffer; } diff --git a/retrace.py b/retrace.py index c0ee82a..7b8c3da 100644 --- a/retrace.py +++ b/retrace.py @@ -102,10 +102,10 @@ class ValueExtractor(stdapi.Visitor): print ' %s = %s;' % (lvalue, new_lvalue) def visit_blob(self, blob, lvalue, rvalue): - print ' %s = static_cast<%s>((%s).blob());' % (lvalue, blob, rvalue) + print ' %s = static_cast<%s>((%s).toPointer());' % (lvalue, blob, rvalue) def visit_string(self, string, lvalue, rvalue): - print ' %s = (%s)((%s).string());' % (lvalue, string.expr, rvalue) + print ' %s = (%s)((%s).toString());' % (lvalue, string.expr, rvalue) class OpaqueValueExtractor(ValueExtractor): @@ -115,7 +115,7 @@ class OpaqueValueExtractor(ValueExtractor): in the context of handles.''' def visit_opaque(self, opaque, lvalue, rvalue): - print ' %s = static_cast<%s>((%s).blob());' % (lvalue, opaque, rvalue) + print ' %s = static_cast<%s>((%s).toPointer());' % (lvalue, opaque, rvalue) class ValueWrapper(stdapi.Visitor): diff --git a/trace_model.cpp b/trace_model.cpp index a817b39..f8801ce 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -106,11 +106,23 @@ Float ::operator double (void) const { return value; } Enum ::operator double (void) const { return static_cast(*sig->second); } -// blob cast -void * Value ::blob(void) const { assert(0); return NULL; } -void * Null ::blob(void) const { return NULL; } -void * Blob ::blob(void) const { return buf; } -void * Pointer::blob(void) const { return (void *)value; } +// pointer cast +void * Value ::toPointer(void) const { assert(0); return NULL; } +void * Null ::toPointer(void) const { return NULL; } +void * Blob ::toPointer(void) const { return buf; } +void * Pointer::toPointer(void) const { return (void *)value; } + + +// pointer cast +unsigned long long Value ::toUIntPtr(void) const { assert(0); return 0; } +unsigned long long Null ::toUIntPtr(void) const { return 0; } +unsigned long long Pointer::toUIntPtr(void) const { return value; } + + +// string cast +const char * Value ::toString(void) const { assert(0); return NULL; } +const char * Null ::toString(void) const { return NULL; } +const char * String::toString(void) const { return value.c_str(); } // virtual Value::visit() @@ -337,17 +349,6 @@ const Value & Value::operator[](size_t index) const { return null; } -const char * Value::string(void) const { - const String *string = dynamic_cast(unwrap(this)); - if (string) - return string->value.c_str(); - const Null *null = dynamic_cast(unwrap(this)); - if (null) - return NULL; - assert(0); - return NULL; -} - std::ostream & operator <<(std::ostream &os, Call &call) { Dumper d(os); os << call.no << " "; diff --git a/trace_model.hpp b/trace_model.hpp index 68f6626..d5b9950 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -59,8 +59,9 @@ public: virtual operator unsigned long long (void) const; virtual operator double (void) const; - virtual void *blob(void) const; - const char *string(void) const; + virtual void *toPointer(void) const; + virtual unsigned long long toUIntPtr(void) const; + virtual const char *toString(void) const; inline operator signed char (void) const { return static_cast(*this); @@ -109,7 +110,9 @@ public: operator signed long long (void) const; operator unsigned long long (void) const; operator double (void) const; - void *blob(void) const; + void *toPointer(void) const; + unsigned long long toUIntPtr(void) const; + const char *toString(void) const; void visit(Visitor &visitor); }; @@ -180,6 +183,7 @@ public: String(std::string _value) : value(_value) {} operator bool (void) const; + const char *toString(void) const; void visit(Visitor &visitor); std::string value; @@ -272,7 +276,7 @@ public: ~Blob(); operator bool (void) const; - void *blob(void) const; + void *toPointer(void) const; void visit(Visitor &visitor); size_t size; @@ -286,7 +290,8 @@ public: Pointer(unsigned long long value) : UInt(value) {} operator bool (void) const; - void *blob(void) const; + void *toPointer(void) const; + unsigned long long toUIntPtr(void) const; void visit(Visitor &visitor); }; -- 2.7.4