Exemplo n.º 1
0
def my_module_gen():
    #module_parser = ModuleParser('a1', '::')
    module_parser = ModuleParser('pypm', '::')
    module = module_parser.parse(['libpm.h'], ["/usr/include/", "lib/"])
    module.add_include('"libpm.h"')
    
    pybindgen.write_preamble(FileCodeSink(sys.stdout))
    module.generate(FileCodeSink(sys.stdout))
Exemplo n.º 2
0
def module_gen():
    os.chdir('/home/trevorsweetnam/Dropbox/notebooks/eef/emxarr/codegen/dll/emx_test')
    #module_parser = ModuleParser('emx_test_emxAPI', '::')
    #module = module_parser.parse(['emx_test_emxAPI.h'])
    #module.add_include('"emx_test_emxAPI.h"')
    
    module_parser = ModuleParser('emx_test', '::')
    module = module_parser.parse(['emx_test.h'])
    module.add_include('"rt_noninfite.h"')
    module.add_include('"emx_test_emxutil.h"')
    
    pybindgen.write_preamble(FileCodeSink(sys.stdout))
    module.generate(FileCodeSink(sys.stdout))
def main():
    out = FileCodeSink(sys.stdout)

    root_module = syncmlmodule_generated.module_init()
    root_module.add_include('"pysyncml.h"')

    syncmlmodule_generated.register_types(root_module)
    syncmlmodule_generated.register_methods(root_module)
    syncmlmodule_generated.register_functions(root_module)

    callback_customizations(root_module)

    write_preamble(out)
    root_module.generate(out)
Exemplo n.º 4
0
def my_module_gen():
    include_paths = [
        os.path.join(base_dir, 'Include'),
        os.path.join(base_dir, 'Src'),
    ]
    header_files = []

    for root, dirs, files in os.walk(base_dir):
        for filename in files:
            if filename.endswith('.h'):
                header_files.append(
                    os.path.join(root, filename)
                )

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

    modules = dict()

    for header in header_files:

        name = header.split('/').pop()
        name = name.split('.')[0]
        try:
            modules[name] = module_parser.parse(
                [header, ],
                gccxml_options = dict(include_paths=include_paths),
                )
        except Exception as _ex:
            logging.warning(
                "Couldn't parse {}: {}\n".format(header, _ex.message)
                )

    for name, module in modules.iteritems():
        try:
            outfile = open(
                os.path.join(build_dir, name + '.cpp')
                , 'w'
            )
            write_preamble(FileCodeSink(outfile))
            module.generate(FileCodeSink(outfile))
            if not outfile.closed:
                outfile.close()
        except Exception as _ex:
            logging.warning(
                "Couldn't write {}: {}\n".format(name, _ex.message)
                )
Exemplo n.º 5
0
def test():
    code_out = codesink.FileCodeSink(sys.stdout)
    pybindgen.write_preamble(code_out)
    print
    print "#include <string>"
    print "#include <stdint.h>"
    print

    ## Declare a dummy class
    sys.stdout.write('''
class Foo
{
    std::string m_datum;
public:
    Foo () : m_datum ("")
        {}
    Foo (std::string datum) : m_datum (datum)
        {}
    std::string get_datum () const { return m_datum; }

    Foo (Foo const & other) : m_datum (other.get_datum ())
        {}
};
''')

    module = Module("foo")

    ## Register type handlers for the class
    Foo = cppclass.CppClass('Foo')
    Foo.module = module
    #Foo.full_name = Foo.name # normally adding the class to a module would take care of this
    Foo.generate_forward_declarations(code_out, module)

    wrapper_number = 0

    ## test return type handlers of reverse wrappers
    for return_type, return_handler in typehandlers.base.return_type_matcher.items(
    ):
        if os.name == 'nt':
            if stdint_rx.search(return_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        if issubclass(return_handler,
                      (cppclass.CppClassPtrReturnValue,
                       typehandlers.pyobjecttype.PyObjectReturnValue)):
            for caller_owns_return in True, False:
                retval = return_handler(return_type,
                                        caller_owns_return=caller_owns_return)
                wrapper = MyReverseWrapper(retval, [])
                wrapper_number += 1
                try:
                    wrapper.generate(
                        code_out,
                        '_test_wrapper_number_%i' % (wrapper_number, ),
                        ['static'])
                except NotImplementedError:
                    print >> sys.stderr, \
                        ("ReverseWrapper %s(void) (caller_owns_return=%r)"
                         " could not be generated: not implemented"
                         % (retval.ctype, caller_owns_return))
                print
        else:
            retval = return_handler(return_type)
            try:
                wrapper = MyReverseWrapper(retval, [])
            except NotSupportedError:
                continue
            wrapper_number += 1
            try:
                wrapper.generate(
                    code_out, '_test_wrapper_number_%i' % (wrapper_number, ),
                    ['static'])
            except NotImplementedError:
                print >> sys.stderr, (
                    "ReverseWrapper %s(void) could not be generated: not implemented"
                    % (retval.ctype, ))
            print

    ## test parameter type handlers of reverse wrappers
    for param_type, param_handler in typehandlers.base.param_type_matcher.items(
    ):
        if os.name == 'nt':
            if stdint_rx.search(param_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        for direction in param_handler.DIRECTIONS:
            if direction == (Parameter.DIRECTION_IN):
                param_name = 'param'
            elif direction == (Parameter.DIRECTION_IN
                               | Parameter.DIRECTION_OUT):
                param_name = 'param_inout'
            elif direction == (Parameter.DIRECTION_OUT):
                param_name = 'param_out'

                def try_wrapper(param, wrapper_number):
                    if 'const' in param.ctype and direction & Parameter.DIRECTION_OUT:
                        return
                    wrapper = MyReverseWrapper(ReturnValue.new('void'),
                                               [param])
                    try:
                        wrapper.generate(
                            code_out,
                            '_test_wrapper_number_%i' % (wrapper_number, ),
                            ['static'])
                    except NotImplementedError:
                        print >> sys.stderr, (
                            "ReverseWrapper void(%s) could not be generated: not implemented"
                            % (param.ctype))
                    print

                if issubclass(param_handler,
                              (cppclass.CppClassPtrParameter,
                               typehandlers.pyobjecttype.PyObjectParam)):
                    for transfer_ownership in True, False:
                        try:
                            param = param_handler(
                                param_type,
                                param_name,
                                transfer_ownership=transfer_ownership)
                        except TypeError:
                            print >> sys.stderr, "ERROR -----> param_handler(param_type=%r, "\
                                "transfer_ownership=%r, is_const=%r)"\
                                % (param_type, transfer_ownership, is_const)
                        wrapper_number += 1
                        try_wrapper(param, wrapper_number)
                else:
                    param = param_handler(param_type, param_name, direction)
                    wrapper_number += 1
                    try_wrapper(param, wrapper_number)

    ## test generic forward wrappers, and module

    for return_type, return_handler in typehandlers.base.return_type_matcher.items(
    ):
        if os.name == 'nt':
            if stdint_rx.search(return_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        wrapper_number += 1
        function_name = 'foo_function_%i' % (wrapper_number, )
        ## declare a fake prototype
        print "%s %s(void);" % (return_type, function_name)
        print

        if issubclass(return_handler,
                      (cppclass.CppClassPtrReturnValue,
                       typehandlers.pyobjecttype.PyObjectReturnValue)):
            retval = return_handler(return_type, caller_owns_return=True)
        else:
            retval = return_handler(return_type)

        module.add_function(function_name, retval, [])

    for param_type, param_handler in typehandlers.base.param_type_matcher.items(
    ):
        if os.name == 'nt':
            if stdint_rx.search(param_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)

        for is_const in [True, False]:
            for direction in param_handler.DIRECTIONS:
                if direction == (Parameter.DIRECTION_IN):
                    param_name = 'param'
                elif direction == (Parameter.DIRECTION_IN
                                   | Parameter.DIRECTION_OUT):
                    param_name = 'param_inout'
                elif direction == (Parameter.DIRECTION_OUT):
                    param_name = 'param_out'

                if is_const and direction & Parameter.DIRECTION_OUT:
                    continue  # const and output parameter makes no sense

                if is_const:
                    if '&' in param_type:  # const references not allowed
                        continue
                    param_type_with_const = "const %s" % (param_type, )
                else:
                    param_type_with_const = param_type

                if issubclass(param_handler,
                              (cppclass.CppClassPtrParameter,
                               typehandlers.pyobjecttype.PyObjectParam)):
                    for transfer_ownership in True, False:
                        name = param_name + (transfer_ownership and '_transfer'
                                             or '_notransfer')
                        try:
                            param = param_handler(
                                param_type,
                                name,
                                transfer_ownership=transfer_ownership)
                        except TypeError:
                            print >> sys.stderr, "ERROR -----> param_handler(param_type=%r, "\
                                "name=%r, transfer_ownership=%r, is_const=%r)"\
                                % (param_type, name, transfer_ownership, is_const)
                        wrapper_number += 1
                        function_name = 'foo_function_%i' % (wrapper_number, )
                        ## declare a fake prototype
                        print "void %s(%s %s);" % (function_name,
                                                   param_type_with_const, name)
                        print
                        module.add_function(function_name,
                                            ReturnValue.new('void'), [param])
                else:
                    param = param_handler(param_type, param_name, direction)
                    wrapper_number += 1
                    function_name = 'foo_function_%i' % (wrapper_number, )
                    ## declare a fake prototype
                    print "void %s(%s);" % (function_name,
                                            param_type_with_const)
                    print
                    module.add_function(function_name, ReturnValue.new('void'),
                                        [param])

    module.generate(code_out)
Exemplo n.º 6
0
def dcepy_module_gen(binddir, ns3path, dcepath):
    DCE_INCLUDE_PATH = dcepath
    '''
    print "************************* dcepy_module_gen"
    print "* binddir = " + binddir
    print "* ns3path = " + ns3path
    print "* dcepath = " + dcepath
    print "******************************************"
    '''

    cflags = ''

    bldpath = 'bindings/python'
    try:
        os.makedirs(bldpath)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(bldpath):
            pass
        else:
            raise

    ref_header_dir = binddir + "/refh"
    gccxml_options = dict(
        #include_paths=[ns3path, dcepath+"/model", dcepath + "/helper"],
        include_paths=[ref_header_dir, ns3path],
        define_symbols={
            #'NS3_ASSERT_ENABLE': None,
            #'NS3_LOG_ENABLE': None,
        },
        cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags))

    inclfiles = []
    for hf in includes_dce:
        inclfiles.append(ref_header_dir + "/" + hf)
        #inclfiles.append( dcepath+"/model/"+hf  )

    #whitelist_paths=[ dcepath+"/model", dcepath + "/helper", ns3path  ]
    whitelist_paths = [ref_header_dir]

    module_parser = ModuleParser('dce', 'ns3')
    module_parser.enable_anonymous_containers = True
    module_parser.add_pre_scan_hook(pre_scan_hook)

    generatepyintermediate = True
    if generatepyintermediate:
        # Test with intermediate file
        fname = bldpath + '/temp_dce_bindings.py'
        print "Generating python pygendbind intermediate file: " + str(fname)
        py_file = open(fname, "wt")
        includes = [
            '"ns3/dce-module.h"', '"ns3/dce-manager-helper.h"',
            '"ns3/dce-application.h"', '"ns3/ipv4-dce-routing-helper.h"'
        ]
        pysink = FileCodeSink(py_file)
        module_parser.parse_init(inclfiles,
                                 whitelist_paths=whitelist_paths,
                                 pygen_sink=pysink,
                                 gccxml_options=gccxml_options,
                                 includes=includes)
        module_parser.scan_types()
        module_parser.scan_methods()
        module_parser.scan_functions()
        module_parser.parse_finalize()

    else:
        # Test with cpp
        fname = bldpath + '/temp_dce_bindings.cpp'
        #fname = 'dce_bindings.cpp'
        print "Generating python bindings c++ file: " + str(fname)
        pygen_file = open(fname, "wt")
        module_parser.parse_init(inclfiles,
                                 whitelist_paths=whitelist_paths,
                                 gccxml_options=gccxml_options)

        module_parser.scan_types()
        module_parser.scan_methods()
        module_parser.scan_functions()
        module_parser.parse_finalize()
        module_parser.module.add_include('<ns3/dce-module.h>')
        module_parser.module.add_include('<ns3/dce-manager-helper.h>')
        module_parser.module.add_include('<ns3/dce-application.h>')
        module_parser.module.add_include('<ns3/ipv4-dce-routing-helper.h>')
        module_parser.module.add_include('<ns3/linux-stack-helper.h>')
        pybindgen.write_preamble(FileCodeSink(pygen_file))
        module_parser.module.generate(FileCodeSink(pygen_file))
Exemplo n.º 7
0
def test():
    code_out = codesink.FileCodeSink(sys.stdout)
    pybindgen.write_preamble(code_out)
    sys.stdout.write("""
#include <string>
#include <stdint.h>
""")
    ## Declare a dummy class
    sys.stdout.write('''
class Foo
{
    std::string m_datum;
public:
    Foo () : m_datum ("")
        {}
    Foo (std::string datum) : m_datum (datum)
        {}
    std::string get_datum () const { return m_datum; }

    Foo (Foo const & other) : m_datum (other.get_datum ())
        {}
};
''')

    module = Module("foo")

    ## Register type handlers for the class
    Foo = cppclass.CppClass('Foo')
    Foo.module = module
    #Foo.full_name = Foo.name # normally adding the class to a module would take care of this
    Foo.generate_forward_declarations(code_out, module)

    wrapper_number = 0

    ## test return type handlers of reverse wrappers
    for return_type, return_handler in list(typehandlers.base.return_type_matcher.items()):
        if type_blacklisted(return_type):
            continue
        if os.name == 'nt':
            if stdint_rx.search(return_type):
                continue # win32 does not support the u?int\d+_t types (defined in <stdint.h>)

        code_out.writeln("/* Test %s (%s) return type  */" % (return_type, return_handler))
        if issubclass(return_handler, (cppclass.CppClassPtrReturnValue,
                                       typehandlers.pyobjecttype.PyObjectReturnValue)):
            for caller_owns_return in True, False:
                retval = return_handler(return_type, caller_owns_return=caller_owns_return)
                wrapper = MyReverseWrapper(retval, [])
                wrapper_number += 1
                try:
                    wrapper.generate(code_out,
                                     '_test_wrapper_number_%i' % (wrapper_number,),
                                     ['static'])
                except NotImplementedError:
                    sys.stderr.write("ReverseWrapper %s(void) (caller_owns_return=%r)"
                                     " could not be generated: not implemented\n"
                                     % (retval.ctype, caller_owns_return))
                sys.stdout.write("\n")
        else:
            retval = return_handler(return_type)
            try:
                wrapper = MyReverseWrapper(retval, [])
            except NotSupportedError:
                continue
            except NotImplementedError:
                sys.stderr.write("ReverseWrapper %s(void) could not be generated: not implemented\n"
                                 % (retval.ctype))
                continue
            wrapper_number += 1
            memsink = codesink.MemoryCodeSink()
            try:
                wrapper.generate(memsink,
                                 '_test_wrapper_number_%i' % (wrapper_number,),
                                 ['static'])
            except NotImplementedError:
                sys.stderr.write("ReverseWrapper %s xxx (void) could not be generated: not implemented\n"
                                 % (retval.ctype,))
                continue
            except NotSupportedError:
                continue
            else:
                memsink.flush_to(code_out)
            sys.stdout.write("\n")


    ## test parameter type handlers of reverse wrappers
    for param_type, param_handler in list(typehandlers.base.param_type_matcher.items()):
        if type_blacklisted(param_type):
            continue
        if os.name == 'nt':
            if stdint_rx.search(param_type):
                continue # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        for direction in param_handler.DIRECTIONS:
            if direction == (Parameter.DIRECTION_IN):
                param_name = 'param'
            elif direction == (Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT):
                param_name = 'param_inout'
            elif direction == (Parameter.DIRECTION_OUT):
                param_name = 'param_out'

                def try_wrapper(param, wrapper_number):
                    if 'const' in param.ctype and direction&Parameter.DIRECTION_OUT:
                        return
                    code_out.writeln("/* Test %s (%s) param type  */" % (param_type, param_handler))
                    wrapper = MyReverseWrapper(ReturnValue.new('void'), [param])
                    try:
                        wrapper.generate(code_out,
                                         '_test_wrapper_number_%i' % (wrapper_number,),
                                         ['static'])
                    except NotImplementedError:
                        sys.stderr.write("ReverseWrapper void(%s) could not be generated: not implemented"
                                         % (param.ctype))
                    sys.stdout.write("\n")

                if issubclass(param_handler, (cppclass.CppClassPtrParameter,
                                              typehandlers.pyobjecttype.PyObjectParam)):
                    for transfer_ownership in True, False:
                        try:
                            param = param_handler(param_type, param_name, transfer_ownership=transfer_ownership)
                        except TypeError:
                            sys.stderr.write("ERROR -----> param_handler(param_type=%r, "
                                             "transfer_ownership=%r, is_const=%r)\n"
                                             % (param_type, transfer_ownership, is_const))
                        wrapper_number += 1
                        try_wrapper(param, wrapper_number)
                else:
                    param = param_handler(param_type, param_name, direction)
                    wrapper_number += 1
                    try_wrapper(param, wrapper_number)

    
    ## test generic forward wrappers, and module

    for return_type, return_handler in list(typehandlers.base.return_type_matcher.items()):
        if type_blacklisted(return_type):
            continue
        if os.name == 'nt':
            if stdint_rx.search(return_type):
                continue # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        wrapper_number += 1
        function_name = 'foo_function_%i' % (wrapper_number,)
        ## declare a fake prototype
        sys.stdout.write("%s %s(void);\n\n" % (return_type, function_name))

        if issubclass(return_handler, (cppclass.CppClassPtrReturnValue,
                                       typehandlers.pyobjecttype.PyObjectReturnValue)):
            retval = return_handler(return_type, caller_owns_return=True)
        else:
            retval = return_handler(return_type)

        module.add_function(function_name, retval, [])
    
    for param_type, param_handler in list(typehandlers.base.param_type_matcher.items()):
        if type_blacklisted(param_type):
            continue
        if os.name == 'nt':
            if stdint_rx.search(param_type):
                continue # win32 does not support the u?int\d+_t types (defined in <stdint.h>)

        for is_const in [True, False]:
            for direction in param_handler.DIRECTIONS:
                if direction == (Parameter.DIRECTION_IN):
                    param_name = 'param'
                elif direction == (Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT):
                    param_name = 'param_inout'
                elif direction == (Parameter.DIRECTION_OUT):
                    param_name = 'param_out'

                if is_const and direction & Parameter.DIRECTION_OUT:
                    continue # const and output parameter makes no sense

                if is_const:
                    if '&' in param_type: # const references not allowed
                        continue
                    param_type_with_const = "const %s" % (param_type,)
                else:
                    param_type_with_const = param_type

                if issubclass(param_handler, (cppclass.CppClassPtrParameter,
                                              typehandlers.pyobjecttype.PyObjectParam)):
                    for transfer_ownership in True, False:
                        name = param_name + (transfer_ownership and '_transfer' or '_notransfer')
                        try:
                            param = param_handler(param_type, name, transfer_ownership=transfer_ownership)
                        except TypeError:
                            sys.stderr.write("ERROR -----> param_handler(param_type=%r, "
                                             "name=%r, transfer_ownership=%r, is_const=%r)\n"
                                             % (param_type, name, transfer_ownership, is_const))
                        wrapper_number += 1
                        function_name = 'foo_function_%i' % (wrapper_number,)
                        ## declare a fake prototype
                        sys.stdout.write("void %s(%s %s);\n\n" % (function_name, param_type_with_const, name))
                        module.add_function(function_name, ReturnValue.new('void'), [param])
                else:
                    param = param_handler(param_type, param_name, direction)
                    wrapper_number += 1
                    function_name = 'foo_function_%i' % (wrapper_number,)
                    ## declare a fake prototype
                    sys.stdout.write("void %s(%s);\n\n" % (function_name, param_type_with_const))
                    module.add_function(function_name, ReturnValue.new('void'), [param])

    module.generate(code_out)
Exemplo n.º 8
0
def test():
    code_out = codesink.FileCodeSink(sys.stdout)
    pybindgen.write_preamble(code_out)
    print
    print "#include <string>"
    print "#include <stdint.h>"
    print

    ## Declare a dummy class
    sys.stdout.write(
        """
class Foo
{
    std::string m_datum;
public:
    Foo () : m_datum ("")
        {}
    Foo (std::string datum) : m_datum (datum)
        {}
    std::string get_datum () const { return m_datum; }

    Foo (Foo const & other) : m_datum (other.get_datum ())
        {}
};
"""
    )

    module = Module("foo")

    ## Register type handlers for the class
    Foo = cppclass.CppClass("Foo")
    Foo.module = module
    # Foo.full_name = Foo.name # normally adding the class to a module would take care of this
    Foo.generate_forward_declarations(code_out, module)

    wrapper_number = 0

    ## test return type handlers of reverse wrappers
    for return_type, return_handler in typehandlers.base.return_type_matcher.items():
        if os.name == "nt":
            if stdint_rx.search(return_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        if issubclass(return_handler, (cppclass.CppClassPtrReturnValue, typehandlers.pyobjecttype.PyObjectReturnValue)):
            for caller_owns_return in True, False:
                retval = return_handler(return_type, caller_owns_return=caller_owns_return)
                wrapper = MyReverseWrapper(retval, [])
                wrapper_number += 1
                try:
                    wrapper.generate(code_out, "_test_wrapper_number_%i" % (wrapper_number,), ["static"])
                except NotImplementedError:
                    print >> sys.stderr, (
                        "ReverseWrapper %s(void) (caller_owns_return=%r)"
                        " could not be generated: not implemented" % (retval.ctype, caller_owns_return)
                    )
                print
        else:
            retval = return_handler(return_type)
            try:
                wrapper = MyReverseWrapper(retval, [])
            except NotSupportedError:
                continue
            wrapper_number += 1
            try:
                wrapper.generate(code_out, "_test_wrapper_number_%i" % (wrapper_number,), ["static"])
            except NotImplementedError:
                print >> sys.stderr, (
                    "ReverseWrapper %s(void) could not be generated: not implemented" % (retval.ctype,)
                )
            print

    ## test parameter type handlers of reverse wrappers
    for param_type, param_handler in typehandlers.base.param_type_matcher.items():
        if os.name == "nt":
            if stdint_rx.search(param_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        for direction in param_handler.DIRECTIONS:
            if direction == (Parameter.DIRECTION_IN):
                param_name = "param"
            elif direction == (Parameter.DIRECTION_IN | Parameter.DIRECTION_OUT):
                param_name = "param_inout"
            elif direction == (Parameter.DIRECTION_OUT):
                param_name = "param_out"
            param = param_handler(param_type, param_name, direction)

            if "const" in param.ctype and direction & Parameter.DIRECTION_OUT:
                continue

            wrapper = MyReverseWrapper(ReturnValue.new("void"), [param])
            wrapper_number += 1
            try:
                wrapper.generate(code_out, "_test_wrapper_number_%i" % (wrapper_number,), ["static"])
            except NotImplementedError:
                print >> sys.stderr, ("ReverseWrapper void(%s) could not be generated: not implemented" % (param.ctype))
            print

    ## test generic forward wrappers, and module

    for return_type, return_handler in typehandlers.base.return_type_matcher.items():
        if os.name == "nt":
            if stdint_rx.search(return_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)
        wrapper_number += 1
        function_name = "foo_function_%i" % (wrapper_number,)
        ## declare a fake prototype
        print "%s %s(void);" % (return_type, function_name)
        print

        if issubclass(return_handler, (cppclass.CppClassPtrReturnValue, typehandlers.pyobjecttype.PyObjectReturnValue)):
            retval = return_handler(return_type, caller_owns_return=True)
        else:
            retval = return_handler(return_type)

        module.add_function(function_name, retval, [])

    for param_type, param_handler in typehandlers.base.param_type_matcher.items():
        if os.name == "nt":
            if stdint_rx.search(param_type):
                continue  # win32 does not support the u?int\d+_t types (defined in <stdint.h>)

        for is_const in [True, False]:
            for direction in param_handler.DIRECTIONS:
                if direction == (Parameter.DIRECTION_IN):
                    param_name = "param"
                elif direction == (Parameter.DIRECTION_IN | Parameter.DIRECTION_OUT):
                    param_name = "param_inout"
                elif direction == (Parameter.DIRECTION_OUT):
                    param_name = "param_out"

                if is_const and direction & Parameter.DIRECTION_OUT:
                    continue  # const and output parameter makes no sense

                if is_const:
                    if "&" in param_type:  # const references not allowed
                        continue
                    param_type_with_const = "const %s" % (param_type,)
                else:
                    param_type_with_const = param_type

                if issubclass(param_handler, (cppclass.CppClassPtrParameter, typehandlers.pyobjecttype.PyObjectParam)):
                    for transfer_ownership in True, False:
                        name = param_name + (transfer_ownership and "_transfer" or "_notransfer")
                        try:
                            param = param_handler(param_type, name, transfer_ownership=transfer_ownership)
                        except TypeError:
                            print >> sys.stderr, "ERROR -----> param_handler(param_type=%r, " "name=%r, transfer_ownership=%r, is_const=%r)" % (
                                param_type,
                                name,
                                transfer_ownership,
                                is_const,
                            )
                        wrapper_number += 1
                        function_name = "foo_function_%i" % (wrapper_number,)
                        ## declare a fake prototype
                        print "void %s(%s %s);" % (function_name, param_type_with_const, name)
                        print
                        module.add_function(function_name, ReturnValue.new("void"), [param])
                else:
                    param = param_handler(param_type, param_name, direction)
                    wrapper_number += 1
                    function_name = "foo_function_%i" % (wrapper_number,)
                    ## declare a fake prototype
                    print "void %s(%s);" % (function_name, param_type_with_const)
                    print
                    module.add_function(function_name, ReturnValue.new("void"), [param])

    module.generate(code_out)