From 46903daf2299f163abddd8731627ba7a809a1d1c Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Wed, 7 Mar 2018 10:32:56 +0100 Subject: [PATCH] Work around FastR's inability to change type in SET_TYPE in place Use C preprocessor to rewrite calls to SET_TYPE(x,y) to x=SET_TYPE(x,y) --- .../src/truffle_common/Rinternals_truffle_common.h | 3 ++- .../fficall/src/truffle_llvm/Rinternals.c | 1 + .../fficall/src/truffle_nfi/Rinternals.c | 1 + com.oracle.truffle.r.native/version.source | 2 +- mx.fastr/mx_fastr_edinclude.py | 13 ++++++++++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h b/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h index 628f5974c6..5edea4d43b 100644 --- a/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h +++ b/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h @@ -68,6 +68,7 @@ #define UNIMPLEMENTED unimplemented(__FUNCTION__) +#define NO_FASTR_REDEFINE #include <rffiutils.h> // these two functions are here just to handle casting void* to void function pointers... @@ -1252,7 +1253,7 @@ void DUPLICATE_ATTRIB(SEXP to, SEXP from) { R_len_t R_BadLongVector(SEXP x, const char *y, int z) { TRACE0(); unimplemented("R_BadLongVector"); - return (R_len_t) 0; + // "no return" function } int IS_S4_OBJECT(SEXP x) { diff --git a/com.oracle.truffle.r.native/fficall/src/truffle_llvm/Rinternals.c b/com.oracle.truffle.r.native/fficall/src/truffle_llvm/Rinternals.c index 4b3d916edd..f6dcf567ef 100644 --- a/com.oracle.truffle.r.native/fficall/src/truffle_llvm/Rinternals.c +++ b/com.oracle.truffle.r.native/fficall/src/truffle_llvm/Rinternals.c @@ -21,6 +21,7 @@ * questions. */ +#define NO_FASTR_REDEFINE #include <Rinterface.h> #include <rffiutils.h> #include <Rinternals_common.h> diff --git a/com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rinternals.c b/com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rinternals.c index 39b2d0b9ab..cf8ea6aa96 100644 --- a/com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rinternals.c +++ b/com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rinternals.c @@ -20,6 +20,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +#define NO_FASTR_REDEFINE #include <Rinterface.h> #include <rffiutils.h> #include <Rinternals_common.h> diff --git a/com.oracle.truffle.r.native/version.source b/com.oracle.truffle.r.native/version.source index c3f407c095..e1617e842a 100644 --- a/com.oracle.truffle.r.native/version.source +++ b/com.oracle.truffle.r.native/version.source @@ -1 +1 @@ -55 +57 diff --git a/mx.fastr/mx_fastr_edinclude.py b/mx.fastr/mx_fastr_edinclude.py index 0032c54979..40d357e92e 100644 --- a/mx.fastr/mx_fastr_edinclude.py +++ b/mx.fastr/mx_fastr_edinclude.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -74,6 +74,14 @@ use_internals_end = '''#endif ''' +set_typeof_rewrite = '''#ifdef FASTR +SEXP SET_TYPEOF_FASTR(SEXP x, int v); +#ifndef NO_FASTR_REDEFINE +#define SET_TYPEOF(X,Y) X=SET_TYPEOF_FASTR(X,Y) +#endif +#endif +''' + def ed_r_internals(gnu_dir): r_internals_h = join(gnu_dir, 'Rinternals.h') with open(r_internals_h) as f: @@ -105,6 +113,9 @@ def ed_r_internals(gnu_dir): rewrite_var(f, var, line) else: f.write(line) + elif 'SET_TYPEOF' in line and '(SEXP' in line: + f.write(line) + f.write(set_typeof_rewrite) else: f.write(line) -- GitLab