--- embedaddon/php/ext/com_dotnet/com_variant.c 2012/02/21 23:47:53 1.1 +++ embedaddon/php/ext/com_dotnet/com_variant.c 2014/06/15 20:03:41 1.1.1.5 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: com_variant.c,v 1.1 2012/02/21 23:47:53 misho Exp $ */ +/* $Id: com_variant.c,v 1.1.1.5 2014/06/15 20:03:41 misho Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -98,12 +98,13 @@ bogus: } } -PHPAPI void php_com_variant_from_zval(VARIANT *v, zval *z, int codepage TSRMLS_DC) +PHP_COM_DOTNET_API void php_com_variant_from_zval(VARIANT *v, zval *z, int codepage TSRMLS_DC) { OLECHAR *olestring; php_com_dotnet_object *obj; + zend_uchar ztype = (z == NULL ? IS_NULL : Z_TYPE_P(z)); - switch (Z_TYPE_P(z)) { + switch (ztype) { case IS_NULL: V_VT(v) = VT_NULL; break; @@ -153,7 +154,11 @@ PHPAPI void php_com_variant_from_zval(VARIANT *v, zval case IS_STRING: V_VT(v) = VT_BSTR; olestring = php_com_string_to_olestring(Z_STRVAL_P(z), Z_STRLEN_P(z), codepage TSRMLS_CC); - V_BSTR(v) = SysAllocStringByteLen((char*)olestring, Z_STRLEN_P(z) * sizeof(OLECHAR)); + if (CP_UTF8 == codepage) { + V_BSTR(v) = SysAllocStringByteLen((char*)olestring, wcslen(olestring) * sizeof(OLECHAR)); + } else { + V_BSTR(v) = SysAllocStringByteLen((char*)olestring, Z_STRLEN_P(z) * sizeof(OLECHAR)); + } efree(olestring); break; @@ -166,7 +171,7 @@ PHPAPI void php_com_variant_from_zval(VARIANT *v, zval } } -PHPAPI int php_com_zval_from_variant(zval *z, VARIANT *v, int codepage TSRMLS_DC) +PHP_COM_DOTNET_API int php_com_zval_from_variant(zval *z, VARIANT *v, int codepage TSRMLS_DC) { OLECHAR *olestring = NULL; int ret = SUCCESS; @@ -258,7 +263,7 @@ PHPAPI int php_com_zval_from_variant(zval *z, VARIANT } -PHPAPI int php_com_copy_variant(VARIANT *dstvar, VARIANT *srcvar TSRMLS_DC) +PHP_COM_DOTNET_API int php_com_copy_variant(VARIANT *dstvar, VARIANT *srcvar TSRMLS_DC) { int ret = SUCCESS; @@ -429,7 +434,7 @@ PHP_FUNCTION(com_variant_create_instance) /* 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) + but will probably fail (original behavior) */ if ((vt & VT_ARRAY) && (V_VT(&obj->v) & VT_ARRAY)) { long orig_vt = vt; @@ -446,7 +451,7 @@ PHP_FUNCTION(com_variant_create_instance) if (FAILED(res)) { char *werr, *msg; - werr = php_win_err(res); + werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Variant type conversion failed: %s", werr); LocalFree(werr); @@ -1027,7 +1032,7 @@ PHP_FUNCTION(variant_set_type) } else { char *werr, *msg; - werr = php_win_err(res); + werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Variant type conversion failed: %s", werr); LocalFree(werr); @@ -1061,7 +1066,7 @@ PHP_FUNCTION(variant_cast) } else { char *werr, *msg; - werr = php_win_err(res); + werr = php_win32_error_to_msg(res); spprintf(&msg, 0, "Variant type conversion failed: %s", werr); LocalFree(werr);