]> git.cworth.org Git - apitrace/blobdiff - wrappers/trace.py
Relocate tracing (dis/en)enablement.
[apitrace] / wrappers / trace.py
index c838dc78a83df0e8e61190b1f30ef774b20e5ba8..958c07279a1bf55eab84d44d349ef6a3fded764f 100644 (file)
@@ -187,7 +187,7 @@ class ValueSerializer(stdapi.Visitor):
         length = '_c' + array.type.tag
         index = '_i' + array.type.tag
         print '    if (%s) {' % instance
-        print '        size_t %s = %s;' % (length, array.length)
+        print '        size_t %s = %s > 0 ? %s : 0;' % (length, array.length, array.length)
         print '        trace::localWriter.beginArray(%s);' % length
         print '        for (size_t %s = 0; %s < %s; ++%s) {' % (index, index, length, index)
         print '            trace::localWriter.beginElement();'
@@ -396,6 +396,9 @@ class Tracer:
         print '#else'
         print '#  include <alloca.h> // alloca'
         print '#endif'
+        print
+        print '#include "trace.hpp"'
+        print
 
     def footer(self, api):
         pass
@@ -422,6 +425,16 @@ class Tracer:
         print function.prototype() + ' {'
         if function.type is not stdapi.Void:
             print '    %s _result;' % function.type
+
+        # No-op if tracing is disabled
+        print '    if (!trace::isTracingEnabled()) {'
+        Tracer.invokeFunction(self, function)
+        if function.type is not stdapi.Void:
+            print '        return _result;'
+        else:
+            print '        return;'
+        print '    }'
+
         self.traceFunctionImplBody(function)
         if function.type is not stdapi.Void:
             print '    return _result;'