Thread: [pygccxml-development] help with constructor default argument error
Brought to you by:
mbaas,
roman_yakovenko
From: Kevin W. <kev...@gm...> - 2008-02-26 00:12:36
|
I'm new to Py++ but I've been experimenting with wrapping wxWidgets, the cross platform GUI library. It has gone fairly well, but I'm getting the following error and I'm not sure how to resolve it. In a header file somewhere, a global called "wxPanelNameStr" is declared: extern WXDLLEXPORT_DATA(const char) wxPanelNameStr[]; The implementation is in a CPP file somewhere else: extern WXDLLEXPORT_DATA(const char) wxPanelNameStr[] = "panel"; My problem arises in a constructor which uses wxPanelNameStr as the default value for one of its arguments: inline wxWindow(wxWindow *parent, wxWindowID winid, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr) Py++ generates the following code for this: .def( bp::init< wxWindow *, wxWindowID, bp::optional< wxPoint const &, wxSize const &, long int, wxString const & > >(( bp::arg("parent"), bp::arg("winid"), bp::arg("pos")=wxDefaultPosition, bp::arg("size")=wxDefaultSize, bp::arg("style")=(long int)(0), bp::arg("name")=wxPanelNameStr )) ); You'll note that the sixth argument takes a value of type const wxString&, but the default argument in the generated code is const char []. The error I get is long and does lots of complaining about convertables and char[], but ultimately I think it boils down to this line: ../boost_1_34_1/boost/python/type_id.hpp:88: error: invalid use of array with unspecified bounds wxString does have a constructor which takes const char*, so the implicit conversion should happen, but I think Boost::Python is getting confused. Does anyone know how I can resolve this? |
From: Roman Y. <rom...@gm...> - 2008-02-26 07:01:38
|
On Tue, Feb 26, 2008 at 2:11 AM, Kevin Watters <kev...@gm...> wrote: > I'm new to Py++ but I've been experimenting with wrapping wxWidgets, > the cross platform GUI library. Let me know if you need help with this. > It has gone fairly well, but I'm getting the following error and I'm > not sure how to resolve it. > > In a header file somewhere, a global called "wxPanelNameStr" is declared: > > extern WXDLLEXPORT_DATA(const char) wxPanelNameStr[]; > > The implementation is in a CPP file somewhere else: > > extern WXDLLEXPORT_DATA(const char) wxPanelNameStr[] = "panel"; > > My problem arises in a constructor which uses wxPanelNameStr as the > default value for one of its arguments: > > inline wxWindow(wxWindow *parent, wxWindowID winid, > const wxPoint& pos = wxDefaultPosition, > const wxSize& size = wxDefaultSize, > long style = 0, > const wxString& name = wxPanelNameStr) > > Py++ generates the following code for this: > > .def( bp::init< wxWindow *, wxWindowID, bp::optional< wxPoint > const &, wxSize const &, long int, wxString const & > >(( > bp::arg("parent"), bp::arg("winid"), bp::arg("pos")=wxDefaultPosition, > bp::arg("size")=wxDefaultSize, bp::arg("style")=(long int)(0), > bp::arg("name")=wxPanelNameStr )) ); > > You'll note that the sixth argument takes a value of type const > wxString&, but the default argument in the generated code is const > char []. The error I get is long and does lots of complaining about > convertables and char[], but ultimately I think it boils down to this > line: > > ../boost_1_34_1/boost/python/type_id.hpp:88: error: invalid use of > array with unspecified bounds > > wxString does have a constructor which takes const char*, so the > implicit conversion should happen, but I think Boost::Python is > getting confused. > > Does anyone know how I can resolve this? mb = module_builder_t( ... ) #find wxWindow constructor with 6 arguments of any type wxWindow = mb.constructor( 'wxWindow', arg_types=[None]*6 ) wxWindow.arguments[-1].default_value = 'wxString( wxPanelNameStr )' This should be enough. I also will check whether Py++ can generate better code in this use-case. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Kevin W. <kev...@gm...> - 2008-02-26 16:00:14
|
> mb = module_builder_t( ... ) > #find wxWindow constructor with 6 arguments of any type > wxWindow = mb.constructor( 'wxWindow', arg_types=[None]*6 ) > wxWindow.arguments[-1].default_value = 'wxString( wxPanelNameStr )' > > This should be enough. Thanks for this! It was exactly what I was looking for. And since wxWidgets follows a very clear convention with all of these globals that were causing problems, I took care of all them at once with a clever declaration matcher. > I also will check whether Py++ can generate better code in this use-case. I couldn't find enough documentation on bp::arg to know whether this was an odd case, or if it has trouble with coercing types with implicit constructors of any kind--but I'd imagine there's a general solution lurking about somewhere. Thanks again. |