C
chris.cenotti
I am currently trying to port some Python and Python C extension code
to C#, and am having trouble understanding what is happening in a
piece of the code.
The pertinent pieces of code are below, and my question follows the
snippets:
in foo.py:
(mgrid,xgrid,ygrid,zgrid,ngrids) = IP.CreateGridCell()
in IP.c:
static PyObject *PyCreateGridCell()
{
GRIDCELL *grid = alloc(...);
for(i=0; i<length; i++)
{
grid[cnt] = .... //etc fill in grid array
cnt++;
}
PyObject *GRIDRET = PyCObject_FromVoidPtr((void *)grid,NULL);
return Py_BuildValue("Oi",GRIDRET,cnt-1);
typedef struct {
XYZ p[8];
double val[8];
} GRIDCELL;
typedef struct {
double x,y,z;
} XYZ;
So my question is (and I hope it's not too silly a question), what is
happening to the grid array pointer in the C code that it maps to
multiple variables (which all are arrays) on the python side. Is the
grid variable being assigned to mgrid, xgrid, ygrid and zgrid whole,
or is it being split somehow (and if so, how)? Thanks for the help.
to C#, and am having trouble understanding what is happening in a
piece of the code.
The pertinent pieces of code are below, and my question follows the
snippets:
in foo.py:
(mgrid,xgrid,ygrid,zgrid,ngrids) = IP.CreateGridCell()
in IP.c:
static PyObject *PyCreateGridCell()
{
GRIDCELL *grid = alloc(...);
for(i=0; i<length; i++)
{
grid[cnt] = .... //etc fill in grid array
cnt++;
}
PyObject *GRIDRET = PyCObject_FromVoidPtr((void *)grid,NULL);
return Py_BuildValue("Oi",GRIDRET,cnt-1);
typedef struct {
XYZ p[8];
double val[8];
} GRIDCELL;
typedef struct {
double x,y,z;
} XYZ;
So my question is (and I hope it's not too silly a question), what is
happening to the grid array pointer in the C code that it maps to
multiple variables (which all are arrays) on the python side. Is the
grid variable being assigned to mgrid, xgrid, ygrid and zgrid whole,
or is it being split somehow (and if so, how)? Thanks for the help.