diff --git a/CompileSteps/Makefile b/CompileSteps/Makefile new file mode 100644 index 0000000..c23d4dc --- /dev/null +++ b/CompileSteps/Makefile @@ -0,0 +1,10 @@ + +%.E: %.c + $(CC) -E -o $@ $(CPPFLAGS) $< + +%.o: %.c + $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $< + + +sm: sm.o simpleMath.o + $(CC) -o $@ simpleMath.o sm.o -lm diff --git a/CompileSteps/simpleMath.E b/CompileSteps/simpleMath.E new file mode 100644 index 0000000..881f32e --- /dev/null +++ b/CompileSteps/simpleMath.E @@ -0,0 +1,449 @@ +# 1 "simpleMath.c" +# 1 "" 1 +# 1 "" 3 +# 361 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "simpleMath.c" 2 +# 1 "/usr/include/math.h" 1 3 4 +# 30 "/usr/include/math.h" 3 4 +# 1 "/usr/include/sys/cdefs.h" 1 3 4 +# 587 "/usr/include/sys/cdefs.h" 3 4 +# 1 "/usr/include/sys/_symbol_aliasing.h" 1 3 4 +# 588 "/usr/include/sys/cdefs.h" 2 3 4 +# 653 "/usr/include/sys/cdefs.h" 3 4 +# 1 "/usr/include/sys/_posix_availability.h" 1 3 4 +# 654 "/usr/include/sys/cdefs.h" 2 3 4 +# 31 "/usr/include/math.h" 2 3 4 +# 1 "/usr/include/Availability.h" 1 3 4 +# 206 "/usr/include/Availability.h" 3 4 +# 1 "/usr/include/AvailabilityInternal.h" 1 3 4 +# 207 "/usr/include/Availability.h" 2 3 4 +# 32 "/usr/include/math.h" 2 3 4 +# 44 "/usr/include/math.h" 3 4 + typedef float float_t; + typedef double double_t; +# 111 "/usr/include/math.h" 3 4 +extern int __math_errhandling(void); +# 144 "/usr/include/math.h" 3 4 +extern int __fpclassifyf(float); +extern int __fpclassifyd(double); +extern int __fpclassifyl(long double); +# 188 "/usr/include/math.h" 3 4 +inline __attribute__ ((__always_inline__)) int __inline_isfinitef(float); +inline __attribute__ ((__always_inline__)) int __inline_isfinited(double); +inline __attribute__ ((__always_inline__)) int __inline_isfinitel(long double); +inline __attribute__ ((__always_inline__)) int __inline_isinff(float); +inline __attribute__ ((__always_inline__)) int __inline_isinfd(double); +inline __attribute__ ((__always_inline__)) int __inline_isinfl(long double); +inline __attribute__ ((__always_inline__)) int __inline_isnanf(float); +inline __attribute__ ((__always_inline__)) int __inline_isnand(double); +inline __attribute__ ((__always_inline__)) int __inline_isnanl(long double); +inline __attribute__ ((__always_inline__)) int __inline_isnormalf(float); +inline __attribute__ ((__always_inline__)) int __inline_isnormald(double); +inline __attribute__ ((__always_inline__)) int __inline_isnormall(long double); +inline __attribute__ ((__always_inline__)) int __inline_signbitf(float); +inline __attribute__ ((__always_inline__)) int __inline_signbitd(double); +inline __attribute__ ((__always_inline__)) int __inline_signbitl(long double); + +inline __attribute__ ((__always_inline__)) int __inline_isfinitef(float __x) { + return __x == __x && __builtin_fabsf(__x) != __builtin_inff(); +} +inline __attribute__ ((__always_inline__)) int __inline_isfinited(double __x) { + return __x == __x && __builtin_fabs(__x) != __builtin_inf(); +} +inline __attribute__ ((__always_inline__)) int __inline_isfinitel(long double __x) { + return __x == __x && __builtin_fabsl(__x) != __builtin_infl(); +} +inline __attribute__ ((__always_inline__)) int __inline_isinff(float __x) { + return __builtin_fabsf(__x) == __builtin_inff(); +} +inline __attribute__ ((__always_inline__)) int __inline_isinfd(double __x) { + return __builtin_fabs(__x) == __builtin_inf(); +} +inline __attribute__ ((__always_inline__)) int __inline_isinfl(long double __x) { + return __builtin_fabsl(__x) == __builtin_infl(); +} +inline __attribute__ ((__always_inline__)) int __inline_isnanf(float __x) { + return __x != __x; +} +inline __attribute__ ((__always_inline__)) int __inline_isnand(double __x) { + return __x != __x; +} +inline __attribute__ ((__always_inline__)) int __inline_isnanl(long double __x) { + return __x != __x; +} +inline __attribute__ ((__always_inline__)) int __inline_signbitf(float __x) { + union { float __f; unsigned int __u; } __u; + __u.__f = __x; + return (int)(__u.__u >> 31); +} +inline __attribute__ ((__always_inline__)) int __inline_signbitd(double __x) { + union { double __f; unsigned long long __u; } __u; + __u.__f = __x; + return (int)(__u.__u >> 63); +} + +inline __attribute__ ((__always_inline__)) int __inline_signbitl(long double __x) { + union { + long double __ld; + struct{ unsigned long long __m; unsigned short __sexp; } __p; + } __u; + __u.__ld = __x; + return (int)(__u.__p.__sexp >> 15); +} + + + + + + + +inline __attribute__ ((__always_inline__)) int __inline_isnormalf(float __x) { + return __inline_isfinitef(__x) && __builtin_fabsf(__x) >= 1.17549435e-38F; +} +inline __attribute__ ((__always_inline__)) int __inline_isnormald(double __x) { + return __inline_isfinited(__x) && __builtin_fabs(__x) >= 2.2250738585072014e-308; +} +inline __attribute__ ((__always_inline__)) int __inline_isnormall(long double __x) { + return __inline_isfinitel(__x) && __builtin_fabsl(__x) >= 3.36210314311209350626e-4932L; +} +# 322 "/usr/include/math.h" 3 4 +extern float acosf(float); +extern double acos(double); +extern long double acosl(long double); + +extern float asinf(float); +extern double asin(double); +extern long double asinl(long double); + +extern float atanf(float); +extern double atan(double); +extern long double atanl(long double); + +extern float atan2f(float, float); +extern double atan2(double, double); +extern long double atan2l(long double, long double); + +extern float cosf(float); +extern double cos(double); +extern long double cosl(long double); + +extern float sinf(float); +extern double sin(double); +extern long double sinl(long double); + +extern float tanf(float); +extern double tan(double); +extern long double tanl(long double); + +extern float acoshf(float); +extern double acosh(double); +extern long double acoshl(long double); + +extern float asinhf(float); +extern double asinh(double); +extern long double asinhl(long double); + +extern float atanhf(float); +extern double atanh(double); +extern long double atanhl(long double); + +extern float coshf(float); +extern double cosh(double); +extern long double coshl(long double); + +extern float sinhf(float); +extern double sinh(double); +extern long double sinhl(long double); + +extern float tanhf(float); +extern double tanh(double); +extern long double tanhl(long double); + +extern float expf(float); +extern double exp(double); +extern long double expl(long double); + +extern float exp2f(float); +extern double exp2(double); +extern long double exp2l(long double); + +extern float expm1f(float); +extern double expm1(double); +extern long double expm1l(long double); + +extern float logf(float); +extern double log(double); +extern long double logl(long double); + +extern float log10f(float); +extern double log10(double); +extern long double log10l(long double); + +extern float log2f(float); +extern double log2(double); +extern long double log2l(long double); + +extern float log1pf(float); +extern double log1p(double); +extern long double log1pl(long double); + +extern float logbf(float); +extern double logb(double); +extern long double logbl(long double); + +extern float modff(float, float *); +extern double modf(double, double *); +extern long double modfl(long double, long double *); + +extern float ldexpf(float, int); +extern double ldexp(double, int); +extern long double ldexpl(long double, int); + +extern float frexpf(float, int *); +extern double frexp(double, int *); +extern long double frexpl(long double, int *); + +extern int ilogbf(float); +extern int ilogb(double); +extern int ilogbl(long double); + +extern float scalbnf(float, int); +extern double scalbn(double, int); +extern long double scalbnl(long double, int); + +extern float scalblnf(float, long int); +extern double scalbln(double, long int); +extern long double scalblnl(long double, long int); + +extern float fabsf(float); +extern double fabs(double); +extern long double fabsl(long double); + +extern float cbrtf(float); +extern double cbrt(double); +extern long double cbrtl(long double); + +extern float hypotf(float, float); +extern double hypot(double, double); +extern long double hypotl(long double, long double); + +extern float powf(float, float); +extern double pow(double, double); +extern long double powl(long double, long double); + +extern float sqrtf(float); +extern double sqrt(double); +extern long double sqrtl(long double); + +extern float erff(float); +extern double erf(double); +extern long double erfl(long double); + +extern float erfcf(float); +extern double erfc(double); +extern long double erfcl(long double); + + + + +extern float lgammaf(float); +extern double lgamma(double); +extern long double lgammal(long double); + +extern float tgammaf(float); +extern double tgamma(double); +extern long double tgammal(long double); + +extern float ceilf(float); +extern double ceil(double); +extern long double ceill(long double); + +extern float floorf(float); +extern double floor(double); +extern long double floorl(long double); + +extern float nearbyintf(float); +extern double nearbyint(double); +extern long double nearbyintl(long double); + +extern float rintf(float); +extern double rint(double); +extern long double rintl(long double); + +extern long int lrintf(float); +extern long int lrint(double); +extern long int lrintl(long double); + +extern float roundf(float); +extern double round(double); +extern long double roundl(long double); + +extern long int lroundf(float); +extern long int lround(double); +extern long int lroundl(long double); + + + + +extern long long int llrintf(float); +extern long long int llrint(double); +extern long long int llrintl(long double); + +extern long long int llroundf(float); +extern long long int llround(double); +extern long long int llroundl(long double); + + +extern float truncf(float); +extern double trunc(double); +extern long double truncl(long double); + +extern float fmodf(float, float); +extern double fmod(double, double); +extern long double fmodl(long double, long double); + +extern float remainderf(float, float); +extern double remainder(double, double); +extern long double remainderl(long double, long double); + +extern float remquof(float, float, int *); +extern double remquo(double, double, int *); +extern long double remquol(long double, long double, int *); + +extern float copysignf(float, float); +extern double copysign(double, double); +extern long double copysignl(long double, long double); + +extern float nanf(const char *); +extern double nan(const char *); +extern long double nanl(const char *); + +extern float nextafterf(float, float); +extern double nextafter(double, double); +extern long double nextafterl(long double, long double); + +extern double nexttoward(double, long double); +extern float nexttowardf(float, long double); +extern long double nexttowardl(long double, long double); + +extern float fdimf(float, float); +extern double fdim(double, double); +extern long double fdiml(long double, long double); + +extern float fmaxf(float, float); +extern double fmax(double, double); +extern long double fmaxl(long double, long double); + +extern float fminf(float, float); +extern double fmin(double, double); +extern long double fminl(long double, long double); + +extern float fmaf(float, float, float); +extern double fma(double, double, double); +extern long double fmal(long double, long double, long double); +# 565 "/usr/include/math.h" 3 4 +extern float __inff(void) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); +extern double __inf(void) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); +extern long double __infl(void) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + +extern float __nan(void) __attribute__((availability(macosx,introduced=10.0))); +# 597 "/usr/include/math.h" 3 4 +extern float __exp10f(float) __attribute__((availability(macosx,introduced=10.9))); +extern double __exp10(double) __attribute__((availability(macosx,introduced=10.9))); + + + + + +inline __attribute__ ((__always_inline__)) void __sincosf(float __x, float *__sinp, float *__cosp); +inline __attribute__ ((__always_inline__)) void __sincos(double __x, double *__sinp, double *__cosp); +# 614 "/usr/include/math.h" 3 4 +extern float __cospif(float) __attribute__((availability(macosx,introduced=10.9))); +extern double __cospi(double) __attribute__((availability(macosx,introduced=10.9))); +extern float __sinpif(float) __attribute__((availability(macosx,introduced=10.9))); +extern double __sinpi(double) __attribute__((availability(macosx,introduced=10.9))); +extern float __tanpif(float) __attribute__((availability(macosx,introduced=10.9))); +extern double __tanpi(double) __attribute__((availability(macosx,introduced=10.9))); +# 645 "/usr/include/math.h" 3 4 +inline __attribute__ ((__always_inline__)) void __sincospif(float __x, float *__sinp, float *__cosp); +inline __attribute__ ((__always_inline__)) void __sincospi(double __x, double *__sinp, double *__cosp); + + + + + + +struct __float2 { float __sinval; float __cosval; }; +struct __double2 { double __sinval; double __cosval; }; + +extern struct __float2 __sincosf_stret(float); +extern struct __double2 __sincos_stret(double); +extern struct __float2 __sincospif_stret(float); +extern struct __double2 __sincospi_stret(double); + +inline __attribute__ ((__always_inline__)) void __sincosf(float __x, float *__sinp, float *__cosp) { + const struct __float2 __stret = __sincosf_stret(__x); + *__sinp = __stret.__sinval; *__cosp = __stret.__cosval; +} + +inline __attribute__ ((__always_inline__)) void __sincos(double __x, double *__sinp, double *__cosp) { + const struct __double2 __stret = __sincos_stret(__x); + *__sinp = __stret.__sinval; *__cosp = __stret.__cosval; +} + +inline __attribute__ ((__always_inline__)) void __sincospif(float __x, float *__sinp, float *__cosp) { + const struct __float2 __stret = __sincospif_stret(__x); + *__sinp = __stret.__sinval; *__cosp = __stret.__cosval; +} + +inline __attribute__ ((__always_inline__)) void __sincospi(double __x, double *__sinp, double *__cosp) { + const struct __double2 __stret = __sincospi_stret(__x); + *__sinp = __stret.__sinval; *__cosp = __stret.__cosval; +} + + + + + + + +extern double j0(double) __attribute__((availability(macosx,introduced=10.0))); +extern double j1(double) __attribute__((availability(macosx,introduced=10.0))); +extern double jn(int, double) __attribute__((availability(macosx,introduced=10.0))); +extern double y0(double) __attribute__((availability(macosx,introduced=10.0))); +extern double y1(double) __attribute__((availability(macosx,introduced=10.0))); +extern double yn(int, double) __attribute__((availability(macosx,introduced=10.0))); +extern double scalb(double, double); +extern int signgam; +# 751 "/usr/include/math.h" 3 4 +extern long int rinttol(double) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + +extern long int roundtol(double) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + +extern double drem(double, double) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + +extern int finite(double) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + +extern double gamma(double) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + +extern double significand(double) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); + + +struct exception { + int type; + char *name; + double arg1; + double arg2; + double retval; +}; + +extern int matherr(struct exception *) __attribute__((availability(macosx,introduced=10.0,deprecated=10.9))); +# 2 "simpleMath.c" 2 + +double +sin2(double x) +{ + return( sin(2 * x) ); +} diff --git a/CompileSteps/simpleMath.c b/CompileSteps/simpleMath.c new file mode 100644 index 0000000..2be94fb --- /dev/null +++ b/CompileSteps/simpleMath.c @@ -0,0 +1,9 @@ +#include + +double +sin2(double x) +{ + return( sin(2 * x) ); +} + + diff --git a/CompileSteps/sm b/CompileSteps/sm new file mode 100755 index 0000000..169ba3b Binary files /dev/null and b/CompileSteps/sm differ diff --git a/CompileSteps/sm.c b/CompileSteps/sm.c new file mode 100644 index 0000000..3161cc6 --- /dev/null +++ b/CompileSteps/sm.c @@ -0,0 +1,20 @@ +#include +#include + +extern double sin2(double); + +int +main(int argc, char *argv[]) +{ + double ans, value; + + // check we have more than one command line argument, the first being the name of the program sm + if(argc < 2) + return(1); + // so we have two or more + value = atof(argv[1]); + + ans = sin2(value); + printf("%lf\n", ans); + return(0); +} diff --git a/Topics.md b/Topics.md new file mode 100644 index 0000000..7d99225 --- /dev/null +++ b/Topics.md @@ -0,0 +1,40 @@ + ++ Calling existing C routine from 3rd party library + + simple routine that takes a vector of doubles and the length and + + matrices and accessing the (i,j) element. + + Compiling + + See CompileSteps + + pre-processor + + include -I, + + Makevars + + Compile + + Link - executable or dynamic library + + What is a shared library + + Motivation + + Benefits - hot-swappable + + Drawbacks - finding it at run-time + + security limitatins + + LD_LIBRARY_PATH/DYLD_LIBRARY_PATH + + Load + + wrapper routine + + return the result. + + Debugging + + R -d gdb ++ Difference between .C() and .Call() ++ R API + + Protecting objects ++ Rcpp ++ Doing more in the routine to avoid returning an intermediate object. + + The externalptr type + + Releasing memory when eventually no longer used. + + Making certain not to use it when it has been freed. + + + + +# Installing Software Locally + +# Configuration +## CMake +## Autoconf +## Make diff --git a/URLs b/URLs new file mode 100644 index 0000000..df31b98 --- /dev/null +++ b/URLs @@ -0,0 +1,8 @@ +https://github.com/dertuxmalwieder/libvldmail + +http://libsound.io/ + + + +GDB tricks +https://blogs.oracle.com/linux/8-gdb-tricks-you-should-know-v2 \ No newline at end of file diff --git a/dotC/src/dotC.c b/dotC/src/dotC.c new file mode 100644 index 0000000..e01303a --- /dev/null +++ b/dotC/src/dotC.c @@ -0,0 +1,7 @@ + +void +add1(double *x, int *len, double *ans) +{ + for(int i = 0; i < *len; i++) + ans[i] = x[i] + 1; +} diff --git a/dotC/tests/show.R b/dotC/tests/show.R new file mode 100644 index 0000000..40aa62b --- /dev/null +++ b/dotC/tests/show.R @@ -0,0 +1,4 @@ +dyn.load("dotC.so") +z = as.numeric(1:100) +o = .C("add1", z, length(z), ans = numeric(length(z))) $ans +o diff --git a/getrusage/R/rusage.R b/getrusage/R/rusage.R new file mode 100644 index 0000000..4be443b --- /dev/null +++ b/getrusage/R/rusage.R @@ -0,0 +1,16 @@ +rusage = +function(who = 0L) +{ + ans = .Call("R_getrusage", as.integer(who)) + names(ans) = c("maxrss", "ixrss", "idrss", "isrss", "minflt", "majflt", "nswap", "inblock", "oublock", "msgsnd", "msgrcv", "nsignals", "nvcsw", "nivcsw") + ans +} + + +rusage2 = +function(who = 0L) +{ + ans = .Call("R_getrusage2", as.integer(who)) + names(ans) = c("utime", "stime", "maxrss", "ixrss", "idrss", "isrss", "minflt", "majflt", "nswap", "inblock", "oublock", "msgsnd", "msgrcv", "nsignals", "nvcsw", "nivcsw") + ans +}