diff options
Diffstat (limited to 'ext/com_dotnet')
24 files changed, 208 insertions, 137 deletions
diff --git a/ext/com_dotnet/com_com.c b/ext/com_dotnet/com_com.c index c9962835d1..460453455d 100644 --- a/ext/com_dotnet/com_com.c +++ b/ext/com_dotnet/com_com.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -230,7 +230,7 @@ PHP_FUNCTION(com_create_instance) werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Failed to create COM object `%s': %s", module_name, werr); - LocalFree(werr); + php_win32_error_msg_free(werr); php_com_throw_exception(res, msg); efree(msg); @@ -266,13 +266,13 @@ PHP_FUNCTION(com_create_instance) if (SUCCEEDED(ITypeLib_GetDocumentation(TL, -1, &name, NULL, NULL, NULL))) { typelib_name = php_com_olestring_to_string(name, &typelib_name_len, obj->code_page); - if (NULL != zend_ts_hash_str_add_ptr(&php_com_typelibraries, typelib_name, typelib_name_len, TL)) { + if (NULL != php_com_cache_typelib(TL, typelib_name, typelib_name_len)) { php_com_import_typelib(TL, mode, obj->code_page); /* add a reference for the hash */ ITypeLib_AddRef(TL); } - + efree(typelib_name); } else { /* try it anyway */ php_com_import_typelib(TL, mode, obj->code_page); @@ -388,7 +388,7 @@ HRESULT php_com_invoke_helper(php_com_dotnet_object *obj, DISPID id_member, case DISP_E_TYPEMISMATCH: desc = php_win32_error_to_msg(hr); spprintf(&msg, 0, "Parameter %d: %s", arg_err, desc); - LocalFree(desc); + php_win32_error_msg_free(desc); break; case DISP_E_BADPARAMCOUNT: @@ -404,7 +404,7 @@ HRESULT php_com_invoke_helper(php_com_dotnet_object *obj, DISPID id_member, default: desc = php_win32_error_to_msg(hr); spprintf(&msg, 0, "Error [0x%08x] %s", hr, desc); - LocalFree(desc); + php_win32_error_msg_free(desc); break; } @@ -484,11 +484,10 @@ int php_com_do_invoke_byref(php_com_dotnet_object *obj, zend_internal_function * hr = php_com_get_id_of_name(obj, f->function_name->val, f->function_name->len, &dispid); if (FAILED(hr)) { - char *winerr = NULL; char *msg = NULL; - winerr = php_win32_error_to_msg(hr); + char *winerr = php_win32_error_to_msg(hr); spprintf(&msg, 0, "Unable to lookup `%s': %s", f->function_name->val, winerr); - LocalFree(winerr); + php_win32_error_msg_free(winerr); php_com_throw_exception(hr, msg); efree(msg); return FAILURE; @@ -647,15 +646,14 @@ int php_com_do_invoke(php_com_dotnet_object *obj, char *name, size_t namelen, { DISPID dispid; HRESULT hr; - char *winerr = NULL; char *msg = NULL; hr = php_com_get_id_of_name(obj, name, namelen, &dispid); if (FAILED(hr)) { - winerr = php_win32_error_to_msg(hr); + char *winerr = php_win32_error_to_msg(hr); spprintf(&msg, 0, "Unable to lookup `%s': %s", name, winerr); - LocalFree(winerr); + php_win32_error_msg_free(winerr); php_com_throw_exception(hr, msg); efree(msg); return FAILURE; @@ -832,6 +830,10 @@ PHP_FUNCTION(com_load_typelib) return; } + if (!cs) { + php_error_docref(NULL, E_DEPRECATED, "Declaration of case-insensitive constants is deprecated"); + } + RETVAL_FALSE; php_com_initialize(); @@ -846,14 +848,3 @@ PHP_FUNCTION(com_load_typelib) } } /* }}} */ - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/ext/com_dotnet/com_dotnet.c b/ext/com_dotnet/com_dotnet.c index f8bdefdf21..7222615986 100644 --- a/ext/com_dotnet/com_dotnet.c +++ b/ext/com_dotnet/com_dotnet.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -205,8 +205,7 @@ PHP_FUNCTION(com_dotnet_create_instance) char buf[1024]; char *err = php_win32_error_to_msg(hr); snprintf(buf, sizeof(buf), "Failed to init .Net runtime [%s] %s", where, err); - if (err) - LocalFree(err); + php_win32_error_msg_free(err); php_com_throw_exception(hr, buf); return; } @@ -219,8 +218,7 @@ PHP_FUNCTION(com_dotnet_create_instance) char buf[1024]; char *err = php_win32_error_to_msg(hr); snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] %s", where, err); - if (err) - LocalFree(err); + php_win32_error_msg_free(err); php_com_throw_exception(hr, buf); ZVAL_NULL(object); return; @@ -232,8 +230,7 @@ PHP_FUNCTION(com_dotnet_create_instance) char buf[1024]; char *err = php_win32_error_to_msg(hr); snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] %s", where, err); - if (err) - LocalFree(err); + php_win32_error_msg_free(err); php_com_throw_exception(hr, buf); ZVAL_NULL(object); return; @@ -315,9 +312,7 @@ PHP_FUNCTION(com_dotnet_create_instance) char buf[1024]; char *err = php_win32_error_to_msg(hr); snprintf(buf, sizeof(buf), "Failed to instantiate .Net object [%s] [0x%08x] %s", where, hr, err); - if (err && err[0]) { - LocalFree(err); - } + php_win32_error_msg_free(err); php_com_throw_exception(hr, buf); return; } diff --git a/ext/com_dotnet/com_extension.c b/ext/com_dotnet/com_extension.c index 34e1f253e9..5ae14815dd 100644 --- a/ext/com_dotnet/com_extension.c +++ b/ext/com_dotnet/com_extension.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -33,8 +33,6 @@ ZEND_DECLARE_MODULE_GLOBALS(com_dotnet) static PHP_GINIT_FUNCTION(com_dotnet); -TsHashTable php_com_typelibraries; - zend_class_entry *php_com_variant_class_entry, *php_com_exception_class_entry, @@ -237,6 +235,7 @@ static PHP_INI_MH(OnTypeLibFileUpdate) modifier = php_strtok_r(NULL, "#", &strtok_buf); if (modifier != NULL) { if (!strcmp(modifier, "cis") || !strcmp(modifier, "case_insensitive")) { + php_error_docref("com.configuration", E_DEPRECATED, "Declaration of case-insensitive constants is deprecated"); mode &= ~CONST_CS; } } @@ -263,11 +262,19 @@ static PHP_INI_MH(OnTypeLibFileUpdate) return SUCCESS; } +static ZEND_INI_MH(OnAutoregisterCasesensitive) +{ + if (!zend_ini_parse_bool(new_value)) { + php_error_docref("com.configuration", E_DEPRECATED, "Declaration of case-insensitive constants is deprecated"); + } + return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); +} + PHP_INI_BEGIN() STD_PHP_INI_ENTRY("com.allow_dcom", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_dcom, zend_com_dotnet_globals, com_dotnet_globals) STD_PHP_INI_ENTRY("com.autoregister_verbose", "0", PHP_INI_ALL, OnUpdateBool, autoreg_verbose, zend_com_dotnet_globals, com_dotnet_globals) STD_PHP_INI_ENTRY("com.autoregister_typelib", "0", PHP_INI_ALL, OnUpdateBool, autoreg_on, zend_com_dotnet_globals, com_dotnet_globals) - STD_PHP_INI_ENTRY("com.autoregister_casesensitive", "1", PHP_INI_ALL, OnUpdateBool, autoreg_case_sensitive, zend_com_dotnet_globals, com_dotnet_globals) + STD_PHP_INI_ENTRY("com.autoregister_casesensitive", "1", PHP_INI_ALL, OnAutoregisterCasesensitive, autoreg_case_sensitive, zend_com_dotnet_globals, com_dotnet_globals) STD_PHP_INI_ENTRY("com.code_page", "", PHP_INI_ALL, OnUpdateLong, code_page, zend_com_dotnet_globals, com_dotnet_globals) PHP_INI_ENTRY("com.typelib_file", "", PHP_INI_SYSTEM, OnTypeLibFileUpdate) PHP_INI_END() @@ -319,8 +326,6 @@ PHP_MINIT_FUNCTION(com_dotnet) tmp->serialize = zend_class_serialize_deny; tmp->unserialize = zend_class_unserialize_deny; - zend_ts_hash_init(&php_com_typelibraries, 0, NULL, php_com_typelibrary_dtor, 1); - #if HAVE_MSCOREE_H INIT_CLASS_ENTRY(ce, "dotnet", NULL); ce.create_object = php_com_object_new; @@ -411,6 +416,9 @@ PHP_MINIT_FUNCTION(com_dotnet) COM_CONST(VT_UI8); COM_CONST(VT_I8); #endif + + PHP_MINIT(com_typeinfo)(INIT_FUNC_ARGS_PASSTHRU); + return SUCCESS; } /* }}} */ @@ -426,7 +434,8 @@ PHP_MSHUTDOWN_FUNCTION(com_dotnet) } #endif - zend_ts_hash_destroy(&php_com_typelibraries); + PHP_MSHUTDOWN(com_typeinfo)(INIT_FUNC_ARGS_PASSTHRU); + return SUCCESS; } /* }}} */ @@ -474,12 +483,3 @@ PHP_MINFO_FUNCTION(com_dotnet) DISPLAY_INI_ENTRIES(); } /* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index 4278818511..d42e7453f8 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -58,7 +58,7 @@ static zval *com_property_read(zval *object, zval *member, int type, void **cahc return rv; } -static void com_property_write(zval *object, zval *member, zval *value, void **cache_slot) +static zval *com_property_write(zval *object, zval *member, zval *value, void **cache_slot) { php_com_dotnet_object *obj; VARIANT v; @@ -76,6 +76,7 @@ static void com_property_write(zval *object, zval *member, zval *value, void **c } else { php_com_throw_exception(E_INVALIDARG, "this variant has no properties"); } + return value; } static zval *com_read_dimension(zval *object, zval *offset, int type, zval *rv) @@ -178,6 +179,11 @@ static void com_write_dimension(zval *object, zval *offset, zval *value) } } +static zval *com_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) +{ + return NULL; +} + #if 0 static void com_object_set(zval **property, zval *value) { @@ -237,6 +243,13 @@ static HashTable *com_properties_get(zval *object) return &zend_empty_array; } +static HashTable *com_get_gc(zval *object, zval **table, int *n) +{ + *table = NULL; + *n = 0; + return NULL; +} + static void function_dtor(zval *zv) { zend_internal_function *f = (zend_internal_function*)Z_PTR_P(zv); @@ -258,10 +271,10 @@ static PHP_FUNCTION(com_method_handler) INTERNAL_FUNCTION_PARAM_PASSTHRU); } -static union _zend_function *com_method_get(zend_object **object_ptr, zend_string *name, const zval *key) +static zend_function *com_method_get(zend_object **object_ptr, zend_string *name, const zval *key) { zend_internal_function f, *fptr = NULL; - union _zend_function *func; + zend_function *func; DISPID dummy; php_com_dotnet_object *obj = (php_com_dotnet_object*)*object_ptr; @@ -393,7 +406,7 @@ static int com_call_method(zend_string *method, zend_object *object, INTERNAL_FU return ret; } -static union _zend_function *com_constructor_get(zend_object *object) +static zend_function *com_constructor_get(zend_object *object) { php_com_dotnet_object *obj = (php_com_dotnet_object *) object; static zend_internal_function c, d, v; @@ -406,7 +419,7 @@ static union _zend_function *com_constructor_get(zend_object *object) f.num_args = 0; \ f.fn_flags = 0; \ f.handler = ZEND_FN(fn); \ - return (union _zend_function*)&f; + return (zend_function*)&f; switch (obj->ce->name->val[0]) { #if HAVE_MSCOREE_H @@ -550,7 +563,7 @@ zend_object_handlers php_com_object_handlers = { com_property_write, com_read_dimension, com_write_dimension, - NULL, + com_get_property_ptr_ptr, NULL, /* com_object_get, */ NULL, /* com_object_set, */ com_property_exists, @@ -567,7 +580,7 @@ zend_object_handlers php_com_object_handlers = { com_object_count, NULL, /* get_debug_info */ NULL, /* get_closure */ - NULL, /* get_gc */ + com_get_gc, /* get_gc */ }; void php_com_object_enable_event_sink(php_com_dotnet_object *obj, int enable) @@ -619,6 +632,8 @@ void php_com_object_free_storage(zend_object *object) zend_hash_destroy(obj->id_of_name_cache); FREE_HASHTABLE(obj->id_of_name_cache); } + + zend_object_std_dtor(object); } zend_object* php_com_object_clone(zval *object) diff --git a/ext/com_dotnet/com_iterator.c b/ext/com_dotnet/com_iterator.c index 5b731777e0..c3206497cf 100644 --- a/ext/com_dotnet/com_iterator.c +++ b/ext/com_dotnet/com_iterator.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -100,18 +100,18 @@ static void com_iter_move_forwards(zend_object_iterator *iter) I->key++; } else { /* indicate that there are no more items */ - I->key = (ulong)-1; + I->key = (zend_ulong)-1; return; } } else { /* safe array */ if (I->key >= (ULONG) I->sa_max) { - I->key = (ulong)-1; + I->key = (zend_ulong)-1; return; } I->key++; if (php_com_safearray_get_elem(&I->safe_array, &I->v, (LONG)I->key) == 0) { - I->key = (ulong)-1; + I->key = (zend_ulong)-1; return; } } @@ -193,7 +193,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b php_com_zval_from_variant(&ptr, &I->v, I->code_page); ZVAL_COPY_VALUE(&I->zdata, &ptr); } else { - I->key = (ulong)-1; + I->key = (zend_ulong)-1; } } else { @@ -228,7 +228,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b ZVAL_COPY_VALUE(&I->zdata, &ptr); } else { /* indicate that there are no more items */ - I->key = (ulong)-1; + I->key = (zend_ulong)-1; } } diff --git a/ext/com_dotnet/com_misc.c b/ext/com_dotnet/com_misc.c index 6488b3c8b4..13a94033e6 100644 --- a/ext/com_dotnet/com_misc.c +++ b/ext/com_dotnet/com_misc.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -40,7 +40,7 @@ void php_com_throw_exception(HRESULT code, char *message) zend_throw_exception(php_com_exception_class_entry, message, (zend_long)code); #endif if (free_msg) { - LocalFree(message); + php_win32_error_msg_free(message); } } diff --git a/ext/com_dotnet/com_olechar.c b/ext/com_dotnet/com_olechar.c index 1cd1017a02..ea9cf1154c 100644 --- a/ext/com_dotnet/com_olechar.c +++ b/ext/com_dotnet/com_olechar.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -63,7 +63,7 @@ PHP_COM_DOTNET_API OLECHAR *php_com_string_to_olestring(char *string, size_t str php_error_docref(NULL, E_WARNING, "Could not convert string to unicode: `%s'", msg); - LocalFree(msg); + php_win32_error_msg_free(msg); } return olestring; @@ -94,7 +94,7 @@ PHP_COM_DOTNET_API char *php_com_olestring_to_string(OLECHAR *olestring, size_t php_error_docref(NULL, E_WARNING, "Could not convert string from unicode: `%s'", msg); - LocalFree(msg); + php_win32_error_msg_free(msg); } if (string_len) { diff --git a/ext/com_dotnet/com_persist.c b/ext/com_dotnet/com_persist.c index 743a441f70..3283e59df7 100644 --- a/ext/com_dotnet/com_persist.c +++ b/ext/com_dotnet/com_persist.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -118,13 +118,13 @@ static HRESULT STDMETHODCALLTYPE stm_read(IStream *This, void *pv, ULONG cb, ULO static HRESULT STDMETHODCALLTYPE stm_write(IStream *This, void const *pv, ULONG cb, ULONG *pcbWritten) { - ULONG nwrote; + ssize_t nwrote; FETCH_STM(); - nwrote = (ULONG)php_stream_write(stm->stream, pv, cb); + nwrote = php_stream_write(stm->stream, pv, cb); if (pcbWritten) { - *pcbWritten = nwrote > 0 ? nwrote : 0; + *pcbWritten = nwrote > 0 ? (ULONG)nwrote : 0; } if (nwrote > 0) { return S_OK; @@ -756,12 +756,3 @@ int php_com_persist_minit(INIT_FUNC_ARGS) return SUCCESS; } - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/ext/com_dotnet/com_saproxy.c b/ext/com_dotnet/com_saproxy.c index bde1986992..5f43c9fe25 100644 --- a/ext/com_dotnet/com_saproxy.c +++ b/ext/com_dotnet/com_saproxy.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -69,7 +69,7 @@ static inline void clone_indices(php_com_saproxy *dest, php_com_saproxy *src, in } } -static zval *saproxy_property_read(zval *object, zval *member, int type, void **cahce_slot, zval *rv) +static zval *saproxy_property_read(zval *object, zval *member, int type, void **cache_slot, zval *rv) { ZVAL_NULL(rv); @@ -78,9 +78,10 @@ static zval *saproxy_property_read(zval *object, zval *member, int type, void ** return rv; } -static void saproxy_property_write(zval *object, zval *member, zval *value, void **cache_slot) +static zval *saproxy_property_write(zval *object, zval *member, zval *value, void **cache_slot) { php_com_throw_exception(E_INVALIDARG, "safearray has no properties"); + return value; } static zval *saproxy_read_dimension(zval *object, zval *offset, int type, zval *rv) @@ -314,7 +315,7 @@ static HashTable *saproxy_properties_get(zval *object) return NULL; } -static union _zend_function *saproxy_method_get(zend_object **object, zend_string *name, const zval *key) +static zend_function *saproxy_method_get(zend_object **object, zend_string *name, const zval *key) { /* no methods */ return NULL; @@ -325,7 +326,7 @@ static int saproxy_call_method(zend_string *method, zend_object *object, INTERNA return FAILURE; } -static union _zend_function *saproxy_constructor_get(zend_object *object) +static zend_function *saproxy_constructor_get(zend_object *object) { /* user cannot instantiate */ return NULL; @@ -374,6 +375,8 @@ static void saproxy_free_storage(zend_object *object) //??? } //??? } + zend_object_std_dtor(object); + zval_ptr_dtor(proxy->zobj); efree(proxy->indices); } @@ -547,7 +550,8 @@ zend_object_iterator *php_com_saproxy_iter_get(zend_class_entry *ce, zval *objec Z_PTR(I->iter.data) = I; I->proxy = proxy; - ZVAL_COPY(&I->proxy_obj, object); + Z_ADDREF_P(object); + ZVAL_OBJ(&I->proxy_obj, Z_OBJ_P(object)); I->indices = safe_emalloc(proxy->dimensions + 1, sizeof(LONG), 0); for (i = 0; i < proxy->dimensions; i++) { diff --git a/ext/com_dotnet/com_typeinfo.c b/ext/com_dotnet/com_typeinfo.c index 794922d938..4ee73cf41f 100644 --- a/ext/com_dotnet/com_typeinfo.c +++ b/ext/com_dotnet/com_typeinfo.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -27,6 +27,33 @@ #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" +static HashTable php_com_typelibraries; + +#ifdef ZTS +static MUTEX_T php_com_typelibraries_mutex; +#endif + +PHP_MINIT_FUNCTION(com_typeinfo) +{ + zend_hash_init(&php_com_typelibraries, 0, NULL, php_com_typelibrary_dtor, 1); + +#ifdef ZTS + php_com_typelibraries_mutex = tsrm_mutex_alloc(); +#endif + + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(com_typeinfo) +{ + zend_hash_destroy(&php_com_typelibraries); + +#ifdef ZTS + tsrm_mutex_free(php_com_typelibraries_mutex); +#endif + + return SUCCESS; +} /* The search string can be either: * a) a file name @@ -184,23 +211,15 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa } const_name = php_com_olestring_to_string(bstr_ids, &len, codepage); - c.name = zend_string_init(const_name, len, mode & CONST_PERSISTENT); - // TODO: avoid reallocation??? - efree(const_name); - if(c.name == NULL) { - ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc); - continue; - } -//??? c.name_len++; /* include NUL */ SysFreeString(bstr_ids); /* sanity check for the case where the constant is already defined */ php_com_zval_from_variant(&value, pVarDesc->lpvarValue, codepage); - if ((exists = zend_get_constant(c.name)) != NULL) { + if ((exists = zend_get_constant_str(const_name, len)) != NULL) { if (COMG(autoreg_verbose) && !compare_function(&results, &value, exists)) { - php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", ZSTR_VAL(c.name)); + php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", const_name); } - zend_string_release_ex(c.name, mode & CONST_PERSISTENT); + efree(const_name); ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc); continue; } @@ -209,6 +228,8 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa if (Z_TYPE(value) == IS_LONG) { ZEND_CONSTANT_SET_FLAGS(&c, mode, 0); ZVAL_LONG(&c.value, Z_LVAL(value)); + c.name = zend_string_init(const_name, len, mode & CONST_PERSISTENT); + efree(const_name); zend_register_constant(&c); } ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc); @@ -226,35 +247,58 @@ void php_com_typelibrary_dtor(zval *pDest) ITypeLib_Release(Lib); } +ITypeLib *php_com_cache_typelib(ITypeLib* TL, char *cache_key, zend_long cache_key_len) { + ITypeLib* result; +#ifdef ZTS + tsrm_mutex_lock(php_com_typelibraries_mutex); +#endif + + result = zend_hash_str_add_ptr(&php_com_typelibraries, cache_key, cache_key_len, TL); + +#ifdef ZTS + tsrm_mutex_unlock(php_com_typelibraries_mutex); +#endif + + return result; +} + PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(char *search_string, int codepage, int *cached) { ITypeLib *TL; char *name_dup; - size_t l; + zend_string *key = zend_string_init(search_string, strlen(search_string), 1); - l = strlen(search_string); +#ifdef ZTS + tsrm_mutex_lock(php_com_typelibraries_mutex); +#endif - if ((TL = zend_ts_hash_str_find_ptr(&php_com_typelibraries, search_string, l)) != NULL) { + if ((TL = zend_hash_find_ptr(&php_com_typelibraries, key)) != NULL) { *cached = 1; /* add a reference for the caller */ ITypeLib_AddRef(TL); - return TL; + + goto php_com_load_typelib_via_cache_return; } *cached = 0; - name_dup = estrndup(search_string, l); + name_dup = estrndup(ZSTR_VAL(key), ZSTR_LEN(key)); TL = php_com_load_typelib(name_dup, codepage); efree(name_dup); if (TL) { - if (NULL != zend_ts_hash_str_update_ptr(&php_com_typelibraries, - search_string, l, TL)) { + if (NULL != zend_hash_add_ptr(&php_com_typelibraries, key, TL)) { /* add a reference for the hash table */ ITypeLib_AddRef(TL); } } +php_com_load_typelib_via_cache_return: +#ifdef ZTS + tsrm_mutex_unlock(php_com_typelibraries_mutex); +#endif + zend_string_release(key); + return TL; } diff --git a/ext/com_dotnet/com_variant.c b/ext/com_dotnet/com_variant.c index 901b0a866a..dc4e42ddc5 100644 --- a/ext/com_dotnet/com_variant.c +++ b/ext/com_dotnet/com_variant.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -479,7 +479,7 @@ PHP_FUNCTION(com_variant_create_instance) werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Variant type conversion failed: %s", werr); - LocalFree(werr); + php_win32_error_msg_free(werr); php_com_throw_exception(res, msg); efree(msg); @@ -1067,7 +1067,7 @@ PHP_FUNCTION(variant_set_type) werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Variant type conversion failed: %s", werr); - LocalFree(werr); + php_win32_error_msg_free(werr); php_com_throw_exception(res, msg); efree(msg); @@ -1101,7 +1101,7 @@ PHP_FUNCTION(variant_cast) werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Variant type conversion failed: %s", werr); - LocalFree(werr); + php_win32_error_msg_free(werr); php_com_throw_exception(res, msg); efree(msg); diff --git a/ext/com_dotnet/com_wrapper.c b/ext/com_dotnet/com_wrapper.c index 437c7c814f..78d8912a90 100644 --- a/ext/com_dotnet/com_wrapper.c +++ b/ext/com_dotnet/com_wrapper.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -286,7 +286,7 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex( } else if (wFlags & DISPATCH_METHOD) { zend_try { retval = &rv; - if (SUCCESS == call_user_function(EG(function_table), &disp->object, name, + if (SUCCESS == call_user_function(NULL, &disp->object, name, retval, pdp->cArgs, params)) { ret = S_OK; trace("function called ok\n"); @@ -397,7 +397,7 @@ static HRESULT STDMETHODCALLTYPE disp_getnextdispid( /* [in] */ DISPID id, /* [out] */ DISPID *pid) { - ulong next = id+1; + zend_ulong next = id+1; FETCH_DISP("GetNextDispID"); while(!zend_hash_index_exists(disp->dispid_to_name, next)) diff --git a/ext/com_dotnet/php_com_dotnet.h b/ext/com_dotnet/php_com_dotnet.h index a2fbca5bf8..50894158f5 100644 --- a/ext/com_dotnet/php_com_dotnet.h +++ b/ext/com_dotnet/php_com_dotnet.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -55,12 +55,3 @@ extern ZEND_DECLARE_MODULE_GLOBALS(com_dotnet); #define COMG(v) ZEND_MODULE_GLOBALS_ACCESSOR(com_dotnet, v) #endif /* PHP_COM_DOTNET_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/ext/com_dotnet/php_com_dotnet_internal.h b/ext/com_dotnet/php_com_dotnet_internal.h index 663c0694fe..8481138699 100644 --- a/ext/com_dotnet/php_com_dotnet_internal.h +++ b/ext/com_dotnet/php_com_dotnet_internal.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -27,8 +27,6 @@ #include <dispex.h> #include "win32/winutil.h" -#include "zend_ts_hash.h" - typedef struct _php_com_dotnet_object { zend_object zo; @@ -70,7 +68,6 @@ static inline int php_com_is_valid_object(zval *zv) } while(0) /* com_extension.c */ -TsHashTable php_com_typelibraries; zend_class_entry *php_com_variant_class_entry, *php_com_exception_class_entry, *php_com_saproxy_class_entry; /* com_handlers.c */ @@ -177,6 +174,9 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, void php_com_typelibrary_dtor(zval *pDest); ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj, char *dispname, int sink); int php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int printdef, GUID *guid, int codepage); +ITypeLib *php_com_cache_typelib(ITypeLib* TL, char *cache_key, zend_long cache_key_len); +PHP_MINIT_FUNCTION(com_typeinfo); +PHP_MSHUTDOWN_FUNCTION(com_typeinfo); /* com_iterator.c */ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int by_ref); diff --git a/ext/com_dotnet/tests/27974.phpt b/ext/com_dotnet/tests/27974.phpt index bdce5cbb74..960a630304 100644 --- a/ext/com_dotnet/tests/27974.phpt +++ b/ext/com_dotnet/tests/27974.phpt @@ -1,7 +1,7 @@ --TEST-- COM: mapping a safearray --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; ?> --FILE-- <?php diff --git a/ext/com_dotnet/tests/bug39606.phpt b/ext/com_dotnet/tests/bug39606.phpt index 27479f9cfb..314e9ce8a2 100644 --- a/ext/com_dotnet/tests/bug39606.phpt +++ b/ext/com_dotnet/tests/bug39606.phpt @@ -1,7 +1,7 @@ --TEST-- COM: Loading typelib corrupts memory --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; ?> --FILE-- <?php diff --git a/ext/com_dotnet/tests/bug66431_0.phpt b/ext/com_dotnet/tests/bug66431_0.phpt index daac328538..e022c18e12 100644 --- a/ext/com_dotnet/tests/bug66431_0.phpt +++ b/ext/com_dotnet/tests/bug66431_0.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("com_dotnet")){ echo "skip COM/.Net support not present"; <?php $text= "Xin chào cộng đồng PHP"; -$fpath = str_replace("/", "\\", dirname(__FILE__) . "/bug66431.txt"); +$fpath = str_replace("/", "\\", __DIR__ . "/bug66431.txt"); $fso = new COM("Scripting.FileSystemObject"); $fh = $fso->OpenTextFile($fpath, 2, true); @@ -31,7 +31,7 @@ if (!$result) { --CLEAN-- <?php -$fpath = str_replace("/", "\\", dirname(__FILE__) . "/bug66431.txt"); +$fpath = str_replace("/", "\\", __DIR__ . "/bug66431.txt"); if (file_exists($fpath)) { unlink($fpath); diff --git a/ext/com_dotnet/tests/bug66431_1.phpt b/ext/com_dotnet/tests/bug66431_1.phpt index 11b76a1546..e68e411125 100644 --- a/ext/com_dotnet/tests/bug66431_1.phpt +++ b/ext/com_dotnet/tests/bug66431_1.phpt @@ -15,7 +15,7 @@ try { <?php $text= "Xin chào cộng đồng PHP"; -$fpath = str_replace("/", "\\", dirname(__FILE__) . "/bug66431.docx"); +$fpath = str_replace("/", "\\", __DIR__ . "/bug66431.docx"); com_load_typelib('Word.Application'); @@ -49,7 +49,7 @@ if (!$result) { --CLEAN-- <?php -$fpath = str_replace("/", "\\", dirname(__FILE__) . "/bug66431.docx"); +$fpath = str_replace("/", "\\", __DIR__ . "/bug66431.docx"); if (file_exists($fpath)) { unlink($fpath); diff --git a/ext/com_dotnet/tests/bug72498.phpt b/ext/com_dotnet/tests/bug72498.phpt index c5aad0cccc..e43251bd3c 100644 --- a/ext/com_dotnet/tests/bug72498.phpt +++ b/ext/com_dotnet/tests/bug72498.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #72498 variant_date_from_timestamp null dereference --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; ?> --FILE-- diff --git a/ext/com_dotnet/tests/bug73679.phpt b/ext/com_dotnet/tests/bug73679.phpt index b1ccdc1650..47de9b10c7 100644 --- a/ext/com_dotnet/tests/bug73679.phpt +++ b/ext/com_dotnet/tests/bug73679.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #73679 DOTNET read access violation using invalid codepage --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only"); ?> diff --git a/ext/com_dotnet/tests/bug78650.phpt b/ext/com_dotnet/tests/bug78650.phpt new file mode 100644 index 0000000000..c362de95bb --- /dev/null +++ b/ext/com_dotnet/tests/bug78650.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #78650 (new COM Crash) +--SKIPIF-- +<?php +if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available'); +?> +--FILE-- +<?php +$fname = __DIR__ . '/bug78650/foo/bar'; +mkdir($fname, 0777, true); + +$fso = new COM("Scripting.FileSystemObject"); +$folder = $fso->GetFolder($fname); +$folder->ParentFolder->Name = 'baz'; + +print('OK'); +?> +--EXPECT-- +OK +--CLEAN-- +<?php +rmdir(__DIR__ . '/bug78650/baz/bar'); +rmdir(__DIR__ . '/bug78650/foo/bar'); +rmdir(__DIR__ . '/bug78650/baz'); +rmdir(__DIR__ . '/bug78650/foo'); +rmdir(__DIR__ . '/bug78650'); +?> diff --git a/ext/com_dotnet/tests/bug79247.phpt b/ext/com_dotnet/tests/bug79247.phpt new file mode 100644 index 0000000000..55e24b1796 --- /dev/null +++ b/ext/com_dotnet/tests/bug79247.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #79247 (Garbage collecting variant objects segfaults) +--SKIPIF-- +<?php +if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available'); +?> +--FILE-- +<?php +$keep = new variant(null); +var_dump(gc_collect_cycles()); +?> +--EXPECT-- +int(0) diff --git a/ext/com_dotnet/tests/variants.phpt b/ext/com_dotnet/tests/variants.phpt index 38b36f5c34..a99e896680 100644 --- a/ext/com_dotnet/tests/variants.phpt +++ b/ext/com_dotnet/tests/variants.phpt @@ -1,7 +1,7 @@ --TEST-- COM: General variant tests --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; if (4 != PHP_INT_SIZE) print "skip x86 only"; ?> --FILE-- diff --git a/ext/com_dotnet/tests/variants_x64.phpt b/ext/com_dotnet/tests/variants_x64.phpt index 8816fc6a2b..e9e7c23b97 100644 --- a/ext/com_dotnet/tests/variants_x64.phpt +++ b/ext/com_dotnet/tests/variants_x64.phpt @@ -1,7 +1,7 @@ --TEST-- COM: General variant tests --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; if (8 != PHP_INT_SIZE) print "skip x64 only"; if ((string) variant_cat(new VARIANT(false), new VARIANT(0.5)) != 'False0.5') |