Changeset 7ba6470 in sasview for src/sas/sascalc/calculator
- Timestamp:
- Oct 11, 2018 9:49:59 PM (6 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/sld2i_module.c
r952ea1f r7ba6470 16 16 #endif 17 17 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 34 38 35 39 /** … … 76 80 //printf("new GenI\n"); 77 81 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); 86 90 sld2i = PyMem_Malloc(sizeof(GenI)); 87 91 //printf("sldi:%p\n", sld2i); … … 111 115 if (!PyArg_ParseTuple(args, "OOOO", &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 112 116 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); 116 120 //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 117 121 … … 139 143 if (!PyArg_ParseTuple(args, "OOO", &gen_obj, &q_obj, &I_out_obj)) return NULL; 140 144 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); 143 147 144 148 // Sanity check
Note: See TracChangeset
for help on using the changeset viewer.