Nikolay Sivov : combase: Move CoRegisterInitializeSpy()/CoRevokeInitializeSpy().

Alexandre Julliard julliard at winehq.org
Wed Aug 19 15:46:01 CDT 2020


Module: wine
Branch: master
Commit: c9586634d4109547f8b28d827d34968b85039409
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=c9586634d4109547f8b28d827d34968b85039409

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Aug 19 11:29:11 2020 +0300

combase: Move CoRegisterInitializeSpy()/CoRevokeInitializeSpy().

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/combase/combase.c    |  95 +++++++++++++++++++++++++++++++++++++++
 dlls/combase/combase.spec |   4 +-
 dlls/ole32/compobj.c      | 110 ----------------------------------------------
 dlls/ole32/ole32.spec     |   4 +-
 4 files changed, 99 insertions(+), 114 deletions(-)

diff --git a/dlls/combase/combase.c b/dlls/combase/combase.c
index 52a159d7fe..114ea89e05 100644
--- a/dlls/combase/combase.c
+++ b/dlls/combase/combase.c
@@ -65,6 +65,26 @@ struct progidredirect_data
     ULONG clsid_offset;
 };
 
+struct init_spy
+{
+    struct list entry;
+    IInitializeSpy *spy;
+    unsigned int id;
+};
+
+static struct init_spy *get_spy_entry(struct tlsdata *tlsdata, unsigned int id)
+{
+    struct init_spy *spy;
+
+    LIST_FOR_EACH_ENTRY(spy, &tlsdata->spies, struct init_spy, entry)
+    {
+        if (id == spy->id && spy->spy)
+            return spy;
+    }
+
+    return NULL;
+}
+
 static NTSTATUS create_key(HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr)
 {
     NTSTATUS status = NtCreateKey((HANDLE *)retkey, access, attr, 0, NULL, 0, NULL);
@@ -1426,3 +1446,78 @@ HRESULT WINAPI CoSwitchCallContext(IUnknown *context, IUnknown **old_context)
 
     return S_OK;
 }
+
+/******************************************************************************
+ *          CoRegisterInitializeSpy    (combase.@)
+ */
+HRESULT WINAPI CoRegisterInitializeSpy(IInitializeSpy *spy, ULARGE_INTEGER *cookie)
+{
+    struct tlsdata *tlsdata;
+    struct init_spy *entry;
+    unsigned int id;
+    HRESULT hr;
+
+    TRACE("%p, %p\n", spy, cookie);
+
+    if (!spy || !cookie)
+        return E_INVALIDARG;
+
+    if (FAILED(hr = com_get_tlsdata(&tlsdata)))
+        return hr;
+
+    hr = IInitializeSpy_QueryInterface(spy, &IID_IInitializeSpy, (void **)&spy);
+    if (FAILED(hr))
+        return hr;
+
+    entry = heap_alloc(sizeof(*entry));
+    if (!entry)
+    {
+        IInitializeSpy_Release(spy);
+        return E_OUTOFMEMORY;
+    }
+
+    entry->spy = spy;
+
+    id = 0;
+    while (get_spy_entry(tlsdata, id) != NULL)
+    {
+        id++;
+    }
+
+    entry->id = id;
+    list_add_head(&tlsdata->spies, &entry->entry);
+
+    cookie->u.HighPart = GetCurrentThreadId();
+    cookie->u.LowPart = entry->id;
+
+    return S_OK;
+}
+
+/******************************************************************************
+ *          CoRevokeInitializeSpy    (combase.@)
+ */
+HRESULT WINAPI CoRevokeInitializeSpy(ULARGE_INTEGER cookie)
+{
+    struct tlsdata *tlsdata;
+    struct init_spy *spy;
+    HRESULT hr;
+
+    TRACE("%s\n", wine_dbgstr_longlong(cookie.QuadPart));
+
+    if (cookie.u.HighPart != GetCurrentThreadId())
+        return E_INVALIDARG;
+
+    if (FAILED(hr = com_get_tlsdata(&tlsdata)))
+        return hr;
+
+    if (!(spy = get_spy_entry(tlsdata, cookie.u.LowPart))) return E_INVALIDARG;
+
+    IInitializeSpy_Release(spy->spy);
+    spy->spy = NULL;
+    if (!tlsdata->spies_lock)
+    {
+        list_remove(&spy->entry);
+        heap_free(spy);
+    }
+    return S_OK;
+}
diff --git a/dlls/combase/combase.spec b/dlls/combase/combase.spec
index 55ba999a37..0842681078 100644
--- a/dlls/combase/combase.spec
+++ b/dlls/combase/combase.spec
@@ -140,7 +140,7 @@
 @ stub CoReactivateObject
 @ stub CoRegisterActivationFilter
 @ stdcall CoRegisterClassObject(ptr ptr long long ptr) ole32.CoRegisterClassObject
-@ stdcall CoRegisterInitializeSpy(ptr ptr) ole32.CoRegisterInitializeSpy
+@ stdcall CoRegisterInitializeSpy(ptr ptr)
 @ stdcall CoRegisterMallocSpy(ptr)
 @ stdcall CoRegisterMessageFilter(ptr ptr) ole32.CoRegisterMessageFilter
 @ stdcall CoRegisterPSClsid(ptr ptr) ole32.CoRegisterPSClsid
@@ -152,7 +152,7 @@
 @ stub CoRetireServer
 @ stdcall CoRevertToSelf()
 @ stdcall CoRevokeClassObject(long) ole32.CoRevokeClassObject
-@ stdcall CoRevokeInitializeSpy(int64) ole32.CoRevokeInitializeSpy
+@ stdcall CoRevokeInitializeSpy(int64)
 @ stdcall CoRevokeMallocSpy()
 @ stub CoSetCancelObject
 @ stdcall CoSetErrorInfo(long ptr) SetErrorInfo
diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c
index 4e7cd3c667..2a5e9f573a 100644
--- a/dlls/ole32/compobj.c
+++ b/dlls/ole32/compobj.c
@@ -1775,19 +1775,6 @@ DWORD WINAPI CoBuildVersion(void)
     return (rmm<<16)+rup;
 }
 
-static struct init_spy *get_spy_entry(struct oletls *info, unsigned int id)
-{
-    struct init_spy *spy;
-
-    LIST_FOR_EACH_ENTRY(spy, &info->spies, struct init_spy, entry)
-    {
-        if (id == spy->id && spy->spy)
-            return spy;
-    }
-
-    return NULL;
-}
-
 /*
  * When locked, don't modify list (unless we add a new head), so that it's
  * safe to iterate it. Freeing of list entries is delayed and done on unlock.
@@ -1811,103 +1798,6 @@ static void unlock_init_spies(struct oletls *info)
     }
 }
 
-/******************************************************************************
- *              CoRegisterInitializeSpy [OLE32.@]
- *
- * Add a Spy that watches CoInitializeEx calls
- *
- * PARAMS
- *  spy [I] Pointer to IUnknown interface that will be QueryInterface'd.
- *  cookie [II] cookie receiver
- *
- * RETURNS
- *  Success: S_OK if not already initialized, S_FALSE otherwise.
- *  Failure: HRESULT code.
- *
- * SEE ALSO
- *   CoInitializeEx
- */
-HRESULT WINAPI CoRegisterInitializeSpy(IInitializeSpy *spy, ULARGE_INTEGER *cookie)
-{
-    struct oletls *info = COM_CurrentInfo();
-    struct init_spy *entry;
-    unsigned int id;
-    HRESULT hr;
-
-    TRACE("(%p, %p)\n", spy, cookie);
-
-    if (!spy || !cookie || !info)
-    {
-        if (!info)
-            WARN("Could not allocate tls\n");
-        return E_INVALIDARG;
-    }
-
-    hr = IInitializeSpy_QueryInterface(spy, &IID_IInitializeSpy, (void **)&spy);
-    if (FAILED(hr))
-        return hr;
-
-    entry = heap_alloc(sizeof(*entry));
-    if (!entry)
-    {
-        IInitializeSpy_Release(spy);
-        return E_OUTOFMEMORY;
-    }
-
-    entry->spy = spy;
-
-    id = 0;
-    while (get_spy_entry(info, id) != NULL)
-    {
-        id++;
-    }
-
-    entry->id = id;
-    list_add_head(&info->spies, &entry->entry);
-
-    cookie->HighPart = GetCurrentThreadId();
-    cookie->LowPart = entry->id;
-
-    return S_OK;
-}
-
-/******************************************************************************
- *              CoRevokeInitializeSpy [OLE32.@]
- *
- * Remove a spy that previously watched CoInitializeEx calls
- *
- * PARAMS
- *  cookie [I] The cookie obtained from a previous CoRegisterInitializeSpy call
- *
- * RETURNS
- *  Success: S_OK if a spy is removed
- *  Failure: E_INVALIDARG
- *
- * SEE ALSO
- *   CoInitializeEx
- */
-HRESULT WINAPI CoRevokeInitializeSpy(ULARGE_INTEGER cookie)
-{
-    struct oletls *info = COM_CurrentInfo();
-    struct init_spy *spy;
-
-    TRACE("(%s)\n", wine_dbgstr_longlong(cookie.QuadPart));
-
-    if (!info || cookie.HighPart != GetCurrentThreadId())
-        return E_INVALIDARG;
-
-    if (!(spy = get_spy_entry(info, cookie.LowPart))) return E_INVALIDARG;
-
-    IInitializeSpy_Release(spy->spy);
-    spy->spy = NULL;
-    if (!info->spies_lock)
-    {
-        list_remove(&spy->entry);
-        heap_free(spy);
-    }
-    return S_OK;
-}
-
 HRESULT enter_apartment( struct oletls *info, DWORD model )
 {
     HRESULT hr = S_OK;
diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec
index b64b511409..a4837bd6ff 100644
--- a/dlls/ole32/ole32.spec
+++ b/dlls/ole32/ole32.spec
@@ -66,7 +66,7 @@
 @ stub CoQueryReleaseObject
 @ stdcall CoRegisterChannelHook(ptr ptr)
 @ stdcall CoRegisterClassObject(ptr ptr long long ptr)
-@ stdcall CoRegisterInitializeSpy(ptr ptr)
+@ stdcall CoRegisterInitializeSpy(ptr ptr) combase.CoRegisterInitializeSpy
 @ stdcall CoRegisterMallocSpy(ptr) combase.CoRegisterMallocSpy
 @ stdcall CoRegisterMessageFilter(ptr ptr)
 @ stdcall CoRegisterPSClsid(ptr ptr)
@@ -77,7 +77,7 @@
 @ stdcall CoResumeClassObjects()
 @ stdcall CoRevertToSelf() combase.CoRevertToSelf
 @ stdcall CoRevokeClassObject(long)
-@ stdcall CoRevokeInitializeSpy(int64)
+@ stdcall CoRevokeInitializeSpy(int64) combase.CoRevokeInitializeSpy
 @ stdcall CoRevokeMallocSpy() combase.CoRevokeMallocSpy
 @ stdcall CoSetProxyBlanket(ptr long long ptr long long ptr long) combase.CoSetProxyBlanket
 @ stdcall CoSetState(ptr)




More information about the wine-cvs mailing list