def visitInterface(self, interface, instance):
assert instance.startswith('*')
instance = instance[1:]
- print " if (%s) {" % instance
- print " %s = static_cast<%s *>(%s)->m_pInstance;" % (instance, getWrapperInterfaceName(interface), instance)
- print " }"
+ print r' if (%s) {' % instance
+ print r' %s *pWrapper = static_cast<%s*>(%s);' % (getWrapperInterfaceName(interface), getWrapperInterfaceName(interface), instance)
+ print r' if (pWrapper && pWrapper->m_dwMagic == 0xd8365d6c) {'
+ print r' %s = pWrapper->m_pInstance;' % (instance,)
+ print r' } else {'
+ print r' os::log("apitrace: warning: %%s: unexpected %%s pointer\n", __FUNCTION__, "%s");' % interface.name
+ print r' }'
+ print r' }'
class Tracer:
def declareWrapperInterfaceVariables(self, interface):
#print "private:"
+ print " DWORD m_dwMagic;"
print " %s * m_pInstance;" % (interface.name,)
def implementWrapperInterface(self, interface):
print '%s::%s(%s * pInstance) {' % (getWrapperInterfaceName(interface), getWrapperInterfaceName(interface), interface.name)
+ print ' m_dwMagic = 0xd8365d6c;'
print ' m_pInstance = pInstance;'
print '}'
print
print ' trace::localWriter.endArg();'
from specs.winapi import REFIID
- from specs.stdapi import Pointer, Opaque
+ from specs.stdapi import Pointer, Opaque, Interface
riid = None
for arg in method.args:
self.serializeArg(method, arg)
self.wrapArg(method, arg)
if riid is not None and isinstance(arg.type, Pointer):
- assert isinstance(arg.type.type, Opaque)
- self.wrapIid(interface, method, riid, arg)
+ if isinstance(arg.type.type, Opaque):
+ self.wrapIid(riid, arg)
+ else:
+ assert isinstance(arg.type.type, Pointer)
+ assert isinstance(arg.type.type.type, Interface)
if method.type is not stdapi.Void:
print ' trace::localWriter.beginReturn();'
print ' if (!__result)'
print ' delete this;'
- def wrapIid(self, interface, method, riid, out):
+ def wrapIid(self, riid, out):
print ' if (%s && *%s) {' % (out.name, out.name)
print ' if (*%s == m_pInstance) {' % (out.name,)
+ print ' AddRef();'
+ print ' m_pInstance->Release();'
print ' *%s = this;' % (out.name,)
print ' }'
- for iface in self.api.interfaces:
+ for iface in self.api.getAllInterfaces():
print r' else if (%s == IID_%s) {' % (riid.name, iface.name)
print r' *%s = new Wrap%s((%s *) *%s);' % (out.name, iface.name, iface.name, out.name)
print r' }'
print r' else {'
- print r' os::log("apitrace: warning: unknown REFIID {0x%08lX,0x%04X,0x%04X,{0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X}}\n",'
+ print r' os::log("apitrace: warning: %s: unknown REFIID {0x%08lX,0x%04X,0x%04X,{0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X}}\n",'
+ print r' __FUNCTION__,'
print r' %s.Data1, %s.Data2, %s.Data3,' % (riid.name, riid.name, riid.name)
print r' %s.Data4[0],' % (riid.name,)
print r' %s.Data4[1],' % (riid.name,)