summaryrefslogtreecommitdiff
path: root/ext/com_dotnet
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-08-14 17:36:20 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-09-01 16:35:56 +0200
commitf7fbc6333ff9a91ffb2f636790657c927b4e3c55 (patch)
tree0c3ca3db071c9c0052fd43c633279fd0cd9d9127 /ext/com_dotnet
parent1c56b40a5ce45f598d718cf34e8a265d44f1d9d4 (diff)
downloadphp-git-f7fbc6333ff9a91ffb2f636790657c927b4e3c55.tar.gz
Add more precise type info for stubs
Closes GH-6005
Diffstat (limited to 'ext/com_dotnet')
-rw-r--r--ext/com_dotnet/com_com.c61
-rw-r--r--ext/com_dotnet/com_extension.stub.php6
-rw-r--r--ext/com_dotnet/com_extension_arginfo.h6
3 files changed, 35 insertions, 38 deletions
diff --git a/ext/com_dotnet/com_com.c b/ext/com_dotnet/com_com.c
index 54a1533266..ef8d99567f 100644
--- a/ext/com_dotnet/com_com.c
+++ b/ext/com_dotnet/com_com.c
@@ -29,11 +29,12 @@
PHP_METHOD(com, __construct)
{
zval *object = getThis();
- zval *server_params = NULL;
+ zend_string *server_name = NULL;
+ HashTable *server_params = NULL;
php_com_dotnet_object *obj;
char *module_name, *typelib_name = NULL;
size_t module_name_len = 0, typelib_name_len = 0;
- zend_string *server_name = NULL, *user_name = NULL, *password = NULL, *domain_name = NULL;
+ zend_string *user_name = NULL, *password = NULL, *domain_name = NULL;
OLECHAR *moniker;
CLSID clsid;
CLSCTX ctx = CLSCTX_SERVER;
@@ -50,16 +51,13 @@ PHP_METHOD(com, __construct)
zend_long cp = GetACP();
const struct php_win32_cp *cp_it;
- if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS(), "s|S!ls",
- &module_name, &module_name_len, &server_name,
- &cp, &typelib_name, &typelib_name_len) &&
- FAILURE == zend_parse_parameters(
- ZEND_NUM_ARGS(), "sa|ls",
- &module_name, &module_name_len, &server_params, &cp,
- &typelib_name, &typelib_name_len)) {
- RETURN_THROWS();
- }
+ ZEND_PARSE_PARAMETERS_START(1, 4)
+ Z_PARAM_STRING(module_name, module_name_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(server_name, server_params)
+ Z_PARAM_LONG(cp)
+ Z_PARAM_STRING(typelib_name, typelib_name_len)
+ ZEND_PARSE_PARAMETERS_END();
php_com_initialize();
obj = CDNO_FETCH(object);
@@ -78,28 +76,28 @@ PHP_METHOD(com, __construct)
/* decode the data from the array */
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
+ if (NULL != (tmp = zend_hash_str_find(server_params,
"Server", sizeof("Server")-1))) {
server_name = zval_get_string(tmp);
ctx = CLSCTX_REMOTE_SERVER;
}
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
+ if (NULL != (tmp = zend_hash_str_find(server_params,
"Username", sizeof("Username")-1))) {
user_name = zval_get_string(tmp);
}
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
+ if (NULL != (tmp = zend_hash_str_find(server_params,
"Password", sizeof("Password")-1))) {
password = zval_get_string(tmp);
}
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
+ if (NULL != (tmp = zend_hash_str_find(server_params,
"Domain", sizeof("Domain")-1))) {
domain_name = zval_get_string(tmp);
}
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
+ if (NULL != (tmp = zend_hash_str_find(server_params,
"Flags", sizeof("Flags")-1))) {
ctx = (CLSCTX)zval_get_long(tmp);
}
@@ -686,34 +684,35 @@ PHP_FUNCTION(com_create_guid)
/* {{{ Connect events from a COM object to a PHP object */
PHP_FUNCTION(com_event_sink)
{
- zval *object, *sinkobject, *sink=NULL;
+ zval *object, *sinkobject;
+ zend_string *sink_str = NULL;
+ HashTable *sink_ht = NULL;
char *dispname = NULL, *typelibname = NULL;
php_com_dotnet_object *obj;
ITypeInfo *typeinfo = NULL;
- RETVAL_FALSE;
+ ZEND_PARSE_PARAMETERS_START(2, 3)
+ Z_PARAM_OBJECT_OF_CLASS(object, php_com_variant_class_entry)
+ Z_PARAM_OBJECT(sinkobject)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(sink_str, sink_ht)
+ ZEND_PARSE_PARAMETERS_END();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "Oo|z/",
- &object, php_com_variant_class_entry, &sinkobject, &sink)) {
- RETURN_THROWS();
- }
+ RETVAL_FALSE;
php_com_initialize();
obj = CDNO_FETCH(object);
- if (sink && Z_TYPE_P(sink) == IS_ARRAY) {
+ if (sink_ht) {
/* 0 => typelibname, 1 => dispname */
zval *tmp;
- if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
+ if ((tmp = zend_hash_index_find(sink_ht, 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
typelibname = Z_STRVAL_P(tmp);
- if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
+ if ((tmp = zend_hash_index_find(sink_ht, 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
dispname = Z_STRVAL_P(tmp);
- } else if (sink != NULL) {
- if (!try_convert_to_string(sink)) {
- RETURN_THROWS();
- }
- dispname = Z_STRVAL_P(sink);
+ } else if (sink_str) {
+ dispname = ZSTR_VAL(sink_str);
}
typeinfo = php_com_locate_typeinfo(typelibname, obj, dispname, 1);
diff --git a/ext/com_dotnet/com_extension.stub.php b/ext/com_dotnet/com_extension.stub.php
index 8323b0796b..9b1edf9d38 100644
--- a/ext/com_dotnet/com_extension.stub.php
+++ b/ext/com_dotnet/com_extension.stub.php
@@ -58,8 +58,7 @@ function com_get_active_object(string $progid, ?int $code_page = null): variant
function com_create_guid(): string|false {}
-/** @param array|string|null $sinkinterface */
-function com_event_sink(variant $comobject, object $sinkobject, $sinkinterface = UNKNOWN): bool {}
+function com_event_sink(variant $comobject, object $sinkobject, array|string|null $sinkinterface = null): bool {}
/** @param com|dotnet|variant|string $comobject */
function com_print_typeinfo($comobject, ?string $dispinterface = null, bool $wantsink = false): bool {}
@@ -75,8 +74,7 @@ class variant
class com
{
- /** @param string|array|null $server_name */
- public function __construct(string $module_name, $server_name = UNKNOWN, int $codepage = CP_ACP, string $typelib = "") {}
+ public function __construct(string $module_name, array|string|null $server_name = null, int $codepage = CP_ACP, string $typelib = "") {}
}
#if HAVE_MSCOREE_H
diff --git a/ext/com_dotnet/com_extension_arginfo.h b/ext/com_dotnet/com_extension_arginfo.h
index aec8108d88..3e583c3211 100644
--- a/ext/com_dotnet/com_extension_arginfo.h
+++ b/ext/com_dotnet/com_extension_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 48167f9ee38966beaf550cd0a7b07d873575b48e */
+ * Stub hash: f78e9db58131f9d67021eaea4c3d4be75cafe2ac */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_set, 0, 2, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
@@ -92,7 +92,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_com_event_sink, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, comobject, variant, 0)
ZEND_ARG_TYPE_INFO(0, sinkobject, IS_OBJECT, 0)
- ZEND_ARG_INFO(0, sinkinterface)
+ ZEND_ARG_TYPE_MASK(0, sinkinterface, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_com_print_typeinfo, 0, 1, _IS_BOOL, 0)
@@ -118,7 +118,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_com___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, module_name, IS_STRING, 0)
- ZEND_ARG_INFO(0, server_name)
+ ZEND_ARG_TYPE_MASK(0, server_name, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, codepage, IS_LONG, 0, "CP_ACP")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, typelib, IS_STRING, 0, "\"\"")
ZEND_END_ARG_INFO()