unable to wrap an exception that inherits from std:exception (in <exception>)

Bug #1044185 reported by Owen Kelly
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyBindGen
New
Undecided
Unassigned

Bug Description

Hello all,

I am trying to wrap an exception that inherits from std::exception that is found in the standard c++ include file <exception>.
I have reproduced this issue on Linux (Ubuntu 12.04) and Win7x64.

Ubuntu 12.04, Python 2.7.3, gcc 4.6.3, GCC-XML version 0.9.0, pybindgen 0.1.6
Win7x64 under MSVC++ 2008 Express, Python 2.6.6, GCC-XML version 0.9.0, pybindgen 0.1.6

The approach is using pybindgen to generate a script which then generates the wrapper code (Workflow 3).
The errors reported are at the first stage of the workflow.

To reproduce:

1. On Linux, open a terminal in which gccxml and python are accessible at the command line.
2. Cd to a folder that contains MyException.h and exc_module-gen.py as included below.
3. At the prompt, issue the command

                 python exc_module-gen.py 2> err.txt

4. Examine err.txt and see that it matches what is reported below. Specifically, there is an error

>>> looking at class gdf::exception::general [class]
C:\Users\wrap\MyException.h:21: ModuleParserWarning: Class ::gdf::exception::general ign
ored because it uses a base class (::std::exception) which is not declared.
  {

There are no special search paths or environment variables set up in the terminal, except that python, and gccxml are available in the path.

It is very possible that I am not using pybindgen in the correct way, but I have tried many things.
The final approach was to reduce the problem to this very minimal example.

Thanks and regards,

Owen

--------- MyException.h ------------------
#ifndef __MYEXCEPTION_H_INCLUDED__
#define __MYEXCEPTION_H_INCLUDED__

#include <exception>
#include <string>

namespace gdf {
        /// A general exception
        class general : public std::exception
        {
        public:
            general( const std::string str ) { msg = str; }
            virtual ~general( ) throw() { }
            const char *what( ) const throw() { return msg.c_str(); }
        private:
            std::string msg;
        };

}

#endif

-------- exc_module-gen.py --------------
#! /usr/bin/env python

import sys

import pybindgen
from pybindgen import FileCodeSink
from pybindgen.gccxmlparser import ModuleParser
import os.path

def my_module_gen():
    '''
    Generates a script codegen.py to generate a wrapper for MyException.h.

    Does not work yet...

    '''

    inputpath = "/home/user/Documents/pbg/MyException.h"

    pygen_file = open('codegen.py', "wt")

    gccxml_options = {'include_paths':
        ['.',
         '/usr/include/c++/4.6.3/',
         '/usr/include/python2.7/'],
         'gccxml_path':'/usr/bin/gccxml',
         'define_symbols':['_HAS_TR1=0']}

    module_parser = ModuleParser('MyException_module', '::')

    module_parser.parse_init([inputpath],
                             includes=['"%s"' % inputpath],
                             whitelist_paths=['/usr/include/c++/4.6.3/exception',],
                             gccxml_options=gccxml_options,
                             pygen_sink=FileCodeSink(pygen_file))

    module = module_parser.module
    std_exception=module.add_exception('exception', foreign_cpp_namespace='::std', message_rvalue='%(EXC)s.what()')
    general_exception=module.add_exception('general', foreign_cpp_namespace='::gdf', message_rvalue='%(EXC)s.what()', parent=std_exception)

    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    pygen_file.close()

if __name__ == '__main__':
    my_module_gen()

 ------------ err.txt ------------------------

INFO Parsing source file "/home/user/Documents/pbg/MyException.h" ...
INFO gccxml cmd: /usr/bin/gccxml -I"." -I"." -I"/usr/include/c++/4.6.3/" -I"/usr/include/python2.7/" -D"_HAS_TR1=0" "/home/user/Documents/pbg/MyException.h" -fxml="/tmp/tmptypbuX.xml"
INFO GCCXML version - 0.9
/home/user/Documents/pbg/MyException.h:14: ModuleParserWarning: Class ::gdf::general ignored because it uses a base class (::std::exception) which is not declared.
  {

---------------- end -------------------------------

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.