[c++-sig] private copy constructor with callback from c++

Holger Joukl Holger.Joukl at LBBW.de
Fri Mar 5 16:41:51 CET 2004


Yet another long post...
I am trying to wrap Tibco´s TIB/Rv API, using BPL 1.31.0 and pyste, gcc
2.95.2, solaris 2.6.

There happens to be a call from the C++ side to TibrvMsgCallback::onEvent
(with BPL
it is actually TibrvMsgCallback_Wrapper::onEvent?), giving a TibrvListener*
as an argument.
Now the problem seems to me that the TibrvListener class (inheriting from
TibrvEvent), has a private copy
constructor.
This results in a core dump when performing the call.
Do I have chance of avoiding this problem?

Funny thing is, I first tried to build all the stuff by hand, not using
bjam -- there I managed to not
run into core, but got an error message that no to_python converter was
registered for
TibrvListener/TibrvEvent; so maybe I could write a custom converter?

Thank you very much for any help
  Holger

Btw I do not have access to my box until tuesday, so no hurry/do not wonder
if I will not
respond quickly.

Here is the wrapper code:


// Boost Includes
==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

// Includes
====================================================================
#include <tibrv/tibrvcpp.h>

// Using
=======================================================================
using namespace boost::python;

// Declarations
================================================================



// Boost Includes
==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

// Includes
====================================================================
#include <tibrv/tibrvcpp.h>

// Using
=======================================================================
using namespace boost::python;

// Declarations
================================================================

struct void_;

BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_);

void_ *TibrvEvent_getClosure_wrapper(TibrvEvent* event)
{
    return (void_ *) event->getClosure();
}

// Boost Includes
==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

// Includes
====================================================================
#include <tibrv/tibrvcpp.h>

// Using
=======================================================================
using namespace boost::python;

// Declarations
================================================================

struct void_;

BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_);

void_ *TibrvEvent_getClosure_wrapper(TibrvEvent* event)
{
    return (void_ *) event->getClosure();
}

//BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void)



namespace  {

struct TibrvEvent_Wrapper: TibrvEvent
{
    TibrvStatus destroy(TibrvEventOnComplete* p0) {
        return call_method< TibrvStatus >(self, "destroy", p0);
    }

    TibrvStatus default_destroy_0() {
        return TibrvEvent::destroy();
    }

    TibrvStatus default_destroy_1(TibrvEventOnComplete* p0) {
        return TibrvEvent::destroy(p0);
    }

    PyObject* self;
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(TibrvListener_create_overloads_4_5,
create, 4, 5)


}// namespace


// Module
======================================================================
void Export_TibrvEvent()
{
    class_< TibrvEvent, boost::noncopyable, TibrvEvent_Wrapper
>("TibrvEvent", no_init)
        .def("destroy", &TibrvEvent::destroy,
&TibrvEvent_Wrapper::default_destroy_1)
        .def("destroy", &TibrvEvent_Wrapper::default_destroy_0)
        .def("isValid", &TibrvEvent::isValid)
        .def("getQueue", &TibrvEvent::getQueue, return_value_policy<
reference_existing_object >())
        .def("getClosure", &TibrvEvent_getClosure_wrapper,
return_value_policy< return_opaque_pointer >())
        .def("isListener", &TibrvEvent::isListener)
        .def("isTimer", &TibrvEvent::isTimer)
        .def("isIOEvent", &TibrvEvent::isIOEvent)
        .def("getType", &TibrvEvent::getType)
        .def("getHandle", &TibrvEvent::getHandle)
    ;

    class_< TibrvListener, bases< TibrvEvent >, boost::noncopyable
>("TibrvListener", init<  >())
        .def("create", &TibrvListener::create,
TibrvListener_create_overloads_4_5())
        .def("getTransport", &TibrvListener::getTransport,
return_value_policy< reference_existing_object >())
        .def("getSubject", &TibrvListener::getSubject)
    ;

}


#include <iostream>

// Boost Includes
==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

// Includes
====================================================================
#include <tibrv/tibrvcpp.h>

// Using
=======================================================================
using namespace boost::python;

// Declarations
================================================================
namespace  {

struct TibrvCallback_Wrapper: TibrvCallback
{
    TibrvCallback_Wrapper(PyObject* self_, const TibrvCallback& p0):
        TibrvCallback(p0), self(self_) {}

    TibrvCallback_Wrapper(PyObject* self_):
        TibrvCallback(), self(self_) {}

    void onEvent(TibrvEvent* p0, TibrvMsg& p1) {
        call_method< void >(self, "onEvent", p0, p1);
    }

    PyObject* self;
};

struct TibrvMsgCallback_Wrapper: TibrvMsgCallback
{
    TibrvMsgCallback_Wrapper(PyObject* self_, const TibrvMsgCallback& p0):
        TibrvMsgCallback(p0), self(self_) {}

    TibrvMsgCallback_Wrapper(PyObject* self_):
        TibrvMsgCallback(), self(self_) {}

    void onMsg(TibrvListener* p0, TibrvMsg& p1) {
        cout << "-->TibrvMsgCallback_Wrapper::onMsg\n";
        call_method< void >(self, "onMsg", p0, p1);
        cout << "<--TibrvMsgCallback_Wrapper::onMsg\n";
    }

    void onEvent(TibrvEvent* p0, TibrvMsg& p1) {
        cout << "-->TibrvMsgCallback_Wrapper::onEvent\n";
        call_method< void >(self, "onEvent", p0, p1);
        cout << "<--TibrvMsgCallback_Wrapper::onEvent\n";
    }

    PyObject* self;
};


Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.







More information about the Cplusplus-sig mailing list