In mpi4py, I have to declare C-level MPI handles. Depending on the MPI
implementation, handles are integers (i.e. a plain C int) or pointers
to a (opaque, incomplete) struct. So the actual type of an MPI handle
is an implementation detail that user code should never rely on. Then
in my pxd I do:
cdef extern from "mpi.h":
cdef struct _mpi_comm_t
ctypedef _mpi_comm_t* MPI_Comm
So _mpi_comm_t is a fake definition, but so far it works everywhere
(and it is IMHO better that using a typedef to an integral type,
because of the added type-checking)
In MPI, invalid handles are indicated by "special" handle values (not
necessarily being zero or NULL), so I also have this definition:
cdef extern from "mpi.h":
MPI_Comm MPI_COMM_NULL
For each C-level MPI handle, I have a proxy class:
ctypedef public api class Comm [type PyMPIComm_Type, object PyMPICommObject]:
cdef MPI_Comm ob_mpi
Now I want to define an API routine for getting the C-level handle
from a Python-level instance. Moreover, I what that routine to return
the MPI_XXXX_NULL handle in case of failure (note the type-check):
cdef api MPI_Comm PyMPIComm_AsComm(object arg) except MPI_COMM_NULL:
return (<Comm?>arg).ob_mpi
However, Cython does not let me write that function. I'm asked to
provide a constant expression. MPI_COMM_NULL do is a constant in MPI
tongue, but AFAIK I have no way to ask Cython to treat an general (I
mean, non-enumeration) external definition as a constant.
After much thinking, I'm not sure why Cython (and likely Pyrex) do
require a constant expression here... Could we relax this requirement?
Of perhaps devise other way that let me use a external definition?
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev