Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError not being raised in SWIG 4 when making an improper ass… #1603

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

alexlin0
Copy link
Contributor

…ignment in input processor #1288

In convert_swig added a line to override the setattr function. This makes the new SWIG behave like older SWIG versions. the _swig_setattr_nondynamic_instance_variable function is provided by SWIG and is similar to what our version of _swig_setattr_nondynamic above is. If later we need to override _swig_setattr_nondynamic_instance_variable it can be done the same way as before.

…ignment in input processor #1288

In convert_swig added a line to override the __setattr__ function. This makes
the new SWIG behave like older SWIG versions. the _swig_setattr_nondynamic_instance_variable
function is provided by SWIG and is similar to what our version of _swig_setattr_nondynamic
above is. If later we need to override _swig_setattr_nondynamic_instance_variable it can
be done the same way as before.
@coveralls
Copy link

Coverage Status

coverage: 55.743%. remained the same when pulling 7bf88ca on NoAttributeError into 80f341f on master.

@sharmeye sharmeye added the Canaries For issues that need to be addressed in the future ;-) label Oct 31, 2023
@sharmeye sharmeye merged commit 763b52f into master Oct 31, 2023
11 checks passed
keithvetter added a commit that referenced this pull request May 17, 2024
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".
sharmeye pushed a commit that referenced this pull request Jul 16, 2024
* 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Canaries For issues that need to be addressed in the future ;-)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants