Commits

Laurent Gautier  committed 48d6b89

Conditional 2to3=True if Python >= 3

  • Participants
  • Parent commits 4b2ec3a

Comments (0)

Files changed (3)

File C-interface

-From: lgautier
-
-diff -r 089949fdede1 rpy/rinterface/buffer.c
---- a/rpy/rinterface/buffer.c	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/buffer.c	Thu Aug 05 23:04:49 2010 +0200
-@@ -220,10 +220,12 @@
- }
- 
- static PyBufferProcs VectorSexp_as_buffer = {
-+#if (PY_VERSION_HEX < 0x03010000)
-         (readbufferproc)VectorSexp_getreadbuf,
-         (writebufferproc)VectorSexp_getwritebuf,
-         (segcountproc)VectorSexp_getsegcount,
- 	(charbufferproc)VectorSexp_getcharbuf,
-+#endif
- #if PY_VERSION_HEX >= 0x02060000
- 	(getbufferproc)VectorSexp_getbuffer,
- 	(releasebufferproc)0,
-diff -r 089949fdede1 rpy/rinterface/na_values.c
---- a/rpy/rinterface/na_values.c	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/na_values.c	Thu Aug 05 23:04:49 2010 +0200
-@@ -11,7 +11,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)  
-     repr = PyString_FromString("NA_integer_");
-+#else
-+    repr = PyUnicode_FromString("NA_integer_");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -22,7 +26,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)  
-     repr = PyString_FromString("NA");
-+#else
-+    repr = PyUnicode_FromString("NA");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -60,7 +68,9 @@
-   (binaryfunc)NA_binaryfunc, /* nb_add */
-   (binaryfunc)NA_binaryfunc, /* nb_subtract; */
-   (binaryfunc)NA_binaryfunc, /* nb_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (binaryfunc)NA_binaryfunc, /* nb_divide; */
-+#endif
-   (binaryfunc)NA_binaryfunc, /* nb_remainder; */
-   (binaryfunc)NA_binaryfunc, /* nb_divmod; */
-   (ternaryfunc)NA_ternaryfunc, /* nb_power; */
-@@ -74,17 +84,27 @@
-   (binaryfunc) NA_binaryfunc, /*  nb_and; */
-   (binaryfunc) NA_binaryfunc, /*  nb_xor; */
-   (binaryfunc) NA_binaryfunc, /* nb_or; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, //(coerce) NA_coerce, /* coercion nb_coerce;       -- Used by the coerce() function */
-+#endif
-   (unaryfunc) NA_unaryfunc, /* nb_int; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (unaryfunc) NA_unaryfunc, /* nb_long; */
-+#else
-+  NULL, /* reserved */
-+#endif
-   (unaryfunc) NA_unaryfunc, /* nb_float; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (unaryfunc) NA_unaryfunc, /* nb_oct; */
-   (unaryfunc) NA_unaryfunc, /* nb_hex; */
-+#endif
-   /* Added in release 2.0 */
-   0, /* nb_inplace_add; */
-   0, /* nb_inplace_subtract; */
-   0, /* nb_inplace_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_inplace_divide; */
-+#endif
-   0, /* nb_inplace_remainder; */
-   0, /* nb_inplace_power; */
-   0, /* nb_inplace_lshift; */
-@@ -111,8 +131,12 @@
- static PyTypeObject NAInteger_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.NAIntegerType",       /*tp_name*/
-         sizeof(PyObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -123,7 +147,7 @@
-         0,                      /*tp_setattr*/
-         0,                      /*tp_compare*/
-         NAInteger_repr,                      /*tp_repr*/
--        &NAInteger_NumberMethods,                      /*tp_as_number*/
-+        &NAInteger_NumberMethods,            /*tp_as_number*/
-         0,                      /*tp_as_sequence*/
-         0,                      /*tp_as_mapping*/
-         0,                      /*tp_hash*/
-@@ -132,7 +156,11 @@
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
-         0,                      /*tp_as_buffer*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
-+#else
-+        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-+#endif
-         NAInteger_Type_doc,                      /*tp_doc*/
-         0,                      /*tp_traverse*/
-         0,                      /*tp_clear*/
-@@ -225,7 +253,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)  
-     repr = PyString_FromString("NA");
-+#else
-+    repr = PyUnicode_FromString("NA");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -235,7 +267,9 @@
-   0, /* nb_add */
-   0, /* nb_subtract; */
-   0, /* nb_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_divide; */
-+#endif
-   0, /* nb_remainder; */
-   0, /* nb_divmod; */
-   0, /* nb_power; */
-@@ -249,17 +283,27 @@
-   (binaryfunc) NA_binaryfunc, /*  nb_and; */
-   (binaryfunc) NA_binaryfunc, /*  nb_xor; */
-   (binaryfunc) NA_binaryfunc, /* nb_or; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, //(coerce) NA_coerce, /* coercion nb_coerce;       -- Used by the coerce() function */
-+#endif
-   0, /* nb_int; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_long; */
-+#else
-+  NULL, /* reserved */
-+#endif
-   0, /* nb_float; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_oct; */
-   0, /* nb_hex; */
-+#endif
-   /* Added in release 2.0 */
-   0, /* nb_inplace_add; */
-   0, /* nb_inplace_subtract; */
-   0, /* nb_inplace_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_inplace_divide; */
-+#endif
-   0, /* nb_inplace_remainder; */
-   0, /* nb_inplace_power; */
-   0, /* nb_inplace_lshift; */
-@@ -281,8 +325,12 @@
- static PyTypeObject NALogical_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.NALogicalType",       /*tp_name*/
-         sizeof(PyObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -302,7 +350,11 @@
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
-         0,                      /*tp_as_buffer*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
-+#else
-+        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-+#endif
-         NALogical_Type_doc,                      /*tp_doc*/
-         0,                      /*tp_traverse*/
-         0,                      /*tp_clear*/
-@@ -349,7 +401,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)  
-     repr = PyString_FromString("NA_real_");
-+#else
-+    repr = PyUnicode_FromString("NA_real_");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -360,7 +416,9 @@
-   (binaryfunc)NA_binaryfunc, /* nb_add */
-   (binaryfunc)NA_binaryfunc, /* nb_subtract; */
-   (binaryfunc)NA_binaryfunc, /* nb_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (binaryfunc)NA_binaryfunc, /* nb_divide; */
-+#endif
-   (binaryfunc)NA_binaryfunc, /* nb_remainder; */
-   (binaryfunc)NA_binaryfunc, /* nb_divmod; */
-   (ternaryfunc)NA_ternaryfunc, /* nb_power; */
-@@ -374,17 +432,27 @@
-   0, /*  nb_and; */
-   0, /*  nb_xor; */
-   0, /* nb_or; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, //(coerce) NA_coerce, /* coercion nb_coerce;       -- Used by the coerce() function */
-+#endif
-   (unaryfunc) NA_unaryfunc, /* nb_int; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (unaryfunc) NA_unaryfunc, /* nb_long; */
-+#else
-+  NULL, /* reserved */
-+#endif
-   (unaryfunc) NA_unaryfunc, /* nb_float; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_oct; */
-   0, /* nb_hex; */
-+#endif
-   /* Added in release 2.0 */
-   0, /* nb_inplace_add; */
-   0, /* nb_inplace_subtract; */
-   0, /* nb_inplace_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_inplace_divide; */
-+#endif
-   0, /* nb_inplace_remainder; */
-   0, /* nb_inplace_power; */
-   0, /* nb_inplace_lshift; */
-@@ -407,8 +475,12 @@
- static PyTypeObject NAReal_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.NARealType",       /*tp_name*/
-         sizeof(PyObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -428,7 +500,11 @@
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
-         0,                      /*tp_as_buffer*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
-+#else
-+        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-+#endif
-         NAReal_Type_doc,                      /*tp_doc*/
-         0,                      /*tp_traverse*/
-         0,                      /*tp_clear*/
-@@ -460,7 +536,11 @@
- static PyObject*
- NACharacter_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
- {
-+#if (PY_VERSION_HEX < 0x03010000)
-   RPY_NA_TP_NEW("NACharacterType", PyString_Type, PyString_FromString, "")
-+#else
-+    RPY_NA_TP_NEW("NACharacterType", PyUnicode_Type, PyUnicode_FromString, "")
-+#endif
- }
- 
- static PyObject*
-@@ -475,7 +555,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)
-     repr = PyString_FromString("NA_character_");
-+#else
-+    repr = PyUnicode_FromString("NA_character_");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -485,8 +569,12 @@
- static PyTypeObject NACharacter_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.NACharacterType",       /*tp_name*/
-         sizeof(PyObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -506,7 +594,11 @@
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
-         0,                      /*tp_as_buffer*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
-+#else
-+        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-+#endif
-         NACharacter_Type_doc,                      /*tp_doc*/
-         0,                      /*tp_traverse*/
-         0,                      /*tp_clear*/
-@@ -517,7 +609,11 @@
-         0, //NAInteger_methods,           /*tp_methods*/
-         0,                      /*tp_members*/
-         0,                      /*tp_getset*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         &PyString_Type,             /*tp_base*/
-+#else
-+	&PyUnicode_Type,
-+#endif
-         0,                      /*tp_dict*/
-         0,                      /*tp_descr_get*/
-         0,                      /*tp_descr_set*/
-@@ -574,7 +670,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)
-     repr = PyString_FromString("NA_complex_");
-+#else
-+    repr = PyUnicode_FromString("NA_complex_");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -585,7 +685,9 @@
-   (binaryfunc)NA_binaryfunc, /* nb_add */
-   (binaryfunc)NA_binaryfunc, /* nb_subtract; */
-   (binaryfunc)NA_binaryfunc, /* nb_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (binaryfunc)NA_binaryfunc, /* nb_divide; */
-+#endif
-   (binaryfunc)NA_binaryfunc, /* nb_remainder; */
-   (binaryfunc)NA_binaryfunc, /* nb_divmod; */
-   (ternaryfunc)NA_ternaryfunc, /* nb_power; */
-@@ -599,17 +701,27 @@
-   0, /*  nb_and; */
-   0, /*  nb_xor; */
-   0, /* nb_or; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, //(coerce) NA_coerce, /* coercion nb_coerce;       -- Used by the coerce() function */
-+#endif
-   (unaryfunc) NA_unaryfunc, /* nb_int; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   (unaryfunc) NA_unaryfunc, /* nb_long; */
-+#else
-+  NULL, /* reserved */
-+#endif
-   (unaryfunc) NA_unaryfunc, /* nb_float; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_oct; */
-   0, /* nb_hex; */
-+#endif
-   /* Added in release 2.0 */
-   0, /* nb_inplace_add; */
-   0, /* nb_inplace_subtract; */
-   0, /* nb_inplace_multiply; */
-+#if (PY_VERSION_HEX < 0x03010000)
-   0, /* nb_inplace_divide; */
-+#endif
-   0, /* nb_inplace_remainder; */
-   0, /* nb_inplace_power; */
-   0, /* nb_inplace_lshift; */
-@@ -632,8 +744,12 @@
- static PyTypeObject NAComplex_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.NAComplexType",       /*tp_name*/
-         sizeof(PyObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -653,7 +769,11 @@
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
-         0,                      /*tp_as_buffer*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
-+#else
-+        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-+#endif
-         NAComplex_Type_doc,                      /*tp_doc*/
-         0,                      /*tp_traverse*/
-         0,                      /*tp_clear*/
-@@ -683,7 +803,11 @@
- "Missing argument (in a function call)."
- );
- 
-+#if (PY_VERSION_HEX < 0x03010000)
- staticforward PyTypeObject MissingArg_Type;
-+#else
-+static PyTypeObject MissingArg_Type;
-+#endif
- 
- static PyObject*
- MissingArgType_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-@@ -720,7 +844,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)
-     repr = PyString_FromString("rpy2.rinterface.MissingArg");
-+#else
-+    repr = PyUnicode_FromString("rpy2.rinterface.MissingArg");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -731,7 +859,11 @@
- {
-   static PyObject* repr = NULL;
-   if (repr == NULL) {
-+#if (PY_VERSION_HEX < 0x03010000)  
-     repr = PyString_FromString("MissingArg");
-+#else
-+    repr = PyUnicode_FromString("MissingArg");
-+#endif
-   }
-   Py_XINCREF(repr);
-   return repr;
-@@ -740,8 +872,12 @@
- static PyTypeObject MissingArg_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.MissingArgType",       /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -761,7 +897,11 @@
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
-         0,                      /*tp_as_buffer*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
-+#else
-+        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-+#endif
-         MissingArg_Type_doc,                      /*tp_doc*/
-         0,                      /*tp_traverse*/
-         0,                      /*tp_clear*/
-diff -r 089949fdede1 rpy/rinterface/rinterface.c
---- a/rpy/rinterface/rinterface.c	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/rinterface.c	Thu Aug 05 23:04:49 2010 +0200
-@@ -83,7 +83,11 @@
- 
- #define _RPY_RINTERFACE_MODULE_
- 
-+#if (PY_VERSION_HEX < 0x03010000)
- staticforward PyObject* EmbeddedR_unserialize(PyObject* self, PyObject* args);
-+#else
-+static PyObject* EmbeddedR_unserialize(PyObject* self, PyObject* args);
-+#endif
- 
- #include "rpy_rinterface.h"
- #include "embeddedr.h"
-@@ -473,7 +477,11 @@
-     return 0;
-   }
- 
--  char *input_str = PyString_AsString(result);
-+#if (PY_VERSION_HEX < 0x03010000)
-+  const char *input_str = PyString_AsString(result);
-+#else
-+  const char *input_str = PyBytes_AsString(result);
-+#endif
-   if (! input_str) {
-     Py_XDECREF(arglist);
-     RPY_GIL_RELEASE(is_threaded, gstate);
-@@ -571,7 +579,11 @@
-   PyGILState_STATE gstate;
-   RPY_GIL_ENSURE(is_threaded, gstate);
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-   arglist = Py_BuildValue("(s)", buf);
-+#else
-+  arglist = Py_BuildValue("(y)", buf);
-+#endif
-   if (! arglist) {
-     PyErr_NoMemory();
-   }
-@@ -602,8 +614,12 @@
-     RPY_GIL_RELEASE(is_threaded, gstate);
-     return 0;
-   }
--
-+#if (PY_VERSION_HEX < 0x03010000)
-   char *path_str = PyString_AsString(result);
-+#else
-+  const char *path_str = PyBytes_AsString(PyUnicode_AsLatin1String(result));
-+#endif
-+
-   if (! path_str) {
-     Py_DECREF(result);
-     PyErr_SetString(PyExc_TypeError, 
-@@ -670,25 +686,39 @@
-   PyObject *arglist;
-   PyObject *result;
- 
--  PyObject *py_wtitle = PyString_FromString(wtitle);
-   PyObject *py_del;
-   RPY_PY_FROM_RBOOL(py_del, del);
-+#if (PY_VERSION_HEX < 0x03010000)
-+  PyObject *py_wtitle = PyString_FromString(wtitle);
-   PyObject *py_pager = PyString_FromString(pager);
--
-+#else
-+   PyObject *py_wtitle = PyUnicode_FromString(wtitle);
-+   PyObject *py_pager = PyUnicode_FromString(pager);
-+#endif  
-   PyObject *py_fileheaders_tuple = PyTuple_New(nfile);
-   PyObject *py_fileheader;
-   int f_i;
-   for (f_i = 0; f_i < nfile; f_i++) {
-     py_fileheader = PyTuple_New(2);
-+#if (PY_VERSION_HEX < 0x03010000)
-     if (PyTuple_SetItem(py_fileheader, 0,
-                         PyString_FromString(headers[f_i])) != 0) {
-+#else
-+    if (PyTuple_SetItem(py_fileheader, 0,
-+                        PyUnicode_FromString(headers[f_i])) != 0) {
-+#endif
-       Py_DECREF(py_fileheaders_tuple);
-       /*FIXME: decref other PyObject arguments */
-       RPY_GIL_RELEASE(is_threaded, gstate);
-       return 0;
-     }
-+#if (PY_VERSION_HEX < 0x03010000)
-     if (PyTuple_SetItem(py_fileheader, 1,
-                         PyString_FromString(file[f_i])) != 0) {
-+#else
-+    if (PyTuple_SetItem(py_fileheader, 1,
-+                        PyUnicode_FromString(file[f_i])) != 0) {
-+#endif
-       Py_DECREF(py_fileheaders_tuple);
-       /*FIXME: decref other PyObject arguments */
-       RPY_GIL_RELEASE(is_threaded, gstate);
-@@ -960,19 +990,27 @@
-   static int status;
-   
-   if (rpy_has_status(RPY_R_INITIALIZED)) {
-+#if (PY_VERSION_HEX < 0x03010000)
-     return PyInt_FromLong(status);
-+#else
-+    return PyLong_FromLong(status);
-+#endif
- /*     PyErr_Format(PyExc_RuntimeError, "R can only be initialized once."); */
- /*     return NULL; */
-   }
- 
-   const Py_ssize_t n_args = PySequence_Size(initOptions);
--  char *options[n_args];
-+  const char *options[n_args];
- 
-   PyObject *opt_string;
-   Py_ssize_t ii;
-   for (ii = 0; ii < n_args; ii++) {
-     opt_string = PyTuple_GetItem(initOptions, ii);
-+#if (PY_VERSION_HEX < 0x03010000)
-     options[ii] = PyString_AsString(opt_string);
-+#else
-+    options[ii] = PyBytes_AsString(opt_string);
-+#endif
-   }
- 
- 
-@@ -1077,8 +1115,11 @@
- 
-   errMessage_SEXP = findVar(install("geterrmessage"), 
-                             R_BaseNamespace);
--
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *res = PyInt_FromLong(status);
-+#else
-+  PyObject *res = PyLong_FromLong(status);
-+#endif
- 
- #ifdef RPY_VERBOSE
-   printf("R initialized - status: %i\n", status);
-@@ -1311,7 +1352,7 @@
- 
-   /* named args */
-   PyObject *argValue, *argName;
--  char *argNameString;
-+  const char *argNameString;
-   unsigned int addArgName;
-   Py_ssize_t item_length;
-   /* Loop through the elements in the sequence "args"
-@@ -1348,7 +1389,11 @@
-     argName = PyTuple_GET_ITEM(tmp_obj, 0);
-     if (argName == Py_None) {
-       addArgName = 0;
-+#if (PY_VERSION_HEX < 0x03010000)
-     } else if (PyString_Check(argName)) {
-+#else
-+    } else if (PyUnicode_Check(argName)) {
-+#endif
-       addArgName = 1;
-     } else {
-       PyErr_SetString(PyExc_TypeError, "All keywords must be strings (or None).");
-@@ -1389,7 +1434,11 @@
-     */
-     SETCAR(c_R, tmp_R);
-     if (addArgName) {
-+#if (PY_VERSION_HEX < 0x03010000)
-       argNameString = PyString_AsString(argName);
-+#else
-+      argNameString = PyBytes_AsString(PyUnicode_AsLatin1String(argName));
-+#endif
-       SET_TAG(c_R, install(argNameString));
-     }
-     c_R = CDR(c_R);
-@@ -1565,8 +1614,12 @@
- static PyTypeObject ClosureSexp_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.SexpClosure",       /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -1665,8 +1718,12 @@
- static PyTypeObject VectorSexp_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.SexpVector",        /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -1685,7 +1742,7 @@
-         0,              /*tp_str*/
-         0,                      /*tp_getattro*/
-         0,                      /*tp_setattro*/
--#if PY_VERSION_HEX >= 0x02060000
-+#if PY_VERSION_HEX >= 0x02060000 & PY_VERSION_HEX < 0x03010000
-         &VectorSexp_as_buffer,                      /*tp_as_buffer*/
-         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER,  /*tp_flags*/
- #else
-@@ -1927,12 +1984,20 @@
-   const char *name;
-   SEXP res_R = NULL;
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-   if (!PyString_Check(key)) {
-+#else
-+    if (!PyUnicode_Check(key)) {
-+#endif
-     PyErr_Format(PyExc_ValueError, "Keys must be string objects.");
-     return NULL;
-   }
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-   name = PyString_AsString(key);
-+#else
-+  name = PyBytes_AsString(PyUnicode_AsLatin1String(key));
-+#endif
- 
-   if (strlen(name) == 0) {
-     PyErr_Format(PyExc_KeyError, "%s", name);
-@@ -1966,9 +2031,13 @@
- static int
- EnvironmentSexp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
- {
--  char *name;
--
-+  const char *name;
-+
-+  #if (PY_VERSION_HEX < 0x03010000)
-   if (!PyString_Check(key)) {
-+#else
-+ if (!PyUnicode_Check(key)) {
-+#endif
-     PyErr_Format(PyExc_ValueError, "Keys must be string objects.");
-     return -1;
-   }
-@@ -1986,7 +2055,11 @@
-     return -1;
-   }
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-   name = PyString_AsString(key);
-+#else
-+  name = PyBytes_AsString(PyUnicode_AsLatin1String(key));
-+#endif
- 
-   if (rpy_has_status(RPY_R_BUSY)) {
-     PyErr_Format(PyExc_RuntimeError, "Concurrent access to R is not allowed.");
-@@ -2095,8 +2168,12 @@
- static PyTypeObject EnvironmentSexp_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.SexpEnvironment",   /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -2188,8 +2265,12 @@
- static PyTypeObject S4Sexp_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.SexpS4",    /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -2241,8 +2322,12 @@
- static PyTypeObject LangSexp_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.SexpLang",  /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -2414,9 +2499,17 @@
-     integer_ptr = INTEGER(sexp);
-     for (i = 0; i < length; ++i) {
-       item = PySequence_Fast_GET_ITEM(seq_object, i);
-+#if (PY_VERSION_HEX < 0x03010000)
-       item_tmp = PyNumber_Int(item);
-+#else
-+      item_tmp = PyNumber_Long(item);
-+#endif
-       if (item_tmp && (item != NAInteger_New(0))) {
-+#if (PY_VERSION_HEX < 0x03010000)
- 	  long l = PyInt_AS_LONG(item_tmp);
-+#else
-+	  long l = PyLong_AS_LONG(item_tmp);
-+#endif
- 	  integer_ptr[i] = RPY_RINT_FROM_LONG(l);
-       } else {
-         PyErr_Clear();
-@@ -2454,7 +2547,11 @@
-       if (item == na) {
-         str_R = NA_STRING;
-       } else if((item_tmp = PyObject_Str(item))) {
-+#if (PY_VERSION_HEX < 0x03010000)
-         str_R = mkChar(PyString_AS_STRING(item_tmp));
-+#else
-+	str_R = mkChar(PyBytes_AsString(PyUnicode_AsLatin1String(item_tmp)));
-+#endif
-         if (!str_R) {
-             PyErr_NoMemory();
-             UNPROTECT(1);
-@@ -2463,8 +2560,13 @@
-             break;
-         }
-         Py_DECREF(item_tmp);
-+#if (PY_VERSION_HEX < 0x03010000)
-       } else if ((item_tmp = PyObject_Unicode(item))) {
-         str_R = mkChar(PyUnicode_AS_DATA(item));
-+#else
-+      } else if ((item_tmp = PyObject_Str(item))) {
-+	str_R = mkChar(PyBytes_AsString(PyUnicode_AsLatin1String(item)));
-+#endif
-         if (!str_R) {
-           PyErr_NoMemory();
-           UNPROTECT(1);
-@@ -2494,9 +2596,17 @@
-           tmp = allocVector(REALSXP, 1);
-           REAL(tmp)[0] = PyFloat_AS_DOUBLE(item);
-           SET_ELEMENT(sexp, i, tmp);
--        } else if (PyInt_Check(item)) {                         
--          tmp = allocVector(INTSXP, 1);                         
-+#if (PY_VERSION_HEX < 0x03010000)
-+        } else if (PyInt_Check(item)) {
-+#else
-+	} else if (PyLong_Check(item)) {
-+#endif
-+          tmp = allocVector(INTSXP, 1);
-+#if (PY_VERSION_HEX < 0x03010000)                         
-           INTEGER_POINTER(tmp)[0] = (int)PyInt_AS_LONG(item);
-+#else
-+	  INTEGER_POINTER(tmp)[0] = (int)PyLong_AS_LONG(item);
-+#endif
-           SET_ELEMENT(sexp, i, tmp);
-         } else if (PyLong_Check(item)) {
-           tmp = allocVector(INTSXP, 1);
-@@ -2508,11 +2618,23 @@
-           SET_ELEMENT(sexp, i, tmp);
-         } else if (PyBool_Check(item)) {
-           tmp = allocVector(LGLSXP, 1);
-+#if (PY_VERSION_HEX < 0x03010000)
-           LOGICAL_POINTER(tmp)[0] = (int)PyInt_AS_LONG(item);
-+#else
-+	  LOGICAL_POINTER(tmp)[0] = (int)PyLong_AS_LONG(item);
-+#endif
-           SET_ELEMENT(sexp, i, tmp);
-+#if (PY_VERSION_HEX < 0x03010000)
-         } else if (PyString_Check(item)) {
-+#else
-+	} else if (PyUnicode_Check(item)) {
-+#endif
-           PROTECT(tmp = NEW_CHARACTER(1));
-+#if (PY_VERSION_HEX < 0x03010000)
-           tmp2 = mkChar(PyString_AS_STRING(item));
-+#else
-+	  tmp2 = mkChar(PyBytes_AsString(PyUnicode_AsLatin1String(item)));
-+#endif
-           if (!tmp2) {
-             PyErr_NoMemory();
-             sexp = NULL;
-@@ -2617,7 +2739,11 @@
-     return NULL;
-   }
-   /* FIXME: store python strings when initializing validSexpType instead */
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *res = PyString_FromString(sexp_type);
-+#else
-+  PyObject *res = PyUnicode_FromString(sexp_type);
-+#endif
-   return res;
- 
- }
-@@ -2752,7 +2878,11 @@
-     PyErr_Fetch(&exctype, &excvalue, &exctraceback);
-     excstr = PyObject_Str(excvalue);
-     if (excstr) {
-+#if (PY_VERSION_HEX < 0x03010000)
-       error(PyString_AS_STRING(excstr));
-+#else
-+      error(PyBytes_AsString(PyUnicode_AsLatin1String(excstr)));
-+#endif
-       Py_DECREF(excstr);
-     } 
-     else {
-@@ -2796,13 +2926,29 @@
- #define PYASSERT_ZERO(code) \
-   if ((code) != 0) {return ; } \
- 
--
-+#if (PY_VERSION_HEX < 0x03010000)
-+#else
-+static struct PyModuleDef rinterfacemodule = {
-+   PyModuleDef_HEAD_INIT,
-+   "rinterface",           /* name of module */
-+   module_doc,               /* module documentation, may be NULL */
-+   -1,                     /* size of per-interpreter state */
-+   EmbeddedR_methods       /* method table */
-+ };
-+#endif
-+
-+/* GS: Necessary? */
-+/* LG: might be for win32/win64 (I can't remember)*/
- #ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
- #define PyMODINIT_FUNC void
- #endif
- 
- PyMODINIT_FUNC
-+#if (PY_VERSION_HEX < 0x03010000)
- initrinterface(void)
-+#else
-+PyInit_rinterface(void)
-+#endif
- {
-   /* PyMODINIT_FUNC */
-   /* RPY_RINTERFACE_INIT(void) */
-@@ -2812,49 +2958,53 @@
-          * object; doing it here is required for portability to Windows 
-          * without requiring C++. */
-   if (PyType_Ready(&Sexp_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&ClosureSexp_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&VectorSexp_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&EnvironmentSexp_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&S4Sexp_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&LangSexp_Type) < 0)
--    return;
-+    return NULL;
- 
-   /* Required because NA types inherit from basic Python types */
-   if (PyType_Ready(&PyBool_Type) < 0) {
--    return;
-+    return NULL;
-   }
-   if (PyType_Ready(&PyLong_Type) < 0) {
--    return;
-+    return NULL;
-   }
- 
-   /* NA types */
-   if (PyType_Ready(&NAInteger_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&NALogical_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&NAReal_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&NAComplex_Type) < 0)
--    return;
-+    return NULL;
-   if (PyType_Ready(&NACharacter_Type) < 0)
--    return;
-+    return NULL;
- 
-   PyObject *m, *d;
-+#if (PY_VERSION_HEX < 0x03010000)
-   m = Py_InitModule3("rinterface", EmbeddedR_methods, module_doc);
-+#else
-+  m = PyModule_Create(&rinterfacemodule);
-+#endif
-   if (m == NULL)
--    return;
-+    return NULL;
-   d = PyModule_GetDict(m);
- 
-   /* Add SXP types */
-   validSexpType = calloc(RPY_MAX_VALIDSEXTYPE, sizeof(char *));
-   if (! validSexpType) {
-     PyErr_NoMemory();
--    return;
-+    return NULL;
-   }
- 
-   ADD_SEXP_CONSTANT(m, NILSXP);
-@@ -2894,6 +3044,7 @@
- 
-   initOptions = PyTuple_New(4);
- 
-+#if (PY_VERSION_HEX < 0x03010000)  
-   PYASSERT_ZERO(
-                 PyTuple_SetItem(initOptions, 0, 
-                                 PyString_FromString("rpy2"))
-@@ -2910,6 +3061,16 @@
-                 PyTuple_SetItem(initOptions, 3, 
-                                 PyString_FromString("--no-save"))
-                 );
-+#else
-+  if (PyTuple_SetItem(initOptions, 0, PyBytes_FromString("rpy2")) < 0) 
-+    return NULL;
-+  if (PyTuple_SetItem(initOptions, 1, PyBytes_FromString("--quiet")) < 0)
-+    return NULL;
-+  if (PyTuple_SetItem(initOptions, 2, PyBytes_FromString("--vanilla")) < 0)
-+    return NULL;
-+  if (PyTuple_SetItem(initOptions, 3, PyBytes_FromString("--no-save")) < 0)
-+    return NULL;
-+#endif
- 
-   /* Add an extra ref. It should remain impossible to delete it */
-   Py_INCREF(initOptions);
-@@ -2936,7 +3097,7 @@
- 
-   /* Missing */
-   if (PyType_Ready(&MissingArg_Type) < 0)
--    return;
-+    return NULL;
-   PyModule_AddObject(m, "MissingArgType", (PyObject *)&MissingArg_Type);
-   PyModule_AddObject(m, "MissingArg", MissingArg_Type_New(1));
- 
-@@ -2944,7 +3105,7 @@
-     RPyExc_RuntimeError = PyErr_NewException("rpy2.rinterface.RRuntimeError", 
-                                              NULL, NULL);
-     if (RPyExc_RuntimeError == NULL)
--      return;
-+      return NULL;
-   }
-   
-   Py_INCREF(RPyExc_RuntimeError);
-@@ -2954,7 +3115,7 @@
-   Py_INCREF(Py_False);
- 
-   if (PyModule_AddObject(m, "isInitialized", embeddedR_isInitialized) < 0)
--    return;
-+    return NULL;
- 
-   globalEnv = (PySexpObject *)Sexp_new(&EnvironmentSexp_Type, 
-                                        Py_None, Py_None);
-@@ -2963,7 +3124,7 @@
-   if (PyDict_SetItemString(d, "globalenv", (PyObject *)globalEnv) < 0)
-   {
-     Py_DECREF(globalEnv);
--    return;
-+    return NULL;
-   }
-   Py_DECREF(globalEnv);
- 
-@@ -2974,7 +3135,7 @@
-                            (PyObject *)baseNameSpaceEnv) < 0)
-   {
-     Py_DECREF(baseNameSpaceEnv);
--    return;
-+    return NULL;
-   }
-   Py_DECREF(baseNameSpaceEnv);
- 
-@@ -2985,7 +3146,7 @@
-                            (PyObject *)emptyEnv) < 0)
-   {
-     Py_DECREF(emptyEnv);
--    return;
-+    return NULL;
-   }
-   Py_DECREF(emptyEnv);
- 
-@@ -2994,10 +3155,10 @@
-   if (PyDict_SetItemString(d, "R_NilValue", (PyObject *)rpy_R_NilValue) < 0)
-   {
-     Py_DECREF(rpy_R_NilValue);
--    return;
-+    return NULL;
-   }
-   Py_DECREF(rpy_R_NilValue);  
- 
-   rinterface_unserialize = PyDict_GetItemString(d, "unserialize");
--
-+  return m;
- }
-diff -r 089949fdede1 rpy/rinterface/rpy_device.c
---- a/rpy/rinterface/rpy_device.c	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/rpy_device.c	Thu Aug 05 23:04:49 2010 +0200
-@@ -211,7 +211,11 @@
- 
-   /* FIXME give the callback access to gc */
-   PyObject *self = (PyObject *)dd->deviceSpecific;
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *py_str = PyString_FromString(str);
-+#else
-+  PyObject *py_str = PyUnicode_FromString(str);
-+#endif
-   result = PyObject_CallMethodObjArgs(self, GrDev_strwidth_name, py_str);
- 
-   rpy_printandclear_error();
-@@ -245,7 +249,11 @@
-   /* FIXME optimize ? */
-   PyObject *py_x = PyFloat_FromDouble(x);
-   PyObject *py_y = PyFloat_FromDouble(y);
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *py_str = PyString_FromString(str);
-+#else
-+  PyObject *py_str = PyUnicode_FromString(str);
-+#endif
-   PyObject *py_rot = PyFloat_FromDouble(rot);
-   PyObject *py_hadj = PyFloat_FromDouble(hadj);
-   /* FIXME pass gc ? */
-@@ -503,7 +511,11 @@
-   /* PyOS_setsig(SIGINT, python_sighandler); */
- 
-   PyObject *self = (PyObject *)dd->deviceSpecific;
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *py_mode = PyInt_FromLong((long)mode);
-+#else
-+  PyObject *py_mode = PyLong_FromLong((long)mode);
-+#endif
-   result = PyObject_CallMethodObjArgs(self, GrDev_mode_name, 
-                                       py_mode,
-                                       NULL);
-@@ -536,7 +548,11 @@
- #ifdef RPY_DEBUG_GRDEV
-   printf("FIXME: MetricInfo.\n");
- #endif
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *py_c = PyInt_FromLong((long)c);
-+#else
-+  PyObject *py_c = PyLong_FromLong((long)c);
-+#endif
-   PyObject *py_ascent = PyFloat_FromDouble(*ascent);
-   PyObject *py_descent = PyFloat_FromDouble(*descent);
-   PyObject *py_width = PyFloat_FromDouble(*width);
-@@ -589,7 +605,11 @@
- #ifdef RPY_DEBUG_GRDEV
-   printf("FIXME: MetricInfo.\n");
- #endif
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyObject *py_prompt = PyString_FromString(prompt);
-+#else
-+  PyObject *py_prompt = PyUnicode_FromString(prompt);
-+#endif
-   /* FIXME pass gc ? */
-   result = PyObject_CallMethodObjArgs(self, GrDev_getevent_name,
-                                       py_prompt,
-@@ -703,7 +723,11 @@
- #endif
-   R_ReleaseObject(self->devnum);
-   PyMem_Free(((PyGrDevObject *)self)->grdev);
-+#if (PY_VERSION_HEX < 0x03010000)
-   self->ob_type->tp_free((PyObject*)self);
-+#else
-+  Py_TYPE(self)->tp_free((PyObject*)self);
-+#endif
- #ifdef RPY_DEBUG_GRDEV
-   printf("  done.\n");
- #endif
-@@ -713,10 +737,17 @@
- GrDev_repr(PyObject *self)
- {
-   pDevDesc devdesc = ((PyGrDevObject *)self)->grdev;
-+#if (PY_VERSION_HEX < 0x03010000)
-   return PyString_FromFormat("<%s - Python:\%p / R graphical device:\%p>",
-                              self->ob_type->tp_name,
-                              self,
-                              devdesc);
-+#else
-+  return PyUnicode_FromFormat("<%s - Python:\%p / R graphical device:\%p>",
-+			      Py_TYPE(self)->tp_name,
-+			      self,
-+			      devdesc);
-+#endif
- }
- 
- static PyMethodDef GrDev_methods[] = {
-@@ -1150,7 +1181,11 @@
-     Py_INCREF(Py_None);
-     res = Py_None;
-   } else {
-+#if (PY_VERSION_HEX < 0x03010000)
-     res = PyInt_FromLong((long)RPY_DEV_NUM(self));
-+#else
-+    res = PyLong_FromLong((long)RPY_DEV_NUM(self));
-+#endif
-   }
-   return res;
- 
-@@ -1248,9 +1283,11 @@
- 
-   configureDevice(dd, self);
-   pGEDevDesc gdd = GEcreateDevDesc(dd);
--
-+#if (PY_VERSION_HEX < 0x03010000)
-   GEaddDevice2(gdd, self->ob_type->tp_name);
--
-+#else
-+  GEaddDevice2(gdd, Py_TYPE(self)->tp_name);
-+#endif
-   ((PyGrDevObject *)self)->devnum = ScalarInteger(ndevNumber(dd) + 1);
-   R_PreserveObject(((PyGrDevObject *)self)->devnum);
-   /* FIXME: protect device number ? */
-@@ -1268,8 +1305,12 @@
- static PyTypeObject GrDev_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.GraphicalDevice",   /*tp_name*/
-         sizeof(PyGrDevObject),  /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-@@ -1278,7 +1319,11 @@
-         0,                      /*tp_print*/
-         0,                      /*tp_getattr*/
-         0,                      /*tp_setattr*/
-+#if (PY_VERSION_HEX < 0x03010000)
-         0,                      /*tp_compare*/
-+#else
-+        0,                      /*tp_reserved*/
-+#endif
-         GrDev_repr,             /*tp_repr*/
-         0,                      /*tp_as_number*/
-         0,                      /*tp_as_sequence*/
-@@ -1312,6 +1357,7 @@
-         0,                      /*tp_is_gc*/
- };
- 
-+/* Additional methods for RpyDevice */
- static PyMethodDef rpydevice_methods[] = {
-   {NULL,                NULL}           /* sentinel */
- };
-@@ -1322,10 +1368,25 @@
- #define PyMODINIT_FUNC void
- #endif
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-+#else
-+static struct PyModuleDef rpydevicemodule = {
-+   PyModuleDef_HEAD_INIT,
-+   "rpy_device",           /* name of module */
-+   module_doc,             /* module documentation, may be NULL */
-+   -1,                     /* size of per-interpreter state of the module */
-+   NULL, NULL, NULL, NULL, NULL
-+ };
-+#endif
-+
- PyMODINIT_FUNC
-+#if (PY_VERSION_HEX < 0x03010000)
- initrpy_device(void)
-+#else
-+PyInit_rpy_device(void)
-+#endif
- {
--
-+#if (PY_VERSION_HEX < 0x03010000)
-   GrDev_close_name = PyString_FromString("close");
-   GrDev_activate_name = PyString_FromString("activate");
-   GrDev_deactivate_name = PyString_FromString("deactivate");
-@@ -1343,15 +1404,41 @@
-   GrDev_mode_name = PyString_FromString("mode");
-   GrDev_metricinfo_name = PyString_FromString("metricinfo");
-   GrDev_getevent_name = PyString_FromString("getevent");
--
-+#else
-+  GrDev_close_name = PyUnicode_FromString("close");
-+  GrDev_activate_name = PyUnicode_FromString("activate");
-+  GrDev_deactivate_name = PyUnicode_FromString("deactivate");
-+  GrDev_size_name = PyUnicode_FromString("size");
-+  GrDev_newpage_name = PyUnicode_FromString("newpage");
-+  GrDev_clip_name = PyUnicode_FromString("clip");
-+  GrDev_strwidth_name = PyUnicode_FromString("strwidth");
-+  GrDev_text_name = PyUnicode_FromString("text");
-+  GrDev_rect_name = PyUnicode_FromString("rect");
-+  GrDev_circle_name = PyUnicode_FromString("circle");
-+  GrDev_line_name = PyUnicode_FromString("line");
-+  GrDev_polyline_name = PyUnicode_FromString("polyline");
-+  GrDev_polygon_name = PyUnicode_FromString("polygon");
-+  GrDev_locator_name = PyUnicode_FromString("locator");
-+  GrDev_mode_name = PyUnicode_FromString("mode");
-+  GrDev_metricinfo_name = PyUnicode_FromString("metricinfo");
-+  GrDev_getevent_name = PyUnicode_FromString("getevent");
-+#endif
-   if (PyType_Ready(&GrDev_Type) < 0)
--    return;
-+    return NULL;
-   
-   PyObject *m, *d;
-+#if (PY_VERSION_HEX < 0x03010000)
-   m = Py_InitModule3("rpy_device", rpydevice_methods, module_doc);
-+#else
-+  m = PyModule_Create(&rpydevicemodule);
-+#endif
-   if (m == NULL)
--    return;
-+    return NULL;
-   d = PyModule_GetDict(m);
--
-+#if (PY_VERSION_HEX < 0x03010000)
-   PyModule_AddObject(m, "GraphicalDevice", (PyObject *)&GrDev_Type);  
-+#else
-+  PyModule_AddObject(m, "GraphicalDevice", (PyObject *)&GrDev_Type);
-+  return m;
-+#endif
- }
-diff -r 089949fdede1 rpy/rinterface/rpy_rinterface.h
---- a/rpy/rinterface/rpy_rinterface.h	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/rpy_rinterface.h	Thu Aug 05 23:04:49 2010 +0200
-@@ -76,7 +76,19 @@
-     PyGILState_Release(gstate);                 \
-   }
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-+#define RPY_PYSCALAR_TESTINT PyInt_Check
-+#else
-+#define RPY_PYSCALAR_TESTINT PyLong_Check
-+#endif
- 
-+#if (PY_VERSION_HEX < 0x03010000)
-+#define RPY_PYSCALAR_SETINT(py_obj)\
-+  ((int)(PyInt_AS_LONG(py_obj)));
-+#else
-+#define RPY_PYSCALAR_SETINT(py_obj)\
-+  RPY_RINT_FROM_LONG(PyLong_AsLong(py_obj));
-+#endif
- 
- #define RPY_PYSCALAR_RVECTOR(py_obj, sexp)                              \
-   sexp = NULL;                                                          \
-@@ -104,9 +116,9 @@
-     LOGICAL_POINTER(sexp)[0] = py_obj == Py_True ? TRUE : FALSE;        \
-     PROTECT(sexp);                                                      \
-     protect_count++;                                                    \
--  } else if (PyInt_Check(py_obj)) {                                     \
-+  } else if (RPY_PYSCALAR_TESTINT(py_obj)) {				\
-     sexp = allocVector(INTSXP, 1);                                      \
--    INTEGER_POINTER(sexp)[0] = (int)(PyInt_AS_LONG(py_obj));            \
-+    INTEGER_POINTER(sexp)[0] = RPY_PYSCALAR_SETINT(py_obj);		\
-     PROTECT(sexp);                                                      \
-     protect_count++;                                                    \
-   } else if (PyLong_Check(py_obj)) {                                    \
-diff -r 089949fdede1 rpy/rinterface/sequence.c
---- a/rpy/rinterface/sequence.c	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/sequence.c	Thu Aug 05 23:04:49 2010 +0200
-@@ -53,7 +53,13 @@
-   len_R = GET_LENGTH(*sexp);
-   
-   if (i < 0) {
-+    /*FIXME: check that unit tests are covering this properly */
-+    /*FIXME: is this valid for Python < 3 ? */
-+#if (PY_VERSION_HEX < 0x03010000)
-     i = len_R - i;
-+#else
-+    i = len_R + i;
-+#endif
-   }
- 
-   /* On 64bits, Python is apparently able to use larger integer
-@@ -97,7 +103,11 @@
-       if (vi == NA_INTEGER) {
-         res = NAInteger_New(1);
-       } else {
-+#if (PY_VERSION_HEX < 0x03010000)
-         res = PyInt_FromLong((long)vi);
-+#else
-+	res = PyLong_FromLong((long)vi);
-+#endif
-       }
-       break;
-     case LGLSXP:
-@@ -117,7 +127,11 @@
-         res = NACharacter_New(1);
-       } else {
-         vs = translateChar(STRING_ELT(*sexp, i_R));
-+#if (PY_VERSION_HEX < 0x03010000)
-         res = PyString_FromString(vs);
-+#else
-+	res = PyUnicode_FromString(vs);
-+#endif
-       }
-       break;
- /*     case CHARSXP: */
-@@ -173,13 +187,16 @@
- 
- 
-   len_R = GET_LENGTH(*sexp);
--  
-+
-+  /*FIXME: is this valid for Python < 3 ?*/  
-+#if (PY_VERSION_HEX < 0x03010000)
-   if (ilow < 0) {
-     ilow = (R_len_t)(len_R - ilow) + 1;
-   }
-   if (ihigh < 0) {
-     ihigh = (R_len_t)(len_R - ihigh) + 1;
-   }
-+#endif
- 
-   /* On 64bits, Python is apparently able to use larger integer
-    * than R for indexing. */
-@@ -301,7 +318,12 @@
-   len_R = GET_LENGTH(*sexp);
-   
-   if (i < 0) {
-+    /* FIXME: Is this valid for Python < 3 ?*/
-+#if (PY_VERSION_HEX < 0x03010000)
-     i = len_R - i;
-+#else
-+    i = len_R + i;
-+#endif
-   }
- 
-   if (i >= len_R) {
-@@ -400,13 +422,16 @@
- 
-   SEXP *sexp = &(RPY_SEXP((PySexpObject *)object));
-   len_R = GET_LENGTH(*sexp);
--  
-+
-+  /* FIXME: Is this valid for Python < 3 ? */
-+#if (PY_VERSION_HEX < 0x03010000)  
-   if (ilow < 0) {
-     ilow = (R_len_t)(len_R - ilow) + 1;
-   }
-   if (ihigh < 0) {
-     ihigh = (R_len_t)(len_R - ihigh) + 1;
-   }
-+#endif
- 
-   if (! sexp) {
-     PyErr_Format(PyExc_ValueError, "NULL SEXP.");
-diff -r 089949fdede1 rpy/rinterface/sexp.c
---- a/rpy/rinterface/sexp.c	Sun Jun 27 09:47:32 2010 +0200
-+++ b/rpy/rinterface/sexp.c	Thu Aug 05 23:04:49 2010 +0200
-@@ -48,8 +48,11 @@
- Sexp_dealloc(PySexpObject *self)
- {
-   Sexp_clear(self);
--  self->ob_type->tp_free((PyObject*)self);
--
-+#if (PY_VERSION_HEX < 0x03010000)
-+  (self->ob_type->tp_free)((PyObject*)self);
-+#else
-+  (Py_TYPE(self)->tp_free)((PyObject *)self);
-+#endif
-   /* PyObject_Del(self); */
- }
- 
-@@ -64,10 +67,17 @@
-    *  return NULL;
-    *}
-    */
-+#if (PY_VERSION_HEX < 0x03010000)
-   return PyString_FromFormat("<%s - Python:\%p / R:\%p>",
-                              self->ob_type->tp_name,
-                              self,
--                             sexp);
-+                             sexp);  
-+#else
-+  return PyUnicode_FromFormat("<%s - Python:\%p / R:\%p>",
-+			      self->ob_type->tp_name,
-+			      self,
-+			      sexp);
-+#endif
- }
- 
- 
-@@ -78,9 +88,13 @@
-   SEXP sexp = RPY_SEXP(pso);
-   if (! sexp) {
-     PyErr_Format(PyExc_ValueError, "NULL SEXP.");
--    return NULL;;
-+    return NULL;
-   }
-+#if (PY_VERSION_HEX < 0x03010000)
-   return PyInt_FromLong((long)TYPEOF(sexp));
-+#else
-+  return PyLong_FromLong((long)TYPEOF(sexp));
-+#endif
- }
- PyDoc_STRVAR(Sexp_typeof_doc,
-              "R internal SEXPREC type.");
-@@ -92,14 +106,21 @@
-   SEXP sexp = RPY_SEXP(((PySexpObject*)self));
-   if (! sexp) {
-     PyErr_Format(PyExc_ValueError, "NULL SEXP.");
--    return NULL;;
-+    return NULL;
-   }
-+#if (PY_VERSION_HEX < 0x03010000)
-   if (! PyString_Check(name)) {
-+#else
-+    if (! PyUnicode_Check(name)) {
-+#endif
-     PyErr_SetString(PyExc_TypeError, "The name must be a string.");
-     return NULL;
-   }
-+#if (PY_VERSION_HEX < 0x03010000)
-   char *name_str = PyString_AS_STRING(name);
--
-+#else
-+  char *name_str = PyBytes_AsString(PyUnicode_AsLatin1String(name));
-+#endif
-   if (! R_has_slot(sexp, install(name_str))) {
-     PyErr_SetString(PyExc_LookupError, "The object has no such attribute.");
-     return NULL;
-@@ -165,7 +186,11 @@
-     return NULL;;
-   }
-   unsigned int res = NAMED(sexp);
-+#if (PY_VERSION_HEX < 0x03010000)
-   return PyInt_FromLong((long)res);
-+#else
-+  return PyLong_FromLong((long)res);
-+#endif
- }
- PyDoc_STRVAR(Sexp_named_doc,
- "Integer code for the R object reference-pseudo counting.\n\
-@@ -243,10 +268,13 @@
- 
-   if (! RPY_SEXP(rpyobj)) {
-     PyErr_Format(PyExc_ValueError, "NULL SEXP.");
--    return NULL;;
-+    return NULL;
-   }
--  
-+#if (PY_VERSION_HEX < 0x03010000)  
-   PyObject *res = PyInt_FromLong((long)(rpyobj->sObj->count));
-+#else
-+  PyObject *res = PyLong_FromLong((long)(rpyobj->sObj->count));
-+#endif
-   return res;
- }
- PyDoc_STRVAR(Sexp_refcount_doc,
-@@ -325,8 +353,13 @@
-           /* res = PyByteArray_FromStringAndSize(sexp_ser, len); */
- 
-   /*FIXME: is this working on 64bit archs ? */
-+#if (PY_VERSION_HEX < 0x03010000)  
-   res_string = PyString_FromStringAndSize((void *)RAW_POINTER(sexp_ser), 
-                                           (Py_ssize_t)LENGTH(sexp_ser));
-+#else
-+  res_string = PyBytes_FromStringAndSize((void *)RAW_POINTER(sexp_ser), 
-+					 (Py_ssize_t)LENGTH(sexp_ser));
-+#endif
-   UNPROTECT(1);
-   return res_string;
- }
-@@ -455,8 +488,13 @@
-    Sexp_do_slot_assign_doc},
-   {"rsame", (PyCFunction)Sexp_rsame, METH_O,
-    Sexp_rsame_doc},
-+#if (PY_VERSION_HEX < 0x03010000)  
-   {"__deepcopy__", (PyCFunction)Sexp_duplicate, METH_KEYWORDS,
-    Sexp_duplicate_doc},
-+#else
-+  {"__deepcopy__", (PyCFunction)Sexp_duplicate, METH_VARARGS | METH_KEYWORDS,
-+   Sexp_duplicate_doc},
-+#endif
-   {"__getstate__", (PyCFunction)Sexp___getstate__, METH_NOARGS,
-    Sexp___getstate___doc},
-   {"__setstate__", (PyCFunction)Sexp___setstate__, METH_O,
-@@ -593,8 +631,12 @@
- static PyTypeObject Sexp_Type = {
-         /* The ob_type field must be initialized in the module init function
-          * to be portable to Windows without using C++. */
-+#if (PY_VERSION_HEX < 0x03010000)
-         PyObject_HEAD_INIT(NULL)
-         0,                      /*ob_size*/
-+#else
-+	PyVarObject_HEAD_INIT(NULL, 0)
-+#endif
-         "rpy2.rinterface.Sexp",      /*tp_name*/
-         sizeof(PySexpObject),   /*tp_basicsize*/
-         0,                      /*tp_itemsize*/
-diff -r 089949fdede1 setup.py
---- a/setup.py	Sun Jun 27 09:47:32 2010 +0200
-+++ b/setup.py	Thu Aug 05 23:04:49 2010 +0200
-@@ -274,6 +274,7 @@
- 
- setup(
-     #install_requires=['distribute'],
-+    #use2to3 = True,
-     cmdclass = {'build': build,
-                 'build_ext': build_ext},
-     name = pack_name,

File build_and_install

+diff -r 2720876f56da setup.py
+--- a/setup.py	Sun Aug 15 22:20:46 2010 +0200
++++ b/setup.py	Thu Aug 19 17:41:27 2010 +0200
+@@ -10,6 +10,11 @@
+ pack_name = 'rpy2'
+ pack_version = __import__('rpy').__version__
+ 
++extra_setup = {}
++if sys.version_info >= (3,):
++    # Python 3 -> need to translate code
++    extra_setup['use_2to3'] = True
++    
+ 
+ class build(_build):
+     user_options = _build.user_options + \
+@@ -274,7 +279,6 @@
+ 
+ setup(
+     #install_requires=['distribute'],
+-    #use2to3 = True,
+     cmdclass = {'build': build,
+                 'build_ext': build_ext},
+     name = pack_name,
+@@ -303,7 +307,8 @@
+                    'Development Status :: 4 - Beta'
+                    ],
+     data_files = [(os.path.join('rpy2', 'images'), 
+-                   [os.path.join('doc', 'source', 'rpy2_logo.png')])]
++                   [os.path.join('doc', 'source', 'rpy2_logo.png')])],
++    **extra_setup
+     
+     #[pack_name + '.rinterface_' + x for x in rinterface_rversions] + \
+         #[pack_name + '.rinterface_' + x + '.tests' for x in rinterface_rversions]
 build_and_install
-C-interface
 # Placed by Bitbucket