Ignore:
Timestamp:
09/14/12 11:16:56 (12 years ago)
Author:
jschierm
Message:

CHG: Changed python FetchData for strings, vectors, and matrices to copy data out of python space.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/python/io/FetchPythonData.cpp

    r13368 r13372  
    6363
    6464        /*output: */
     65        double* dmatrix=NULL;
    6566        double* matrix=NULL;
    6667        int M,N;
    67         int ndim;
     68        int i,ndim;
    6869        npy_intp*  dims=NULL;
    6970
     
    7576       
    7677        /*retrieve internal value: */
    77         matrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
     78        dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
     79
     80        /*copy matrix: */
     81        matrix=xNew<double>(M*N);
     82        for(i=0;i<M*N;i++)matrix[i]=dmatrix[i];
    7883
    7984        /*output: */
     
    119124
    120125        /*output: */
     126        double* dvector=NULL;
    121127        double* vector=NULL;
    122128        int M;
    123         int ndim;
     129        int i,ndim;
    124130        npy_intp*  dims=NULL;
    125131
     
    131137       
    132138        /*retrieve internal value: */
    133         vector=(double*)PyArray_DATA((PyArrayObject*)py_vector);
     139        dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector);
     140
     141        /*copy vector: */
     142        vector=xNew<double>(M);
     143        for(i=0;i<M;i++)vector[i]=dvector[i];
    134144
    135145        /*output: */
     
    282292
    283293        /*clean-up and assign output pointer*/
     294        xDelete<char>(contourname);
    284295        *pcontours=contours;
    285296}
     
    294305        char* string=NULL;
    295306
    296        
    297307        /*convert to bytes format: */
    298308        PyUnicode_FSConverter(py_unicode,&py_bytes);
     
    312322        /*extract internal string: */
    313323        string=PyString_AsString(py_string);
    314        
    315         *pstring=string;
     324
     325        /*copy string (note strlen does not include trailing NULL): */
     326        *pstring=xNew<char>(strlen(string)+1);
     327        memcpy(*pstring,string,(strlen(string)+1)*sizeof(char));
    316328}
    317329/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.