Permalink
Browse files

COM initialization/deinitialization are done only if necessary

  • Loading branch information...
1 parent cb4b75f commit c06f9e1efe5375abcbb507876e04e893885e4ade Dmitry Stogov committed Nov 17, 2006
Showing with 34 additions and 2 deletions.
  1. +1 −0 NEWS
  2. +7 −0 ext/com_dotnet/com_com.c
  3. +1 −0 ext/com_dotnet/com_dotnet.c
  4. +1 −0 ext/com_dotnet/com_handlers.c
  5. +1 −0 ext/com_dotnet/com_variant.c
  6. +18 −2 main/main.c
  7. +2 −0 main/php.h
  8. +3 −0 main/php_globals.h
View
1 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
View
@@ -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) {
@@ -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)) {
@@ -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));
@@ -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;
}
View
@@ -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)
View
@@ -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 */
View
@@ -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
};

0 comments on commit c06f9e1

Please sign in to comment.