Yarp: [Bindings] New template definition `Vector` is shadowing previous extensions of yarp::sig::Vector

Created on 20 Jul 2018  路  5Comments  路  Source: robotology/yarp

Describe the bug
We run in Matlab the following commands for creating and reading a yarp Vector:

>> aVec=yarp.Vector(3)

aVec = 

  3 Vector array with no properties.

>> aVec.get(0)
No appropriate method, property, or field 'get' for class
'yarp.Vector'.

Error in SwigRef/subsref (line 33)
        [varargout{1:nargout}] = builtin('subsref',self,s);

Initial comments here by @lrapetti who spotted the issue.

To Reproduce
Robotology-superbuild with compiled Yarp bindings.

Expected behavior
Matlab should return an empty value or 0 instead of an error.

Configuration (please complete the following information):

Root cause
The line https://github.com/robotology/yarp/blob/15c3328681fc8d3da5bb3bef76d686b8fbc81d64/bindings/yarp.i#L567 is shadowing the further extensions (%extend) of the class yarp::sig::Vector, such that the extra get, set, fromMatlab, toMatlab method definitions are ignored.
For more details, please refer to the analysis here.

Bindings YARP v3.1.0 Bug Fixed

Most helpful comment

Some explanations

After trying several combinations of:

  • masking or not of the typedef in yarp/sig/Vector.h (SWIG flag),
  • adding, removing or moving the line %template(Vector) yarp::sig::VectorOf<double> in yarp.i,
  • in yarp.i, replacing the instances of yarp::sig::Vector by the defined template Vector,
  • in yarp.i, replacing the instances of yarp::sig::Vector by yarp::sig::VectorOf<double> which is a straightforward solution but I wanted to avoid it,

I came to the following conclusions:

The simplest solution is to use directly yarp::sig:VectorOf<double> instead of yarp::sig:Vector in yarp.i. But this means we have to keep this in mind every time we use the pattern wrapping a class instance like https://github.com/robotology/yarp/blob/15c3328681fc8d3da5bb3bef76d686b8fbc81d64/src/libYARP_sig/include/yarp/sig/Vector.h#L36

All 5 comments

This issue was introduced by https://github.com/robotology/yarp/commit/2417c7d5e50aebca2ca8532fb40e7084262d50e8.
Hi @Nicogene , because of this code:
https://github.com/robotology/yarp/blob/15c3328681fc8d3da5bb3bef76d686b8fbc81d64/src/libYARP_sig/include/yarp/sig/Vector.h#L25-L39
SWIG doesn't see the typedef and so no Vector class is defined under the yarp::sig namespace and all lines regarding that class in yarp.i are ignored. Any ideas to fix this are welcome.

Some explanations

After trying several combinations of:

  • masking or not of the typedef in yarp/sig/Vector.h (SWIG flag),
  • adding, removing or moving the line %template(Vector) yarp::sig::VectorOf<double> in yarp.i,
  • in yarp.i, replacing the instances of yarp::sig::Vector by the defined template Vector,
  • in yarp.i, replacing the instances of yarp::sig::Vector by yarp::sig::VectorOf<double> which is a straightforward solution but I wanted to avoid it,

I came to the following conclusions:

The simplest solution is to use directly yarp::sig:VectorOf<double> instead of yarp::sig:Vector in yarp.i. But this means we have to keep this in mind every time we use the pattern wrapping a class instance like https://github.com/robotology/yarp/blob/15c3328681fc8d3da5bb3bef76d686b8fbc81d64/src/libYARP_sig/include/yarp/sig/Vector.h#L36

Reopening since #1811 is not merged yet.
@nunoguedelha Please, do not close issues until the relative PR is merged...

Reopening since #1811 is not merged yet.
@nunoguedelha Please, do not close issues until the relative PR is merged...

@drdanz sure, sorry for that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drdanz picture drdanz  路  3Comments

jeljaik picture jeljaik  路  3Comments

lornat75 picture lornat75  路  4Comments

drdanz picture drdanz  路  3Comments

diegoferigo picture diegoferigo  路  3Comments