Commit f12f8f21 authored by John Zhang's avatar John Zhang

create mu instance and tag current thread using ctypes for test_cmpop; preload_mu() function

parent 04711fe7
......@@ -10,7 +10,7 @@ import ctypes
from rpython.translator.interactive import Translation
from rpython.config.translationoption import set_opt_level
from util import libmu_path, libext
from util import libmu_path, libext, preload_libmu
CPYTHON = os.environ.get('CPYTHON', 'python')
PYPY = os.environ.get('PYPY', 'pypy')
......@@ -153,8 +153,7 @@ uint64_t fib(uint64_t n) {
exec (py_code_str, mod)
rpy_fnc = mod['fib']
# load libmu before rffi so to load it with RTLD_GLOBAL
libmu = ctypes.CDLL(libmu_path.strpath, ctypes.RTLD_GLOBAL)
preload_libmu()
t = Translation(rpy_fnc, [int],
backend='mu', muimpl='fast', mucodegen='api', mutestjit=True)
......
from util import fncptr_from_c_script
from util import fncptr_from_c_script, preload_libmu
import ctypes
def test_eq_int():
fn, _ = fncptr_from_c_script("test_eq_int.c", "test_fnc")
assert fn() == 0
def mu_instance_via_ctyeps():
libmu = preload_libmu()
class MuVM(ctypes.Structure):
pass
MuVM._fields_ = [
('header', ctypes.c_voidp),
('new_context', ctypes.c_voidp), # function pointers should have the same size as c_voidp
('id_of', ctypes.c_voidp),
('name_of', ctypes.c_voidp),
('set_trap_handler', ctypes.c_voidp),
('compile_to_sharedlib', ctypes.c_voidp),
('current_thread_as_mu_thread', ctypes.CFUNCTYPE(None, ctypes.POINTER(MuVM), ctypes.c_voidp)),
]
libmu.mu_fastimpl_new.restype = ctypes.POINTER(MuVM)
mu = libmu.mu_fastimpl_new()
mu.contents.current_thread_as_mu_thread(mu, None)
return mu
def test_eq_ref():
mu = mu_instance_via_ctyeps()
fn, _ = fncptr_from_c_script("test_eq_ref.c", "test_fnc")
assert fn() == 0
......@@ -14,6 +33,7 @@ def test_ne_int():
assert fn() == 1
def test_ne_ref():
mu = mu_instance_via_ctyeps()
fn, _ = fncptr_from_c_script("test_ne_ref.c", "test_fnc")
assert fn() == 1
......
......@@ -84,6 +84,9 @@ def fncptr_from_py_script(py_fnc, name, argtypes=[], restype=ctypes.c_longlong):
lib = ctypes.CDLL('emit/%(libname)s' % locals())
return fncptr_from_lib(lib, name, argtypes, restype), (mu, ctx, bldr)
def preload_libmu():
# load libmu before rffi so to load it with RTLD_GLOBAL
return ctypes.CDLL(libmu_path.strpath, ctypes.RTLD_GLOBAL)
def fncptr_from_rpy_func(rpy_fnc, llargtypes, llrestype, **kwargs):
# NOTE: requires mu-client-pypy
......@@ -91,8 +94,7 @@ def fncptr_from_rpy_func(rpy_fnc, llargtypes, llrestype, **kwargs):
from rpython.translator.interactive import Translation
from rpython.config.translationoption import set_opt_level
# load libmu before rffi so to load it with RTLD_GLOBAL
libmu = ctypes.CDLL(libmu_path.strpath, ctypes.RTLD_GLOBAL)
preload_libmu()
kwargs.setdefault('backend', 'mu')
kwargs.setdefault('muimpl', 'fast')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment