cvs: php-src /ext/com_dotnet com_wrapper.c

From: Date: Thu, 29 Jul 2004 06:19:27 +0000
Subject: cvs: php-src /ext/com_dotnet com_wrapper.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-28053@lists.php.net to get a copy of this message
wez Thu Jul 29 02:19:27 2004 EDT Modified files: /php-src/ext/com_dotnet com_wrapper.c Log: Use the correct lengths when building the name -> dispid mapping http://cvs.php.net/diff.php/php-src/ext/com_dotnet/com_wrapper.c?r1=1.5&r2=1.6&ty=u Index: php-src/ext/com_dotnet/com_wrapper.c diff -u php-src/ext/com_dotnet/com_wrapper.c:1.5 php-src/ext/com_dotnet/com_wrapper.c:1.6 --- php-src/ext/com_dotnet/com_wrapper.c:1.5 Mon Jul 26 23:44:40 2004 +++ php-src/ext/com_dotnet/com_wrapper.c Thu Jul 29 02:19:27 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: com_wrapper.c,v 1.5 2004/07/27 03:44:40 wez Exp $ */ +/* $Id: com_wrapper.c,v 1.6 2004/07/29 06:19:27 wez Exp $ */ /* This module exports a PHP object as a COM object by wrapping it * using IDispatchEx */ @@ -235,8 +235,11 @@ name = php_com_olestring_to_string(bstrName, &namelen, COMG(code_page) TSRMLS_CC); + trace("Looking for %s, namelen=%d in %p\n", name, namelen, disp->name_to_dispid); + /* Lookup the name in the hash */ if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == SUCCESS) { + trace("found it\n"); *pid = Z_LVAL_PP(tmp); ret = S_OK; } @@ -268,22 +271,24 @@ if (SUCCESS == zend_hash_index_find(disp->dispid_to_name, id, (void**)&name)) { /* TODO: add support for overloaded objects */ - trace("-- Invoke: %d %20s flags=%08x args=%d\n", id, Z_STRVAL_PP(name), wFlags, pdp->cArgs); + trace("-- Invoke: %d %20s [%d] flags=%08x args=%d\n", id, Z_STRVAL_PP(name), Z_STRLEN_PP(name), wFlags, pdp->cArgs); /* convert args into zvals. * Args are in reverse order */ - params = (zval ***)safe_emalloc(sizeof(zval **), pdp->cArgs, 0); - for (i = 0; i < pdp->cArgs; i++) { - VARIANT *arg; - zval *zarg; - - arg = &pdp->rgvarg[ pdp->cArgs - 1 - i]; - - trace("alloc zval for arg %d VT=%08x\n", i, V_VT(arg)); - - ALLOC_INIT_ZVAL(zarg); - php_com_wrap_variant(zarg, arg, COMG(code_page) TSRMLS_CC); - params[i] = &zarg; + if (pdp->cArgs) { + params = (zval ***)safe_emalloc(sizeof(zval **), pdp->cArgs, 0); + for (i = 0; i < pdp->cArgs; i++) { + VARIANT *arg; + zval *zarg; + + arg = &pdp->rgvarg[ pdp->cArgs - 1 - i]; + + trace("alloc zval for arg %d VT=%08x\n", i, V_VT(arg)); + + ALLOC_INIT_ZVAL(zarg); + php_com_wrap_variant(zarg, arg, COMG(code_page) TSRMLS_CC); + params[i] = &zarg; + } } trace("arguments processed, prepare to do some work\n"); @@ -300,10 +305,13 @@ if (SUCCESS == call_user_function_ex(EG(function_table), &disp->object, *name, &retval, pdp->cArgs, params, 1, NULL TSRMLS_CC)) { ret = S_OK; + trace("function called ok\n"); } else { + trace("failed to call func\n"); ret = DISP_E_EXCEPTION; } } zend_catch { + trace("something blew up\n"); ret = DISP_E_EXCEPTION; } zend_end_try(); } else { @@ -311,9 +319,11 @@ } /* release arguments */ - for (i = 0; i < pdp->cArgs; i++) - zval_ptr_dtor(params[i]); - efree(params); + if (params) { + for (i = 0; i < pdp->cArgs; i++) + zval_ptr_dtor(params[i]); + efree(params); + } /* return value */ if (retval) { @@ -473,23 +483,23 @@ if (keytype == HASH_KEY_IS_LONG) { sprintf(namebuf, "%d", pid); name = namebuf; - namelen = strlen(namebuf); + namelen = strlen(namebuf)+1; } zend_hash_move_forward_ex(Z_OBJPROP_P(disp->object), &pos); /* Find the existing id */ - if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == SUCCESS) + if (zend_hash_find(disp->name_to_dispid, name, namelen, (void**)&tmp) == SUCCESS) continue; /* add the mappings */ MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, name, namelen, 1); + ZVAL_STRINGL(tmp, name, namelen-1, 1); zend_hash_index_update(disp->dispid_to_name, pid, (void*)&tmp, sizeof(zval *), NULL); MAKE_STD_ZVAL(tmp); ZVAL_LONG(tmp, pid); - zend_hash_update(disp->name_to_dispid, name, namelen+1, (void*)&tmp, sizeof(zval *), NULL); + zend_hash_update(disp->name_to_dispid, name, namelen, (void*)&tmp, sizeof(zval *), NULL); } } @@ -504,23 +514,23 @@ if (keytype == HASH_KEY_IS_LONG) { sprintf(namebuf, "%d", pid); name = namebuf; - namelen = strlen(namebuf); + namelen = strlen(namebuf) + 1; } zend_hash_move_forward_ex(Z_OBJPROP_P(disp->object), &pos); /* Find the existing id */ - if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == SUCCESS) + if (zend_hash_find(disp->name_to_dispid, name, namelen, (void**)&tmp) == SUCCESS) continue; /* add the mappings */ MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, name, namelen, 1); + ZVAL_STRINGL(tmp, name, namelen-1, 1); zend_hash_index_update(disp->dispid_to_name, pid, (void*)&tmp, sizeof(zval *), NULL); MAKE_STD_ZVAL(tmp); ZVAL_LONG(tmp, pid); - zend_hash_update(disp->name_to_dispid, name, namelen+1, (void*)&tmp, sizeof(zval *), NULL); + zend_hash_update(disp->name_to_dispid, name, namelen, (void*)&tmp, sizeof(zval *), NULL); } } }

« previous php.cvs (#28053) next »