From: William S F. <ws...@fu...> - 2008-01-24 21:53:16
|
Nitro wrote: > I did some experimentation on this, below is my interface file I used > for testing (1.3.31, hope that doesn't make a difference). > > The problem appears because the const and non-const versions trigger > different templates in std/std_vector.i. The const version uses the > first template defined in this file, the non-const version uses the > lower one which is tagged with this note: > > // *** > // This specialization should dissapear or get simplified when > // a 'const SWIGTYPE*&' can be defined > // *** > > The difference between those templates is that they generate different > traits each. The trait that needs to be presented in the final file is > > namespace swig { > template <> struct traits<Calendar > { > typedef pointer_category category; > static const char* type_name() { return"Calendar"; } > }; > } > > The fix marcelo checked in makes sure that "const* type" resolve to the > "type" trait. Now the const version generates an improper trait for > "const* type". That's why the compiler will later complain that it can't > find the type_name() for Calendar as there is only a trait for const > Calendar*. > The two lines in the code below fix the problem apparently. The > generated code compiles fine and I can load the wrapper. I can do this: > > import problem > v = problem.VectCalendar() > problem.foo(v) > > and it will print "foo called". > Doing > > c = problem.Calendar() > problem.append(c) > shouldn't this read v.append(c) ? I think that the const Calendar * container should be different to the non-const one. They are separate beasts in the Java/C# modules, so we may as well keep that consistent. However, adding to the container should be possible. > does not work, because Calendar is not a const Calendar (I guess). I am > not sure if this is supposed to work at all. Maybe you can comment on > this. > > Finally, I am not sure whether this "fix" only fixes the apparent > problem or if there's a much deeper problem with const vectors somewhere > under the covers. > Matthias, this is great. I'll try this out tomorrow, but meanwhile is there any chance of making a patch to pycontainers.swg so that it is fixed for everyone and then I can test it on the entire test-suite? William |