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