CXXR (C++ R)
Rdynpriv.h
1 /*CXXR $Id: Rdynpriv.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 2001-6 The R Core Team.
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  * GNU Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, a copy is available at
33  * http://www.r-project.org/Licenses/
34  */
35 
36 #ifndef R_DYNPRIV_H
37 #define R_DYNPRIV_H
38 
39 /*****************************************************
40  These are internal routines and definitions subject
41  to unannounced changes. Do not use for packages, etc.
42 
43  There is a great deal of repetition in the definitions
44  of the user-level method definitions and in the internal
45  definition structures. This is done to ensure that we
46  don't get into troubles needing different types, etc.
47  We could do it with typedef's and reduce the code, but it
48  is done now and isn't too complicated yet.
49 *****************************************************/
50 
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 
57 #ifdef Win32
58 #include <windows.h>
59 #define CACHE_DLL_SYM 1
60 #else
61 typedef void *HINSTANCE;
62 #endif
63 
64 
65 #include <Defn.h>
66 #include <R_ext/Rdynload.h>
67 
68  /*
69  A name-routine pair.
70  */
71 typedef struct {
72  char *name;
73  DL_FUNC func;
74 } CFunTabEntry;
75 
76  /*
77  These three structures are the processed, internal information about
78  native routines that can be called by R. They are intended to be
79  instantiated by packages that explicitly register the routines in the
80  library.
81 
82  More fields will be added to these "real soon now". These may contain
83  information such as
84  a) whether the routine is thread-safe or not,
85  b) with which other routines it must be sychronized,
86  c) the parameter types,
87  ...
88  */
89 
90 typedef struct {
91  char *name;
92  DL_FUNC fun;
93  int numArgs;
94 
95  R_NativePrimitiveArgType *types;
96  R_NativeArgStyle *styles;
97 
98 } Rf_DotCSymbol;
99 typedef Rf_DotCSymbol Rf_DotFortranSymbol;
100 
101 
102 typedef struct {
103  char *name;
104  DL_FUNC fun;
105  int numArgs;
106  R_NativeObjectArgType *types;
107 
108  R_NativeArgStyle *styles;
109 } Rf_DotCallSymbol;
110 
111 typedef Rf_DotCallSymbol Rf_DotExternalSymbol;
112 
113 
114 
115  /*
116  This structure holds the information about a library that is
117  loaded into R and whose symbols are directly accessible to
118  .C, .Call, .Fortran, .External, ...
119  This stores the short name of the library (with the path and extension removed),
120  and its fully qualified name including the path and extension.
121  Additionally, it can potentially be populated with information about
122  the native routines in that library that are callable by R.
123  */
124 struct _DllInfo {
125  char *path;
126  char *name;
127  HINSTANCE handle;
128  Rboolean useDynamicLookup; /* Flag indicating whether we use both registered
129  and dynamic lookup (TRUE) or just registered
130  values if there are any.
131  */
132 
133  int numCSymbols;
134  Rf_DotCSymbol *CSymbols;
135 
136  int numCallSymbols;
137  Rf_DotCallSymbol *CallSymbols;
138 
139  int numFortranSymbols;
140  Rf_DotFortranSymbol *FortranSymbols;
141 
142  int numExternalSymbols;
143  Rf_DotExternalSymbol *ExternalSymbols;
144 };
145 
146 
147 struct Rf_RegisteredNativeSymbol {
148  NativeSymbolType type;
149  union {
150  Rf_DotCSymbol *c;
151  Rf_DotCallSymbol *call;
152  Rf_DotFortranSymbol *fortran;
153  Rf_DotExternalSymbol *external;
154  } symbol;
155  DllInfo *dll;
156 };
157 
158 
159  /*
160  An abstraction of the system-specific hooks that can be implemented
161  to customize the dynamic loading for a particular operating system
162  or application.
163  The function pointers implement
164  the opening and closing of the libraries,
165  the resolution of symbol,
166  returning error messages from system-level failures,
167  finding symbols in R itself,
168  handling the cached symbols,
169  processing the library path.
170  */
171 typedef struct {
172  HINSTANCE (*loadLibrary)(const char *path, int asLocal, int now,
173  char const *search);
174  /* Load the dynamic library. */
175  DL_FUNC (*dlsym)(DllInfo *info, char const *name);
176  /* Low-level symbol lookup in library */
177  void (*closeLibrary)(HINSTANCE handle);
178  /* Unload the dynamic library from process. */
179  void (*getError)(char *buf, int len);
180  /* Put the current system error in DLLerror. */
181 
182 
183  void (*deleteCachedSymbols)(DllInfo *dll); /* Discard cached symbols */
184  DL_FUNC (*lookupCachedSymbol)(const char *name, const char *pkg, int all);
185 
186  void (*fixPath)(char *path);
187  void (*getFullDLLPath)(SEXP call, char *buf, const char * const path);
188 
189 } OSDynSymbol;
190 
191 extern OSDynSymbol Rf_osDynSymbol, *R_osDynSymbol;
192 
193 
194 #ifdef CACHE_DLL_SYM
195  /*
196  The collection of cached symbol holders which are used to make the lookup
197  more efficient. The most recently resolved symbols are stored in this
198  pool if CACHE_DLL_SYM is defined and repeated lookups check here first,
199  before using the dynamic loader's lookup mechanism.
200  */
201 typedef struct {
202  char pkg[21];
203  char name[41];
204  DL_FUNC func;
205 } R_CPFun;
206 
207 extern R_CPFun CPFun[];
208 extern int nCPFun;
209 
210 #endif /* CACHE_DLL_SYM */
211 
212 
213 DL_FUNC Rf_lookupCachedSymbol(const char *name, const char *pkg, int all);
214 
215 DL_FUNC R_dlsym(DllInfo *info, char const *name, R_RegisteredNativeSymbol *symbol);
216 
217 SEXP R_MakeExternalPtrFn(DL_FUNC p, SEXP tag, SEXP prot);
218 DL_FUNC R_ExternalPtrAddrFn(SEXP s);
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif /* ifdef R_DYNPRIV_H */