@@ -511,7 +511,12 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
511
511
if (sm ) {
512
512
/* Got a typemap. Need to only merge attributes for methods that match our signature */
513
513
Iterator ki ;
514
+ Hash * deferred_add ;
514
515
match = 1 ;
516
+
517
+ /* Since typemap_register can modify the `sm` hash, we *cannot* call typemap_register while iterating over sm.
518
+ * Create a temporary hash of typemaps to add immediately after. */
519
+ deferred_add = NewHash ();
515
520
for (ki = First (sm ); ki .key ; ki = Next (ki )) {
516
521
/* Check for a signature match with the source signature */
517
522
if ((count_args (ki .key ) == narg ) && (Strstr (ki .key , ssig ))) {
@@ -521,34 +526,36 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
521
526
Replace (nkey , ssig , dsig , DOH_REPLACE_ANY );
522
527
523
528
/* Make sure the typemap doesn't already exist in the target map */
524
-
525
529
oldm = Getattr (tm , nkey );
526
530
if (!oldm || (!Getattr (tm , "code" ))) {
527
531
String * code ;
528
- ParmList * locals ;
529
- ParmList * kwargs ;
530
532
Hash * sm1 = ki .item ;
531
533
532
534
code = Getattr (sm1 , "code" );
533
- locals = Getattr (sm1 , "locals" );
534
- kwargs = Getattr (sm1 , "kwargs" );
535
535
if (code ) {
536
+ Replace (nkey , dsig , "" , DOH_REPLACE_ANY );
537
+ Replace (nkey , "tmap:" , "" , DOH_REPLACE_ANY );
538
+ Setattr (deferred_add , nkey , sm1 );
539
+ }
540
+ Delete (nkey );
541
+ }
542
+ }
543
+ }
544
+
545
+ /* After assembling the key/item pairs, add the resulting typemaps */
546
+ for (ki = First (deferred_add ); ki .key ; ki = Next (ki )) {
547
+ Hash * sm1 = ki .item ;
536
548
String * src_str = ParmList_str_multibrackets (src );
537
549
String * dest_str = ParmList_str_multibrackets (dest );
538
550
String * source_directive = NewStringf ("apply %s { %s }" , src_str , dest_str );
539
551
540
- Replace (nkey , dsig , "" , DOH_REPLACE_ANY );
541
- Replace (nkey , "tmap:" , "" , DOH_REPLACE_ANY );
542
- typemap_register (nkey , dest , code , locals , kwargs , source_directive );
552
+ typemap_register (ki .key , dest , Getattr (sm1 , "code" ), Getattr (sm1 , "locals" ), Getattr (sm1 , "kwargs" ), source_directive );
543
553
544
554
Delete (source_directive );
545
555
Delete (dest_str );
546
556
Delete (src_str );
547
557
}
548
- }
549
- Delete (nkey );
550
- }
551
- }
558
+ Delete (deferred_add );
552
559
}
553
560
Delete (ssig );
554
561
Delete (dsig );
@@ -2090,14 +2097,22 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
2090
2097
Printf (stdout , "Swig_typemap_attach_parms: embedded\n" );
2091
2098
#endif
2092
2099
if (already_substituting < 10 ) {
2100
+ char * found_colon ;
2093
2101
already_substituting ++ ;
2094
2102
if ((in_typemap_search_multi == 0 ) && typemap_search_debug ) {
2095
2103
String * dtypemap = NewString (dollar_typemap );
2096
2104
Replaceall (dtypemap , "$TYPEMAP" , "$typemap" );
2097
2105
Printf (stdout , " Containing: %s\n" , dtypemap );
2098
2106
Delete (dtypemap );
2099
2107
}
2100
- Swig_typemap_attach_parms (tmap_method , to_match_parms , f );
2108
+ found_colon = Strstr (tmap_method , ":" );
2109
+ if (found_colon ) {
2110
+ String * temp_tmap_method = NewStringWithSize (Char (tmap_method ), found_colon - Char (tmap_method ));
2111
+ Swig_typemap_attach_parms (temp_tmap_method , to_match_parms , f );
2112
+ Delete (temp_tmap_method );
2113
+ } else {
2114
+ Swig_typemap_attach_parms (tmap_method , to_match_parms , f );
2115
+ }
2101
2116
already_substituting -- ;
2102
2117
2103
2118
/* Look for the typemap code */
0 commit comments