#13 Replacing include'd file by its contents bug

closed
nobody
None
5
2008-06-12
2008-06-11
Mike Wilson
No

"Different results from Py++ if include'd file is replaced by its contents"

Py++ gives seems to be giving different results depending on whether a file (in this case pair.hpp)
is "include"d or not.

The file

include_file.hpp

has the following lines

#include "pair.hpp"
pair<double,double> f2();
int j = sizeof(pair<double,double>);

pair.hpp (the include'd file) consists of

template<typename T1, typename T2>
struct pair
{
pair(T1,T2);
T1 first;
T2 second;
};

The file

insert_text.hpp

is a copy of include_file.hpp, but with the include statement replaced
with the actual contents of pair.hpp, as follows:

template<typename T1, typename T2>
struct pair
{
pair(T1,T2);
T1 first;
T2 second;
};
pair<double,double> f2();
int j = sizeof(pair<double,double>);

I'd expect the results from Py++ for include_file.hpp to to be the same as insert_text.hpp,
but they are not, the latter correctly(?) generates the following

bp::class_< pair< double, double > >( "pair_less_ ..... )
.def_readwrite(....)
.def_readwrite(....);

Now I do realise how to overcome this problem, but I thought this bug should be reported.

You can run the file test.bat to run the two test cases.
The results are logged in .log.txt files.

(I found this error when trying to instantiate std::pair using sizeof!)
Mike

Discussion

  • Mike Wilson
    Mike Wilson
    2008-06-11

    Contains test.bat & test.py to show error

     
    Attachments
  • Roman
    Roman
    2008-06-12

    Logged In: YES
    user_id=1084190
    Originator: NO

    Hi Mikey. What you found is not bug, but a "feature".

    By default, Py++ exposes only declarations from the header files you pass to module_builder_t.__init__ method.

    I am aware that this is a source of confusions, but unfortunately it could not be changed. Any other behavior is not better and creates confusion in some situation. Also there are backward compatibility reasons too.

    The work around is pretty simple: just define explicitly what you want to export.

     
  • Roman
    Roman
    2008-06-12

    • status: open --> closed