PHPAPI zval *php_COM_object_from_dispatch(IDispatch *disp, zval *val TSRMLS_DC)
{
comval *obj;
- long rid;
zval *zobj;
ALLOC_COM(obj);
- C_DISPATCH(obj) = disp;
- php_COM_set(obj, &C_DISPATCH(obj), FALSE TSRMLS_CC);
-
- /* resource */
- rid = zend_list_insert(obj, IS_COM);
-
- if (val == NULL)
- MAKE_STD_ZVAL(val);
- ZVAL_RESOURCE(val, rid);
-
- /* now we want an object */
MAKE_STD_ZVAL(zobj);
- object_init_ex(zobj, &COM_class_entry);
- zend_hash_index_update(Z_OBJPROP_P(zobj), 0, &val, sizeof(zval *), NULL);
-
+ php_COM_set(obj, &disp, FALSE TSRMLS_CC);
+ ZVAL_COM_EX(zobj, obj, val);
+
return zobj;
}
END_EXTERN_C()
#define ZVAL_COM(z,o) { \
- zval *handle; \
+ zval *handle = NULL; \
+ ZVAL_COM_EX(z,o,handle) \
+ }
+
+#define ZVAL_COM_EX(z,o,handle) { \
HashTable *properties; \
\
ALLOC_HASHTABLE(properties); \
zend_hash_init(properties, 0, NULL, ZVAL_PTR_DTOR, 0); \
\
- MAKE_STD_ZVAL(handle); \
+ if (handle == NULL) { \
+ MAKE_STD_ZVAL(handle); \
+ } \
ZVAL_LONG(handle, zend_list_insert((o), IS_COM)); \
\
zval_copy_ctor(handle); \
case IS_OBJECT:
if (!strcmp(Z_OBJCE_P(pval_arg)->name, "VARIANT")) {
type = VT_VARIANT|VT_BYREF;
- } else if (!strcmp(Z_OBJCE_P(pval_arg)->name, "COM")) {
- type = VT_DISPATCH;
} else {
type = VT_DISPATCH;
}
comval_to_variant(pval_arg, var_arg TSRMLS_CC);
} else {
V_DISPATCH(var_arg) = php_COM_export_object(pval_arg TSRMLS_CC);
- if (V_DISPATCH(var_arg))
+ if (V_DISPATCH(var_arg)) {
V_VT(var_arg) = VT_DISPATCH;
+ }
}
if (V_VT(var_arg) != VT_DISPATCH) {
VariantInit(var_arg);
PHPAPI zval *php_COM_object_from_dispatch(IDispatch *disp, zval *val TSRMLS_DC)
{
comval *obj;
- long rid;
zval *zobj;
ALLOC_COM(obj);
- C_DISPATCH(obj) = disp;
- php_COM_set(obj, &C_DISPATCH(obj), FALSE TSRMLS_CC);
-
- /* resource */
- rid = zend_list_insert(obj, IS_COM);
-
- if (val == NULL)
- MAKE_STD_ZVAL(val);
- ZVAL_RESOURCE(val, rid);
-
- /* now we want an object */
MAKE_STD_ZVAL(zobj);
- object_init_ex(zobj, &COM_class_entry);
- zend_hash_index_update(Z_OBJPROP_P(zobj), 0, &val, sizeof(zval *), NULL);
-
+ php_COM_set(obj, &disp, FALSE TSRMLS_CC);
+ ZVAL_COM_EX(zobj, obj, val);
+
return zobj;
}
END_EXTERN_C()
#define ZVAL_COM(z,o) { \
- zval *handle; \
+ zval *handle = NULL; \
+ ZVAL_COM_EX(z,o,handle) \
+ }
+
+#define ZVAL_COM_EX(z,o,handle) { \
HashTable *properties; \
\
ALLOC_HASHTABLE(properties); \
zend_hash_init(properties, 0, NULL, ZVAL_PTR_DTOR, 0); \
\
- MAKE_STD_ZVAL(handle); \
+ if (handle == NULL) { \
+ MAKE_STD_ZVAL(handle); \
+ } \
ZVAL_LONG(handle, zend_list_insert((o), IS_COM)); \
\
zval_copy_ctor(handle); \
case IS_OBJECT:
if (!strcmp(Z_OBJCE_P(pval_arg)->name, "VARIANT")) {
type = VT_VARIANT|VT_BYREF;
- } else if (!strcmp(Z_OBJCE_P(pval_arg)->name, "COM")) {
- type = VT_DISPATCH;
} else {
type = VT_DISPATCH;
}
comval_to_variant(pval_arg, var_arg TSRMLS_CC);
} else {
V_DISPATCH(var_arg) = php_COM_export_object(pval_arg TSRMLS_CC);
- if (V_DISPATCH(var_arg))
+ if (V_DISPATCH(var_arg)) {
V_VT(var_arg) = VT_DISPATCH;
+ }
}
if (V_VT(var_arg) != VT_DISPATCH) {
VariantInit(var_arg);