Commits

wesmckinn committed 653a7a0

fix missing strndup on OS X

Comments (0)

Files changed (1)

rpy/rinterface/rinterface.c

 /* A python-R interface*/
 
-/* 
+/*
  * The authors for the original RPy code, as well as
  * belopolsky for his contributed code, are listed here as authors;
  * although the design is largely new, parts of this code is
- * derived from their contributions. 
- * 
+ * derived from their contributions.
+ *
  * Laurent Gautier - 2008
  */
 
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  * for the specific language governing rights and limitations under the
  * License.
- * 
+ *
  * Copyright (C) 2008-2011 Laurent Gautier
  *
- * Portions created by Alexander Belopolsky are 
+ * Portions created by Alexander Belopolsky are
  * Copyright (C) 2006 Alexander Belopolsky.
  *
  * Portions created by Gregory R. Warnes are
  * Copyright (C) 2003-2008 Gregory Warnes.
  *
- * Portions created by Walter Moreira are 
+ * Portions created by Walter Moreira are
  * Copyright (C) 2002-2003 Walter Moreira
  *
  * Alternatively, the contents of this file may be used under the terms of
 #include <signal.h>
 #include <setjmp.h>
 
-#define PY_SSIZE_T_CLEAN 
+#define PY_SSIZE_T_CLEAN
 #include "Python.h"
 
 #if Win32
 #include "sequence.c"
 #include "rexternalptr.c"
 
+#ifdef __APPLE__
+/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
+char *strndup (const char *s, size_t n)
+{
+    size_t len = strlen (s);
+    char *ret;
+
+    if (len <= n)
+	return strdup (s);
+
+    ret = malloc(n + 1);
+    strncpy(ret, s, n);
+    ret[n] = '\0';
+    return ret;
+}
+
+#endif
+
 static PyObject *embeddedR_isInitialized;
 
 /* A tuple that holds options to initialize R */
                                                  PyObject *args,
                                                  PyObject **target)
 {
-  
+
   PyObject *result = NULL;
   PyObject *function;
-  
-  if ( PyArg_ParseTuple(args, "O:console", 
+
+  if ( PyArg_ParseTuple(args, "O:console",
                         &function)) {
-    
+
     if (function != Py_None && !PyCallable_Check(function)) {
       PyErr_SetString(PyExc_TypeError, "parameter must be callable");
       return NULL;
     PyErr_SetString(PyExc_TypeError, "The parameter should be a callable.");
   }
   return result;
-  
+
 }
 
 static PyObject* EmbeddedR_getAnyCallback(PyObject *self,
 
   Py_DECREF(arglist);
 /*   signal(SIGINT, old_int); */
-  
-  Py_XDECREF(result);  
+
+  Py_XDECREF(result);
   RPY_GIL_RELEASE(is_threaded, gstate);
 }
 
 static PyObject* EmbeddedR_setShowMessage(PyObject *self,
                                           PyObject *args)
 {
-  return EmbeddedR_setAnyCallback(self, args, &showMessageCallback);  
+  return EmbeddedR_setAnyCallback(self, args, &showMessageCallback);
 }
 
 PyDoc_STRVAR(EmbeddedR_setShowMessage_doc,
 
   Py_DECREF(arglist);
 /*   signal(SIGINT, old_int); */
-  
+
   Py_XDECREF(result);
   RPY_GIL_RELEASE(is_threaded, gstate);
 }
 static PyObject* EmbeddedR_setReadConsole(PyObject *self,
                                           PyObject *args)
 {
-  return EmbeddedR_setAnyCallback(self, args, &readConsoleCallback); 
+  return EmbeddedR_setAnyCallback(self, args, &readConsoleCallback);
 }
 
 PyDoc_STRVAR(EmbeddedR_setReadConsole_doc,
              " (see set_readconsole)");
 
 static int
-EmbeddedR_ReadConsole(const char *prompt, unsigned char *buf, 
+EmbeddedR_ReadConsole(const char *prompt, unsigned char *buf,
                       int len, int addtohistory)
 {
   PyObject *arglist;
   if (is_unicode)
     Py_XDECREF(pybytes);
 #endif
-  
+
   Py_XDECREF(result);
 /*   signal(SIGINT, old_int); */
 
 static PyObject* EmbeddedR_setFlushConsole(PyObject *self,
                                            PyObject *args)
 {
-  return EmbeddedR_setAnyCallback(self, args, &flushConsoleCallback);  
+  return EmbeddedR_setAnyCallback(self, args, &flushConsoleCallback);
 }
 
 PyDoc_STRVAR(EmbeddedR_setFlushConsole_doc,
 static PyObject* EmbeddedR_setChooseFile(PyObject *self,
                                          PyObject *args)
 {
-  return EmbeddedR_setAnyCallback(self, args, &chooseFileCallback);  
+  return EmbeddedR_setAnyCallback(self, args, &chooseFileCallback);
 }
 
 PyDoc_STRVAR(EmbeddedR_setChooseFile_doc,
     RPY_GIL_RELEASE(is_threaded, gstate);
     return 0;
   }
-  
+
   if (result == NULL) {
     /* FIXME: can this be reached ? result == NULL while no error ? */
     Py_XDECREF(arglist);
     Py_DECREF(pybytes);
 #endif
     Py_DECREF(result);
-    PyErr_SetString(PyExc_TypeError, 
+    PyErr_SetString(PyExc_TypeError,
                     "Returned value should have a string representation");
     PyErr_Print();
     PyErr_Clear();
     Py_DECREF(pybytes);
 #endif
 
-  Py_DECREF(arglist);  
+  Py_DECREF(arglist);
   Py_DECREF(result);
 
   RPY_GIL_RELEASE(is_threaded, gstate);
 static PyObject* EmbeddedR_setShowFiles(PyObject *self,
                                         PyObject *args)
 {
-  return EmbeddedR_setAnyCallback(self, args, &showFilesCallback);  
+  return EmbeddedR_setAnyCallback(self, args, &showFilesCallback);
 }
 
 PyDoc_STRVAR(EmbeddedR_setShowFiles_doc,
     RPY_GIL_RELEASE(is_threaded, gstate);
     return 0;
   }
-   
+
   if (nfile < 1) {
     RPY_GIL_RELEASE(is_threaded, gstate);
     return 0;
 #else
    PyObject *py_wtitle = PyUnicode_FromString(wtitle);
    PyObject *py_pager = PyUnicode_FromString(pager);
-#endif  
+#endif
   PyObject *py_fileheaders_tuple = PyTuple_New(nfile);
   PyObject *py_fileheader;
   int f_i;
     RPY_GIL_RELEASE(is_threaded, gstate);
     return 0;
   }
-  
+
   if (result == NULL) {
     /* FIXME: can this be reached ? result == NULL while no error ? */
     Py_XDECREF(arglist);
   /*FIXME: check that nothing is returned ? */
   if (! 1) {
     Py_DECREF(result);
-    PyErr_SetString(PyExc_TypeError, 
+    PyErr_SetString(PyExc_TypeError,
                     "Returned value should be None");
     PyErr_Print();
     PyErr_Clear();
 static PyObject* EmbeddedR_setCleanUp(PyObject *self,
                                        PyObject *args)
 {
-  return EmbeddedR_setAnyCallback(self, args, &cleanUpCallback);  
+  return EmbeddedR_setAnyCallback(self, args, &cleanUpCallback);
 }
 
 PyDoc_STRVAR(EmbeddedR_setCleanUp_doc,
 PyDoc_STRVAR(EmbeddedR_getCleanUp_doc,
              "Get the function called to clean up when exiting R.");
 
-extern SA_TYPE SaveAction; 
+extern SA_TYPE SaveAction;
 static void
 EmbeddedR_CleanUp(SA_TYPE saveact, int status, int runLast)
 {
   if(saveact == SA_DEFAULT) { /* The normal case apart from R_Suicide */
     saveact = SaveAction;
   }
-  
+
   RPY_GIL_ENSURE(is_threaded, gstate);
-  
+
   PyObject *arglist = Py_BuildValue("iii", saveact, status, runLast);
   PyObject *result = PyEval_CallObject(cleanUpCallback, arglist);
   PyObject* pythonerror = PyErr_Occurred();
-  
+
   if (pythonerror != NULL) {
     /* All R actions should be stopped since the Python callback failed,
              and the Python exception raised up.*/
   if (saveact == SA_SAVEASK) {
     if (R_Interactive) {
       /* if (cleanUpCallback != NULL) {  */
-        
+
       /*        } */
       /* } else { */
         saveact = SaveAction;
 /*   if(ifp) fclose(ifp); */
 /*   if(ifile[0]) unlink(ifile); */
   /* exit(status); */
-  
+
 }
 
 /* --- Initialize and terminate an embedded R --- */
-static PyObject* EmbeddedR_getinitoptions(PyObject *self) 
+static PyObject* EmbeddedR_getinitoptions(PyObject *self)
 {
   return initOptions;
 }
 Get the options used to initialize R.\
 ");
 
-static PyObject* EmbeddedR_setinitoptions(PyObject *self, PyObject *tuple) 
+static PyObject* EmbeddedR_setinitoptions(PyObject *self, PyObject *tuple)
 {
 
   if (rpy_has_status(RPY_R_INITIALIZED)) {
-    PyErr_Format(PyExc_RuntimeError, 
+    PyErr_Format(PyExc_RuntimeError,
                  "Options cannot be set once R has been initialized.");
     return NULL;
   }
     }
 #endif
   }
-  
-  
+
+
   Py_DECREF(initOptions);
   Py_INCREF(tuple);
   initOptions = tuple;
 static PyObject* EmbeddedR_ProcessEvents(PyObject *self)
 {
   if (! (rpy_has_status(RPY_R_INITIALIZED))) {
-    PyErr_Format(PyExc_RuntimeError, 
+    PyErr_Format(PyExc_RuntimeError,
                  "R should not process events before being initialized.");
     return NULL;
   }
 }
 void Re_Busy(int which)
 {
-  
+
 }
 #endif
 
-static PyObject* EmbeddedR_init(PyObject *self) 
+static PyObject* EmbeddedR_init(PyObject *self)
 {
 
   static int status;
-  
+
   if (rpy_has_status(RPY_R_INITIALIZED)) {
 #if (PY_VERSION_HEX < 0x03010000)
     return PyInt_FromLong(status);
 
 #ifdef RIF_HAS_RSIGHAND
   R_SignalHandlers = 0;
-#endif  
+#endif
   /* int status = Rf_initEmbeddedR(n_args, options);*/
   status = Rf_initialize_R(n_args, options);
   if (status < 0) {
   R_Interactive = TRUE;
 #ifdef RIF_HAS_RSIGHAND
   R_SignalHandlers = 0;
-#endif  
+#endif
 
 #ifdef R_INTERFACE_PTRS
   ptr_R_CleanUp = EmbeddedR_CleanUp;
   RPY_SEXP((PySexpObject *)RNULL_Type_New(0)) = R_NilValue;
   RPY_SEXP(rpy_R_NilValue) = R_NilValue;
 
-  errMessage_SEXP = findVar(install("geterrmessage"), 
+  errMessage_SEXP = findVar(install("geterrmessage"),
                             R_BaseNamespace);
 #if (PY_VERSION_HEX < 0x03010000)
   PyObject *res = PyInt_FromLong(status);
   /* FIXME: Have a reference count for R objects known to Python.
    * ending R will not be possible until all such objects are already
    * deallocated in Python ?
-   *other possibility would be to have a fallback for "unreachable" objects ? 
+   *other possibility would be to have a fallback for "unreachable" objects ?
    */
   /*FIXME: rpy has something to terminate R. Check the details of what they are. */
   /* taken from the tests/Embedded/shutdown.c in the R source tree */
 
-  R_dot_Last();           
-  R_RunExitFinalizers();  
+  R_dot_Last();
+  R_RunExitFinalizers();
   /* CleanEd(); */
   Rf_KillAllDevices();
-  
+
   R_CleanTempDir();
   /* PrintWarnings(); */
   R_gc();
   /* */
 
   Rf_endEmbeddedR((int)fatal);
-  
+
   embeddedR_status = embeddedR_status & (! RPY_R_INITIALIZED);
 
   RPY_SEXP(globalEnv) = R_EmptyEnv;
   RPY_SEXP(baseNameSpaceEnv) = R_EmptyEnv;
   RPY_SEXP(emptyEnv) = R_EmptyEnv;
-  errMessage_SEXP = R_NilValue; 
+  errMessage_SEXP = R_NilValue;
 
   /* FIXME: Is it possible to reinitialize R later ?
    * Py_XDECREF(embeddedR_isInitialized);
    * embeddedR_isInitialized = Py_False;
-   *Py_INCREF(embeddedR_isInitialized); 
+   *Py_INCREF(embeddedR_isInitialized);
    */
 
   Py_RETURN_NONE;
   ParseStatus status;
 
   if (! (rpy_has_status(RPY_R_INITIALIZED))) {
-    PyErr_Format(PyExc_RuntimeError, 
+    PyErr_Format(PyExc_RuntimeError,
                  "R must be initialized before any call to R functions is possible.");
     return NULL;
   }
 
   /* Py_BEGIN_ALLOW_THREADS */
 
-#ifdef _WIN32  
+#ifdef _WIN32
   last_sighandler = PyOS_setsig(SIGBREAK, interrupt_R);
 #else
   last_sighandler = PyOS_setsig(SIGINT, interrupt_R);
 
   /* Py_END_ALLOW_THREADS */
 #ifdef _WIN32
-  PyOS_setsig(SIGBREAK, python_sighandler);   
-#else 
+  PyOS_setsig(SIGBREAK, python_sighandler);
+#else
   PyOS_setsig(SIGINT, python_sighandler);
 #endif
 
 static PyObject *
 Sexp_rcall(PyObject *self, PyObject *args)
 {
-  
+
   if (! (rpy_has_status(RPY_R_INITIALIZED))) {
-    PyErr_Format(PyExc_RuntimeError, 
+    PyErr_Format(PyExc_RuntimeError,
                  "R must be initialized before any call to R functions is possible.");
     return NULL;
   }
   }
   if (! PyObject_IsInstance(env,
                             (PyObject*)&EnvironmentSexp_Type)) {
-    PyErr_Format(PyExc_ValueError, 
+    PyErr_Format(PyExc_ValueError,
                  "The second parameter must be an EnvironmentSexp_Type.");
     return NULL;
   }
     return NULL;
   }
   embeddedR_setlock();
-    
+
   SEXP call_R, c_R, res_R;
   int nparams;
   SEXP tmp_R, fun_R;
   int protect_count = 0;
-  
+
   if (! PySequence_Check(args)) {
-    PyErr_Format(PyExc_ValueError, 
+    PyErr_Format(PyExc_ValueError,
                  "The one argument to the function must implement the sequence protocol.");
     embeddedR_freelock();
     return NULL;
   }
   nparams = PySequence_Length(params);
-  
+
   /* A SEXP with the function to call and the arguments and keywords. */
   PROTECT(c_R = call_R = allocList(nparams+1));
   protect_count++;
   /* named args */
   PyObject *argValue, *argName;
 #if (PY_VERSION_HEX < 0x03010000)
-#else  
+#else
   PyObject *pybytes;
 #endif
   const char *argNameString;
   for (arg_i=0; arg_i<nparams; arg_i++) {
     /* printf("item: %i\n", arg_i); */
     tmp_obj = PySequence_GetItem(params, arg_i);
-    /* PySequence_GetItem() returns a new reference 
+    /* PySequence_GetItem() returns a new reference
     * so tmp_obj must be DECREFed when no longer required */
     if (! tmp_obj) {
       PyErr_Format(PyExc_ValueError, "No item %i !?", arg_i);
       goto fail;
     }
     if (! PyTuple_Check(tmp_obj)) {
-      PyErr_Format(PyExc_ValueError, 
+      PyErr_Format(PyExc_ValueError,
                    "Item %i in the sequence is not a tuple.",
                    arg_i);
       Py_DECREF(tmp_obj);
     item_length = PyTuple_GET_SIZE(tmp_obj);
     if (item_length != 2) {
       PyErr_Format(PyExc_ValueError, "Item %i in the sequence passed as an argument"
-                   "should have two elements.", 
+                   "should have two elements.",
                    arg_i);
       Py_DECREF(tmp_obj);
       goto fail;
       on_the_fly = 1;
       RPY_PYSCALAR_RVECTOR(argValue, tmp_R);
       if (tmp_R == NULL) {
-        PyErr_Format(PyExc_ValueError, 
+        PyErr_Format(PyExc_ValueError,
                      "All parameters must be of type Sexp_Type,"
                      "or Python int/long, float, bool, or None"
                      );
   UNPROTECT(protect_count);
   embeddedR_freelock();
   return res;
-  
+
  fail:
   UNPROTECT(protect_count);
   embeddedR_freelock();
   Py_ssize_t n_unnamedparams, n_namedparams, n_params, p_i, ppos;
   PyObject *tmp_pair, *tmp_key, *tmp_value, *params, *new_args, *res;
   n_unnamedparams = PySequence_Length(args);
-  /* test present in Objects/funcobject.c in the Python source 
+  /* test present in Objects/funcobject.c in the Python source
    * Missing keywords do not translate to an empty dict.
    */
   if (kwds != NULL && PyDict_Check(kwds)) {
   PyObject *copy;
   static char *kwlist[] = {"sexpclos", "copy", NULL};
   /* FIXME: handle the copy argument */
-  if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|O!", 
+  if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|O!",
                                     kwlist,
                                     &object,
                                     &PyBool_Type, &copy)) {
     return -1;
   }
-  if (PyObject_IsInstance(object, 
+  if (PyObject_IsInstance(object,
                           (PyObject*)&ClosureSexp_Type)) {
     /* call parent's constructor */
     if (Sexp_init(self, args, NULL) == -1) {
   PyObject *wantFun = Py_False;
 
   static char *kwlist[] = {"name", "wantfun", NULL};
- 
+
   if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O!",
                                    kwlist,
-                                   &name, 
-                                   &PyBool_Type, &wantFun)) { 
-    return NULL; 
+                                   &name,
+                                   &PyBool_Type, &wantFun)) {
+    return NULL;
   }
 
   if (rpy_has_status(RPY_R_BUSY)) {
 EnvironmentSexp_frame(PyObject *self)
 {
   if (! (rpy_has_status(RPY_R_INITIALIZED))) {
-    PyErr_Format(PyExc_RuntimeError, 
+    PyErr_Format(PyExc_RuntimeError,
                  "R must be initialized before environments can be accessed.");
     return NULL;
   }
 EnvironmentSexp_enclos(PyObject *self)
 {
   if (! (rpy_has_status(RPY_R_INITIALIZED))) {
-    PyErr_Format(PyExc_RuntimeError, 
+    PyErr_Format(PyExc_RuntimeError,
                  "R must be initialized before environments can be accessed.");
     return NULL;
   }
 
   int is_PySexpObject = PyObject_TypeCheck(value, &Sexp_Type);
   if (! is_PySexpObject) {
-    PyErr_Format(PyExc_ValueError, 
+    PyErr_Format(PyExc_ValueError,
                  "All parameters must be of type Sexp_Type.");
     return -1;
   }
   return 0;
 }
 
-static Py_ssize_t EnvironmentSexp_length(PyObject *self) 
+static Py_ssize_t EnvironmentSexp_length(PyObject *self)
 {
   if (rpy_has_status(RPY_R_BUSY)) {
     PyErr_Format(PyExc_RuntimeError, "Concurrent access to R is not allowed.");
   (objobjargproc)EnvironmentSexp_ass_subscript  /* mp_ass_subscript */
 };
 
-static PyObject* 
+static PyObject*
 EnvironmentSexp_iter(PyObject *sexpEnvironment)
 {
   if (rpy_has_status(RPY_R_BUSY)) {
   PySexpObject *seq = newPySexpObject(symbols, 1);
   Py_INCREF(seq);
   UNPROTECT(1);
- 
+
   PyObject *it = PyObject_GetIter((PyObject *)seq);
   Py_DECREF(seq);
   embeddedR_freelock();
   PyObject *copy = Py_False;
   static char *kwlist[] = {"sexpenv", "copy", NULL};
   /* FIXME: handle the copy argument */
-  if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|O!", 
+  if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|O!",
                                     kwlist,
                                     &object,
                                     &PyBool_Type, &copy)) {
   }
   embeddedR_setlock();
 
-  if (PyObject_IsInstance(object, 
+  if (PyObject_IsInstance(object,
                           (PyObject*)&EnvironmentSexp_Type)) {
     /* call parent's constructor */
     if (Sexp_init(self, args, NULL) == -1) {
 };
 
 
-/* --- Create a SEXP object --- 
- * Given an R SEXP object, it creates a 
+/* --- Create a SEXP object ---
+ * Given an R SEXP object, it creates a
  * PySexpObject that is an rpy2 Python representation
  * of an R object.
  * if preserve is not 0, it the resulting object is 'preserved'
     sexp_ok = eval(sexp, env_R);
 #ifdef RPY_DEBUG_PROMISE
     printf("  evaluating promise %p into %p.\n", sexp, sexp_ok);
-#endif 
-  } 
+#endif
+  }
   else {
     sexp_ok = sexp;
   }
     R_PreserveObject(sexp_ok);
 #ifdef RPY_DEBUG_PRESERVE
     preserved_robjects += 1;
-    printf("  PRESERVE -- R_PreserveObject -- %p -- %i\n", 
+    printf("  PRESERVE -- R_PreserveObject -- %p -- %i\n",
            sexp_ok, preserved_robjects);
-#endif 
+#endif
   }
 
   switch (TYPEOF(sexp_ok)) {
     object  = (PySexpObject *)Sexp_new(&ClosureSexp_Type, Py_None, Py_None);
     break;
     /*FIXME: BUILTINSXP and SPECIALSXP really like CLOSXP ? */
-  case REALSXP: 
-  case INTSXP: 
+  case REALSXP:
+  case INTSXP:
   case LGLSXP:
   case CPLXSXP:
   case VECSXP:
   }
   if (!object) {
 #ifdef RPY_DEBUG_PRESERVE
-    printf("  PRESERVE -- Sexp_clear: R_ReleaseObject -- %p ", 
+    printf("  PRESERVE -- Sexp_clear: R_ReleaseObject -- %p ",
            sexp_ok);
     preserved_robjects -= 1;
     printf("-- %i\n", preserved_robjects);
 }
 
 
-/* This function is only able to create a R-Python object 
+/* This function is only able to create a R-Python object
    for an R vector-like 'rType', and from an 'object'
    that is a sequence. */
 static SEXP
 {
   SEXP sexp;
   SEXP str_R; /* used whenever there a string / unicode */
-  PyObject *seq_object, *item, *item_tmp, *na, *pybytes; 
+  PyObject *seq_object, *item, *item_tmp, *na, *pybytes;
 
 #ifdef RPY_VERBOSE
   printf("  new SEXP for Python:%p.\n", object);
-#endif 
-
-  seq_object = PySequence_Fast(object, 
+#endif
+
+  seq_object = PySequence_Fast(object,
                                "Cannot create R object from non-sequence Python object.");
 
   if (! seq_object) {
 	} else if (PyLong_Check(item)) {
 #endif
           tmp = allocVector(INTSXP, 1);
-#if (PY_VERSION_HEX < 0x03010000)                         
+#if (PY_VERSION_HEX < 0x03010000)
           INTEGER_POINTER(tmp)[0] = (int)PyInt_AS_LONG(item);
 #else
 	  INTEGER_POINTER(tmp)[0] = (int)PyLong_AS_LONG(item);
     R_PreserveObject(sexp);
 #ifdef RPY_DEBUG_PRESERVE
     preserved_robjects += 1;
-    printf("  PRESERVE -- R_PreserveObject -- %p -- %i\n", 
+    printf("  PRESERVE -- R_PreserveObject -- %p -- %i\n",
            sexp, preserved_robjects);
-#endif 
+#endif
   }
 
 #ifdef RPY_VERBOSE
   SEXP rho_R = R_GlobalEnv, res;
   PyObject rho;
 
-  if (!PyArg_ParseTuple(args, "s", &name, &rho)) { 
-    return NULL; 
+  if (!PyArg_ParseTuple(args, "s", &name, &rho)) {
+    return NULL;
   }
 
   res = findVar(install(name), rho_R);
 /* --- List of functions defined in the module --- */
 
 static PyMethodDef EmbeddedR_methods[] = {
-  {"get_initoptions",     (PyCFunction)EmbeddedR_getinitoptions,   
+  {"get_initoptions",     (PyCFunction)EmbeddedR_getinitoptions,
    METH_NOARGS,
    EmbeddedR_get_initoptions_doc},
-  {"set_initoptions",     (PyCFunction)EmbeddedR_setinitoptions,   
+  {"set_initoptions",     (PyCFunction)EmbeddedR_setinitoptions,
    METH_O,
    EmbeddedR_set_initoptions_doc},
   {"initr",     (PyCFunction)EmbeddedR_init,   METH_NOARGS,
   embeddedR_setlock();
   if (!pyres) {
     PyObject *exctype;
-    PyObject *excvalue; 
+    PyObject *excvalue;
     PyObject *exctraceback;
     PyObject *excstr;
     PyErr_Fetch(&exctype, &excvalue, &exctraceback);
       Py_DECREF(pybytes);
 #endif
       Py_DECREF(excstr);
-    } 
+    }
     else {
       error("Python error");
     }
   }
   Py_DECREF(pyargs);
   Py_DECREF(pyargstup);
-  if (PyObject_IsInstance((PyObject*)pyres, 
+  if (PyObject_IsInstance((PyObject*)pyres,
                           (PyObject*)&Sexp_Type)) {
     res = RPY_SEXP((PySexpObject*)pyres);
   }
     UNPROTECT(protect_count);
   }
   Py_DECREF(pyres);
-  
+
   return res;
 }
 
 static void RegisterExternalSymbols() {
-  R_ExternalMethodDef externalMethods[] = { 
+  R_ExternalMethodDef externalMethods[] = {
     {".Python", (DL_FUNC)&do_Python, -1},
-    {NULL, NULL, 0} 
+    {NULL, NULL, 0}
   };
   R_registerRoutines(R_getEmbeddingDllInfo(), NULL, NULL, NULL, externalMethods);
 }
   /* { */
 
   /* Finalize the type object including setting type of the new type
-         * object; doing it here is required for portability to Windows 
+         * object; doing it here is required for portability to Windows
          * without requiring C++. */
   if (PyType_Ready(&Sexp_Type) < 0)
     return;
 
   initOptions = PyTuple_New(4);
 
-#if (PY_VERSION_HEX < 0x03010000)  
+#if (PY_VERSION_HEX < 0x03010000)
   PYASSERT_ZERO(
-                PyTuple_SetItem(initOptions, 0, 
+                PyTuple_SetItem(initOptions, 0,
                                 PyString_FromString("rpy2"))
                 );
   PYASSERT_ZERO(
-                PyTuple_SetItem(initOptions, 1, 
+                PyTuple_SetItem(initOptions, 1,
                                 PyString_FromString("--quiet"))
                 );
   PYASSERT_ZERO(
                                 PyString_FromString("--vanilla"))
                 );
   PYASSERT_ZERO(
-                PyTuple_SetItem(initOptions, 3, 
+                PyTuple_SetItem(initOptions, 3,
                                 PyString_FromString("--no-save"))
                 );
 #else
-  if (PyTuple_SetItem(initOptions, 0, PyBytes_FromString("rpy2")) < 0) 
+  if (PyTuple_SetItem(initOptions, 0, PyBytes_FromString("rpy2")) < 0)
     return;
   if (PyTuple_SetItem(initOptions, 1, PyBytes_FromString("--quiet")) < 0)
     return;
 
 
   if (RPyExc_RuntimeError == NULL) {
-    RPyExc_RuntimeError = PyErr_NewException("rpy2.rinterface.RRuntimeError", 
+    RPyExc_RuntimeError = PyErr_NewException("rpy2.rinterface.RRuntimeError",
                                              NULL, NULL);
     if (RPyExc_RuntimeError == NULL)
       return;
   }
-  
+
   Py_INCREF(RPyExc_RuntimeError);
   PyModule_AddObject(m, "RRuntimeError", RPyExc_RuntimeError);
 
   if (PyModule_AddObject(m, "isInitialized", embeddedR_isInitialized) < 0)
     return;
 
-  globalEnv = (PySexpObject *)Sexp_new(&EnvironmentSexp_Type, 
+  globalEnv = (PySexpObject *)Sexp_new(&EnvironmentSexp_Type,
                                        Py_None, Py_None);
   RPY_SEXP(globalEnv) = R_EmptyEnv;
 
   baseNameSpaceEnv = (PySexpObject*)Sexp_new(&EnvironmentSexp_Type,
                                              Py_None, Py_None);
   RPY_SEXP(baseNameSpaceEnv) = R_EmptyEnv;
-  if (PyDict_SetItemString(d, "baseenv", 
+  if (PyDict_SetItemString(d, "baseenv",
                            (PyObject *)baseNameSpaceEnv) < 0)
   {
     Py_DECREF(baseNameSpaceEnv);
   emptyEnv = (PySexpObject*)Sexp_new(&EnvironmentSexp_Type,
                                      Py_None, Py_None);
   RPY_SEXP(emptyEnv) = R_EmptyEnv;
-  if (PyDict_SetItemString(d, "emptyenv", 
+  if (PyDict_SetItemString(d, "emptyenv",
                            (PyObject *)emptyEnv) < 0)
   {
     Py_DECREF(emptyEnv);
     Py_DECREF(rpy_R_NilValue);
     return;
   }
-  Py_DECREF(rpy_R_NilValue);  
+  Py_DECREF(rpy_R_NilValue);
 
   R_PyObject_type_tag = (PySexpObject*)Sexp_new(&VectorSexp_Type,
 						Py_None, Py_None);
-  if (PyDict_SetItemString(d, "python_type_tag", 
+  if (PyDict_SetItemString(d, "python_type_tag",
                            (PyObject *)R_PyObject_type_tag) < 0)
   {
     Py_DECREF(R_PyObject_type_tag);