CXXR (C++ R) API
RS.h
1 /*CXXR $Id: RS.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) 1999-2007 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 Lesser General Public License as published by
23  * the Free Software Foundation; either version 2.1 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 Lesser 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_RS_H
37 #define R_RS_H
38 
39 #ifndef NO_C_HEADERS
40 # include <string.h> /* for memcpy */
41 #endif
42 
43 #include <Rconfig.h> /* for F77_APPEND_UNDERSCORE */
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /* S Like Error Handling */
50 
51 #include <R_ext/Error.h> /* for error and warning */
52 
53 #ifndef STRICT_R_HEADERS
54 
55 #define R_PROBLEM_BUFSIZE 4096
56 /* Parentheses added for FC4 with gcc4 and -D_FORTIFY_SOURCE=2 */
57 #define PROBLEM {char R_problem_buf[R_PROBLEM_BUFSIZE];(sprintf)(R_problem_buf,
58 #define MESSAGE {char R_problem_buf[R_PROBLEM_BUFSIZE];(sprintf)(R_problem_buf,
59 #define ERROR ),error(R_problem_buf);}
60 #define RECOVER(x) ),error(R_problem_buf);}
61 #define WARNING(x) ),warning(R_problem_buf);}
62 #define LOCAL_EVALUATOR
63 #define NULL_ENTRY
64 #define WARN WARNING(NULL)
65 
66 #endif
67 
68 /* S Like Memory Management */
69 
70 extern void *R_chk_calloc(size_t, size_t);
71 extern void *R_chk_realloc(void *, size_t);
72 extern void R_chk_free(void *);
73 
74 #ifdef __cplusplus
75 #ifndef STRICT_R_HEADERS
76 /* S-PLUS 3.x but not 5.x NULLs the pointer in the following */
77 #define Calloc(n, t) reinterpret_cast<t *>(R_chk_calloc(size_t(n), sizeof(t) ))
78 #define Realloc(p,n,t) reinterpret_cast<t *>(R_chk_realloc( p, size_t((n) * sizeof(t)) ))
79 #define Free(p) (R_chk_free(p), (p) = NULL)
80 #endif
81 #define R_Calloc(n, t) reinterpret_cast<t *>(R_chk_calloc( size_t(n), sizeof(t) ))
82 #define R_Realloc(p,n,t) reinterpret_cast<t *>(R_chk_realloc( (p), (size_t)((n) * sizeof(t)) ))
83 #define R_Free(p) (R_chk_free(p), (p) = NULL)
84 #define Memcpy(p,q,n) memcpy( p, q, size_t( (n) * sizeof(*p) ) )
85 #else /* not __cplusplus */
86 #ifndef STRICT_R_HEADERS
87 /* S-PLUS 3.x but not 5.x NULLs the pointer in the following */
88 #define Calloc(n, t) (t *) R_chk_calloc( (size_t) (n), sizeof(t) )
89 #define Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (size_t)((n) * sizeof(t)) )
90 #define Free(p) (R_chk_free( (void *)(p) ), (p) = NULL)
91 #endif
92 #define R_Calloc(n, t) (t *) R_chk_calloc( (size_t) (n), sizeof(t) )
93 #define R_Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (size_t)((n) * sizeof(t)) )
94 #define R_Free(p) (R_chk_free( (void *)(p) ), (p) = NULL)
95 #define Memcpy(p,q,n) memcpy( p, q, (size_t)( (n) * sizeof(*p) ) )
96 #endif /* __cplusplus */
97 
98 #ifdef __cplusplus
99 #define CallocCharBuf(n) reinterpret_cast<char *>(R_chk_calloc(size_t((n)+1), sizeof(char)))
100 #else
101 #define CallocCharBuf(n) (char *) R_chk_calloc((size_t) ((n)+1), sizeof(char))
102 #endif
103 
104 /* S Like Fortran Interface */
105 /* These may not be adequate everywhere. Convex had _ prepending common
106  blocks, and some compilers may need to specify Fortran linkage */
107 
108 #ifdef HAVE_F77_UNDERSCORE
109 # define F77_CALL(x) x ## _
110 #else
111 # define F77_CALL(x) x
112 #endif
113 #define F77_NAME(x) F77_CALL(x)
114 #define F77_SUB(x) F77_CALL(x)
115 #define F77_COM(x) F77_CALL(x)
116 #define F77_COMDECL(x) F77_CALL(x)
117 
118 #ifndef NO_CALL_R
119 void call_R(char*, long, void**, char**, long*, char**, long, char**);
120 #endif
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* R_RS_H */