trick/trick_source/trick_swig
Keith Vetter f2e93ac490
Fix for assigning to non-existent variables (#1708) (#1718)
* Fix for assigning to non-existent variables (#1708)

This fix modifies Trick's convert_swig script.  It
adds a directive to not accept dynamic attributes.
The directive will ensure that modelers do not
assign to non-existent parameter in their input files.

The prior fix (issues #1288 and/or #1603) did not
cover C structures, so this commit is really an
addendum to that fix.  With this commit, the convert_swig
script will generate a non-dynamic directive foreach
class and structure.

This fix also stops generating swig interface code
for typedef structure definitions since swig only
produces an interface to the actual typedef name.
For example, with this typedef:

typedef struct StructureName {
   double  main_engine_thrust;  /* N Thrust of main engine */
   struct StructureName* next;  /* ** Next pointer */
} TypeDefName;

swig creates an interface for "TypeDefName", and not
"StructureName", so there is no need for Trick to
produce anything in regards "StructureName".

* Fix for issue with classes defined in ifndef SWIG block

convert_swig takes in the raw header and does no preprocessing,
so blocks of c/c++ header code which are meant to be skipped
by Swig are processed by convert_swig.  This causes an issue
with the generated python code that try to access classes
that are ifndef SWIGed out.

To fix this, check for class existence in the generated python
code e.g:

if 'MomMom' in globals():
    MomMom.__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)

* Fix for assignment to swig_double and swig_int primitives

The previous commit(s) on this branch fixed bad assignments
like (misspell position an attribute of BSTATE_IN):
ball.state.input.positiaaaan = 4.0

This commit fixes bad assignments to leaf/primitive attributes
like (try to add attribute to primitive/leaf double type):

ball.state.input.position.fred = 4.0

* Moved _swig_setattr_nondynamic_instance_variable to right after each class in process_class and removed duplicate _swig_setattr_nondynamic_instance_variable blocks for classes that are not in a namespace.

* Add the call for __setattr__ for class templates.

---------

Co-authored-by: Hong Chen <hong.chen-1@nasa.gov>
2024-07-16 10:34:02 -05:00
..
.gitignore Initial commit of everything. 2015-02-26 09:02:31 -06:00
extra_functions.i Use udunits package for units conversions 2016-05-09 08:36:43 -05:00
Makefile Ensure swig target folder is created (#1533) 2023-07-13 13:44:29 -05:00
PrimitiveAttributesMap.cpp Pre-increment (rather than post-increment) STL iterators in for loops… (#1692) 2024-04-18 11:41:35 -05:00
sim_services.i checksum enhancement for -d option (#1579) 2023-10-05 10:56:02 -05:00
swig_convert_units.cpp Use udunits package for units conversions 2016-05-17 09:01:37 -05:00
swig_double.cpp Replace sprintf with snprintf in all of Trick source. #1384 (#1392) 2022-11-15 15:00:05 -06:00
swig_double.i Fix for assigning to non-existent variables (#1708) (#1718) 2024-07-16 10:34:02 -05:00
swig_global_vars.cpp Remove trailing whitespaces 2016-11-08 10:25:07 +01:00
swig_int.cpp Replace sprintf with snprintf in all of Trick source. #1384 (#1392) 2022-11-15 15:00:05 -06:00
swig_int.i Fix for assigning to non-existent variables (#1708) (#1718) 2024-07-16 10:34:02 -05:00
swig_ref.cpp Support using Python 3 2016-06-28 13:44:21 -05:00
swig_ref.i Trick swig headers don't make it to the destination directory with make install 2015-06-17 14:07:52 -05:00
units_attach.i Update swig interface to work python 3.11 (#1486) 2023-04-11 13:14:30 -05:00