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