def setup_class(cls):
     cls.space = space
     env = os.environ
     cls.w_test_dct = space.wrap(test_dct)
     cls.w_capi_identity = space.wrap(capi.identify())
     cls.w_advanced = cls.space.appexec([], """():
         import cppyy
         return cppyy.load_reflection_info(%r)""" % (test_dct, ))
Exemple #2
0
    def _run_zjit(self, method_name):
        if capi.identify() == 'CINT':   # CINT does not support fast path
            return

        space = FakeSpace()
        drv = jit.JitDriver(greens=[], reds=["i", "inst", "cppmethod"])
        def f():
            lib = interp_cppyy.load_dictionary(space, "./example01Dict.so")
            cls  = interp_cppyy.scope_byname(space, "example01")
            inst = cls.get_overload("example01").call(None, [FakeInt(0)])
            cppmethod = cls.get_overload(method_name)
            assert isinstance(inst, interp_cppyy.W_CPPInstance)
            i = 10
            while i > 0:
                drv.jit_merge_point(inst=inst, cppmethod=cppmethod, i=i)
                cppmethod.call(inst, [FakeInt(i)])
                i -= 1
            return 7
        f()
        space = FakeSpace()
        result = self.meta_interp(f, [], listops=True, backendopt=True, listcomp=True)
        self.check_jitcell_token_count(1)
Exemple #3
0
import py, os, sys
from rpython.jit.metainterp.test.support import LLJitMixin
from rpython.rlib.objectmodel import specialize, instantiate
from rpython.rlib import rarithmetic, jit
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root

from pypy.module.cppyy import interp_cppyy, capi
# These tests are for the backend that support the fast path only.
if capi.identify() == 'CINT':
    py.test.skip("CINT does not support fast path")
elif capi.identify() == 'loadable_capi':
    py.test.skip("can not currently use FakeSpace with _cffi_backend")

# load cpyext early, or its global vars are counted as leaks in the test
# (note that the module is not otherwise used in the test itself)
import pypy.module.cpyext

# change capi's direct_ptradd and exchange_address to being jit-opaque
@jit.dont_look_inside
def _opaque_direct_ptradd(ptr, offset):
    address = rffi.cast(rffi.CCHARP, ptr)
    return rffi.cast(capi.C_OBJECT, lltype.direct_ptradd(address, offset))
capi.direct_ptradd = _opaque_direct_ptradd

@jit.dont_look_inside
def _opaque_exchange_address(ptr, cif_descr, index):
    offset = rffi.cast(rffi.LONG, cif_descr.exchange_args[index])
    return rffi.ptradd(ptr, offset)
capi.exchange_address = _opaque_exchange_address
Exemple #4
0
import py, os, sys
from rpython.jit.metainterp.test.support import LLJitMixin
from rpython.rlib.objectmodel import specialize, instantiate
from rpython.rlib import rarithmetic, jit
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root

from pypy.module.cppyy import interp_cppyy, capi
# These tests are for the backend that support the fast path only.
if capi.identify() == 'CINT':
    py.test.skip("CINT does not support fast path")
elif capi.identify() == 'loadable_capi':
    py.test.skip("can not currently use FakeSpace with _cffi_backend")

# load cpyext early, or its global vars are counted as leaks in the test
# (note that the module is not otherwise used in the test itself)
import pypy.module.cpyext

# change capi's direct_ptradd and exchange_address to being jit-opaque
@jit.dont_look_inside
def _opaque_direct_ptradd(ptr, offset):
    address = rffi.cast(rffi.CCHARP, ptr)
    return rffi.cast(capi.C_OBJECT, lltype.direct_ptradd(address, offset))
capi.direct_ptradd = _opaque_direct_ptradd

@jit.dont_look_inside
def _opaque_exchange_address(ptr, cif_descr, index):
    offset = rffi.cast(rffi.LONG, cif_descr.exchange_args[index])
    return rffi.ptradd(ptr, offset)
capi.exchange_address = _opaque_exchange_address
Exemple #5
0
import py, os, sys

# These tests are for the CINT backend only (they exercise ROOT features
# and classes that are not loaded/available with the Reflex backend). At
# some point, these tests are likely covered by the CLang/LLVM backend.
from pypy.module.cppyy import capi
if capi.identify() != 'CINT':
    py.test.skip("backend-specific: CINT-only tests")

# load _cffi_backend early, or its global vars are counted as leaks in the
# test (note that the module is not otherwise used in the test itself)
from pypy.module._cffi_backend import newtype

currpath = py.path.local(__file__).dirpath()
iotypes_dct = str(currpath.join("iotypesDict.so"))


def setup_module(mod):
    if sys.platform == 'win32':
        py.test.skip("win32 not supported so far")
    err = os.system("cd '%s' && make CINT=t iotypesDict.so" % currpath)
    if err:
        raise OSError("'make' failed (see stderr)")


class AppTestCINT:
    spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])

    def test01_globals(self):
        """Test the availability of ROOT globals"""
Exemple #6
0
 def setup_class(cls):
     cls.w_test_dct = cls.space.newtext(test_dct)
     cls.w_identity = cls.space.newtext(capi.identify())
     cls.w_fragile = cls.space.appexec([], """():
         import cppyy
         return cppyy.load_reflection_info(%r)""" % (test_dct, ))
        ("const char*", "char*"),
        ("std::basic_string<char>", "string"),
        ("const std::basic_string<char>&", "const string&"),
        ("std::basic_string<char>&", "string&"),
        ("PyObject*", "_object*"),
    )

    for c_type, alias in aliases:
        _converters[alias] = _converters[c_type]


_add_aliased_converters()

# ROOT-specific converters (TODO: this is a general use case and should grow
# an API; putting it here is done only to circumvent circular imports)
if capi.identify() == "CINT":

    class TStringConverter(InstanceConverter):
        def __init__(self, space, extra):
            from pypy.module.cppyy import interp_cppyy
            cppclass = interp_cppyy.scope_byname(space, "TString")
            InstanceConverter.__init__(self, space, cppclass)

        def _unwrap_object(self, space, w_obj):
            from pypy.module.cppyy import interp_cppyy
            if isinstance(w_obj, interp_cppyy.W_CPPInstance):
                arg = InstanceConverter._unwrap_object(self, space, w_obj)
                return capi.backend.c_TString2TString(space, arg)
            else:
                return capi.backend.c_charp2TString(space, space.text_w(w_obj))
Exemple #8
0
        ("const char*",                     "char*"),

        ("std::basic_string<char>",         "string"),
        ("const std::basic_string<char>&",  "const string&"),
        ("std::basic_string<char>&",        "string&"),

        ("PyObject*",                       "_object*"),
    )
 
    for c_type, alias in aliases:
        _converters[alias] = _converters[c_type]
_add_aliased_converters()

# ROOT-specific converters (TODO: this is a general use case and should grow
# an API; putting it here is done only to circumvent circular imports)
if capi.identify() == "CINT":

    class TStringConverter(InstanceConverter):
        def __init__(self, space, extra):
            from pypy.module.cppyy import interp_cppyy
            cppclass = interp_cppyy.scope_byname(space, "TString")
            InstanceConverter.__init__(self, space, cppclass)

        def _unwrap_object(self, space, w_obj):
            from pypy.module.cppyy import interp_cppyy
            if isinstance(w_obj, interp_cppyy.W_CPPInstance):
                arg = InstanceConverter._unwrap_object(self, space, w_obj)
                return capi.backend.c_TString2TString(space, arg)
            else:
                return capi.backend.c_charp2TString(space, space.str_w(w_obj))
Exemple #9
0
 def setup_class(cls):
     cls.w_test_dct  = cls.space.wrap(test_dct)
     cls.w_identity = cls.space.wrap(capi.identify())
     cls.w_fragile = cls.space.appexec([], """():
         import cppyy
         return cppyy.load_reflection_info(%r)""" % (test_dct, ))
Exemple #10
0
import py, os, sys

# These tests are for the CINT backend only (they exercise ROOT features
# and classes that are not loaded/available with the Reflex backend). At
# some point, these tests are likely covered by the CLang/LLVM backend.
from pypy.module.cppyy import capi
if capi.identify() != 'CINT':
    py.test.skip("backend-specific: CINT-only tests")

# load _cffi_backend early, or its global vars are counted as leaks in the
# test (note that the module is not otherwise used in the test itself)
from pypy.module._cffi_backend import newtype

currpath = py.path.local(__file__).dirpath()
iotypes_dct = str(currpath.join("iotypesDict.so"))

def setup_module(mod):
    if sys.platform == 'win32':
        py.test.skip("win32 not supported so far")
    err = os.system("cd '%s' && make CINT=t iotypesDict.so" % currpath)
    if err:
        raise OSError("'make' failed (see stderr)")

class AppTestCINT:
    spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])

    def test01_globals(self):
        """Test the availability of ROOT globals"""

        import cppyy
Exemple #11
0
 def setup_class(cls):
     cls.w_test_dct = cls.space.wrap(test_dct)
     cls.w_capi_identity = cls.space.wrap(capi.identify())
     cls.w_advanced = cls.space.appexec([], """():
         import cppyy
         return cppyy.load_reflection_info(%r)""" % (test_dct, ))