From: José Fonseca Date: Mon, 29 Nov 2010 14:43:06 +0000 (+0000) Subject: Portability fixes. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=8ebb10b1c15ec5999b9a828d3efb7eefb3494e46;p=apitrace Portability fixes. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 914c12a..78a6f2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,9 @@ if (MSVC) string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") endif (${flag_var} MATCHES "/MD") endforeach (flag_var) + + # C99 headers + include_directories (c99) else () # Adjust warnings add_definitions (-Wall) diff --git a/trace.py b/trace.py index 8c4eb75..65b03b6 100644 --- a/trace.py +++ b/trace.py @@ -322,7 +322,10 @@ class Tracer: def trace_function_impl(self, function): pvalue = self.function_pointer_value(function) print function.prototype() + ' {' - print ' static const char * __args[%u] = {%s};' % (len(function.args), ', '.join(['"%s"' % arg.name for arg in function.args])) + if function.args: + print ' static const char * __args[%u] = {%s};' % (len(function.args), ', '.join(['"%s"' % arg.name for arg in function.args])) + else: + print ' static const char ** __args = NULL;' print ' static const Trace::FunctionSig __sig = {%u, "%s", %u, __args};' % (int(function.id), function.name, len(function.args)) if function.type is stdapi.Void: result = '' diff --git a/wgltrace.py b/wgltrace.py index 11da692..6474755 100644 --- a/wgltrace.py +++ b/wgltrace.py @@ -26,6 +26,7 @@ from wglapi import wglapi from trace import Tracer +from codegen import * public_symbols = set([ @@ -410,18 +411,20 @@ class WglTracer(Tracer): def wrap_ret(self, function, instance): if function.name == "wglGetProcAddress": print ' if (%s) {' % instance - else_ = '' - for f in wglapi.functions: + + func_dict = dict([(f.name, f) for f in wglapi.functions]) + + def handle_case(function_name): + f = func_dict[function_name] ptype = self.function_pointer_type(f) pvalue = self.function_pointer_value(f) - print ' %sif (!strcmp("%s", lpszProc)) {' % (else_, f.name) - print ' %s = (%s)%s;' % (pvalue, ptype, instance) - print ' %s = (%s)&%s;' % (instance, function.type, f.name); - print ' }' - else_ = 'else ' - print ' %s{' % (else_,) - print ' OS::DebugMessage("apitrace: unknown function \\"%s\\"\\n", lpszProc);' - print ' }' + print ' %s = (%s)%s;' % (pvalue, ptype, instance) + print ' %s = (%s)&%s;' % (instance, function.type, f.name); + + def handle_default(): + print ' OS::DebugMessage("apitrace: unknown function \\"%s\\"\\n", lpszProc);' + + string_switch('lpszProc', func_dict.keys(), handle_case, handle_default) print ' }'