annotate R/rdyncall/src/rdynload.c @ 3:f5d4d5c2f750

- gemspec fix
author cslag
date Thu, 31 Dec 2015 20:24:53 +0100
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /** ===========================================================================
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 ** R-Package: rdyncall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 ** File: src/rdynload.c
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 ** Description: R bindings to dynload
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 **/
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 #include <Rinternals.h>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 #include "dynload.h"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 /** ---------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 ** C-Function: r_dynload
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 ** Description: load shared library and return lib handle
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 ** R-Calling Convention: .Call
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 **
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 **/
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 SEXP r_dynload(SEXP libpath_x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 const char* libpath_S;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 void* libHandle;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 libpath_S = CHAR(STRING_ELT(libpath_x,0));
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 libHandle = dlLoadLibrary(libpath_S);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 if (!libHandle)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 return R_NilValue;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 return R_MakeExternalPtr(libHandle, R_NilValue, R_NilValue);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 /** ---------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 ** C-Function: r_dynunload
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 ** Description: unload shared library
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 ** R-Calling Convention: .Call
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 **
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 **/
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 SEXP r_dynunload(SEXP libobj_x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 void* libHandle;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 if (TYPEOF(libobj_x) != EXTPTRSXP) error("first argument is not of type external ptr.");
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 libHandle = R_ExternalPtrAddr(libobj_x);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 if (!libHandle) error("not a lib handle");
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 dlFreeLibrary( libHandle );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 return R_NilValue;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 /** ---------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 ** C-Function: r_dynsym
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 ** Description: resolve symbol
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 ** R-Calling Convention: .Call
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 **
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 **/
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 SEXP r_dynsym(SEXP libh, SEXP symname_x, SEXP protectlib)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 void* libHandle;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 const char* symbol;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 void* addr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 SEXP protect;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 libHandle = R_ExternalPtrAddr(libh);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 symbol = CHAR(STRING_ELT(symname_x,0) );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 addr = dlFindSymbol( libHandle, symbol );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 protect = (LOGICAL(protectlib)[0]) ? libh : R_NilValue;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 return (addr) ? R_MakeExternalPtr(addr, R_NilValue, protect) : R_NilValue;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 }