#1334 pybuffer_mutable_binary generates incorrect code

open
nobody
None
5
2015-02-03
2013-09-18
tatsujin
No
SWIGINTERN PyObject *_wrap_recv(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; int arg1 ;
  char *arg2 = (char *) 0 ; size_t arg3 ; int arg4 ; int val1 ; int ecode1 = 0 ; int res2 ; Py_ssize_t size2 = 0 ;
  void *buf2 = 0 ; int val4 ; int ecode4 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; int result;
  if (!PyArg_ParseTuple(args,(char *)"OOO:recv",&obj0,&obj1,&obj2)) SWIG_fail; ecode1 = SWIG_AsVal_int(obj0, &val1);
  if (!SWIG_IsOK(ecode1)) {
    SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "recv" "', argument " "1"" of type '" "int""'"); }  
  arg1 = (int)(val1); { res2 = PyObject_AsWriteBuffer(obj1, &buf2, &size2); if (res2<0) { PyErr_Clear();
      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "recv" "', argument " "2"" of type '" "(char *buf2, size_t len)""'"); }
     arg2 = (char *) buf; arg3 = (size_t) (size2/sizeof(char)); }  ecode4 = SWIG_AsVal_int(obj2, &val4);
  if (!SWIG_IsOK(ecode4)) {
    SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "recv" "', argument " "4"" of type '" "int""'"); }  
  arg4 = (int)(val4); result = (int)nn_recv(arg1,arg2,arg3,arg4); resultobj = SWIG_From_int((int)(result)); return resultobj;
  fail: return NULL; }

The arg2 = (char *) buf; is incorrect (and does not compile) as "buf" does not exist.
I'm guessing that it should be "buf2" instead of "buf". The related macro pybuffer_binary generates as such.

Discussion

  • tatsujin

    tatsujin - 2013-09-18

    Hm... should probably specify what declarations were used to get this error :)

    %pybuffer_mutable_binary(char *buf, size_t len);
    int nn_recv(int s, char *buf, size_t len, int flags);
    

    Also, sorry about the -small usage, realized that after posting.

     
  • William Fulton

    William Fulton - 2013-09-18

    What is the complete code to replicate this?

     
  • tatsujin

    tatsujin - 2013-09-18

    I don't have it accessible right now, but it is in essence only including the nn.h header (nanomsg.org) and then the above type mapping for nn_recv. I haven't tried stripping it to the minimum that still generates the error.

    Tomorrow I can paste the complete .i-file.

     
  • tatsujin

    tatsujin - 2013-09-19

    Nope the only part needed is what I mentioned in my first comment.
    The minimal is this:

    %module something
    %include "pybuffer.i"
    %pybuffer_mutable_binary(char *buf, size_t len);
    int whatever(char *buf, size_t len);
    

    This will generate the following code:

    SWIGINTERN PyObject *_wrap_whatever(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
      PyObject *resultobj = 0;
      char *arg1 = (char *) 0 ;
      size_t arg2 ;
      int res1 ;
      Py_ssize_t size1 = 0 ;
      void *buf1 = 0 ;
      PyObject * obj0 = 0 ;
      int result;
    
      if (!PyArg_ParseTuple(args,(char *)"O:whatever",&obj0)) SWIG_fail;
      {
        res1 = PyObject_AsWriteBuffer(obj0, &buf1, &size1);
        if (res1<0) {
          PyErr_Clear();
          SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "whatever" "', argument " "1"" of type '" "(char *buf1, size_t len)""'");
        }
        arg1 = (char *) buf;
       arg2 = (size_t) (size1/sizeof(char));
      }
      result = (int)whatever(arg1,arg2);
      resultobj = SWIG_From_int((int)(result));
      return resultobj;
    fail:
      return NULL;
    }
    

    Where this is the problem part:

        arg1 = (char *) buf;
    

    I assume should be "buf1". (buf2 in my original post since I had another argument in front of it)

     
    Last edit: tatsujin 2013-09-19

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks