dbghelp: Constify some variables.
[wine] / dlls / ole32 / marshal.c
index 821cb87..ab1d332 100644 (file)
@@ -52,6 +52,37 @@ extern const CLSID CLSID_DfMarshal;
  * when the proxy disconnects or is destroyed */
 #define SORFP_NOLIFETIMEMGMT SORF_OXRES2
 
+/* imported object / proxy manager */
+struct proxy_manager
+{
+  const IMultiQIVtbl *lpVtbl;
+  const IMarshalVtbl *lpVtblMarshal;
+  const IClientSecurityVtbl *lpVtblCliSec;
+  struct apartment *parent; /* owning apartment (RO) */
+  struct list entry;        /* entry in apartment (CS parent->cs) */
+  OXID oxid;                /* object exported ID (RO) */
+  OXID_INFO oxid_info;      /* string binding, ipid of rem unknown and other information (RO) */
+  OID oid;                  /* object ID (RO) */
+  struct list interfaces;   /* imported interfaces (CS cs) */
+  LONG refs;                /* proxy reference count (LOCK) */
+  CRITICAL_SECTION cs;      /* thread safety for this object and children */
+  ULONG sorflags;           /* STDOBJREF flags (RO) */
+  IRemUnknown *remunk;      /* proxy to IRemUnknown used for lifecycle management (CS cs) */
+  HANDLE remoting_mutex;    /* mutex used for synchronizing access to IRemUnknown */
+  MSHCTX dest_context;      /* context used for activating optimisations (LOCK) */
+  void *dest_context_data;  /* reserved context value (LOCK) */
+};
+
+static inline struct proxy_manager *impl_from_IMarshal( IMarshal *iface )
+{
+    return (struct proxy_manager *)((char*)iface - FIELD_OFFSET(struct proxy_manager, lpVtblMarshal));
+}
+
+static inline struct proxy_manager *impl_from_IClientSecurity( IClientSecurity *iface )
+{
+    return (struct proxy_manager *)((char*)iface - FIELD_OFFSET(struct proxy_manager, lpVtblCliSec));
+}
+
 static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt,
                                 MSHCTX dest_context, void *dest_context_data,
                                 REFIID riid, const OXID_INFO *oxid_info,
@@ -352,19 +383,19 @@ static HRESULT WINAPI StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwR
 
 static HRESULT WINAPI Proxy_QueryInterface(IMarshal *iface, REFIID riid, void **ppvObject)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
+    struct proxy_manager *This = impl_from_IMarshal( iface );
     return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject);
 }
 
 static ULONG WINAPI Proxy_AddRef(IMarshal *iface)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
+    struct proxy_manager *This = impl_from_IMarshal( iface );
     return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
 }
 
 static ULONG WINAPI Proxy_Release(IMarshal *iface)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
+    struct proxy_manager *This = impl_from_IMarshal( iface );
     return IMultiQI_Release((IMultiQI *)&This->lpVtbl);
 }
 
@@ -372,7 +403,7 @@ static HRESULT WINAPI Proxy_MarshalInterface(
     LPMARSHAL iface, IStream *pStm, REFIID riid, void* pv, DWORD dwDestContext,
     void* pvDestContext, DWORD mshlflags)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
+    struct proxy_manager *This = impl_from_IMarshal( iface );
     HRESULT hr;
     struct ifproxy *ifproxy;
 
@@ -497,19 +528,19 @@ static const IMarshalVtbl ProxyMarshal_Vtbl =
 
 static HRESULT WINAPI ProxyCliSec_QueryInterface(IClientSecurity *iface, REFIID riid, void **ppvObject)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblCliSec, iface);
+    struct proxy_manager *This = impl_from_IClientSecurity( iface );
     return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject);
 }
 
 static ULONG WINAPI ProxyCliSec_AddRef(IClientSecurity *iface)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblCliSec, iface);
+    struct proxy_manager *This = impl_from_IClientSecurity( iface );
     return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
 }
 
 static ULONG WINAPI ProxyCliSec_Release(IClientSecurity *iface)
 {
-    ICOM_THIS_MULTI(struct proxy_manager, lpVtblCliSec, iface);
+    struct proxy_manager *This = impl_from_IClientSecurity( iface );
     return IMultiQI_Release((IMultiQI *)&This->lpVtbl);
 }
 
@@ -1214,16 +1245,13 @@ StdMarshalImpl_MarshalInterface(
     RPC_StartRemoting(apt);
 
     hres = marshal_object(apt, &stdobjref, riid, pv, mshlflags);
-    if (hres)
+    if (hres != S_OK)
     {
         ERR("Failed to create ifstub, hres=0x%x\n", hres);
         return hres;
     }
 
-    hres = IStream_Write(pStm, &stdobjref, sizeof(stdobjref), &res);
-    if (hres) return hres;
-
-    return S_OK;
+    return IStream_Write(pStm, &stdobjref, sizeof(stdobjref), &res);
 }
 
 /* helper for StdMarshalImpl_UnmarshalInterface - does the unmarshaling with
@@ -1321,10 +1349,10 @@ StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, v
 
     /* read STDOBJREF from wire */
     hres = IStream_Read(pStm, &stdobjref, sizeof(stdobjref), &res);
-    if (hres) return STG_E_READFAULT;
+    if (hres != S_OK) return STG_E_READFAULT;
 
     hres = apartment_getoxid(apt, &oxid);
-    if (hres) return hres;
+    if (hres != S_OK) return hres;
 
     /* check if we're marshalling back to ourselves */
     if ((oxid == stdobjref.oxid) && (stubmgr = get_stub_manager(apt, stdobjref.oid)))
@@ -1336,7 +1364,7 @@ StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, v
       
         /* unref the ifstub. FIXME: only do this on success? */
         if (!stub_manager_is_table_marshaled(stubmgr, &stdobjref.ipid))
-            stub_manager_ext_release(stubmgr, stdobjref.cPublicRefs, stdobjref.flags & SORFP_TABLEWEAK, TRUE);
+            stub_manager_ext_release(stubmgr, stdobjref.cPublicRefs, stdobjref.flags & SORFP_TABLEWEAK, FALSE);
 
         stub_manager_int_release(stubmgr);
         return hres;
@@ -1374,7 +1402,7 @@ StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, v
     if (stubmgr) stub_manager_int_release(stubmgr);
     if (stub_apt) apartment_release(stub_apt);
 
-    if (hres) WARN("Failed with error 0x%08x\n", hres);
+    if (hres != S_OK) WARN("Failed with error 0x%08x\n", hres);
     else TRACE("Successfully created proxy %p\n", *ppv);
 
     return hres;
@@ -1392,7 +1420,7 @@ StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
     TRACE("iface=%p, pStm=%p\n", iface, pStm);
     
     hres = IStream_Read(pStm, &stdobjref, sizeof(stdobjref), &res);
-    if (hres) return STG_E_READFAULT;
+    if (hres != S_OK) return STG_E_READFAULT;
 
     TRACE("oxid = %s, oid = %s, ipid = %s\n",
         wine_dbgstr_longlong(stdobjref.oxid),
@@ -1516,7 +1544,7 @@ static HRESULT get_marshaler(REFIID riid, IUnknown *pUnk, DWORD dwDestContext,
     if (!pUnk)
         return E_POINTER;
     hr = IUnknown_QueryInterface(pUnk, &IID_IMarshal, (LPVOID*)pMarshal);
-    if (hr)
+    if (hr != S_OK)
         hr = CoGetStandardMarshal(riid, pUnk, dwDestContext, pvDestContext,
                                   mshlFlags, pMarshal);
     return hr;
@@ -1537,7 +1565,7 @@ static HRESULT get_unmarshaler_from_stream(IStream *stream, IMarshal **marshal,
 
     /* read common OBJREF header */
     hr = IStream_Read(stream, &objref, FIELD_OFFSET(OBJREF, u_objref), &res);
-    if (hr || (res != FIELD_OFFSET(OBJREF, u_objref)))
+    if (hr != S_OK || (res != FIELD_OFFSET(OBJREF, u_objref)))
     {
         ERR("Failed to read common OBJREF header, 0x%08x\n", hr);
         return STG_E_READFAULT;
@@ -1566,7 +1594,7 @@ static HRESULT get_unmarshaler_from_stream(IStream *stream, IMarshal **marshal,
         /* read constant sized OR_CUSTOM data from stream */
         hr = IStream_Read(stream, &objref.u_objref.u_custom,
                           custom_header_size, &res);
-        if (hr || (res != custom_header_size))
+        if (hr != S_OK || (res != custom_header_size))
         {
             ERR("Failed to read OR_CUSTOM header, 0x%08x\n", hr);
             return STG_E_READFAULT;
@@ -1583,7 +1611,7 @@ static HRESULT get_unmarshaler_from_stream(IStream *stream, IMarshal **marshal,
         return RPC_E_INVALID_OBJREF;
     }
 
-    if (hr)
+    if (hr != S_OK)
         ERR("Failed to create marshal, 0x%08x\n", hr);
 
     return hr;
@@ -1618,12 +1646,12 @@ HRESULT WINAPI CoGetMarshalSizeMax(ULONG *pulSize, REFIID riid, IUnknown *pUnk,
     CLSID marshaler_clsid;
 
     hr = get_marshaler(riid, pUnk, dwDestContext, pvDestContext, mshlFlags, &pMarshal);
-    if (hr)
+    if (hr != S_OK)
         return hr;
 
     hr = IMarshal_GetUnmarshalClass(pMarshal, riid, pUnk, dwDestContext,
                                     pvDestContext, mshlFlags, &marshaler_clsid);
-    if (hr)
+    if (hr != S_OK)
     {
         ERR("IMarshal::GetUnmarshalClass failed, 0x%08x\n", hr);
         IMarshal_Release(pMarshal);
@@ -1711,7 +1739,7 @@ HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
 
     /* get the marshaler for the specified interface */
     hr = get_marshaler(riid, pUnk, dwDestContext, pvDestContext, mshlFlags, &pMarshal);
-    if (hr)
+    if (hr != S_OK)
     {
         ERR("Failed to get marshaller, 0x%08x\n", hr);
         return hr;
@@ -1719,7 +1747,7 @@ HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
 
     hr = IMarshal_GetUnmarshalClass(pMarshal, riid, pUnk, dwDestContext,
                                     pvDestContext, mshlFlags, &marshaler_clsid);
-    if (hr)
+    if (hr != S_OK)
     {
         ERR("IMarshal::GetUnmarshalClass failed, 0x%08x\n", hr);
         goto cleanup;
@@ -1733,7 +1761,7 @@ HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
 
         /* write the common OBJREF header to the stream */
         hr = IStream_Write(pStream, &objref, FIELD_OFFSET(OBJREF, u_objref), NULL);
-        if (hr)
+        if (hr != S_OK)
         {
             ERR("Failed to write OBJREF header to stream, 0x%08x\n", hr);
             goto cleanup;
@@ -1749,7 +1777,7 @@ HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
         hr = IMarshal_GetMarshalSizeMax(pMarshal, riid, pUnk, dwDestContext,
                                         pvDestContext, mshlFlags,
                                         &objref.u_objref.u_custom.size);
-        if (hr)
+        if (hr != S_OK)
         {
             ERR("Failed to get max size of marshal data, error 0x%08x\n", hr);
             goto cleanup;
@@ -1757,7 +1785,7 @@ HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
         /* write constant sized common header and OR_CUSTOM data into stream */
         hr = IStream_Write(pStream, &objref,
                           FIELD_OFFSET(OBJREF, u_objref.u_custom.pData), NULL);
-        if (hr)
+        if (hr != S_OK)
         {
             ERR("Failed to write OR_CUSTOM header to stream with 0x%08x\n", hr);
             goto cleanup;
@@ -1769,7 +1797,7 @@ HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
     hr = IMarshal_MarshalInterface(pMarshal, pStream, riid, pUnk, dwDestContext,
                                    pvDestContext, mshlFlags);
 
-    if (hr)
+    if (hr != S_OK)
     {
         ERR("Failed to marshal the interface %s, %x\n", debugstr_guid(riid), hr);
         goto cleanup;
@@ -1821,7 +1849,7 @@ HRESULT WINAPI CoUnmarshalInterface(IStream *pStream, REFIID riid, LPVOID *ppv)
 
     /* call the helper object to do the actual unmarshaling */
     hr = IMarshal_UnmarshalInterface(pMarshal, pStream, &iid, (LPVOID*)&object);
-    if (hr)
+    if (hr != S_OK)
         ERR("IMarshal::UnmarshalInterface failed, 0x%08x\n", hr);
 
     if (hr == S_OK)
@@ -1831,7 +1859,7 @@ HRESULT WINAPI CoUnmarshalInterface(IStream *pStream, REFIID riid, LPVOID *ppv)
         {
             TRACE("requested interface != marshalled interface, additional QI needed\n");
             hr = IUnknown_QueryInterface(object, riid, ppv);
-            if (hr)
+            if (hr != S_OK)
                 ERR("Couldn't query for interface %s, hr = 0x%08x\n",
                     debugstr_guid(riid), hr);
             IUnknown_Release(object);
@@ -1885,7 +1913,7 @@ HRESULT WINAPI CoReleaseMarshalData(IStream *pStream)
 
     /* call the helper object to do the releasing of marshal data */
     hr = IMarshal_ReleaseMarshalData(pMarshal, pStream);
-    if (hr)
+    if (hr != S_OK)
         ERR("IMarshal::ReleaseMarshalData failed with error 0x%08x\n", hr);
 
     IMarshal_Release(pMarshal);