On Wed, Dec 9, 2009 at 6:38 PM, Dag Sverre Seljebotn
<[email protected]> wrote:
> Greg Ewing wrote:
>> Lisandro Dalcin wrote:
>>
>>> The point is that NULL is not a valid return value, but MPI_COMM_NULL is.
>>
>> In that case, you don't have a problem in the first
>> place, because you *want* something that is not a
>> valid return value.
>>
>> Are you sure you understand what the 'except' clause
>> is doing here? It *doesn't* cause an exception to be
>> raised when the routine returns that value. It's an
>> out-of-band value for Pyrex to use to indicate that
>> the routine has, or may have, already raised an
>> exception.
>>
>> If you're calling an external routine, you need to
>> check for whatever it uses to signal an error and raise
>> and exception yourself. When you do that, Pyrex will
>> use the exception value you've declared to signal
>> that to calling Python-aware code.
>>
>> The exception value is ideally a value that the routine
>> can't ever return normally, or (with '?') one that
>> it returns rarely. If the external routine is guaranteed
>> never to return NULL, then that's an ideal unconditional
>> exception value for your wrapper routine to use.
>
> I believe the idea is that the routine doesn't return a pointer, but a
> struct or similar. Of course, also structs can have NULL-like values
> defined for them.
>
Indeed. I need to return a MPI_Comm value, and MPI_Comm can be
anything (well, it usually is an integer or a pointer, depending on
the implementation). So I need to code this:
cdef class Comm:
MPI_Comm ob_mpi
cdef api MPI_Comm PyMPIComm_AsComm(object o) except? MPI_COMM_NULL:
return (<Comm?>o).ob_mpi
Inside that function I do a typecheck to make sure that object 'o' do
have the appropriate type. So if the typecheck fail, Cython/Pyrex
should set the Python error, and I want MPI_COMM_NULL to be returned
to signal the failure to the caller.
--
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