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

Anonymous struct arrays in namespace #1351

Open
ninotarantino opened this issue Sep 27, 2022 · 1 comment
Open

Anonymous struct arrays in namespace #1351

ninotarantino opened this issue Sep 27, 2022 · 1 comment

Comments

@ninotarantino
Copy link

There's an issue when trying to index into an array of anonymous structs when the datatype is a struct within a namespace. Not sure if this is SWIG's fault or possibly ICG.

SWIG version: 3.0.12
Trick version: 19.3.1
GCC version: 7.5.0

Example

test.hh:

#ifndef _TEST_HH_
#define _TEST_HH_

namespace nino {

typedef struct {
    double num[3][5]; /* (--) Test */
    double den[3][5]; /* (--) Test */
} FilterCoeffs;

typedef struct {
    FilterCoeffs filters[4]; /* (--) Test */
} Control;

} // namespace nino

#endif // _TEST_HH_

S_define:

#include "sim_objects/default_trick_sys.sm"
##include "test.hh"

class FilterSimObject : public Trick::SimObject {
    public:
        nino::Control control; /* (--) Test */

        FilterSimObject() {
        }
};
FilterSimObject filter;

Input file:

filter.control.filters[0].num[0] = [1,2,3,4,5]

Outputs

I get the following error when trying to run this unit sim:

Traceback (most recent call last): 
File "RUN_test/input.py", line 3, in <module>
filter.control.filters[0].num[0] = [1,2,3,4,5]
TypeError: 'FilterCoeffs' object does not support indexing

Other notes

This code does work when the FilterCoeffs struct isn't in a namespace, or if it's a class. The workaround right now is to not use C-style struct definitions and instead do

struct MyType {
    // data
};

I messaged Scott about this earlier this year so I thought I'd document it here. It can be a pain to track down.

@jdeans289
Copy link
Contributor

This is being addressed by a refactor of ICG. We will update this issue once it has been completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants