Ignore:
Timestamp:
Dec 21, 2007, 12:44:10 PM (16 years ago)
Author:
duncan
Message:

Good fix for the memory leak found in ticket#189

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c

    r4893 r4894  
    6262#include "Python.h"
    6363
     64//#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
     65
     66#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
     67//#define NO_IMPORT_ARRAY
    6468#include "Numeric/arrayobject.h"
    65 
     69#include <sys/types.h>
    6670
    6771 static PyObject *triang_genMesh(PyObject *self, PyObject *args){
     
    214218  /*printf("\n\nTriangulate input args: %s \n\n", mod); */
    215219  triangulate(mod, &in, &out, (struct triangulateio *)NULL );
    216 
     220 
     221 
     222  /*
     223  PyArray_FromDims allolws you to create a Numeric array with unitialized data.
     224   The first argument is the size of the second argument (
     225   the dimensions array).
     226    The dimension array argument is just a 1D C array where each element of
     227     the array is the size of that dimension.
     228     (int dimensions[2] = { 4, 3 }; defines a 4 by 3 array.)
     229     The third argument is just the desired type.
     230  */
     231 
     232  //Py_Initialize();
     233  // Testing passing a numeric array out
     234  dimensions[0] = 4;
     235  // Allocate space for return vectors a and b (don't DECREF)
     236  r_test = (PyArrayObject *) PyArray_FromDims(1, dimensions, PyArray_DOUBLE);
     237 
    217238  /* printf(" ***  back from triangulate\n" );    */
    218239  /*
     
    330351    Py_DECREF(ii); Py_DECREF(holderlist);
    331352  }   
    332   /*
    333   // Testing passing a numeric array out
    334   dimensions[0] = 4;
    335   // Allocate space for return vectors a and b (don't DECREF)
    336   // This is crashing - don't know why
    337   r_test = (PyArrayObject *) PyArray_FromDims(1, dimensions, PyArray_DOUBLE);
    338   */
     353 
     354 
    339355 
    340356  /* Free in/out structure memory */
     
    382398  }
    383399 
    384   /*Py_DECREF(holder);*/
    385   R = Py_BuildValue((char *)"O", holder);
    386   /*Py_DECREF(holder);* Try this to fix memory problems */
     400  /* R = Py_BuildValue((char *)"O", holder); */
     401  R = Py_BuildValue((char *)"OO", holder, PyArray_Return(r_test));
     402  Py_DECREF(holder); /** This fixed a  memory problem ticket#189 */
     403  Py_DECREF(r_test);
    387404  return R;
    388405}
     
    397414void initmesh_engine_c_layer(){
    398415  Py_InitModule((char *)"mesh_engine_c_layer",triang_methods);
     416 
     417  import_array(); // Necessary for handling of NumPY structures
    399418}   
Note: See TracChangeset for help on using the changeset viewer.