pygccxml-development Mailing List for C++ Python language bindings (Page 15)
Brought to you by:
mbaas,
roman_yakovenko
You can subscribe to this list here.
2006 |
Jan
|
Feb
(6) |
Mar
(160) |
Apr
(96) |
May
(152) |
Jun
(72) |
Jul
(99) |
Aug
(189) |
Sep
(161) |
Oct
(110) |
Nov
(9) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(13) |
Feb
(48) |
Mar
(35) |
Apr
(7) |
May
(37) |
Jun
(8) |
Jul
(15) |
Aug
(8) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(38) |
2008 |
Jan
(11) |
Feb
(29) |
Mar
(17) |
Apr
(3) |
May
|
Jun
(64) |
Jul
(49) |
Aug
(51) |
Sep
(18) |
Oct
(22) |
Nov
(9) |
Dec
(9) |
2009 |
Jan
(28) |
Feb
(15) |
Mar
(2) |
Apr
(11) |
May
(6) |
Jun
(2) |
Jul
(3) |
Aug
(34) |
Sep
(5) |
Oct
(7) |
Nov
(13) |
Dec
(14) |
2010 |
Jan
(39) |
Feb
(3) |
Mar
(3) |
Apr
(14) |
May
(11) |
Jun
(8) |
Jul
(9) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
(7) |
Apr
|
May
|
Jun
(3) |
Jul
(3) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2016 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2021 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
From: Roman Y. <rom...@gm...> - 2008-08-13 20:01:41
|
On Wed, Aug 13, 2008 at 6:45 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > so I have class with create function that act a factory function . > > typedef boost::smart_ptr<Color> ColorPtr ; > > class Color > { > static ColorPtr create(); > static ColorPtr create(int i); > > private: > Color(); > } > > make sense for the c++ side by in python I want to hide that > so I can do > > col = Color() # this is actually calling Color.create() .. > > // this code that py++ create > { //::Color::create > typedef ::ColorPtr ( *create_function_type )( ); > > Color_exposer.def( > "create" > , create_function_type( &::Color::create ) > , "Create a color 0 0 0 " ); > } > > I found that I can use make_contructor easily and do : > { > typedef ::ColorPtr ( *create_function_type )( ); > Color_exposer.def ("__init__", > bp::make_constructor(create_function_type(&::Color::create) ) ); > } > > so is there a nice way for ne to generate this code for any class that > have > static boost::smart_ptr<Class> create(....) methods ? > > looking onto the source I saw : > > class constructor_transformed_t <cid:par...@mo...>( calldef_t ): > > that doesn something that might be in the right direction for me . > > I can see how I would find all the methods that match this style . > and doing all the typed def and thing but it look like I might be able to do > > md.classes().decls('create').make_contructors() :) > > well not that simple but something in that direction ? Why not? I just committed the implementation of the functionality you want. http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1392 The usage is pretty simple: namespace mc{ struct numbers_t{ numbers_t() : x( 0 ) , y( 0 ) {} ~numbers_t(){} static std::auto_ptr<numbers_t> create( int i, int j, int k, int m ); int x; int y; }; std::auto_ptr<numbers_t> create( int i, int j); } Usage: mc = mb.namespace( 'mc' ) numbers = mc.class_( 'numbers_t' ) numbers.add_fake_constructors( mc.calldefs( 'create' ) ) and I attached the generated code. Obviously this functionality may contain few bugs here and there, but main success scenario should work. > the more I get into py++ the more I like it !! :-), thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-08-13 15:44:58
|
Hi , so I have class with create function that act a factory function . typedef boost::smart_ptr<Color> ColorPtr ; class Color { static ColorPtr create(); static ColorPtr create(int i); private: Color(); } make sense for the c++ side by in python I want to hide that so I can do col = Color() # this is actually calling Color.create() .. // this code that py++ create { //::Color::create typedef ::ColorPtr ( *create_function_type )( ); Color_exposer.def( "create" , create_function_type( &::Color::create ) , "Create a color 0 0 0 " ); } I found that I can use make_contructor easily and do : { typedef ::ColorPtr ( *create_function_type )( ); Color_exposer.def ("__init__", bp::make_constructor(create_function_type(&::Color::create) ) ); } so is there a nice way for ne to generate this code for any class that have static boost::smart_ptr<Class> create(....) methods ? looking onto the source I saw : class constructor_transformed_t <cid:par...@mo...>( calldef_t ): that doesn something that might be in the right direction for me . I can see how I would find all the methods that match this style . and doing all the typed def and thing but it look like I might be able to do md.classes().decls('create').make_contructors() :) well not that simple but something in that direction ? thanks the more I get into py++ the more I like it !! |
From: Roman Y. <rom...@gm...> - 2008-08-13 13:00:21
|
On Wed, Aug 13, 2008 at 2:14 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > so here is my case : > > /// Module A > /// __BIND__ > class Base > { > /// __BIND__ > void foo() = 0; > } > > /// __BIND__ > class BaseImp : public Base > { > void foo() { // do something default } > } > > /// Module B > /// __BIND__ > class Usefull : public BaseImp > { > void foo() { // do something usefull } > } > > I use doxygen to expose classes or methodes , ///__BIND__ is the trigger . > > Module A and B and build in too different process , and come for > different libs . > Module A is loaded before Module B. > > Class Base shouldnt/cant be overriden in python . I can add new property to class "no_init", which will path "no_init" to boost::python::class_<...> constructor. This will do the trick > > the problem that I am having is that when I call > > Usefull.foo() I get an exeption on calling a pure virtual function . > and its kinda make sense when I look at the wrapper for Base::foo Not for me. Usefull is exposed too, right? You also meant to wrote Usefull().foo(), right ? In this case you should not get "pure virtual function call" exception, because the function has "default" implementation. I think something wrong with the example, you tried to build. May be you have overloaded "foo"? > can I tell py++ that I dont want a pureVirtual to be declare are such ? > also can I force py++ to not enable virtual methods overwriting ? No. The only "hacky" way you can do this, is to change function "virtuality" http://language-binding.net/pyplusplus/documentation/apidocs/pygccxml.declarations.calldef.member_calldef_t-class.html#virtuality but I am not responsible for the result :-) > I guess that I could try to write the implemation of those class > manually but py++ is doign such a good job that I have become very lasy :) :-), Create complete example ( C++ + Python code with desired behavior ) and lets see what could be done -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-08-13 11:14:23
|
Hi , so here is my case : /// Module A /// __BIND__ class Base { /// __BIND__ void foo() = 0; } /// __BIND__ class BaseImp : public Base { void foo() { // do something default } } /// Module B /// __BIND__ class Usefull : public BaseImp { void foo() { // do something usefull } } I use doxygen to expose classes or methodes , ///__BIND__ is the trigger . Module A and B and build in too different process , and come for different libs . Module A is loaded before Module B. Class Base shouldnt/cant be overriden in python . the problem that I am having is that when I call Usefull.foo() I get an exeption on calling a pure virtual function . and its kinda make sense when I look at the wrapper for Base::foo can I tell py++ that I dont want a pureVirtual to be declare are such ? also can I force py++ to not enable virtual methods overwriting ? I guess that I could try to write the implemation of those class manually but py++ is doign such a good job that I have become very lasy :) thanks Damien |
From: Roman Y. <rom...@gm...> - 2008-08-13 10:09:57
|
On Wed, Aug 13, 2008 at 12:34 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > in our project we use OpenEXR Imath classes for our Math objects. > its heavily templetized , I have create a special header where I > instanciate the class that I need to be expose to > gcc-xml and that part is working fine , but the problem come when those > class have template member functions . > > I have try to instanciate those too but I still dont get them in . > > I can across this in goggle : > http://mail.python.org/pipermail/c++-sig/2008-June/013663.html > > does that mean that there is currently no way using py++ to expose > template member functions of template class even with some forced > instanciation ? If you will success to instantiate them, Py++ will pick up them. I really tried to find some work-around and failed. If you have a big use-case, may be it worse to turn to Brad King, author of gccxml, and ask help from him. HTH. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-08-13 09:34:02
|
Hi , in our project we use OpenEXR Imath classes for our Math objects. its heavily templetized , I have create a special header where I instanciate the class that I need to be expose to gcc-xml and that part is working fine , but the problem come when those class have template member functions . I have try to instanciate those too but I still dont get them in . I can across this in goggle : http://mail.python.org/pipermail/c++-sig/2008-June/013663.html does that mean that there is currently no way using py++ to expose template member functions of template class even with some forced instanciation ? Thanks Damien |
From: Roman Y. <rom...@gm...> - 2008-08-07 18:51:43
|
On Thu, Aug 7, 2008 at 9:37 PM, Ben Schleimer <bsc...@lu...> wrote: > Isn't it better to use explicit annotations rather then relying on > pattern-matching to figure out what is a property and what isn't? The only "right" answer is: it depends. If you have some coding convention - you can reuse it. Most projects do have the coding convention. > Like using the META_PROPERTY() macro to add __gccxml__ attributes into > the code. In many projects, changing the code is not an option and running some intelligent algorithm helps to cover 90-95% of all properties, so why not to use it? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Ben S. <bsc...@lu...> - 2008-08-07 18:37:57
|
Isn't it better to use explicit annotations rather then relying on pattern-matching to figure out what is a property and what isn't? Like using the META_PROPERTY() macro to add __gccxml__ attributes into the code. Cheers Ben > -----Original Message----- > From: pyg...@li... > [mailto:pyg...@li...] > On Behalf Of Roman Yakovenko > Sent: Thursday, August 07, 2008 11:09 AM > To: Damien Fagnou > Cc: pyg...@li... > Subject: Re: [pygccxml-development] properties detection > > On Thu, Aug 7, 2008 at 8:47 PM, Damien Fagnou > <dam...@mo...> wrote: > > Hi , > > > > we are trying to use the Python properties , idealy I would like to > > use the automatic detection : > > > > mb = module_builder_t( ... ) > > number = mb.class_( 'myClass' ) > > number.add_properties( exclude_accessors=False ) #accessors will be > > exposed > > > > our accessor are of type : > > > > float getRadius(); > > void setRadius(float rad); > > > > and I would like the properties to be 'radius' > > > > is this form normaly detected ? > > No. "get" function should be const, otherwise Py++ thinks > that the function has a side effect, and doesn't expose it as > property. > > > we try to do : > > self.moduleBuilder.classes().add_properties( > exclude_accessors=False ) > > > > but nothing .. > > is there a way to see more what the add_properties algo is doing ? > > Of course. It is open source project :-) Take a look on this > file > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus > _dev/pyplusplus/decl_wrappers/properties.py?revision=842&view=markup > > In your case I suggest you to create new class, which derives > from name_based_recognizer_t class and override "is_getter" function. > > Then pass instance of the new class to add_properties method: > > number.add_properties( recognizer=..., > exclude_accessors=False ) #accessors will be exposed > > As for the name, you can also override "find_out_property_name" > function, so it will convert "Radius" to "radius" > > HTH. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > > -------------------------------------------------------------- > ----------- > This SF.Net email is sponsored by the Moblin Your Move > Developer's challenge Build the coolest Linux based > applications with Moblin SDK & win great prizes Grand prize > is a trip for two to an Open Source event anywhere in the > world http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > pygccxml-development mailing list > pyg...@li... > https://lists.sourceforge.net/lists/listinfo/pygccxml-development > > |
From: Roman Y. <rom...@gm...> - 2008-08-07 18:09:14
|
On Thu, Aug 7, 2008 at 8:47 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > we are trying to use the Python properties , > idealy I would like to use the automatic detection : > > mb = module_builder_t( ... ) > number = mb.class_( 'myClass' ) > number.add_properties( exclude_accessors=False ) #accessors will be exposed > > our accessor are of type : > > float getRadius(); > void setRadius(float rad); > > and I would like the properties to be 'radius' > > is this form normaly detected ? No. "get" function should be const, otherwise Py++ thinks that the function has a side effect, and doesn't expose it as property. > we try to do : > self.moduleBuilder.classes().add_properties( exclude_accessors=False ) > > but nothing .. > is there a way to see more what the add_properties algo is doing ? Of course. It is open source project :-) Take a look on this file http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/decl_wrappers/properties.py?revision=842&view=markup In your case I suggest you to create new class, which derives from name_based_recognizer_t class and override "is_getter" function. Then pass instance of the new class to add_properties method: number.add_properties( recognizer=..., exclude_accessors=False ) #accessors will be exposed As for the name, you can also override "find_out_property_name" function, so it will convert "Radius" to "radius" HTH. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-08-07 17:47:33
|
Hi , we are trying to use the Python properties , idealy I would like to use the automatic detection : mb = module_builder_t( ... ) number = mb.class_( 'myClass' ) number.add_properties( exclude_accessors=False ) #accessors will be exposed our accessor are of type : float getRadius(); void setRadius(float rad); and I would like the properties to be 'radius' is this form normaly detected ? we try to do : self.moduleBuilder.classes().add_properties( exclude_accessors=False ) but nothing .. is there a way to see more what the add_properties algo is doing ? thanks Damien |
From: Roman Y. <rom...@gm...> - 2008-07-30 17:28:14
|
On Wed, Jul 30, 2008 at 6:00 PM, Vincent Ferries <vin...@gm...> wrote: > Ok, thanks for your answear. > > With further investigations, I thing the cause of my problem comes > from the non-call to the constructor when instanciating my class. Some > variables are not initialized and then the program encounters problems > to store datas in unreserved memory. (-> segmentations faults) > > > I have the following constructor (I simpllify it a little) : > > dataBase::dataBase(void) : generic::dataBase() { > try { > // Just for debugging purpose > cout << "Here we are in constructor!" << endl; > properties.clear(); > } > catchAll("dataBase::dataBase(void)",""); > } > > > I didn't seem to go through it, the first log sentence was never printed. > I've gone in the associated wrapper class and found this declaration > for the constructor : > > struct dataBase_wrapper : postLib::nastran::dataBase, bp::wrapper< > postLib::nastran::dataBase > { > > dataBase_wrapper( ) > : postLib::nastran::dataBase( ) > , bp::wrapper< postLib::nastran::dataBase >(){ > // null constructor > > } > > It seems weird to me... > According to me, the instanciation of the corresponding class in > Python should instanciate the underneath class with its defined > constructor... > > Is there a bug or am I missing something? I need to see Python code -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-07-30 15:00:28
|
Ok, thanks for your answear. With further investigations, I thing the cause of my problem comes from the non-call to the constructor when instanciating my class. Some variables are not initialized and then the program encounters problems to store datas in unreserved memory. (-> segmentations faults) I have the following constructor (I simpllify it a little) : dataBase::dataBase(void) : generic::dataBase() { try { // Just for debugging purpose cout << "Here we are in constructor!" << endl; properties.clear(); } catchAll("dataBase::dataBase(void)",""); } I didn't seem to go through it, the first log sentence was never printed. I've gone in the associated wrapper class and found this declaration for the constructor : struct dataBase_wrapper : postLib::nastran::dataBase, bp::wrapper< postLib::nastran::dataBase > { dataBase_wrapper( ) : postLib::nastran::dataBase( ) , bp::wrapper< postLib::nastran::dataBase >(){ // null constructor } It seems weird to me... According to me, the instanciation of the corresponding class in Python should instanciate the underneath class with its defined constructor... Is there a bug or am I missing something? Thanks again! 2008/7/30, Roman Yakovenko <rom...@gm...>: > On Wed, Jul 30, 2008 at 11:17 AM, Vincent Ferries > <vin...@gm...> wrote: >> I'm getting segmentation fault errors trying to replace data in a map. >> >> I've have the following attribute in my class : >> std::map<int,property> properties ; >> >> I get this map from a getter function with the following signature: >> map<int,property> & dataBase::getProperties(void) { >> return properties; >> } >> >> Then the method is called from another class in the C++ code : >> map<int,property> &target=DB.getProperties(); >> >> And I try to change data in it : >> target[tmpProperty.id]=tmpProperty; >> >> I get the segmentation fault at this line. >> The compiled C++ code is completely working alone, I allready tested it. >> I can load a file using one of my functions from C++ directly without >> any problem, but when I try to use this same function from Python, I >> get this segfault. >> >> I think the problem comes from a bad call policy fro this >> getProperties() function, but I'm not really sure. >> I'm currently using the following one : >> function.call_policies = >> call_policies.return_value_policy(call_policies.reference_existing_object) > > http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/return_internal_reference.html > > In this case return_internal_reference should be used > > > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |
From: Roman Y. <rom...@gm...> - 2008-07-30 09:29:48
|
On Wed, Jul 30, 2008 at 11:17 AM, Vincent Ferries <vin...@gm...> wrote: > I'm getting segmentation fault errors trying to replace data in a map. > > I've have the following attribute in my class : > std::map<int,property> properties ; > > I get this map from a getter function with the following signature: > map<int,property> & dataBase::getProperties(void) { > return properties; > } > > Then the method is called from another class in the C++ code : > map<int,property> &target=DB.getProperties(); > > And I try to change data in it : > target[tmpProperty.id]=tmpProperty; > > I get the segmentation fault at this line. > The compiled C++ code is completely working alone, I allready tested it. > I can load a file using one of my functions from C++ directly without > any problem, but when I try to use this same function from Python, I > get this segfault. > > I think the problem comes from a bad call policy fro this > getProperties() function, but I'm not really sure. > I'm currently using the following one : > function.call_policies = > call_policies.return_value_policy(call_policies.reference_existing_object) http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/return_internal_reference.html In this case return_internal_reference should be used -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-07-30 08:17:42
|
I'm getting segmentation fault errors trying to replace data in a map. I've have the following attribute in my class : std::map<int,property> properties ; I get this map from a getter function with the following signature: map<int,property> & dataBase::getProperties(void) { return properties; } Then the method is called from another class in the C++ code : map<int,property> &target=DB.getProperties(); And I try to change data in it : target[tmpProperty.id]=tmpProperty; I get the segmentation fault at this line. The compiled C++ code is completely working alone, I allready tested it. I can load a file using one of my functions from C++ directly without any problem, but when I try to use this same function from Python, I get this segfault. I think the problem comes from a bad call policy fro this getProperties() function, but I'm not really sure. I'm currently using the following one : function.call_policies = call_policies.return_value_policy(call_policies.reference_existing_object) Thanks in advance for any help! |
From: Roman Y. <rom...@gm...> - 2008-07-29 08:21:49
|
On Mon, Jul 28, 2008 at 11:36 PM, P. J. Reed <pr...@sw...> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Let's say that I have a class definition and implementation that look > something like this: > > class Test { > Test(); > int a, b; > }; > > Test::Test(): > a( 1 ), > b( 2 ) > {} > > I'd like to use pygccxml to get the values in the intialization list in > the constructor -- that is, I want to find out that it's setting "a" to > 1 and "b" to 2. I can't quite figure out how to do this. I would > assume that there would be some member method of constructor_t that I > could use to read it, but I don't see it. > > Is there some way to do this that I'm missing? No. > If it's not currently possible, would it be difficult to add that in? Yes. GCCXML is not able to dump arbitrary C++ expression it is toooooooooo difficult. There are few projects out-there, that tries to add dumping functions body to GCCXML. I don't know their status. Mozilla has some project based on gcc, which is used for refactoring, I guess you can find such functionality there. Another valid option is clang project, but it doesn't support C++ well right know. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: P. J. R. <pr...@sw...> - 2008-07-28 20:35:59
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Let's say that I have a class definition and implementation that look something like this: class Test { Test(); int a, b; }; Test::Test(): a( 1 ), b( 2 ) {} I'd like to use pygccxml to get the values in the intialization list in the constructor -- that is, I want to find out that it's setting "a" to 1 and "b" to 2. I can't quite figure out how to do this. I would assume that there would be some member method of constructor_t that I could use to read it, but I don't see it. Is there some way to do this that I'm missing? If it's not currently possible, would it be difficult to add that in? Thanks! - -- P. J. Reed Southwest Research Institute Signal Exploitation & Geolocation Division Research Analyst (210) 522-6948 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIji2zBhzuKzQK4BYRCAe3AKDgl780AY8uwK4NiyEz+rAoIu+5wACdEXob NJojYbO/DkYW4E/hJFLOEQs= =7H5Y -----END PGP SIGNATURE----- |
From: Roman Y. <rom...@gm...> - 2008-07-27 18:21:33
|
On Sun, Jul 27, 2008 at 5:56 PM, Gustavo Carneiro <gjc...@gm...> wrote: > Hello. I am trying to scan the following definitions: > > > struct SomeStruct > { > int x; > float y; > }; > > enum SomeEnum { > SOME_FOO, > SOME_BAR > }; > > int hello_xpto (struct SomeStruct xto); > int hello_zbr (enum SomeEnum xto); > > > typedef struct { > int x; > float y; > } SomeStruct2; > > typedef enum { > SOME2_FOO, > SOME2_BAR > } SomeEnum2; > > int hello_xpto2 (SomeStruct2 xto); > int hello_zbr2 (SomeEnum2 xto); > > The intent is to generate bindings for, in this case, a pure C library, > using pure C code. My issue here is how to distinguish between an enum > defined via a typedef (SomeEnum2) and an enum the old fashioned C way. > Because the type needs to generated differently in both cases. I have to > generate 'enum SomeEnum', because simply referencing 'SomeEnum' does not > compile with a C compiler. On the other hand, I cannot generate a type > string 'enum SomeEnum2', because SomeEnum2 is actually a typedef, not a > proper enum; it also does not compile. So always putting enum in front of > everything does not work. > > Idem for 'struct SomeStruct' vs 'SomeStruct2'. > > I have been experimenting for a while, but could not find any way to > distinguish between the two cases. Any idea? The short answer is: you cannot, gccxml doesn't support C front-end. The longer answer is: you can write your own "custom" parser. I took next definition and put it within the file: 0 typedef enum { 1 SOME2_FOO, 2 SOME2_BAR 3 } SomeEnum2; 4 5 int hello_zbr2 (SomeEnum2 xto); GCCXML generate piece of xml: <Enumeration id="_34" name="SomeEnum2" context="_1" location="f1:4" file="f1" line="4" size="32" align="32"> <EnumValue name="SOME2_FOO" init="0"/> <EnumValue name="SOME2_BAR" init="1"/> </Enumeration> It points to the line "4". It is 1 based. It seems that all you have to do is to * assume the code is 100% valid code * check that after enum name comes ";" and not "{" In my opinion it should not be too difficult. P.S. If you accept this as a solution, I will accept your patch to pygccxml :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Gustavo C. <gjc...@gm...> - 2008-07-27 14:56:38
|
Hello. I am trying to scan the following definitions: struct SomeStruct { int x; float y; }; enum SomeEnum { SOME_FOO, SOME_BAR }; int hello_xpto (struct SomeStruct xto); int hello_zbr (enum SomeEnum xto); typedef struct { int x; float y; } SomeStruct2; typedef enum { SOME2_FOO, SOME2_BAR } SomeEnum2; int hello_xpto2 (SomeStruct2 xto); int hello_zbr2 (SomeEnum2 xto); The intent is to generate bindings for, in this case, a pure C library, using pure C code. My issue here is how to distinguish between an enum defined via a typedef (SomeEnum2) and an enum the old fashioned C way. Because the type needs to generated differently in both cases. I have to generate 'enum SomeEnum', because simply referencing 'SomeEnum' does not compile with a C compiler. On the other hand, I cannot generate a type string 'enum SomeEnum2', because SomeEnum2 is actually a typedef, not a proper enum; it also does not compile. So always putting enum in front of everything does not work. Idem for 'struct SomeStruct' vs 'SomeStruct2'. I have been experimenting for a while, but could not find any way to distinguish between the two cases. Any idea? Thanks in advance. -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert |
From: Damien F. <dam...@mo...> - 2008-07-23 08:37:57
|
Roman Yakovenko wrote: > On Tue, Jul 22, 2008 at 8:46 PM, Damien Fagnou > <dam...@mo...> wrote: > >> Hi , >> >> the library that I need to convert is organized sort like : >> >> src/algo >> /misc/string >> /number >> /utils >> /stream >> >> then inside the file the include are : >> >> #include "algo/sort.h" >> #include "misc/string/capitalize.h" >> #include "stream/save.h" >> >> reading the documentation I originally copied all the header into a >> single directory an include those into the main file to Bind. >> this work quite well but there is some problem . >> - I can't use the live files >> - there are some file with the same names . >> - etc >> >> I there a way to update my project so I could have one include file : >> >> #include "algo/sort.h" >> #include "misc/string/capitalize.h" >> #include "stream/save.h" >> #include "utils/io.h" >> >> then setup my search so it doesnt exlude the class registered in ./algo >> , ./mist , ./stream , ./utils ? >> I have try using the include path , but didnt manage to make it work . >> just want to make sure its possible . >> > > Hope next code will help you, at least will give you some direction > It definitely did ! Thanks again for you quick and useful reply . > import os > > source_dir = absolute path to "src" directory > source_files = iterate over source_dir recursive and gather all files, > use absolute paths > > tmp = [] > for f in source_files: > tmp.append( '#include "%s"' % f ) > tmp = os.linesep.join( tmp ) > > from pygccxml import parser > > mb = module_builder_t( [ parser.create_text_fc( tmp ) ], .... ); > > #now I hope you can filter on location: > > def my_filter( decl ): > if not decl.location: > return True > elif decl.location.file_name is under one of your directories: > return True > else: > return False > > mb.global_ns.exclude() > mb.global_ns.decls( my_filter ).include() > > HTH > > |
From: Roman Y. <rom...@gm...> - 2008-07-22 18:27:08
|
On Tue, Jul 22, 2008 at 8:46 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > the library that I need to convert is organized sort like : > > src/algo > /misc/string > /number > /utils > /stream > > then inside the file the include are : > > #include "algo/sort.h" > #include "misc/string/capitalize.h" > #include "stream/save.h" > > reading the documentation I originally copied all the header into a > single directory an include those into the main file to Bind. > this work quite well but there is some problem . > - I can't use the live files > - there are some file with the same names . > - etc > > I there a way to update my project so I could have one include file : > > #include "algo/sort.h" > #include "misc/string/capitalize.h" > #include "stream/save.h" > #include "utils/io.h" > > then setup my search so it doesnt exlude the class registered in ./algo > , ./mist , ./stream , ./utils ? > I have try using the include path , but didnt manage to make it work . > just want to make sure its possible . Hope next code will help you, at least will give you some direction import os source_dir = absolute path to "src" directory source_files = iterate over source_dir recursive and gather all files, use absolute paths tmp = [] for f in source_files: tmp.append( '#include "%s"' % f ) tmp = os.linesep.join( tmp ) from pygccxml import parser mb = module_builder_t( [ parser.create_text_fc( tmp ) ], .... ); #now I hope you can filter on location: def my_filter( decl ): if not decl.location: return True elif decl.location.file_name is under one of your directories: return True else: return False mb.global_ns.exclude() mb.global_ns.decls( my_filter ).include() HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-07-22 17:46:29
|
Hi , the library that I need to convert is organized sort like : src/algo /misc/string /number /utils /stream then inside the file the include are : #include "algo/sort.h" #include "misc/string/capitalize.h" #include "stream/save.h" reading the documentation I originally copied all the header into a single directory an include those into the main file to Bind. this work quite well but there is some problem . - I can't use the live files - there are some file with the same names . - etc I there a way to update my project so I could have one include file : #include "algo/sort.h" #include "misc/string/capitalize.h" #include "stream/save.h" #include "utils/io.h" then setup my search so it doesnt exlude the class registered in ./algo , ./mist , ./stream , ./utils ? I have try using the include path , but didnt manage to make it work . just want to make sure its possible . Thanks Damien |
From: Roman Y. <rom...@gm...> - 2008-07-21 18:05:00
|
On Mon, Jul 21, 2008 at 5:50 PM, Vincent Ferries <vin...@gm...> wrote: > My work is going pretty well thanks to all your support and advices, > and I can see the light. > Unfortunately, I encountered another problem. > > Using one of the wrapped methods, I've a Segmentation fault exception. > I tried to call this method with the same argument directly from my > C++ compiled code and all worked well, without any exception. > > I double-looked at my python code and can't see any mistake. > > This method is defined in a class called NastranDatabase. It simply > reads a file and stores the data in the NastranDatabase class as > attributes. > The method has 6 parameters, the last 2 ones are optional. > Param 1 : string const & -> the file name > Param 2 : vector<std::string> const & -> just a filter, I can put an > empty vector in > Param 3 : string const & -> the jidType, no matter what it is, I can > give it an empty string > Param 4 : map<std::string, std::string> const & -> another filter, I > can put an empty map in > Param 5 : boolean -> verbose or not > Param 6 : boolean -> If we must read the header or not, default false > This method doesn't return anything. > > I tried following solutions to map it correctly : > - leaving py++ generate it automaticaly > - a lot of different method conversions like > nastranDb.member_functions('readBdf').add_transformation(FT.modify_type(0, > declarations.remove_reference), FT.input(1), FT.input(2), FT.input(3)) > > None of these worked. > The wrapper generation and the compilation seem to work fine. > But the execution never work... > > Do you have an idea of what could be wrong? No. In order to save you and me time, please create small and complete example that reproduce the problem. This is the only way to solve issues like that. P.S. It looks like the member function could be exposed as-is, you don't need any function transformations. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-07-21 14:50:24
|
My work is going pretty well thanks to all your support and advices, and I can see the light. Unfortunately, I encountered another problem. Using one of the wrapped methods, I've a Segmentation fault exception. I tried to call this method with the same argument directly from my C++ compiled code and all worked well, without any exception. I double-looked at my python code and can't see any mistake. This method is defined in a class called NastranDatabase. It simply reads a file and stores the data in the NastranDatabase class as attributes. The method has 6 parameters, the last 2 ones are optional. Param 1 : string const & -> the file name Param 2 : vector<std::string> const & -> just a filter, I can put an empty vector in Param 3 : string const & -> the jidType, no matter what it is, I can give it an empty string Param 4 : map<std::string, std::string> const & -> another filter, I can put an empty map in Param 5 : boolean -> verbose or not Param 6 : boolean -> If we must read the header or not, default false This method doesn't return anything. I tried following solutions to map it correctly : - leaving py++ generate it automaticaly - a lot of different method conversions like nastranDb.member_functions('readBdf').add_transformation(FT.modify_type(0, declarations.remove_reference), FT.input(1), FT.input(2), FT.input(3)) None of these worked. The wrapper generation and the compilation seem to work fine. But the execution never work... Do you have an idea of what could be wrong? Thanks in advance. |
From: Roman Y. <rom...@gm...> - 2008-07-14 19:38:34
|
On Mon, Jul 14, 2008 at 8:56 AM, Gordon Wrigley <gor...@gm...> wrote: > and there are no calls for destructors Not anymore: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1372 -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Gordon W. <gor...@gm...> - 2008-07-14 05:56:11
|
and there are no calls for destructors On Sun, Jul 13, 2008 at 2:59 PM, Roman Yakovenko <rom...@gm...> wrote: > On Fri, Jul 11, 2008 at 4:40 AM, Gordon Wrigley > <gor...@gm...> wrote: > > it would be nice to have an add version of set_constructors_body that > > appends stuff > > I can add this. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |