Ignore:
Timestamp:
Nov 7, 2017 10:00:25 AM (7 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, ticket885, unittest-saveload
Children:
54b0650
Parents:
0fc5a03
Message:

convert sldi from C++ to C

File:
1 moved

Legend:

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

    r1d014cb r0957bb3a  
    44#include <Python.h> 
    55#include <stdio.h> 
    6 #include <sld2i.hh> 
     6#include <sld2i.h> 
    77 
    88#if PY_MAJOR_VERSION < 3 
     
    3535void 
    3636del_sld2i(PyObject *obj){ 
    37         GenI* sld2i = static_cast<GenI *>(PyCapsule_GetPointer(obj, "GenI")); 
    38         delete sld2i; 
    39         return; 
     37        GenI* sld2i = (GenI *)(PyCapsule_GetPointer(obj, "GenI")); 
     38        PyMem_Free((void *)sld2i); 
    4039} 
    4140 
     
    4342 * Create a GenI as a python object by supplying arrays 
    4443 */ 
    45 PyObject * new_GenI(PyObject *, PyObject *args) { 
     44PyObject * new_GenI(PyObject *self, PyObject *args) { 
    4645        PyObject *x_val_obj; 
    4746        PyObject *y_val_obj; 
     
    7978        OUTVECTOR(mz_val_obj, mz_val, n_x); 
    8079        OUTVECTOR(vol_pix_obj, vol_pix, n_x); 
    81         GenI* sld2i = new GenI(n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,vol_pix,inspin,outspin,stheta); 
     80        GenI* sld2i =  PyMem_Malloc(sizeof(GenI)); 
     81        if (sld2i != NULL) { 
     82                initGenI(sld2i, n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,vol_pix,inspin,outspin,stheta); 
     83        } 
    8284        return PyCapsule_New(sld2i, "GenI", del_sld2i); 
    8385} 
     
    8688 * GenI the given input (2D) according to a given object 
    8789 */ 
    88 PyObject * genicom_inputXY(PyObject *, PyObject *args) { 
     90PyObject * genicom_inputXY(PyObject *self, PyObject *args) { 
    8991        int npoints; 
    9092        PyObject *qx_obj; 
     
    106108 
    107109        // Set the array pointers 
    108         void *temp = PyCapsule_GetPointer(gen_obj, "GenI"); 
    109         GenI* s = static_cast<GenI *>(temp); 
    110  
    111         s->genicomXY(npoints, qx, qy, I_out); 
     110        GenI* sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 
     111 
     112        genicomXY(sld2i, npoints, qx, qy, I_out); 
    112113        //return PyCObject_FromVoidPtr(s, del_genicom); 
    113114        return Py_BuildValue("i",1); 
     
    117118 * GenI the given 1D input according to a given object 
    118119 */ 
    119 PyObject * genicom_input(PyObject *, PyObject *args) { 
     120PyObject * genicom_input(PyObject *self, PyObject *args) { 
    120121        int npoints; 
    121122        PyObject *q_obj; 
     
    134135 
    135136        // Set the array pointers 
    136         void *temp = PyCapsule_GetPointer(gen_obj, "GenI"); 
    137         GenI* s = static_cast<GenI *>(temp); 
    138  
    139         s->genicom(npoints, q, I_out); 
     137        GenI *sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 
     138 
     139        genicom(sld2i, npoints, q, I_out); 
    140140        //return PyCObject_FromVoidPtr(s, del_genicom); 
    141141        return Py_BuildValue("i",1); 
Note: See TracChangeset for help on using the changeset viewer.