Skip to content

Commit e55f0c7

Browse files
committed
Promote warnings to Error in COM extension
Closes GH-6141
1 parent 213b666 commit e55f0c7

10 files changed

+40
-29
lines changed

ext/com_dotnet/com_com.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -746,35 +746,37 @@ PHP_FUNCTION(com_event_sink)
746746
/* {{{ Print out a PHP class definition for a dispatchable interface */
747747
PHP_FUNCTION(com_print_typeinfo)
748748
{
749-
zval *arg1;
749+
zend_object *object_zpp;
750+
zend_string *typelib_name_zpp = NULL;
750751
char *ifacename = NULL;
751752
char *typelibname = NULL;
752753
size_t ifacelen;
753754
zend_bool wantsink = 0;
754755
php_com_dotnet_object *obj = NULL;
755756
ITypeInfo *typeinfo;
756757

757-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "z/|s!b", &arg1, &ifacename,
758-
&ifacelen, &wantsink)) {
759-
RETURN_THROWS();
760-
}
758+
ZEND_PARSE_PARAMETERS_START(1, 3)
759+
Z_PARAM_OBJ_OF_CLASS_OR_STR(object_zpp, php_com_variant_class_entry, typelib_name_zpp)
760+
Z_PARAM_OPTIONAL
761+
Z_PARAM_STRING_OR_NULL(ifacename, ifacelen)
762+
Z_PARAM_BOOL(wantsink)
763+
ZEND_PARSE_PARAMETERS_END();
761764

762765
php_com_initialize();
763-
if (Z_TYPE_P(arg1) == IS_OBJECT) {
764-
CDNO_FETCH_VERIFY(obj, arg1);
766+
if (object_zpp) {
767+
obj = (php_com_dotnet_object*)object_zpp;
765768
} else {
766-
convert_to_string(arg1);
767-
typelibname = Z_STRVAL_P(arg1);
769+
typelibname = ZSTR_VAL(typelib_name_zpp);
768770
}
769771

770772
typeinfo = php_com_locate_typeinfo(typelibname, obj, ifacename, wantsink ? 1 : 0);
771773
if (typeinfo) {
772774
php_com_process_typeinfo(typeinfo, NULL, 1, NULL, obj ? obj->code_page : COMG(code_page));
773775
ITypeInfo_Release(typeinfo);
774776
RETURN_TRUE;
775-
} else {
776-
zend_error(E_WARNING, "Unable to find typeinfo using the parameters supplied");
777777
}
778+
779+
php_error_docref(NULL, E_WARNING, "Unable to find typeinfo using the parameters supplied");
778780
RETURN_FALSE;
779781
}
780782
/* }}} */

ext/com_dotnet/com_extension.stub.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function variant_cmp(mixed $left, mixed $right, int $lcid = LOCALE_SYSTEM_DEFAUL
4646

4747
function variant_date_to_timestamp(variant $variant): ?int {}
4848

49-
function variant_date_from_timestamp(int $timestamp): variant|false {}
49+
function variant_date_from_timestamp(int $timestamp): variant {}
5050

5151
function variant_get_type(variant $variant): int {}
5252

ext/com_dotnet/com_extension_arginfo.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: f78e9db58131f9d67021eaea4c3d4be75cafe2ac */
2+
* Stub hash: 637bee9d71fb0d566ce38004eec8bc6f75656837 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_set, 0, 2, IS_VOID, 0)
55
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,
6363
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
6464
ZEND_END_ARG_INFO()
6565

66-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_variant_date_from_timestamp, 0, 1, variant, MAY_BE_FALSE)
66+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_variant_date_from_timestamp, 0, 1, variant, 0)
6767
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
6868
ZEND_END_ARG_INFO()
6969

ext/com_dotnet/com_handlers.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,19 @@ static int com_property_exists(zend_object *object, zend_string *member, int che
203203

204204
static int com_dimension_exists(zend_object *object, zval *member, int check_empty)
205205
{
206-
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
206+
/* TODO Add support */
207+
zend_throw_error(NULL, "Cannot check dimension on a COM object");
207208
return 0;
208209
}
209210

210211
static void com_property_delete(zend_object *object, zend_string *member, void **cache_slot)
211212
{
212-
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
213+
zend_throw_error(NULL, "Cannot delete properties from a COM object");
213214
}
214215

215216
static void com_dimension_delete(zend_object *object, zval *offset)
216217
{
217-
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
218+
zend_throw_error(NULL, "Cannot delete dimension from a COM object");
218219
}
219220

220221
static HashTable *com_properties_get(zend_object *object)

ext/com_dotnet/com_iterator.c

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
149149
obj = CDNO_FETCH(object);
150150

151151
if (V_VT(&obj->v) != VT_DISPATCH && !V_ISARRAY(&obj->v)) {
152+
/* TODO Promote to TypeError? */
152153
php_error_docref(NULL, E_WARNING, "Variant is not an object or array VT=%d", V_VT(&obj->v));
153154
return NULL;
154155
}
@@ -172,6 +173,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
172173
dims = SafeArrayGetDim(V_ARRAY(&obj->v));
173174

174175
if (dims != 1) {
176+
/* TODO Promote to ValueError? */
175177
php_error_docref(NULL, E_WARNING,
176178
"Can only handle single dimension variant arrays (this array has %d)", dims);
177179
goto fail;

ext/com_dotnet/com_misc.c

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest,
105105
dims = SafeArrayGetDim(V_ARRAY(array));
106106

107107
if (dims != 1) {
108+
/* TODO Promote to ValueError? */
108109
php_error_docref(NULL, E_WARNING,
109110
"Can only handle single dimension variant arrays (this array has %d)", dims);
110111
return 0;

ext/com_dotnet/com_saproxy.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,19 @@ static int saproxy_property_exists(zend_object *object, zend_string *member, int
288288

289289
static int saproxy_dimension_exists(zend_object *object, zval *member, int check_empty)
290290
{
291-
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
291+
/* TODO Add support */
292+
zend_throw_error(NULL, "Cannot check dimension on a COM object");
292293
return 0;
293294
}
294295

295296
static void saproxy_property_delete(zend_object *object, zend_string *member, void **cache_slot)
296297
{
297-
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
298+
zend_throw_error(NULL, "Cannot delete properties from a COM object");
298299
}
299300

300301
static void saproxy_dimension_delete(zend_object *object, zval *offset)
301302
{
302-
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
303+
zend_throw_error(NULL, "Cannot delete dimension from a COM object");
303304
}
304305

305306
static HashTable *saproxy_properties_get(zend_object *object)

ext/com_dotnet/com_typeinfo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ int php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int pri
633633

634634
ret = 1;
635635
} else {
636-
zend_error(E_WARNING, "That's not a dispatchable interface!! type kind = %08x", attr->typekind);
636+
zend_throw_error(NULL, "Type kind must be dispatchable, %08x given", attr->typekind);
637637
}
638638

639639
ITypeInfo_ReleaseTypeAttr(typeinfo, attr);

ext/com_dotnet/com_variant.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,8 @@ PHP_FUNCTION(variant_date_from_timestamp)
964964
}
965965

966966
if (timestamp < 0) {
967-
php_error_docref(NULL, E_WARNING, "Timestamp value must be a positive value.");
968-
RETURN_FALSE;
967+
zend_argument_value_error(1, "must be greater than or equal to 0");
968+
RETURN_THROWS();
969969
}
970970

971971
VariantInit(&res);
@@ -975,8 +975,8 @@ PHP_FUNCTION(variant_date_from_timestamp)
975975

976976
/* Invalid after 23:59:59, December 31, 3000, UTC */
977977
if (!tmv) {
978-
php_error_docref(NULL, E_WARNING, "Invalid timestamp " ZEND_LONG_FMT, timestamp);
979-
RETURN_FALSE;
978+
zend_argument_value_error(1, "must not go past 23:59:59, December 31, 3000, UTC");
979+
RETURN_THROWS();
980980
}
981981

982982
memset(&systime, 0, sizeof(systime));

ext/com_dotnet/tests/bug72498.phpt

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present";
88
<?php
99

1010
$v1 = PHP_INT_MAX;
11-
var_dump(variant_date_from_timestamp($v1));
11+
12+
try {
13+
var_dump(variant_date_from_timestamp($v1));
14+
} catch (\ValueError $e) {
15+
echo $e->getMessage() . \PHP_EOL;
16+
}
1217
?>
13-
--EXPECTF--
14-
Warning: variant_date_from_timestamp(): Invalid timestamp %d in %sbug72498.php on line %d
15-
bool(false)
18+
--EXPECT--
19+
variant_date_from_timestamp(): Argument #1 ($timestamp) must not go past 23:59:59, December 31, 3000, UTC

0 commit comments

Comments
 (0)