php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
com_misc.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Wez Furlong <wez@thebrainroom.com> |
14 +----------------------------------------------------------------------+
15 */
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "php.h"
22#include "php_ini.h"
23#include "ext/standard/info.h"
24#include "php_com_dotnet.h"
27
28void php_com_throw_exception(HRESULT code, char *message)
29{
30 int free_msg = 0;
31 if (message == NULL) {
32 message = php_win32_error_to_msg(code);
33 free_msg = 1;
34 }
35#if SIZEOF_ZEND_LONG == 8
37#else
39#endif
40 if (free_msg) {
42 }
43}
44
46 int codepage)
47{
49
50 obj = emalloc(sizeof(*obj));
51 memset(obj, 0, sizeof(*obj));
52 obj->code_page = codepage;
55
56 VariantInit(&obj->v);
57 V_VT(&obj->v) = VT_DISPATCH;
58 V_DISPATCH(&obj->v) = disp;
59
60 IDispatch_AddRef(V_DISPATCH(&obj->v));
61 IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &obj->typeinfo);
62
64 ZVAL_OBJ(z, &obj->zo);
65}
66
68 int codepage)
69{
71
72 obj = emalloc(sizeof(*obj));
73 memset(obj, 0, sizeof(*obj));
74 obj->code_page = codepage;
77
78 VariantInit(&obj->v);
79 VariantCopyInd(&obj->v, v);
80 obj->modified = 0;
81
82 if ((V_VT(&obj->v) == VT_DISPATCH) && (V_DISPATCH(&obj->v) != NULL)) {
83 IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &obj->typeinfo);
84 }
85
87 ZVAL_OBJ(z, &obj->zo);
88}
89
90/* this is a convenience function for fetching a particular
91 * element from a (possibly multi-dimensional) safe array */
92PHP_COM_DOTNET_API bool php_com_safearray_get_elem(VARIANT *array, VARIANT *dest, LONG dim1)
93{
94 UINT dims;
95 LONG lbound, ubound;
96 LONG indices[1];
97 VARTYPE vt;
98
99 if (!V_ISARRAY(array)) {
100 return 0;
101 }
102
103 dims = SafeArrayGetDim(V_ARRAY(array));
104
105 if (dims != 1) {
106 /* TODO Promote to ValueError? */
108 "Can only handle single dimension variant arrays (this array has %d)", dims);
109 return 0;
110 }
111
112 if (FAILED(SafeArrayGetVartype(V_ARRAY(array), &vt)) || vt == VT_EMPTY) {
113 vt = V_VT(array) & ~VT_ARRAY;
114 }
115
116 /* determine the bounds */
117 SafeArrayGetLBound(V_ARRAY(array), 1, &lbound);
118 SafeArrayGetUBound(V_ARRAY(array), 1, &ubound);
119
120 /* check bounds */
121 if (dim1 < lbound || dim1 > ubound) {
122 php_com_throw_exception(DISP_E_BADINDEX, "index out of bounds");
123 return 0;
124 }
125
126 /* now fetch that element */
127 VariantInit(dest);
128
129 indices[0] = dim1;
130
131 if (vt == VT_VARIANT) {
132 SafeArrayGetElement(V_ARRAY(array), indices, dest);
133 } else {
134 V_VT(dest) = vt;
135 /* store the value into "lVal" member of the variant.
136 * This works because it is a union; since we know the variant
137 * type, we end up with a working variant */
138 SafeArrayGetElement(V_ARRAY(array), indices, &dest->lVal);
139 }
140
141 return 1;
142}
uint32_t v
Definition cdf.c:1237
zend_class_entry * php_com_exception_class_entry
zend_class_entry * php_com_variant_class_entry
const DISP_E_BADINDEX
const VT_DISPATCH
const VT_VARIANT
const VT_EMPTY
const VT_ARRAY
PHP_COM_DOTNET_API bool php_com_safearray_get_elem(VARIANT *array, VARIANT *dest, LONG dim1)
Definition com_misc.c:92
PHP_COM_DOTNET_API void php_com_wrap_variant(zval *z, VARIANT *v, int codepage)
Definition com_misc.c:67
void php_com_throw_exception(HRESULT code, char *message)
Definition com_misc.c:28
PHP_COM_DOTNET_API void php_com_wrap_dispatch(zval *z, IDispatch *disp, int codepage)
Definition com_misc.c:45
VARTYPE vt
HashTable * dims
Definition ffi.c:4261
memset(ptr, 0, type->size)
#define NULL
Definition gdcache.h:45
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
#define PHP_COM_DOTNET_API
struct _php_com_dotnet_object php_com_dotnet_object
zend_class_entry * ce
Definition zend_types.h:560
PHP_WINUTIL_API char * php_win32_error_to_msg(HRESULT error)
Definition winutil.c:25
PHP_WINUTIL_API void php_win32_error_msg_free(char *msg)
Definition winutil.c:50
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
#define E_WARNING
Definition zend_errors.h:24
ZEND_API ZEND_COLD zend_object * zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code)
int32_t zend_long
Definition zend_long.h:42
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
#define ZVAL_OBJ(z, o)