[C++-sig] ArgumentError storing and retrieving pointer in class: wrong type

Gary Oberbrunner garyo at genarts.com
Thu Oct 24 16:54:55 CEST 2013


I recently posted an issue on StackOverflow about some Py++-generated code that didn't seem to work.  The question is at http://stackoverflow.com/questions/19461274/.

Simply, I have these classes:

struct classA {
  int intval;
  unsigned int bitfield_member:1;
};

struct Collection {
  classA * class_a_ptr;
};

and Py++ generates a wrapper for classA, and setter/getters for bitfield_member, but the problem seems to be that the getter for class_a_ptr (get_class_a_ptr) returns a classA *, not a classA_wrapper *, and that doesn't have the bitfield_member accessors, so doing this in python fails at runtime:

  coll=Collection()
  g = classA()
  coll.class_a_ptr = g
  print coll.class_a_ptr.bitfield_member <-- fails with ArgumentError, wrong type

The solution suggested in the SO question is to change the generated bitfield_member setter/getter to take an explicit classA * as "this".  My solution instead was to change get_class_a_ptr to return a classA_wrapper *, since it has the same data layout as classA.  (The answer in the SO article would be hard for me, since in my real case classA has hundreds of members and I'd rather not hand-edit them all.)

Either way, it seems py++ generates non-working code for this example.  See the SO question for complete details.  Roman, if you're reading this, I presume this is the best way to submit these kinds of issues?  I'm happy to post a bug report elsewhere if that's appropriate.

Thanks;

-- Gary


More information about the Cplusplus-sig mailing list