Ignore:
Timestamp:
Feb 21, 2013, 3:16:55 PM (12 years ago)
Author:
wilsonp
Message:

Updating sparse_ext.c and quad_tree_ext.c with PyCObject code

Location:
trunk/anuga_core/source/anuga/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/utilities/quad_tree_ext.c

    r8709 r8710  
    165165*/
    166166
    167 static void delete_quad_tree_cap(PyObject * cap){
    168 
     167#ifdef PYVERSION273
     168
     169
     170void delete_quad_tree_cap(PyObject * cap){
    169171    quad_tree * kill = (quad_tree*) PyCapsule_GetPointer(cap,"quad tree");
    170172    if(kill!=NULL){
    171173        delete_quad_tree(kill);
    172     }
    173 }
     174    } else{
     175    }
     176}
     177
     178
     179
     180#else
     181
     182// If using python earlier version, build with PyCObject
     183
     184// Delete cobj containing a quad tree
     185void delete_quad_tree_cobj(void * cobj){
     186    quad_tree * kill = (quad_tree*) cobj;
     187    if(kill!=NULL){
     188        delete_quad_tree(kill);
     189    }
     190}
     191
     192
     193#endif
    174194
    175195//----------------------- PYTHON WRAPPER FUNCTION -----------------------------
  • trunk/anuga_core/source/anuga/utilities/sparse_matrix_ext.c

    r8691 r8710  
    1111#include "sparse_dok.h"
    1212
    13 
     13#include "patchlevel.h"
     14
     15// PYVERSION273 used to check python version for use of PyCapsule
     16#if PY_MAJOR_VERSION>=2 && PY_MINOR_VERSION>=7 && PY_MICRO_VERSION>=3
     17    #define PYVERSION273
     18#endif
    1419
    1520
     
    9297};
    9398
     99// ----------------------------------------------------------------------------
     100
     101// If using python 2.7.3 or later, build with PyCapsules
     102
     103// Delete capsule containing a quad tree - name of capsule must be exactly
     104// "quad tree".
     105
     106#ifdef PYVERSION273
    94107
    95108// Delete capsule containing a sparse_dok - name of capsule must be exactly
    96109// "sparse dok".
    97 static void delete_sparse_dok_cap(PyObject *cap){
     110void delete_dok_cap(PyObject *cap){
    98111
    99112    sparse_dok * kill = (sparse_dok*) PyCapsule_GetPointer(cap,"sparse dok");
     
    101114        delete_dok_matrix(kill);
    102115    }
    103 
    104 }
     116}
     117
     118#else
     119
     120// If using python earlier version, build with PyCObject
     121
     122
     123// Delete cobj containing a sparse_dok
     124void delete_dok_cobj(void *cobj){
     125
     126    sparse_dok * kill = (sparse_dok*) cobj;
     127    if(kill!=NULL){
     128        delete_dok_matrix(kill);
     129    }
     130}
     131
     132#endif
    105133//----------------------- PYTHON WRAPPER FUNCTION -----------------------------
    106134
     
    119147      return NULL;
    120148    }
    121 
     149    #ifdef PYVERSION273
    122150    sparse_dok * dok = (sparse_dok*) PyCapsule_GetPointer(sparse_dok_cap,"sparse dok");
     151    #else
     152    sparse_dok * dok = (sparse_dok*) PyCObject_AsVoidPtr(sparse_dok_cap);
     153    #endif
    123154
    124155    serial_sparse_dok = PyDict_New();
     
    155186    err = _deserialise(dok,serial_sparse_dok);
    156187
     188    #ifdef PYVERSION273
    157189    return  PyCapsule_New((void*) dok,
    158190                      "sparse dok",
    159                       &delete_sparse_dok_cap);
     191                      &delete_dok_cap);
     192    #else
     193    return  PyCObject_FromVoidPtr((void*) dok,
     194                      &delete_dok_obj);
     195    #endif
    160196
    161197}
Note: See TracChangeset for help on using the changeset viewer.