[C++-sig] Re: long long unsigned issue...

Milind Patil milind_patil at hotmail.com
Fri May 23 03:59:27 CEST 2003

Thanks Dave. The to_python conversion error has gone away.

I am running accross a different issue now. My assumption was that once
I had a way to convert python long to Y via long_, I should also be able to handle
statements like

x = hello.Y(2, 4294967295)

possibly after adding

implicitly_convertible<int, Y_Wrapper>();

But this does not work. Is my assumption wrong? Any pointers as to
where to look for a solution?



Code reproduced here for reference:

class Y {
    Y() : y(0L) { }
    Y(int y) : y(y) { }
    Y(long long unsigned int y) : y(y) { }
    Y(int s, const Y & y) : y(y << s) { }
    Y(Y const& rhs) : y(rhs.y) { }
    virtual ~Y() { }

    operator int() const { return y; }

    void operator=(Y const& y) {
        this->y = y.y;

    long long unsigned int y;

The Wrapped boost part (hello.cpp):

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

#include <boost/python.hpp>
#include <hello.h>

using namespace boost::python;

namespace {
struct Y_Wrapper: Y {
    Y_Wrapper (PyObject* self_) : Y(), self(self_) {}
    Y_Wrapper (PyObject* self_, int y) : Y(y), self(self_) {}
    Y_Wrapper (PyObject* self_, long long unsigned int y) : Y(y),
self(self_) {}
    Y_Wrapper (PyObject* self_, int s,  const Y& y) : Y(s,y), self(self_) {}
    Y_Wrapper (PyObject* self_, const Y& y) : Y(y), self(self_) {}
    Y_Wrapper (PyObject* self_, boost::python::long_ y) : Y(0), self(self_)
{printf("hello long_");}

    PyObject* self;

    class_< Y, Y_Wrapper >("Y", init<  >())
        .def(init< const Y & >())
        .def(init< int, const Y & >())
        .def(init< int >())
        .def(init< long long unsigned int >())
        .def(init< long_ >())
        .def_readwrite("y", &Y::y)
        .def("__int__", &Y::operator int)

    implicitly_convertible<int, Y>();
    implicitly_convertible<long_, Y_Wrapper>();

The python script:

import hello

x = hello.Y(4294967295)
print x.y
z = hello.Y(2, 4294967295)
print z.y

More information about the Cplusplus-sig mailing list