From: William S F. <ws...@fu...> - 2009-09-11 18:53:44
|
Adriaan, the 3 argument version of memmove you see is 'transformed' into the 2 argument version via the multi-argument typemap in cdata.swg or cdata.i: %typemap(in) (const void *indata, size_t inlen) = (char *STRING, size_t SIZE); This typemap had an error in it and was introduced some while back with some changes using int instead of size_t as the type was made. It is fixed now in svn. William Adriaan Renting wrote: > L.S. > > I've done some more investigation on the problem on memmove I had earlier. I have now narrowed it down to a difference on how SWIG Generates the wrapper function for memmove. > I have now posted to both swig-devel and swig-user while my earlier message was only to swig-user (I provided a copy at the bottom of this mail). My apologies if I wasn't supposed to do that. It seems quite a low level problem and I didn't get any replies in swig-user last week, so this question might be better suited for swig-devel. It's also not a new problem, given what I found in the mailing list archives and internet, but I found no solution. > > This is my problem: > > This code is in cdata.i for all swig versions I have (1.3.21 and 1.3.22 and 1.3.24 and 1.3.35) > ---------cdata.i---------------------------------------- > void memmove(void *data, const void *indata, int inlen); > ------------------------------------------------------- > > This is what the latest documentation for SWIG 1.3 on cdata.i says: > ------------ http://www.swig.org/Doc1.3/SWIGDocumentation.html#Library_nn7 -------- > void memmove(void *ptr, char *s) > ----------------------------------------------------------------------------- > > Now when I generate a wrapper with the older SWIG versions (1.3.21 and 1.3.22 and 1.3.24) > I get something that translates memmove(&obj0,&obj1) into memmove(arg1,(void const *)arg2,arg3) just like the documentation says. > But on the new SWIG (1.3.35), I get a straight wrapper around memmove(&obj0,&obj1,&obj2) with thee arguments instead of two. > See examples below. > > My question is if anyone can explain to me how the versions of SWIG can generate the different code below from the same cdata.i > and how to get it to generate the code for the memmove(void *ptr, char *s) that is in the documentation or why it doesn't do that any more. > > Thanks for any help, > > Adriaan Renting > > -------------------------old SWIG 1.3.2x---------------------------------------------------- > static PyObject *_wrap_memmove(PyObject *self, PyObject *args) { > PyObject *resultobj; > void *arg1 = (void *) 0 ; > void *arg2 = (void *) 0 ; > int arg3 ; > PyObject * obj0 = 0 ; > PyObject * obj1 = 0 ; > > if(!PyArg_ParseTuple(args,(char *)"OO:memmove",&obj0,&obj1)) goto fail; > if ((SWIG_ConvertPtr(obj0,(void **) &arg1, 0, SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; > { > arg2 = (void *) PyString_AsString(obj1); > arg3 = (int) PyString_Size(obj1); > } > memmove(arg1,(void const *)arg2,arg3); > > Py_INCREF(Py_None); resultobj = Py_None; > return resultobj; > fail: > return NULL; > } > ----------------------------------------------------------------------------------------- > > -----------------------new SWIG 1.3.35---------------------------------------------------- > SWIGINTERN PyObject *_wrap_memmove(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { > PyObject *resultobj = 0; > void *arg1 = (void *) 0 ; > void *arg2 = (void *) 0 ; > size_t arg3 ; > int res1 ; > int res2 ; > size_t val3 ; > int ecode3 = 0 ; > PyObject * obj0 = 0 ; > PyObject * obj1 = 0 ; > PyObject * obj2 = 0 ; > > if (!PyArg_ParseTuple(args,(char *)"OOO:memmove",&obj0,&obj1,&obj2)) SWIG_fail; > res1 = SWIG_ConvertPtr(obj0,SWIG_as_voidptrptr(&arg1), 0, 0); > if (!SWIG_IsOK(res1)) { > SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "memmove" "', argument " "1"" of type '" "void *""'"); > } > res2 = SWIG_ConvertPtr(obj1,SWIG_as_voidptrptr(&arg2), 0, 0); > if (!SWIG_IsOK(res2)) { > SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "memmove" "', argument " "2"" of type '" "void const *""'"); > } > ecode3 = SWIG_AsVal_size_t(obj2, &val3); > if (!SWIG_IsOK(ecode3)) { > SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "memmove" "', argument " "3"" of type '" "size_t""'"); > } > arg3 = (size_t)(val3); > memmove(arg1,(void const *)arg2,arg3); > resultobj = SWIG_Py_Void(); > return resultobj; > fail: > return NULL; > } > ----------------------------------------------------------------------------------------- > > > > Adriaan Renting | Email: re...@as... > Software Engineer Radio Observatory > ASTRON | Phone: +31 521 595 100 (797 direct) > P.O. Box 2 | GSM: +31 6 24 25 17 28 > NL-7990 AA Dwingeloo | FAX: +31 521 595 101 > The Netherlands | Web: http://www.astron.nl/~renting/ > > > > > > >>> My earlier message on the problem from [Swig-user]: >>>> On Fri, Sep 4, 2009 at 1:36 PM, in message "[Swig-user] Documentation on memmove and cdata.i implementation don't match", > "Adriaan Renting" wrote: > >> I have some older code I inherited that was originally used with swig >> 1.3.24. I am now trying to use it with swig 1.3.35. The project wraps C code >> for use in Python. >> >> The code uses the memmove funcion. It works on the old system and according >> to the Documentation here: >> http://www.swig.org/Doc1.3/SWIGDocumentation.html#Library_nn7 >> | >> | void memmove(void *ptr, char *s) >> | Copies all of the string data in s into the memory pointed to by >> ptr. The string may contain embedded NULL bytes. >> | The length of the string is implicitly determined in the underlying >> wrapper code." >> | >> On the newer system the code fails with the error: "memmove() takes exactly >> 3 arguments (2 given)" >> >> If I look into cdata.i I see this both in the old 1.3.24 and the new 1.3.35 >> | >> | void memmove(void *data, const void *indata, int inlen); >> | >> So it seems that the function didn't change. I'm stuck because I can't >> figure out how "void memmove(void *ptr, char *s)" works on the older system >> or how to change the Python code to use the newer version. I've also looked >> in /usr/share/swig/1.3.24/python to see if it might be something specific to >> that language, nothing special seems to be in pyswigtype.swg or any of the >> other files. I've also tried searching the bugs database at sourceforge. >> >> It seems that there used to be a separate version of memmove that used a >> char* and didn't need the lenght. It also seems that the documentation in >> http://www.swig.org/Doc1.3/SWIGDocumentation.html#Library_nn7 has not been >> updated since that got changed or removed. >> >> I've done a search on the internet and this mailing list, and found several >> others with the same problem, but no replies or solutions: >> http://www.nabble.com/Using-cdata.i-memmove-function-with-a-Python-string-td22878497 >> .html >> http://article.gmane.org/gmane.comp.programming.swig/14333/match=memmove >> http://article.gmane.org/gmane.comp.programming.swig/10700/match=memmove >> >> The newer system also uses Python 2.5 instead of 2.4, which might be >> connected to this issue, as 2.5 contains ctypes, which also has a memmove >> function, but my knowledge of python doesn't go that far, I'm just mentioning >> it in case it's relevant. >> >> Is there anyone who can confim the documentation is out of date, or that >> there is a bug so that the function described there no longer works? >> >> I'm stuck now, is there anyone who knows how to use memmove in Python when >> dealing with swig 1.3.35 and higher? >> >> Any help is appreciated. >> >> Thanks, >> >> >> Adriaan Renting >> >> >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Swig-user mailing list >> Swi...@li... >> https://lists.sourceforge.net/lists/listinfo/swig-user > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Swig-devel mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-devel > |