Skip to content

Add more precise type info for stubs #6005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,9 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
#define Z_PARAM_PATH_STR(dest) \
Z_PARAM_PATH_STR_EX(dest, 0, 0)

#define Z_PARAM_PATH_STR_OR_NULL(dest) \
Z_PARAM_PATH_STR_EX(dest, 1, 0)

/* old "r" */
#define Z_PARAM_RESOURCE_EX2(dest, check_null, deref, separate) \
Z_PARAM_PROLOGUE(deref, separate); \
Expand Down
10 changes: 3 additions & 7 deletions Zend/zend_weakrefs.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ final class WeakMap implements ArrayAccess, Countable, IteratorAggregate
{
/**
* @param object $object
* @return mixed
*/
public function offsetGet($object) {}
public function offsetGet($object): mixed {}

/**
* @param object $object
* @param mixed $value
*/
public function offsetSet($object, $value): void {}
/** @param object $object */
public function offsetSet($object, mixed $value): void {}

/** @param object $object */
public function offsetExists($object): bool {}
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_weakrefs_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 8a90ffe614346c65d312bc5061fd304056b5640a */
* Stub hash: 0569bc7e10a1ec15a3a9eec481da27b647eb1d1d */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_WeakReference___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand All @@ -11,13 +11,13 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakReference_get, 0, 0, IS_OBJECT, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_WeakMap_offsetGet, 0, 0, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakMap_offsetGet, 0, 1, IS_MIXED, 0)
ZEND_ARG_INFO(0, object)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakMap_offsetSet, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, object)
ZEND_ARG_INFO(0, value)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakMap_offsetExists, 0, 1, _IS_BOOL, 0)
Expand Down
61 changes: 30 additions & 31 deletions ext/com_dotnet/com_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions ext/com_dotnet/com_extension.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -75,8 +74,7 @@ public function __construct(mixed $value = null, int $type = VT_EMPTY, int $code

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
Expand Down
6 changes: 3 additions & 3 deletions ext/com_dotnet/com_extension_arginfo.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
11 changes: 0 additions & 11 deletions ext/ctype/ctype.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,24 @@

/** @generate-function-entries */

/** @param string|int $text */
function ctype_alnum(mixed $text): bool {}

/** @param string|int $text */
function ctype_alpha(mixed $text): bool {}

/** @param string|int $text */
function ctype_cntrl(mixed $text): bool {}

/** @param string|int $text */
function ctype_digit(mixed $text): bool {}

/** @param string|int $text */
function ctype_lower(mixed $text): bool {}

/** @param string|int $text */
function ctype_graph(mixed $text): bool {}

/** @param string|int $text */
function ctype_print(mixed $text): bool {}

/** @param string|int $text */
function ctype_punct(mixed $text): bool {}

/** @param string|int $text */
function ctype_space(mixed $text): bool {}

/** @param string|int $text */
function ctype_upper(mixed $text): bool {}

/** @param string|int $text */
function ctype_xdigit(mixed $text): bool {}
2 changes: 1 addition & 1 deletion ext/ctype/ctype_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 5263184b90f82d53c6da4388c79b76a8c17977e9 */
* Stub hash: aa287af25fe33a05d15d85b92b0edcfae00284a2 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ctype_alnum, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_MIXED, 0)
Expand Down
10 changes: 3 additions & 7 deletions ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,7 @@ static void zend_ffi_tags_cleanup(zend_ffi_dcl *dcl) /* {{{ */
ZEND_METHOD(FFI, new) /* {{{ */
{
zend_string *type_def = NULL;
zval *ztype = NULL;
zend_object *type_obj = NULL;
zend_ffi_type *type, *type_ptr;
zend_ffi_cdata *cdata;
void *ptr;
Expand All @@ -3601,11 +3601,7 @@ ZEND_METHOD(FFI, new) /* {{{ */

ZEND_FFI_VALIDATE_API_RESTRICTION();
ZEND_PARSE_PARAMETERS_START(1, 3)
if (Z_TYPE_P(EX_VAR_NUM(0)) == IS_STRING) {
Z_PARAM_STR(type_def)
} else {
Z_PARAM_OBJECT_OF_CLASS(ztype, zend_ffi_ctype_ce)
}
Z_PARAM_STR_OR_OBJ_OF_CLASS(type_def, type_obj, zend_ffi_ctype_ce)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(owned)
Z_PARAM_BOOL(persistent)
Expand Down Expand Up @@ -3670,7 +3666,7 @@ ZEND_METHOD(FFI, new) /* {{{ */

type_ptr = dcl.type;
} else {
zend_ffi_ctype *ctype = (zend_ffi_ctype*)Z_OBJ_P(ztype);
zend_ffi_ctype *ctype = (zend_ffi_ctype*) type_obj;

type_ptr = type = ctype->type;
if (ZEND_FFI_TYPE_IS_OWNED(type)) {
Expand Down
3 changes: 1 addition & 2 deletions ext/ffi/ffi.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public static function load(string $filename): ?FFI {}

public static function scope(string $scope_name): ?FFI {}

/** @param FFI\CType|string $type */
public static function new($type, bool $owned = true, bool $persistent = false): ?FFI\CData {}
public static function new(FFI\CType|string $type, bool $owned = true, bool $persistent = false): ?FFI\CData {}

/** @prefer-ref $ptr */
public static function free(FFI\CData $ptr): void {}
Expand Down
4 changes: 2 additions & 2 deletions ext/ffi/ffi_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a486305cd865e2798f7d9916760a3ec3c6f114b0 */
* Stub hash: c5ad08a2c62988e2b50468c1c5b941b5c28f23b5 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")
Expand All @@ -15,7 +15,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_scope, 0, 1, FFI, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_new, 0, 1, FFI\\CData, 1)
ZEND_ARG_INFO(0, type)
ZEND_ARG_OBJ_TYPE_MASK(0, type, FFI\\CType, MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, owned, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, persistent, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()
Expand Down
3 changes: 1 addition & 2 deletions ext/intl/calendar/calendar.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ public function before(IntlCalendar $calendar) {}
public function clear(?int $field = null) {}

/**
* @param DateTime|string $dateTime
* @return IntlCalendar|null
* @alias intlcal_from_date_time
*/
public static function fromDateTime($dateTime, ?string $locale = null) {}
public static function fromDateTime(DateTime|string $dateTime, ?string $locale = null) {}

/**
* @return int
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/calendar/calendar_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 3facb6bdce18efae3d6b9594d1fcddfb220dd54d */
* Stub hash: 0ac7a1d4e011518fc956fb05624b45b061fa9710 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar_clear, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar_fromDateTime, 0, 0, 1)
ZEND_ARG_INFO(0, dateTime)
ZEND_ARG_OBJ_TYPE_MASK(0, dateTime, DateTime, MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()

Expand Down
Loading