[Numpy-svn] r8266 - in trunk/numpy/f2py: . src

numpy-svn@scip... numpy-svn@scip...
Wed Feb 24 23:20:51 CST 2010


Author: charris
Date: 2010-02-24 23:20:51 -0600 (Wed, 24 Feb 2010)
New Revision: 8266

Modified:
   trunk/numpy/f2py/cb_rules.py
   trunk/numpy/f2py/cfuncs.py
   trunk/numpy/f2py/rules.py
   trunk/numpy/f2py/src/fortranobject.c
   trunk/numpy/f2py/src/fortranobject.h
Log:
ENH: Add support for PyCapsule.

Modified: trunk/numpy/f2py/cb_rules.py
===================================================================
--- trunk/numpy/f2py/cb_rules.py	2010-02-25 05:20:44 UTC (rev 8265)
+++ trunk/numpy/f2py/cb_rules.py	2010-02-25 05:20:51 UTC (rev 8266)
@@ -60,9 +60,9 @@
 \t\tPyErr_SetString(#modulename#_error,\"cb: Callback #argname# not defined (as an argument or module #modulename# attribute).\\n\");
 \t\tgoto capi_fail;
 \t}
-\tif (PyCObject_Check(#name#_capi)) {
+\tif (F2PyCapsule_Check(#name#_capi)) {
 \t#name#_typedef #name#_cptr;
-\t#name#_cptr = PyCObject_AsVoidPtr(#name#_capi);
+\t#name#_cptr = F2PyCapsule_AsVoidPtr(#name#_capi);
 \t#returncptr#(*#name#_cptr)(#optargs_nm##args_nm##strarglens_nm#);
 \t#return#
 \t}

Modified: trunk/numpy/f2py/cfuncs.py
===================================================================
--- trunk/numpy/f2py/cfuncs.py	2010-02-25 05:20:44 UTC (rev 8265)
+++ trunk/numpy/f2py/cfuncs.py	2010-02-25 05:20:51 UTC (rev 8266)
@@ -999,7 +999,7 @@
 \t\t\t\ttot += PyTuple_Size((PyObject *)xa);
 \t\t\ttmp_fun = fun;
 \t\t}
-\t\telse if (PyCObject_Check(fun)) {
+\t\telse if (F2PyCapsule_Check(fun)) {
 \t\t\ttot = maxnofargs;
 \t\t\tif (xa != NULL)
 \t\t\t\text = PyTuple_Size((PyObject *)xa);

Modified: trunk/numpy/f2py/rules.py
===================================================================
--- trunk/numpy/f2py/rules.py	2010-02-25 05:20:44 UTC (rev 8265)
+++ trunk/numpy/f2py/rules.py	2010-02-25 05:20:51 UTC (rev 8266)
@@ -392,7 +392,7 @@
     {
       extern #ctype# #F_FUNC#(#name_lower#,#NAME#)(void);
       PyObject* o = PyDict_GetItemString(d,"#name#");
-      PyObject_SetAttrString(o,"_cpointer", PyCObject_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL));
+      PyObject_SetAttrString(o,"_cpointer", F2PyCapsule_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL));
     }
     '''},
     'need':{l_not(l_or(ismoduleroutine,isdummyroutine)):['F_WRAPPEDFUNC','F_FUNC']},
@@ -686,8 +686,8 @@
     },
     {
     'frompyobj':[{l_not(isintent_callback):"""\
-if(PyCObject_Check(#varname#_capi)) {
-  #varname#_cptr = PyCObject_AsVoidPtr(#varname#_capi);
+if(F2PyCapsule_Check(#varname#_capi)) {
+  #varname#_cptr = F2PyCapsule_AsVoidPtr(#varname#_capi);
 } else {
   #varname#_cptr = #cbname#;
 }

Modified: trunk/numpy/f2py/src/fortranobject.c
===================================================================
--- trunk/numpy/f2py/src/fortranobject.c	2010-02-25 05:20:44 UTC (rev 8265)
+++ trunk/numpy/f2py/src/fortranobject.c	2010-02-25 05:20:51 UTC (rev 8266)
@@ -855,6 +855,61 @@
     return PyArray_CopyInto(out, (PyArrayObject *)arr);
 }
 
+/*******************************************/
+/* Compatibility functions for Python 3.1  */
+/*******************************************/
+
+#if PY_VERSION_HEX >= 0X03010000
+
+PyObject *
+F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *))
+{
+    PyObject *ret = PyCapsule_New(ptr, NULL, dtor);
+    if (ret == NULL) {
+        PyErr_Clear();
+    }
+    return ret;
+}
+
+void *
+F2PyCapsule_AsVoidPtr(PyObject *obj)
+{
+    void *ret = PyCapsule_GetPointer(obj, NULL);
+    if (ret == NULL) {
+        PyErr_Clear();
+    }
+    return ret;
+}
+
+int
+F2PyCapsule_Check(PyObject *ptr)
+{
+    return PyCapsule_CheckExact(ptr);
+}
+
+#else
+
+PyObject *
+F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(void *))
+{
+    return PyCObject_FromVoidPtr(ptr, dtor);
+}
+
+void *
+F2PyCapsule_AsVoidPtr(PyObject *ptr)
+{
+    return PyCObject_AsVoidPtr(ptr);
+}
+
+int
+F2PyCapsule_Check(PyObject *ptr)
+{
+    return PyCObject_Check(ptr);
+}
+
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/numpy/f2py/src/fortranobject.h
===================================================================
--- trunk/numpy/f2py/src/fortranobject.h	2010-02-25 05:20:44 UTC (rev 8265)
+++ trunk/numpy/f2py/src/fortranobject.h	2010-02-25 05:20:51 UTC (rev 8266)
@@ -84,7 +84,7 @@
 typedef struct {
   PyObject_HEAD
   int len;                   /* Number of attributes */
-  FortranDataDef *defs;      /* An array of FortranDataDef's */ 
+  FortranDataDef *defs;      /* An array of FortranDataDef's */
   PyObject       *dict;      /* Fortran object attribute dictionary */
 } PyFortranObject;
 
@@ -96,6 +96,20 @@
   extern PyObject * PyFortranObject_New(FortranDataDef* defs, f2py_void_func init);
   extern PyObject * PyFortranObject_NewAsAttr(FortranDataDef* defs);
 
+#if PY_VERSION_HEX >= 0X03010000
+
+PyObject * F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *));
+void * F2PyCapsule_AsVoidPtr(PyObject *obj);
+int F2PyCapsule_Check(PyObject *ptr);
+
+#else
+
+PyObject * F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(void *));
+void * F2PyCapsule_AsVoidPtr(PyObject *ptr);
+int F2PyCapsule_Check(PyObject *ptr);
+
+#endif
+
 #define ISCONTIGUOUS(m) ((m)->flags & NPY_CONTIGUOUS)
 #define F2PY_INTENT_IN 1
 #define F2PY_INTENT_INOUT 2



More information about the Numpy-svn mailing list