Skip to content

Commit db00790

Browse files
committed
ext/com_dotnet support for new object handlers API
1 parent 1a304d3 commit db00790

File tree

4 files changed

+53
-57
lines changed

4 files changed

+53
-57
lines changed

ext/com_dotnet/com_handlers.c

+26-27
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,30 @@
2727
#include "php_com_dotnet_internal.h"
2828
#include "Zend/zend_exceptions.h"
2929

30-
static zval *com_property_read(zval *object, zval *member, int type, void **cahce_slot, zval *rv)
30+
static zval *com_property_read(zend_object *object, zend_string *member, int type, void **cahce_slot, zval *rv)
3131
{
3232
php_com_dotnet_object *obj;
3333
VARIANT v;
3434
HRESULT res;
3535

3636
ZVAL_NULL(rv);
3737

38-
obj = CDNO_FETCH(object);
38+
obj = (php_com_dotnet_object*) object;
3939

4040
if (V_VT(&obj->v) == VT_DISPATCH) {
4141
VariantInit(&v);
4242

43-
convert_to_string_ex(member);
44-
45-
res = php_com_do_invoke(obj, Z_STRVAL_P(member), Z_STRLEN_P(member),
43+
res = php_com_do_invoke(obj, ZSTR_VAL(member), ZSTR_LEN(member),
4644
DISPATCH_METHOD|DISPATCH_PROPERTYGET, &v, 0, NULL, 1);
4745

4846
if (res == SUCCESS) {
4947
php_com_zval_from_variant(rv, &v, obj->code_page);
5048
VariantClear(&v);
5149
} else if (res == DISP_E_BADPARAMCOUNT) {
52-
php_com_saproxy_create(object, rv, member);
50+
zval zv;
51+
52+
ZVAL_STR(&zv, member);
53+
php_com_saproxy_create(object, rv, &zv);
5354
}
5455
} else {
5556
php_com_throw_exception(E_INVALIDARG, "this variant has no properties");
@@ -58,18 +59,17 @@ static zval *com_property_read(zval *object, zval *member, int type, void **cahc
5859
return rv;
5960
}
6061

61-
static zval *com_property_write(zval *object, zval *member, zval *value, void **cache_slot)
62+
static zval *com_property_write(zend_object *object, zend_string *member, zval *value, void **cache_slot)
6263
{
6364
php_com_dotnet_object *obj;
6465
VARIANT v;
6566

66-
obj = CDNO_FETCH(object);
67+
obj = (php_com_dotnet_object*) object;
6768

6869
if (V_VT(&obj->v) == VT_DISPATCH) {
6970
VariantInit(&v);
7071

71-
convert_to_string_ex(member);
72-
if (SUCCESS == php_com_do_invoke(obj, Z_STRVAL_P(member), Z_STRLEN_P(member),
72+
if (SUCCESS == php_com_do_invoke(obj, ZSTR_VAL(member), ZSTR_LEN(member),
7373
DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF, &v, 1, value, 0)) {
7474
VariantClear(&v);
7575
}
@@ -79,14 +79,14 @@ static zval *com_property_write(zval *object, zval *member, zval *value, void **
7979
return value;
8080
}
8181

82-
static zval *com_read_dimension(zval *object, zval *offset, int type, zval *rv)
82+
static zval *com_read_dimension(zend_object *object, zval *offset, int type, zval *rv)
8383
{
8484
php_com_dotnet_object *obj;
8585
VARIANT v;
8686

8787
ZVAL_NULL(rv);
8888

89-
obj = CDNO_FETCH(object);
89+
obj = (php_com_dotnet_object*) object;
9090

9191
if (V_VT(&obj->v) == VT_DISPATCH) {
9292
VariantInit(&v);
@@ -115,14 +115,14 @@ static zval *com_read_dimension(zval *object, zval *offset, int type, zval *rv)
115115
return rv;
116116
}
117117

118-
static void com_write_dimension(zval *object, zval *offset, zval *value)
118+
static void com_write_dimension(zend_object *object, zval *offset, zval *value)
119119
{
120120
php_com_dotnet_object *obj;
121121
zval args[2];
122122
VARIANT v;
123123
HRESULT res;
124124

125-
obj = CDNO_FETCH(object);
125+
obj = (php_com_dotnet_object*) object;
126126

127127
if (V_VT(&obj->v) == VT_DISPATCH) {
128128
ZVAL_COPY_VALUE(&args[0], offset);
@@ -187,16 +187,15 @@ static zval *com_object_get(zval *property)
187187
}
188188
#endif
189189

190-
static int com_property_exists(zval *object, zval *member, int check_empty, void **cache_slot)
190+
static int com_property_exists(zend_object *object, zend_string *member, int check_empty, void **cache_slot)
191191
{
192192
DISPID dispid;
193193
php_com_dotnet_object *obj;
194194

195-
obj = CDNO_FETCH(object);
195+
obj = (php_com_dotnet_object*) object;
196196

197197
if (V_VT(&obj->v) == VT_DISPATCH) {
198-
convert_to_string_ex(member);
199-
if (SUCCEEDED(php_com_get_id_of_name(obj, Z_STRVAL_P(member), Z_STRLEN_P(member), &dispid))) {
198+
if (SUCCEEDED(php_com_get_id_of_name(obj, ZSTR_VAL(member), ZSTR_LEN(member), &dispid))) {
200199
/* TODO: distinguish between property and method! */
201200
return 1;
202201
}
@@ -207,23 +206,23 @@ static int com_property_exists(zval *object, zval *member, int check_empty, void
207206
return 0;
208207
}
209208

210-
static int com_dimension_exists(zval *object, zval *member, int check_empty)
209+
static int com_dimension_exists(zend_object *object, zval *member, int check_empty)
211210
{
212211
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
213212
return 0;
214213
}
215214

216-
static void com_property_delete(zval *object, zval *member, void **cache_slot)
215+
static void com_property_delete(zend_object *object, zend_string *member, void **cache_slot)
217216
{
218217
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
219218
}
220219

221-
static void com_dimension_delete(zval *object, zval *offset)
220+
static void com_dimension_delete(zend_object *object, zval *offset)
222221
{
223222
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
224223
}
225224

226-
static HashTable *com_properties_get(zval *object)
225+
static HashTable *com_properties_get(zend_object *object)
227226
{
228227
/* TODO: use type-info to get all the names and values ?
229228
* DANGER: if we do that, there is a strong possibility for
@@ -468,7 +467,7 @@ static int com_object_cast(zend_object *readobj, zval *writeobj, int type)
468467
VARTYPE vt = VT_EMPTY;
469468
HRESULT res = S_OK;
470469

471-
obj = CDNO_FETCH(readobj);
470+
obj = (php_com_dotnet_object*) readobj;
472471
ZVAL_NULL(writeobj);
473472
VariantInit(&v);
474473

@@ -518,12 +517,12 @@ static int com_object_cast(zend_object *readobj, zval *writeobj, int type)
518517
return zend_std_cast_object_tostring(readobj, writeobj, type);
519518
}
520519

521-
static int com_object_count(zval *object, zend_long *count)
520+
static int com_object_count(zend_object *object, zend_long *count)
522521
{
523522
php_com_dotnet_object *obj;
524523
LONG ubound = 0, lbound = 0;
525524

526-
obj = CDNO_FETCH(object);
525+
obj = (php_com_dotnet_object*) object;
527526

528527
if (!V_ISARRAY(&obj->v)) {
529528
return FAILURE;
@@ -617,11 +616,11 @@ void php_com_object_free_storage(zend_object *object)
617616
}
618617
}
619618

620-
zend_object* php_com_object_clone(zval *object)
619+
zend_object* php_com_object_clone(zend_object *object)
621620
{
622621
php_com_dotnet_object *cloneobj, *origobject;
623622

624-
origobject = (php_com_dotnet_object*)Z_OBJ_P(object);
623+
origobject = (php_com_dotnet_object*) object;
625624
cloneobj = (php_com_dotnet_object*)emalloc(sizeof(php_com_dotnet_object));
626625

627626
memcpy(cloneobj, origobject, sizeof(*cloneobj));

ext/com_dotnet/com_persist.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,9 @@ static void helper_free_storage(zend_object *obj)
709709
}
710710

711711

712-
static zend_object* helper_clone(zval *obj)
712+
static zend_object* helper_clone(zend_object *obj)
713713
{
714-
php_com_persist_helper *clone, *object = (php_com_persist_helper*)Z_OBJ_P(obj);
714+
php_com_persist_helper *clone, *object = (php_com_persist_helper*) obj;
715715

716716
clone = emalloc(sizeof(*object));
717717
memcpy(clone, object, sizeof(*object));

ext/com_dotnet/com_saproxy.c

+23-26
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
typedef struct {
3838
zend_object std;
3939
/* the object we a proxying for; we hold a refcount to it */
40-
zval *zobj;
4140
php_com_dotnet_object *obj;
4241

4342
/* how many dimensions we are indirecting to get into this element */
@@ -69,7 +68,7 @@ static inline void clone_indices(php_com_saproxy *dest, php_com_saproxy *src, in
6968
}
7069
}
7170

72-
static zval *saproxy_property_read(zval *object, zval *member, int type, void **cache_slot, zval *rv)
71+
static zval *saproxy_property_read(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv)
7372
{
7473
ZVAL_NULL(rv);
7574

@@ -78,14 +77,14 @@ static zval *saproxy_property_read(zval *object, zval *member, int type, void **
7877
return rv;
7978
}
8079

81-
static void saproxy_property_write(zval *object, zval *member, zval *value, void **cache_slot)
80+
static void saproxy_property_write(zend_object *object, zend_string *member, zval *value, void **cache_slot)
8281
{
8382
php_com_throw_exception(E_INVALIDARG, "safearray has no properties");
8483
}
8584

86-
static zval *saproxy_read_dimension(zval *object, zval *offset, int type, zval *rv)
85+
static zval *saproxy_read_dimension(zend_object *object, zval *offset, int type, zval *rv)
8786
{
88-
php_com_saproxy *proxy = SA_FETCH(object);
87+
php_com_saproxy *proxy = (php_com_saproxy*) object;
8988
UINT dims, i;
9089
SAFEARRAY *sa;
9190
LONG ubound, lbound;
@@ -201,9 +200,9 @@ static zval *saproxy_read_dimension(zval *object, zval *offset, int type, zval *
201200
return rv;
202201
}
203202

204-
static void saproxy_write_dimension(zval *object, zval *offset, zval *value)
203+
static void saproxy_write_dimension(zend_object *object, zval *offset, zval *value)
205204
{
206-
php_com_saproxy *proxy = SA_FETCH(object);
205+
php_com_saproxy *proxy = (php_com_saproxy*) object;
207206
UINT dims, i;
208207
HRESULT res;
209208
VARIANT v;
@@ -286,29 +285,29 @@ static zval *saproxy_object_get(zval *property)
286285
}
287286
#endif
288287

289-
static int saproxy_property_exists(zval *object, zval *member, int check_empty, void **cache_slot)
288+
static int saproxy_property_exists(zend_object *object, zend_string *member, int check_empty, void **cache_slot)
290289
{
291290
/* no properties */
292291
return 0;
293292
}
294293

295-
static int saproxy_dimension_exists(zval *object, zval *member, int check_empty)
294+
static int saproxy_dimension_exists(zend_object *object, zval *member, int check_empty)
296295
{
297296
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
298297
return 0;
299298
}
300299

301-
static void saproxy_property_delete(zval *object, zval *member, void **cache_slot)
300+
static void saproxy_property_delete(zend_object *object, zend_string *member, void **cache_slot)
302301
{
303302
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
304303
}
305304

306-
static void saproxy_dimension_delete(zval *object, zval *offset)
305+
static void saproxy_dimension_delete(zend_object *object, zval *offset)
307306
{
308307
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
309308
}
310309

311-
static HashTable *saproxy_properties_get(zval *object)
310+
static HashTable *saproxy_properties_get(zend_object *object)
312311
{
313312
/* no properties */
314313
return NULL;
@@ -341,14 +340,14 @@ static int saproxy_objects_compare(zval *object1, zval *object2)
341340
return -1;
342341
}
343342

344-
static int saproxy_object_cast(zval *readobj, zval *writeobj, int type)
343+
static int saproxy_object_cast(zend_object *readobj, zval *writeobj, int type)
345344
{
346345
return FAILURE;
347346
}
348347

349-
static int saproxy_count_elements(zval *object, zend_long *count)
348+
static int saproxy_count_elements(zend_object *object, zend_long *count)
350349
{
351-
php_com_saproxy *proxy = SA_FETCH(object);
350+
php_com_saproxy *proxy = (php_com_saproxy*) object;
352351
LONG ubound, lbound;
353352

354353
if (!V_ISARRAY(&proxy->obj->v)) {
@@ -374,19 +373,19 @@ static void saproxy_free_storage(zend_object *object)
374373
//??? }
375374
//??? }
376375

377-
zval_ptr_dtor(proxy->zobj);
376+
OBJ_RELEASE(&proxy->obj->zo);
378377
efree(proxy->indices);
379378
}
380379

381-
static zend_object* saproxy_clone(zval *object)
380+
static zend_object* saproxy_clone(zend_object *object)
382381
{
383-
php_com_saproxy *proxy = (php_com_saproxy *)Z_OBJ_P(object);
382+
php_com_saproxy *proxy = (php_com_saproxy *) object;
384383
php_com_saproxy *cloneproxy;
385384

386385
cloneproxy = emalloc(sizeof(*cloneproxy));
387386
memcpy(cloneproxy, proxy, sizeof(*cloneproxy));
388387

389-
Z_ADDREF_P(cloneproxy->zobj);
388+
GC_ADDREF(&cloneproxy->obj->zo);
390389
cloneproxy->indices = safe_emalloc(cloneproxy->dimensions, sizeof(zval *), 0);
391390
clone_indices(cloneproxy, proxy, proxy->dimensions);
392391

@@ -419,24 +418,22 @@ zend_object_handlers php_com_saproxy_handlers = {
419418
saproxy_count_elements
420419
};
421420

422-
int php_com_saproxy_create(zval *com_object, zval *proxy_out, zval *index)
421+
int php_com_saproxy_create(zend_object *com_object, zval *proxy_out, zval *index)
423422
{
424423
php_com_saproxy *proxy, *rel = NULL;
425424

426425
proxy = ecalloc(1, sizeof(*proxy));
427426
proxy->dimensions = 1;
428427

429-
if (Z_OBJCE_P(com_object) == php_com_saproxy_class_entry) {
430-
rel = SA_FETCH(com_object);
428+
if (com_object->ce == php_com_saproxy_class_entry) {
429+
rel = (php_com_saproxy*) com_object;
431430
proxy->obj = rel->obj;
432-
proxy->zobj = rel->zobj;
433431
proxy->dimensions += rel->dimensions;
434432
} else {
435-
proxy->obj = CDNO_FETCH(com_object);
436-
proxy->zobj = com_object;
433+
proxy->obj = (php_com_dotnet_object*) com_object;
437434
}
438435

439-
Z_ADDREF_P(proxy->zobj);
436+
Z_ADDREF_P(&proxy->obj->zo);
440437
proxy->indices = safe_emalloc(proxy->dimensions, sizeof(zval *), 0);
441438

442439
if (rel) {

ext/com_dotnet/php_com_dotnet_internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ zend_class_entry *php_com_variant_class_entry, *php_com_exception_class_entry, *
7575

7676
/* com_handlers.c */
7777
zend_object* php_com_object_new(zend_class_entry *ce);
78-
zend_object* php_com_object_clone(zval *object);
78+
zend_object* php_com_object_clone(zend_object *object);
7979
void php_com_object_free_storage(zend_object *object);
8080
zend_object_handlers php_com_object_handlers;
8181
void php_com_object_enable_event_sink(php_com_dotnet_object *obj, int enable);
8282

8383
/* com_saproxy.c */
8484
zend_object_iterator *php_com_saproxy_iter_get(zend_class_entry *ce, zval *object, int by_ref);
85-
int php_com_saproxy_create(zval *com_object, zval *proxy_out, zval *index);
85+
int php_com_saproxy_create(zend_object *com_object, zval *proxy_out, zval *index);
8686

8787
/* com_olechar.c */
8888
PHP_COM_DOTNET_API char *php_com_olestring_to_string(OLECHAR *olestring,

0 commit comments

Comments
 (0)