summaryrefslogtreecommitdiff
path: root/ext/com_dotnet/com_variant.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/com_dotnet/com_variant.c')
-rw-r--r--ext/com_dotnet/com_variant.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/ext/com_dotnet/com_variant.c b/ext/com_dotnet/com_variant.c
index a904a08ac0..733f0bcd50 100644
--- a/ext/com_dotnet/com_variant.c
+++ b/ext/com_dotnet/com_variant.c
@@ -289,19 +289,36 @@ PHP_FUNCTION(com_variant_create_instance)
php_com_variant_from_zval(&obj->v, zvalue, obj->code_page TSRMLS_CC);
}
- if (ZEND_NUM_ARGS() >= 2) {
+ /* Only perform conversion if variant not already of type passed */
+ if ((ZEND_NUM_ARGS() >= 2) && (vt != V_VT(&obj->v))) {
+
+ /* If already an array and VT_ARRAY is passed then:
+ - if only VT_ARRAY passed then do not perform a conversion
+ - if VT_ARRAY plus other type passed then perform conversion
+ but will probably fail (origional behavior)
+ */
+ if ((vt & VT_ARRAY) && (V_VT(&obj->v) & VT_ARRAY)) {
+ long orig_vt = vt;
+
+ vt &= ~VT_ARRAY;
+ if (vt) {
+ vt = orig_vt;
+ }
+ }
- res = VariantChangeType(&obj->v, &obj->v, 0, (VARTYPE)vt);
+ if (vt) {
+ res = VariantChangeType(&obj->v, &obj->v, 0, (VARTYPE)vt);
- if (FAILED(res)) {
- char *werr, *msg;
+ if (FAILED(res)) {
+ char *werr, *msg;
- werr = php_win_err(res);
- spprintf(&msg, 0, "Variant type conversion failed: %s", werr);
- LocalFree(werr);
+ werr = php_win_err(res);
+ spprintf(&msg, 0, "Variant type conversion failed: %s", werr);
+ LocalFree(werr);
- php_com_throw_exception(res, msg TSRMLS_CC);
- efree(msg);
+ php_com_throw_exception(res, msg TSRMLS_CC);
+ efree(msg);
+ }
}
}