Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-17662

PyBind 11 ack bug

    XMLWordPrintable

    Details

      Description

      I have a Data struct that looks like this

      .h
      class AckCmd
      {
        public:
          SALData_ackcmdC ackData;
          AckCmd(int ack, int error, std::string result);
      };

      .cpp 
      AckCmd::AckCmd(int ack, int error, std::string result)
      {
        ackData.ack = ack;
        ackData.error = error;
        ackData.result = result;
      }
       

      I then am binding it as follows

       
      py::class_<AckCmd>(m,"AckCmd", py::module_local(), py::dynamic_attr())    
              .def(py::init<int, int, const std::string &>())   
              ;
       
      I have the `py::module_local()` tag because I was getting an `ImportError: generic_type: type "*" is already registered!` error. 
      I have the `py::dynamic_attr()` tag to set the `ack`, `error` and `result` attributes of the ackData object. 
       
      However, when I enter the following within a python shell
       
      >>> import SALPY_Library
      >>> myAck = SALPY_Library.AckCmd( 1, 2, "myack")
      >>> print(myAck.ack)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      AttributeError: 'SALPY_Scheduler.AckCmd' object has no attribute 'ack'
      The attributes are not there. When using double tabbing to view the attributes of the object it doesn't show any of the attributes from the c++ struct.

      >>> myAck.__
      myAck._class(          myAck.doc             myAck.getattribute(   myAck.init_subclass(  myAck.ne(             myAck.repr(           myAck.subclasshook_(   
      myAck._delattr(        myAck.eq(             myAck.gt(             myAck.le(             myAck.new(            myAck.setattr_(        
      myAck._dict            myAck.format(         myAck.hash(           myAck.lt(             myAck.reduce(         myAck.sizeof_(         
      myAck._dir(            myAck.ge(             myAck.init(           myAck.module          myAck.reduce_ex(      myAck.str_(            

        Attachments

          Issue Links

            Activity

            Hide
            aheyer Andrew Heyer [X] (Inactive) added a comment -

            The following email is a draft of what I plan on sending to Pim. 

            Hi Pim,

            Dave tells me you have worked with Pybind11 and I was wondering if you could me with a problem I am having. 

            I have a Data struct that looks like this

             

            .h
            class AckCmd
            {
              public:
                SALData_ackcmdC ackData;
                AckCmd(int ack, int error, std::string result);
            };
             

            .cpp

             
            AckCmd::AckCmd(int ack, int error, std::string result)
            {
              ackData.ack = ack;
              ackData.error = error;
              ackData.result = result;
            }
             

            I then am binding it as follows

             
            py::class_<AckCmd>(m,"AckCmd", py::module_local(), py::dynamic_attr())    
                    .def(py::init<int, int, const std::string &>())   
                    ;
             
            I have the `py::module_local()` tag because I was getting an `ImportError: generic_type: type "*" is already registered!` error. 
            I have the `py::dynamic_attr()` tag to set the `ack`, `error` and `result` attributes of the ackData object. 
             
            However, when I enter the following within a python shell
             
            >>> import SALPY_Library
            >>> myAck = SALPY_Library.AckCmd( 1, 2, "myack")
            >>> print(myAck.ack)
            Traceback (most recent call last):
              File "<stdin>", line 1, in <module>
            AttributeError: 'SALPY_Scheduler.AckCmd' object has no attribute 'ack'
            The attributes are not there. When using double tabbing to view the attributes of the object it doesn't show any of the attributes from the c++ struct.

            >>> myAck.__
            myAck._class(          myAck.doc             myAck.getattribute(   myAck.init_subclass(  myAck.ne(             myAck.repr(           myAck.subclasshook_(   
            myAck._delattr(        myAck.eq(             myAck.gt(             myAck.le(             myAck.new(            myAck.setattr_(        
            myAck._dict            myAck.format(         myAck.hash(           myAck.lt(             myAck.reduce(         myAck.sizeof_(         
            myAck._dir(            myAck.ge(             myAck.init(           myAck.module          myAck.reduce_ex(      myAck.str_(            

            Would you be able to help with binding these attributes correctly?

            Show
            aheyer Andrew Heyer [X] (Inactive) added a comment - The following email is a draft of what I plan on sending to Pim.  Hi Pim, Dave tells me you have worked with Pybind11 and I was wondering if you could me with a problem I am having.  I have a Data struct that looks like this   .h class AckCmd {   public:     SALData_ackcmdC ackData;     AckCmd(int ack, int error, std::string result); };   .cpp   AckCmd::AckCmd(int ack, int error, std::string result) {   ackData.ack = ack;   ackData.error = error;   ackData.result = result; }   I then am binding it as follows   py::class_<AckCmd>(m,"AckCmd", py::module_local(), py::dynamic_attr())             .def(py::init<int, int, const std::string &>())            ;   I have the `py::module_local()` tag because I was getting an `ImportError: generic_type: type "*" is already registered!` error.  I have the `py::dynamic_attr()` tag to set the `ack`, `error` and `result` attributes of the ackData object.    However, when I enter the following within a python shell   >>> import SALPY_Library >>> myAck = SALPY_Library.AckCmd( 1, 2, "myack") >>> print(myAck.ack) Traceback (most recent call last):   File "<stdin>", line 1, in <module> AttributeError: 'SALPY_Scheduler.AckCmd' object has no attribute 'ack' The attributes are not there. When using double tabbing to view the attributes of the object it doesn't show any of the attributes from the c++ struct. >>> myAck.__ myAck._ class (          myAck. doc              myAck. getattribute (   myAck. init_subclass (  myAck. ne (             myAck. repr (           myAck. subclasshook _(    myAck._ delattr (        myAck. eq (             myAck. gt (             myAck. le (             myAck. new (            myAck. setattr _(         myAck._ dict             myAck. format (         myAck. hash (           myAck. lt (             myAck. reduce (         myAck. sizeof _(          myAck._ dir (            myAck. ge (             myAck. init (           myAck. module           myAck. reduce_ex (      myAck. str _(             Would you be able to help with binding these attributes correctly?
            Hide
            dmills Dave Mills added a comment -

            Contacted pybind11 expert for assistance

            Show
            dmills Dave Mills added a comment - Contacted pybind11 expert for assistance

              People

              Assignee:
              aheyer Andrew Heyer [X] (Inactive)
              Reporter:
              jbuffill James Buffill [X] (Inactive)
              Reviewers:
              Dave Mills
              Watchers:
              Andrew Heyer [X] (Inactive), Dave Mills, James Buffill [X] (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Start date:
                End date:

                  Jenkins

                  No builds found.