Changeset 7ba6470 in sasview


Ignore:
Timestamp:
Oct 11, 2018 7:49:59 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
Children:
3e6829d
Parents:
952ea1f
Message:

remove deprecation warnings for old buffer protocol from py37 build

Location:
src/sas/sascalc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/calculator/c_extensions/sld2i_module.c

    r952ea1f r7ba6470  
    1616#endif 
    1717 
    18  
    19 // Utilities 
    20 #define INVECTOR(obj,buf,len)                                                                           \ 
    21     do { \ 
    22         int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ 
    23         if (err < 0) return NULL; \ 
    24         len /= sizeof(*buf); \ 
    25     } while (0) 
    26  
    27 #define OUTVECTOR(obj,buf,len) \ 
    28     do { \ 
    29         int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \ 
    30         if (err < 0) return NULL; \ 
    31         len /= sizeof(*buf); \ 
    32     } while (0) 
    33  
     18// Vector binding glue 
     19#if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API) 
     20  // Assuming that a view into a writable vector points to a  
     21  // non-changing pointer for the duration of the C call, capture  
     22  // the view pointer and immediately free the view. 
     23  #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 
     24    Py_buffer VEC_view; \ 
     25    int VEC_err = PyObject_GetBuffer(VEC_obj, &VEC_view, PyBUF_WRITABLE|PyBUF_FORMAT); \ 
     26    if (VEC_err < 0 || sizeof(*VEC_buf) != VEC_view.itemsize) return NULL; \ 
     27    VEC_buf = (typeof(VEC_buf))VEC_view.buf; \ 
     28    VEC_len = VEC_view.len/sizeof(*VEC_buf); \ 
     29    PyBuffer_Release(&VEC_view); \ 
     30  } while (0) 
     31#else 
     32  #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 
     33    int VEC_err = PyObject_AsWriteBuffer(VEC_obj, (void **)(&VEC_buf), &VEC_len); \ 
     34    if (VEC_err < 0) return NULL; \ 
     35    VEC_len /= sizeof(*VEC_buf); \ 
     36  } while (0) 
     37#endif 
    3438 
    3539/** 
     
    7680        //printf("new GenI\n"); 
    7781        if (!PyArg_ParseTuple(args, "iOOOOOOOOddd", &is_avg, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &vol_pix_obj, &inspin, &outspin, &stheta)) return NULL; 
    78         INVECTOR(x_val_obj, x_val, n_x); 
    79         INVECTOR(y_val_obj, y_val, n_y); 
    80         INVECTOR(z_val_obj, z_val, n_z); 
    81         INVECTOR(sldn_val_obj, sldn_val, n_sld); 
    82         INVECTOR(mx_val_obj, mx_val, n_mx); 
    83         INVECTOR(my_val_obj, my_val, n_my); 
    84         INVECTOR(mz_val_obj, mz_val, n_mz); 
    85         INVECTOR(vol_pix_obj, vol_pix, n_vol_pix); 
     82        VECTOR(x_val_obj, x_val, n_x); 
     83        VECTOR(y_val_obj, y_val, n_y); 
     84        VECTOR(z_val_obj, z_val, n_z); 
     85        VECTOR(sldn_val_obj, sldn_val, n_sld); 
     86        VECTOR(mx_val_obj, mx_val, n_mx); 
     87        VECTOR(my_val_obj, my_val, n_my); 
     88        VECTOR(mz_val_obj, mz_val, n_mz); 
     89        VECTOR(vol_pix_obj, vol_pix, n_vol_pix); 
    8690        sld2i = PyMem_Malloc(sizeof(GenI)); 
    8791        //printf("sldi:%p\n", sld2i); 
     
    111115        if (!PyArg_ParseTuple(args, "OOOO",  &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 
    112116        sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 
    113         INVECTOR(qx_obj, qx, n_qx); 
    114         INVECTOR(qy_obj, qy, n_qy); 
    115         OUTVECTOR(I_out_obj, I_out, n_out); 
     117        VECTOR(qx_obj, qx, n_qx); 
     118        VECTOR(qy_obj, qy, n_qy); 
     119        VECTOR(I_out_obj, I_out, n_out); 
    116120        //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 
    117121 
     
    139143        if (!PyArg_ParseTuple(args, "OOO",  &gen_obj, &q_obj, &I_out_obj)) return NULL; 
    140144        sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 
    141         INVECTOR(q_obj, q, n_q); 
    142         OUTVECTOR(I_out_obj, I_out, n_out); 
     145        VECTOR(q_obj, q, n_q); 
     146        VECTOR(I_out_obj, I_out, n_out); 
    143147 
    144148        // Sanity check 
  • src/sas/sascalc/pr/c_extensions/Cinvertor.c

    r952ea1f r7ba6470  
    1414#include <structmember.h> 
    1515 
     16// Vector binding glue 
     17#if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API) 
     18  // Assuming that a view into a writable vector points to a 
     19  // non-changing pointer for the duration of the C call, capture 
     20  // the view pointer and immediately free the view. 
     21  #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 
     22    Py_buffer VEC_view; \ 
     23    int VEC_err = PyObject_GetBuffer(VEC_obj, &VEC_view, PyBUF_WRITABLE|PyBUF_FORMAT); \ 
     24    if (VEC_err < 0 || sizeof(*VEC_buf) != VEC_view.itemsize) return NULL; \ 
     25    VEC_buf = (typeof(VEC_buf))VEC_view.buf; \ 
     26    VEC_len = VEC_view.len/sizeof(*VEC_buf); \ 
     27    PyBuffer_Release(&VEC_view); \ 
     28  } while (0) 
     29#else 
     30  #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 
     31    int VEC_err = PyObject_AsWriteBuffer(VEC_obj, (void **)(&VEC_buf), &VEC_len); \ 
     32    if (VEC_err < 0) return NULL; \ 
     33    VEC_len /= sizeof(*VEC_buf); \ 
     34  } while (0) 
     35#endif 
     36 
    1637#include "invertor.h" 
    1738 
    1839/// Error object for raised exceptions 
    1940PyObject * CinvertorError; 
    20  
    21 #define INVECTOR(obj,buf,len)                                                                           \ 
    22     do { \ 
    23         int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ 
    24         if (err < 0) return NULL; \ 
    25         len /= sizeof(*buf); \ 
    26     } while (0) 
    27  
    28 #define OUTVECTOR(obj,buf,len) \ 
    29     do { \ 
    30         int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \ 
    31         if (err < 0) return NULL; \ 
    32         len /= sizeof(*buf); \ 
    33     } while (0) 
    34  
    3541 
    3642// Class definition 
     
    100106 
    101107        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    102         OUTVECTOR(data_obj,data,ndata); 
     108        VECTOR(data_obj,data,ndata); 
    103109 
    104110        free(self->params.x); 
     
    132138 
    133139        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    134         OUTVECTOR(data_obj, data, ndata); 
     140        VECTOR(data_obj, data, ndata); 
    135141 
    136142        // Check that the input array is large enough 
     
    165171 
    166172        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    167         OUTVECTOR(data_obj,data,ndata); 
     173        VECTOR(data_obj,data,ndata); 
    168174 
    169175        free(self->params.y); 
     
    197203 
    198204        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    199         OUTVECTOR(data_obj, data, ndata); 
     205        VECTOR(data_obj, data, ndata); 
    200206 
    201207        // Check that the input array is large enough 
     
    230236 
    231237        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    232         OUTVECTOR(data_obj,data,ndata); 
     238        VECTOR(data_obj,data,ndata); 
    233239 
    234240        free(self->params.err); 
     
    262268 
    263269        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    264         OUTVECTOR(data_obj, data, ndata); 
     270        VECTOR(data_obj, data, ndata); 
    265271 
    266272        // Check that the input array is large enough 
     
    518524        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    519525 
    520         OUTVECTOR(data_obj,pars,npars); 
     526        VECTOR(data_obj,pars,npars); 
    521527 
    522528    // PyList of residuals 
     
    569575        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    570576 
    571         OUTVECTOR(data_obj,pars,npars); 
     577        VECTOR(data_obj,pars,npars); 
    572578 
    573579        // Should create this list only once and refill it 
     
    610616 
    611617        if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 
    612         OUTVECTOR(data_obj,pars,npars); 
     618        VECTOR(data_obj,pars,npars); 
    613619 
    614620        iq_value = iq(pars, self->params.d_max, (int)npars, q); 
     
    635641 
    636642        if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 
    637         OUTVECTOR(data_obj,pars,npars); 
     643        VECTOR(data_obj,pars,npars); 
    638644 
    639645        iq_value = iq_smeared(pars, self->params.d_max, (int)npars, 
     
    660666 
    661667        if (!PyArg_ParseTuple(args, "Od", &data_obj, &r)) return NULL; 
    662         OUTVECTOR(data_obj,pars,npars); 
     668        VECTOR(data_obj,pars,npars); 
    663669 
    664670        pr_value = pr(pars, self->params.d_max, (int)npars, r); 
     
    687693 
    688694        if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 
    689         OUTVECTOR(data_obj,pars,npars); 
     695        VECTOR(data_obj,pars,npars); 
    690696 
    691697        if (err_obj == Py_None) { 
     
    693699                pr_err_value = 0.0; 
    694700        } else { 
    695                 OUTVECTOR(err_obj,pars_err,npars2); 
     701                VECTOR(err_obj,pars_err,npars2); 
    696702                pr_err(pars, pars_err, self->params.d_max, (int)npars, r, &pr_value, &pr_err_value); 
    697703        } 
     
    727733 
    728734        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    729         OUTVECTOR(data_obj,pars,npars); 
     735        VECTOR(data_obj,pars,npars); 
    730736 
    731737        oscill = reg_term(pars, self->params.d_max, (int)npars, 100); 
     
    748754 
    749755        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    750         OUTVECTOR(data_obj,pars,npars); 
     756        VECTOR(data_obj,pars,npars); 
    751757 
    752758        count = npeaks(pars, self->params.d_max, (int)npars, 100); 
     
    769775 
    770776        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    771         OUTVECTOR(data_obj,pars,npars); 
     777        VECTOR(data_obj,pars,npars); 
    772778 
    773779        fraction = positive_integral(pars, self->params.d_max, (int)npars, 100); 
     
    793799 
    794800        if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL; 
    795         OUTVECTOR(data_obj,pars,npars); 
    796         OUTVECTOR(err_obj,pars_err,npars2); 
     801        VECTOR(data_obj,pars,npars); 
     802        VECTOR(err_obj,pars_err,npars2); 
    797803 
    798804        fraction = positive_errors(pars, pars_err, self->params.d_max, (int)npars, 51); 
     
    814820 
    815821        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    816         OUTVECTOR(data_obj,pars,npars); 
     822        VECTOR(data_obj,pars,npars); 
    817823 
    818824        value = rg(pars, self->params.d_max, (int)npars, 101); 
     
    834840 
    835841        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    836         OUTVECTOR(data_obj,pars,npars); 
     842        VECTOR(data_obj,pars,npars); 
    837843 
    838844        value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, (int)npars, 101); 
     
    875881 
    876882        if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &b_obj)) return NULL; 
    877         OUTVECTOR(a_obj,a,n_a); 
    878         OUTVECTOR(b_obj,b,n_b); 
     883        VECTOR(a_obj,a,n_a); 
     884        VECTOR(b_obj,b,n_b); 
    879885 
    880886        assert(n_b>=nfunc); 
     
    948954 
    949955        if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &cov_obj)) return NULL; 
    950         OUTVECTOR(a_obj,a,n_a); 
    951         OUTVECTOR(cov_obj,inv_cov,n_cov); 
     956        VECTOR(a_obj,a,n_a); 
     957        VECTOR(cov_obj,inv_cov,n_cov); 
    952958 
    953959        assert(n_cov>=nfunc*nfunc); 
     
    982988 
    983989        if (!PyArg_ParseTuple(args, "iiO", &nfunc, &nr, &a_obj)) return NULL; 
    984         OUTVECTOR(a_obj,a,n_a); 
     990        VECTOR(a_obj,a,n_a); 
    985991 
    986992        assert(n_a>=nfunc*(nr+self->params.npoints)); 
Note: See TracChangeset for help on using the changeset viewer.