The R Project SVN R

Rev

Rev 60255 | Rev 68949 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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