summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2006-11-17 11:40:52 +0000
committerDmitry Stogov <dmitry@php.net>2006-11-17 11:40:52 +0000
commitc06f9e1efe5375abcbb507876e04e893885e4ade (patch)
tree1fec799294f4e5db9b88dcbaa46f62aa6a6886a4
parentcb4b75f155950d57979c5c69c37e78d46f60d3d7 (diff)
downloadphp-git-c06f9e1efe5375abcbb507876e04e893885e4ade.tar.gz
COM initialization/deinitialization are done only if necessary
-rw-r--r--NEWS1
-rw-r--r--ext/com_dotnet/com_com.c7
-rw-r--r--ext/com_dotnet/com_dotnet.c1
-rw-r--r--ext/com_dotnet/com_handlers.c1
-rw-r--r--ext/com_dotnet/com_variant.c1
-rw-r--r--main/main.c20
-rw-r--r--main/php.h2
-rw-r--r--main/php_globals.h3
8 files changed, 34 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 0fedebc7e6..9ba2a4faac 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ PHP NEWS
The new directive cgi.check_shebang_line can be used to ommiting checnk
for "#! /usr/bin/php" line. (Dmitry).
- Windows related optimizations (Dmitry, Stas)
+ . COM initialization/deinitialization are done only if necessary
. removed unnecessary checks for ISREG file and corresponding stat() calls
. opendir() is reimplemented using GetFistFile/GetNextFile those are faster
then _findfirst/_findnext
diff --git a/ext/com_dotnet/com_com.c b/ext/com_dotnet/com_com.c
index 706dca6fe1..2f17455400 100644
--- a/ext/com_dotnet/com_com.c
+++ b/ext/com_dotnet/com_com.c
@@ -53,6 +53,7 @@ PHP_FUNCTION(com_create_instance)
&authid, EOAC_NONE
};
+ php_com_initialize(TSRMLS_C);
obj = CDNO_FETCH(object);
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
@@ -294,6 +295,7 @@ PHP_FUNCTION(com_get_active_object)
HRESULT res;
OLECHAR *module = NULL;
+ php_com_initialize(TSRMLS_C);
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
&module_name, &module_name_len, &code_page)) {
php_com_throw_exception(E_INVALIDARG, "Invalid arguments!" TSRMLS_CC);
@@ -660,6 +662,7 @@ PHP_FUNCTION(com_create_guid)
ZEND_WRONG_PARAM_COUNT();
}
+ php_com_initialize(TSRMLS_C);
if (CoCreateGuid(&retval) == S_OK && StringFromCLSID(&retval, &guid_string) == S_OK) {
Z_TYPE_P(return_value) = IS_STRING;
Z_STRVAL_P(return_value) = php_com_olestring_to_string(guid_string, &Z_STRLEN_P(return_value), CP_ACP, 0);
@@ -688,6 +691,7 @@ PHP_FUNCTION(com_event_sink)
RETURN_FALSE;
}
+ php_com_initialize(TSRMLS_C);
obj = CDNO_FETCH(object);
if (sink && Z_TYPE_P(sink) == IS_ARRAY) {
@@ -748,6 +752,7 @@ PHP_FUNCTION(com_print_typeinfo)
RETURN_FALSE;
}
+ php_com_initialize(TSRMLS_C);
if (Z_TYPE_P(arg1) == IS_OBJECT) {
CDNO_FETCH_VERIFY(obj, arg1);
} else {
@@ -778,6 +783,7 @@ PHP_FUNCTION(com_message_pump)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timeoutms) == FAILURE)
RETURN_FALSE;
+ php_com_initialize(TSRMLS_C);
result = MsgWaitForMultipleObjects(0, NULL, FALSE, timeoutms, QS_ALLINPUT);
if (result == WAIT_OBJECT_0) {
@@ -811,6 +817,7 @@ PHP_FUNCTION(com_load_typelib)
RETVAL_FALSE;
+ php_com_initialize(TSRMLS_C);
pTL = php_com_load_typelib_via_cache(name, codepage, &cached TSRMLS_CC);
if (pTL) {
if (cached) {
diff --git a/ext/com_dotnet/com_dotnet.c b/ext/com_dotnet/com_dotnet.c
index 4edeff5ac0..b1d63a418b 100644
--- a/ext/com_dotnet/com_dotnet.c
+++ b/ext/com_dotnet/com_dotnet.c
@@ -193,6 +193,7 @@ PHP_FUNCTION(com_dotnet_create_instance)
char *where = "";
IUnknown *unk = NULL;
+ php_com_initialize(TSRMLS_C);
if (COMG(dotnet_runtime_stuff) == NULL) {
hr = dotnet_init(&where TSRMLS_CC);
if (FAILED(hr)) {
diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c
index 12628098d6..a422b32041 100644
--- a/ext/com_dotnet/com_handlers.c
+++ b/ext/com_dotnet/com_handlers.c
@@ -664,6 +664,7 @@ zend_object_value php_com_object_new(zend_class_entry *ce TSRMLS_DC)
php_com_dotnet_object *obj;
zend_object_value retval;
+ php_com_initialize(TSRMLS_C);
obj = emalloc(sizeof(*obj));
memset(obj, 0, sizeof(*obj));
diff --git a/ext/com_dotnet/com_variant.c b/ext/com_dotnet/com_variant.c
index d45c094a70..a904a08ac0 100644
--- a/ext/com_dotnet/com_variant.c
+++ b/ext/com_dotnet/com_variant.c
@@ -280,6 +280,7 @@ PHP_FUNCTION(com_variant_create_instance)
return;
}
+ php_com_initialize(TSRMLS_C);
if (ZEND_NUM_ARGS() == 3) {
obj->code_page = codepage;
}
diff --git a/main/main.c b/main/main.c
index 87a0f95802..be300e43d2 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1073,7 +1073,7 @@ int php_request_startup(TSRMLS_D)
int retval = SUCCESS;
#ifdef PHP_WIN32
- CoInitialize(NULL);
+ PG(com_initialized) = 0;
#endif
#if PHP_SIGCHILD
@@ -1325,12 +1325,28 @@ void php_request_shutdown(void *dummy)
} zend_end_try();
#ifdef PHP_WIN32
- CoUninitialize();
+ if (PG(com_initialized)) {
+ CoUninitialize();
+ PG(com_initialized) = 0;
+ }
#endif
}
/* }}} */
+/* {{{ php_com_initialize
+ */
+PHPAPI void php_com_initialize(TSRMLS_D)
+{
+#ifdef PHP_WIN32
+ if (!PG(com_initialized)) {
+ CoInitialize(NULL);
+ PG(com_initialized) = 1;
+ }
+#endif
+}
+/* }}} */
+
/* {{{ php_body_write_wrapper
*/
static int php_body_write_wrapper(const char *str, uint str_length)
diff --git a/main/php.h b/main/php.h
index 6ff3bfe7da..a3825a4659 100644
--- a/main/php.h
+++ b/main/php.h
@@ -329,6 +329,8 @@ PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userda
PHPAPI int cfg_get_long(char *varname, long *result);
PHPAPI int cfg_get_double(char *varname, double *result);
PHPAPI int cfg_get_string(char *varname, char **result);
+
+PHPAPI void php_com_initialize(TSRMLS_D);
END_EXTERN_C()
/* PHP-named Zend macro wrappers */
diff --git a/main/php_globals.h b/main/php_globals.h
index d20ebb1ef7..c17a1e947b 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -152,6 +152,9 @@ struct _php_core_globals {
char *disable_functions;
char *disable_classes;
zend_bool allow_url_include;
+#ifdef PHP_WIN32
+ zend_bool com_initialized;
+#endif
};