#271 Make java vector iterable

closed
nobody
general (37)
5
2012-01-13
2011-06-23
No

Discussion

  • Volker Diels-Grabsch

    I'm the author of this patch. Thanks to Mathieu for providing it here.

    The patch does not only make the Vector wrapper iterable, it provides the full java.util.List<> interface for it. The test suite has been extended accordingly to check all those add/remove/iteration/... methods.

    The tests ran well on SWIG 2.0.2, and I just confirmed that they still succeed on SWIG 2.0.4 using the following command:

    make check-java-examples check-java-test-suite

    The patch has been used in production for months and we haven't had any issues with it.

    I also tried to run the whole test suite (make check), but it failed somewhere within the Python checks. It didn't even succeed for the unmodified SWIG-2.0.4, so this issue is not related to this patch. I opened a separate entry for that issue: https://sourceforge.net/tracker/?func=detail&aid=3391906&group_id=1645&atid=101645

    Regards,
    Volker

     
  • Volker Diels-Grabsch

    Whoops, I overlooked a failed Java test case, which can be reproduced via the following command:

    make -s -C Examples/test-suite/java li_boost_shared_ptr_bits.cpptest

    checking testcase li_boost_shared_ptr_bits (with run test) under java
    ./li_boost_shared_ptr_bits_runme.java:16: cannot find symbol
    symbol : method add(li_boost_shared_ptr_bits.IntHolder)
    location: class li_boost_shared_ptr_bits.VectorIntHolder
    v.add(new IntHolder(11));
    ^
    ./li_boost_shared_ptr_bits_runme.java:17: cannot find symbol
    symbol : method add(li_boost_shared_ptr_bits.IntHolder)
    location: class li_boost_shared_ptr_bits.VectorIntHolder
    v.add(new IntHolder(22));
    ^
    ./li_boost_shared_ptr_bits_runme.java:18: cannot find symbol
    symbol : method add(li_boost_shared_ptr_bits.IntHolder)
    location: class li_boost_shared_ptr_bits.VectorIntHolder
    v.add(new IntHolder(33));
    ^
    3 errors

    The reason is simply a missing call to SWIG_STD_VECTOR_ENHANCED() which is necessary to instantiate the Java part of the VectorIntHolder wrapper, as defined in "Examples/test-suite/li_boost_shared_ptr_bits.i":

    %template(VectorIntHolder) std::vector< boost::shared_ptr<IntHolder> >;

    So all we need is prepending the missing call to SWIG_STD_VECTOR_ENHANCED():

    #if defined(SWIGJAVA)
    SWIG_STD_VECTOR_ENHANCED(boost::shared_ptr<IntHolder>)
    #endif
    %template(VectorIntHolder) std::vector< boost::shared_ptr<IntHolder> >;

    However, this produces a syntax error.

    ../../../../Examples/test-suite/li_boost_shared_ptr_bits.i:50: Error: Syntax error in input(1).

    So how am I supposed to solve that issue in SWIG? It works if I introduce a dummy typedef "SharedPtrIntHolder":

    %inline %{
    typedef boost::shared_ptr<IntHolder> SharedPtrIntHolder;
    %}
    #if defined(SWIGJAVA)
    SWIG_STD_VECTOR_ENHANCED(SharedPtrIntHolder)
    #endif
    %template(VectorIntHolder) std::vector<SharedPtrIntHolder>;

    But is that the intended way to solve this issue?

    Any advice would be appreciated. I'd then propose an improved patch which fixes this test case. All other Java test cases ran fine.

    Regards,
    Volker

     
  • Volker Diels-Grabsch

    Since I got no advice in the last two days, I just went ahead and solved the boost::shared_ptr<> using the mentioned typedef. Unfortunately, I'm not allowed to upload the improved patch to this tracker entry. That's why I opened a new one for it: https://sourceforge.net/tracker/?func=detail&aid=3393025&group_id=1645&atid=301645

    Please close this tracker entry, as the attached patch is outdated by now.

     
  • Vadim Zeitlin

    Vadim Zeitlin - 2012-01-13

    Superseded by 3393025, closing as requested.

     
  • Vadim Zeitlin

    Vadim Zeitlin - 2012-01-13
    • status: open --> closed
     

Log in to post a comment.