Skip to content

Commit

Permalink
Added _swig_setattr_nondynamic_instance_variable function call back f…
Browse files Browse the repository at this point in the history
…or struct and moved it to right after struct declaration instead of at the end of the swig interface file. (#1795)
  • Loading branch information
hchen99 authored Oct 15, 2024
1 parent 48029fe commit 5a5379b
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions libexec/trick/convert_swig
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,6 @@ sub process_file() {
print OUT "$contents\n" ;
print OUT $global_template_typedefs ;

# Add _swig_setattr_nondynamic_instance_variable function for raising AttributeError for improper non-class attribute assingment in input processor.
# _swig_setattr_nondynamic_instance_variable function is added for each class in process_class subroutine.
foreach my $c ( @class_names ) {
if ( ! exists $class_typemap_printed{$c} ) {
my $c_ = $c ;
$c_ =~ s/\:/_/g ;
if ( $c !~ /::/ ) {
print OUT "\n#if SWIG_VERSION > 0x040000\n";
print OUT "%pythoncode %{\n" ;
print OUT " if '$c' in globals():\n";
print OUT " $c.__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n" ;
print OUT "%}\n" ;
print OUT "#endif\n";
}
}
}

# Add a trick_cast_as macro line for each class parsed in the file. These lines must appear at the bottom of the
# file to ensure they are not in a namespace directive and they are after the #define statements they depend on.
undef %class_typemap_printed ;
Expand Down Expand Up @@ -785,7 +768,7 @@ sub process_typedef_struct($$$$) {
my ($typedef_struct_string , $contents_ref, $new_contents_ref , $class_names_ref) = @_ ;

my $extracted ;
my ($tail , $struct_names, @struct_names) ;
my ($tail , $my_struct_contents, $struct_names, @struct_names) ;

#print "*** typedef_struct_string = $typedef_struct_string ***\n" ;

Expand All @@ -811,10 +794,12 @@ sub process_typedef_struct($$$$) {
foreach my $s ( @struct_names ) {
if ( $s !~ /\*/ ) {
push @$class_names_ref , $s ;
# Add _swig_setattr_nondynamic_instance_variable function for raising AttributeError for improper struct attribute assingment in input processor
$my_struct_contents .= "\n#if SWIG_VERSION > 0x040000\n\%pythoncode \%{\n if '$s' in globals():\n $s.__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n\%}\n#endif\n" ;
}
}

$$new_contents_ref .= $extracted . $tail ;
$$new_contents_ref .= $extracted . $tail . $my_struct_contents ;

}

Expand Down

0 comments on commit 5a5379b

Please sign in to comment.