To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit ffb49130 authored by John Zhang's avatar John Zhang
Browse files

wip: refactoring RPython language module to use rffi to call callback function

parent 1c22ca23
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
def get_callback(libcb_path):
from rpython.rtyper.lltypesystem import rffi
import py
import sys
libcb = py.path.local(libcb_path)
libext = '.dylib' if sys.platform == 'darwin' else '.so'
libname = libcb.basename[3:libcb.basename.index(libext)]
eci = rffi.ExternalCompilationInfo(libraries=[libname], library_dirs=[libcb.dirname])
def external(name, args, result, compilation_info=eci, **kwds):
return rffi.llexternal(name, args, result,
compilation_info=compilation_info,
_nowrapper=True, **kwds)
c_cb_init = external("cb_init", [rffi.CCHARP], rffi.VOIDP)
c_cb_begin = external("cb_begin", [rffi.VOIDP], rffi.lltype.Void)
c_cb_end = external("cb_end", [rffi.VOIDP], rffi.lltype.Void)
c_cb_report = external("cb_report", [rffi.VOIDP], rffi.lltype.Void)
class Callback:
def __init__(self, param_s):
with rffi.scoped_str2charp(param_s) as buf:
self.cb = c_cb_init(buf)
def begin(self):
c_cb_begin(self.cb)
def end(self):
c_cb_end(self.cb)
def report(self):
c_cb_report(self.cb)
return Callback
\ No newline at end of file
......@@ -148,8 +148,8 @@ class RPython(Language):
cmd.append(task.srcfile)
# target configuration arguments
# first argument: callback name
cmd.append(task.callback['name'])
# first argument: callback lib
cmd.append(task.callback['dylib'])
# the rest, custom defined arguments
cmd.extend(task.compiler['args'])
......
......@@ -68,11 +68,13 @@ class TaskSet:
callback['param'] = expandenv(callback['param'], self.env)
# compiled callback shared library
self.callback['dylib'] = self.output_dir / ('libcb_%(name)s.dylib' % self.callback)
if sys.platform == 'darwin':
self.env['DYLD_LIBRARY_PATH'] = str(self.output_dir)
libext = '.dylib'
else:
self.env['LD_LIBRARY_PATH'] = str(self.output_dir)
libext = '.so'
self.callback['dylib'] = self.output_dir / ('libcb_%(name)s' % self.callback + libext)
@staticmethod
def from_config_dict(name, conf_d, conf_dir=None):
......
......@@ -45,3 +45,8 @@ def target(driver, args):
return int(s != fib(n) * scale_factor)
return main, None
if __name__ == "__main__":
import sys
main, _ = target(None, sys.argv[1:])
main([sys.argv[0]] + sys.argv[2:])
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