Skip to content

Commit da012ba

Browse files
committed
Refactor php_com_locate_typeinfo()
Use zend_string pointers Use bool
1 parent 816d4ac commit da012ba

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

ext/com_dotnet/com_com.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,8 @@ PHP_FUNCTION(com_event_sink)
677677
zval *object, *sinkobject;
678678
zend_string *sink_str = NULL;
679679
HashTable *sink_ht = NULL;
680-
char *dispname = NULL, *typelibname = NULL;
680+
zend_string *type_lib_name = NULL;
681+
zend_string *dispatch_name = NULL;
681682
php_com_dotnet_object *obj;
682683
ITypeInfo *typeinfo = NULL;
683684

@@ -698,14 +699,14 @@ PHP_FUNCTION(com_event_sink)
698699
zval *tmp;
699700

700701
if ((tmp = zend_hash_index_find(sink_ht, 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
701-
typelibname = Z_STRVAL_P(tmp);
702+
type_lib_name = Z_STR_P(tmp);
702703
if ((tmp = zend_hash_index_find(sink_ht, 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
703-
dispname = Z_STRVAL_P(tmp);
704+
dispatch_name = Z_STR_P(tmp);
704705
} else if (sink_str) {
705-
dispname = ZSTR_VAL(sink_str);
706+
dispatch_name = sink_str;
706707
}
707708

708-
typeinfo = php_com_locate_typeinfo(typelibname, obj, dispname, 1);
709+
typeinfo = php_com_locate_typeinfo(type_lib_name, obj, dispatch_name, /* sink */ true);
709710

710711
if (typeinfo) {
711712
HashTable *id_to_name;
@@ -737,29 +738,25 @@ PHP_FUNCTION(com_event_sink)
737738
PHP_FUNCTION(com_print_typeinfo)
738739
{
739740
zend_object *object_zpp;
740-
zend_string *typelib_name_zpp = NULL;
741-
char *ifacename = NULL;
742-
char *typelibname = NULL;
743-
size_t ifacelen;
744-
bool wantsink = 0;
741+
zend_string *type_lib_name = NULL;
742+
zend_string *interface_name = NULL;
743+
bool want_sink = false;
745744
php_com_dotnet_object *obj = NULL;
746745
ITypeInfo *typeinfo;
747746

748747
ZEND_PARSE_PARAMETERS_START(1, 3)
749-
Z_PARAM_OBJ_OF_CLASS_OR_STR(object_zpp, php_com_variant_class_entry, typelib_name_zpp)
748+
Z_PARAM_OBJ_OF_CLASS_OR_STR(object_zpp, php_com_variant_class_entry, type_lib_name)
750749
Z_PARAM_OPTIONAL
751-
Z_PARAM_STRING_OR_NULL(ifacename, ifacelen)
752-
Z_PARAM_BOOL(wantsink)
750+
Z_PARAM_STR_OR_NULL(interface_name)
751+
Z_PARAM_BOOL(want_sink)
753752
ZEND_PARSE_PARAMETERS_END();
754753

755754
php_com_initialize();
756755
if (object_zpp) {
757756
obj = (php_com_dotnet_object*)object_zpp;
758-
} else {
759-
typelibname = ZSTR_VAL(typelib_name_zpp);
760757
}
761758

762-
typeinfo = php_com_locate_typeinfo(typelibname, obj, ifacename, wantsink ? 1 : 0);
759+
typeinfo = php_com_locate_typeinfo(type_lib_name, obj, interface_name, want_sink);
763760
if (typeinfo) {
764761
php_com_process_typeinfo(typeinfo, NULL, 1, NULL, obj ? obj->code_page : COMG(code_page));
765762
ITypeInfo_Release(typeinfo);

ext/com_dotnet/com_typeinfo.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,16 @@ PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(const char *search_s
302302
return TL;
303303
}
304304

305-
ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj, char *dispname, int sink)
305+
ITypeInfo *php_com_locate_typeinfo(zend_string *type_lib_name, php_com_dotnet_object *obj,
306+
zend_string *dispatch_name, bool sink)
306307
{
307308
ITypeInfo *typeinfo = NULL;
308309
ITypeLib *typelib = NULL;
309310
int gotguid = 0;
310311
GUID iid;
311312

312313
if (obj) {
313-
if (dispname == NULL && sink) {
314+
if (dispatch_name == NULL && sink) {
314315
if (V_VT(&obj->v) == VT_DISPATCH) {
315316
IProvideClassInfo2 *pci2;
316317
IProvideClassInfo *pci;
@@ -326,7 +327,7 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
326327
IProvideClassInfo_Release(pci);
327328
}
328329
}
329-
} else if (dispname == NULL) {
330+
} else if (dispatch_name == NULL) {
330331
if (obj->typeinfo) {
331332
ITypeInfo_AddRef(obj->typeinfo);
332333
return obj->typeinfo;
@@ -336,14 +337,14 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
336337
return typeinfo;
337338
}
338339
}
339-
} else if (dispname && obj->typeinfo) {
340+
} else if (dispatch_name && obj->typeinfo) {
340341
unsigned int idx;
341342
/* get the library from the object; the rest will be dealt with later */
342343
ITypeInfo_GetContainingTypeLib(obj->typeinfo, &typelib, &idx);
343-
} else if (typelibname == NULL) {
344+
} else if (type_lib_name == NULL) {
344345
if (V_VT(&obj->v) == VT_DISPATCH) {
345346
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &typeinfo);
346-
if (dispname) {
347+
if (dispatch_name) {
347348
unsigned int idx;
348349
/* get the library from the object; the rest will be dealt with later */
349350
ITypeInfo_GetContainingTypeLib(typeinfo, &typelib, &idx);
@@ -355,15 +356,15 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
355356
}
356357
}
357358
}
358-
} else if (typelibname) {
359+
} else if (type_lib_name) {
359360
/* Fetch the typelibrary and use that to look things up */
360-
typelib = php_com_load_typelib(typelibname, CP_THREAD_ACP);
361+
typelib = php_com_load_typelib(ZSTR_VAL(type_lib_name), CP_THREAD_ACP);
361362
}
362363

363-
if (!gotguid && dispname && typelib) {
364+
if (!gotguid && dispatch_name && typelib) {
364365
unsigned short cfound;
365366
MEMBERID memid;
366-
OLECHAR *olename = php_com_string_to_olestring(dispname, strlen(dispname), CP_ACP);
367+
OLECHAR *olename = php_com_string_to_olestring(ZSTR_VAL(dispatch_name), ZSTR_LEN(dispatch_name), CP_ACP);
367368

368369
cfound = 1;
369370
if (FAILED(ITypeLib_FindName(typelib, olename, 0, &typeinfo, &memid, &cfound)) || cfound == 0) {

ext/com_dotnet/php_com_dotnet_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(const char *search_s
135135
PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib(char *search_string, int codepage);
136136
PHP_COM_DOTNET_API zend_result php_com_import_typelib(ITypeLib *TL, int mode, int codepage);
137137
void php_com_typelibrary_dtor(zval *pDest);
138-
ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj, char *dispname, int sink);
138+
ITypeInfo *php_com_locate_typeinfo(zend_string *type_lib_name, php_com_dotnet_object *obj,
139+
zend_string *dispatch_name, bool sink);
139140
bool php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, bool printdef, GUID *guid, int codepage);
140141
ITypeLib *php_com_cache_typelib(ITypeLib* TL, char *cache_key, zend_long cache_key_len);
141142
PHP_MINIT_FUNCTION(com_typeinfo);

0 commit comments

Comments
 (0)