|
RE: SWIG-PERL-Vector of pointers: msg#00102programming.swig
Hi Luigi, Thanks for replying. If I don't use specialize, the code generated does not contain the type information. If you write the perl code to pass this vector, it gives the following error: Type error in argument 3 of ItpBreakpointSLIProxy_ReadBp. Expected _p_SBSD__BpDa taStruct_SLI_vector at x.pl line 44. I have the following swig code %module SbsdSLI %include "std_vector.i" %template (Int_vector) std::vector<int>; typedef std::vector<int> Int_vector; //namespace std { // specialize_std_vector(SBSD::BpDataStruct_SLI); //} namespace SBSD { struct BpDataStruct_SLI{ long type; }; typedef std::vector<BpDataStruct_SLI> BpDataStruct_SLI_vector; class ItpBreakpointSLIProxy { int ReadBp ( const Int_vector& vReadData, BpDataStruct_SLI_vector& vReadData ); }; }; I have the following SWIG generated code XS(_wrap_ItpBreakpointSLIProxy_ReadBp) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; { SBSD::ItpBreakpointSLIProxy *arg1 = (SBSD::ItpBreakpointSLIProxy *) 0 ; Int_vector *arg2 = 0 ; SBSD::BpDataStruct_SLI_vector *arg3 = 0 ; int result; int argvi = 0; dXSARGS; if ((items < 3) || (items > 3)) { SWIG_croak("Usage: ItpBreakpointSLIProxy_ReadBp(self,vReadData,vReadData);"); } { if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_SBSD__ItpBreakpointSLIProxy,0) < 0) { SWIG_croak("Type error in argument 1 of ItpBreakpointSLIProxy_ReadBp. Expected _p_SBSD__ItpBreakpointSLIProxy"); } } { if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_Int_vector,0) < 0) { SWIG_croak("Type error in argument 2 of ItpBreakpointSLIProxy_ReadBp. Expected _p_Int_vector"); } } { if (SWIG_ConvertPtr(ST(2), (void **) &arg3, SWIGTYPE_p_SBSD__BpDataStruct_SLI_vector,0) < 0) { SWIG_croak("Type error in argument 3 of ItpBreakpointSLIProxy_ReadBp. Expected _p_SBSD__BpDataStruct_SLI_vector"); } } result = (int)(arg1)->ReadBp((Int_vector const &)*arg2,*arg3); ST(argvi) = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result); XSRETURN(argvi); fail: (void) _swigerr; } croak(_swigerr); } if you look at the /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ section of the generated file, It generates different code for Vector of structs and Vector of ints. static swig_type_info _swigt__p_Int_vector[] = {{"_p_Int_vector", 0, "Int_vector &", 0},{"_p_Int_vector"},{"_p_std__vectorTint_t"},{0}}; // 4 params static swig_type_info _swigt__p_SBSD__BpDataStruct_SLI_vector[] = {{"_p_SBSD__BpDataStruct_SLI_vector", 0, "SBSD::BpDataStruct_SLI_vector &", 0},{"_p_SBSD__BpDataStruct_SLI_vector"},{0}}; // ONLY 3 params!!! I tried to use this by writing the following perl code. use SbsdSLI; use strict; my $intVector = SbsdSLI::new_Int_vector(); my $bpDataStructVector = SbsdSLI::new_BpDataStruct_SLI_vector(); $hResult = SbsdSLI::ItpBreakpointSLIProxy_ReadBp( $itpBreakpointProxy, $intVector, $bpDataStructVector ); And this line gives Type error in argument 3 of ItpBreakpointSLIProxy_ReadBp. Expected _p_SBSD__BpDa taStruct_SLI_vector at x.pl line xx. When I use the specialize code the generated file for BpDataStruct_SLI_vector looks as: static swig_type_info _swigt__p_SBSD__BpDataStruct_SLI_vector[] = {{"_p_SBSD__BpDataStruct_SLI_vector", 0, "SBSD::BpDataStruct_SLI_vector &", 0},{"_p_SBSD__BpDataStruct_SLI_vector"},{"_p_std__vectorTSBSD__BpDataStr uct_SLI_t"},{0}}; // 4 params Clearly there is a difference between the generated code with and without the specialize statement. Is the namespace is causing any problems? Also, do you support Vector of pointers in SWIG? If yes, could you please let me know how to use it? Your help will be much appreciated. Thanks, -sanjay -----Original Message----- From: Luigi Ballabio [mailto:luigi.ballabio@xxxxxxxxxxxxx] Sent: Saturday, November 15, 2003 5:34 AM To: Nair, Sanjay S Cc: swig@xxxxxxxxxxxxxxx Subject: Re: [Swig] SWIG-PERL-Vector of pointers On 2003.11.15 01:55, "Nair, Sanjay S" wrote: > Hi, > > I have a structure defined and my .i file has following entries: > > %module SLI > namespace std { > specialize_std_vector(ABC::BpDataStruct_SLI*); > } Don't do this. specialize_std_vector is a macro which is only used for built-in types and it's an implementation detail. You shouldn't even know it exists---because if you did, you could instantiate it with the wrong number of arguments, as above, and you could get all kinds of weird syntax errors :) The rest of the file looks ok to me. Let me know if the problem persists. Also, there was a bug in SWIG 1.3.19 which could give you problems if a vector was returned from a function by copy. That will be fixed in SWIG 1.3.20, soon in a website near you. Hope this helps, Luigi _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re[3]: %include: 00102, Kerim Borchaev |
|---|---|
| Next by Date: | Re: SWIG-PERL-Vector of pointers: 00102, Luigi Ballabio |
| Previous by Thread: | Re: SWIG-PERL-Vector of pointersi: 00102, Luigi Ballabio |
| Next by Thread: | Re: SWIG-PERL-Vector of pointers: 00102, Luigi Ballabio |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |