[C++-sig] pygccxml and template classes

2010-12-08 Thread Davidson, Josh
I'm having some trouble getting pyccxml to parse specialized classes.  Consider 
the following simple header file:


#ifndef TEMPLATECLASS_HPP_
#define TEMPLATECLASS_HPP_

template 
class TemplateClass {
public:
TemplateClass(){}

protected:
int x;
Type1 y;
Type2 z;


};

#endif


Now, if I parse it with the following statements:
loggers.gccxml.setLevel(logging.WARNING)
config = parser.config_t(gccxml_path="gccxml", include_paths=includes, 
define_symbols=defines)
#file is above header file
decls = parser.parse([file], config)
xml = declarations.get_global_namespace(decls)

It parses OK, but xml.classes() returns nothing.  If I remove the template 
types, it works fine.  What am I doing wrong?

Thanks,
Josh
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] pygccxml and template classes

2010-12-08 Thread Roman Yakovenko
On Wed, Dec 8, 2010 at 9:40 AM, Davidson, Josh wrote:

> I'm having some trouble getting pyccxml to parse specialized classes.
>  Consider the following simple header file:
>
>
> #ifndef TEMPLATECLASS_HPP_
> #define TEMPLATECLASS_HPP_
>
> template 
> class TemplateClass {
>
   ...

> };
>
> #endif
>
>
> Now, if I parse it with the following statements:
> loggers.gccxml.setLevel(logging.WARNING)
> config = parser.config_t(gccxml_path="gccxml", include_paths=includes,
> define_symbols=defines)
> #file is above header file
> decls = parser.parse([file], config)
> xml = declarations.get_global_namespace(decls)
>
> It parses OK, but xml.classes() returns nothing.  If I remove the template
> types, it works fine.  What am I doing wrong?
>
>
Nothing.

GCC-XML is not able to dump template classes, but only template
instantiations.


HTH
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] Cygwin and boost::python exceptions

2010-12-08 Thread Brad Bell

There seems to be a problem with the example on

http://www.boost.org/doc/libs/1_45_0/libs/python/doc/v2/exception_translator.html

when I compile it I get the following message:
--
bradb...@apl-9232eef971d ~/pycppad/boost_py
$ g++  -I/usr/include/python2.6 -g -c exception.cpp
exception.cpp: In function `void translate(const my_exception&)':
exception.cpp:14: error: passing `const my_exception' as `this' argument 
of `con

st char* my_exception::what()' discards qualifiers
exception.cpp: In function `void something_which_throws()':
exception.cpp:19: error: expected primary-expression before `...' token
exception.cpp:19: error: expected `;' before `...' token
exception.cpp:21: error: expected primary-expression before `...' token
exception.cpp:21: error: expected `;' before `...' token

bradb...@apl-9232eef971d ~/pycppad/boost_py
$ g++ --version
g++ (GCC) 4.3.4 20090804 (release) 1
--

I have figured out a way around this problem, see the attached file 
exception.sh. This works fine under unix, but under cygwin, the 
exception does not seem to be caught by the python 'except' section of 
the 'try' block.


--
Here is the result of running exception.sh under unix:

[bradb...@localhost trash]$ ./exception.sh
cat << EOF > exception.cpp
g++  -I/usr/include/python2.7 -g -c exception.cpp
g++ -shared  \
-g \
exception.o \
-L/usr/lib -L/usr/lib/python2.7/config  \
-lboost_python-mt -lpython2.7 \
-o exception.so
cat << EOF > exception.py
exception.sh: OK
...
--
Here is the result of running under cygwin:

$ ./exception.sh
cat << EOF > exception.cpp
g++  -I/usr/include/python2.6 -g -c exception.cpp
g++ -shared -Wl,--enable-auto-image-base \
-g \
exception.o \
-L/usr/lib -L/usr/lib/python2.6/config  \
-lboost_python-mt -lpython2.6 \
-o exception.dll
cat << EOF > exception.py
terminate called after throwing an instance of 'my_exception'
  what():  my error message
./exception.sh: line 97:  2108 Aborted (core dumped) 
python exception.py

exception.sh: Error

# /bin/bash
set -e
# Modified version of http://www.boost.org/doc/libs/1_45_0/libs/python/doc/v2/
#   exception_translator.html
# --
python_version=`ls /usr/include | grep python | sed -e 's/python//'` 
system=`uname | sed -e 's/\(..\).*/\1/'`
if [ "$system" == "CYGWIN" ]
then
extra_compile="-Wl,--enable-auto-image-base"
library_extension=".dll"
else
extra_compile=""
library_extension=".so"
fi
# --
#
echo "cat << EOF > exception.cpp"
cat << EOF > exception.cpp
# include 
# include 
# include 
# include 
# include 

class my_exception : public std::exception
{   
private : 
char message_[201];
public :
my_exception(const char* message)
{   strncpy(message_, message, 200);
message_[200] = '\0';
}
const char* what(void) const throw()
{   return message_; }

};

void translate(my_exception const& e)
{
// Use the Python 'C' API to set up an exception object
PyErr_SetString(PyExc_RuntimeError, e.what());
}

void something_which_throws()
{
throw my_exception("my error message");
}

BOOST_PYTHON_MODULE(exception)
{
  boost::python::register_exception_translator(&translate);
  
  boost::python::def("something_which_throws", something_which_throws);
}
EOF
#
echo "g++  -I/usr/include/python$python_version -g -c exception.cpp"
g++  -I/usr/include/python$python_version -g -c exception.cpp 
#
echo "g++ -shared $extra_compile \\"
echo "  -g \\"
echo "  exception.o \\"
echo "  -L/usr/lib -L/usr/lib/python$python_version/config  \\"
echo "  -lboost_python-mt -lpython$python_version \\"
echo "  -o exception$library_extension"
g++ -shared $extra_compile \
-g \
exception.o \
-L/usr/lib -L/usr/lib/python$python_version/config \
-lboost_python-mt -lpython$python_version \
-o exception$library_extension
#
echo "cat << EOF > exception.py"
cat << EOF > exception.py
from sys import exit
import exception
try :
exception.something_which_throws()
except RuntimeError :
exit(0) 
exit(1)
EOF
if python exception.py
then
flag=0
echo "exception.sh: OK"
for ext in .cpp .o $library_extension .py
do
echo "rm exception$ext"
rm exception$ext
done
else
echo "exception.sh: Error"
flag=1
fi
exit $flag
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusp