Skip to content

No ext/com-dotnet resources #14282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ext/com_dotnet/com_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 6 additions & 16 deletions ext/com_dotnet/com_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <config.h>
Expand All @@ -38,18 +41,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) \
Expand Down Expand Up @@ -93,8 +88,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;
}
Expand Down Expand Up @@ -271,7 +265,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;
}
Expand Down Expand Up @@ -722,7 +715,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);
}
36 changes: 1 addition & 35 deletions ext/com_dotnet/com_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion ext/com_dotnet/php_com_dotnet_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading