|
Re[2]: Directors and passing args by value.: msg#00127programming.swig
Hello Mark, MR> Ok. I had to change the (python) director method generator slightly MR> to handle enum returns, and I want to run some tests before checking MR> in the new code. Good motivation to finally write that typemap MR> regression test I guess. I tried to create typemap by myself: %typemap(directorout) enum SWIGTYPE "$result = ($1_type) PyInt_AsLong($input);" This produces code like this: E SwigDirector_C::method() { int c_result ; PyObject *result; if (swig_get_up()) { return C::method(); } result = PyObject_CallMethod(swig_get_self(), "method", NULL); c_result = (E) PyInt_AsLong(result); Py_XDECREF(result); return c_result; } That doesn't compile: ... : error C2440: 'return' : cannot convert from 'int' to 'E' Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast) Could you tell me what your solution is? Best regards, Kerim mailto:warkid@xxxxxxxxx Tuesday, November 18, 2003, 7:44:44 PM, you wrote: MR> Cheers, MR> Mark MR> On Tue, Nov 18, 2003 at 05:10:43PM +0300, Kerim Borchaev wrote: >> I'm sorry - I've mistaken. Passing enum to function is ok. >> Returning - this is what doesn't work. >> >> Best regards, >> Kerim mailto:warkid@xxxxxxxxx >> >> Tuesday, November 18, 2003, 3:46:36 PM, you wrote: >> >> KB> Hello. >> >> KB> I've uncommented that "dangerous" typemap;-) It works well except >> KB> it doesn't work with enums. >> KB> What could I do to make it handle them? >> >> KB> Thanks. >> KB> Kerim mailto:warkid@xxxxxxxxx >> >> KB> Tuesday, November 18, 2003, 10:28:21 AM, you wrote: >> >> MR>> I actually added the typemap to do this to python.swg many >> MR>> months ago, but commented it out with the note "this is rather >> MR>> dangerous." ;-) I probably should have been more explicit at >> MR>> that time, since I can't remember now exactly what concerned >> MR>> me about it (other than the possibility of the python method >> MR>> hanging on to references to its arguments). Maybe there's >> MR>> nothing terribly wrong with that typemap as it stands, or >> MR>> maybe there's another approach that would be safer. Any >> MR>> typemap/object ownership gurus care to comment? >> >> MR>> Mark >> >> >> MR>> On Mon, Nov 17, 2003 at 12:08:20PM +0300, Kerim Borchaev wrote: >> >>> Hello. >> >>> >> >>> I've checked CVS version and now it seems that directors aren't >> >>> generated for methods with args passed by value. Any plans to >> >>> support it? >> >>> >> >>> Best regards, >> >>> Kerim mailto:warkid@xxxxxxxxx >> >>> >> >>> Thursday, November 13, 2003, 8:16:02 PM, you wrote: >> >>> >> >>> MR> Hi Kerim, >> >>> >> >>> MR> What version of SWIG are you using? SWIG cvs parses your >> >>> MR> interface without any warnings on my machine, and does the >> >>> MR> right thing in the python test. Note that if you ever get >> >>> MR> warning 461, SWIG will not generate any director stubs for >> >>> MR> the method. So the result you get in your Python test is >> >>> MR> understandable, and the only question is what is causing the >> >>> MR> warning. >> >>> >> >>> MR> Cheers, >> >>> MR> Mark >> >>> >> >>> >> >>> MR> On Thu, Nov 13, 2003 at 05:55:55PM +0300, Kerim Borchaev wrote: >> >>> >> Hello swig, >> >>> >> >> >>> >> SWIG doesn't wrap for directors methods that return objects by >> >>> >> value? >> >>> >> >> >>> >> This code: >> >>> >> //main.i >> >>> >> %module(directors="1") test >> >>> >> >> >>> >> %feature("director"); >> >>> >> %inline %{ >> >>> >> struct D{ >> >>> >> int value; >> >>> >> }; >> >>> >> >> >>> >> struct C{ >> >>> >> virtual ~C(){} >> >>> >> virtual D method(){ >> >>> >> D d; >> >>> >> d.value = 7; >> >>> >> return d; >> >>> >> } >> >>> >> }; >> >>> >> >> >>> >> int getValue(C&o){ >> >>> >> D d = o.method(); >> >>> >> return d.value; >> >>> >> } >> >>> >> %} >> >>> >> ////////////////////////// >> >>> >> >> >>> >> Produces this warning: >> >>> >> >> >>> >> main.i:29: Warning(461): Unable to return type D in director method >> >>> >> C::method (s >> >>> >> kipping method). >> >>> >> >> >>> >> And works like this: >> >>> >> >> >>> >> Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] >> >>> >> on win32 >> >>> >> Type "help", "copyright", "credits" or "license" for more information. >> >>> >> >>> import test >> >>> >> >>> from test import * >> >>> >> >>> class Derived(C): >> >>> >> ... def method(self): >> >>> >> ... d = D() >> >>> >> ... d.value = 13 >> >>> >> ... return d >> >>> >> ... >> >>> >> >>> getValue(Derived())#should return 13 >> >>> >> 7 >> >>> >> >> >>> >> >> >>> >> >> >>> >> Best regards, >> >>> >> Kerim mailto:warkid@xxxxxxxxx >> >>> >> >> >>> >> >> >>> >> _______________________________________________ >> >>> >> Swig maillist - Swig@xxxxxxxxxxxxxxx >> >>> >> http://mailman.cs.uchicago.edu/mailman/listinfo/swig >> >>> >> >>> >> >> >> KB> _______________________________________________ >> KB> Swig maillist - Swig@xxxxxxxxxxxxxxx >> KB> http://mailman.cs.uchicago.edu/mailman/listinfo/swig >> >> >> _______________________________________________ >> Swig maillist - Swig@xxxxxxxxxxxxxxx >> http://mailman.cs.uchicago.edu/mailman/listinfo/swig _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: SWIG-PERL-Vector of pointers: 00127, Luigi Ballabio |
|---|---|
| Next by Date: | Re: Directors and passing args by value.: 00127, Mark Rose |
| Previous by Thread: | Re: Directors and passing args by value.i: 00127, Mark Rose |
| Next by Thread: | Re: Directors and passing args by value.: 00127, Mark Rose |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |