From 7e99e20a8968613f33bf112c0c191764d5cdeece Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 20 May 2024 21:14:29 +0200 Subject: [PATCH 1/3] Get rid of le_istream --- ext/com_dotnet/com_persist.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/ext/com_dotnet/com_persist.c b/ext/com_dotnet/com_persist.c index 56c613e54d051..109e9d677c262 100644 --- a/ext/com_dotnet/com_persist.c +++ b/ext/com_dotnet/com_persist.c @@ -38,18 +38,10 @@ typedef struct { DWORD engine_thread; LONG refcount; php_stream *stream; - zend_resource *res; } php_istream; -static int le_istream; static void istream_destructor(php_istream *stm); -static void istream_dtor(zend_resource *rsrc) -{ - php_istream *stm = (php_istream *)rsrc->ptr; - istream_destructor(stm); -} - #define FETCH_STM() \ php_istream *stm = (php_istream*)This; \ if (GetCurrentThreadId() != stm->engine_thread) \ @@ -93,8 +85,7 @@ static ULONG STDMETHODCALLTYPE stm_release(IStream *This) ret = InterlockedDecrement(&stm->refcount); if (ret == 0) { /* destroy it */ - if (stm->res) - zend_list_delete(stm->res); + istream_destructor(stm); } return ret; } @@ -271,7 +262,6 @@ PHP_COM_DOTNET_API IStream *php_com_wrapper_export_stream(php_stream *stream) stm->stream = stream; GC_ADDREF(stream->res); - stm->res = zend_register_resource(stm, le_istream); return (IStream*)stm; } @@ -722,7 +712,4 @@ void php_com_persist_minit(INIT_FUNC_ARGS) helper_ce = register_class_COMPersistHelper(); helper_ce->create_object = helper_new; helper_ce->default_object_handlers = &helper_handlers; - - le_istream = zend_register_list_destructors_ex(istream_dtor, - NULL, "com_dotnet_istream_wrapper", module_number); } From 6e62284f3e2dd3805a68293d14cdbf1ef7c177a8 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 10 Aug 2024 20:25:39 +0200 Subject: [PATCH 2/3] Get rid of le_dispatch --- ext/com_dotnet/com_extension.c | 1 - ext/com_dotnet/com_wrapper.c | 36 +----------------------- ext/com_dotnet/php_com_dotnet_internal.h | 1 - 3 files changed, 1 insertion(+), 37 deletions(-) diff --git a/ext/com_dotnet/com_extension.c b/ext/com_dotnet/com_extension.c index bd9f981be13ec..e6e14a45a9c75 100644 --- a/ext/com_dotnet/com_extension.c +++ b/ext/com_dotnet/com_extension.c @@ -175,7 +175,6 @@ PHP_MINIT_FUNCTION(com_dotnet) { zend_class_entry *tmp; - php_com_wrapper_minit(INIT_FUNC_ARGS_PASSTHRU); php_com_persist_minit(INIT_FUNC_ARGS_PASSTHRU); php_com_exception_class_entry = register_class_com_exception(zend_ce_exception); diff --git a/ext/com_dotnet/com_wrapper.c b/ext/com_dotnet/com_wrapper.c index 621bce4202bbb..3b19d89cf705d 100644 --- a/ext/com_dotnet/com_wrapper.c +++ b/ext/com_dotnet/com_wrapper.c @@ -42,27 +42,10 @@ typedef struct { HashTable *name_to_dispid; /* keep track of name -> dispid mappings */ GUID sinkid; /* iid that we "implement" for event sinking */ - - zend_resource *res; } php_dispatchex; -static int le_dispatch; - static void disp_destructor(php_dispatchex *disp); -static void dispatch_dtor(zend_resource *rsrc) -{ - php_dispatchex *disp = (php_dispatchex *)rsrc->ptr; - disp_destructor(disp); -} - -int php_com_wrapper_minit(INIT_FUNC_ARGS) -{ - le_dispatch = zend_register_list_destructors_ex(dispatch_dtor, - NULL, "com_dotnet_dispatch_wrapper", module_number); - return le_dispatch; -} - /* {{{ trace */ static inline void trace(char *fmt, ...) @@ -129,8 +112,7 @@ static ULONG STDMETHODCALLTYPE disp_release(IDispatchEx *This) trace("-- refcount now %d\n", ret); if (ret == 0) { /* destroy it */ - if (disp->res) - zend_list_delete(disp->res); + disp_destructor(disp); } return ret; } @@ -525,7 +507,6 @@ static void generate_dispids(php_dispatchex *disp) static php_dispatchex *disp_constructor(zval *object) { php_dispatchex *disp = (php_dispatchex*)CoTaskMemAlloc(sizeof(php_dispatchex)); - zval *tmp; trace("constructing a COM wrapper for PHP object %p (%s)\n", object, Z_OBJCE_P(object)->name); @@ -545,26 +526,11 @@ static php_dispatchex *disp_constructor(zval *object) ZVAL_UNDEF(&disp->object); } - tmp = zend_list_insert(disp, le_dispatch); - disp->res = Z_RES_P(tmp); - return disp; } static void disp_destructor(php_dispatchex *disp) { - /* Object store not available during request shutdown */ - if (COMG(rshutdown_started)) { - trace("destroying COM wrapper for PHP object %p (name:unknown)\n", Z_OBJ(disp->object)); - } else { - trace("destroying COM wrapper for PHP object %p (name:%s)\n", Z_OBJ(disp->object), Z_OBJCE(disp->object)->name->val); - } - - disp->res = NULL; - - if (disp->refcount > 0) - CoDisconnectObject((IUnknown*)disp, 0); - zend_hash_destroy(disp->dispid_to_name); zend_hash_destroy(disp->name_to_dispid); FREE_HASHTABLE(disp->dispid_to_name); diff --git a/ext/com_dotnet/php_com_dotnet_internal.h b/ext/com_dotnet/php_com_dotnet_internal.h index 66b4f859377a6..6735afba94289 100644 --- a/ext/com_dotnet/php_com_dotnet_internal.h +++ b/ext/com_dotnet/php_com_dotnet_internal.h @@ -103,7 +103,6 @@ zend_result php_com_do_invoke_byref(php_com_dotnet_object *obj, zend_internal_fu WORD flags, VARIANT *v, int nargs, zval *args); /* com_wrapper.c */ -int php_com_wrapper_minit(INIT_FUNC_ARGS); PHP_COM_DOTNET_API IDispatch *php_com_wrapper_export_as_sink(zval *val, GUID *sinkid, HashTable *id_to_name); PHP_COM_DOTNET_API IDispatch *php_com_wrapper_export(zval *val); From 904dc63889ab057e33c9fe3e426963d92c6f2e35 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 10 Aug 2024 20:25:44 +0200 Subject: [PATCH 3/3] Update TODOs in com_dotnet --- ext/com_dotnet/com_persist.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/com_dotnet/com_persist.c b/ext/com_dotnet/com_persist.c index 109e9d677c262..a4544cd88549a 100644 --- a/ext/com_dotnet/com_persist.c +++ b/ext/com_dotnet/com_persist.c @@ -16,8 +16,11 @@ /* Infrastructure for working with persistent COM objects. * Implements: IStream* wrapper for PHP streams. - * TODO: Magic __wakeup and __sleep handlers for serialization - * (can wait till 5.1) */ + * TODO: + * - Magic __wakeup and __sleep handlers for serialization. + * - Track the stream and dispatch instances in a global list to make sure + * they are destroyed when a fatal error occurs. + */ #ifdef HAVE_CONFIG_H #include