Revision: 497
          http://rpy.svn.sourceforge.net/rpy/?rev=497&view=rev
Author:   lgautier
Date:     2008-04-19 08:28:30 -0700 (Sat, 19 Apr 2008)

Log Message:
-----------
missed two files in the previous commit

Modified Paths:
--------------
    branches/rpy_nextgen/rpy/rinterface/array.c
    branches/rpy_nextgen/rpy/rinterface/tests/__init__.py

Modified: branches/rpy_nextgen/rpy/rinterface/array.c
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/array.c 2008-04-19 14:43:10 UTC (rev 
496)
+++ branches/rpy_nextgen/rpy/rinterface/array.c 2008-04-19 15:28:30 UTC (rev 
497)
@@ -9,37 +9,51 @@
 #define ARRAY_INTERFACE_VERSION 2
 
 /* Array Interface flags */
+#define CONTIGUOUS    0x001
 #define FORTRAN       0x002
 #define ALIGNED       0x100
 #define NOTSWAPPED    0x200
 #define WRITEABLE     0x400
 
 typedef struct {
-       int version;
-       int nd;
-       char typekind;
-       int itemsize;
-       int flags;
-       Py_intptr_t *shape;
-       Py_intptr_t *strides;
-       void *data;
+  int version;
+  int nd;
+  char typekind;
+  int itemsize;
+  int flags;
+  Py_intptr_t *shape;
+  Py_intptr_t *strides;
+  void *data;
 } PyArrayInterface;
 
-static int
+static char
 sexp_typekind(SEXP sexp)
 {
   switch (TYPEOF(sexp)) {
-  case REALSXP: return 'f';
-  case INTSXP: return 'i';
-  case STRSXP: return 'S';
-  case CPLXSXP: return 'c';
-    //FIXME: correct type ?
-  case LGLSXP: return 'b';
+  case REALSXP: return 'd';
+  case INTSXP: return 'l';
+    //FIXME: handle strings ?
+    //case STRSXP: return 'S';
+  case CPLXSXP: return 'D';
+    //case LGLSXP: return 'b';
   }
   return 0;
 }
 
+static void*
+sexp_typepointer(SEXP sexp)
+{
+  switch (TYPEOF(sexp)) {
+  case REALSXP: return (void *)NUMERIC_POINTER(sexp);
+  case INTSXP: return (void *)INTEGER_POINTER(sexp);
+    //case STRSXP: return (void *)CHARACTER_POINTER(;
+  case CPLXSXP: return (void *)COMPLEX_POINTER(sexp);
+  case LGLSXP: return (void *)LOGICAL_POINTER(sexp);
+  }
+  return NULL;
+}
 
+
 static int
 sexp_itemsize(SEXP sexp)
 {
@@ -84,7 +98,7 @@
 }
 
 
-static PyObject* 
+PyObject* 
 array_struct_get(SexpObject *self)
 {
   SEXP sexp = self->sexp;
@@ -93,7 +107,7 @@
     return NULL;
   }
   PyArrayInterface *inter;
-  int typekind =  sexp_typekind(sexp);
+  char typekind =  sexp_typekind(sexp);
   if (!typekind) {
     PyErr_SetString(PyExc_AttributeError, "Unsupported SEXP type");
     return NULL;
@@ -118,7 +132,11 @@
     stride *= inter->shape[i-1];
     inter->strides[i] = stride;
   }
-  inter->data = RAW(sexp);
+  inter->data = sexp_typepointer(sexp);
+  if (inter->data == NULL) {
+    PyErr_SetString(PyExc_RuntimeError, "Error while mapping type.");
+    return NULL;
+  }
   Py_INCREF(self);
   return PyCObject_FromVoidPtrAndDesc(inter, self, array_struct_free);
 }

Modified: branches/rpy_nextgen/rpy/rinterface/tests/__init__.py
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/tests/__init__.py       2008-04-19 
14:43:10 UTC (rev 496)
+++ branches/rpy_nextgen/rpy/rinterface/tests/__init__.py       2008-04-19 
15:28:30 UTC (rev 497)
@@ -3,12 +3,18 @@
 import test_SexpVector
 import test_SexpEnvironment
 import test_Sexp
+import test_SexpVectorNumeric
 
+
 def suite():
     suite_SexpVector = test_SexpVector.suite()
     suite_SexpEnvironment = test_SexpEnvironment.suite()
     suite_Sexp = test_Sexp.suite()
-    alltests = unittest.TestSuite([suite_SexpVector, suite_SexpEnvironment, 
suite_Sexp])
+    suite_SexpVectorNumeric = test_SexpVectorNumeric.suite()
+    alltests = unittest.TestSuite([suite_SexpVector, 
+                                   suite_SexpEnvironment, 
+                                   suite_Sexp, 
+                                   suite_SexpVectorNumeric])
     return alltests
 
 def main():


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to