@@ -421,10 +421,8 @@ static struct IDispatchExVtbl php_dispatch_vtbl = {
421
421
* dispatch ids */
422
422
static void generate_dispids (php_dispatchex * disp )
423
423
{
424
- HashPosition pos ;
425
424
zend_string * name = NULL ;
426
- zval * tmp , tmp2 ;
427
- int keytype ;
425
+ zval tmp ;
428
426
zend_ulong pid ;
429
427
430
428
if (disp -> dispid_to_name == NULL ) {
@@ -436,71 +434,42 @@ static void generate_dispids(php_dispatchex *disp)
436
434
437
435
/* properties */
438
436
if (Z_OBJPROP (disp -> object )) {
439
- zend_hash_internal_pointer_reset_ex (Z_OBJPROP (disp -> object ), & pos );
440
- while (HASH_KEY_NON_EXISTENT != (keytype =
441
- zend_hash_get_current_key_ex (Z_OBJPROP (disp -> object ), & name ,
442
- & pid , & pos ))) {
443
- char namebuf [32 ];
444
- if (keytype == HASH_KEY_IS_LONG ) {
445
- snprintf (namebuf , sizeof (namebuf ), ZEND_ULONG_FMT , pid );
446
- name = zend_string_init (namebuf , strlen (namebuf ), 0 );
447
- } else {
448
- zend_string_addref (name );
449
- }
450
-
451
- zend_hash_move_forward_ex (Z_OBJPROP (disp -> object ), & pos );
437
+ ZEND_HASH_FOREACH_STR_KEY (Z_OBJPROP (disp -> object ), name ) {
438
+ ZEND_ASSERT (name );
452
439
453
- /* Find the existing id */
454
- if ((tmp = zend_hash_find (disp -> name_to_dispid , name )) != NULL ) {
455
- zend_string_release_ex (name , 0 );
440
+ /* Check ID exists */
441
+ if (!zend_hash_exists (disp -> name_to_dispid , name )) {
456
442
continue ;
457
443
}
458
444
459
445
/* add the mappings */
460
- ZVAL_STR_COPY (& tmp2 , name );
446
+ ZVAL_STR_COPY (& tmp , name );
461
447
pid = zend_hash_next_free_element (disp -> dispid_to_name );
462
- zend_hash_index_update (disp -> dispid_to_name , pid , & tmp2 );
463
-
464
- ZVAL_LONG (& tmp2 , pid );
465
- zend_hash_update (disp -> name_to_dispid , name , & tmp2 );
448
+ zend_hash_index_update (disp -> dispid_to_name , pid , & tmp );
466
449
467
- zend_string_release_ex (name , 0 );
468
- }
450
+ ZVAL_LONG (& tmp , pid );
451
+ zend_hash_update (disp -> name_to_dispid , name , & tmp );
452
+ } ZEND_HASH_FOREACH_END ();
469
453
}
470
454
471
455
/* functions */
472
456
if (Z_OBJCE (disp -> object )) {
473
- zend_hash_internal_pointer_reset_ex (& Z_OBJCE (disp -> object )-> function_table , & pos );
474
- while (HASH_KEY_NON_EXISTENT != (keytype =
475
- zend_hash_get_current_key_ex (& Z_OBJCE (disp -> object )-> function_table ,
476
- & name , & pid , & pos ))) {
477
-
478
- char namebuf [32 ];
479
- if (keytype == HASH_KEY_IS_LONG ) {
480
- snprintf (namebuf , sizeof (namebuf ), ZEND_ULONG_FMT , pid );
481
- name = zend_string_init (namebuf , strlen (namebuf ), 0 );
482
- } else {
483
- zend_string_addref (name );
484
- }
485
-
486
- zend_hash_move_forward_ex (& Z_OBJCE (disp -> object )-> function_table , & pos );
457
+ ZEND_HASH_FOREACH_STR_KEY (& Z_OBJCE (disp -> object )-> function_table , name ) {
458
+ ZEND_ASSERT (name );
487
459
488
- /* Find the existing id */
489
- if ((tmp = zend_hash_find (disp -> name_to_dispid , name )) != NULL ) {
490
- zend_string_release_ex (name , 0 );
460
+ /* Check ID exists */
461
+ if (!zend_hash_exists (disp -> name_to_dispid , name )) {
491
462
continue ;
492
463
}
493
464
494
465
/* add the mappings */
495
- ZVAL_STR_COPY (& tmp2 , name );
466
+ ZVAL_STR_COPY (& tmp , name );
496
467
pid = zend_hash_next_free_element (disp -> dispid_to_name );
497
- zend_hash_index_update (disp -> dispid_to_name , pid , & tmp2 );
498
-
499
- ZVAL_LONG (& tmp2 , pid );
500
- zend_hash_update (disp -> name_to_dispid , name , & tmp2 );
468
+ zend_hash_index_update (disp -> dispid_to_name , pid , & tmp );
501
469
502
- zend_string_release_ex (name , 0 );
503
- }
470
+ ZVAL_LONG (& tmp , pid );
471
+ zend_hash_update (disp -> name_to_dispid , name , & tmp );
472
+ } ZEND_HASH_FOREACH_END ();
504
473
}
505
474
}
506
475
@@ -541,15 +510,9 @@ static void disp_destructor(php_dispatchex *disp)
541
510
CoTaskMemFree (disp );
542
511
}
543
512
544
- PHP_COM_DOTNET_API IDispatch * php_com_wrapper_export_as_sink (zval * val , GUID * sinkid ,
545
- HashTable * id_to_name )
513
+ PHP_COM_DOTNET_API IDispatch * php_com_wrapper_export_as_sink (zval * val , GUID * sinkid , HashTable * id_to_name )
546
514
{
547
515
php_dispatchex * disp = disp_constructor (val );
548
- HashPosition pos ;
549
- zend_string * name = NULL ;
550
- zval tmp , * ntmp ;
551
- int keytype ;
552
- zend_ulong pid ;
553
516
554
517
disp -> dispid_to_name = id_to_name ;
555
518
@@ -559,20 +522,16 @@ PHP_COM_DOTNET_API IDispatch *php_com_wrapper_export_as_sink(zval *val, GUID *si
559
522
ALLOC_HASHTABLE (disp -> name_to_dispid );
560
523
zend_hash_init (disp -> name_to_dispid , 0 , NULL , ZVAL_PTR_DTOR , 0 );
561
524
562
- zend_hash_internal_pointer_reset_ex (id_to_name , & pos );
563
- while (HASH_KEY_NON_EXISTENT != (keytype =
564
- zend_hash_get_current_key_ex (id_to_name , & name , & pid , & pos ))) {
565
-
566
- if (keytype == HASH_KEY_IS_LONG ) {
567
-
568
- ntmp = zend_hash_get_current_data_ex (id_to_name , & pos );
569
-
570
- ZVAL_LONG (& tmp , pid );
571
- zend_hash_update (disp -> name_to_dispid , Z_STR_P (ntmp ), & tmp );
572
- }
573
-
574
- zend_hash_move_forward_ex (id_to_name , & pos );
575
- }
525
+ ZEND_ASSERT (zend_array_is_list (id_to_name ));
526
+ zend_ulong pid ;
527
+ zval * value ;
528
+ ZEND_HASH_FOREACH_NUM_KEY_VAL (id_to_name , pid , value ) {
529
+ ZEND_ASSERT (Z_TYPE_P (value ) == IS_STRING );
530
+
531
+ zval tmp ;
532
+ ZVAL_LONG (& tmp , pid );
533
+ zend_hash_update (disp -> name_to_dispid , Z_STR_P (value ), & tmp );
534
+ } ZEND_HASH_FOREACH_END ();
576
535
577
536
return (IDispatch * )disp ;
578
537
}
0 commit comments