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

Commit 3d4d75ad authored by John Zhang's avatar John Zhang
Browse files

wip: refactored C language module to use the compiled callback shared library

parent c73afe29
......@@ -18,7 +18,7 @@ This header file defines callback interface for C.
*/
void* cb_init(const char* param_s); // use void* to hide implementation details
void cb_begin(void* cb); // data is implementation defined
void cb_end(void* cb);
void cb_report(void* cb);
extern void* cb_init(const char* param_s); // use void* to hide implementation details
extern void cb_begin(void* cb); // data is implementation defined
extern void cb_end(void* cb);
extern void cb_report(void* cb);
......@@ -34,7 +34,7 @@ class C(Language):
@classmethod
def compile(cls, task):
callback_dir = CALLBACKS_DIR / cls.name
callback_dir = CALLBACKS_DIR
cc = task.compiler
cmd = []
......@@ -42,20 +42,23 @@ class C(Language):
# flags
flags = []
include_flags = ['-I%(callback_dir)s' % locals()]
cc_flags = list(map(lambda a: expandenv(a, task.env), cc.get('flags', [])))
flags.extend(cc_flags)
include_flags = ['-I%(callback_dir)s' % locals()]
flags.extend(include_flags)
libcb = task.callback['dylib']
liblink_flags = ['-L%s' % libcb.parent, '-lcb_%(name)s' % task.callback]
flags.extend(liblink_flags)
target = cls.get_default_target(task)
flags.extend(['-o', str(target)])
cmd.extend(flags)
cmd.append(task.srcfile)
# callback selected at compile time, initialised at runtime
callback_file = callback_dir / ('cb_%(name)s.c' % task.callback)
cmd.append(callback_file)
cls.run_in_subproc(cmd, task.env)
assert target.exists()
......
......@@ -31,7 +31,7 @@ int fib(int n) {
int main(int argc, char** argv) {
int n, scale_factor;
char* resfile;
struct Callback* cb;
void* cb;
int sum = 0;
cb = cb_init(argv[1]);
......@@ -39,10 +39,10 @@ int main(int argc, char** argv) {
scale_factor = atoi(argv[2]);
n = atoi(argv[3]);
cb_begin(cb, NULL);
cb_begin(cb);
for(int i = n + 1; i < (scale_factor + n + 1); i ++)
sum += fib(n % i);
cb_end(cb, NULL);
cb_end(cb);
printf("sum = %d\n", sum);
cb_report(cb);
return 0;
......
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