|
RE: SWIG-PERL-Vector of pointers: msg#00125programming.swig
Luigi, It looks like the code generated by vector without the specialize_std_vector call causing some problems. For example, consider the following swig snippet %template (Byte_vector) std::vector<unsigned char>; Code generate for the get method (returns a reference). XS(_wrap_Byte_vector_get) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; { std::vector<unsigned char > *arg1 = (std::vector<unsigned char > *) 0 ; int arg2 ; unsigned char *result; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Byte_vector_get(self,i);"); } { if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_std__vectorTunsigned_char_t,0) < 0) { SWIG_croak("Type error in argument 1 of Byte_vector_get. Expected _p_std__vectorTunsigned_char_t"); } } arg2 = (int) SvIV(ST(1)); { try { { unsigned char &_result_ref = std_vectorlunsigned_char_g_get___(arg1,arg2); result = (unsigned char *) &_result_ref; } }catch (std::out_of_range& e) { SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what())); } } ST(argvi) = sv_newmortal(); SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_unsigned_char,0); XSRETURN(argvi); fail: (void) _swigerr; } croak(_swigerr); } NOW DEFINE namespace std { specialize_std_vector(unsigned char); }; %template (Byte_vector) std::vector<unsigned char>; The generated code for get method is XS(_wrap_Byte_vector_get) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; { std::vector<unsigned char > *arg1 = (std::vector<unsigned char > *) 0 ; int arg2 ; unsigned char result; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Byte_vector_get(self,i);"); } { if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_std__vectorTunsigned_char_t,0) < 0) { SWIG_croak("Type error in argument 1 of Byte_vector_get. Expected _p_std__vectorTunsigned_char_t"); } } arg2 = (int) SvIV(ST(1)); { try { result = (unsigned char)std_vectorlunsigned_char_g_get___(arg1,arg2); }catch (std::out_of_range& e) { SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what())); } } ST(argvi) = sv_newmortal(); sv_setuv(ST(argvi++), (UV) result); XSRETURN(argvi); fail: (void) _swigerr; } croak(_swigerr); } Why you need to specialize the basic types (such as int, float etc.)? Could you please suggest any other method of solving this issue ( by not using specialize method )? Thanks, -sanjay -----Original Message----- From: swig-admin@xxxxxxxxxxxxxxx [mailto:swig-admin@xxxxxxxxxxxxxxx] On Behalf Of Nair, Sanjay S Sent: Tuesday, November 18, 2003 1:37 PM To: luigi.ballabio@xxxxxxxxxxxxx Cc: swig@xxxxxxxxxxxxxxx Subject: RE: [Swig] SWIG-PERL-Vector of pointers Types generated by const and non const vectors are different %template (Byte_vector) std::vector<unsigned char>; int ABC( std::vector<unsigned char>& pvReadArray, const std::vector<unsigned char>& pvWriteArray); code generated for checking the type for pvReadArray is different that that of prWriteArray. I have the following prel code which fails to run because of the type error for pvWriteArray my $readVector; my $writeVector; my $result = XYZ::ABC( $readVector, $writeVector ); Any idea why the type checking is different? Thanks, -sanjay -----Original Message----- From: Luigi Ballabio [mailto:luigi.ballabio@xxxxxxxxxxxxx] Sent: Tuesday, November 18, 2003 8:56 AM To: Nair, Sanjay S Cc: luigi.ballabio@xxxxxxxxxxxxx; swig@xxxxxxxxxxxxxxx Subject: Re: [Swig] SWIG-PERL-Vector of pointers On 2003.11.18 17:30, "Nair, Sanjay S" wrote: > Do you have any perl example that uses Vector of pointers? I don't use Perl myself. Maybe among the examples in the distribution, but I'm not that sure... Cheers, Luigi _______________________________________________ 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: | unsatisfied link error on linux : java module: 00125, archana perumal |
|---|---|
| Next by Date: | Re: SWIG-PERL-Vector of pointers: 00125, Luigi Ballabio |
| Previous by Thread: | Re: SWIG-PERL-Vector of pointersi: 00125, Luigi Ballabio |
| Next by Thread: | Talking Perl to Java and Back: 00125, Jay Strauss |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |