From 7397928555258f6fce3f0a3388f8fba9995b8782 Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Wed, 30 Sep 2015 10:31:13 +0200 Subject: [PATCH] fix various formatting and "end of function without return" warnings --- .../fficall/jni/src/alloc.c | 64 +++++------ .../fficall/jni/src/attrib.c | 6 +- .../fficall/jni/src/rffiutils.h | 4 + .../fficall/jni/src/rmathc.c | 100 +++++++++++------- .../fficall/jni/src/rng.c | 3 + .../fficall/jni/src/typecoerce.c | 3 + 6 files changed, 110 insertions(+), 70 deletions(-) diff --git a/com.oracle.truffle.r.native/fficall/jni/src/alloc.c b/com.oracle.truffle.r.native/fficall/jni/src/alloc.c index 6bb69ea2d2..3217c993e8 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/alloc.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/alloc.c @@ -11,6 +11,7 @@ */ #include "rffiutils.h" #include <stdlib.h> +#include <string.h> #define T_MEM_TABLE_INITIAL_SIZE 0 // The table of transient objects that have been allocated dur the current FFI call @@ -19,28 +20,29 @@ static void **tMemTable; static int tMemTableIndex; static int tMemTableLength; void init_alloc(JNIEnv *env) { - tMemTable = malloc(sizeof(void*) * T_MEM_TABLE_INITIAL_SIZE); + tMemTable = malloc(sizeof(void*) * T_MEM_TABLE_INITIAL_SIZE); tMemTableLength = T_MEM_TABLE_INITIAL_SIZE; tMemTableIndex = 0; } +void *R_chk_calloc(size_t nelem, size_t elsize); // Memory that is auto-reclaimed across FFI calls char *R_alloc(size_t n, int size) { - void *p = R_chk_alloc(n, size); - if (tMemTableIndex >= tMemTableLength) { - int newLength = 2 * tMemTableLength; - void *newtMemTable = malloc(sizeof(void*) * newLength); - if (newtMemTable == NULL) { - fatalError("malloc failure"); - } - memcpy(newtMemTable, tMemTable, tMemTableLength * sizeof(void*)); - free(tMemTable); - tMemTable = newtMemTable; - tMemTableLength = newLength; + void *p = R_chk_calloc(n, size); + if (tMemTableIndex >= tMemTableLength) { + int newLength = 2 * tMemTableLength; + void *newtMemTable = malloc(sizeof(void*) * newLength); + if (newtMemTable == NULL) { + fatalError("malloc failure"); } - tMemTable[tMemTableIndex] = p; - return (char*) p; + memcpy(newtMemTable, tMemTable, tMemTableLength * sizeof(void*)); + free(tMemTable); + tMemTable = newtMemTable; + tMemTableLength = newLength; + } + tMemTable[tMemTableIndex] = p; + return (char*) p; } char* S_alloc(long n, int size) { @@ -50,27 +52,27 @@ char* S_alloc(long n, int size) { } void allocExit() { - int i; - for (i = 0; i < tMemTableIndex; i++) { - free(tMemTable[i]); - } + int i; + for (i = 0; i < tMemTableIndex; i++) { + free(tMemTable[i]); + } } void *R_chk_calloc(size_t nelem, size_t elsize) { - void *p; - #ifndef HAVE_WORKING_CALLOC - if(nelem == 0) - return(NULL); - #endif - p = calloc(nelem, elsize); - if(!p) /* problem here is that we don't have a format for size_t. */ - error(_("'Calloc' could not allocate memory (%.0f of %u bytes)"), - (double) nelem, elsize); - return(p); + void *p; +#ifndef HAVE_WORKING_CALLOC + if (nelem == 0) + return (NULL); +#endif + p = calloc(nelem, elsize); + if (!p) /* problem here is that we don't have a format for size_t. */ + error(_("'Calloc' could not allocate memory (%.0f of %u bytes)"), + (double) nelem, elsize); + return (p); } void *R_chk_realloc(void *p, size_t size) { - unimplemented("R_chk_realloc"); + return unimplemented("R_chk_realloc"); } void R_chk_free(void *p) { @@ -85,11 +87,11 @@ void vmaxset(const void * x) { unimplemented("vmaxget"); } - void R_gc(void) { unimplemented("R_gc"); } -int R_gc_running() { +int R_gc_running() { unimplemented("R_gc_running"); + return 0; } diff --git a/com.oracle.truffle.r.native/fficall/jni/src/attrib.c b/com.oracle.truffle.r.native/fficall/jni/src/attrib.c index 503bcbcd52..f72186fcbc 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/attrib.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/attrib.c @@ -39,23 +39,27 @@ int TYPEOF(SEXP x) { SEXP ATTRIB(SEXP x){ unimplemented("ATTRIB"); + return NULL; } int OBJECT(SEXP x){ unimplemented("OBJECT"); + return 0; } int MARK(SEXP x){ unimplemented("MARK"); + return 0; } int NAMED(SEXP x){ - JNIEnv *thisenv = getEnv(); + JNIEnv *thisenv = getEnv(); return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, NAMED_MethodID, x); } int REFCNT(SEXP x){ unimplemented("REFCNT"); + return 0; } void SET_OBJECT(SEXP x, int v){ diff --git a/com.oracle.truffle.r.native/fficall/jni/src/rffiutils.h b/com.oracle.truffle.r.native/fficall/jni/src/rffiutils.h index a8545151b2..cb295e7195 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/rffiutils.h +++ b/com.oracle.truffle.r.native/fficall/jni/src/rffiutils.h @@ -63,6 +63,9 @@ void *findCopiedObject(JNIEnv *env, SEXP x); // add a new object to the internal rep cache void addCopiedObject(JNIEnv *env, SEXP x, SEXPTYPE type, void *jArray, void *data); +void init_rmath(JNIEnv *env); +void init_graphicsengine(JNIEnv *env); +void init_graphicsdevices(JNIEnv *env); void init_variables(JNIEnv *env, jobjectArray initialValues); void init_register(JNIEnv *env); void init_rf_functions(JNIEnv *env); @@ -92,5 +95,6 @@ extern jclass RRuntimeClass; #define TRACE(format, ...) #endif +#define _(Source) (Source) #endif /* RFFIUTILS_H */ diff --git a/com.oracle.truffle.r.native/fficall/jni/src/rmathc.c b/com.oracle.truffle.r.native/fficall/jni/src/rmathc.c index 231d4be286..2e5d72c66d 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/rmathc.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/rmathc.c @@ -26,98 +26,122 @@ void init_rmath(JNIEnv *env) { } -double Rf_choose(double x, double y) { - unimplemented("Rf_choose"); +double Rf_choose(double x, double y) { + unimplemented("Rf_choose"); + return 0; } -double Rf_lchoose(double x, double y) { - unimplemented("Rf_lchoose"); +double Rf_lchoose(double x, double y) { + unimplemented("Rf_lchoose"); + return 0; } -double Rf_dbeta(double x, double y, double z, int w) { - unimplemented("Rf_dbeta"); +double Rf_dbeta(double x, double y, double z, int w) { + unimplemented("Rf_dbeta"); + return 0; } -double Rf_pbeta(double x, double y, double z, int w , int v) { - unimplemented("Rf_pbeta"); +double Rf_pbeta(double x, double y, double z, int w, int v) { + unimplemented("Rf_pbeta"); + return 0; } -double Rf_qbeta(double x, double y, double z, int w , int v) { - unimplemented("Rf_qbeta"); +double Rf_qbeta(double x, double y, double z, int w, int v) { + unimplemented("Rf_qbeta"); + return 0; } -double Rf_rbeta(double x, double y) { - unimplemented("Rf_rbeta"); +double Rf_rbeta(double x, double y) { + unimplemented("Rf_rbeta"); + return 0; } -double Rf_dnorm4(double a, double b, double c , int d) { - unimplemented("Rf_dnorm4"); +double Rf_dnorm4(double a, double b, double c, int d) { + unimplemented("Rf_dnorm4"); + return 0; } -double Rf_pnorm5(double x, double y, double z, int w, int v) { - unimplemented("Rf_pnorm5"); +double Rf_pnorm5(double x, double y, double z, int w, int v) { + unimplemented("Rf_pnorm5"); + return 0; } -int Rf_imax2(int x, int y) { - unimplemented("Rf_imax2"); +int Rf_imax2(int x, int y) { + unimplemented("Rf_imax2"); + return 0; } -int Rf_imin2(int x, int y) { - unimplemented("Rf_imin2"); +int Rf_imin2(int x, int y) { + unimplemented("Rf_imin2"); + return 0; } double Rf_fmax2(double x, double y) { - unimplemented("Rf_fmax2"); + unimplemented("Rf_fmax2"); + return 0; } double Rf_fmin2(double x, double y) { - unimplemented("Rf_fmin2"); + unimplemented("Rf_fmin2"); + return 0; } double Rf_sign(double x) { - unimplemented("Rf_sign"); + unimplemented("Rf_sign"); + return 0; } double Rf_runif(double x, double y) { - unimplemented("Rf_runif"); + unimplemented("Rf_runif"); + return 0; } -double Rf_gammafn(double x) { - unimplemented("Rf_gammafn"); +double Rf_gammafn(double x) { + unimplemented("Rf_gammafn"); + return 0; } -double Rf_lgammafn(double x) { - unimplemented("Rf_lgammafn"); +double Rf_lgammafn(double x) { + unimplemented("Rf_lgammafn"); + return 0; } -double Rf_lgammafn_sign(double x, int*y) { - unimplemented("Rf_lgammafn_sign"); +double Rf_lgammafn_sign(double x, int*y) { + unimplemented("Rf_lgammafn_sign"); + return 0; } double R_pow(double x, double y) { - unimplemented("R_pow"); + unimplemented("R_pow"); + return 0; } -double R_pow_di(double x , int y) { - unimplemented("R_pow_di"); +double R_pow_di(double x, int y) { + unimplemented("R_pow_di"); + return 0; } double Rf_dchisq(double x, double y, int z) { - unimplemented("Rf_dchisq"); + unimplemented("Rf_dchisq"); + return 0; } double Rf_pchisq(double x, double y, int z, int w) { - unimplemented("Rf_pchisq"); + unimplemented("Rf_pchisq"); + return 0; } double Rf_qchisq(double x, double y, int z, int w) { - unimplemented("Rf_qchisq"); + unimplemented("Rf_qchisq"); + return 0; } double Rf_rchisq(double x) { - unimplemented("Rf_rchisq"); + unimplemented("Rf_rchisq"); + return 0; } double Rf_dexp(double x, double y, int z) { - unimplemented("Rf_dexp"); + unimplemented("Rf_dexp"); + return 0; } diff --git a/com.oracle.truffle.r.native/fficall/jni/src/rng.c b/com.oracle.truffle.r.native/fficall/jni/src/rng.c index 41fd1a7b93..71d0de688e 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/rng.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/rng.c @@ -35,12 +35,15 @@ void PutRNGstate() { double unif_rand() { unimplemented("unif_rand"); + return 0; } double norm_rand() { unimplemented("norm_rand"); + return 0; } double exp_rand() { unimplemented("exp_rand"); + return 0; } diff --git a/com.oracle.truffle.r.native/fficall/jni/src/typecoerce.c b/com.oracle.truffle.r.native/fficall/jni/src/typecoerce.c index 2782978855..ce0dd39c56 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/typecoerce.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/typecoerce.c @@ -55,10 +55,12 @@ SEXP Rf_PairToVectorList(SEXP x){ SEXP Rf_VectorToPairList(SEXP x){ unimplemented("Rf_coerceVector"); + return NULL; } SEXP Rf_asCharacterFactor(SEXP x){ unimplemented("Rf_VectorToPairList"); + return NULL; } int Rf_asLogical(SEXP x){ @@ -81,4 +83,5 @@ double Rf_asReal(SEXP x) { Rcomplex Rf_asComplex(SEXP x){ unimplemented("Rf_asLogical"); + Rcomplex c; return c; } -- GitLab