Example #1
0
def _post_import_startup():
    # run only once (function is explicitly called in testing)
    global cppyyIsInitialized
    if cppyyIsInitialized:
        return

    # _cppyy should not be loaded at the module level, as that will trigger a
    # call to space.getbuiltinmodule(), which will cause _cppyy to be loaded
    # at pypy-c startup, rather than on the "import _cppyy" statement
    import _cppyy

    # root of all proxy classes: CPPClass in pythonify exists to combine the
    # CPPClassMeta metaclass (for Python-side class behavior) with the
    # interp-level CPPInstance (for bound object behavior)
    global CPPClass

    class CPPClass(with_metaclass(CPPClassMeta, _cppyy.CPPInstance)):
        pass

    # class generator callback
    _cppyy._set_class_generator(clgen_callback)

    # function generator callback
    _cppyy._set_function_generator(fngen_callback)

    # user interface objects
    global gbl
    gbl = make_cppnamespace(None, 'gbl', _cppyy._scope_byname(''))
    gbl.__module__ = 'cppyy'
    gbl.__doc__ = 'Global C++ namespace.'

    # pre-create std to allow direct importing
    gbl.std = make_cppnamespace(gbl, 'std', _cppyy._scope_byname('std'))

    # add move cast
    gbl.std.move = _cppyy.move

    # install a type for enums to refer to
    setattr(gbl, 'internal_enum_type_t', int)
    setattr(gbl, 'unsigned int', int)  # if resolved

    # install for user access
    _cppyy.gbl = gbl

    # install nullptr as a unique reference
    _cppyy.nullptr = _cppyy._get_nullptr()

    # done
    cppyyIsInitialized = True
Example #2
0
def _init_pythonify():
    # _cppyy should not be loaded at the module level, as that will trigger a
    # call to space.getbuiltinmodule(), which will cause _cppyy to be loaded
    # at pypy-c startup, rather than on the "import _cppyy" statement
    import _cppyy

    # root of all proxy classes: CPPInstance in pythonify exists to combine the
    # CPPClass meta class with the interp-level CPPInstanceBase
    global CPPInstance

    class CPPInstance(_cppyy.CPPInstanceBase):
        __metaclass__ = CPPClass
        pass

    # class generator callback
    _cppyy._set_class_generator(clgen_callback)

    # function generator callback
    _cppyy._set_function_generator(fngen_callback)

    # user interface objects (note the two-step of not calling scope_byname here:
    # creation of global functions may cause the creation of classes in the global
    # namespace, so gbl must exist at that point to cache them)
    global gbl
    gbl = make_cppnamespace(None, "::", None, False)  # global C++ namespace
    gbl.__doc__ = "Global C++ namespace."

    # pre-create std to allow direct importing
    gbl.std = make_cppnamespace(None, "std", None, False)

    # install a type for enums to refer to
    # TODO: this is correct for C++98, not for C++11 and in general there will
    # be the same issue for all typedef'd builtin types
    setattr(gbl, 'internal_enum_type_t', int)

    # install nullptr as a unique reference
    setattr(gbl, 'nullptr', _cppyy._get_nullptr())

    # install for user access
    _cppyy.gbl = gbl

    # install as modules to allow importing from
    sys.modules['_cppyy.gbl'] = gbl
    sys.modules['_cppyy.gbl.std'] = gbl.std
Example #3
0
def _init_pythonify():
    # _cppyy should not be loaded at the module level, as that will trigger a
    # call to space.getbuiltinmodule(), which will cause _cppyy to be loaded
    # at pypy-c startup, rather than on the "import _cppyy" statement
    import _cppyy

    # root of all proxy classes: CPPClass in pythonify exists to combine the
    # CPPMetaScope metaclass with the interp-level CPPClassBase
    global CPPClass

    class CPPClass(_cppyy.CPPClassBase):
        __metaclass__ = CPPMetaScope
        pass

    # class generator callback
    _cppyy._set_class_generator(clgen_callback)

    # function generator callback
    _cppyy._set_function_generator(fngen_callback)

    # user interface objects
    global gbl
    gbl = make_cppnamespace(None, 'gbl', _cppyy._scope_byname(''))
    gbl.__module__ = 'cppyy'
    gbl.__doc__ = 'Global C++ namespace.'

    # pre-create std to allow direct importing
    gbl.std = make_cppnamespace(gbl, 'std', _cppyy._scope_byname('std'))

    # add move cast
    gbl.std.move = _cppyy.move

    # install a type for enums to refer to
    # TODO: this is correct for C++98, not for C++11 and in general there will
    # be the same issue for all typedef'd builtin types
    setattr(gbl, 'internal_enum_type_t', int)

    # install for user access
    _cppyy.gbl = gbl

    # install nullptr as a unique reference
    _cppyy.nullptr = _cppyy._get_nullptr()
Example #4
0
def _post_import_startup():
    # _cppyy should not be loaded at the module level, as that will trigger a
    # call to space.getbuiltinmodule(), which will cause _cppyy to be loaded
    # at pypy-c startup, rather than on the "import _cppyy" statement
    import _cppyy

    # root of all proxy classes: CPPInstance in pythonify exists to combine
    # the CPPScope metaclass with the interp-level CPPInstanceBase
    global CPPInstance

    class CPPInstance(_cppyy.CPPInstanceBase):
        __metaclass__ = CPPScope
        pass

    # class generator callback
    _cppyy._set_class_generator(clgen_callback)

    # function generator callback
    _cppyy._set_function_generator(fngen_callback)

    # user interface objects
    global gbl
    gbl = make_cppnamespace(None, 'gbl', _cppyy._scope_byname(''))
    gbl.__module__ = 'cppyy'
    gbl.__doc__ = 'Global C++ namespace.'

    # pre-create std to allow direct importing
    gbl.std = make_cppnamespace(gbl, 'std', _cppyy._scope_byname('std'))

    # add move cast
    gbl.std.move = _cppyy.move

    # install a type for enums to refer to
    setattr(gbl, 'internal_enum_type_t', int)
    setattr(gbl, 'unsigned int', int)  # if resolved

    # install for user access
    _cppyy.gbl = gbl

    # install nullptr as a unique reference
    _cppyy.nullptr = _cppyy._get_nullptr()