Changes in src/sas/sascalc/calculator/c_extensions/sld2i_module.c [7ba6470:a1daf86] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/sld2i_module.c
r7ba6470 ra1daf86 2 2 SLD2I module to perform point and I calculations 3 3 */ 4 #include <Python.h> 4 5 #include <stdio.h> 5 6 //#define Py_LIMITED_API 0x030200007 #include <Python.h>8 9 6 #include "sld2i.h" 10 7 … … 16 13 #endif 17 14 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 15 16 // Utilities 17 #define INVECTOR(obj,buf,len) \ 18 do { \ 19 int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ 20 if (err < 0) return NULL; \ 21 len /= sizeof(*buf); \ 22 } while (0) 23 24 #define OUTVECTOR(obj,buf,len) \ 25 do { \ 26 int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \ 27 if (err < 0) return NULL; \ 28 len /= sizeof(*buf); \ 29 } while (0) 30 38 31 39 32 /** … … 80 73 //printf("new GenI\n"); 81 74 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; 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);75 INVECTOR(x_val_obj, x_val, n_x); 76 INVECTOR(y_val_obj, y_val, n_y); 77 INVECTOR(z_val_obj, z_val, n_z); 78 INVECTOR(sldn_val_obj, sldn_val, n_sld); 79 INVECTOR(mx_val_obj, mx_val, n_mx); 80 INVECTOR(my_val_obj, my_val, n_my); 81 INVECTOR(mz_val_obj, mz_val, n_mz); 82 INVECTOR(vol_pix_obj, vol_pix, n_vol_pix); 90 83 sld2i = PyMem_Malloc(sizeof(GenI)); 91 84 //printf("sldi:%p\n", sld2i); … … 115 108 if (!PyArg_ParseTuple(args, "OOOO", &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 116 109 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 117 VECTOR(qx_obj, qx, n_qx);118 VECTOR(qy_obj, qy, n_qy);119 VECTOR(I_out_obj, I_out, n_out);110 INVECTOR(qx_obj, qx, n_qx); 111 INVECTOR(qy_obj, qy, n_qy); 112 OUTVECTOR(I_out_obj, I_out, n_out); 120 113 //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 121 114 … … 143 136 if (!PyArg_ParseTuple(args, "OOO", &gen_obj, &q_obj, &I_out_obj)) return NULL; 144 137 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 145 VECTOR(q_obj, q, n_q);146 VECTOR(I_out_obj, I_out, n_out);138 INVECTOR(q_obj, q, n_q); 139 OUTVECTOR(I_out_obj, I_out, n_out); 147 140 148 141 // Sanity check … … 167 160 168 161 #define MODULE_DOC "Sld2i C Library" 169 #define MODULE_NAME " _sld2i"170 #define MODULE_INIT2 init _sld2i171 #define MODULE_INIT3 PyInit_ _sld2i162 #define MODULE_NAME "sld2i" 163 #define MODULE_INIT2 initsld2i 164 #define MODULE_INIT3 PyInit_sld2i 172 165 #define MODULE_METHODS module_methods 173 166
Note: See TracChangeset
for help on using the changeset viewer.