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 # top-level classes global CppyyClass class CppyyClass(cppyy.CPPInstance): __metaclass__ = CppyyClassMeta def __init__(self, *args, **kwds): pass # ignored, for the C++ backend, ctor == __new__ + __init__ # class generator callback cppyy._set_class_generator(clgen_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." # mostly for the benefit of the CINT backend, which treats std as special gbl.std = make_cppnamespace(None, "std", None, False) # 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
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
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." # mostly for the benefit of the CINT backend, which treats std as special 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, 'unsigned int', 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
arg = arg.__name__ return arg def __call__(self, *args): fullname = ''.join( [self._name, '<', ','.join(map(self._arg_to_str, args))]) if fullname[-1] == '>': fullname += ' >' else: fullname += '>' return getattr(self._scope, fullname) def clgen_callback(name): return get_pycppclass(name) cppyy._set_class_generator(clgen_callback) def make_static_function(func_name, cppol): def function(*args): return cppol.call(None, *args) function.__name__ = func_name function.__doc__ = cppol.signature() return staticmethod(function) def make_method(meth_name, cppol): def method(self, *args): return cppol.call(self, *args) method.__name__ = meth_name method.__doc__ = cppol.signature() return method