1/* Remove global namespace pollution */ 2#if !defined(SWIG_NO_R_NO_REMAP) 3# define R_NO_REMAP 4#endif 5#if !defined(SWIG_NO_STRICT_R_HEADERS) 6# define STRICT_R_HEADERS 7#endif 8 9#include <Rdefines.h> 10#include <Rversion.h> 11 12#ifdef __cplusplus 13#include <exception> 14extern "C" { 15#endif 16 17/* for raw pointer */ 18#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_R_ConvertPtr(obj, pptr, type, flags) 19#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_R_ConvertPtr(obj, pptr, type, flags) 20#define SWIG_NewPointerObj(ptr, type, flags) SWIG_R_NewPointerObj(ptr, type, flags) 21 22#include <stdio.h> 23#include <stdlib.h> 24#include <assert.h> 25#include <stdarg.h> 26 27#if R_VERSION >= R_Version(2,6,0) 28#define VMAXTYPE void * 29#else 30#define VMAXTYPE char * 31#endif 32 33/* Last error */ 34static int SWIG_lasterror_code = 0; 35static char SWIG_lasterror_msg[1024]; 36SWIGRUNTIME void SWIG_Error(int code, const char *format, ...) { 37 va_list arg; 38 SWIG_lasterror_code = code; 39 va_start(arg, format); 40 vsnprintf(SWIG_lasterror_msg, sizeof(SWIG_lasterror_msg), format, arg); 41 va_end(arg); 42} 43 44SWIGRUNTIME const char *SWIG_ErrorType(int code) { 45 switch (code) { 46 case SWIG_MemoryError: 47 return "SWIG:MemoryError"; 48 case SWIG_IOError: 49 return "SWIG:IOError"; 50 case SWIG_RuntimeError: 51 return "SWIG:RuntimeError"; 52 case SWIG_IndexError: 53 return "SWIG:IndexError"; 54 case SWIG_TypeError: 55 return "SWIG:TypeError"; 56 case SWIG_DivisionByZero: 57 return "SWIG:DivisionByZero"; 58 case SWIG_OverflowError: 59 return "SWIG:OverflowError"; 60 case SWIG_SyntaxError: 61 return "SWIG:SyntaxError"; 62 case SWIG_ValueError: 63 return "SWIG:ValueError"; 64 case SWIG_SystemError: 65 return "SWIG:SystemError"; 66 case SWIG_AttributeError: 67 return "SWIG:AttributeError"; 68 } 69 return "SWIG:UnknownError"; 70} 71 72#define SWIG_fail goto fail 73 74/* 75 This is mainly a way to avoid having lots of local variables that may 76 conflict with those in the routine. 77 78 Change name to R_SWIG_Callb.... 79*/ 80typedef struct RCallbackFunctionData { 81 82 SEXP fun; 83 SEXP userData; 84 85 86 SEXP expr; 87 SEXP retValue; 88 int errorOccurred; 89 90 SEXP el; /* Temporary pointer used in the construction of the expression to call the R function. */ 91 92 struct RCallbackFunctionData *previous; /* Stack */ 93 94} RCallbackFunctionData; 95 96static RCallbackFunctionData *callbackFunctionDataStack; 97 98 99SWIGRUNTIME SEXP 100R_SWIG_debug_getCallbackFunctionData() 101{ 102 int n, i; 103 SEXP ans; 104 RCallbackFunctionData *p = callbackFunctionDataStack; 105 106 n = 0; 107 while(p) { 108 n++; 109 p = p->previous; 110 } 111 112 Rf_protect(ans = Rf_allocVector(VECSXP, n)); 113 for(p = callbackFunctionDataStack, i = 0; i < n; p = p->previous, i++) 114 SET_VECTOR_ELT(ans, i, p->fun); 115 116 Rf_unprotect(1); 117 118 return(ans); 119} 120 121 122 123SWIGRUNTIME RCallbackFunctionData * 124R_SWIG_pushCallbackFunctionData(SEXP fun, SEXP userData) 125{ 126 RCallbackFunctionData *el; 127 el = (RCallbackFunctionData *) calloc(1, sizeof(RCallbackFunctionData)); 128 el->fun = fun; 129 el->userData = userData; 130 el->previous = callbackFunctionDataStack; 131 132 callbackFunctionDataStack = el; 133 134 return(el); 135} 136 137 138SWIGRUNTIME SEXP 139R_SWIG_R_pushCallbackFunctionData(SEXP fun, SEXP userData) 140{ 141 R_SWIG_pushCallbackFunctionData(fun, userData); 142 return R_NilValue; 143} 144 145SWIGRUNTIME RCallbackFunctionData * 146R_SWIG_getCallbackFunctionData() 147{ 148 if(!callbackFunctionDataStack) { 149 Rf_error("Supposedly impossible error occurred in the SWIG callback mechanism." 150 " No callback function data set."); 151 } 152 153 return callbackFunctionDataStack; 154} 155 156SWIGRUNTIME void 157R_SWIG_popCallbackFunctionData(int doFree) 158{ 159 RCallbackFunctionData *el = NULL; 160 if(!callbackFunctionDataStack) 161 return ; /* Error !!! */ 162 163 el = callbackFunctionDataStack ; 164 callbackFunctionDataStack = callbackFunctionDataStack->previous; 165 166 if(doFree) 167 free(el); 168} 169 170 171/* 172 Interface to S function 173 is(obj, type) 174 which is to be used to determine if an 175 external pointer inherits from the right class. 176 177 Ideally, we would like to be able to do this without an explicit call to the is() function. 178 When the S4 class system uses its own SEXP types, then we will hopefully be able to do this 179 in the C code. 180 181 Should we make the expression static and preserve it to avoid the overhead of 182 allocating each time. 183*/ 184SWIGRUNTIME int 185R_SWIG_checkInherits(SEXP obj, SEXP tag, const char *type) 186{ 187 SEXP e, val; 188 int check_err = 0; 189 190 Rf_protect(e = Rf_allocVector(LANGSXP, 3)); 191 SETCAR(e, Rf_install("extends")); 192 193 SETCAR(CDR(e), Rf_mkString(CHAR(PRINTNAME(tag)))); 194 SETCAR(CDR(CDR(e)), Rf_mkString(type)); 195 196 val = R_tryEval(e, R_GlobalEnv, &check_err); 197 Rf_unprotect(1); 198 if(check_err) 199 return(0); 200 201 202 return(LOGICAL(val)[0]); 203} 204 205 206SWIGRUNTIME void * 207R_SWIG_resolveExternalRef(SEXP arg, const char * const type, const char * const argName, Rboolean nullOk) 208{ 209 void *ptr; 210 SEXP orig = arg; 211 212 if(TYPEOF(arg) != EXTPTRSXP) 213 arg = GET_SLOT(arg, Rf_mkString("ref")); 214 215 216 if(TYPEOF(arg) != EXTPTRSXP) { 217 Rf_error("argument %s must be an external pointer (from an ExternalReference)", argName); 218 } 219 220 221 ptr = R_ExternalPtrAddr(arg); 222 223 if(ptr == NULL && nullOk == (Rboolean) FALSE) { 224 Rf_error("the external pointer (of type %s) for argument %s has value NULL", argName, type); 225 } 226 227 if(type[0] && R_ExternalPtrTag(arg) != Rf_install(type) && strcmp(type, "voidRef") 228 && !R_SWIG_checkInherits(orig, R_ExternalPtrTag(arg), type)) { 229 Rf_error("the external pointer for argument %s has tag %s, not the expected value %s", 230 argName, CHAR(PRINTNAME(R_ExternalPtrTag(arg))), type); 231 } 232 233 234 return(ptr); 235} 236 237SWIGRUNTIME void 238R_SWIG_ReferenceFinalizer(SEXP el) 239{ 240 void *ptr = R_SWIG_resolveExternalRef(el, "", "<finalizer>", (Rboolean) 1); 241 fprintf(stderr, "In R_SWIG_ReferenceFinalizer for %p\n", ptr); 242 Rf_PrintValue(el); 243 244 if(ptr) { 245 if(TYPEOF(el) != EXTPTRSXP) 246 el = GET_SLOT(el, Rf_mkString("ref")); 247 248 if(TYPEOF(el) == EXTPTRSXP) 249 R_ClearExternalPtr(el); 250 251 free(ptr); 252 } 253 254 return; 255} 256 257SWIGRUNTIME SEXP 258SWIG_MakePtr(void *ptr, const char *typeName, int flags) 259{ 260 SEXP external, r_obj; 261 262 Rf_protect(external = R_MakeExternalPtr(ptr, Rf_install(typeName), R_NilValue)); 263 Rf_protect(r_obj = NEW_OBJECT(MAKE_CLASS((char *) typeName))); 264 265 if (flags & SWIG_POINTER_OWN) 266 R_RegisterCFinalizer(external, R_SWIG_ReferenceFinalizer); 267 268 r_obj = SET_SLOT(r_obj, Rf_mkString((char *) "ref"), external); 269 SET_S4_OBJECT(r_obj); 270 Rf_unprotect(2); 271 272 return(r_obj); 273} 274 275 276SWIGRUNTIME SEXP 277R_SWIG_create_SWIG_R_Array(const char *typeName, SEXP ref, int len) 278{ 279 SEXP arr; 280 281/*XXX remove the char * cast when we can. MAKE_CLASS should be declared appropriately. */ 282 Rf_protect(arr = NEW_OBJECT(MAKE_CLASS((char *) typeName))); 283 Rf_protect(arr = R_do_slot_assign(arr, Rf_mkString("ref"), ref)); 284 Rf_protect(arr = R_do_slot_assign(arr, Rf_mkString("dims"), Rf_ScalarInteger(len))); 285 286 Rf_unprotect(3); 287 SET_S4_OBJECT(arr); 288 return arr; 289} 290 291#define ADD_OUTPUT_ARG(result, pos, value, name) r_ans = AddOutputArgToReturn(pos, value, name, OutputValues); 292 293SWIGRUNTIME SEXP 294AddOutputArgToReturn(int pos, SEXP value, const char *name, SEXP output) 295{ 296 SET_VECTOR_ELT(output, pos, value); 297 298 return(output); 299} 300 301/* Create a new pointer object */ 302SWIGRUNTIMEINLINE SEXP 303SWIG_R_NewPointerObj(void *ptr, swig_type_info *type, int flags) { 304 SEXP rptr; 305 if (!ptr) { 306 return R_NilValue; 307 } 308 rptr = R_MakeExternalPtr(ptr, 309 R_MakeExternalPtr(type, R_NilValue, R_NilValue), R_NilValue); 310 SET_S4_OBJECT(rptr); 311 return rptr; 312} 313 314 315/* Convert a pointer value */ 316SWIGRUNTIMEINLINE int 317SWIG_R_ConvertPtr(SEXP obj, void **ptr, swig_type_info *ty, int flags) { 318 void *vptr; 319 if (!obj) return SWIG_ERROR; 320 if (obj == R_NilValue) { 321 if (ptr) *ptr = NULL; 322 return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; 323 } 324 325 vptr = R_ExternalPtrAddr(obj); 326 if (ty) { 327 swig_type_info *to = (swig_type_info*) 328 R_ExternalPtrAddr(R_ExternalPtrTag(obj)); 329 if (to == ty) { 330 if (ptr) *ptr = vptr; 331 } else { 332 swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); 333 int newmemory = 0; 334 if (ptr) *ptr = SWIG_TypeCast(tc,vptr,&newmemory); 335 assert(!newmemory); /* newmemory handling not yet implemented */ 336 } 337 } else { 338 if (ptr) *ptr = vptr; 339 } 340 return SWIG_OK; 341} 342 343SWIGRUNTIME swig_module_info * 344SWIG_GetModule(void *SWIGUNUSEDPARM(clientdata)) { 345 static void *type_pointer = (void *)0; 346 return (swig_module_info *) type_pointer; 347} 348 349SWIGRUNTIME void 350SWIG_SetModule(void *v, swig_module_info *swig_module) { 351} 352 353typedef struct { 354 void *pack; 355 swig_type_info *ty; 356 size_t size; 357} RSwigPacked; 358 359/* Create a new packed object */ 360 361SWIGRUNTIMEINLINE SEXP RSwigPacked_New(void *ptr, size_t sz, 362 swig_type_info *ty) { 363 SEXP rptr; 364 RSwigPacked *sobj = 365 (RSwigPacked*) malloc(sizeof(RSwigPacked)); 366 if (sobj) { 367 void *pack = malloc(sz); 368 if (pack) { 369 memcpy(pack, ptr, sz); 370 sobj->pack = pack; 371 sobj->ty = ty; 372 sobj->size = sz; 373 } else { 374 sobj = 0; 375 } 376 } 377 rptr = R_MakeExternalPtr(sobj, R_NilValue, R_NilValue); 378 return rptr; 379} 380 381SWIGRUNTIME swig_type_info * 382RSwigPacked_UnpackData(SEXP obj, void *ptr, size_t size) 383{ 384 RSwigPacked *sobj = 385 (RSwigPacked *)R_ExternalPtrAddr(obj); 386 if (sobj->size != size) return 0; 387 memcpy(ptr, sobj->pack, size); 388 return sobj->ty; 389} 390 391SWIGRUNTIMEINLINE SEXP 392SWIG_R_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { 393 return ptr ? RSwigPacked_New((void *) ptr, sz, type) : R_NilValue; 394} 395 396/* Convert a packed pointer value */ 397 398SWIGRUNTIME int 399SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) { 400 swig_type_info *to = RSwigPacked_UnpackData(obj, ptr, sz); 401 if (!to) return SWIG_ERROR; 402 if (ty) { 403 if (to != ty) { 404 /* check type cast? */ 405 swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); 406 if (!tc) return SWIG_ERROR; 407 } 408 } 409 return SWIG_OK; 410} 411 412#ifdef __cplusplus 413#define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0) 414#else 415#define SWIG_exception_noreturn(code, msg) do { return result; } while(0) 416#endif 417 418#ifdef __cplusplus 419} 420#endif 421