[C++-sig] boost.python fails to recognize type

Mateusz Berezecki mateuszb at gmail.com
Sun Jul 27 03:01:21 CEST 2008


Hi list readers,

I want to enable Python to access the C++ class.
I do this as follows:

BOOST_PYTHON_MODULE(ht)
{
  <...>
  class_<Hypertable::ScanSpec>("ScanSpec")
    .def_readwrite("row_limit", &Hypertable::ScanSpec::row_limit)
    .def_readwrite("max_versions", &Hypertable::ScanSpec::max_versions)
    .def_readwrite("columns", &Hypertable::ScanSpec::columns)
    .def_readwrite("start_row", &Hypertable::ScanSpec::start_row)
    .def_readwrite("start_row_inclusive",
&Hypertable::ScanSpec::start_row_inclusive)
    .def_readwrite("end_row", &Hypertable::ScanSpec::end_row)
    .def_readwrite("end_row_inclusive",
&Hypertable::ScanSpec::end_row_inclusive)
    ;
  <...>
}

The ScanSpec class is defined as follows:
00087   class ScanSpec {
00088   public:
00089     ScanSpec();
00090     size_t encoded_length();
00091     void encode(uint8_t **bufPtr);
00092     bool decode(uint8_t **bufPtr, size_t *remainingPtr);
00093     uint32_t row_limit;
00094     uint32_t max_versions;
00095     std::vector<const char *> columns;
00096     const char *start_row;
00097     bool start_row_inclusive;
00098     const char *end_row;
00099     bool end_row_inclusive;
00100     std::pair<uint64_t,uint64_t> interval;
00101     bool return_deletes;
00102   };

The conversion process happens in the Table class wrapper which is
defined as follows
class Table {
private:
  Hypertable::TablePtr m_table_ptr;

public:
  Table() {}
  Table(Hypertable::TablePtr ptr) : m_table_ptr(ptr) {}

  TableScanner create_scanner(object pyspec)
  {
    Hypertable::ScanSpec& spec = extract<Hypertable::ScanSpec&>(pyspec);
    return TableScanner(m_table_ptr->create_scanner(spec, 10));
  }
};

The error is as follows
TypeError: No registered converter was able to extract a C++ reference
to type Hypertable::ScanSpec from this Python object of type
Boost.Python.class

I've also tried extracting it as a pointer
TypeError: No registered converter was able to extract a C++ pointer
to type Hypertable::ScanSpec from this Python object of type
Boost.Python.class

And the same happens when trying to extract a copy of ScanSpec, but
this time the error message tells it's not possible to extract rvalue
from Boost.Python.class.

I've tried every possible combination and it doesn't work.

Can somebody please help me ?

Mateusz



More information about the Cplusplus-sig mailing list