Skip to content

Commit

Permalink
Refactor disp_invokeex() to avoid superfluous recheck (GH-17001)
Browse files Browse the repository at this point in the history
Since we already know the method is callable, we can just call it
directly.
  • Loading branch information
cmb69 authored Dec 1, 2024
1 parent 514cd20 commit 1d2c544
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions ext/com_dotnet/com_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,31 +256,26 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex(

/* TODO: if PHP raises an exception here, we should catch it
* and expose it as a COM exception */

zend_fcall_info_cache fcc;
if (wFlags & DISPATCH_PROPERTYPUT) {
zend_update_property(Z_OBJCE(disp->object), Z_OBJ(disp->object), Z_STRVAL_P(name), Z_STRLEN_P(name), &params[0]);
ret = S_OK;
} else if (wFlags & DISPATCH_METHOD && zend_is_callable_ex(name, Z_OBJ(disp->object), 0, NULL, NULL, NULL)) {
} else if (wFlags & DISPATCH_METHOD && zend_is_callable_ex(name, Z_OBJ(disp->object), 0, NULL, &fcc, NULL)) {
zend_try {
retval = &rv;
if (SUCCESS == call_user_function(NULL, &disp->object, name,
retval, pdp->cArgs, params)) {
ret = S_OK;
trace("function called ok\n");

/* Copy any modified values to callers copy of variant*/
for (i = 0; i < pdp->cArgs; i++) {
php_com_dotnet_object *obj = CDNO_FETCH(&params[i]);
VARIANT *srcvar = &obj->v;
VARIANT *dstvar = &pdp->rgvarg[ pdp->cArgs - 1 - i];
if ((V_VT(dstvar) & VT_BYREF) && obj->modified ) {
trace("percolate modified value for arg %u VT=%08x\n", i, V_VT(dstvar));
php_com_copy_variant(dstvar, srcvar);
}
zend_call_known_fcc(&fcc, retval, pdp->cArgs, params, NULL);
ret = S_OK;
trace("function called ok\n");

/* Copy any modified values to callers copy of variant*/
for (i = 0; i < pdp->cArgs; i++) {
php_com_dotnet_object *obj = CDNO_FETCH(&params[i]);
VARIANT *srcvar = &obj->v;
VARIANT *dstvar = &pdp->rgvarg[ pdp->cArgs - 1 - i];
if ((V_VT(dstvar) & VT_BYREF) && obj->modified ) {
trace("percolate modified value for arg %u VT=%08x\n", i, V_VT(dstvar));
php_com_copy_variant(dstvar, srcvar);
}
} else {
trace("failed to call func\n");
ret = DISP_E_EXCEPTION;
}
} zend_catch {
trace("something blew up\n");
Expand Down

0 comments on commit 1d2c544

Please sign in to comment.