Promote warnings to Error in COM extension

Closes GH-6141
This commit is contained in:
George Peter Banyard 2020-09-16 02:03:46 +02:00
parent 213b666781
commit e55f0c796c
10 changed files with 40 additions and 29 deletions

View File

@ -746,7 +746,8 @@ PHP_FUNCTION(com_event_sink)
/* {{{ Print out a PHP class definition for a dispatchable interface */
PHP_FUNCTION(com_print_typeinfo)
{
zval *arg1;
zend_object *object_zpp;
zend_string *typelib_name_zpp = NULL;
char *ifacename = NULL;
char *typelibname = NULL;
size_t ifacelen;
@ -754,17 +755,18 @@ PHP_FUNCTION(com_print_typeinfo)
php_com_dotnet_object *obj = NULL;
ITypeInfo *typeinfo;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "z/|s!b", &arg1, &ifacename,
&ifacelen, &wantsink)) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_OBJ_OF_CLASS_OR_STR(object_zpp, php_com_variant_class_entry, typelib_name_zpp)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(ifacename, ifacelen)
Z_PARAM_BOOL(wantsink)
ZEND_PARSE_PARAMETERS_END();
php_com_initialize();
if (Z_TYPE_P(arg1) == IS_OBJECT) {
CDNO_FETCH_VERIFY(obj, arg1);
if (object_zpp) {
obj = (php_com_dotnet_object*)object_zpp;
} else {
convert_to_string(arg1);
typelibname = Z_STRVAL_P(arg1);
typelibname = ZSTR_VAL(typelib_name_zpp);
}
typeinfo = php_com_locate_typeinfo(typelibname, obj, ifacename, wantsink ? 1 : 0);
@ -772,9 +774,9 @@ PHP_FUNCTION(com_print_typeinfo)
php_com_process_typeinfo(typeinfo, NULL, 1, NULL, obj ? obj->code_page : COMG(code_page));
ITypeInfo_Release(typeinfo);
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Unable to find typeinfo using the parameters supplied");
}
php_error_docref(NULL, E_WARNING, "Unable to find typeinfo using the parameters supplied");
RETURN_FALSE;
}
/* }}} */

View File

@ -46,7 +46,7 @@ function variant_cmp(mixed $left, mixed $right, int $lcid = LOCALE_SYSTEM_DEFAUL
function variant_date_to_timestamp(variant $variant): ?int {}
function variant_date_from_timestamp(int $timestamp): variant|false {}
function variant_date_from_timestamp(int $timestamp): variant {}
function variant_get_type(variant $variant): int {}

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: f78e9db58131f9d67021eaea4c3d4be75cafe2ac */
* Stub hash: 637bee9d71fb0d566ce38004eec8bc6f75656837 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_set, 0, 2, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
@ -63,7 +63,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_date_to_timestamp, 0, 1,
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_variant_date_from_timestamp, 0, 1, variant, MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_variant_date_from_timestamp, 0, 1, variant, 0)
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
ZEND_END_ARG_INFO()

View File

@ -203,18 +203,19 @@ static int com_property_exists(zend_object *object, zend_string *member, int che
static int com_dimension_exists(zend_object *object, zval *member, int check_empty)
{
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
/* TODO Add support */
zend_throw_error(NULL, "Cannot check dimension on a COM object");
return 0;
}
static void com_property_delete(zend_object *object, zend_string *member, void **cache_slot)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete properties from a COM object");
}
static void com_dimension_delete(zend_object *object, zval *offset)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete dimension from a COM object");
}
static HashTable *com_properties_get(zend_object *object)

View File

@ -149,6 +149,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
obj = CDNO_FETCH(object);
if (V_VT(&obj->v) != VT_DISPATCH && !V_ISARRAY(&obj->v)) {
/* TODO Promote to TypeError? */
php_error_docref(NULL, E_WARNING, "Variant is not an object or array VT=%d", V_VT(&obj->v));
return NULL;
}
@ -172,6 +173,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
dims = SafeArrayGetDim(V_ARRAY(&obj->v));
if (dims != 1) {
/* TODO Promote to ValueError? */
php_error_docref(NULL, E_WARNING,
"Can only handle single dimension variant arrays (this array has %d)", dims);
goto fail;

View File

@ -105,6 +105,7 @@ PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest,
dims = SafeArrayGetDim(V_ARRAY(array));
if (dims != 1) {
/* TODO Promote to ValueError? */
php_error_docref(NULL, E_WARNING,
"Can only handle single dimension variant arrays (this array has %d)", dims);
return 0;

View File

@ -288,18 +288,19 @@ static int saproxy_property_exists(zend_object *object, zend_string *member, int
static int saproxy_dimension_exists(zend_object *object, zval *member, int check_empty)
{
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
/* TODO Add support */
zend_throw_error(NULL, "Cannot check dimension on a COM object");
return 0;
}
static void saproxy_property_delete(zend_object *object, zend_string *member, void **cache_slot)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete properties from a COM object");
}
static void saproxy_dimension_delete(zend_object *object, zval *offset)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete dimension from a COM object");
}
static HashTable *saproxy_properties_get(zend_object *object)

View File

@ -633,7 +633,7 @@ int php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int pri
ret = 1;
} else {
zend_error(E_WARNING, "That's not a dispatchable interface!! type kind = %08x", attr->typekind);
zend_throw_error(NULL, "Type kind must be dispatchable, %08x given", attr->typekind);
}
ITypeInfo_ReleaseTypeAttr(typeinfo, attr);

View File

@ -964,8 +964,8 @@ PHP_FUNCTION(variant_date_from_timestamp)
}
if (timestamp < 0) {
php_error_docref(NULL, E_WARNING, "Timestamp value must be a positive value.");
RETURN_FALSE;
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}
VariantInit(&res);
@ -975,8 +975,8 @@ PHP_FUNCTION(variant_date_from_timestamp)
/* Invalid after 23:59:59, December 31, 3000, UTC */
if (!tmv) {
php_error_docref(NULL, E_WARNING, "Invalid timestamp " ZEND_LONG_FMT, timestamp);
RETURN_FALSE;
zend_argument_value_error(1, "must not go past 23:59:59, December 31, 3000, UTC");
RETURN_THROWS();
}
memset(&systime, 0, sizeof(systime));

View File

@ -8,8 +8,12 @@ if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present";
<?php
$v1 = PHP_INT_MAX;
var_dump(variant_date_from_timestamp($v1));
try {
var_dump(variant_date_from_timestamp($v1));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
Warning: variant_date_from_timestamp(): Invalid timestamp %d in %sbug72498.php on line %d
bool(false)
--EXPECT--
variant_date_from_timestamp(): Argument #1 ($timestamp) must not go past 23:59:59, December 31, 3000, UTC